summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Yang <kaishen.yy@antfin.com>2020-09-13 20:31:13 +0800
committerMatt Caswell <matt@openssl.org>2020-09-22 08:18:09 +0100
commitb3d267caac21dd0a7d7a8cfcc304b253df5e82f4 (patch)
tree564617e6678615586334c8fdaecc794f06282364
parentd0b79f8631c0f522c514175be4e4fbe984cf8f6c (diff)
Address review comments
Reviewed-by: Richard Levitte <levitte@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/12536)
-rw-r--r--crypto/sm2/sm2_sign.c14
-rw-r--r--providers/common/der/der_sm2_key.c2
-rw-r--r--providers/implementations/signature/sm2sig.c36
3 files changed, 9 insertions, 43 deletions
diff --git a/crypto/sm2/sm2_sign.c b/crypto/sm2/sm2_sign.c
index 9216ab6b3d..39b6e11cf2 100644
--- a/crypto/sm2/sm2_sign.c
+++ b/crypto/sm2/sm2_sign.c
@@ -428,19 +428,19 @@ int sm2_internal_sign(const unsigned char *dgst, int dgstlen,
e = BN_bin2bn(dgst, dgstlen, NULL);
if (e == NULL) {
- SM2err(SM2_F_SM2_INTERNAL_SIGN, ERR_R_BN_LIB);
+ SM2err(0, ERR_R_BN_LIB);
goto done;
}
s = sm2_sig_gen(eckey, e);
if (s == NULL) {
- SM2err(SM2_F_SM2_INTERNAL_SIGN, ERR_R_INTERNAL_ERROR);
+ SM2err(0, ERR_R_INTERNAL_ERROR);
goto done;
}
sigleni = i2d_ECDSA_SIG(s, &sig);
if (sigleni < 0) {
- SM2err(SM2_F_SM2_INTERNAL_SIGN, ERR_R_INTERNAL_ERROR);
+ SM2err(0, ERR_R_INTERNAL_ERROR);
goto done;
}
*siglen = (unsigned int)sigleni;
@@ -465,23 +465,23 @@ int sm2_internal_verify(const unsigned char *dgst, int dgstlen,
s = ECDSA_SIG_new();
if (s == NULL) {
- SM2err(SM2_F_SM2_INTERNAL_VERIFY, ERR_R_MALLOC_FAILURE);
+ SM2err(0, ERR_R_MALLOC_FAILURE);
goto done;
}
if (d2i_ECDSA_SIG(&s, &p, sig_len) == NULL) {
- SM2err(SM2_F_SM2_INTERNAL_VERIFY, SM2_R_INVALID_ENCODING);
+ SM2err(0, SM2_R_INVALID_ENCODING);
goto done;
}
/* Ensure signature uses DER and doesn't have trailing garbage */
derlen = i2d_ECDSA_SIG(s, &der);
if (derlen != sig_len || memcmp(sig, der, derlen) != 0) {
- SM2err(SM2_F_SM2_INTERNAL_VERIFY, SM2_R_INVALID_ENCODING);
+ SM2err(0, SM2_R_INVALID_ENCODING);
goto done;
}
e = BN_bin2bn(dgst, dgstlen, NULL);
if (e == NULL) {
- SM2err(SM2_F_SM2_INTERNAL_VERIFY, ERR_R_BN_LIB);
+ SM2err(0, ERR_R_BN_LIB);
goto done;
}
diff --git a/providers/common/der/der_sm2_key.c b/providers/common/der/der_sm2_key.c
index daf2072c9e..7167088099 100644
--- a/providers/common/der/der_sm2_key.c
+++ b/providers/common/der/der_sm2_key.c
@@ -16,7 +16,7 @@ int DER_w_algorithmIdentifier_SM2(WPACKET *pkt, int cont, EC_KEY *ec)
{
return DER_w_begin_sequence(pkt, cont)
/* No parameters (yet?) */
- /* It seems SM2 identifier is the same to id_ecPublidKey */
+ /* It seems SM2 identifier is the same as id_ecPublidKey */
&& DER_w_precompiled(pkt, -1, der_oid_id_ecPublicKey,
sizeof(der_oid_id_ecPublicKey))
&& DER_w_end_sequence(pkt, cont);
diff --git a/providers/implementations/signature/sm2sig.c b/providers/implementations/signature/sm2sig.c
index 0e35fb4739..d2a091b89b 100644
--- a/providers/implementations/signature/sm2sig.c
+++ b/providers/implementations/signature/sm2sig.c
@@ -95,37 +95,6 @@ typedef struct {
size_t id_len;
} PROV_SM2_CTX;
-/* TODO: it seems SM2 doesn't need this */
-static int sm2sig_get_md_nid(const EVP_MD *md)
-{
- /*
- * Because the EC library deals with NIDs, we need to translate.
- * We do so using EVP_MD_is_a(), and therefore need a name to NID
- * map.
- */
- static const OSSL_ITEM name_to_nid[] = {
- { NID_sm3, OSSL_DIGEST_NAME_SM3 },
- };
- size_t i;
- int mdnid = NID_undef;
-
- if (md == NULL)
- goto end;
-
- for (i = 0; i < OSSL_NELEM(name_to_nid); i++) {
- if (EVP_MD_is_a(md, name_to_nid[i].ptr)) {
- mdnid = (int)name_to_nid[i].id;
- break;
- }
- }
-
- if (mdnid == NID_undef)
- ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST);
-
- end:
- return mdnid;
-}
-
static void *sm2sig_newctx(void *provctx, const char *propq)
{
PROV_SM2_CTX *ctx = OPENSSL_zalloc(sizeof(PROV_SM2_CTX));
@@ -207,7 +176,7 @@ static int sm2sig_digest_signverify_init(void *vpsm2ctx, const char *mdname,
void *ec)
{
PROV_SM2_CTX *ctx = (PROV_SM2_CTX *)vpsm2ctx;
- int md_nid = NID_undef;
+ int md_nid = NID_sm3;
WPACKET pkt;
int ret = 0;
@@ -217,9 +186,6 @@ static int sm2sig_digest_signverify_init(void *vpsm2ctx, const char *mdname,
return ret;
ctx->md = EVP_MD_fetch(ctx->libctx, mdname, ctx->propq);
- if ((md_nid = sm2sig_get_md_nid(ctx->md)) == NID_undef)
- goto error;
-
ctx->mdsize = EVP_MD_size(ctx->md);
ctx->mdctx = EVP_MD_CTX_new();
if (ctx->mdctx == NULL)