Drop the aid field of the signature prov ctx

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)
This commit is contained in:
lan1120 2024-09-30 15:00:04 +08:00 committed by Tomas Mraz
parent 76c4f0e8ea
commit b69ca92a5e
4 changed files with 30 additions and 13 deletions

View 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);

View 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);

View 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;

View 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);