Skip to content

Commit

Permalink
xtest: pkcs11_1025: ED25519 Asymm sign against short buffer cases
Browse files Browse the repository at this point in the history
Test that providing a too small signature output buffer for an
ED25519 sign operation makes the Cryptoki API function to return
CKR_OK (nul size case) or CKR_BUFFER_TOO_SMALL (non-nul too small size)
as expected and that providing a bigger buffer returns the expected
signature size.

Signed-off-by: Etienne Carriere <etienne.carriere@foss.st.com>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
  • Loading branch information
etienne-lms committed Dec 5, 2024
1 parent 46b01e9 commit 9ec38f2
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion host/xtest/pkcs11_1000.c
Original file line number Diff line number Diff line change
Expand Up @@ -8125,7 +8125,7 @@ static void xtest_pkcs11_test_1025(ADBG_Case_t *c)
CK_OBJECT_HANDLE private_key = CK_INVALID_HANDLE;
size_t i = 0;
struct eddsa_test *test = NULL;
char sign[64] = { };
char sign[128] = { };
CK_EDDSA_PARAMS eddsa_params = { };
CK_ULONG sign_len = ARRAY_SIZE(sign);

Expand Down Expand Up @@ -8231,12 +8231,33 @@ static void xtest_pkcs11_test_1025(ADBG_Case_t *c)
if (!ADBG_EXPECT_CK_OK(c, rv))
goto err_destroy_keys;

/* Query signature size providing a 0 size value */
sign_len = 0;
rv = C_Sign(session, (CK_BYTE_PTR)test->message,
test->message_len, NULL, &sign_len);
if (!ADBG_EXPECT_CK_OK(c, rv))
goto err_destroy_keys;

/* Query signature size providing a size value too small */
sign_len--;
rv = C_Sign(session, (CK_BYTE_PTR)test->message,
test->message_len,
(CK_BYTE_PTR)sign, &sign_len);
if (!ADBG_EXPECT_CK_RESULT(c, CKR_BUFFER_TOO_SMALL, rv))
goto err_destroy_keys;

/* Effective signature computation */
sign_len = ARRAY_SIZE(sign);
rv = C_Sign(session, (CK_BYTE_PTR)test->message,
test->message_len,
(CK_BYTE_PTR)sign, &sign_len);
if (!ADBG_EXPECT_CK_OK(c, rv))
goto err_destroy_keys;

/* Check size of the signature */
if (!ADBG_EXPECT_COMPARE_UNSIGNED(c, sign_len, ==, 64))
goto err_destroy_keys;

rv = C_VerifyInit(session, &sign_mechanism, public_key);
if (!ADBG_EXPECT_CK_OK(c, rv))
goto err_destroy_keys;
Expand Down

0 comments on commit 9ec38f2

Please sign in to comment.