Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sm2: Allow setting 0 length SM2 dist ID param #18052

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions providers/implementations/signature/sm2_sig.c
Expand Up @@ -430,15 +430,16 @@ static int sm2sig_set_ctx_params(void *vpsm2ctx, const OSSL_PARAM params[])
p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_DIST_ID);
if (p != NULL) {
void *tmp_id = NULL;
size_t tmp_idlen;
size_t tmp_idlen = 0;

/*
* If the 'z' digest has already been computed, the ID is set too late
*/
if (!psm2ctx->flag_compute_z_digest)
return 0;

if (!OSSL_PARAM_get_octet_string(p, &tmp_id, 0, &tmp_idlen))
if (p->data_size != 0
&& !OSSL_PARAM_get_octet_string(p, &tmp_id, 0, &tmp_idlen))
return 0;
OPENSSL_free(psm2ctx->id);
psm2ctx->id = tmp_id;
Expand Down
18 changes: 18 additions & 0 deletions test/evp_extra_test.c
Expand Up @@ -1963,6 +1963,24 @@ static int test_EVP_SM2(void)
if (!TEST_int_gt(EVP_DigestVerifyFinal(md_ctx_verify, sig, sig_len), 0))
goto done;

/*
* Try verify again with non-matching 0 length id but ensure that it can
* be set on the context and overrides the previous value.
*/

if (!TEST_true(EVP_DigestVerifyInit(md_ctx_verify, NULL, check_md, NULL,
pkey)))
goto done;

if (!TEST_int_gt(EVP_PKEY_CTX_set1_id(sctx, NULL, 0), 0))
goto done;

if (!TEST_true(EVP_DigestVerifyUpdate(md_ctx_verify, kMsg, sizeof(kMsg))))
goto done;

if (!TEST_int_eq(EVP_DigestVerifyFinal(md_ctx_verify, sig, sig_len), 0))
goto done;

/* now check encryption/decryption */

gparams[0] = OSSL_PARAM_construct_utf8_string(OSSL_ASYM_CIPHER_PARAM_DIGEST,
Expand Down