tests: psa: Add mbedtls/MBEDTLS prefix to test driver symbols

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
Ronald Cron 2021-04-13 12:41:34 +02:00
parent b5d59a05b2
commit 7f13fa2454
18 changed files with 623 additions and 578 deletions

View file

@ -37,7 +37,7 @@
#ifndef PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT #ifndef PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT
#define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT #define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT
#endif #endif
#include "test/drivers/test_driver.h" #include "test/drivers/mbedtls_test_driver.h"
#endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_DRIVER_TEST */
/* Repeat above block for each JSON-declared driver during autogeneration */ /* Repeat above block for each JSON-declared driver during autogeneration */
@ -101,7 +101,7 @@ psa_status_t psa_driver_wrapper_sign_hash(
* cycle through all known transparent accelerators */ * cycle through all known transparent accelerators */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
status = test_transparent_signature_sign_hash( attributes, status = mbedtls_test_transparent_signature_sign_hash( attributes,
key_buffer, key_buffer,
key_buffer_size, key_buffer_size,
alg, alg,
@ -130,7 +130,7 @@ psa_status_t psa_driver_wrapper_sign_hash(
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TEST_DRIVER_LOCATION: case PSA_CRYPTO_TEST_DRIVER_LOCATION:
return( test_opaque_signature_sign_hash( attributes, return( mbedtls_test_opaque_signature_sign_hash( attributes,
key_buffer, key_buffer,
key_buffer_size, key_buffer_size,
alg, alg,
@ -185,7 +185,8 @@ psa_status_t psa_driver_wrapper_verify_hash(
* cycle through all known transparent accelerators */ * cycle through all known transparent accelerators */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
status = test_transparent_signature_verify_hash( attributes, status = mbedtls_test_transparent_signature_verify_hash(
attributes,
key_buffer, key_buffer,
key_buffer_size, key_buffer_size,
alg, alg,
@ -212,7 +213,7 @@ psa_status_t psa_driver_wrapper_verify_hash(
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TEST_DRIVER_LOCATION: case PSA_CRYPTO_TEST_DRIVER_LOCATION:
return( test_opaque_signature_verify_hash( attributes, return( mbedtls_test_opaque_signature_verify_hash( attributes,
key_buffer, key_buffer,
key_buffer_size, key_buffer_size,
alg, alg,
@ -267,37 +268,37 @@ psa_status_t psa_driver_wrapper_get_key_buffer_size(
return( PSA_SUCCESS ); return( PSA_SUCCESS );
} }
#endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */ #endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */
#ifdef TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION #ifdef MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION
*key_buffer_size = test_size_function( key_type, key_bits ); *key_buffer_size = mbedtls_test_size_function( key_type, key_bits );
return( PSA_SUCCESS ); return( PSA_SUCCESS );
#else /* TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION */ #else /* MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION */
if( PSA_KEY_TYPE_IS_KEY_PAIR( key_type ) ) if( PSA_KEY_TYPE_IS_KEY_PAIR( key_type ) )
{ {
int public_key_overhead = int public_key_overhead =
( ( TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY == 1 ) ? ( ( MBEDTLS_TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY == 1 )
PSA_EXPORT_KEY_OUTPUT_SIZE( key_type, key_bits ) : 0 ); ? PSA_EXPORT_KEY_OUTPUT_SIZE( key_type, key_bits ) : 0 );
*key_buffer_size = TEST_DRIVER_KEY_CONTEXT_BASE_SIZE *key_buffer_size = MBEDTLS_TEST_DRIVER_KEY_CONTEXT_BASE_SIZE +
+ TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE MBEDTLS_TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE +
+ public_key_overhead; public_key_overhead;
} }
else if( PSA_KEY_TYPE_IS_PUBLIC_KEY( key_type ) ) else if( PSA_KEY_TYPE_IS_PUBLIC_KEY( key_type ) )
{ {
*key_buffer_size = TEST_DRIVER_KEY_CONTEXT_BASE_SIZE *key_buffer_size = MBEDTLS_TEST_DRIVER_KEY_CONTEXT_BASE_SIZE +
+ TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE; MBEDTLS_TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE;
} }
else if ( !PSA_KEY_TYPE_IS_KEY_PAIR( key_type ) && else if ( !PSA_KEY_TYPE_IS_KEY_PAIR( key_type ) &&
!PSA_KEY_TYPE_IS_PUBLIC_KEY ( key_type ) ) !PSA_KEY_TYPE_IS_PUBLIC_KEY ( key_type ) )
{ {
*key_buffer_size = TEST_DRIVER_KEY_CONTEXT_BASE_SIZE *key_buffer_size = MBEDTLS_TEST_DRIVER_KEY_CONTEXT_BASE_SIZE +
+ TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR ( MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR *
* ( ( key_bits + 7 ) / 8 ); ( ( key_bits + 7 ) / 8 ) );
} }
else else
{ {
return( PSA_ERROR_NOT_SUPPORTED ); return( PSA_ERROR_NOT_SUPPORTED );
} }
return( PSA_SUCCESS ); return( PSA_SUCCESS );
#endif /* TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION */ #endif /* MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION */
#endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_DRIVER_TEST */
default: default:
@ -345,7 +346,7 @@ psa_status_t psa_driver_wrapper_generate_key(
{ {
/* Cycle through all known transparent accelerators */ /* Cycle through all known transparent accelerators */
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
status = test_transparent_generate_key( status = mbedtls_test_transparent_generate_key(
attributes, key_buffer, key_buffer_size, attributes, key_buffer, key_buffer_size,
key_buffer_length ); key_buffer_length );
/* Declared with fallback == true */ /* Declared with fallback == true */
@ -364,7 +365,7 @@ psa_status_t psa_driver_wrapper_generate_key(
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TEST_DRIVER_LOCATION: case PSA_CRYPTO_TEST_DRIVER_LOCATION:
status = test_opaque_generate_key( status = mbedtls_test_opaque_generate_key(
attributes, key_buffer, key_buffer_size, key_buffer_length ); attributes, key_buffer, key_buffer_size, key_buffer_length );
break; break;
#endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_DRIVER_TEST */
@ -428,7 +429,8 @@ psa_status_t psa_driver_wrapper_import_key(
* cycle through all known transparent accelerators */ * cycle through all known transparent accelerators */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
status = test_transparent_import_key( attributes, status = mbedtls_test_transparent_import_key(
attributes,
data, data_length, data, data_length,
key_buffer, key_buffer_size, key_buffer, key_buffer_size,
key_buffer_length, bits ); key_buffer_length, bits );
@ -496,7 +498,7 @@ psa_status_t psa_driver_wrapper_export_key(
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TEST_DRIVER_LOCATION: case PSA_CRYPTO_TEST_DRIVER_LOCATION:
return( test_opaque_export_key( attributes, return( mbedtls_test_opaque_export_key( attributes,
key_buffer, key_buffer,
key_buffer_size, key_buffer_size,
data, data,
@ -547,7 +549,8 @@ psa_status_t psa_driver_wrapper_export_public_key(
* cycle through all known transparent accelerators */ * cycle through all known transparent accelerators */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
status = test_transparent_export_public_key( attributes, status = mbedtls_test_transparent_export_public_key(
attributes,
key_buffer, key_buffer,
key_buffer_size, key_buffer_size,
data, data,
@ -570,7 +573,7 @@ psa_status_t psa_driver_wrapper_export_public_key(
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TEST_DRIVER_LOCATION: case PSA_CRYPTO_TEST_DRIVER_LOCATION:
return( test_opaque_export_public_key( attributes, return( mbedtls_test_opaque_export_public_key( attributes,
key_buffer, key_buffer,
key_buffer_size, key_buffer_size,
data, data,
@ -594,7 +597,7 @@ psa_status_t psa_driver_wrapper_get_builtin_key(
{ {
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TEST_DRIVER_LOCATION: case PSA_CRYPTO_TEST_DRIVER_LOCATION:
return( test_opaque_get_builtin_key( return( mbedtls_test_opaque_get_builtin_key(
slot_number, slot_number,
attributes, attributes,
key_buffer, key_buffer_size, key_buffer_length ) ); key_buffer, key_buffer_size, key_buffer_length ) );
@ -633,7 +636,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt(
/* Key is stored in the slot in export representation, so /* Key is stored in the slot in export representation, so
* cycle through all known transparent accelerators */ * cycle through all known transparent accelerators */
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
status = test_transparent_cipher_encrypt( &attributes, status = mbedtls_test_transparent_cipher_encrypt( &attributes,
slot->key.data, slot->key.data,
slot->key.bytes, slot->key.bytes,
alg, alg,
@ -651,7 +654,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt(
/* Add cases for opaque driver here */ /* Add cases for opaque driver here */
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TEST_DRIVER_LOCATION: case PSA_CRYPTO_TEST_DRIVER_LOCATION:
return( test_opaque_cipher_encrypt( &attributes, return( mbedtls_test_opaque_cipher_encrypt( &attributes,
slot->key.data, slot->key.data,
slot->key.bytes, slot->key.bytes,
alg, alg,
@ -700,7 +703,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt(
/* Key is stored in the slot in export representation, so /* Key is stored in the slot in export representation, so
* cycle through all known transparent accelerators */ * cycle through all known transparent accelerators */
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
status = test_transparent_cipher_decrypt( &attributes, status = mbedtls_test_transparent_cipher_decrypt( &attributes,
slot->key.data, slot->key.data,
slot->key.bytes, slot->key.bytes,
alg, alg,
@ -718,7 +721,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt(
/* Add cases for opaque driver here */ /* Add cases for opaque driver here */
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TEST_DRIVER_LOCATION: case PSA_CRYPTO_TEST_DRIVER_LOCATION:
return( test_opaque_cipher_decrypt( &attributes, return( mbedtls_test_opaque_cipher_decrypt( &attributes,
slot->key.data, slot->key.data,
slot->key.bytes, slot->key.bytes,
alg, alg,
@ -762,7 +765,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt_setup(
* cycle through all known transparent accelerators */ * cycle through all known transparent accelerators */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
status = test_transparent_cipher_encrypt_setup( status = mbedtls_test_transparent_cipher_encrypt_setup(
&operation->ctx.transparent_test_driver_ctx, &operation->ctx.transparent_test_driver_ctx,
attributes, attributes,
key_buffer, key_buffer,
@ -795,7 +798,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt_setup(
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TEST_DRIVER_LOCATION: case PSA_CRYPTO_TEST_DRIVER_LOCATION:
status = test_opaque_cipher_encrypt_setup( status = mbedtls_test_opaque_cipher_encrypt_setup(
&operation->ctx.opaque_test_driver_ctx, &operation->ctx.opaque_test_driver_ctx,
attributes, attributes,
key_buffer, key_buffer_size, key_buffer, key_buffer_size,
@ -834,7 +837,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt_setup(
* cycle through all known transparent accelerators */ * cycle through all known transparent accelerators */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
status = test_transparent_cipher_decrypt_setup( status = mbedtls_test_transparent_cipher_decrypt_setup(
&operation->ctx.transparent_test_driver_ctx, &operation->ctx.transparent_test_driver_ctx,
attributes, attributes,
key_buffer, key_buffer,
@ -866,7 +869,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt_setup(
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TEST_DRIVER_LOCATION: case PSA_CRYPTO_TEST_DRIVER_LOCATION:
status = test_opaque_cipher_decrypt_setup( status = mbedtls_test_opaque_cipher_decrypt_setup(
&operation->ctx.opaque_test_driver_ctx, &operation->ctx.opaque_test_driver_ctx,
attributes, attributes,
key_buffer, key_buffer_size, key_buffer, key_buffer_size,
@ -905,12 +908,12 @@ psa_status_t psa_driver_wrapper_cipher_set_iv(
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
return( test_transparent_cipher_set_iv( return( mbedtls_test_transparent_cipher_set_iv(
&operation->ctx.transparent_test_driver_ctx, &operation->ctx.transparent_test_driver_ctx,
iv, iv_length ) ); iv, iv_length ) );
case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
return( test_opaque_cipher_set_iv( return( mbedtls_test_opaque_cipher_set_iv(
&operation->ctx.opaque_test_driver_ctx, &operation->ctx.opaque_test_driver_ctx,
iv, iv_length ) ); iv, iv_length ) );
#endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_DRIVER_TEST */
@ -946,13 +949,13 @@ psa_status_t psa_driver_wrapper_cipher_update(
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
return( test_transparent_cipher_update( return( mbedtls_test_transparent_cipher_update(
&operation->ctx.transparent_test_driver_ctx, &operation->ctx.transparent_test_driver_ctx,
input, input_length, input, input_length,
output, output_size, output_length ) ); output, output_size, output_length ) );
case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
return( test_opaque_cipher_update( return( mbedtls_test_opaque_cipher_update(
&operation->ctx.opaque_test_driver_ctx, &operation->ctx.opaque_test_driver_ctx,
input, input_length, input, input_length,
output, output_size, output_length ) ); output, output_size, output_length ) );
@ -988,12 +991,12 @@ psa_status_t psa_driver_wrapper_cipher_finish(
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
return( test_transparent_cipher_finish( return( mbedtls_test_transparent_cipher_finish(
&operation->ctx.transparent_test_driver_ctx, &operation->ctx.transparent_test_driver_ctx,
output, output_size, output_length ) ); output, output_size, output_length ) );
case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
return( test_opaque_cipher_finish( return( mbedtls_test_opaque_cipher_finish(
&operation->ctx.opaque_test_driver_ctx, &operation->ctx.opaque_test_driver_ctx,
output, output_size, output_length ) ); output, output_size, output_length ) );
#endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_DRIVER_TEST */
@ -1022,7 +1025,7 @@ psa_status_t psa_driver_wrapper_cipher_abort(
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
status = test_transparent_cipher_abort( status = mbedtls_test_transparent_cipher_abort(
&operation->ctx.transparent_test_driver_ctx ); &operation->ctx.transparent_test_driver_ctx );
mbedtls_platform_zeroize( mbedtls_platform_zeroize(
&operation->ctx.transparent_test_driver_ctx, &operation->ctx.transparent_test_driver_ctx,
@ -1030,7 +1033,7 @@ psa_status_t psa_driver_wrapper_cipher_abort(
return( status ); return( status );
case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
status = test_opaque_cipher_abort( status = mbedtls_test_opaque_cipher_abort(
&operation->ctx.opaque_test_driver_ctx ); &operation->ctx.opaque_test_driver_ctx );
mbedtls_platform_zeroize( mbedtls_platform_zeroize(
&operation->ctx.opaque_test_driver_ctx, &operation->ctx.opaque_test_driver_ctx,
@ -1059,7 +1062,7 @@ psa_status_t psa_driver_wrapper_hash_compute(
/* Try accelerators first */ /* Try accelerators first */
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
status = test_transparent_hash_compute( status = mbedtls_test_transparent_hash_compute(
alg, input, input_length, hash, hash_size, hash_length ); alg, input, input_length, hash, hash_size, hash_length );
if( status != PSA_ERROR_NOT_SUPPORTED ) if( status != PSA_ERROR_NOT_SUPPORTED )
return( status ); return( status );
@ -1091,7 +1094,7 @@ psa_status_t psa_driver_wrapper_hash_setup(
/* Try setup on accelerators first */ /* Try setup on accelerators first */
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
status = test_transparent_hash_setup( status = mbedtls_test_transparent_hash_setup(
&operation->ctx.test_driver_ctx, alg ); &operation->ctx.test_driver_ctx, alg );
if( status == PSA_SUCCESS ) if( status == PSA_SUCCESS )
operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
@ -1131,7 +1134,7 @@ psa_status_t psa_driver_wrapper_hash_clone(
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
target_operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; target_operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
return( test_transparent_hash_clone( return( mbedtls_test_transparent_hash_clone(
&source_operation->ctx.test_driver_ctx, &source_operation->ctx.test_driver_ctx,
&target_operation->ctx.test_driver_ctx ) ); &target_operation->ctx.test_driver_ctx ) );
#endif #endif
@ -1155,7 +1158,7 @@ psa_status_t psa_driver_wrapper_hash_update(
#endif #endif
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
return( test_transparent_hash_update( return( mbedtls_test_transparent_hash_update(
&operation->ctx.test_driver_ctx, &operation->ctx.test_driver_ctx,
input, input_length ) ); input, input_length ) );
#endif #endif
@ -1181,7 +1184,7 @@ psa_status_t psa_driver_wrapper_hash_finish(
#endif #endif
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
return( test_transparent_hash_finish( return( mbedtls_test_transparent_hash_finish(
&operation->ctx.test_driver_ctx, &operation->ctx.test_driver_ctx,
hash, hash_size, hash_length ) ); hash, hash_size, hash_length ) );
#endif #endif
@ -1204,7 +1207,7 @@ psa_status_t psa_driver_wrapper_hash_abort(
#endif #endif
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
return( test_transparent_hash_abort( return( mbedtls_test_transparent_hash_abort(
&operation->ctx.test_driver_ctx ) ); &operation->ctx.test_driver_ctx ) );
#endif #endif
default: default:
@ -1233,7 +1236,7 @@ psa_status_t psa_driver_wrapper_aead_encrypt(
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
status = test_transparent_aead_encrypt( status = mbedtls_test_transparent_aead_encrypt(
attributes, key_buffer, key_buffer_size, attributes, key_buffer, key_buffer_size,
alg, alg,
nonce, nonce_length, nonce, nonce_length,
@ -1285,7 +1288,7 @@ psa_status_t psa_driver_wrapper_aead_decrypt(
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
status = test_transparent_aead_decrypt( status = mbedtls_test_transparent_aead_decrypt(
attributes, key_buffer, key_buffer_size, attributes, key_buffer, key_buffer_size,
alg, alg,
nonce, nonce_length, nonce, nonce_length,

View file

@ -37,18 +37,19 @@ typedef struct {
unsigned long hits; unsigned long hits;
/* Status returned by the last AEAD driver function call. */ /* Status returned by the last AEAD driver function call. */
psa_status_t driver_status; psa_status_t driver_status;
} test_driver_aead_hooks_t; } mbedtls_test_driver_aead_hooks_t;
#define TEST_DRIVER_AEAD_INIT { 0, 0, 0 } #define MBEDTLS_TEST_DRIVER_AEAD_INIT { 0, 0, 0 }
static inline test_driver_aead_hooks_t test_driver_aead_hooks_init( void ) static inline mbedtls_test_driver_aead_hooks_t
mbedtls_test_driver_aead_hooks_init( void )
{ {
const test_driver_aead_hooks_t v = TEST_DRIVER_AEAD_INIT; const mbedtls_test_driver_aead_hooks_t v = MBEDTLS_TEST_DRIVER_AEAD_INIT;
return( v ); return( v );
} }
extern test_driver_aead_hooks_t test_driver_aead_hooks; extern mbedtls_test_driver_aead_hooks_t mbedtls_test_driver_aead_hooks;
psa_status_t test_transparent_aead_encrypt( psa_status_t mbedtls_test_transparent_aead_encrypt(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key_buffer, size_t key_buffer_size, const uint8_t *key_buffer, size_t key_buffer_size,
psa_algorithm_t alg, psa_algorithm_t alg,
@ -57,7 +58,7 @@ psa_status_t test_transparent_aead_encrypt(
const uint8_t *plaintext, size_t plaintext_length, const uint8_t *plaintext, size_t plaintext_length,
uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length ); uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length );
psa_status_t test_transparent_aead_decrypt( psa_status_t mbedtls_test_transparent_aead_decrypt(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key_buffer, size_t key_buffer_size, const uint8_t *key_buffer, size_t key_buffer_size,
psa_algorithm_t alg, psa_algorithm_t alg,

View file

@ -41,101 +41,102 @@ typedef struct {
psa_status_t forced_status; psa_status_t forced_status;
/* Count the amount of times one of the cipher driver functions is called. */ /* Count the amount of times one of the cipher driver functions is called. */
unsigned long hits; unsigned long hits;
} test_driver_cipher_hooks_t; } mbedtls_test_driver_cipher_hooks_t;
#define TEST_DRIVER_CIPHER_INIT { NULL, 0, PSA_SUCCESS, 0 } #define MBEDTLS_TEST_DRIVER_CIPHER_INIT { NULL, 0, PSA_SUCCESS, 0 }
static inline test_driver_cipher_hooks_t test_driver_cipher_hooks_init( void ) static inline mbedtls_test_driver_cipher_hooks_t
mbedtls_test_driver_cipher_hooks_init( void )
{ {
const test_driver_cipher_hooks_t v = TEST_DRIVER_CIPHER_INIT; const mbedtls_test_driver_cipher_hooks_t v = MBEDTLS_TEST_DRIVER_CIPHER_INIT;
return( v ); return( v );
} }
extern test_driver_cipher_hooks_t test_driver_cipher_hooks; extern mbedtls_test_driver_cipher_hooks_t mbedtls_test_driver_cipher_hooks;
psa_status_t test_transparent_cipher_encrypt( psa_status_t mbedtls_test_transparent_cipher_encrypt(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
psa_algorithm_t alg, psa_algorithm_t alg,
const uint8_t *input, size_t input_length, const uint8_t *input, size_t input_length,
uint8_t *output, size_t output_size, size_t *output_length); uint8_t *output, size_t output_size, size_t *output_length);
psa_status_t test_transparent_cipher_decrypt( psa_status_t mbedtls_test_transparent_cipher_decrypt(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
psa_algorithm_t alg, psa_algorithm_t alg,
const uint8_t *input, size_t input_length, const uint8_t *input, size_t input_length,
uint8_t *output, size_t output_size, size_t *output_length); uint8_t *output, size_t output_size, size_t *output_length);
psa_status_t test_transparent_cipher_encrypt_setup( psa_status_t mbedtls_test_transparent_cipher_encrypt_setup(
mbedtls_transparent_test_driver_cipher_operation_t *operation, mbedtls_transparent_test_driver_cipher_operation_t *operation,
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
psa_algorithm_t alg); psa_algorithm_t alg);
psa_status_t test_transparent_cipher_decrypt_setup( psa_status_t mbedtls_test_transparent_cipher_decrypt_setup(
mbedtls_transparent_test_driver_cipher_operation_t *operation, mbedtls_transparent_test_driver_cipher_operation_t *operation,
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
psa_algorithm_t alg); psa_algorithm_t alg);
psa_status_t test_transparent_cipher_abort( psa_status_t mbedtls_test_transparent_cipher_abort(
mbedtls_transparent_test_driver_cipher_operation_t *operation ); mbedtls_transparent_test_driver_cipher_operation_t *operation );
psa_status_t test_transparent_cipher_set_iv( psa_status_t mbedtls_test_transparent_cipher_set_iv(
mbedtls_transparent_test_driver_cipher_operation_t *operation, mbedtls_transparent_test_driver_cipher_operation_t *operation,
const uint8_t *iv, size_t iv_length); const uint8_t *iv, size_t iv_length);
psa_status_t test_transparent_cipher_update( psa_status_t mbedtls_test_transparent_cipher_update(
mbedtls_transparent_test_driver_cipher_operation_t *operation, mbedtls_transparent_test_driver_cipher_operation_t *operation,
const uint8_t *input, size_t input_length, const uint8_t *input, size_t input_length,
uint8_t *output, size_t output_size, size_t *output_length); uint8_t *output, size_t output_size, size_t *output_length);
psa_status_t test_transparent_cipher_finish( psa_status_t mbedtls_test_transparent_cipher_finish(
mbedtls_transparent_test_driver_cipher_operation_t *operation, mbedtls_transparent_test_driver_cipher_operation_t *operation,
uint8_t *output, size_t output_size, size_t *output_length); uint8_t *output, size_t output_size, size_t *output_length);
/* /*
* opaque versions * opaque versions
*/ */
psa_status_t test_opaque_cipher_encrypt( psa_status_t mbedtls_test_opaque_cipher_encrypt(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
psa_algorithm_t alg, psa_algorithm_t alg,
const uint8_t *input, size_t input_length, const uint8_t *input, size_t input_length,
uint8_t *output, size_t output_size, size_t *output_length); uint8_t *output, size_t output_size, size_t *output_length);
psa_status_t test_opaque_cipher_decrypt( psa_status_t mbedtls_test_opaque_cipher_decrypt(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
psa_algorithm_t alg, psa_algorithm_t alg,
const uint8_t *input, size_t input_length, const uint8_t *input, size_t input_length,
uint8_t *output, size_t output_size, size_t *output_length); uint8_t *output, size_t output_size, size_t *output_length);
psa_status_t test_opaque_cipher_encrypt_setup( psa_status_t mbedtls_test_opaque_cipher_encrypt_setup(
mbedtls_opaque_test_driver_cipher_operation_t *operation, mbedtls_opaque_test_driver_cipher_operation_t *operation,
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
psa_algorithm_t alg); psa_algorithm_t alg);
psa_status_t test_opaque_cipher_decrypt_setup( psa_status_t mbedtls_test_opaque_cipher_decrypt_setup(
mbedtls_opaque_test_driver_cipher_operation_t *operation, mbedtls_opaque_test_driver_cipher_operation_t *operation,
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
psa_algorithm_t alg); psa_algorithm_t alg);
psa_status_t test_opaque_cipher_abort( psa_status_t mbedtls_test_opaque_cipher_abort(
mbedtls_opaque_test_driver_cipher_operation_t *operation); mbedtls_opaque_test_driver_cipher_operation_t *operation);
psa_status_t test_opaque_cipher_set_iv( psa_status_t mbedtls_test_opaque_cipher_set_iv(
mbedtls_opaque_test_driver_cipher_operation_t *operation, mbedtls_opaque_test_driver_cipher_operation_t *operation,
const uint8_t *iv, size_t iv_length); const uint8_t *iv, size_t iv_length);
psa_status_t test_opaque_cipher_update( psa_status_t mbedtls_test_opaque_cipher_update(
mbedtls_opaque_test_driver_cipher_operation_t *operation, mbedtls_opaque_test_driver_cipher_operation_t *operation,
const uint8_t *input, size_t input_length, const uint8_t *input, size_t input_length,
uint8_t *output, size_t output_size, size_t *output_length); uint8_t *output, size_t output_size, size_t *output_length);
psa_status_t test_opaque_cipher_finish( psa_status_t mbedtls_test_opaque_cipher_finish(
mbedtls_opaque_test_driver_cipher_operation_t *operation, mbedtls_opaque_test_driver_cipher_operation_t *operation,
uint8_t *output, size_t output_size, size_t *output_length); uint8_t *output, size_t output_size, size_t *output_length);

View file

@ -37,42 +37,43 @@ typedef struct {
unsigned long hits; unsigned long hits;
/* Status returned by the last hash driver entry point call. */ /* Status returned by the last hash driver entry point call. */
psa_status_t driver_status; psa_status_t driver_status;
} test_driver_hash_hooks_t; } mbedtls_test_driver_hash_hooks_t;
#define TEST_DRIVER_HASH_INIT { 0, 0, 0 } #define MBEDTLS_TEST_DRIVER_HASH_INIT { 0, 0, 0 }
static inline test_driver_hash_hooks_t test_driver_hash_hooks_init( void ) static inline mbedtls_test_driver_hash_hooks_t
mbedtls_test_driver_hash_hooks_init( void )
{ {
const test_driver_hash_hooks_t v = TEST_DRIVER_HASH_INIT; const mbedtls_test_driver_hash_hooks_t v = MBEDTLS_TEST_DRIVER_HASH_INIT;
return( v ); return( v );
} }
extern test_driver_hash_hooks_t test_driver_hash_hooks; extern mbedtls_test_driver_hash_hooks_t mbedtls_test_driver_hash_hooks;
psa_status_t test_transparent_hash_compute( psa_status_t mbedtls_test_transparent_hash_compute(
psa_algorithm_t alg, psa_algorithm_t alg,
const uint8_t *input, size_t input_length, const uint8_t *input, size_t input_length,
uint8_t *hash, size_t hash_size, size_t *hash_length ); uint8_t *hash, size_t hash_size, size_t *hash_length );
psa_status_t test_transparent_hash_setup( psa_status_t mbedtls_test_transparent_hash_setup(
mbedtls_transparent_test_driver_hash_operation_t *operation, mbedtls_transparent_test_driver_hash_operation_t *operation,
psa_algorithm_t alg ); psa_algorithm_t alg );
psa_status_t test_transparent_hash_clone( psa_status_t mbedtls_test_transparent_hash_clone(
const mbedtls_transparent_test_driver_hash_operation_t *source_operation, const mbedtls_transparent_test_driver_hash_operation_t *source_operation,
mbedtls_transparent_test_driver_hash_operation_t *target_operation ); mbedtls_transparent_test_driver_hash_operation_t *target_operation );
psa_status_t test_transparent_hash_update( psa_status_t mbedtls_test_transparent_hash_update(
mbedtls_transparent_test_driver_hash_operation_t *operation, mbedtls_transparent_test_driver_hash_operation_t *operation,
const uint8_t *input, const uint8_t *input,
size_t input_length ); size_t input_length );
psa_status_t test_transparent_hash_finish( psa_status_t mbedtls_test_transparent_hash_finish(
mbedtls_transparent_test_driver_hash_operation_t *operation, mbedtls_transparent_test_driver_hash_operation_t *operation,
uint8_t *hash, uint8_t *hash,
size_t hash_size, size_t hash_size,
size_t *hash_length ); size_t *hash_length );
psa_status_t test_transparent_hash_abort( psa_status_t mbedtls_test_transparent_hash_abort(
mbedtls_psa_hash_operation_t *operation ); mbedtls_psa_hash_operation_t *operation );
#endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_DRIVER_TEST */

View file

@ -42,41 +42,44 @@ typedef struct {
/* Count the amount of times one of the key management driver functions /* Count the amount of times one of the key management driver functions
* is called. */ * is called. */
unsigned long hits; unsigned long hits;
} test_driver_key_management_hooks_t; } mbedtls_test_driver_key_management_hooks_t;
#define TEST_DRIVER_KEY_MANAGEMENT_INIT { NULL, 0, PSA_SUCCESS, 0 } #define MBEDTLS_TEST_DRIVER_KEY_MANAGEMENT_INIT { NULL, 0, PSA_SUCCESS, 0 }
static inline test_driver_key_management_hooks_t test_driver_key_management_hooks_init( void ) static inline mbedtls_test_driver_key_management_hooks_t
mbedtls_test_driver_key_management_hooks_init( void )
{ {
const test_driver_key_management_hooks_t v = TEST_DRIVER_KEY_MANAGEMENT_INIT; const mbedtls_test_driver_key_management_hooks_t
v = MBEDTLS_TEST_DRIVER_KEY_MANAGEMENT_INIT;
return( v ); return( v );
} }
extern test_driver_key_management_hooks_t test_driver_key_management_hooks; extern mbedtls_test_driver_key_management_hooks_t
mbedtls_test_driver_key_management_hooks;
psa_status_t test_transparent_generate_key( psa_status_t mbedtls_test_transparent_generate_key(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
uint8_t *key, size_t key_size, size_t *key_length ); uint8_t *key, size_t key_size, size_t *key_length );
psa_status_t test_opaque_generate_key( psa_status_t mbedtls_test_opaque_generate_key(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
uint8_t *key, size_t key_size, size_t *key_length ); uint8_t *key, size_t key_size, size_t *key_length );
psa_status_t test_opaque_export_key( psa_status_t mbedtls_test_opaque_export_key(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
uint8_t *data, size_t data_size, size_t *data_length ); uint8_t *data, size_t data_size, size_t *data_length );
psa_status_t test_transparent_export_public_key( psa_status_t mbedtls_test_transparent_export_public_key(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
uint8_t *data, size_t data_size, size_t *data_length ); uint8_t *data, size_t data_size, size_t *data_length );
psa_status_t test_opaque_export_public_key( psa_status_t mbedtls_test_opaque_export_public_key(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
uint8_t *data, size_t data_size, size_t *data_length ); uint8_t *data, size_t data_size, size_t *data_length );
psa_status_t test_transparent_import_key( psa_status_t mbedtls_test_transparent_import_key(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *data, const uint8_t *data,
size_t data_length, size_t data_length,
@ -85,7 +88,7 @@ psa_status_t test_transparent_import_key(
size_t *key_buffer_length, size_t *key_buffer_length,
size_t *bits); size_t *bits);
psa_status_t test_opaque_get_builtin_key( psa_status_t mbedtls_test_opaque_get_builtin_key(
psa_drv_slot_number_t slot_number, psa_drv_slot_number_t slot_number,
psa_key_attributes_t *attributes, psa_key_attributes_t *attributes,
uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ); uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length );

View file

@ -38,40 +38,44 @@ typedef struct {
psa_status_t forced_status; psa_status_t forced_status;
/* Count the amount of times one of the signature driver functions is called. */ /* Count the amount of times one of the signature driver functions is called. */
unsigned long hits; unsigned long hits;
} test_driver_signature_hooks_t; } mbedtls_test_driver_signature_hooks_t;
#define TEST_DRIVER_SIGNATURE_INIT { NULL, 0, PSA_SUCCESS, 0 } #define MBEDTLS_TEST_DRIVER_SIGNATURE_INIT { NULL, 0, PSA_SUCCESS, 0 }
static inline test_driver_signature_hooks_t test_driver_signature_hooks_init( void ) static inline mbedtls_test_driver_signature_hooks_t
mbedtls_test_driver_signature_hooks_init( void )
{ {
const test_driver_signature_hooks_t v = TEST_DRIVER_SIGNATURE_INIT; const mbedtls_test_driver_signature_hooks_t
v = MBEDTLS_TEST_DRIVER_SIGNATURE_INIT;
return( v ); return( v );
} }
extern test_driver_signature_hooks_t test_driver_signature_sign_hooks; extern mbedtls_test_driver_signature_hooks_t
extern test_driver_signature_hooks_t test_driver_signature_verify_hooks; mbedtls_test_driver_signature_sign_hooks;
extern mbedtls_test_driver_signature_hooks_t
mbedtls_test_driver_signature_verify_hooks;
psa_status_t test_transparent_signature_sign_hash( psa_status_t mbedtls_test_transparent_signature_sign_hash(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
psa_algorithm_t alg, psa_algorithm_t alg,
const uint8_t *hash, size_t hash_length, const uint8_t *hash, size_t hash_length,
uint8_t *signature, size_t signature_size, size_t *signature_length ); uint8_t *signature, size_t signature_size, size_t *signature_length );
psa_status_t test_opaque_signature_sign_hash( psa_status_t mbedtls_test_opaque_signature_sign_hash(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
psa_algorithm_t alg, psa_algorithm_t alg,
const uint8_t *hash, size_t hash_length, const uint8_t *hash, size_t hash_length,
uint8_t *signature, size_t signature_size, size_t *signature_length ); uint8_t *signature, size_t signature_size, size_t *signature_length );
psa_status_t test_transparent_signature_verify_hash( psa_status_t mbedtls_test_transparent_signature_verify_hash(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
psa_algorithm_t alg, psa_algorithm_t alg,
const uint8_t *hash, size_t hash_length, const uint8_t *hash, size_t hash_length,
const uint8_t *signature, size_t signature_length ); const uint8_t *signature, size_t signature_length );
psa_status_t test_opaque_signature_verify_hash( psa_status_t mbedtls_test_opaque_signature_verify_hash(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
psa_algorithm_t alg, psa_algorithm_t alg,

View file

@ -31,16 +31,17 @@
typedef struct { typedef struct {
unsigned int context; unsigned int context;
} test_driver_key_context_t; } mbedtls_test_driver_key_context_t;
/** \def TEST_DRIVER_KEY_CONTEXT_BASE_SIZE /** \def MBEDTLS_TEST_DRIVER_KEY_CONTEXT_BASE_SIZE
* *
* This macro returns the base size for the key context. It is the size of the * This macro returns the base size for the key context. It is the size of the
* driver specific information stored in each key context. * driver specific information stored in each key context.
*/ */
#define TEST_DRIVER_KEY_CONTEXT_BASE_SIZE sizeof( test_driver_key_context_t ) #define MBEDTLS_TEST_DRIVER_KEY_CONTEXT_BASE_SIZE \
sizeof( mbedtls_test_driver_key_context_t )
/** \def TEST_DRIVER_KEY_CONTEXT_KEY_PAIR_SIZE /** \def MBEDTLS_TEST_DRIVER_KEY_CONTEXT_KEY_PAIR_SIZE
* *
* Number of bytes included in every key context for a key pair. * Number of bytes included in every key context for a key pair.
* *
@ -49,47 +50,47 @@ typedef struct {
* subtracting the public key size below from this one. * subtracting the public key size below from this one.
*/ */
#define TEST_DRIVER_KEY_CONTEXT_KEY_PAIR_SIZE 65 #define MBEDTLS_TEST_DRIVER_KEY_CONTEXT_KEY_PAIR_SIZE 65
/** \def TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE /** \def MBEDTLS_TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE
* *
* Number of bytes included in every key context for a public key. * Number of bytes included in every key context for a public key.
* *
* For ECC public keys, it needs 257 bits so 33 bytes. * For ECC public keys, it needs 257 bits so 33 bytes.
*/ */
#define TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE 33 #define MBEDTLS_TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE 33
/** \def TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR /** \def MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR
* *
* Every key context for a symmetric key includes this many times the key size. * Every key context for a symmetric key includes this many times the key size.
*/ */
#define TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR 0 #define MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR 0
/** \def TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY /** \def MBEDTLS_TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY
* *
* If this is true for a key pair, the key context includes space for the public key. * If this is true for a key pair, the key context includes space for the public key.
* If this is false, no additional space is added for the public key. * If this is false, no additional space is added for the public key.
* *
* For this instance, store the public key with the private one. * For this instance, store the public key with the private one.
*/ */
#define TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY 1 #define MBEDTLS_TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY 1
/** \def TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION /** \def MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION
* *
* If TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION is defined, the test driver * If MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION is defined, the test driver
* provides a size_function entry point, otherwise, it does not. * provides a size_function entry point, otherwise, it does not.
* *
* Some opaque drivers have the need to support a custom size for the storage * Some opaque drivers have the need to support a custom size for the storage
* of key and context information. The size_function provides the ability to * of key and context information. The size_function provides the ability to
* provide that customization. * provide that customization.
*/ */
//#define TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION //#define MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION
#ifdef TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION #ifdef MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION
size_t test_size_function( size_t mbedtls_test_size_function(
const psa_key_type_t key_type, const psa_key_type_t key_type,
const size_t key_bits ); const size_t key_bits );
#endif /* TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION */ #endif /* MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION */
#endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_DRIVER_TEST */
#endif /* PSA_CRYPTO_TEST_DRIVERS_SIZE_H */ #endif /* PSA_CRYPTO_TEST_DRIVERS_SIZE_H */

View file

@ -22,7 +22,7 @@ if [ -d include/mbedtls ]; then :; else
exit 1 exit 1
fi fi
HEADERS=$( ls include/mbedtls/*.h include/psa/*.h ) HEADERS=$( ls include/mbedtls/*.h include/psa/*.h tests/include/test/drivers/*.h )
HEADERS="$HEADERS library/*.h" HEADERS="$HEADERS library/*.h"
HEADERS="$HEADERS 3rdparty/everest/include/everest/everest.h 3rdparty/everest/include/everest/x25519.h" HEADERS="$HEADERS 3rdparty/everest/include/everest/everest.h 3rdparty/everest/include/everest/x25519.h"

View file

@ -28,133 +28,134 @@
#include "test/drivers/hash.h" #include "test/drivers/hash.h"
test_driver_hash_hooks_t test_driver_hash_hooks = TEST_DRIVER_HASH_INIT; mbedtls_test_driver_hash_hooks_t
mbedtls_test_driver_hash_hooks = MBEDTLS_TEST_DRIVER_HASH_INIT;
psa_status_t test_transparent_hash_compute( psa_status_t mbedtls_test_transparent_hash_compute(
psa_algorithm_t alg, psa_algorithm_t alg,
const uint8_t *input, size_t input_length, const uint8_t *input, size_t input_length,
uint8_t *hash, size_t hash_size, size_t *hash_length ) uint8_t *hash, size_t hash_size, size_t *hash_length )
{ {
test_driver_hash_hooks.hits++; mbedtls_test_driver_hash_hooks.hits++;
if( test_driver_hash_hooks.forced_status != PSA_SUCCESS ) if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS )
{ {
test_driver_hash_hooks.driver_status = mbedtls_test_driver_hash_hooks.driver_status =
test_driver_hash_hooks.forced_status; mbedtls_test_driver_hash_hooks.forced_status;
} }
else else
{ {
test_driver_hash_hooks.driver_status = mbedtls_test_driver_hash_hooks.driver_status =
mbedtls_transparent_test_driver_hash_compute( mbedtls_transparent_test_driver_hash_compute(
alg, input, input_length, alg, input, input_length,
hash, hash_size, hash_length ); hash, hash_size, hash_length );
} }
return( test_driver_hash_hooks.driver_status ); return( mbedtls_test_driver_hash_hooks.driver_status );
} }
psa_status_t test_transparent_hash_setup( psa_status_t mbedtls_test_transparent_hash_setup(
mbedtls_transparent_test_driver_hash_operation_t *operation, mbedtls_transparent_test_driver_hash_operation_t *operation,
psa_algorithm_t alg ) psa_algorithm_t alg )
{ {
test_driver_hash_hooks.hits++; mbedtls_test_driver_hash_hooks.hits++;
if( test_driver_hash_hooks.forced_status != PSA_SUCCESS ) if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS )
{ {
test_driver_hash_hooks.driver_status = mbedtls_test_driver_hash_hooks.driver_status =
test_driver_hash_hooks.forced_status; mbedtls_test_driver_hash_hooks.forced_status;
} }
else else
{ {
test_driver_hash_hooks.driver_status = mbedtls_test_driver_hash_hooks.driver_status =
mbedtls_transparent_test_driver_hash_setup( operation, alg ); mbedtls_transparent_test_driver_hash_setup( operation, alg );
} }
return( test_driver_hash_hooks.driver_status ); return( mbedtls_test_driver_hash_hooks.driver_status );
} }
psa_status_t test_transparent_hash_clone( psa_status_t mbedtls_test_transparent_hash_clone(
const mbedtls_transparent_test_driver_hash_operation_t *source_operation, const mbedtls_transparent_test_driver_hash_operation_t *source_operation,
mbedtls_transparent_test_driver_hash_operation_t *target_operation ) mbedtls_transparent_test_driver_hash_operation_t *target_operation )
{ {
test_driver_hash_hooks.hits++; mbedtls_test_driver_hash_hooks.hits++;
if( test_driver_hash_hooks.forced_status != PSA_SUCCESS ) if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS )
{ {
test_driver_hash_hooks.driver_status = mbedtls_test_driver_hash_hooks.driver_status =
test_driver_hash_hooks.forced_status; mbedtls_test_driver_hash_hooks.forced_status;
} }
else else
{ {
test_driver_hash_hooks.driver_status = mbedtls_test_driver_hash_hooks.driver_status =
mbedtls_transparent_test_driver_hash_clone( source_operation, mbedtls_transparent_test_driver_hash_clone( source_operation,
target_operation ); target_operation );
} }
return( test_driver_hash_hooks.driver_status ); return( mbedtls_test_driver_hash_hooks.driver_status );
} }
psa_status_t test_transparent_hash_update( psa_status_t mbedtls_test_transparent_hash_update(
mbedtls_transparent_test_driver_hash_operation_t *operation, mbedtls_transparent_test_driver_hash_operation_t *operation,
const uint8_t *input, const uint8_t *input,
size_t input_length ) size_t input_length )
{ {
test_driver_hash_hooks.hits++; mbedtls_test_driver_hash_hooks.hits++;
if( test_driver_hash_hooks.forced_status != PSA_SUCCESS ) if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS )
{ {
test_driver_hash_hooks.driver_status = mbedtls_test_driver_hash_hooks.driver_status =
test_driver_hash_hooks.forced_status; mbedtls_test_driver_hash_hooks.forced_status;
} }
else else
{ {
test_driver_hash_hooks.driver_status = mbedtls_test_driver_hash_hooks.driver_status =
mbedtls_transparent_test_driver_hash_update( mbedtls_transparent_test_driver_hash_update(
operation, input, input_length ); operation, input, input_length );
} }
return( test_driver_hash_hooks.driver_status ); return( mbedtls_test_driver_hash_hooks.driver_status );
} }
psa_status_t test_transparent_hash_finish( psa_status_t mbedtls_test_transparent_hash_finish(
mbedtls_transparent_test_driver_hash_operation_t *operation, mbedtls_transparent_test_driver_hash_operation_t *operation,
uint8_t *hash, uint8_t *hash,
size_t hash_size, size_t hash_size,
size_t *hash_length ) size_t *hash_length )
{ {
test_driver_hash_hooks.hits++; mbedtls_test_driver_hash_hooks.hits++;
if( test_driver_hash_hooks.forced_status != PSA_SUCCESS ) if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS )
{ {
test_driver_hash_hooks.driver_status = mbedtls_test_driver_hash_hooks.driver_status =
test_driver_hash_hooks.forced_status; mbedtls_test_driver_hash_hooks.forced_status;
} }
else else
{ {
test_driver_hash_hooks.driver_status = mbedtls_test_driver_hash_hooks.driver_status =
mbedtls_transparent_test_driver_hash_finish( mbedtls_transparent_test_driver_hash_finish(
operation, hash, hash_size, hash_length ); operation, hash, hash_size, hash_length );
} }
return( test_driver_hash_hooks.driver_status ); return( mbedtls_test_driver_hash_hooks.driver_status );
} }
psa_status_t test_transparent_hash_abort( psa_status_t mbedtls_test_transparent_hash_abort(
mbedtls_transparent_test_driver_hash_operation_t *operation ) mbedtls_transparent_test_driver_hash_operation_t *operation )
{ {
test_driver_hash_hooks.hits++; mbedtls_test_driver_hash_hooks.hits++;
if( test_driver_hash_hooks.forced_status != PSA_SUCCESS ) if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS )
{ {
test_driver_hash_hooks.driver_status = mbedtls_test_driver_hash_hooks.driver_status =
test_driver_hash_hooks.forced_status; mbedtls_test_driver_hash_hooks.forced_status;
} }
else else
{ {
test_driver_hash_hooks.driver_status = mbedtls_test_driver_hash_hooks.driver_status =
mbedtls_transparent_test_driver_hash_abort( operation ); mbedtls_transparent_test_driver_hash_abort( operation );
} }
return( test_driver_hash_hooks.driver_status ); return( mbedtls_test_driver_hash_hooks.driver_status );
} }
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */

View file

@ -24,7 +24,7 @@
#include <psa/crypto_extra.h> #include <psa/crypto_extra.h>
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
#include <test/drivers/test_driver.h> #include <test/drivers/mbedtls_test_driver.h>
#endif #endif
typedef struct typedef struct

View file

@ -28,9 +28,10 @@
#include "test/drivers/aead.h" #include "test/drivers/aead.h"
test_driver_aead_hooks_t test_driver_aead_hooks = TEST_DRIVER_AEAD_INIT; mbedtls_test_driver_aead_hooks_t
mbedtls_test_driver_aead_hooks = MBEDTLS_TEST_DRIVER_AEAD_INIT;
psa_status_t test_transparent_aead_encrypt( psa_status_t mbedtls_test_transparent_aead_encrypt(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key_buffer, size_t key_buffer_size, const uint8_t *key_buffer, size_t key_buffer_size,
psa_algorithm_t alg, psa_algorithm_t alg,
@ -39,16 +40,16 @@ psa_status_t test_transparent_aead_encrypt(
const uint8_t *plaintext, size_t plaintext_length, const uint8_t *plaintext, size_t plaintext_length,
uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length ) uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length )
{ {
test_driver_aead_hooks.hits++; mbedtls_test_driver_aead_hooks.hits++;
if( test_driver_aead_hooks.forced_status != PSA_SUCCESS ) if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
{ {
test_driver_aead_hooks.driver_status = mbedtls_test_driver_aead_hooks.driver_status =
test_driver_aead_hooks.forced_status; mbedtls_test_driver_aead_hooks.forced_status;
} }
else else
{ {
test_driver_aead_hooks.driver_status = mbedtls_test_driver_aead_hooks.driver_status =
mbedtls_psa_aead_encrypt( mbedtls_psa_aead_encrypt(
attributes, key_buffer, key_buffer_size, attributes, key_buffer, key_buffer_size,
alg, alg,
@ -58,10 +59,10 @@ psa_status_t test_transparent_aead_encrypt(
ciphertext, ciphertext_size, ciphertext_length ); ciphertext, ciphertext_size, ciphertext_length );
} }
return( test_driver_aead_hooks.driver_status ); return( mbedtls_test_driver_aead_hooks.driver_status );
} }
psa_status_t test_transparent_aead_decrypt( psa_status_t mbedtls_test_transparent_aead_decrypt(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key_buffer, size_t key_buffer_size, const uint8_t *key_buffer, size_t key_buffer_size,
psa_algorithm_t alg, psa_algorithm_t alg,
@ -70,16 +71,16 @@ psa_status_t test_transparent_aead_decrypt(
const uint8_t *ciphertext, size_t ciphertext_length, const uint8_t *ciphertext, size_t ciphertext_length,
uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length ) uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length )
{ {
test_driver_aead_hooks.hits++; mbedtls_test_driver_aead_hooks.hits++;
if( test_driver_aead_hooks.forced_status != PSA_SUCCESS ) if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
{ {
test_driver_aead_hooks.driver_status = mbedtls_test_driver_aead_hooks.driver_status =
test_driver_aead_hooks.forced_status; mbedtls_test_driver_aead_hooks.forced_status;
} }
else else
{ {
test_driver_aead_hooks.driver_status = mbedtls_test_driver_aead_hooks.driver_status =
mbedtls_psa_aead_decrypt( mbedtls_psa_aead_decrypt(
attributes, key_buffer, key_buffer_size, attributes, key_buffer, key_buffer_size,
alg, alg,
@ -89,7 +90,7 @@ psa_status_t test_transparent_aead_decrypt(
plaintext, plaintext_size, plaintext_length ); plaintext, plaintext_size, plaintext_length );
} }
return( test_driver_aead_hooks.driver_status ); return( mbedtls_test_driver_aead_hooks.driver_status );
} }
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */

View file

@ -36,9 +36,10 @@
#include <string.h> #include <string.h>
test_driver_cipher_hooks_t test_driver_cipher_hooks = TEST_DRIVER_CIPHER_INIT; mbedtls_test_driver_cipher_hooks_t mbedtls_test_driver_cipher_hooks =
MBEDTLS_TEST_DRIVER_CIPHER_INIT;
static psa_status_t test_transparent_cipher_oneshot( static psa_status_t mbedtls_test_transparent_cipher_oneshot(
mbedtls_operation_t direction, mbedtls_operation_t direction,
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
@ -46,7 +47,7 @@ static psa_status_t test_transparent_cipher_oneshot(
const uint8_t *input, size_t input_length, const uint8_t *input, size_t input_length,
uint8_t *output, size_t output_size, size_t *output_length) uint8_t *output, size_t output_size, size_t *output_length)
{ {
test_driver_cipher_hooks.hits++; mbedtls_test_driver_cipher_hooks.hits++;
/* Test driver supports AES-CTR only, to verify operation calls. */ /* Test driver supports AES-CTR only, to verify operation calls. */
if( alg != PSA_ALG_CTR || if( alg != PSA_ALG_CTR ||
@ -54,21 +55,21 @@ static psa_status_t test_transparent_cipher_oneshot(
return( PSA_ERROR_NOT_SUPPORTED ); return( PSA_ERROR_NOT_SUPPORTED );
/* If test driver response code is not SUCCESS, we can return early */ /* If test driver response code is not SUCCESS, we can return early */
if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
return( test_driver_cipher_hooks.forced_status ); return( mbedtls_test_driver_cipher_hooks.forced_status );
/* If test driver output is overridden, we don't need to do actual crypto */ /* If test driver output is overridden, we don't need to do actual crypto */
if( test_driver_cipher_hooks.forced_output != NULL ) if( mbedtls_test_driver_cipher_hooks.forced_output != NULL )
{ {
if( output_size < test_driver_cipher_hooks.forced_output_length ) if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length )
return( PSA_ERROR_BUFFER_TOO_SMALL ); return( PSA_ERROR_BUFFER_TOO_SMALL );
memcpy( output, memcpy( output,
test_driver_cipher_hooks.forced_output, mbedtls_test_driver_cipher_hooks.forced_output,
test_driver_cipher_hooks.forced_output_length ); mbedtls_test_driver_cipher_hooks.forced_output_length );
*output_length = test_driver_cipher_hooks.forced_output_length; *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
return( test_driver_cipher_hooks.forced_status ); return( mbedtls_test_driver_cipher_hooks.forced_status );
} }
/* Run AES-CTR using the cipher module */ /* Run AES-CTR using the cipher module */
@ -166,7 +167,7 @@ exit:
} }
} }
psa_status_t test_transparent_cipher_encrypt( psa_status_t mbedtls_test_transparent_cipher_encrypt(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
psa_algorithm_t alg, psa_algorithm_t alg,
@ -174,7 +175,7 @@ psa_status_t test_transparent_cipher_encrypt(
uint8_t *output, size_t output_size, size_t *output_length) uint8_t *output, size_t output_size, size_t *output_length)
{ {
return ( return (
test_transparent_cipher_oneshot( mbedtls_test_transparent_cipher_oneshot(
MBEDTLS_ENCRYPT, MBEDTLS_ENCRYPT,
attributes, attributes,
key, key_length, key, key_length,
@ -183,7 +184,7 @@ psa_status_t test_transparent_cipher_encrypt(
output, output_size, output_length) ); output, output_size, output_length) );
} }
psa_status_t test_transparent_cipher_decrypt( psa_status_t mbedtls_test_transparent_cipher_decrypt(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
psa_algorithm_t alg, psa_algorithm_t alg,
@ -191,7 +192,7 @@ psa_status_t test_transparent_cipher_decrypt(
uint8_t *output, size_t output_size, size_t *output_length) uint8_t *output, size_t output_size, size_t *output_length)
{ {
return ( return (
test_transparent_cipher_oneshot( mbedtls_test_transparent_cipher_oneshot(
MBEDTLS_DECRYPT, MBEDTLS_DECRYPT,
attributes, attributes,
key, key_length, key, key_length,
@ -200,13 +201,13 @@ psa_status_t test_transparent_cipher_decrypt(
output, output_size, output_length) ); output, output_size, output_length) );
} }
psa_status_t test_transparent_cipher_encrypt_setup( psa_status_t mbedtls_test_transparent_cipher_encrypt_setup(
mbedtls_transparent_test_driver_cipher_operation_t *operation, mbedtls_transparent_test_driver_cipher_operation_t *operation,
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
psa_algorithm_t alg) psa_algorithm_t alg)
{ {
test_driver_cipher_hooks.hits++; mbedtls_test_driver_cipher_hooks.hits++;
/* Wiping the entire struct here, instead of member-by-member. This is /* Wiping the entire struct here, instead of member-by-member. This is
* useful for the test suite, since it gives a chance of catching memory * useful for the test suite, since it gives a chance of catching memory
@ -214,32 +215,32 @@ psa_status_t test_transparent_cipher_encrypt_setup(
* our context struct. */ * our context struct. */
memset( operation, 0, sizeof( *operation ) ); memset( operation, 0, sizeof( *operation ) );
if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
return( test_driver_cipher_hooks.forced_status ); return( mbedtls_test_driver_cipher_hooks.forced_status );
return ( mbedtls_transparent_test_driver_cipher_encrypt_setup( return ( mbedtls_transparent_test_driver_cipher_encrypt_setup(
operation, attributes, key, key_length, alg ) ); operation, attributes, key, key_length, alg ) );
} }
psa_status_t test_transparent_cipher_decrypt_setup( psa_status_t mbedtls_test_transparent_cipher_decrypt_setup(
mbedtls_transparent_test_driver_cipher_operation_t *operation, mbedtls_transparent_test_driver_cipher_operation_t *operation,
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
psa_algorithm_t alg) psa_algorithm_t alg)
{ {
test_driver_cipher_hooks.hits++; mbedtls_test_driver_cipher_hooks.hits++;
if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
return( test_driver_cipher_hooks.forced_status ); return( mbedtls_test_driver_cipher_hooks.forced_status );
return ( mbedtls_transparent_test_driver_cipher_decrypt_setup( return ( mbedtls_transparent_test_driver_cipher_decrypt_setup(
operation, attributes, key, key_length, alg ) ); operation, attributes, key, key_length, alg ) );
} }
psa_status_t test_transparent_cipher_abort( psa_status_t mbedtls_test_transparent_cipher_abort(
mbedtls_transparent_test_driver_cipher_operation_t *operation) mbedtls_transparent_test_driver_cipher_operation_t *operation)
{ {
test_driver_cipher_hooks.hits++; mbedtls_test_driver_cipher_hooks.hits++;
if( operation->alg == 0 ) if( operation->alg == 0 )
return( PSA_SUCCESS ); return( PSA_SUCCESS );
@ -252,24 +253,24 @@ psa_status_t test_transparent_cipher_abort(
* our context struct. */ * our context struct. */
memset( operation, 0, sizeof( *operation ) ); memset( operation, 0, sizeof( *operation ) );
return( test_driver_cipher_hooks.forced_status ); return( mbedtls_test_driver_cipher_hooks.forced_status );
} }
psa_status_t test_transparent_cipher_set_iv( psa_status_t mbedtls_test_transparent_cipher_set_iv(
mbedtls_transparent_test_driver_cipher_operation_t *operation, mbedtls_transparent_test_driver_cipher_operation_t *operation,
const uint8_t *iv, const uint8_t *iv,
size_t iv_length) size_t iv_length)
{ {
test_driver_cipher_hooks.hits++; mbedtls_test_driver_cipher_hooks.hits++;
if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
return( test_driver_cipher_hooks.forced_status ); return( mbedtls_test_driver_cipher_hooks.forced_status );
return( mbedtls_transparent_test_driver_cipher_set_iv( return( mbedtls_transparent_test_driver_cipher_set_iv(
operation, iv, iv_length ) ); operation, iv, iv_length ) );
} }
psa_status_t test_transparent_cipher_update( psa_status_t mbedtls_test_transparent_cipher_update(
mbedtls_transparent_test_driver_cipher_operation_t *operation, mbedtls_transparent_test_driver_cipher_operation_t *operation,
const uint8_t *input, const uint8_t *input,
size_t input_length, size_t input_length,
@ -277,52 +278,52 @@ psa_status_t test_transparent_cipher_update(
size_t output_size, size_t output_size,
size_t *output_length) size_t *output_length)
{ {
test_driver_cipher_hooks.hits++; mbedtls_test_driver_cipher_hooks.hits++;
if( test_driver_cipher_hooks.forced_output != NULL ) if( mbedtls_test_driver_cipher_hooks.forced_output != NULL )
{ {
if( output_size < test_driver_cipher_hooks.forced_output_length ) if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length )
return PSA_ERROR_BUFFER_TOO_SMALL; return PSA_ERROR_BUFFER_TOO_SMALL;
memcpy( output, memcpy( output,
test_driver_cipher_hooks.forced_output, mbedtls_test_driver_cipher_hooks.forced_output,
test_driver_cipher_hooks.forced_output_length ); mbedtls_test_driver_cipher_hooks.forced_output_length );
*output_length = test_driver_cipher_hooks.forced_output_length; *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
return( test_driver_cipher_hooks.forced_status ); return( mbedtls_test_driver_cipher_hooks.forced_status );
} }
if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
return( test_driver_cipher_hooks.forced_status ); return( mbedtls_test_driver_cipher_hooks.forced_status );
return( mbedtls_transparent_test_driver_cipher_update( return( mbedtls_transparent_test_driver_cipher_update(
operation, input, input_length, operation, input, input_length,
output, output_size, output_length ) ); output, output_size, output_length ) );
} }
psa_status_t test_transparent_cipher_finish( psa_status_t mbedtls_test_transparent_cipher_finish(
mbedtls_transparent_test_driver_cipher_operation_t *operation, mbedtls_transparent_test_driver_cipher_operation_t *operation,
uint8_t *output, uint8_t *output,
size_t output_size, size_t output_size,
size_t *output_length) size_t *output_length)
{ {
test_driver_cipher_hooks.hits++; mbedtls_test_driver_cipher_hooks.hits++;
if( test_driver_cipher_hooks.forced_output != NULL ) if( mbedtls_test_driver_cipher_hooks.forced_output != NULL )
{ {
if( output_size < test_driver_cipher_hooks.forced_output_length ) if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length )
return PSA_ERROR_BUFFER_TOO_SMALL; return PSA_ERROR_BUFFER_TOO_SMALL;
memcpy( output, memcpy( output,
test_driver_cipher_hooks.forced_output, mbedtls_test_driver_cipher_hooks.forced_output,
test_driver_cipher_hooks.forced_output_length ); mbedtls_test_driver_cipher_hooks.forced_output_length );
*output_length = test_driver_cipher_hooks.forced_output_length; *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
return( test_driver_cipher_hooks.forced_status ); return( mbedtls_test_driver_cipher_hooks.forced_status );
} }
if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
return( test_driver_cipher_hooks.forced_status ); return( mbedtls_test_driver_cipher_hooks.forced_status );
return( mbedtls_transparent_test_driver_cipher_finish( return( mbedtls_transparent_test_driver_cipher_finish(
operation, output, output_size, output_length ) ); operation, output, output_size, output_length ) );
@ -331,7 +332,7 @@ psa_status_t test_transparent_cipher_finish(
/* /*
* opaque versions, to do * opaque versions, to do
*/ */
psa_status_t test_opaque_cipher_encrypt( psa_status_t mbedtls_test_opaque_cipher_encrypt(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
psa_algorithm_t alg, psa_algorithm_t alg,
@ -350,7 +351,7 @@ psa_status_t test_opaque_cipher_encrypt(
return( PSA_ERROR_NOT_SUPPORTED ); return( PSA_ERROR_NOT_SUPPORTED );
} }
psa_status_t test_opaque_cipher_decrypt( psa_status_t mbedtls_test_opaque_cipher_decrypt(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
psa_algorithm_t alg, psa_algorithm_t alg,
@ -369,7 +370,7 @@ psa_status_t test_opaque_cipher_decrypt(
return( PSA_ERROR_NOT_SUPPORTED ); return( PSA_ERROR_NOT_SUPPORTED );
} }
psa_status_t test_opaque_cipher_encrypt_setup( psa_status_t mbedtls_test_opaque_cipher_encrypt_setup(
mbedtls_opaque_test_driver_cipher_operation_t *operation, mbedtls_opaque_test_driver_cipher_operation_t *operation,
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
@ -383,7 +384,7 @@ psa_status_t test_opaque_cipher_encrypt_setup(
return( PSA_ERROR_NOT_SUPPORTED ); return( PSA_ERROR_NOT_SUPPORTED );
} }
psa_status_t test_opaque_cipher_decrypt_setup( psa_status_t mbedtls_test_opaque_cipher_decrypt_setup(
mbedtls_opaque_test_driver_cipher_operation_t *operation, mbedtls_opaque_test_driver_cipher_operation_t *operation,
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
@ -397,14 +398,14 @@ psa_status_t test_opaque_cipher_decrypt_setup(
return( PSA_ERROR_NOT_SUPPORTED ); return( PSA_ERROR_NOT_SUPPORTED );
} }
psa_status_t test_opaque_cipher_abort( psa_status_t mbedtls_test_opaque_cipher_abort(
mbedtls_opaque_test_driver_cipher_operation_t *operation ) mbedtls_opaque_test_driver_cipher_operation_t *operation )
{ {
(void) operation; (void) operation;
return( PSA_ERROR_NOT_SUPPORTED ); return( PSA_ERROR_NOT_SUPPORTED );
} }
psa_status_t test_opaque_cipher_set_iv( psa_status_t mbedtls_test_opaque_cipher_set_iv(
mbedtls_opaque_test_driver_cipher_operation_t *operation, mbedtls_opaque_test_driver_cipher_operation_t *operation,
const uint8_t *iv, const uint8_t *iv,
size_t iv_length) size_t iv_length)
@ -415,7 +416,7 @@ psa_status_t test_opaque_cipher_set_iv(
return( PSA_ERROR_NOT_SUPPORTED ); return( PSA_ERROR_NOT_SUPPORTED );
} }
psa_status_t test_opaque_cipher_update( psa_status_t mbedtls_test_opaque_cipher_update(
mbedtls_opaque_test_driver_cipher_operation_t *operation, mbedtls_opaque_test_driver_cipher_operation_t *operation,
const uint8_t *input, const uint8_t *input,
size_t input_length, size_t input_length,
@ -432,7 +433,7 @@ psa_status_t test_opaque_cipher_update(
return( PSA_ERROR_NOT_SUPPORTED ); return( PSA_ERROR_NOT_SUPPORTED );
} }
psa_status_t test_opaque_cipher_finish( psa_status_t mbedtls_test_opaque_cipher_finish(
mbedtls_opaque_test_driver_cipher_operation_t *operation, mbedtls_opaque_test_driver_cipher_operation_t *operation,
uint8_t *output, uint8_t *output,
size_t output_size, size_t output_size,

View file

@ -38,18 +38,18 @@
#include <string.h> #include <string.h>
test_driver_key_management_hooks_t test_driver_key_management_hooks = mbedtls_test_driver_key_management_hooks_t
TEST_DRIVER_KEY_MANAGEMENT_INIT; mbedtls_test_driver_key_management_hooks = MBEDTLS_TEST_DRIVER_KEY_MANAGEMENT_INIT;
const uint8_t test_driver_aes_key[16] = const uint8_t mbedtls_test_driver_aes_key[16] =
{ 0x36, 0x77, 0x39, 0x7A, 0x24, 0x43, 0x26, 0x46, { 0x36, 0x77, 0x39, 0x7A, 0x24, 0x43, 0x26, 0x46,
0x29, 0x4A, 0x40, 0x4E, 0x63, 0x52, 0x66, 0x55 }; 0x29, 0x4A, 0x40, 0x4E, 0x63, 0x52, 0x66, 0x55 };
const uint8_t test_driver_ecdsa_key[32] = const uint8_t mbedtls_test_driver_ecdsa_key[32] =
{ 0xdc, 0x7d, 0x9d, 0x26, 0xd6, 0x7a, 0x4f, 0x63, { 0xdc, 0x7d, 0x9d, 0x26, 0xd6, 0x7a, 0x4f, 0x63,
0x2c, 0x34, 0xc2, 0xdc, 0x0b, 0x69, 0x86, 0x18, 0x2c, 0x34, 0xc2, 0xdc, 0x0b, 0x69, 0x86, 0x18,
0x38, 0x82, 0xc2, 0x06, 0xdf, 0x04, 0xcd, 0xb7, 0x38, 0x82, 0xc2, 0x06, 0xdf, 0x04, 0xcd, 0xb7,
0xd6, 0x9a, 0xab, 0xe2, 0x8b, 0xe4, 0xf8, 0x1a }; 0xd6, 0x9a, 0xab, 0xe2, 0x8b, 0xe4, 0xf8, 0x1a };
const uint8_t test_driver_ecdsa_pubkey[65] = const uint8_t mbedtls_test_driver_ecdsa_pubkey[65] =
{ 0x04, { 0x04,
0x85, 0xf6, 0x4d, 0x89, 0xf0, 0x0b, 0xe6, 0x6c, 0x85, 0xf6, 0x4d, 0x89, 0xf0, 0x0b, 0xe6, 0x6c,
0x88, 0xdd, 0x93, 0x7e, 0xfd, 0x6d, 0x7c, 0x44, 0x88, 0xdd, 0x93, 0x7e, 0xfd, 0x6d, 0x7c, 0x44,
@ -60,22 +60,23 @@ const uint8_t test_driver_ecdsa_pubkey[65] =
0xbc, 0x25, 0x16, 0xc3, 0xd2, 0x70, 0x2d, 0x79, 0xbc, 0x25, 0x16, 0xc3, 0xd2, 0x70, 0x2d, 0x79,
0x2f, 0x13, 0x1a, 0x92, 0x20, 0x95, 0xfd, 0x6c }; 0x2f, 0x13, 0x1a, 0x92, 0x20, 0x95, 0xfd, 0x6c };
psa_status_t test_transparent_generate_key( psa_status_t mbedtls_test_transparent_generate_key(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
uint8_t *key, size_t key_size, size_t *key_length ) uint8_t *key, size_t key_size, size_t *key_length )
{ {
++test_driver_key_management_hooks.hits; ++mbedtls_test_driver_key_management_hooks.hits;
if( test_driver_key_management_hooks.forced_status != PSA_SUCCESS ) if( mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS )
return( test_driver_key_management_hooks.forced_status ); return( mbedtls_test_driver_key_management_hooks.forced_status );
if( test_driver_key_management_hooks.forced_output != NULL ) if( mbedtls_test_driver_key_management_hooks.forced_output != NULL )
{ {
if( test_driver_key_management_hooks.forced_output_length > key_size ) if( mbedtls_test_driver_key_management_hooks.forced_output_length >
key_size )
return( PSA_ERROR_BUFFER_TOO_SMALL ); return( PSA_ERROR_BUFFER_TOO_SMALL );
memcpy( key, test_driver_key_management_hooks.forced_output, memcpy( key, mbedtls_test_driver_key_management_hooks.forced_output,
test_driver_key_management_hooks.forced_output_length ); mbedtls_test_driver_key_management_hooks.forced_output_length );
*key_length = test_driver_key_management_hooks.forced_output_length; *key_length = mbedtls_test_driver_key_management_hooks.forced_output_length;
return( PSA_SUCCESS ); return( PSA_SUCCESS );
} }
@ -102,7 +103,7 @@ psa_status_t test_transparent_generate_key(
} }
} }
psa_status_t test_opaque_generate_key( psa_status_t mbedtls_test_opaque_generate_key(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
uint8_t *key, size_t key_size, size_t *key_length ) uint8_t *key, size_t key_size, size_t *key_length )
{ {
@ -113,7 +114,7 @@ psa_status_t test_opaque_generate_key(
return( PSA_ERROR_NOT_SUPPORTED ); return( PSA_ERROR_NOT_SUPPORTED );
} }
psa_status_t test_transparent_import_key( psa_status_t mbedtls_test_transparent_import_key(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *data, const uint8_t *data,
size_t data_length, size_t data_length,
@ -122,10 +123,10 @@ psa_status_t test_transparent_import_key(
size_t *key_buffer_length, size_t *key_buffer_length,
size_t *bits) size_t *bits)
{ {
++test_driver_key_management_hooks.hits; ++mbedtls_test_driver_key_management_hooks.hits;
if( test_driver_key_management_hooks.forced_status != PSA_SUCCESS ) if( mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS )
return( test_driver_key_management_hooks.forced_status ); return( mbedtls_test_driver_key_management_hooks.forced_status );
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
psa_key_type_t type = psa_get_key_type( attributes ); psa_key_type_t type = psa_get_key_type( attributes );
@ -168,7 +169,7 @@ psa_status_t test_transparent_import_key(
return( status ); return( status );
} }
psa_status_t test_opaque_export_key( psa_status_t mbedtls_test_opaque_export_key(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
uint8_t *data, size_t data_size, size_t *data_length ) uint8_t *data, size_t data_size, size_t *data_length )
@ -199,12 +200,12 @@ psa_status_t test_opaque_export_key(
PSA_KEY_USAGE_EXPORT ) == 0 ) PSA_KEY_USAGE_EXPORT ) == 0 )
return( PSA_ERROR_CORRUPTION_DETECTED ); return( PSA_ERROR_CORRUPTION_DETECTED );
if( data_size < sizeof( test_driver_ecdsa_key ) ) if( data_size < sizeof( mbedtls_test_driver_ecdsa_key ) )
return( PSA_ERROR_BUFFER_TOO_SMALL ); return( PSA_ERROR_BUFFER_TOO_SMALL );
memcpy( data, test_driver_ecdsa_key, memcpy( data, mbedtls_test_driver_ecdsa_key,
sizeof( test_driver_ecdsa_key ) ); sizeof( mbedtls_test_driver_ecdsa_key ) );
*data_length = sizeof( test_driver_ecdsa_key ); *data_length = sizeof( mbedtls_test_driver_ecdsa_key );
return( PSA_SUCCESS ); return( PSA_SUCCESS );
case PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT: case PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT:
@ -220,12 +221,12 @@ psa_status_t test_opaque_export_key(
PSA_KEY_USAGE_EXPORT ) == 0 ) PSA_KEY_USAGE_EXPORT ) == 0 )
return( PSA_ERROR_CORRUPTION_DETECTED ); return( PSA_ERROR_CORRUPTION_DETECTED );
if( data_size < sizeof( test_driver_aes_key ) ) if( data_size < sizeof( mbedtls_test_driver_aes_key ) )
return( PSA_ERROR_BUFFER_TOO_SMALL ); return( PSA_ERROR_BUFFER_TOO_SMALL );
memcpy( data, test_driver_aes_key, memcpy( data, mbedtls_test_driver_aes_key,
sizeof( test_driver_aes_key ) ); sizeof( mbedtls_test_driver_aes_key ) );
*data_length = sizeof( test_driver_aes_key ); *data_length = sizeof( mbedtls_test_driver_aes_key );
return( PSA_SUCCESS ); return( PSA_SUCCESS );
default: default:
@ -233,23 +234,24 @@ psa_status_t test_opaque_export_key(
} }
} }
psa_status_t test_transparent_export_public_key( psa_status_t mbedtls_test_transparent_export_public_key(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key_buffer, size_t key_buffer_size, const uint8_t *key_buffer, size_t key_buffer_size,
uint8_t *data, size_t data_size, size_t *data_length ) uint8_t *data, size_t data_size, size_t *data_length )
{ {
++test_driver_key_management_hooks.hits; ++mbedtls_test_driver_key_management_hooks.hits;
if( test_driver_key_management_hooks.forced_status != PSA_SUCCESS ) if( mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS )
return( test_driver_key_management_hooks.forced_status ); return( mbedtls_test_driver_key_management_hooks.forced_status );
if( test_driver_key_management_hooks.forced_output != NULL ) if( mbedtls_test_driver_key_management_hooks.forced_output != NULL )
{ {
if( test_driver_key_management_hooks.forced_output_length > data_size ) if( mbedtls_test_driver_key_management_hooks.forced_output_length >
data_size )
return( PSA_ERROR_BUFFER_TOO_SMALL ); return( PSA_ERROR_BUFFER_TOO_SMALL );
memcpy( data, test_driver_key_management_hooks.forced_output, memcpy( data, mbedtls_test_driver_key_management_hooks.forced_output,
test_driver_key_management_hooks.forced_output_length ); mbedtls_test_driver_key_management_hooks.forced_output_length );
*data_length = test_driver_key_management_hooks.forced_output_length; *data_length = mbedtls_test_driver_key_management_hooks.forced_output_length;
return( PSA_SUCCESS ); return( PSA_SUCCESS );
} }
@ -288,7 +290,7 @@ psa_status_t test_transparent_export_public_key(
return( status ); return( status );
} }
psa_status_t test_opaque_export_public_key( psa_status_t mbedtls_test_opaque_export_public_key(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
uint8_t *data, size_t data_size, size_t *data_length ) uint8_t *data, size_t data_size, size_t *data_length )
@ -315,12 +317,12 @@ psa_status_t test_opaque_export_public_key(
PSA_ALG_ECDSA( PSA_ALG_ANY_HASH ) ) PSA_ALG_ECDSA( PSA_ALG_ANY_HASH ) )
return( PSA_ERROR_CORRUPTION_DETECTED ); return( PSA_ERROR_CORRUPTION_DETECTED );
if( data_size < sizeof( test_driver_ecdsa_pubkey ) ) if( data_size < sizeof( mbedtls_test_driver_ecdsa_pubkey ) )
return( PSA_ERROR_BUFFER_TOO_SMALL ); return( PSA_ERROR_BUFFER_TOO_SMALL );
memcpy( data, test_driver_ecdsa_pubkey, memcpy( data, mbedtls_test_driver_ecdsa_pubkey,
sizeof( test_driver_ecdsa_pubkey ) ); sizeof( mbedtls_test_driver_ecdsa_pubkey ) );
*data_length = sizeof( test_driver_ecdsa_pubkey ); *data_length = sizeof( mbedtls_test_driver_ecdsa_pubkey );
return( PSA_SUCCESS ); return( PSA_SUCCESS );
default: default:
@ -338,7 +340,7 @@ psa_status_t test_opaque_export_public_key(
* (i.e. for an actual driver this would mean 'builtin_key_size' = * (i.e. for an actual driver this would mean 'builtin_key_size' =
* sizeof(psa_drv_slot_number_t)). * sizeof(psa_drv_slot_number_t)).
*/ */
psa_status_t test_opaque_get_builtin_key( psa_status_t mbedtls_test_opaque_get_builtin_key(
psa_drv_slot_number_t slot_number, psa_drv_slot_number_t slot_number,
psa_key_attributes_t *attributes, psa_key_attributes_t *attributes,
uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ) uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length )

View file

@ -41,28 +41,32 @@
#include <string.h> #include <string.h>
test_driver_signature_hooks_t test_driver_signature_sign_hooks = TEST_DRIVER_SIGNATURE_INIT; mbedtls_test_driver_signature_hooks_t
test_driver_signature_hooks_t test_driver_signature_verify_hooks = TEST_DRIVER_SIGNATURE_INIT; mbedtls_test_driver_signature_sign_hooks = MBEDTLS_TEST_DRIVER_SIGNATURE_INIT;
mbedtls_test_driver_signature_hooks_t
mbedtls_test_driver_signature_verify_hooks = MBEDTLS_TEST_DRIVER_SIGNATURE_INIT;
psa_status_t test_transparent_signature_sign_hash( psa_status_t mbedtls_test_transparent_signature_sign_hash(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key_buffer, size_t key_buffer_size, const uint8_t *key_buffer, size_t key_buffer_size,
psa_algorithm_t alg, psa_algorithm_t alg,
const uint8_t *hash, size_t hash_length, const uint8_t *hash, size_t hash_length,
uint8_t *signature, size_t signature_size, size_t *signature_length ) uint8_t *signature, size_t signature_size, size_t *signature_length )
{ {
++test_driver_signature_sign_hooks.hits; ++mbedtls_test_driver_signature_sign_hooks.hits;
if( test_driver_signature_sign_hooks.forced_status != PSA_SUCCESS ) if( mbedtls_test_driver_signature_sign_hooks.forced_status != PSA_SUCCESS )
return( test_driver_signature_sign_hooks.forced_status ); return( mbedtls_test_driver_signature_sign_hooks.forced_status );
if( test_driver_signature_sign_hooks.forced_output != NULL ) if( mbedtls_test_driver_signature_sign_hooks.forced_output != NULL )
{ {
if( test_driver_signature_sign_hooks.forced_output_length > signature_size ) if( mbedtls_test_driver_signature_sign_hooks.forced_output_length >
signature_size )
return( PSA_ERROR_BUFFER_TOO_SMALL ); return( PSA_ERROR_BUFFER_TOO_SMALL );
memcpy( signature, test_driver_signature_sign_hooks.forced_output, memcpy( signature,
test_driver_signature_sign_hooks.forced_output_length ); mbedtls_test_driver_signature_sign_hooks.forced_output,
*signature_length = test_driver_signature_sign_hooks.forced_output_length; mbedtls_test_driver_signature_sign_hooks.forced_output_length );
*signature_length = mbedtls_test_driver_signature_sign_hooks.forced_output_length;
return( PSA_SUCCESS ); return( PSA_SUCCESS );
} }
@ -120,7 +124,7 @@ psa_status_t test_transparent_signature_sign_hash(
} }
} }
psa_status_t test_opaque_signature_sign_hash( psa_status_t mbedtls_test_opaque_signature_sign_hash(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
psa_algorithm_t alg, psa_algorithm_t alg,
@ -140,17 +144,17 @@ psa_status_t test_opaque_signature_sign_hash(
return( PSA_ERROR_NOT_SUPPORTED ); return( PSA_ERROR_NOT_SUPPORTED );
} }
psa_status_t test_transparent_signature_verify_hash( psa_status_t mbedtls_test_transparent_signature_verify_hash(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key_buffer, size_t key_buffer_size, const uint8_t *key_buffer, size_t key_buffer_size,
psa_algorithm_t alg, psa_algorithm_t alg,
const uint8_t *hash, size_t hash_length, const uint8_t *hash, size_t hash_length,
const uint8_t *signature, size_t signature_length ) const uint8_t *signature, size_t signature_length )
{ {
++test_driver_signature_verify_hooks.hits; ++mbedtls_test_driver_signature_verify_hooks.hits;
if( test_driver_signature_verify_hooks.forced_status != PSA_SUCCESS ) if( mbedtls_test_driver_signature_verify_hooks.forced_status != PSA_SUCCESS )
return( test_driver_signature_verify_hooks.forced_status ); return( mbedtls_test_driver_signature_verify_hooks.forced_status );
#if defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN) || \ #if defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN) || \
defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PSS) defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PSS)
@ -200,7 +204,7 @@ psa_status_t test_transparent_signature_verify_hash(
} }
} }
psa_status_t test_opaque_signature_verify_hash( psa_status_t mbedtls_test_opaque_signature_verify_hash(
const psa_key_attributes_t *attributes, const psa_key_attributes_t *attributes,
const uint8_t *key, size_t key_length, const uint8_t *key, size_t key_length,
psa_algorithm_t alg, psa_algorithm_t alg,

View file

@ -28,8 +28,8 @@
#include "test/drivers/size.h" #include "test/drivers/size.h"
#ifdef TEST_KEY_CONTEXT_SIZE_FUNCTION #ifdef MBEDTLS_TEST_KEY_CONTEXT_SIZE_FUNCTION
size_t test_size_function( size_t mbedtls_test_size_function(
const psa_key_type_t key_type, const psa_key_type_t key_type,
const size_t key_bits ) const size_t key_bits )
{ {
@ -37,6 +37,6 @@ size_t test_size_function(
(void) key_bits; (void) key_bits;
return 0; return 0;
} }
#endif /*TEST_KEY_CONTEXT_SIZE_FUNCTION */ #endif /*MBEDTLS_TEST_KEY_CONTEXT_SIZE_FUNCTION */
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */

View file

@ -1,5 +1,5 @@
/* BEGIN_HEADER */ /* BEGIN_HEADER */
#include "test/drivers/test_driver.h" #include "test/drivers/mbedtls_test_driver.h"
/* END_HEADER */ /* END_HEADER */
/* BEGIN_DEPENDENCIES /* BEGIN_DEPENDENCIES
@ -23,7 +23,8 @@ void ecdsa_sign( int force_status_arg,
uint8_t signature[64]; uint8_t signature[64];
size_t signature_length = 0xdeadbeef; size_t signature_length = 0xdeadbeef;
psa_status_t actual_status; psa_status_t actual_status;
test_driver_signature_sign_hooks = test_driver_signature_hooks_init(); mbedtls_test_driver_signature_sign_hooks =
mbedtls_test_driver_signature_hooks_init();
PSA_ASSERT( psa_crypto_init( ) ); PSA_ASSERT( psa_crypto_init( ) );
psa_set_key_type( &attributes, psa_set_key_type( &attributes,
@ -34,11 +35,13 @@ void ecdsa_sign( int force_status_arg,
key_input->x, key_input->len, key_input->x, key_input->len,
&key ); &key );
test_driver_signature_sign_hooks.forced_status = force_status; mbedtls_test_driver_signature_sign_hooks.forced_status = force_status;
if( fake_output == 1 ) if( fake_output == 1 )
{ {
test_driver_signature_sign_hooks.forced_output = expected_output->x; mbedtls_test_driver_signature_sign_hooks.forced_output =
test_driver_signature_sign_hooks.forced_output_length = expected_output->len; expected_output->x;
mbedtls_test_driver_signature_sign_hooks.forced_output_length =
expected_output->len;
} }
actual_status = psa_sign_hash( key, alg, actual_status = psa_sign_hash( key, alg,
@ -51,13 +54,14 @@ void ecdsa_sign( int force_status_arg,
ASSERT_COMPARE( signature, signature_length, ASSERT_COMPARE( signature, signature_length,
expected_output->x, expected_output->len ); expected_output->x, expected_output->len );
} }
TEST_EQUAL( test_driver_signature_sign_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_signature_sign_hooks.hits, 1 );
exit: exit:
psa_reset_key_attributes( &attributes ); psa_reset_key_attributes( &attributes );
psa_destroy_key( key ); psa_destroy_key( key );
PSA_DONE( ); PSA_DONE( );
test_driver_signature_sign_hooks = test_driver_signature_hooks_init(); mbedtls_test_driver_signature_sign_hooks =
mbedtls_test_driver_signature_hooks_init();
} }
/* END_CASE */ /* END_CASE */
@ -75,7 +79,8 @@ void ecdsa_verify( int force_status_arg,
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_algorithm_t alg = PSA_ALG_DETERMINISTIC_ECDSA( PSA_ALG_SHA_256 ); psa_algorithm_t alg = PSA_ALG_DETERMINISTIC_ECDSA( PSA_ALG_SHA_256 );
psa_status_t actual_status; psa_status_t actual_status;
test_driver_signature_verify_hooks = test_driver_signature_hooks_init(); mbedtls_test_driver_signature_verify_hooks =
mbedtls_test_driver_signature_hooks_init();
PSA_ASSERT( psa_crypto_init( ) ); PSA_ASSERT( psa_crypto_init( ) );
if( register_public_key ) if( register_public_key )
@ -99,19 +104,20 @@ void ecdsa_verify( int force_status_arg,
&key ); &key );
} }
test_driver_signature_verify_hooks.forced_status = force_status; mbedtls_test_driver_signature_verify_hooks.forced_status = force_status;
actual_status = psa_verify_hash( key, alg, actual_status = psa_verify_hash( key, alg,
data_input->x, data_input->len, data_input->x, data_input->len,
signature_input->x, signature_input->len ); signature_input->x, signature_input->len );
TEST_EQUAL( actual_status, expected_status ); TEST_EQUAL( actual_status, expected_status );
TEST_EQUAL( test_driver_signature_verify_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_signature_verify_hooks.hits, 1 );
exit: exit:
psa_reset_key_attributes( &attributes ); psa_reset_key_attributes( &attributes );
psa_destroy_key( key ); psa_destroy_key( key );
PSA_DONE( ); PSA_DONE( );
test_driver_signature_verify_hooks = test_driver_signature_hooks_init(); mbedtls_test_driver_signature_verify_hooks =
mbedtls_test_driver_signature_hooks_init();
} }
/* END_CASE */ /* END_CASE */
@ -130,7 +136,8 @@ void generate_key( int force_status_arg,
psa_status_t actual_status; psa_status_t actual_status;
uint8_t actual_output[PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(256)] = {0}; uint8_t actual_output[PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(256)] = {0};
size_t actual_output_length; size_t actual_output_length;
test_driver_key_management_hooks = test_driver_key_management_hooks_init(); mbedtls_test_driver_key_management_hooks =
mbedtls_test_driver_key_management_hooks_init();
psa_set_key_type( &attributes, psa_set_key_type( &attributes,
PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_FAMILY_SECP_R1 ) ); PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_FAMILY_SECP_R1 ) );
@ -140,18 +147,22 @@ void generate_key( int force_status_arg,
if( fake_output->len > 0 ) if( fake_output->len > 0 )
{ {
expected_output = test_driver_key_management_hooks.forced_output = fake_output->x; expected_output =
expected_output_length = test_driver_key_management_hooks.forced_output_length = mbedtls_test_driver_key_management_hooks.forced_output =
fake_output->x;
expected_output_length =
mbedtls_test_driver_key_management_hooks.forced_output_length =
fake_output->len; fake_output->len;
} }
test_driver_key_management_hooks.hits = 0; mbedtls_test_driver_key_management_hooks.hits = 0;
test_driver_key_management_hooks.forced_status = force_status; mbedtls_test_driver_key_management_hooks.forced_status = force_status;
PSA_ASSERT( psa_crypto_init( ) ); PSA_ASSERT( psa_crypto_init( ) );
actual_status = psa_generate_key( &attributes, &key ); actual_status = psa_generate_key( &attributes, &key );
TEST_EQUAL( test_driver_key_management_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_key_management_hooks.hits, 1 );
TEST_EQUAL( actual_status, expected_status ); TEST_EQUAL( actual_status, expected_status );
if( actual_status == PSA_SUCCESS ) if( actual_status == PSA_SUCCESS )
@ -178,7 +189,8 @@ exit:
psa_reset_key_attributes( &attributes ); psa_reset_key_attributes( &attributes );
psa_destroy_key( key ); psa_destroy_key( key );
PSA_DONE( ); PSA_DONE( );
test_driver_key_management_hooks = test_driver_key_management_hooks_init(); mbedtls_test_driver_key_management_hooks =
mbedtls_test_driver_key_management_hooks_init();
} }
/* END_CASE */ /* END_CASE */
@ -194,25 +206,27 @@ void validate_key( int force_status_arg,
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT; mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_status_t actual_status; psa_status_t actual_status;
test_driver_key_management_hooks = test_driver_key_management_hooks_init(); mbedtls_test_driver_key_management_hooks =
mbedtls_test_driver_key_management_hooks_init();
psa_set_key_type( &attributes, psa_set_key_type( &attributes,
key_type ); key_type );
psa_set_key_bits( &attributes, 0 ); psa_set_key_bits( &attributes, 0 );
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT ); psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT );
test_driver_key_management_hooks.forced_status = force_status; mbedtls_test_driver_key_management_hooks.forced_status = force_status;
PSA_ASSERT( psa_crypto_init( ) ); PSA_ASSERT( psa_crypto_init( ) );
actual_status = psa_import_key( &attributes, key_input->x, key_input->len, &key ); actual_status = psa_import_key( &attributes, key_input->x, key_input->len, &key );
TEST_EQUAL( test_driver_key_management_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_key_management_hooks.hits, 1 );
TEST_EQUAL( actual_status, expected_status ); TEST_EQUAL( actual_status, expected_status );
exit: exit:
psa_reset_key_attributes( &attributes ); psa_reset_key_attributes( &attributes );
psa_destroy_key( key ); psa_destroy_key( key );
PSA_DONE( ); PSA_DONE( );
test_driver_key_management_hooks = test_driver_key_management_hooks_init(); mbedtls_test_driver_key_management_hooks =
mbedtls_test_driver_key_management_hooks_init();
} }
/* END_CASE */ /* END_CASE */
@ -236,7 +250,8 @@ void export_key( int force_status_arg,
psa_status_t actual_status; psa_status_t actual_status;
uint8_t actual_output[PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(256)] = {0}; uint8_t actual_output[PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(256)] = {0};
size_t actual_output_length; size_t actual_output_length;
test_driver_key_management_hooks = test_driver_key_management_hooks_init(); mbedtls_test_driver_key_management_hooks =
mbedtls_test_driver_key_management_hooks_init();
psa_set_key_type( &attributes, input_key_type ); psa_set_key_type( &attributes, input_key_type );
psa_set_key_bits( &attributes, 256 ); psa_set_key_bits( &attributes, 256 );
@ -247,8 +262,12 @@ void export_key( int force_status_arg,
if( fake_output->len > 0 ) if( fake_output->len > 0 )
{ {
expected_output_ptr = test_driver_key_management_hooks.forced_output = fake_output->x; expected_output_ptr =
expected_output_length = test_driver_key_management_hooks.forced_output_length = mbedtls_test_driver_key_management_hooks.forced_output =
fake_output->x;
expected_output_length =
mbedtls_test_driver_key_management_hooks.forced_output_length =
fake_output->len; fake_output->len;
} }
else else
@ -257,8 +276,8 @@ void export_key( int force_status_arg,
expected_output_length = expected_output->len; expected_output_length = expected_output->len;
} }
test_driver_key_management_hooks.hits = 0; mbedtls_test_driver_key_management_hooks.hits = 0;
test_driver_key_management_hooks.forced_status = force_status; mbedtls_test_driver_key_management_hooks.forced_status = force_status;
if( PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY( output_key_type ) ) if( PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY( output_key_type ) )
actual_status = psa_export_public_key( handle, actual_output, sizeof(actual_output), &actual_output_length ); actual_status = psa_export_public_key( handle, actual_output, sizeof(actual_output), &actual_output_length );
@ -268,7 +287,7 @@ void export_key( int force_status_arg,
if( PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY( output_key_type ) && if( PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY( output_key_type ) &&
!PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY( input_key_type ) ) !PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY( input_key_type ) )
TEST_EQUAL( test_driver_key_management_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_key_management_hooks.hits, 1 );
if( actual_status == PSA_SUCCESS ) if( actual_status == PSA_SUCCESS )
{ {
@ -279,7 +298,8 @@ exit:
psa_reset_key_attributes( &attributes ); psa_reset_key_attributes( &attributes );
psa_destroy_key( handle ); psa_destroy_key( handle );
PSA_DONE( ); PSA_DONE( );
test_driver_key_management_hooks = test_driver_key_management_hooks_init(); mbedtls_test_driver_key_management_hooks =
mbedtls_test_driver_key_management_hooks_init();
} }
/* END_CASE */ /* END_CASE */
@ -303,8 +323,8 @@ void cipher_encrypt( int alg_arg, int key_type_arg,
size_t total_output_length = 0; size_t total_output_length = 0;
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT; psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
test_driver_cipher_hooks = test_driver_cipher_hooks_init(); mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init();
test_driver_cipher_hooks.forced_status = force_status; mbedtls_test_driver_cipher_hooks.forced_status = force_status;
PSA_ASSERT( psa_crypto_init( ) ); PSA_ASSERT( psa_crypto_init( ) );
@ -316,12 +336,12 @@ void cipher_encrypt( int alg_arg, int key_type_arg,
&key ) ); &key ) );
PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) ); PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) ); PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) );
TEST_EQUAL( test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
output_buffer_size = ( (size_t) input->len + output_buffer_size = ( (size_t) input->len +
PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type ) ); PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type ) );
@ -329,21 +349,21 @@ void cipher_encrypt( int alg_arg, int key_type_arg,
if( mock_output_arg ) if( mock_output_arg )
{ {
test_driver_cipher_hooks.forced_output = expected_output->x; mbedtls_test_driver_cipher_hooks.forced_output = expected_output->x;
test_driver_cipher_hooks.forced_output_length = expected_output->len; mbedtls_test_driver_cipher_hooks.forced_output_length = expected_output->len;
} }
PSA_ASSERT( psa_cipher_update( &operation, PSA_ASSERT( psa_cipher_update( &operation,
input->x, input->len, input->x, input->len,
output, output_buffer_size, output, output_buffer_size,
&function_output_length ) ); &function_output_length ) );
TEST_EQUAL( test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
if( mock_output_arg ) if( mock_output_arg )
{ {
test_driver_cipher_hooks.forced_output = NULL; mbedtls_test_driver_cipher_hooks.forced_output = NULL;
test_driver_cipher_hooks.forced_output_length = 0; mbedtls_test_driver_cipher_hooks.forced_output_length = 0;
} }
total_output_length += function_output_length; total_output_length += function_output_length;
@ -352,8 +372,8 @@ void cipher_encrypt( int alg_arg, int key_type_arg,
output_buffer_size - total_output_length, output_buffer_size - total_output_length,
&function_output_length ); &function_output_length );
/* Finish will have called abort as well, so expecting two hits here */ /* Finish will have called abort as well, so expecting two hits here */
TEST_EQUAL( test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 2 : 0 ) ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 2 : 0 ) );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
total_output_length += function_output_length; total_output_length += function_output_length;
@ -362,7 +382,7 @@ void cipher_encrypt( int alg_arg, int key_type_arg,
{ {
PSA_ASSERT( psa_cipher_abort( &operation ) ); PSA_ASSERT( psa_cipher_abort( &operation ) );
// driver function should've been called as part of the finish() core routine // driver function should've been called as part of the finish() core routine
TEST_EQUAL( test_driver_cipher_hooks.hits, 0 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 );
ASSERT_COMPARE( expected_output->x, expected_output->len, ASSERT_COMPARE( expected_output->x, expected_output->len,
output, total_output_length ); output, total_output_length );
} }
@ -372,7 +392,7 @@ exit:
mbedtls_free( output ); mbedtls_free( output );
psa_destroy_key( key ); psa_destroy_key( key );
PSA_DONE( ); PSA_DONE( );
test_driver_cipher_hooks = test_driver_cipher_hooks_init(); mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init();
} }
/* END_CASE */ /* END_CASE */
@ -396,7 +416,7 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg,
size_t total_output_length = 0; size_t total_output_length = 0;
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT; psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
test_driver_cipher_hooks = test_driver_cipher_hooks_init(); mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init();
PSA_ASSERT( psa_crypto_init( ) ); PSA_ASSERT( psa_crypto_init( ) );
@ -408,12 +428,12 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg,
&key ) ); &key ) );
PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) ); PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) ); PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) );
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
output_buffer_size = ( (size_t) input->len + output_buffer_size = ( (size_t) input->len +
PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type ) ); PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type ) );
@ -423,8 +443,8 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg,
PSA_ASSERT( psa_cipher_update( &operation, input->x, first_part_size, PSA_ASSERT( psa_cipher_update( &operation, input->x, first_part_size,
output, output_buffer_size, output, output_buffer_size,
&function_output_length ) ); &function_output_length ) );
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
TEST_ASSERT( function_output_length == output1_length ); TEST_ASSERT( function_output_length == output1_length );
total_output_length += function_output_length; total_output_length += function_output_length;
@ -434,8 +454,8 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg,
output + total_output_length, output + total_output_length,
output_buffer_size - total_output_length, output_buffer_size - total_output_length,
&function_output_length ) ); &function_output_length ) );
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
TEST_ASSERT( function_output_length == output2_length ); TEST_ASSERT( function_output_length == output2_length );
total_output_length += function_output_length; total_output_length += function_output_length;
PSA_ASSERT( psa_cipher_finish( &operation, PSA_ASSERT( psa_cipher_finish( &operation,
@ -443,11 +463,11 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg,
output_buffer_size - total_output_length, output_buffer_size - total_output_length,
&function_output_length ) ); &function_output_length ) );
/* Finish will have called abort as well, so expecting two hits here */ /* Finish will have called abort as well, so expecting two hits here */
TEST_EQUAL( test_driver_cipher_hooks.hits, 2 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 );
test_driver_cipher_hooks.hits = 0 ; mbedtls_test_driver_cipher_hooks.hits = 0 ;
total_output_length += function_output_length; total_output_length += function_output_length;
PSA_ASSERT( psa_cipher_abort( &operation ) ); PSA_ASSERT( psa_cipher_abort( &operation ) );
TEST_EQUAL( test_driver_cipher_hooks.hits, 0 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 );
ASSERT_COMPARE( expected_output->x, expected_output->len, ASSERT_COMPARE( expected_output->x, expected_output->len,
output, total_output_length ); output, total_output_length );
@ -457,7 +477,7 @@ exit:
mbedtls_free( output ); mbedtls_free( output );
psa_destroy_key( key ); psa_destroy_key( key );
PSA_DONE( ); PSA_DONE( );
test_driver_cipher_hooks = test_driver_cipher_hooks_init(); mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init();
} }
/* END_CASE */ /* END_CASE */
@ -481,7 +501,7 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg,
size_t total_output_length = 0; size_t total_output_length = 0;
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT; psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
test_driver_cipher_hooks = test_driver_cipher_hooks_init(); mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init();
PSA_ASSERT( psa_crypto_init( ) ); PSA_ASSERT( psa_crypto_init( ) );
@ -493,12 +513,12 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg,
&key ) ); &key ) );
PSA_ASSERT( psa_cipher_decrypt_setup( &operation, key, alg ) ); PSA_ASSERT( psa_cipher_decrypt_setup( &operation, key, alg ) );
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) ); PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) );
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
output_buffer_size = ( (size_t) input->len + output_buffer_size = ( (size_t) input->len +
PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type ) ); PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type ) );
@ -509,8 +529,8 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg,
input->x, first_part_size, input->x, first_part_size,
output, output_buffer_size, output, output_buffer_size,
&function_output_length ) ); &function_output_length ) );
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
TEST_ASSERT( function_output_length == output1_length ); TEST_ASSERT( function_output_length == output1_length );
total_output_length += function_output_length; total_output_length += function_output_length;
@ -520,8 +540,8 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg,
output + total_output_length, output + total_output_length,
output_buffer_size - total_output_length, output_buffer_size - total_output_length,
&function_output_length ) ); &function_output_length ) );
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
TEST_ASSERT( function_output_length == output2_length ); TEST_ASSERT( function_output_length == output2_length );
total_output_length += function_output_length; total_output_length += function_output_length;
@ -530,11 +550,11 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg,
output_buffer_size - total_output_length, output_buffer_size - total_output_length,
&function_output_length ) ); &function_output_length ) );
/* Finish will have called abort as well, so expecting two hits here */ /* Finish will have called abort as well, so expecting two hits here */
TEST_EQUAL( test_driver_cipher_hooks.hits, 2 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
total_output_length += function_output_length; total_output_length += function_output_length;
PSA_ASSERT( psa_cipher_abort( &operation ) ); PSA_ASSERT( psa_cipher_abort( &operation ) );
TEST_EQUAL( test_driver_cipher_hooks.hits, 0 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 );
ASSERT_COMPARE( expected_output->x, expected_output->len, ASSERT_COMPARE( expected_output->x, expected_output->len,
output, total_output_length ); output, total_output_length );
@ -544,7 +564,7 @@ exit:
mbedtls_free( output ); mbedtls_free( output );
psa_destroy_key( key ); psa_destroy_key( key );
PSA_DONE( ); PSA_DONE( );
test_driver_cipher_hooks = test_driver_cipher_hooks_init(); mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init();
} }
/* END_CASE */ /* END_CASE */
@ -568,8 +588,8 @@ void cipher_decrypt( int alg_arg, int key_type_arg,
size_t total_output_length = 0; size_t total_output_length = 0;
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT; psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
test_driver_cipher_hooks = test_driver_cipher_hooks_init(); mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init();
test_driver_cipher_hooks.forced_status = force_status; mbedtls_test_driver_cipher_hooks.forced_status = force_status;
PSA_ASSERT( psa_crypto_init( ) ); PSA_ASSERT( psa_crypto_init( ) );
@ -581,12 +601,12 @@ void cipher_decrypt( int alg_arg, int key_type_arg,
&key ) ); &key ) );
PSA_ASSERT( psa_cipher_decrypt_setup( &operation, key, alg ) ); PSA_ASSERT( psa_cipher_decrypt_setup( &operation, key, alg ) );
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) ); PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) );
TEST_EQUAL( test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
output_buffer_size = ( (size_t) input->len + output_buffer_size = ( (size_t) input->len +
PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type ) ); PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type ) );
@ -594,21 +614,21 @@ void cipher_decrypt( int alg_arg, int key_type_arg,
if( mock_output_arg ) if( mock_output_arg )
{ {
test_driver_cipher_hooks.forced_output = expected_output->x; mbedtls_test_driver_cipher_hooks.forced_output = expected_output->x;
test_driver_cipher_hooks.forced_output_length = expected_output->len; mbedtls_test_driver_cipher_hooks.forced_output_length = expected_output->len;
} }
PSA_ASSERT( psa_cipher_update( &operation, PSA_ASSERT( psa_cipher_update( &operation,
input->x, input->len, input->x, input->len,
output, output_buffer_size, output, output_buffer_size,
&function_output_length ) ); &function_output_length ) );
TEST_EQUAL( test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
if( mock_output_arg ) if( mock_output_arg )
{ {
test_driver_cipher_hooks.forced_output = NULL; mbedtls_test_driver_cipher_hooks.forced_output = NULL;
test_driver_cipher_hooks.forced_output_length = 0; mbedtls_test_driver_cipher_hooks.forced_output_length = 0;
} }
total_output_length += function_output_length; total_output_length += function_output_length;
@ -617,8 +637,8 @@ void cipher_decrypt( int alg_arg, int key_type_arg,
output_buffer_size - total_output_length, output_buffer_size - total_output_length,
&function_output_length ); &function_output_length );
/* Finish will have called abort as well, so expecting two hits here */ /* Finish will have called abort as well, so expecting two hits here */
TEST_EQUAL( test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 2 : 0 ) ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 2 : 0 ) );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
total_output_length += function_output_length; total_output_length += function_output_length;
TEST_EQUAL( status, expected_status ); TEST_EQUAL( status, expected_status );
@ -626,7 +646,7 @@ void cipher_decrypt( int alg_arg, int key_type_arg,
if( expected_status == PSA_SUCCESS ) if( expected_status == PSA_SUCCESS )
{ {
PSA_ASSERT( psa_cipher_abort( &operation ) ); PSA_ASSERT( psa_cipher_abort( &operation ) );
TEST_EQUAL( test_driver_cipher_hooks.hits, 0 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 );
ASSERT_COMPARE( expected_output->x, expected_output->len, ASSERT_COMPARE( expected_output->x, expected_output->len,
output, total_output_length ); output, total_output_length );
} }
@ -636,7 +656,7 @@ exit:
mbedtls_free( output ); mbedtls_free( output );
psa_destroy_key( key ); psa_destroy_key( key );
PSA_DONE( ); PSA_DONE( );
test_driver_cipher_hooks = test_driver_cipher_hooks_init(); mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init();
} }
/* END_CASE */ /* END_CASE */
@ -654,7 +674,7 @@ void cipher_entry_points( int alg_arg, int key_type_arg,
size_t function_output_length = 0; size_t function_output_length = 0;
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT; psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
test_driver_cipher_hooks = test_driver_cipher_hooks_init(); mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init();
ASSERT_ALLOC( output, input->len + 16 ); ASSERT_ALLOC( output, input->len + 16 );
output_buffer_size = input->len + 16; output_buffer_size = input->len + 16;
@ -669,136 +689,136 @@ void cipher_entry_points( int alg_arg, int key_type_arg,
&key ) ); &key ) );
/* Test setup call, encrypt */ /* Test setup call, encrypt */
test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR; mbedtls_test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR;
status = psa_cipher_encrypt_setup( &operation, key, alg ); status = psa_cipher_encrypt_setup( &operation, key, alg );
/* When setup fails, it shouldn't call any further entry points */ /* When setup fails, it shouldn't call any further entry points */
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
status = psa_cipher_set_iv( &operation, iv->x, iv->len ); status = psa_cipher_set_iv( &operation, iv->x, iv->len );
TEST_EQUAL( status, PSA_ERROR_BAD_STATE ); TEST_EQUAL( status, PSA_ERROR_BAD_STATE );
TEST_EQUAL( test_driver_cipher_hooks.hits, 0 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 );
/* Test setup call failure, decrypt */ /* Test setup call failure, decrypt */
status = psa_cipher_decrypt_setup( &operation, key, alg ); status = psa_cipher_decrypt_setup( &operation, key, alg );
/* When setup fails, it shouldn't call any further entry points */ /* When setup fails, it shouldn't call any further entry points */
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
status = psa_cipher_set_iv( &operation, iv->x, iv->len ); status = psa_cipher_set_iv( &operation, iv->x, iv->len );
TEST_EQUAL( status, PSA_ERROR_BAD_STATE ); TEST_EQUAL( status, PSA_ERROR_BAD_STATE );
TEST_EQUAL( test_driver_cipher_hooks.hits, 0 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 );
/* Test IV setting failure */ /* Test IV setting failure */
test_driver_cipher_hooks.forced_status = PSA_SUCCESS; mbedtls_test_driver_cipher_hooks.forced_status = PSA_SUCCESS;
status = psa_cipher_encrypt_setup( &operation, key, alg ); status = psa_cipher_encrypt_setup( &operation, key, alg );
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR; mbedtls_test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR;
status = psa_cipher_set_iv( &operation, iv->x, iv->len ); status = psa_cipher_set_iv( &operation, iv->x, iv->len );
/* When setting the IV fails, it should call abort too */ /* When setting the IV fails, it should call abort too */
TEST_EQUAL( test_driver_cipher_hooks.hits, 2 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 );
TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
/* Failure should prevent further operations from executing on the driver */ /* Failure should prevent further operations from executing on the driver */
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
status = psa_cipher_update( &operation, status = psa_cipher_update( &operation,
input->x, input->len, input->x, input->len,
output, output_buffer_size, output, output_buffer_size,
&function_output_length ); &function_output_length );
TEST_EQUAL( status, PSA_ERROR_BAD_STATE ); TEST_EQUAL( status, PSA_ERROR_BAD_STATE );
TEST_EQUAL( test_driver_cipher_hooks.hits, 0 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 );
psa_cipher_abort( &operation ); psa_cipher_abort( &operation );
/* Test IV generation failure */ /* Test IV generation failure */
test_driver_cipher_hooks.forced_status = PSA_SUCCESS; mbedtls_test_driver_cipher_hooks.forced_status = PSA_SUCCESS;
status = psa_cipher_encrypt_setup( &operation, key, alg ); status = psa_cipher_encrypt_setup( &operation, key, alg );
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR; mbedtls_test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR;
status = psa_cipher_generate_iv( &operation, output, 16, &function_output_length ); status = psa_cipher_generate_iv( &operation, output, 16, &function_output_length );
/* When generating the IV fails, it should call abort too */ /* When generating the IV fails, it should call abort too */
TEST_EQUAL( test_driver_cipher_hooks.hits, 2 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 );
TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
/* Failure should prevent further operations from executing on the driver */ /* Failure should prevent further operations from executing on the driver */
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
status = psa_cipher_update( &operation, status = psa_cipher_update( &operation,
input->x, input->len, input->x, input->len,
output, output_buffer_size, output, output_buffer_size,
&function_output_length ); &function_output_length );
TEST_EQUAL( status, PSA_ERROR_BAD_STATE ); TEST_EQUAL( status, PSA_ERROR_BAD_STATE );
TEST_EQUAL( test_driver_cipher_hooks.hits, 0 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 );
psa_cipher_abort( &operation ); psa_cipher_abort( &operation );
/* Test update failure */ /* Test update failure */
test_driver_cipher_hooks.forced_status = PSA_SUCCESS; mbedtls_test_driver_cipher_hooks.forced_status = PSA_SUCCESS;
status = psa_cipher_encrypt_setup( &operation, key, alg ); status = psa_cipher_encrypt_setup( &operation, key, alg );
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
status = psa_cipher_set_iv( &operation, iv->x, iv->len ); status = psa_cipher_set_iv( &operation, iv->x, iv->len );
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR; mbedtls_test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR;
status = psa_cipher_update( &operation, status = psa_cipher_update( &operation,
input->x, input->len, input->x, input->len,
output, output_buffer_size, output, output_buffer_size,
&function_output_length ); &function_output_length );
/* When the update call fails, it should call abort too */ /* When the update call fails, it should call abort too */
TEST_EQUAL( test_driver_cipher_hooks.hits, 2 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 );
TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
/* Failure should prevent further operations from executing on the driver */ /* Failure should prevent further operations from executing on the driver */
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
status = psa_cipher_update( &operation, status = psa_cipher_update( &operation,
input->x, input->len, input->x, input->len,
output, output_buffer_size, output, output_buffer_size,
&function_output_length ); &function_output_length );
TEST_EQUAL( status, PSA_ERROR_BAD_STATE ); TEST_EQUAL( status, PSA_ERROR_BAD_STATE );
TEST_EQUAL( test_driver_cipher_hooks.hits, 0 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 );
psa_cipher_abort( &operation ); psa_cipher_abort( &operation );
/* Test finish failure */ /* Test finish failure */
test_driver_cipher_hooks.forced_status = PSA_SUCCESS; mbedtls_test_driver_cipher_hooks.forced_status = PSA_SUCCESS;
status = psa_cipher_encrypt_setup( &operation, key, alg ); status = psa_cipher_encrypt_setup( &operation, key, alg );
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
status = psa_cipher_set_iv( &operation, iv->x, iv->len ); status = psa_cipher_set_iv( &operation, iv->x, iv->len );
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
status = psa_cipher_update( &operation, status = psa_cipher_update( &operation,
input->x, input->len, input->x, input->len,
output, output_buffer_size, output, output_buffer_size,
&function_output_length ); &function_output_length );
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 );
TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR; mbedtls_test_driver_cipher_hooks.forced_status = PSA_ERROR_GENERIC_ERROR;
status = psa_cipher_finish( &operation, status = psa_cipher_finish( &operation,
output + function_output_length, output + function_output_length,
output_buffer_size - function_output_length, output_buffer_size - function_output_length,
&function_output_length ); &function_output_length );
/* When the finish call fails, it should call abort too */ /* When the finish call fails, it should call abort too */
TEST_EQUAL( test_driver_cipher_hooks.hits, 2 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 );
TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status );
/* Failure should prevent further operations from executing on the driver */ /* Failure should prevent further operations from executing on the driver */
test_driver_cipher_hooks.hits = 0; mbedtls_test_driver_cipher_hooks.hits = 0;
status = psa_cipher_update( &operation, status = psa_cipher_update( &operation,
input->x, input->len, input->x, input->len,
output, output_buffer_size, output, output_buffer_size,
&function_output_length ); &function_output_length );
TEST_EQUAL( status, PSA_ERROR_BAD_STATE ); TEST_EQUAL( status, PSA_ERROR_BAD_STATE );
TEST_EQUAL( test_driver_cipher_hooks.hits, 0 ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 0 );
psa_cipher_abort( &operation ); psa_cipher_abort( &operation );
exit: exit:
@ -806,7 +826,7 @@ exit:
mbedtls_free( output ); mbedtls_free( output );
psa_destroy_key( key ); psa_destroy_key( key );
PSA_DONE( ); PSA_DONE( );
test_driver_cipher_hooks = test_driver_cipher_hooks_init(); mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init();
} }
/* END_CASE */ /* END_CASE */
@ -829,7 +849,7 @@ void aead_encrypt( int key_type_arg, data_t *key_data,
size_t output_length = 0; size_t output_length = 0;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_status_t status = PSA_ERROR_GENERIC_ERROR; psa_status_t status = PSA_ERROR_GENERIC_ERROR;
test_driver_aead_hooks = test_driver_aead_hooks_init(); mbedtls_test_driver_aead_hooks = mbedtls_test_driver_aead_hooks_init();
PSA_ASSERT( psa_crypto_init( ) ); PSA_ASSERT( psa_crypto_init( ) );
@ -852,15 +872,15 @@ void aead_encrypt( int key_type_arg, data_t *key_data,
PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE( input_data->len ) ); PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE( input_data->len ) );
ASSERT_ALLOC( output_data, output_size ); ASSERT_ALLOC( output_data, output_size );
test_driver_aead_hooks.forced_status = forced_status; mbedtls_test_driver_aead_hooks.forced_status = forced_status;
status = psa_aead_encrypt( key, alg, status = psa_aead_encrypt( key, alg,
nonce->x, nonce->len, nonce->x, nonce->len,
additional_data->x, additional_data->len, additional_data->x, additional_data->len,
input_data->x, input_data->len, input_data->x, input_data->len,
output_data, output_size, output_data, output_size,
&output_length ); &output_length );
TEST_EQUAL( test_driver_aead_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits, 1 );
TEST_EQUAL( test_driver_aead_hooks.driver_status, forced_status ); TEST_EQUAL( mbedtls_test_driver_aead_hooks.driver_status, forced_status );
TEST_EQUAL( status, ( forced_status == PSA_ERROR_NOT_SUPPORTED ) ? TEST_EQUAL( status, ( forced_status == PSA_ERROR_NOT_SUPPORTED ) ?
PSA_SUCCESS : forced_status ); PSA_SUCCESS : forced_status );
@ -875,7 +895,7 @@ exit:
psa_destroy_key( key ); psa_destroy_key( key );
mbedtls_free( output_data ); mbedtls_free( output_data );
PSA_DONE( ); PSA_DONE( );
test_driver_aead_hooks = test_driver_aead_hooks_init(); mbedtls_test_driver_aead_hooks = mbedtls_test_driver_aead_hooks_init();
} }
/* END_CASE */ /* END_CASE */
@ -898,7 +918,7 @@ void aead_decrypt( int key_type_arg, data_t *key_data,
size_t output_length = 0; size_t output_length = 0;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_status_t status = PSA_ERROR_GENERIC_ERROR; psa_status_t status = PSA_ERROR_GENERIC_ERROR;
test_driver_aead_hooks = test_driver_aead_hooks_init(); mbedtls_test_driver_aead_hooks = mbedtls_test_driver_aead_hooks_init();
PSA_ASSERT( psa_crypto_init( ) ); PSA_ASSERT( psa_crypto_init( ) );
@ -915,7 +935,7 @@ void aead_decrypt( int key_type_arg, data_t *key_data,
alg ); alg );
ASSERT_ALLOC( output_data, output_size ); ASSERT_ALLOC( output_data, output_size );
test_driver_aead_hooks.forced_status = forced_status; mbedtls_test_driver_aead_hooks.forced_status = forced_status;
status = psa_aead_decrypt( key, alg, status = psa_aead_decrypt( key, alg,
nonce->x, nonce->len, nonce->x, nonce->len,
additional_data->x, additional_data->x,
@ -923,8 +943,8 @@ void aead_decrypt( int key_type_arg, data_t *key_data,
input_data->x, input_data->len, input_data->x, input_data->len,
output_data, output_size, output_data, output_size,
&output_length ); &output_length );
TEST_EQUAL( test_driver_aead_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits, 1 );
TEST_EQUAL( test_driver_aead_hooks.driver_status, forced_status ); TEST_EQUAL( mbedtls_test_driver_aead_hooks.driver_status, forced_status );
TEST_EQUAL( status, ( forced_status == PSA_ERROR_NOT_SUPPORTED ) ? TEST_EQUAL( status, ( forced_status == PSA_ERROR_NOT_SUPPORTED ) ?
PSA_SUCCESS : forced_status ); PSA_SUCCESS : forced_status );
@ -939,7 +959,7 @@ exit:
psa_destroy_key( key ); psa_destroy_key( key );
mbedtls_free( output_data ); mbedtls_free( output_data );
PSA_DONE( ); PSA_DONE( );
test_driver_aead_hooks = test_driver_aead_hooks_init(); mbedtls_test_driver_aead_hooks = mbedtls_test_driver_aead_hooks_init();
} }
/* END_CASE */ /* END_CASE */
@ -1059,8 +1079,8 @@ void hash_compute( int alg_arg,
unsigned char *output = NULL; unsigned char *output = NULL;
size_t output_length; size_t output_length;
test_driver_hash_hooks = test_driver_hash_hooks_init(); mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
test_driver_hash_hooks.forced_status = forced_status; mbedtls_test_driver_hash_hooks.forced_status = forced_status;
PSA_ASSERT( psa_crypto_init( ) ); PSA_ASSERT( psa_crypto_init( ) );
ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) ); ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) );
@ -1068,8 +1088,8 @@ void hash_compute( int alg_arg,
TEST_EQUAL( psa_hash_compute( alg, input->x, input->len, TEST_EQUAL( psa_hash_compute( alg, input->x, input->len,
output, PSA_HASH_LENGTH( alg ), output, PSA_HASH_LENGTH( alg ),
&output_length ), expected_status ); &output_length ), expected_status );
TEST_EQUAL( test_driver_hash_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 );
TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status );
if( expected_status == PSA_SUCCESS ) if( expected_status == PSA_SUCCESS )
{ {
@ -1079,7 +1099,7 @@ void hash_compute( int alg_arg,
exit: exit:
mbedtls_free( output ); mbedtls_free( output );
PSA_DONE( ); PSA_DONE( );
test_driver_hash_hooks = test_driver_hash_hooks_init(); mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
} }
/* END_CASE */ /* END_CASE */
@ -1096,7 +1116,7 @@ void hash_multipart( int alg_arg,
psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT; psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
size_t output_length; size_t output_length;
test_driver_hash_hooks = test_driver_hash_hooks_init(); mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) ); ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) );
PSA_ASSERT( psa_crypto_init( ) ); PSA_ASSERT( psa_crypto_init( ) );
@ -1104,24 +1124,24 @@ void hash_multipart( int alg_arg,
/* /*
* Case 1: Force the driver return status for setup. * Case 1: Force the driver return status for setup.
*/ */
test_driver_hash_hooks.forced_status = forced_status; mbedtls_test_driver_hash_hooks.forced_status = forced_status;
TEST_EQUAL( psa_hash_setup( &operation, alg ), expected_status ); TEST_EQUAL( psa_hash_setup( &operation, alg ), expected_status );
TEST_EQUAL( test_driver_hash_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 );
TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status );
if( expected_status == PSA_SUCCESS ) if( expected_status == PSA_SUCCESS )
{ {
PSA_ASSERT( psa_hash_update( &operation, input->x, input->len ) ); PSA_ASSERT( psa_hash_update( &operation, input->x, input->len ) );
TEST_EQUAL( test_driver_hash_hooks.hits, TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits,
forced_status == PSA_ERROR_NOT_SUPPORTED ? 1 : 2 ); forced_status == PSA_ERROR_NOT_SUPPORTED ? 1 : 2 );
TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status );
PSA_ASSERT( psa_hash_finish( &operation, PSA_ASSERT( psa_hash_finish( &operation,
output, PSA_HASH_LENGTH( alg ), output, PSA_HASH_LENGTH( alg ),
&output_length ) ); &output_length ) );
TEST_EQUAL( test_driver_hash_hooks.hits, TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits,
forced_status == PSA_ERROR_NOT_SUPPORTED ? 1 : 4 ); forced_status == PSA_ERROR_NOT_SUPPORTED ? 1 : 4 );
TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status );
ASSERT_COMPARE( output, output_length, hash->x, hash->len ); ASSERT_COMPARE( output, output_length, hash->x, hash->len );
} }
@ -1129,25 +1149,25 @@ void hash_multipart( int alg_arg,
/* /*
* Case 2: Force the driver return status for update. * Case 2: Force the driver return status for update.
*/ */
test_driver_hash_hooks = test_driver_hash_hooks_init(); mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
PSA_ASSERT( psa_hash_setup( &operation, alg ) ); PSA_ASSERT( psa_hash_setup( &operation, alg ) );
TEST_EQUAL( test_driver_hash_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 );
TEST_EQUAL( test_driver_hash_hooks.driver_status, PSA_SUCCESS ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS );
test_driver_hash_hooks.forced_status = forced_status; mbedtls_test_driver_hash_hooks.forced_status = forced_status;
TEST_EQUAL( psa_hash_update( &operation, input->x, input->len ), TEST_EQUAL( psa_hash_update( &operation, input->x, input->len ),
forced_status ); forced_status );
TEST_EQUAL( test_driver_hash_hooks.hits, TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits,
forced_status != PSA_SUCCESS ? 3 : 2 ); forced_status != PSA_SUCCESS ? 3 : 2 );
TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status );
if( forced_status == PSA_SUCCESS ) if( forced_status == PSA_SUCCESS )
{ {
PSA_ASSERT( psa_hash_finish( &operation, PSA_ASSERT( psa_hash_finish( &operation,
output, PSA_HASH_LENGTH( alg ), output, PSA_HASH_LENGTH( alg ),
&output_length ) ); &output_length ) );
TEST_EQUAL( test_driver_hash_hooks.hits, 4 ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 4 );
TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status );
ASSERT_COMPARE( output, output_length, hash->x, hash->len ); ASSERT_COMPARE( output, output_length, hash->x, hash->len );
} }
@ -1155,21 +1175,21 @@ void hash_multipart( int alg_arg,
/* /*
* Case 3: Force the driver return status for finish. * Case 3: Force the driver return status for finish.
*/ */
test_driver_hash_hooks = test_driver_hash_hooks_init(); mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
PSA_ASSERT( psa_hash_setup( &operation, alg ) ); PSA_ASSERT( psa_hash_setup( &operation, alg ) );
TEST_EQUAL( test_driver_hash_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 );
TEST_EQUAL( test_driver_hash_hooks.driver_status, PSA_SUCCESS ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS );
PSA_ASSERT( psa_hash_update( &operation, input->x, input->len ) ); PSA_ASSERT( psa_hash_update( &operation, input->x, input->len ) );
TEST_EQUAL( test_driver_hash_hooks.hits, 2 ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 2 );
TEST_EQUAL( test_driver_hash_hooks.driver_status, PSA_SUCCESS ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS );
test_driver_hash_hooks.forced_status = forced_status; mbedtls_test_driver_hash_hooks.forced_status = forced_status;
TEST_EQUAL( psa_hash_finish( &operation, TEST_EQUAL( psa_hash_finish( &operation,
output, PSA_HASH_LENGTH( alg ), output, PSA_HASH_LENGTH( alg ),
&output_length ), forced_status ); &output_length ), forced_status );
TEST_EQUAL( test_driver_hash_hooks.hits, 4 ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 4 );
TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status );
if( forced_status == PSA_SUCCESS ) if( forced_status == PSA_SUCCESS )
{ {
@ -1180,7 +1200,7 @@ exit:
psa_hash_abort( &operation ); psa_hash_abort( &operation );
mbedtls_free( output ); mbedtls_free( output );
PSA_DONE( ); PSA_DONE( );
test_driver_hash_hooks = test_driver_hash_hooks_init(); mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
} }
/* END_CASE */ /* END_CASE */
@ -1196,7 +1216,7 @@ void hash_clone( int alg_arg,
psa_hash_operation_t target_operation = PSA_HASH_OPERATION_INIT; psa_hash_operation_t target_operation = PSA_HASH_OPERATION_INIT;
size_t output_length; size_t output_length;
test_driver_hash_hooks = test_driver_hash_hooks_init(); mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) ); ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) );
PSA_ASSERT( psa_crypto_init( ) ); PSA_ASSERT( psa_crypto_init( ) );
@ -1206,32 +1226,32 @@ void hash_clone( int alg_arg,
*/ */
TEST_EQUAL( psa_hash_clone( &source_operation, &target_operation ), TEST_EQUAL( psa_hash_clone( &source_operation, &target_operation ),
PSA_ERROR_BAD_STATE ); PSA_ERROR_BAD_STATE );
TEST_EQUAL( test_driver_hash_hooks.hits, 0 ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 0 );
PSA_ASSERT( psa_hash_setup( &source_operation, alg ) ); PSA_ASSERT( psa_hash_setup( &source_operation, alg ) );
TEST_EQUAL( test_driver_hash_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 );
TEST_EQUAL( test_driver_hash_hooks.driver_status, PSA_SUCCESS ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS );
test_driver_hash_hooks.forced_status = forced_status; mbedtls_test_driver_hash_hooks.forced_status = forced_status;
TEST_EQUAL( psa_hash_clone( &source_operation, &target_operation ), TEST_EQUAL( psa_hash_clone( &source_operation, &target_operation ),
forced_status ); forced_status );
TEST_EQUAL( test_driver_hash_hooks.hits, TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits,
forced_status == PSA_SUCCESS ? 2 : 3 ); forced_status == PSA_SUCCESS ? 2 : 3 );
TEST_EQUAL( test_driver_hash_hooks.driver_status, forced_status ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status );
if( forced_status == PSA_SUCCESS ) if( forced_status == PSA_SUCCESS )
{ {
test_driver_hash_hooks = test_driver_hash_hooks_init(); mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
PSA_ASSERT( psa_hash_update( &target_operation, PSA_ASSERT( psa_hash_update( &target_operation,
input->x, input->len ) ); input->x, input->len ) );
TEST_EQUAL( test_driver_hash_hooks.hits, 1 ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 );
TEST_EQUAL( test_driver_hash_hooks.driver_status, PSA_SUCCESS ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS );
PSA_ASSERT( psa_hash_finish( &target_operation, PSA_ASSERT( psa_hash_finish( &target_operation,
output, PSA_HASH_LENGTH( alg ), output, PSA_HASH_LENGTH( alg ),
&output_length ) ); &output_length ) );
TEST_EQUAL( test_driver_hash_hooks.hits, 3 ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 3 );
TEST_EQUAL( test_driver_hash_hooks.driver_status, PSA_SUCCESS ); TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS );
ASSERT_COMPARE( output, output_length, hash->x, hash->len ); ASSERT_COMPARE( output, output_length, hash->x, hash->len );
} }
@ -1241,6 +1261,6 @@ exit:
psa_hash_abort( &target_operation ); psa_hash_abort( &target_operation );
mbedtls_free( output ); mbedtls_free( output );
PSA_DONE( ); PSA_DONE( );
test_driver_hash_hooks = test_driver_hash_hooks_init(); mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
} }
/* END_CASE */ /* END_CASE */

View file

@ -234,9 +234,9 @@
<ClInclude Include="..\..\tests\include\test\drivers\cipher.h" /> <ClInclude Include="..\..\tests\include\test\drivers\cipher.h" />
<ClInclude Include="..\..\tests\include\test\drivers\hash.h" /> <ClInclude Include="..\..\tests\include\test\drivers\hash.h" />
<ClInclude Include="..\..\tests\include\test\drivers\key_management.h" /> <ClInclude Include="..\..\tests\include\test\drivers\key_management.h" />
<ClInclude Include="..\..\tests\include\test\drivers\mbedtls_test_driver.h" />
<ClInclude Include="..\..\tests\include\test\drivers\signature.h" /> <ClInclude Include="..\..\tests\include\test\drivers\signature.h" />
<ClInclude Include="..\..\tests\include\test\drivers\size.h" /> <ClInclude Include="..\..\tests\include\test\drivers\size.h" />
<ClInclude Include="..\..\tests\include\test\drivers\test_driver.h" />
<ClInclude Include="..\..\library\aesni.h" /> <ClInclude Include="..\..\library\aesni.h" />
<ClInclude Include="..\..\library\bn_mul.h" /> <ClInclude Include="..\..\library\bn_mul.h" />
<ClInclude Include="..\..\library\check_crypto_config.h" /> <ClInclude Include="..\..\library\check_crypto_config.h" />
@ -375,6 +375,8 @@
<ClCompile Include="..\..\tests\src\psa_exercise_key.c" /> <ClCompile Include="..\..\tests\src\psa_exercise_key.c" />
<ClCompile Include="..\..\tests\src\random.c" /> <ClCompile Include="..\..\tests\src\random.c" />
<ClCompile Include="..\..\tests\src\threading_helpers.c" /> <ClCompile Include="..\..\tests\src\threading_helpers.c" />
<ClCompile Include="..\..\tests\src\drivers\hash.c" />
<ClCompile Include="..\..\tests\src\drivers\key_management.c" />
<ClCompile Include="..\..\tests\src\drivers\platform_builtin_keys.c" /> <ClCompile Include="..\..\tests\src\drivers\platform_builtin_keys.c" />
<ClCompile Include="..\..\tests\src\drivers\test_driver_aead.c" /> <ClCompile Include="..\..\tests\src\drivers\test_driver_aead.c" />
<ClCompile Include="..\..\tests\src\drivers\test_driver_cipher.c" /> <ClCompile Include="..\..\tests\src\drivers\test_driver_cipher.c" />