Skip to content

Commit

Permalink
tests: Adapt PSA tests to openless APIs
Browse files Browse the repository at this point in the history
Signed-off-by: Ronald Cron <[email protected]>
  • Loading branch information
ronald-cron-arm committed Sep 18, 2020
1 parent 31d8f3f commit 9b6be96
Show file tree
Hide file tree
Showing 10 changed files with 713 additions and 812 deletions.
20 changes: 10 additions & 10 deletions tests/suites/test_suite_pk.function
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ size_t mbedtls_rsa_key_len_func( void *ctx )
#if defined(MBEDTLS_USE_PSA_CRYPTO)

/*
* Generate a key using PSA and return a handle to that key,
* Generate a key using PSA and return the key identifier of that key,
* or 0 if the key generation failed.
* The key uses NIST P-256 and is usable for signing with SHA-256.
*/
psa_key_handle_t pk_psa_genkey( void )
mbedtls_svc_key_id_t pk_psa_genkey( void )
{
psa_key_handle_t key;
mbedtls_svc_key_id_t key;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
const psa_key_type_t type =
PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_FAMILY_SECP_R1 );
Expand All @@ -133,7 +133,7 @@ exit:
void pk_psa_utils( )
{
mbedtls_pk_context pk, pk2;
psa_key_handle_t key;
mbedtls_svc_key_id_t key;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;

const char * const name = "Opaque";
Expand All @@ -151,14 +151,14 @@ void pk_psa_utils( )

TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );

TEST_ASSERT( mbedtls_pk_setup_opaque( &pk, PSA_KEY_HANDLE_INIT ) ==
TEST_ASSERT( mbedtls_pk_setup_opaque( &pk, MBEDTLS_SVC_KEY_ID_INIT ) ==
MBEDTLS_ERR_PK_BAD_INPUT_DATA );

mbedtls_pk_free( &pk );
mbedtls_pk_init( &pk );

key = pk_psa_genkey();
if( psa_key_handle_is_null( key ) )
if( mbedtls_svc_key_id_is_null( key ) )
goto exit;

TEST_ASSERT( mbedtls_pk_setup_opaque( &pk, key ) == 0 );
Expand Down Expand Up @@ -1220,7 +1220,7 @@ void pk_psa_sign( int grpid_arg,
unsigned char *pkey_legacy_start, *pkey_psa_start;
size_t sig_len, klen_legacy, klen_psa;
int ret;
psa_key_handle_t handle;
mbedtls_svc_key_id_t key_id;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_type_t expected_type = PSA_KEY_TYPE_ECC_KEY_PAIR( psa_curve_arg );
size_t expected_bits = expected_bits_arg;
Expand Down Expand Up @@ -1252,10 +1252,10 @@ void pk_psa_sign( int grpid_arg,
pkey_legacy_start = pkey_legacy + sizeof( pkey_legacy ) - klen_legacy;

/* Turn PK context into an opaque one. */
TEST_ASSERT( mbedtls_pk_wrap_as_opaque( &pk, &handle,
TEST_ASSERT( mbedtls_pk_wrap_as_opaque( &pk, &key_id,
PSA_ALG_SHA_256 ) == 0 );

PSA_ASSERT( psa_get_key_attributes( handle, &attributes ) );
PSA_ASSERT( psa_get_key_attributes( key_id, &attributes ) );
TEST_EQUAL( psa_get_key_type( &attributes ), expected_type );
TEST_EQUAL( psa_get_key_bits( &attributes ), expected_bits );
TEST_EQUAL( psa_get_key_lifetime( &attributes ),
Expand All @@ -1280,7 +1280,7 @@ void pk_psa_sign( int grpid_arg,
TEST_ASSERT( memcmp( pkey_psa_start, pkey_legacy_start, klen_psa ) == 0 );

mbedtls_pk_free( &pk );
TEST_ASSERT( PSA_SUCCESS == psa_destroy_key( handle ) );
TEST_ASSERT( PSA_SUCCESS == psa_destroy_key( key_id ) );

mbedtls_pk_init( &pk );
TEST_ASSERT( mbedtls_pk_parse_public_key( &pk, pkey_legacy_start,
Expand Down
Loading

0 comments on commit 9b6be96

Please sign in to comment.