From 5b20a7e8b3e80421a65d79a90069a27a6bb2e8d7 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Thu, 7 Oct 2021 11:08:56 +0200 Subject: [PATCH] psa_generate_key(): return PSA_ERROR_INVALID_ARGUMENT for public key Signed-off-by: Przemyslaw Stekiel --- library/psa_crypto.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index adcb0ccf2..818ff9e90 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -5230,6 +5230,10 @@ psa_status_t psa_generate_key( const psa_key_attributes_t *attributes, if( psa_get_key_bits( attributes ) == 0 ) return( PSA_ERROR_INVALID_ARGUMENT ); + /* Reject any attempt to create a public key. */ + if( PSA_KEY_TYPE_IS_PUBLIC_KEY(attributes->core.type) ) + return( PSA_ERROR_INVALID_ARGUMENT ); + status = psa_start_key_creation( PSA_KEY_CREATION_GENERATE, attributes, &slot, &driver ); if( status != PSA_SUCCESS )