Add missing FFDH public key buffer length check

When exporting an FFDH public key we were not properly checking the
length of the output buffer and would write the full length of the key
in all cases. Fix this by checking the size of the output buffer before
we write to it.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
This commit is contained in:
David Horstmann
2026-02-26 14:47:04 +00:00
parent 443300e700
commit 01bcc1f754

View File

@@ -168,6 +168,10 @@ psa_status_t mbedtls_psa_ffdh_export_public_key(
mbedtls_mpi_init(&X); mbedtls_mpi_init(&P);
size_t key_len = PSA_BITS_TO_BYTES(attributes->bits);
if (key_len > data_size) {
status = PSA_ERROR_BUFFER_TOO_SMALL;
goto cleanup;
}
status = mbedtls_psa_ffdh_set_prime_generator(key_len, &P, &G);