Apply mbedtls namespacing to MAC driver test hooks

Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
This commit is contained in:
Steven Cooreman 2021-05-10 11:18:20 +02:00
parent d1a68f10c0
commit ae3ec52d8d
3 changed files with 111 additions and 109 deletions

View file

@ -37,16 +37,17 @@ typedef struct {
unsigned long hits;
/* Status returned by the last MAC driver function call. */
psa_status_t driver_status;
} test_driver_mac_hooks_t;
} mbedtls_test_driver_mac_hooks_t;
#define MBEDTLS_TEST_DRIVER_MAC_INIT { 0, 0, 0 }
static inline test_driver_mac_hooks_t test_driver_mac_hooks_init( void )
static inline mbedtls_test_driver_mac_hooks_t
mbedtls_test_driver_mac_hooks_init( void )
{
const test_driver_mac_hooks_t v = MBEDTLS_TEST_DRIVER_MAC_INIT;
const mbedtls_test_driver_mac_hooks_t v = MBEDTLS_TEST_DRIVER_MAC_INIT;
return( v );
}
extern test_driver_mac_hooks_t test_driver_mac_hooks;
extern mbedtls_test_driver_mac_hooks_t mbedtls_test_driver_mac_hooks;
psa_status_t mbedtls_test_transparent_mac_compute(
const psa_key_attributes_t *attributes,

View file

@ -28,7 +28,8 @@
#include "test/drivers/mac.h"
test_driver_mac_hooks_t test_driver_mac_hooks = MBEDTLS_TEST_DRIVER_MAC_INIT;
mbedtls_test_driver_mac_hooks_t mbedtls_test_driver_mac_hooks =
MBEDTLS_TEST_DRIVER_MAC_INIT;
psa_status_t mbedtls_test_transparent_mac_compute(
const psa_key_attributes_t *attributes,
@ -41,23 +42,23 @@ psa_status_t mbedtls_test_transparent_mac_compute(
size_t mac_size,
size_t *mac_length )
{
test_driver_mac_hooks.hits++;
mbedtls_test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_transparent_test_driver_mac_compute(
attributes, key_buffer, key_buffer_size, alg,
input, input_length,
mac, mac_size, mac_length );
}
return( test_driver_mac_hooks.driver_status );
return( mbedtls_test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_transparent_mac_sign_setup(
@ -67,21 +68,21 @@ psa_status_t mbedtls_test_transparent_mac_sign_setup(
size_t key_buffer_size,
psa_algorithm_t alg )
{
test_driver_mac_hooks.hits++;
mbedtls_test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_transparent_test_driver_mac_sign_setup(
operation, attributes, key_buffer, key_buffer_size, alg );
}
return( test_driver_mac_hooks.driver_status );
return( mbedtls_test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_transparent_mac_verify_setup(
@ -91,21 +92,21 @@ psa_status_t mbedtls_test_transparent_mac_verify_setup(
size_t key_buffer_size,
psa_algorithm_t alg )
{
test_driver_mac_hooks.hits++;
mbedtls_test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_transparent_test_driver_mac_verify_setup(
operation, attributes, key_buffer, key_buffer_size, alg );
}
return( test_driver_mac_hooks.driver_status );
return( mbedtls_test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_transparent_mac_update(
@ -113,21 +114,21 @@ psa_status_t mbedtls_test_transparent_mac_update(
const uint8_t *input,
size_t input_length )
{
test_driver_mac_hooks.hits++;
mbedtls_test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_transparent_test_driver_mac_update(
operation, input, input_length );
}
return( test_driver_mac_hooks.driver_status );
return( mbedtls_test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_transparent_mac_sign_finish(
@ -136,21 +137,21 @@ psa_status_t mbedtls_test_transparent_mac_sign_finish(
size_t mac_size,
size_t *mac_length )
{
test_driver_mac_hooks.hits++;
mbedtls_test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_transparent_test_driver_mac_sign_finish(
operation, mac, mac_size, mac_length );
}
return( test_driver_mac_hooks.driver_status );
return( mbedtls_test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_transparent_mac_verify_finish(
@ -158,40 +159,40 @@ psa_status_t mbedtls_test_transparent_mac_verify_finish(
const uint8_t *mac,
size_t mac_length )
{
test_driver_mac_hooks.hits++;
mbedtls_test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_transparent_test_driver_mac_verify_finish(
operation, mac, mac_length );
}
return( test_driver_mac_hooks.driver_status );
return( mbedtls_test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_transparent_mac_abort(
mbedtls_transparent_test_driver_mac_operation_t *operation )
{
test_driver_mac_hooks.hits++;
mbedtls_test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_transparent_test_driver_mac_abort( operation );
}
return( test_driver_mac_hooks.driver_status );
return( mbedtls_test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_opaque_mac_compute(
@ -205,23 +206,23 @@ psa_status_t mbedtls_test_opaque_mac_compute(
size_t mac_size,
size_t *mac_length )
{
test_driver_mac_hooks.hits++;
mbedtls_test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_opaque_test_driver_mac_compute(
attributes, key_buffer, key_buffer_size, alg,
input, input_length,
mac, mac_size, mac_length );
}
return( test_driver_mac_hooks.driver_status );
return( mbedtls_test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_opaque_mac_sign_setup(
@ -231,21 +232,21 @@ psa_status_t mbedtls_test_opaque_mac_sign_setup(
size_t key_buffer_size,
psa_algorithm_t alg )
{
test_driver_mac_hooks.hits++;
mbedtls_test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_opaque_test_driver_mac_sign_setup(
operation, attributes, key_buffer, key_buffer_size, alg );
}
return( test_driver_mac_hooks.driver_status );
return( mbedtls_test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_opaque_mac_verify_setup(
@ -255,21 +256,21 @@ psa_status_t mbedtls_test_opaque_mac_verify_setup(
size_t key_buffer_size,
psa_algorithm_t alg )
{
test_driver_mac_hooks.hits++;
mbedtls_test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_opaque_test_driver_mac_verify_setup(
operation, attributes, key_buffer, key_buffer_size, alg );
}
return( test_driver_mac_hooks.driver_status );
return( mbedtls_test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_opaque_mac_update(
@ -277,21 +278,21 @@ psa_status_t mbedtls_test_opaque_mac_update(
const uint8_t *input,
size_t input_length )
{
test_driver_mac_hooks.hits++;
mbedtls_test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_opaque_test_driver_mac_update(
operation, input, input_length );
}
return( test_driver_mac_hooks.driver_status );
return( mbedtls_test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_opaque_mac_sign_finish(
@ -300,21 +301,21 @@ psa_status_t mbedtls_test_opaque_mac_sign_finish(
size_t mac_size,
size_t *mac_length )
{
test_driver_mac_hooks.hits++;
mbedtls_test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_opaque_test_driver_mac_sign_finish(
operation, mac, mac_size, mac_length );
}
return( test_driver_mac_hooks.driver_status );
return( mbedtls_test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_opaque_mac_verify_finish(
@ -322,40 +323,40 @@ psa_status_t mbedtls_test_opaque_mac_verify_finish(
const uint8_t *mac,
size_t mac_length )
{
test_driver_mac_hooks.hits++;
mbedtls_test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_opaque_test_driver_mac_verify_finish(
operation, mac, mac_length );
}
return( test_driver_mac_hooks.driver_status );
return( mbedtls_test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_opaque_mac_abort(
mbedtls_opaque_test_driver_mac_operation_t *operation )
{
test_driver_mac_hooks.hits++;
mbedtls_test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_test_driver_mac_hooks.driver_status =
mbedtls_opaque_test_driver_mac_abort( operation );
}
return( test_driver_mac_hooks.driver_status );
return( mbedtls_test_driver_mac_hooks.driver_status );
}
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */

View file

@ -982,7 +982,7 @@ void mac_sign( int key_type_arg,
size_t mac_length = 0;
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
psa_status_t forced_status = forced_status_arg;
test_driver_mac_hooks = test_driver_mac_hooks_init();
mbedtls_test_driver_mac_hooks = mbedtls_test_driver_mac_hooks_init();
TEST_ASSERT( mac_buffer_size <= PSA_MAC_MAX_SIZE );
/* We expect PSA_MAC_LENGTH to be exact. */
@ -998,11 +998,11 @@ void mac_sign( int key_type_arg,
&key ) );
ASSERT_ALLOC( actual_mac, mac_buffer_size );
test_driver_mac_hooks.forced_status = forced_status;
mbedtls_test_driver_mac_hooks.forced_status = forced_status;
/* Calculate the MAC. */
status = psa_mac_sign_setup( &operation, key, alg );
TEST_EQUAL( test_driver_mac_hooks.hits, 1 );
TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 1 );
if( forced_status == PSA_SUCCESS ||
forced_status == PSA_ERROR_NOT_SUPPORTED )
@ -1015,9 +1015,9 @@ void mac_sign( int key_type_arg,
status = psa_mac_update( &operation,
input->x, input->len );
if( forced_status == PSA_SUCCESS )
TEST_EQUAL( test_driver_mac_hooks.hits, 2 );
TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 2 );
else
TEST_EQUAL( test_driver_mac_hooks.hits, 1 );
TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 1 );
if( forced_status == PSA_SUCCESS ||
forced_status == PSA_ERROR_NOT_SUPPORTED )
{
@ -1030,9 +1030,9 @@ void mac_sign( int key_type_arg,
actual_mac, mac_buffer_size,
&mac_length );
if( forced_status == PSA_SUCCESS )
TEST_EQUAL( test_driver_mac_hooks.hits, 4 );
TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 4 );
else
TEST_EQUAL( test_driver_mac_hooks.hits, 1 );
TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 1 );
if( forced_status == PSA_SUCCESS ||
forced_status == PSA_ERROR_NOT_SUPPORTED )
@ -1044,9 +1044,9 @@ void mac_sign( int key_type_arg,
PSA_ASSERT( psa_mac_abort( &operation ) );
if( forced_status == PSA_SUCCESS )
TEST_EQUAL( test_driver_mac_hooks.hits, 4 );
TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 4 );
else
TEST_EQUAL( test_driver_mac_hooks.hits, 1 );
TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 1 );
if( forced_status == PSA_SUCCESS )
{
@ -1062,7 +1062,7 @@ exit:
psa_destroy_key( key );
PSA_DONE( );
mbedtls_free( actual_mac );
test_driver_mac_hooks = test_driver_mac_hooks_init();
mbedtls_test_driver_mac_hooks = mbedtls_test_driver_mac_hooks_init();
}
/* END_CASE */
@ -1081,7 +1081,7 @@ void mac_verify( int key_type_arg,
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
psa_status_t forced_status = forced_status_arg;
test_driver_mac_hooks = test_driver_mac_hooks_init();
mbedtls_test_driver_mac_hooks = mbedtls_test_driver_mac_hooks_init();
TEST_ASSERT( expected_mac->len <= PSA_MAC_MAX_SIZE );
@ -1094,11 +1094,11 @@ void mac_verify( int key_type_arg,
PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
&key ) );
test_driver_mac_hooks.forced_status = forced_status;
mbedtls_test_driver_mac_hooks.forced_status = forced_status;
/* Test the correct MAC. */
status = psa_mac_verify_setup( &operation, key, alg );
TEST_EQUAL( test_driver_mac_hooks.hits, 1 );
TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 1 );
if( forced_status == PSA_SUCCESS ||
forced_status == PSA_ERROR_NOT_SUPPORTED )
@ -1111,9 +1111,9 @@ void mac_verify( int key_type_arg,
status = psa_mac_update( &operation,
input->x, input->len );
if( forced_status == PSA_SUCCESS )
TEST_EQUAL( test_driver_mac_hooks.hits, 2 );
TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 2 );
else
TEST_EQUAL( test_driver_mac_hooks.hits, 1 );
TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 1 );
if( forced_status == PSA_SUCCESS ||
forced_status == PSA_ERROR_NOT_SUPPORTED )
@ -1127,9 +1127,9 @@ void mac_verify( int key_type_arg,
expected_mac->x,
expected_mac->len );
if( forced_status == PSA_SUCCESS )
TEST_EQUAL( test_driver_mac_hooks.hits, 4 );
TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 4 );
else
TEST_EQUAL( test_driver_mac_hooks.hits, 1 );
TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 1 );
if( forced_status == PSA_SUCCESS ||
forced_status == PSA_ERROR_NOT_SUPPORTED )
@ -1142,15 +1142,15 @@ void mac_verify( int key_type_arg,
PSA_ASSERT( psa_mac_abort( &operation ) );
if( forced_status == PSA_SUCCESS )
TEST_EQUAL( test_driver_mac_hooks.hits, 4 );
TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 4 );
else
TEST_EQUAL( test_driver_mac_hooks.hits, 1 );
TEST_EQUAL( mbedtls_test_driver_mac_hooks.hits, 1 );
exit:
psa_mac_abort( &operation );
psa_destroy_key( key );
PSA_DONE( );
test_driver_mac_hooks = test_driver_mac_hooks_init();
mbedtls_test_driver_mac_hooks = mbedtls_test_driver_mac_hooks_init();
}
/* END_CASE */