crypto_se_driver: add key generation mock and test
This commit is contained in:
parent
c9ad5910aa
commit
9fd6b0cb6f
@ -3,3 +3,6 @@ mock_import:
|
||||
|
||||
SE key exporting mock test
|
||||
mock_export:
|
||||
|
||||
SE key generating mock test
|
||||
mock_generate:
|
||||
|
@ -4,6 +4,14 @@
|
||||
|
||||
#include "psa_crypto_se.h"
|
||||
|
||||
static struct
|
||||
{
|
||||
uint16_t called;
|
||||
psa_key_slot_number_t key_slot;
|
||||
psa_key_attributes_t attributes;
|
||||
size_t pubkey_size;
|
||||
} mock_generate_data;
|
||||
|
||||
static struct
|
||||
{
|
||||
uint16_t called;
|
||||
@ -36,6 +44,26 @@ static void mock_teardown( void )
|
||||
memset( &mock_export_data, 0, sizeof( mock_export_data ) );
|
||||
memset( &mock_allocate_data, 0, sizeof( mock_allocate_data ) );
|
||||
memset( &mock_destroy_data, 0, sizeof( mock_destroy_data ) );
|
||||
memset( &mock_generate_data, 0, sizeof( mock_generate_data ) );
|
||||
}
|
||||
|
||||
static psa_status_t mock_generate( psa_drv_se_context_t *drv_context,
|
||||
psa_key_slot_number_t key_slot,
|
||||
const psa_key_attributes_t *attributes,
|
||||
uint8_t *pubkey,
|
||||
size_t pubkey_size,
|
||||
size_t *pubkey_length )
|
||||
{
|
||||
(void) drv_context;
|
||||
(void) pubkey;
|
||||
(void) pubkey_length;
|
||||
|
||||
mock_generate_data.called++;
|
||||
mock_generate_data.key_slot = key_slot;
|
||||
mock_generate_data.attributes = *attributes;
|
||||
mock_generate_data.pubkey_size = pubkey_size;
|
||||
|
||||
return( PSA_SUCCESS );
|
||||
}
|
||||
|
||||
static psa_status_t mock_import( psa_drv_se_context_t *drv_context,
|
||||
@ -204,3 +232,44 @@ exit:
|
||||
mock_teardown( );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mock_generate( )
|
||||
{
|
||||
psa_drv_se_t driver;
|
||||
psa_drv_se_key_management_t key_management;
|
||||
psa_key_lifetime_t lifetime = 2;
|
||||
psa_key_id_t id = 1;
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
|
||||
memset( &driver, 0, sizeof( driver ) );
|
||||
memset( &key_management, 0, sizeof( key_management ) );
|
||||
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
|
||||
driver.key_management = &key_management;
|
||||
key_management.p_generate = mock_generate;
|
||||
key_management.p_destroy = mock_destroy;
|
||||
key_management.p_allocate = mock_allocate;
|
||||
|
||||
PSA_ASSERT( psa_register_se_driver( lifetime, &driver ) );
|
||||
PSA_ASSERT( psa_crypto_init( ) );
|
||||
|
||||
psa_set_key_id( &attributes, id );
|
||||
psa_set_key_lifetime( &attributes, lifetime );
|
||||
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT );
|
||||
psa_set_key_type( &attributes, PSA_KEY_TYPE_RAW_DATA );
|
||||
PSA_ASSERT( psa_generate_key( &attributes, &handle ) );
|
||||
TEST_ASSERT( mock_allocate_data.called == 1 );
|
||||
TEST_ASSERT( mock_generate_data.called == 1 );
|
||||
|
||||
if( expected_result == PSA_SUCCESS )
|
||||
{
|
||||
PSA_ASSERT( psa_destroy_key( handle ) );
|
||||
TEST_ASSERT( mock_destroy_data.called == 1 );
|
||||
}
|
||||
|
||||
exit:
|
||||
PSA_DONE( );
|
||||
mock_teardown( );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
Loading…
Reference in New Issue
Block a user