Skip to content

Commit 4a17200

Browse files
committed
test/provider: Add tests for ECDSA deterministic signatures
Perform a deterministic signature with IBMCA and the default provider using the same key, and compare the resulting signatures. Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
1 parent 91f1ab7 commit 4a17200

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/provider/eckey.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,12 @@ static int check_eckey(int nid, const char *curvename)
425425
size_t keylen1, keylen2;
426426
unsigned char keybuf1[512], keybuf2[512];
427427
unsigned char digest[32];
428+
#ifdef OSSL_SIGNATURE_PARAM_NONCE_TYPE
429+
size_t siglen2;
430+
unsigned char sigbuf2[1024];
431+
OSSL_PARAM params[2];
432+
unsigned int nonce_type;
433+
#endif
428434

429435
memset(digest, 0, sizeof(digest));
430436

@@ -485,6 +491,34 @@ static int check_eckey(int nid, const char *curvename)
485491
digest, sizeof(digest), sigbuf, siglen))
486492
goto out;
487493

494+
#ifdef OSSL_SIGNATURE_PARAM_NONCE_TYPE
495+
nonce_type = 1;
496+
params[0] = OSSL_PARAM_construct_uint(OSSL_SIGNATURE_PARAM_NONCE_TYPE,
497+
&nonce_type);
498+
params[1] = OSSL_PARAM_construct_end();
499+
500+
/* Digest-Sign using deterministic signature with default provider */
501+
siglen = sizeof(sigbuf);
502+
if (!sign_digest(NULL, ec_pkey, "SHA256", params,
503+
digest, sizeof(digest), sigbuf, &siglen))
504+
goto out;
505+
506+
/* Digest-Sign using deterministic signature with IBMCA provider */
507+
siglen2 = sizeof(sigbuf2);
508+
if (!sign_digest("ibmca", ec_pkey, "SHA256", params,
509+
digest, sizeof(digest), sigbuf2, &siglen2))
510+
goto out;
511+
512+
if (siglen != siglen2 ||
513+
memcmp(sigbuf, sigbuf2, siglen) != 0) {
514+
fprintf(stderr, "Deterministic signatures do not match\n");
515+
ok = 0;
516+
goto out;
517+
} else {
518+
printf("Deterministic signature is correct\n");
519+
}
520+
#endif
521+
488522
/* Keygen with IBMCA provider (using ec_pkey as template) */
489523
if (!generate_key("ibmca", nid, curvename, NULL, ec_pkey, &peer_pkey))
490524
goto out;

0 commit comments

Comments
 (0)