]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Address review comments
authorPaul Yang <kaishen.yy@antfin.com>
Sun, 13 Sep 2020 12:31:13 +0000 (20:31 +0800)
committerMatt Caswell <matt@openssl.org>
Tue, 22 Sep 2020 07:18:09 +0000 (08:18 +0100)
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/12536)

crypto/sm2/sm2_sign.c
providers/common/der/der_sm2_key.c
providers/implementations/signature/sm2sig.c

index 9216ab6b3d102a5fe0f109b54c65bfb632e0a44b..39b6e11cf2a88d515a5f123894a07ae1b9bf988e 100644 (file)
@@ -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;
     }
 
index daf2072c9e62e421eea5b4a716b42074d35b6bb3..7167088099a9ff08f395a665e6fd1c8f4c12ff21 100644 (file)
@@ -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);
index 0e35fb4739221c850168400b54822a64030eeece..d2a091b89bde817a0e81df634a5c0335a635ca7e 100644 (file)
@@ -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)