pk: test buffer too small for RSA-opaque + RSA-alt

A previous commit added tests "normal" PK RSA contexts, but missed
opaque RSA keys and RSA_ALT keys.

Signed-off-by: Manuel Pégourié-Gonnard <[email protected]>
This commit is contained in:
Manuel Pégourié-Gonnard
2026-06-11 11:52:18 +02:00
parent 9516cc4e70
commit 29108ed8ce
+13
View File
@@ -1624,6 +1624,12 @@ void pk_wrap_rsa_decrypt_test_vec(data_t *cipher, int mod,
if (ret == 0) {
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);
}
TEST_EQUAL(PSA_SUCCESS, psa_destroy_key(key_id));
@@ -1795,6 +1801,13 @@ void pk_rsa_alt()
TEST_ASSERT(test_len == sizeof(msg));
TEST_ASSERT(memcmp(test, msg, test_len) == 0);
/* Try again with an output buffer that's too small */
TEST_EQUAL(mbedtls_pk_decrypt(&alt, ciph, ciph_len,
test, &test_len, sizeof(msg) - 1,
mbedtls_test_rnd_std_rand, NULL),
MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE);
/* Test forbidden operations */
TEST_ASSERT(mbedtls_pk_encrypt(&alt, msg, sizeof(msg),
ciph, &ciph_len, sizeof(ciph),