Add support for get_(bit)len on opaque keys

This commit is contained in:
Manuel Pégourié-Gonnard 2018-10-31 10:36:51 +01:00
parent 01a12c49aa
commit 0184b3c69b
2 changed files with 18 additions and 2 deletions

View File

@ -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 */

View File

@ -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 ) );