From 9ec38f2eb6d7c64fa3e84f42cb077f72665b9bc5 Mon Sep 17 00:00:00 2001 From: Etienne Carriere Date: Wed, 4 Dec 2024 17:04:03 +0100 Subject: [PATCH] xtest: pkcs11_1025: ED25519 Asymm sign against short buffer cases 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 Acked-by: Jens Wiklander --- host/xtest/pkcs11_1000.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/host/xtest/pkcs11_1000.c b/host/xtest/pkcs11_1000.c index c6b5e4100..13f3f43ed 100644 --- a/host/xtest/pkcs11_1000.c +++ b/host/xtest/pkcs11_1000.c @@ -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); @@ -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;