mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-30 09:54:14 +01:00
crypto_se_driver: add verification mock test
This commit is contained in:
parent
b7656a8a85
commit
f740b0abbb
@ -33,3 +33,9 @@ mock_sign:PSA_SUCCESS:PSA_SUCCESS
|
|||||||
|
|
||||||
SE signing mock test: sign failed
|
SE signing mock test: sign failed
|
||||||
mock_sign:PSA_ERROR_HARDWARE_FAILURE:PSA_ERROR_HARDWARE_FAILURE
|
mock_sign:PSA_ERROR_HARDWARE_FAILURE:PSA_ERROR_HARDWARE_FAILURE
|
||||||
|
|
||||||
|
SE verification mock test
|
||||||
|
mock_verify:PSA_SUCCESS:PSA_SUCCESS
|
||||||
|
|
||||||
|
SE verification mock test: verify failed
|
||||||
|
mock_verify:PSA_ERROR_HARDWARE_FAILURE:PSA_ERROR_HARDWARE_FAILURE
|
||||||
|
@ -48,6 +48,16 @@ static struct
|
|||||||
psa_status_t return_value;
|
psa_status_t return_value;
|
||||||
} mock_sign_data;
|
} mock_sign_data;
|
||||||
|
|
||||||
|
static struct
|
||||||
|
{
|
||||||
|
uint16_t called;
|
||||||
|
psa_key_slot_number_t key_slot;
|
||||||
|
psa_algorithm_t alg;
|
||||||
|
size_t hash_length;
|
||||||
|
size_t signature_length;
|
||||||
|
psa_status_t return_value;
|
||||||
|
} mock_verify_data;
|
||||||
|
|
||||||
static struct
|
static struct
|
||||||
{
|
{
|
||||||
uint16_t called;
|
uint16_t called;
|
||||||
@ -67,6 +77,7 @@ static void mock_teardown( void )
|
|||||||
memset( &mock_export_data, 0, sizeof( mock_export_data ) );
|
memset( &mock_export_data, 0, sizeof( mock_export_data ) );
|
||||||
memset( &mock_export_public_data, 0, sizeof( mock_export_public_data ) );
|
memset( &mock_export_public_data, 0, sizeof( mock_export_public_data ) );
|
||||||
memset( &mock_sign_data, 0, sizeof( mock_sign_data ) );
|
memset( &mock_sign_data, 0, sizeof( mock_sign_data ) );
|
||||||
|
memset( &mock_verify_data, 0, sizeof( mock_verify_data ) );
|
||||||
memset( &mock_allocate_data, 0, sizeof( mock_allocate_data ) );
|
memset( &mock_allocate_data, 0, sizeof( mock_allocate_data ) );
|
||||||
memset( &mock_destroy_data, 0, sizeof( mock_destroy_data ) );
|
memset( &mock_destroy_data, 0, sizeof( mock_destroy_data ) );
|
||||||
memset( &mock_generate_data, 0, sizeof( mock_generate_data ) );
|
memset( &mock_generate_data, 0, sizeof( mock_generate_data ) );
|
||||||
@ -167,6 +178,27 @@ psa_status_t mock_sign( psa_drv_se_context_t *context,
|
|||||||
return mock_sign_data.return_value;
|
return mock_sign_data.return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
psa_status_t mock_verify( psa_drv_se_context_t *context,
|
||||||
|
psa_key_slot_number_t key_slot,
|
||||||
|
psa_algorithm_t alg,
|
||||||
|
const uint8_t *p_hash,
|
||||||
|
size_t hash_length,
|
||||||
|
const uint8_t *p_signature,
|
||||||
|
size_t signature_length )
|
||||||
|
{
|
||||||
|
(void) context;
|
||||||
|
(void) p_hash;
|
||||||
|
(void) p_signature;
|
||||||
|
|
||||||
|
mock_verify_data.called++;
|
||||||
|
mock_verify_data.key_slot = key_slot;
|
||||||
|
mock_verify_data.alg = alg;
|
||||||
|
mock_verify_data.hash_length = hash_length;
|
||||||
|
mock_verify_data.signature_length = signature_length;
|
||||||
|
|
||||||
|
return mock_verify_data.return_value;
|
||||||
|
}
|
||||||
|
|
||||||
psa_status_t mock_allocate( psa_drv_se_context_t *drv_context,
|
psa_status_t mock_allocate( psa_drv_se_context_t *drv_context,
|
||||||
void *persistent_data,
|
void *persistent_data,
|
||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
@ -470,3 +502,57 @@ exit:
|
|||||||
mock_teardown( );
|
mock_teardown( );
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
|
/* BEGIN_CASE */
|
||||||
|
void mock_verify( int mock_verify_return_value, int expected_result )
|
||||||
|
{
|
||||||
|
psa_drv_se_t driver;
|
||||||
|
psa_drv_se_key_management_t key_management;
|
||||||
|
psa_drv_se_asymmetric_t asymmetric;
|
||||||
|
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;
|
||||||
|
const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
|
||||||
|
psa_algorithm_t algorithm = PSA_ALG_ECDSA(PSA_ALG_SHA_256);
|
||||||
|
|
||||||
|
mock_verify_data.return_value = mock_verify_return_value;
|
||||||
|
memset( &driver, 0, sizeof( driver ) );
|
||||||
|
memset( &key_management, 0, sizeof( key_management ) );
|
||||||
|
memset( &asymmetric, 0, sizeof( asymmetric ) );
|
||||||
|
|
||||||
|
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
|
||||||
|
|
||||||
|
driver.key_management = &key_management;
|
||||||
|
key_management.p_import = mock_import;
|
||||||
|
key_management.p_destroy = mock_destroy;
|
||||||
|
key_management.p_allocate = mock_allocate;
|
||||||
|
|
||||||
|
driver.asymmetric = &asymmetric;
|
||||||
|
asymmetric.p_verify = mock_verify;
|
||||||
|
|
||||||
|
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_VERIFY );
|
||||||
|
psa_set_key_algorithm( &attributes, algorithm );
|
||||||
|
psa_set_key_type( &attributes, PSA_KEY_TYPE_RAW_DATA );
|
||||||
|
|
||||||
|
PSA_ASSERT( psa_import_key( &attributes,
|
||||||
|
key_material, sizeof( key_material ),
|
||||||
|
&handle ) );
|
||||||
|
|
||||||
|
TEST_ASSERT( psa_asymmetric_verify( handle, algorithm, NULL, 0, NULL, 0)
|
||||||
|
== expected_result );
|
||||||
|
TEST_ASSERT( mock_verify_data.called == 1 );
|
||||||
|
|
||||||
|
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