diff --git a/library/pk_wrap.c b/library/pk_wrap.c index 0e12d05c2..75a49a15c 100644 --- a/library/pk_wrap.c +++ b/library/pk_wrap.c @@ -733,10 +733,21 @@ static void pk_psa_free_wrap( void *ctx ) mbedtls_free( ctx ); } +static size_t pk_psa_get_bitlen( const void *ctx ) +{ + const psa_key_slot_t *key = (const psa_key_slot_t *) ctx; + size_t bits; + + if( PSA_SUCCESS != psa_get_key_information( *key, NULL, &bits ) ) + return( 0 ); + + return( bits ); +} + const mbedtls_pk_info_t mbedtls_pk_opaque_psa_info = { MBEDTLS_PK_OPAQUE_PSA, "Opaque (PSA)", - NULL, /* coming soon: bitlen */ + pk_psa_get_bitlen, NULL, /* coming soon: can_do */ NULL, /* verify - will be done later */ NULL, /* coming soon: sign */ diff --git a/tests/suites/test_suite_pk.function b/tests/suites/test_suite_pk.function index 64f1fec42..8f6abf59e 100644 --- a/tests/suites/test_suite_pk.function +++ b/tests/suites/test_suite_pk.function @@ -101,9 +101,11 @@ psa_key_slot_t pk_psa_genkey( void ) void pk_psa_utils( ) { mbedtls_pk_context pk; - const char * const name = "Opaque (PSA)"; psa_key_slot_t key; + const char * const name = "Opaque (PSA)"; + const size_t bitlen = 256; /* harcoded in genkey() */ + mbedtls_pk_init( &pk ); key = pk_psa_genkey(); @@ -114,6 +116,9 @@ void pk_psa_utils( ) TEST_ASSERT( mbedtls_pk_get_type( &pk ) == MBEDTLS_PK_OPAQUE_PSA ); TEST_ASSERT( strcmp( mbedtls_pk_get_name( &pk), name ) == 0 ); + TEST_ASSERT( mbedtls_pk_get_bitlen( &pk ) == bitlen ); + TEST_ASSERT( mbedtls_pk_get_len( &pk ) == bitlen / 8 ); + /* test that freeing the context does not destroy the key */ mbedtls_pk_free( &pk ); TEST_ASSERT( PSA_SUCCESS == psa_destroy_key( key ) );