From 255fd41e1ef4619e4743acd1c687de8966a9a821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Thu, 11 Jun 2026 16:50:29 +0200 Subject: [PATCH] pk: tests: avoid corner case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manuel Pégourié-Gonnard --- tests/suites/test_suite_pk.function | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/tests/suites/test_suite_pk.function b/tests/suites/test_suite_pk.function index ea065095e5..aad93cbae7 100644 --- a/tests/suites/test_suite_pk.function +++ b/tests/suites/test_suite_pk.function @@ -1547,11 +1547,13 @@ void pk_rsa_decrypt_test_vec(data_t *cipher, int mod, int padding, int md_alg, TEST_ASSERT(olen == clear->len); TEST_ASSERT(memcmp(output, clear->x, olen) == 0); - /* Try again with an output buffer that's too small */ - TEST_EQUAL(mbedtls_pk_decrypt(&pk, cipher->x, cipher->len, - output, &olen, clear->len - 1, - mbedtls_test_rnd_pseudo_rand, &rnd_info), - MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE); + if (clear->len != 0) { + /* Try again with an output buffer that's too small */ + TEST_EQUAL(mbedtls_pk_decrypt(&pk, cipher->x, cipher->len, + output, &olen, clear->len - 1, + mbedtls_test_rnd_pseudo_rand, &rnd_info), + MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE); + } } exit: @@ -1625,11 +1627,13 @@ void pk_wrap_rsa_decrypt_test_vec(data_t *cipher, int mod, TEST_EQUAL(olen, clear->len); TEST_EQUAL(memcmp(output, clear->x, olen), 0); - /* Try again with an output buffer that's too small */ - TEST_EQUAL(mbedtls_pk_decrypt(&pk, cipher->x, cipher->len, - output, &olen, clear->len - 1, - mbedtls_test_rnd_pseudo_rand, &rnd_info), - MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE); + if (clear->len != 0) { + /* Try again with an output buffer that's too small */ + TEST_EQUAL(mbedtls_pk_decrypt(&pk, cipher->x, cipher->len, + output, &olen, clear->len - 1, + mbedtls_test_rnd_pseudo_rand, &rnd_info), + MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE); + } } TEST_EQUAL(PSA_SUCCESS, psa_destroy_key(key_id));