]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Drop the aid field of the signature prov ctx
authorlan1120 <lanming@huawei.com>
Mon, 30 Sep 2024 07:00:04 +0000 (15:00 +0800)
committerTomas Mraz <tomas@openssl.org>
Mon, 7 Oct 2024 15:35:28 +0000 (17:35 +0200)
Signed-off-by: lan1120 <lanming@huawei.com>
Reviewed-by: Hugo Landau <hlandau@devever.net>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23094)

providers/implementations/signature/dsa_sig.c
providers/implementations/signature/ecdsa_sig.c
providers/implementations/signature/eddsa_sig.c
providers/implementations/signature/sm2_sig.c

index 45dc2358323c61369cce8ea14df12f4806d0f665..eb28c595b7ede241c13b8ee0a467f536a211314b 100644 (file)
@@ -98,7 +98,6 @@ typedef struct {
 
     /* The Algorithm Identifier of the combined signature algorithm */
     unsigned char aid_buf[OSSL_MAX_ALGORITHM_ID_SIZE];
-    unsigned char *aid;
     size_t  aid_len;
 
     /* main digest */
@@ -160,6 +159,7 @@ static int dsa_setup_md(PROV_DSA_CTX *ctx,
         WPACKET pkt;
         int md_nid;
         size_t mdname_len = strlen(mdname);
+        unsigned char *aid = NULL;
 
         md = EVP_MD_fetch(ctx->libctx, mdname, mdprops);
         md_nid = ossl_digest_get_approved_nid(md);
@@ -223,9 +223,11 @@ static int dsa_setup_md(PROV_DSA_CTX *ctx,
                                                           md_nid)
             && WPACKET_finish(&pkt)) {
             WPACKET_get_total_written(&pkt, &ctx->aid_len);
-            ctx->aid = WPACKET_get_curr(&pkt);
+            aid = WPACKET_get_curr(&pkt);
         }
         WPACKET_cleanup(&pkt);
+        if (aid != NULL && ctx->aid_len != 0)
+            memmove(ctx->aid_buf, aid, ctx->aid_len);
 
         ctx->mdctx = NULL;
         ctx->md = md;
@@ -674,7 +676,9 @@ static int dsa_get_ctx_params(void *vpdsactx, OSSL_PARAM *params)
 
     p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID);
     if (p != NULL
-        && !OSSL_PARAM_set_octet_string(p, pdsactx->aid, pdsactx->aid_len))
+        && !OSSL_PARAM_set_octet_string(p,
+                                        pdsactx->aid_len == 0 ? NULL : pdsactx->aid_buf,
+                                        pdsactx->aid_len))
         return 0;
 
     p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST);
index 52607245a4c74bcaa84497d5ae8e9bc2f952fd4c..72be2bcb62075c9f3a84e89438a387f5b741ed42 100644 (file)
@@ -95,7 +95,6 @@ typedef struct {
 
     /* The Algorithm Identifier of the combined signature algorithm */
     unsigned char aid_buf[OSSL_MAX_ALGORITHM_ID_SIZE];
-    unsigned char *aid;
     size_t  aid_len;
 
     /* main digest */
@@ -172,6 +171,7 @@ static int ecdsa_setup_md(PROV_ECDSA_CTX *ctx,
     size_t mdname_len;
     int md_nid, md_size;
     WPACKET pkt;
+    unsigned char *aid = NULL;
 
     if (mdname == NULL)
         return 1;
@@ -242,9 +242,12 @@ static int ecdsa_setup_md(PROV_ECDSA_CTX *ctx,
                                                         md_nid)
         && WPACKET_finish(&pkt)) {
         WPACKET_get_total_written(&pkt, &ctx->aid_len);
-        ctx->aid = WPACKET_get_curr(&pkt);
+        aid = WPACKET_get_curr(&pkt);
     }
     WPACKET_cleanup(&pkt);
+    if (aid != NULL && ctx->aid_len != 0)
+        memmove(ctx->aid_buf, aid, ctx->aid_len);
+
     ctx->mdctx = NULL;
     ctx->md = md;
     ctx->mdsize = (size_t)md_size;
@@ -670,7 +673,9 @@ static int ecdsa_get_ctx_params(void *vctx, OSSL_PARAM *params)
         return 0;
 
     p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID);
-    if (p != NULL && !OSSL_PARAM_set_octet_string(p, ctx->aid, ctx->aid_len))
+    if (p != NULL && !OSSL_PARAM_set_octet_string(p,
+                                                  ctx->aid_len == 0 ? NULL : ctx->aid_buf,
+                                                  ctx->aid_len))
         return 0;
 
     p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST_SIZE);
index 395d4b4daf5e606de3963b23df6cdd80862a46e4..e6689911c84cb292108e65317636a31f916cdc3e 100644 (file)
@@ -141,7 +141,6 @@ typedef struct {
 
     /* The Algorithm Identifier of the signature algorithm */
     unsigned char aid_buf[OSSL_MAX_ALGORITHM_ID_SIZE];
-    unsigned char *aid;
     size_t  aid_len;
 
     /* id indicating the EdDSA instance */
@@ -234,6 +233,7 @@ static int eddsa_signverify_init(void *vpeddsactx, void *vedkey)
     ECX_KEY *edkey = (ECX_KEY *)vedkey;
     WPACKET pkt;
     int ret;
+    unsigned char *aid = NULL;
 
     if (!ossl_prov_is_running())
         return 0;
@@ -281,9 +281,11 @@ static int eddsa_signverify_init(void *vpeddsactx, void *vedkey)
     }
     if (ret && WPACKET_finish(&pkt)) {
         WPACKET_get_total_written(&pkt, &peddsactx->aid_len);
-        peddsactx->aid = WPACKET_get_curr(&pkt);
+        aid = WPACKET_get_curr(&pkt);
     }
     WPACKET_cleanup(&pkt);
+    if (aid != NULL && peddsactx->aid_len != 0)
+        memmove(peddsactx->aid_buf, aid, peddsactx->aid_len);
 
     return 1;
 }
@@ -795,8 +797,10 @@ static int eddsa_get_ctx_params(void *vpeddsactx, OSSL_PARAM *params)
         return 0;
 
     p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID);
-    if (p != NULL && !OSSL_PARAM_set_octet_string(p, peddsactx->aid,
-                                                  peddsactx->aid_len))
+    if (p != NULL
+        && !OSSL_PARAM_set_octet_string(p,
+                                        peddsactx->aid_len == 0 ? NULL : peddsactx->aid_buf,
+                                        peddsactx->aid_len))
         return 0;
 
     return 1;
index ec7c4af3892a0f46b9d35be5a56046a0c88341e3..fa7dcefaa31282f3a116138df5afe97a2fd89757 100644 (file)
@@ -77,7 +77,6 @@ typedef struct {
 
     /* The Algorithm Identifier of the combined signature algorithm */
     unsigned char aid_buf[OSSL_MAX_ALGORITHM_ID_SIZE];
-    unsigned char *aid;
     size_t  aid_len;
 
     /* main digest */
@@ -213,6 +212,7 @@ static int sm2sig_digest_signverify_init(void *vpsm2ctx, const char *mdname,
     int md_nid;
     WPACKET pkt;
     int ret = 0;
+    unsigned char *aid = NULL;
 
     if (!sm2sig_signature_init(vpsm2ctx, ec, params)
         || !sm2sig_set_mdname(ctx, mdname))
@@ -238,9 +238,11 @@ static int sm2sig_digest_signverify_init(void *vpsm2ctx, const char *mdname,
         && ossl_DER_w_algorithmIdentifier_SM2_with_MD(&pkt, -1, ctx->ec, md_nid)
         && WPACKET_finish(&pkt)) {
         WPACKET_get_total_written(&pkt, &ctx->aid_len);
-        ctx->aid = WPACKET_get_curr(&pkt);
+        aid = WPACKET_get_curr(&pkt);
     }
     WPACKET_cleanup(&pkt);
+    if (aid != NULL && ctx->aid_len != 0)
+        memmove(ctx->aid_buf, aid, ctx->aid_len);
 
     if (!EVP_DigestInit_ex2(ctx->mdctx, ctx->md, params))
         goto error;
@@ -404,7 +406,9 @@ static int sm2sig_get_ctx_params(void *vpsm2ctx, OSSL_PARAM *params)
 
     p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID);
     if (p != NULL
-        && !OSSL_PARAM_set_octet_string(p, psm2ctx->aid, psm2ctx->aid_len))
+        && !OSSL_PARAM_set_octet_string(p,
+                                        psm2ctx->aid_len == 0 ? NULL : psm2ctx->aid_buf,
+                                        psm2ctx->aid_len))
         return 0;
 
     p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST_SIZE);