diff --git a/library/psa_crypto_driver_wrappers.c b/library/psa_crypto_driver_wrappers.c index 11160d82d..9bef02cd0 100644 --- a/library/psa_crypto_driver_wrappers.c +++ b/library/psa_crypto_driver_wrappers.c @@ -101,7 +101,7 @@ psa_status_t psa_driver_wrapper_sign_hash( * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #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_size, alg, @@ -130,15 +130,15 @@ psa_status_t psa_driver_wrapper_sign_hash( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TEST_DRIVER_LOCATION: - return( test_opaque_signature_sign_hash( attributes, - key_buffer, - key_buffer_size, - alg, - hash, - hash_length, - signature, - signature_size, - signature_length ) ); + return( mbedtls_test_opaque_signature_sign_hash( attributes, + key_buffer, + key_buffer_size, + alg, + hash, + hash_length, + signature, + signature_size, + signature_length ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ default: @@ -185,14 +185,15 @@ psa_status_t psa_driver_wrapper_verify_hash( * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) - status = test_transparent_signature_verify_hash( attributes, - key_buffer, - key_buffer_size, - alg, - hash, - hash_length, - signature, - signature_length ); + status = mbedtls_test_transparent_signature_verify_hash( + attributes, + key_buffer, + key_buffer_size, + alg, + hash, + hash_length, + signature, + signature_length ); /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); @@ -212,14 +213,14 @@ psa_status_t psa_driver_wrapper_verify_hash( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TEST_DRIVER_LOCATION: - return( test_opaque_signature_verify_hash( attributes, - key_buffer, - key_buffer_size, - alg, - hash, - hash_length, - signature, - signature_length ) ); + return( mbedtls_test_opaque_signature_verify_hash( attributes, + key_buffer, + key_buffer_size, + alg, + hash, + hash_length, + signature, + signature_length ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ default: @@ -267,37 +268,9 @@ psa_status_t psa_driver_wrapper_get_key_buffer_size( return( PSA_SUCCESS ); } #endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */ -#ifdef TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION - *key_buffer_size = test_size_function( key_type, key_bits ); - return( PSA_SUCCESS ); -#else /* TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION */ - if( PSA_KEY_TYPE_IS_KEY_PAIR( key_type ) ) - { - int public_key_overhead = - ( ( TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY == 1 ) ? - PSA_EXPORT_KEY_OUTPUT_SIZE( key_type, key_bits ) : 0 ); - *key_buffer_size = TEST_DRIVER_KEY_CONTEXT_BASE_SIZE - + TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE - + public_key_overhead; - } - else if( PSA_KEY_TYPE_IS_PUBLIC_KEY( key_type ) ) - { - *key_buffer_size = TEST_DRIVER_KEY_CONTEXT_BASE_SIZE - + TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE; - } - else if ( !PSA_KEY_TYPE_IS_KEY_PAIR( key_type ) && - !PSA_KEY_TYPE_IS_PUBLIC_KEY ( key_type ) ) - { - *key_buffer_size = TEST_DRIVER_KEY_CONTEXT_BASE_SIZE - + TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR - * ( ( key_bits + 7 ) / 8 ); - } - else - { - return( PSA_ERROR_NOT_SUPPORTED ); - } - return( PSA_SUCCESS ); -#endif /* TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION */ + *key_buffer_size = mbedtls_test_size_function( key_type, key_bits ); + return( ( *key_buffer_size != 0 ) ? + PSA_SUCCESS : PSA_ERROR_NOT_SUPPORTED ); #endif /* PSA_CRYPTO_DRIVER_TEST */ default: @@ -345,7 +318,7 @@ psa_status_t psa_driver_wrapper_generate_key( { /* Cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_DRIVER_TEST) - status = test_transparent_generate_key( + status = mbedtls_test_transparent_generate_key( attributes, key_buffer, key_buffer_size, key_buffer_length ); /* Declared with fallback == true */ @@ -364,7 +337,7 @@ psa_status_t psa_driver_wrapper_generate_key( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) 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 ); break; #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -428,10 +401,11 @@ psa_status_t psa_driver_wrapper_import_key( * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) - status = test_transparent_import_key( attributes, - data, data_length, - key_buffer, key_buffer_size, - key_buffer_length, bits ); + status = mbedtls_test_transparent_import_key( + attributes, + data, data_length, + key_buffer, key_buffer_size, + key_buffer_length, bits ); /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); @@ -496,12 +470,12 @@ psa_status_t psa_driver_wrapper_export_key( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TEST_DRIVER_LOCATION: - return( test_opaque_export_key( attributes, - key_buffer, - key_buffer_size, - data, - data_size, - data_length ) ); + return( mbedtls_test_opaque_export_key( attributes, + key_buffer, + key_buffer_size, + data, + data_size, + data_length ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ default: @@ -547,12 +521,13 @@ psa_status_t psa_driver_wrapper_export_public_key( * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) - status = test_transparent_export_public_key( attributes, - key_buffer, - key_buffer_size, - data, - data_size, - data_length ); + status = mbedtls_test_transparent_export_public_key( + attributes, + key_buffer, + key_buffer_size, + data, + data_size, + data_length ); /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); @@ -570,12 +545,12 @@ psa_status_t psa_driver_wrapper_export_public_key( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TEST_DRIVER_LOCATION: - return( test_opaque_export_public_key( attributes, - key_buffer, - key_buffer_size, - data, - data_size, - data_length ) ); + return( mbedtls_test_opaque_export_public_key( attributes, + key_buffer, + key_buffer_size, + data, + data_size, + data_length ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ default: @@ -594,7 +569,7 @@ psa_status_t psa_driver_wrapper_get_builtin_key( { #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TEST_DRIVER_LOCATION: - return( test_opaque_get_builtin_key( + return( mbedtls_test_opaque_get_builtin_key( slot_number, attributes, key_buffer, key_buffer_size, key_buffer_length ) ); @@ -633,15 +608,15 @@ psa_status_t psa_driver_wrapper_cipher_encrypt( /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_DRIVER_TEST) - status = test_transparent_cipher_encrypt( &attributes, - slot->key.data, - slot->key.bytes, - alg, - input, - input_length, - output, - output_size, - output_length ); + status = mbedtls_test_transparent_cipher_encrypt( &attributes, + slot->key.data, + slot->key.bytes, + alg, + input, + input_length, + output, + output_size, + output_length ); /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); @@ -651,15 +626,15 @@ psa_status_t psa_driver_wrapper_cipher_encrypt( /* Add cases for opaque driver here */ #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TEST_DRIVER_LOCATION: - return( test_opaque_cipher_encrypt( &attributes, - slot->key.data, - slot->key.bytes, - alg, - input, - input_length, - output, - output_size, - output_length ) ); + return( mbedtls_test_opaque_cipher_encrypt( &attributes, + slot->key.data, + slot->key.bytes, + alg, + input, + input_length, + output, + output_size, + output_length ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ default: /* Key is declared with a lifetime not known to us */ @@ -700,15 +675,15 @@ psa_status_t psa_driver_wrapper_cipher_decrypt( /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_DRIVER_TEST) - status = test_transparent_cipher_decrypt( &attributes, - slot->key.data, - slot->key.bytes, - alg, - input, - input_length, - output, - output_size, - output_length ); + status = mbedtls_test_transparent_cipher_decrypt( &attributes, + slot->key.data, + slot->key.bytes, + alg, + input, + input_length, + output, + output_size, + output_length ); /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); @@ -718,15 +693,15 @@ psa_status_t psa_driver_wrapper_cipher_decrypt( /* Add cases for opaque driver here */ #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TEST_DRIVER_LOCATION: - return( test_opaque_cipher_decrypt( &attributes, - slot->key.data, - slot->key.bytes, - alg, - input, - input_length, - output, - output_size, - output_length ) ); + return( mbedtls_test_opaque_cipher_decrypt( &attributes, + slot->key.data, + slot->key.bytes, + alg, + input, + input_length, + output, + output_size, + output_length ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ default: /* Key is declared with a lifetime not known to us */ @@ -762,7 +737,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt_setup( * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #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, attributes, key_buffer, @@ -795,7 +770,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt_setup( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) 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, attributes, key_buffer, key_buffer_size, @@ -834,7 +809,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt_setup( * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #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, attributes, key_buffer, @@ -866,7 +841,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt_setup( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) 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, attributes, key_buffer, key_buffer_size, @@ -905,12 +880,12 @@ psa_status_t psa_driver_wrapper_cipher_set_iv( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) 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, iv, iv_length ) ); 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, iv, iv_length ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -946,13 +921,13 @@ psa_status_t psa_driver_wrapper_cipher_update( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: - return( test_transparent_cipher_update( + return( mbedtls_test_transparent_cipher_update( &operation->ctx.transparent_test_driver_ctx, input, input_length, output, output_size, output_length ) ); case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: - return( test_opaque_cipher_update( + return( mbedtls_test_opaque_cipher_update( &operation->ctx.opaque_test_driver_ctx, input, input_length, output, output_size, output_length ) ); @@ -988,12 +963,12 @@ psa_status_t psa_driver_wrapper_cipher_finish( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: - return( test_transparent_cipher_finish( + return( mbedtls_test_transparent_cipher_finish( &operation->ctx.transparent_test_driver_ctx, output, output_size, output_length ) ); case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: - return( test_opaque_cipher_finish( + return( mbedtls_test_opaque_cipher_finish( &operation->ctx.opaque_test_driver_ctx, output, output_size, output_length ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -1022,7 +997,7 @@ psa_status_t psa_driver_wrapper_cipher_abort( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: - status = test_transparent_cipher_abort( + status = mbedtls_test_transparent_cipher_abort( &operation->ctx.transparent_test_driver_ctx ); mbedtls_platform_zeroize( &operation->ctx.transparent_test_driver_ctx, @@ -1030,7 +1005,7 @@ psa_status_t psa_driver_wrapper_cipher_abort( return( status ); case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: - status = test_opaque_cipher_abort( + status = mbedtls_test_opaque_cipher_abort( &operation->ctx.opaque_test_driver_ctx ); mbedtls_platform_zeroize( &operation->ctx.opaque_test_driver_ctx, @@ -1059,7 +1034,7 @@ psa_status_t psa_driver_wrapper_hash_compute( /* Try accelerators first */ #if defined(PSA_CRYPTO_DRIVER_TEST) - status = mbedtls_transparent_test_driver_hash_compute( + status = mbedtls_test_transparent_hash_compute( alg, input, input_length, hash, hash_size, hash_length ); if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); @@ -1091,7 +1066,7 @@ psa_status_t psa_driver_wrapper_hash_setup( /* Try setup on accelerators first */ #if defined(PSA_CRYPTO_DRIVER_TEST) - status = mbedtls_transparent_test_driver_hash_setup( + status = mbedtls_test_transparent_hash_setup( &operation->ctx.test_driver_ctx, alg ); if( status == PSA_SUCCESS ) operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; @@ -1131,7 +1106,7 @@ psa_status_t psa_driver_wrapper_hash_clone( #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: target_operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; - return( mbedtls_transparent_test_driver_hash_clone( + return( mbedtls_test_transparent_hash_clone( &source_operation->ctx.test_driver_ctx, &target_operation->ctx.test_driver_ctx ) ); #endif @@ -1155,7 +1130,7 @@ psa_status_t psa_driver_wrapper_hash_update( #endif #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: - return( mbedtls_transparent_test_driver_hash_update( + return( mbedtls_test_transparent_hash_update( &operation->ctx.test_driver_ctx, input, input_length ) ); #endif @@ -1181,7 +1156,7 @@ psa_status_t psa_driver_wrapper_hash_finish( #endif #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: - return( mbedtls_transparent_test_driver_hash_finish( + return( mbedtls_test_transparent_hash_finish( &operation->ctx.test_driver_ctx, hash, hash_size, hash_length ) ); #endif @@ -1204,7 +1179,7 @@ psa_status_t psa_driver_wrapper_hash_abort( #endif #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: - return( mbedtls_transparent_test_driver_hash_abort( + return( mbedtls_test_transparent_hash_abort( &operation->ctx.test_driver_ctx ) ); #endif default: @@ -1233,7 +1208,7 @@ psa_status_t psa_driver_wrapper_aead_encrypt( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) - status = test_transparent_aead_encrypt( + status = mbedtls_test_transparent_aead_encrypt( attributes, key_buffer, key_buffer_size, alg, nonce, nonce_length, @@ -1285,7 +1260,7 @@ psa_status_t psa_driver_wrapper_aead_decrypt( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) - status = test_transparent_aead_decrypt( + status = mbedtls_test_transparent_aead_decrypt( attributes, key_buffer, key_buffer_size, alg, nonce, nonce_length, diff --git a/tests/include/test/drivers/aead.h b/tests/include/test/drivers/aead.h index 1be8910a3..2207cb36f 100644 --- a/tests/include/test/drivers/aead.h +++ b/tests/include/test/drivers/aead.h @@ -37,18 +37,19 @@ typedef struct { unsigned long hits; /* Status returned by the last AEAD driver function call. */ psa_status_t driver_status; -} test_driver_aead_hooks_t; +} mbedtls_test_driver_aead_hooks_t; -#define TEST_DRIVER_AEAD_INIT { 0, 0, 0 } -static inline test_driver_aead_hooks_t test_driver_aead_hooks_init( void ) +#define MBEDTLS_TEST_DRIVER_AEAD_INIT { 0, 0, 0 } +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 ); } -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 uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, @@ -57,7 +58,7 @@ psa_status_t test_transparent_aead_encrypt( const uint8_t *plaintext, size_t plaintext_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 uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, diff --git a/tests/include/test/drivers/cipher.h b/tests/include/test/drivers/cipher.h index 6d6a6af42..4fe559618 100644 --- a/tests/include/test/drivers/cipher.h +++ b/tests/include/test/drivers/cipher.h @@ -41,101 +41,102 @@ typedef struct { psa_status_t forced_status; /* Count the amount of times one of the cipher driver functions is called. */ unsigned long hits; -} test_driver_cipher_hooks_t; +} mbedtls_test_driver_cipher_hooks_t; -#define TEST_DRIVER_CIPHER_INIT { NULL, 0, PSA_SUCCESS, 0 } -static inline test_driver_cipher_hooks_t test_driver_cipher_hooks_init( void ) +#define MBEDTLS_TEST_DRIVER_CIPHER_INIT { NULL, 0, PSA_SUCCESS, 0 } +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 ); } -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 uint8_t *key, size_t key_length, psa_algorithm_t alg, const uint8_t *input, size_t input_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 uint8_t *key, size_t key_length, psa_algorithm_t alg, const uint8_t *input, size_t input_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, const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, 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, const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, 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 ); -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, 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, const uint8_t *input, size_t input_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, uint8_t *output, size_t output_size, size_t *output_length); /* * opaque versions */ -psa_status_t test_opaque_cipher_encrypt( +psa_status_t mbedtls_test_opaque_cipher_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, psa_algorithm_t alg, const uint8_t *input, size_t input_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 uint8_t *key, size_t key_length, psa_algorithm_t alg, const uint8_t *input, size_t input_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, const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, 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, const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, 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); -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, 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, const uint8_t *input, size_t input_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, uint8_t *output, size_t output_size, size_t *output_length); diff --git a/tests/include/test/drivers/hash.h b/tests/include/test/drivers/hash.h new file mode 100644 index 000000000..ebe83dee4 --- /dev/null +++ b/tests/include/test/drivers/hash.h @@ -0,0 +1,80 @@ +/* + * Test driver for hash driver entry points. + */ +/* Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PSA_CRYPTO_TEST_DRIVERS_HASH_H +#define PSA_CRYPTO_TEST_DRIVERS_HASH_H + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#if defined(PSA_CRYPTO_DRIVER_TEST) +#include + +typedef struct { + /* If not PSA_SUCCESS, return this error code instead of processing the + * function call. */ + psa_status_t forced_status; + /* Count the amount of times hash driver entry points are called. */ + unsigned long hits; + /* Status returned by the last hash driver entry point call. */ + psa_status_t driver_status; +} mbedtls_test_driver_hash_hooks_t; + +#define MBEDTLS_TEST_DRIVER_HASH_INIT { 0, 0, 0 } +static inline mbedtls_test_driver_hash_hooks_t + mbedtls_test_driver_hash_hooks_init( void ) +{ + const mbedtls_test_driver_hash_hooks_t v = MBEDTLS_TEST_DRIVER_HASH_INIT; + return( v ); +} + +extern mbedtls_test_driver_hash_hooks_t mbedtls_test_driver_hash_hooks; + +psa_status_t mbedtls_test_transparent_hash_compute( + psa_algorithm_t alg, + const uint8_t *input, size_t input_length, + uint8_t *hash, size_t hash_size, size_t *hash_length ); + +psa_status_t mbedtls_test_transparent_hash_setup( + mbedtls_transparent_test_driver_hash_operation_t *operation, + psa_algorithm_t alg ); + +psa_status_t mbedtls_test_transparent_hash_clone( + const mbedtls_transparent_test_driver_hash_operation_t *source_operation, + mbedtls_transparent_test_driver_hash_operation_t *target_operation ); + +psa_status_t mbedtls_test_transparent_hash_update( + mbedtls_transparent_test_driver_hash_operation_t *operation, + const uint8_t *input, + size_t input_length ); + +psa_status_t mbedtls_test_transparent_hash_finish( + mbedtls_transparent_test_driver_hash_operation_t *operation, + uint8_t *hash, + size_t hash_size, + size_t *hash_length ); + +psa_status_t mbedtls_test_transparent_hash_abort( + mbedtls_psa_hash_operation_t *operation ); + +#endif /* PSA_CRYPTO_DRIVER_TEST */ +#endif /* PSA_CRYPTO_TEST_DRIVERS_HASH_H */ diff --git a/tests/include/test/drivers/key_management.h b/tests/include/test/drivers/key_management.h index 100fc18d3..45814fd03 100644 --- a/tests/include/test/drivers/key_management.h +++ b/tests/include/test/drivers/key_management.h @@ -42,41 +42,44 @@ typedef struct { /* Count the amount of times one of the key management driver functions * is called. */ 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 } -static inline test_driver_key_management_hooks_t test_driver_key_management_hooks_init( void ) +#define MBEDTLS_TEST_DRIVER_KEY_MANAGEMENT_INIT { NULL, 0, PSA_SUCCESS, 0 } +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 ); } -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, 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, 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 uint8_t *key, size_t key_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 uint8_t *key, size_t key_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 uint8_t *key, size_t key_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 uint8_t *data, size_t data_length, @@ -85,7 +88,7 @@ psa_status_t test_transparent_import_key( size_t *key_buffer_length, 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_key_attributes_t *attributes, uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ); diff --git a/tests/include/test/drivers/signature.h b/tests/include/test/drivers/signature.h index e78515125..1586ce9bc 100644 --- a/tests/include/test/drivers/signature.h +++ b/tests/include/test/drivers/signature.h @@ -38,40 +38,44 @@ typedef struct { psa_status_t forced_status; /* Count the amount of times one of the signature driver functions is called. */ unsigned long hits; -} test_driver_signature_hooks_t; +} mbedtls_test_driver_signature_hooks_t; -#define TEST_DRIVER_SIGNATURE_INIT { NULL, 0, PSA_SUCCESS, 0 } -static inline test_driver_signature_hooks_t test_driver_signature_hooks_init( void ) +#define MBEDTLS_TEST_DRIVER_SIGNATURE_INIT { NULL, 0, PSA_SUCCESS, 0 } +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 ); } -extern test_driver_signature_hooks_t test_driver_signature_sign_hooks; -extern test_driver_signature_hooks_t test_driver_signature_verify_hooks; +extern mbedtls_test_driver_signature_hooks_t + 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 uint8_t *key, size_t key_length, psa_algorithm_t alg, const uint8_t *hash, size_t hash_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 uint8_t *key, size_t key_length, psa_algorithm_t alg, const uint8_t *hash, size_t hash_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 uint8_t *key, size_t key_length, psa_algorithm_t alg, const uint8_t *hash, size_t hash_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 uint8_t *key, size_t key_length, psa_algorithm_t alg, diff --git a/tests/include/test/drivers/size.h b/tests/include/test/drivers/size.h index 4bfe986a2..b2665bdda 100644 --- a/tests/include/test/drivers/size.h +++ b/tests/include/test/drivers/size.h @@ -29,67 +29,9 @@ #if defined(PSA_CRYPTO_DRIVER_TEST) #include -typedef struct { - unsigned int context; -} test_driver_key_context_t; - -/** \def TEST_DRIVER_KEY_CONTEXT_BASE_SIZE - * - * This macro returns the base size for the key context. It is the size of the - * driver specific information stored in each key context. - */ -#define TEST_DRIVER_KEY_CONTEXT_BASE_SIZE sizeof( test_driver_key_context_t ) - -/** \def TEST_DRIVER_KEY_CONTEXT_KEY_PAIR_SIZE - * - * Number of bytes included in every key context for a key pair. - * - * This pair size is for an ECC 256-bit private/public key pair. - * Based on this value, the size of the private key can be derived by - * subtracting the public key size below from this one. - */ - -#define TEST_DRIVER_KEY_CONTEXT_KEY_PAIR_SIZE 65 - -/** \def TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE - * - * Number of bytes included in every key context for a public key. - * - * For ECC public keys, it needs 257 bits so 33 bytes. - */ -#define TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE 33 - -/** \def TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR - * - * Every key context for a symmetric key includes this many times the key size. - */ -#define TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR 0 - -/** \def 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 false, no additional space is added for the public key. - * - * For this instance, store the public key with the private one. - */ -#define TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY 1 - -/** \def TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION - * - * If TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION is defined, the test driver - * provides a size_function entry point, otherwise, it does not. - * - * 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 - * provide that customization. - */ -//#define TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION - -#ifdef 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 size_t key_bits ); -#endif /* TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION */ #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_TEST_DRIVERS_SIZE_H */ diff --git a/tests/include/test/drivers/test_driver.h b/tests/include/test/drivers/test_driver.h index 84d0caa5e..dc2136a6a 100644 --- a/tests/include/test/drivers/test_driver.h +++ b/tests/include/test/drivers/test_driver.h @@ -23,9 +23,10 @@ #define PSA_CRYPTO_TEST_DRIVER_LOCATION 0x7fffff #include "test/drivers/aead.h" -#include "test/drivers/signature.h" -#include "test/drivers/key_management.h" #include "test/drivers/cipher.h" +#include "test/drivers/hash.h" +#include "test/drivers/key_management.h" +#include "test/drivers/signature.h" #include "test/drivers/size.h" #endif /* PSA_CRYPTO_TEST_DRIVER_H */ diff --git a/tests/scripts/list-macros.sh b/tests/scripts/list-macros.sh index 2727ff9d5..fd19c471b 100755 --- a/tests/scripts/list-macros.sh +++ b/tests/scripts/list-macros.sh @@ -22,7 +22,7 @@ if [ -d include/mbedtls ]; then :; else exit 1 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 3rdparty/everest/include/everest/everest.h 3rdparty/everest/include/everest/x25519.h" diff --git a/tests/src/drivers/hash.c b/tests/src/drivers/hash.c new file mode 100644 index 000000000..f95aa6b61 --- /dev/null +++ b/tests/src/drivers/hash.c @@ -0,0 +1,161 @@ +/* + * Test driver for hash entry points. + */ +/* Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST) +#include "psa_crypto_hash.h" + +#include "test/drivers/hash.h" + +mbedtls_test_driver_hash_hooks_t + mbedtls_test_driver_hash_hooks = MBEDTLS_TEST_DRIVER_HASH_INIT; + +psa_status_t mbedtls_test_transparent_hash_compute( + psa_algorithm_t alg, + const uint8_t *input, size_t input_length, + uint8_t *hash, size_t hash_size, size_t *hash_length ) +{ + mbedtls_test_driver_hash_hooks.hits++; + + if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS ) + { + mbedtls_test_driver_hash_hooks.driver_status = + mbedtls_test_driver_hash_hooks.forced_status; + } + else + { + mbedtls_test_driver_hash_hooks.driver_status = + mbedtls_transparent_test_driver_hash_compute( + alg, input, input_length, + hash, hash_size, hash_length ); + } + + return( mbedtls_test_driver_hash_hooks.driver_status ); +} + +psa_status_t mbedtls_test_transparent_hash_setup( + mbedtls_transparent_test_driver_hash_operation_t *operation, + psa_algorithm_t alg ) +{ + mbedtls_test_driver_hash_hooks.hits++; + + if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS ) + { + mbedtls_test_driver_hash_hooks.driver_status = + mbedtls_test_driver_hash_hooks.forced_status; + } + else + { + mbedtls_test_driver_hash_hooks.driver_status = + mbedtls_transparent_test_driver_hash_setup( operation, alg ); + } + + return( mbedtls_test_driver_hash_hooks.driver_status ); +} + +psa_status_t mbedtls_test_transparent_hash_clone( + const mbedtls_transparent_test_driver_hash_operation_t *source_operation, + mbedtls_transparent_test_driver_hash_operation_t *target_operation ) +{ + mbedtls_test_driver_hash_hooks.hits++; + + if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS ) + { + mbedtls_test_driver_hash_hooks.driver_status = + mbedtls_test_driver_hash_hooks.forced_status; + } + else + { + mbedtls_test_driver_hash_hooks.driver_status = + mbedtls_transparent_test_driver_hash_clone( source_operation, + target_operation ); + } + + return( mbedtls_test_driver_hash_hooks.driver_status ); +} + +psa_status_t mbedtls_test_transparent_hash_update( + mbedtls_transparent_test_driver_hash_operation_t *operation, + const uint8_t *input, + size_t input_length ) +{ + mbedtls_test_driver_hash_hooks.hits++; + + if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS ) + { + mbedtls_test_driver_hash_hooks.driver_status = + mbedtls_test_driver_hash_hooks.forced_status; + } + else + { + mbedtls_test_driver_hash_hooks.driver_status = + mbedtls_transparent_test_driver_hash_update( + operation, input, input_length ); + } + + return( mbedtls_test_driver_hash_hooks.driver_status ); +} + +psa_status_t mbedtls_test_transparent_hash_finish( + mbedtls_transparent_test_driver_hash_operation_t *operation, + uint8_t *hash, + size_t hash_size, + size_t *hash_length ) +{ + mbedtls_test_driver_hash_hooks.hits++; + + if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS ) + { + mbedtls_test_driver_hash_hooks.driver_status = + mbedtls_test_driver_hash_hooks.forced_status; + } + else + { + mbedtls_test_driver_hash_hooks.driver_status = + mbedtls_transparent_test_driver_hash_finish( + operation, hash, hash_size, hash_length ); + } + + return( mbedtls_test_driver_hash_hooks.driver_status ); +} + +psa_status_t mbedtls_test_transparent_hash_abort( + mbedtls_transparent_test_driver_hash_operation_t *operation ) +{ + mbedtls_test_driver_hash_hooks.hits++; + + if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS ) + { + mbedtls_test_driver_hash_hooks.driver_status = + mbedtls_test_driver_hash_hooks.forced_status; + } + else + { + mbedtls_test_driver_hash_hooks.driver_status = + mbedtls_transparent_test_driver_hash_abort( operation ); + } + + return( mbedtls_test_driver_hash_hooks.driver_status ); +} +#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ diff --git a/tests/src/drivers/test_driver_aead.c b/tests/src/drivers/test_driver_aead.c index c87752502..25396c92f 100644 --- a/tests/src/drivers/test_driver_aead.c +++ b/tests/src/drivers/test_driver_aead.c @@ -28,9 +28,10 @@ #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 uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, @@ -39,16 +40,16 @@ psa_status_t test_transparent_aead_encrypt( const uint8_t *plaintext, size_t plaintext_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 = - test_driver_aead_hooks.forced_status; + mbedtls_test_driver_aead_hooks.driver_status = + mbedtls_test_driver_aead_hooks.forced_status; } else { - test_driver_aead_hooks.driver_status = + mbedtls_test_driver_aead_hooks.driver_status = mbedtls_psa_aead_encrypt( attributes, key_buffer, key_buffer_size, alg, @@ -58,10 +59,10 @@ psa_status_t test_transparent_aead_encrypt( 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 uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, @@ -70,16 +71,16 @@ psa_status_t test_transparent_aead_decrypt( const uint8_t *ciphertext, size_t ciphertext_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 = - test_driver_aead_hooks.forced_status; + mbedtls_test_driver_aead_hooks.driver_status = + mbedtls_test_driver_aead_hooks.forced_status; } else { - test_driver_aead_hooks.driver_status = + mbedtls_test_driver_aead_hooks.driver_status = mbedtls_psa_aead_decrypt( attributes, key_buffer, key_buffer_size, alg, @@ -89,7 +90,7 @@ psa_status_t test_transparent_aead_decrypt( 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 */ diff --git a/tests/src/drivers/test_driver_cipher.c b/tests/src/drivers/test_driver_cipher.c index 4dc46789b..a415dd812 100644 --- a/tests/src/drivers/test_driver_cipher.c +++ b/tests/src/drivers/test_driver_cipher.c @@ -36,14 +36,10 @@ #include -/* Test driver implements AES-CTR only. Its default behaviour (when its return - * status is not overridden through the hooks) is to take care of all AES-CTR - * operations, and return PSA_ERROR_NOT_SUPPORTED for all others. - * Set test_driver_cipher_hooks.forced_status to PSA_ERROR_NOT_SUPPORTED to use - * fallback even for AES-CTR. */ -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, const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, @@ -51,7 +47,7 @@ static psa_status_t test_transparent_cipher_oneshot( const uint8_t *input, size_t input_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. */ if( alg != PSA_ALG_CTR || @@ -59,21 +55,21 @@ static psa_status_t test_transparent_cipher_oneshot( return( PSA_ERROR_NOT_SUPPORTED ); /* If test driver response code is not SUCCESS, we can return early */ - if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) - return( test_driver_cipher_hooks.forced_status ); + if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) + 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_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 ); memcpy( output, - test_driver_cipher_hooks.forced_output, - test_driver_cipher_hooks.forced_output_length ); - *output_length = test_driver_cipher_hooks.forced_output_length; + mbedtls_test_driver_cipher_hooks.forced_output, + mbedtls_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 */ @@ -171,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 uint8_t *key, size_t key_length, psa_algorithm_t alg, @@ -179,7 +175,7 @@ psa_status_t test_transparent_cipher_encrypt( uint8_t *output, size_t output_size, size_t *output_length) { return ( - test_transparent_cipher_oneshot( + mbedtls_test_transparent_cipher_oneshot( MBEDTLS_ENCRYPT, attributes, key, key_length, @@ -188,7 +184,7 @@ psa_status_t test_transparent_cipher_encrypt( 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 uint8_t *key, size_t key_length, psa_algorithm_t alg, @@ -196,7 +192,7 @@ psa_status_t test_transparent_cipher_decrypt( uint8_t *output, size_t output_size, size_t *output_length) { return ( - test_transparent_cipher_oneshot( + mbedtls_test_transparent_cipher_oneshot( MBEDTLS_DECRYPT, attributes, key, key_length, @@ -205,13 +201,13 @@ psa_status_t test_transparent_cipher_decrypt( 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, const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, 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 * useful for the test suite, since it gives a chance of catching memory @@ -219,32 +215,32 @@ psa_status_t test_transparent_cipher_encrypt_setup( * our context struct. */ memset( operation, 0, sizeof( *operation ) ); - if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) - return( test_driver_cipher_hooks.forced_status ); + if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) + return( mbedtls_test_driver_cipher_hooks.forced_status ); return ( mbedtls_transparent_test_driver_cipher_encrypt_setup( 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, const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, psa_algorithm_t alg) { - test_driver_cipher_hooks.hits++; + mbedtls_test_driver_cipher_hooks.hits++; - if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) - return( test_driver_cipher_hooks.forced_status ); + if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) + return( mbedtls_test_driver_cipher_hooks.forced_status ); return ( mbedtls_transparent_test_driver_cipher_decrypt_setup( 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) { - test_driver_cipher_hooks.hits++; + mbedtls_test_driver_cipher_hooks.hits++; if( operation->alg == 0 ) return( PSA_SUCCESS ); @@ -257,24 +253,24 @@ psa_status_t test_transparent_cipher_abort( * our context struct. */ 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, const uint8_t *iv, size_t iv_length) { - test_driver_cipher_hooks.hits++; + mbedtls_test_driver_cipher_hooks.hits++; - if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) - return( test_driver_cipher_hooks.forced_status ); + if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) + return( mbedtls_test_driver_cipher_hooks.forced_status ); return( mbedtls_transparent_test_driver_cipher_set_iv( 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, const uint8_t *input, size_t input_length, @@ -282,52 +278,52 @@ psa_status_t test_transparent_cipher_update( size_t output_size, 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; memcpy( output, - test_driver_cipher_hooks.forced_output, - test_driver_cipher_hooks.forced_output_length ); - *output_length = test_driver_cipher_hooks.forced_output_length; + mbedtls_test_driver_cipher_hooks.forced_output, + mbedtls_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 ) - return( test_driver_cipher_hooks.forced_status ); + if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) + return( mbedtls_test_driver_cipher_hooks.forced_status ); return( mbedtls_transparent_test_driver_cipher_update( operation, input, input_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, uint8_t *output, size_t output_size, 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; memcpy( output, - test_driver_cipher_hooks.forced_output, - test_driver_cipher_hooks.forced_output_length ); - *output_length = test_driver_cipher_hooks.forced_output_length; + mbedtls_test_driver_cipher_hooks.forced_output, + mbedtls_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 ) - return( test_driver_cipher_hooks.forced_status ); + if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) + return( mbedtls_test_driver_cipher_hooks.forced_status ); return( mbedtls_transparent_test_driver_cipher_finish( operation, output, output_size, output_length ) ); @@ -336,7 +332,7 @@ psa_status_t test_transparent_cipher_finish( /* * 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 uint8_t *key, size_t key_length, psa_algorithm_t alg, @@ -355,7 +351,7 @@ psa_status_t test_opaque_cipher_encrypt( 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 uint8_t *key, size_t key_length, psa_algorithm_t alg, @@ -374,7 +370,7 @@ psa_status_t test_opaque_cipher_decrypt( 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, const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, @@ -388,7 +384,7 @@ psa_status_t test_opaque_cipher_encrypt_setup( 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, const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_length, @@ -402,14 +398,14 @@ psa_status_t test_opaque_cipher_decrypt_setup( 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 ) { (void) operation; 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, const uint8_t *iv, size_t iv_length) @@ -420,7 +416,7 @@ psa_status_t test_opaque_cipher_set_iv( 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, const uint8_t *input, size_t input_length, @@ -437,7 +433,7 @@ psa_status_t test_opaque_cipher_update( 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, uint8_t *output, size_t output_size, diff --git a/tests/src/drivers/test_driver_key_management.c b/tests/src/drivers/test_driver_key_management.c index a0626fbf4..19e103331 100644 --- a/tests/src/drivers/test_driver_key_management.c +++ b/tests/src/drivers/test_driver_key_management.c @@ -38,18 +38,18 @@ #include -test_driver_key_management_hooks_t test_driver_key_management_hooks = - TEST_DRIVER_KEY_MANAGEMENT_INIT; +mbedtls_test_driver_key_management_hooks_t + 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, 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, 0x2c, 0x34, 0xc2, 0xdc, 0x0b, 0x69, 0x86, 0x18, 0x38, 0x82, 0xc2, 0x06, 0xdf, 0x04, 0xcd, 0xb7, 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, 0x85, 0xf6, 0x4d, 0x89, 0xf0, 0x0b, 0xe6, 0x6c, 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, 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, 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 ) - return( test_driver_key_management_hooks.forced_status ); + if( mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS ) + 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 ); - memcpy( key, test_driver_key_management_hooks.forced_output, - test_driver_key_management_hooks.forced_output_length ); - *key_length = test_driver_key_management_hooks.forced_output_length; + memcpy( key, mbedtls_test_driver_key_management_hooks.forced_output, + mbedtls_test_driver_key_management_hooks.forced_output_length ); + *key_length = mbedtls_test_driver_key_management_hooks.forced_output_length; 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, 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 ); } -psa_status_t test_transparent_import_key( +psa_status_t mbedtls_test_transparent_import_key( const psa_key_attributes_t *attributes, const uint8_t *data, size_t data_length, @@ -122,10 +123,10 @@ psa_status_t test_transparent_import_key( size_t *key_buffer_length, 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 ) - return( test_driver_key_management_hooks.forced_status ); + if( mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS ) + return( mbedtls_test_driver_key_management_hooks.forced_status ); psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; psa_key_type_t type = psa_get_key_type( attributes ); @@ -168,7 +169,7 @@ psa_status_t test_transparent_import_key( return( status ); } -psa_status_t test_opaque_export_key( +psa_status_t mbedtls_test_opaque_export_key( const psa_key_attributes_t *attributes, const uint8_t *key, size_t key_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 ) 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 ); - memcpy( data, test_driver_ecdsa_key, - sizeof( test_driver_ecdsa_key ) ); - *data_length = sizeof( test_driver_ecdsa_key ); + memcpy( data, mbedtls_test_driver_ecdsa_key, + sizeof( mbedtls_test_driver_ecdsa_key ) ); + *data_length = sizeof( mbedtls_test_driver_ecdsa_key ); return( PSA_SUCCESS ); 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 ) 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 ); - memcpy( data, test_driver_aes_key, - sizeof( test_driver_aes_key ) ); - *data_length = sizeof( test_driver_aes_key ); + memcpy( data, mbedtls_test_driver_aes_key, + sizeof( mbedtls_test_driver_aes_key ) ); + *data_length = sizeof( mbedtls_test_driver_aes_key ); return( PSA_SUCCESS ); 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 uint8_t *key_buffer, size_t key_buffer_size, 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 ) - return( test_driver_key_management_hooks.forced_status ); + if( mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS ) + 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 ); - memcpy( data, test_driver_key_management_hooks.forced_output, - test_driver_key_management_hooks.forced_output_length ); - *data_length = test_driver_key_management_hooks.forced_output_length; + memcpy( data, mbedtls_test_driver_key_management_hooks.forced_output, + mbedtls_test_driver_key_management_hooks.forced_output_length ); + *data_length = mbedtls_test_driver_key_management_hooks.forced_output_length; return( PSA_SUCCESS ); } @@ -288,7 +290,7 @@ psa_status_t test_transparent_export_public_key( 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 uint8_t *key, size_t key_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 ) ) 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 ); - memcpy( data, test_driver_ecdsa_pubkey, - sizeof( test_driver_ecdsa_pubkey ) ); - *data_length = sizeof( test_driver_ecdsa_pubkey ); + memcpy( data, mbedtls_test_driver_ecdsa_pubkey, + sizeof( mbedtls_test_driver_ecdsa_pubkey ) ); + *data_length = sizeof( mbedtls_test_driver_ecdsa_pubkey ); return( PSA_SUCCESS ); 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' = * 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_key_attributes_t *attributes, uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ) diff --git a/tests/src/drivers/test_driver_signature.c b/tests/src/drivers/test_driver_signature.c index 47c6debc5..be8c1792b 100644 --- a/tests/src/drivers/test_driver_signature.c +++ b/tests/src/drivers/test_driver_signature.c @@ -41,28 +41,32 @@ #include -test_driver_signature_hooks_t test_driver_signature_sign_hooks = TEST_DRIVER_SIGNATURE_INIT; -test_driver_signature_hooks_t test_driver_signature_verify_hooks = TEST_DRIVER_SIGNATURE_INIT; +mbedtls_test_driver_signature_hooks_t + 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 uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *hash, size_t hash_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 ) - return( test_driver_signature_sign_hooks.forced_status ); + if( mbedtls_test_driver_signature_sign_hooks.forced_status != PSA_SUCCESS ) + 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 ); - memcpy( signature, test_driver_signature_sign_hooks.forced_output, - test_driver_signature_sign_hooks.forced_output_length ); - *signature_length = test_driver_signature_sign_hooks.forced_output_length; + memcpy( signature, + mbedtls_test_driver_signature_sign_hooks.forced_output, + mbedtls_test_driver_signature_sign_hooks.forced_output_length ); + *signature_length = mbedtls_test_driver_signature_sign_hooks.forced_output_length; 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 uint8_t *key, size_t key_length, psa_algorithm_t alg, @@ -140,17 +144,17 @@ psa_status_t test_opaque_signature_sign_hash( 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 uint8_t *key_buffer, size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *hash, size_t hash_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 ) - return( test_driver_signature_verify_hooks.forced_status ); + if( mbedtls_test_driver_signature_verify_hooks.forced_status != PSA_SUCCESS ) + return( mbedtls_test_driver_signature_verify_hooks.forced_status ); #if defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN) || \ 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 uint8_t *key, size_t key_length, psa_algorithm_t alg, diff --git a/tests/src/drivers/test_driver_size.c b/tests/src/drivers/test_driver_size.c index 16a86922a..d8bcaee38 100644 --- a/tests/src/drivers/test_driver_size.c +++ b/tests/src/drivers/test_driver_size.c @@ -27,16 +27,75 @@ #if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST) #include "test/drivers/size.h" +#include "psa/crypto.h" -#ifdef TEST_KEY_CONTEXT_SIZE_FUNCTION -size_t test_size_function( +typedef struct { + unsigned int context; +} test_driver_key_context_t; + +/* + * This macro returns the base size for the key context. It is the size of the + * driver specific information stored in each key context. + */ +#define TEST_DRIVER_KEY_CONTEXT_BASE_SIZE sizeof( test_driver_key_context_t ) + +/* + * Number of bytes included in every key context for a key pair. + * + * This pair size is for an ECC 256-bit private/public key pair. + * Based on this value, the size of the private key can be derived by + * subtracting the public key size below from this one. + */ +#define TEST_DRIVER_KEY_CONTEXT_KEY_PAIR_SIZE 65 + +/* + * Number of bytes included in every key context for a public key. + * + * For ECC public keys, it needs 257 bits so 33 bytes. + */ +#define TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE 33 + +/* + * Every key context for a symmetric key includes this many times the key size. + */ +#define TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR 0 + +/* + * 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. + * + * For this instance, store the public key with the private one. + */ +#define TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY 1 + +size_t mbedtls_test_size_function( const psa_key_type_t key_type, const size_t key_bits ) { - (void) key_type; - (void) key_bits; - return 0; -} -#endif /*TEST_KEY_CONTEXT_SIZE_FUNCTION */ + size_t key_buffer_size = 0; + if( PSA_KEY_TYPE_IS_KEY_PAIR( key_type ) ) + { + int public_key_overhead = + ( ( TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY == 1 ) + ? PSA_EXPORT_KEY_OUTPUT_SIZE( key_type, key_bits ) : 0 ); + key_buffer_size = TEST_DRIVER_KEY_CONTEXT_BASE_SIZE + + TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE + + public_key_overhead; + } + else if( PSA_KEY_TYPE_IS_PUBLIC_KEY( key_type ) ) + { + key_buffer_size = TEST_DRIVER_KEY_CONTEXT_BASE_SIZE + + TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE; + } + else if ( !PSA_KEY_TYPE_IS_KEY_PAIR( key_type ) && + !PSA_KEY_TYPE_IS_PUBLIC_KEY ( key_type ) ) + { + key_buffer_size = TEST_DRIVER_KEY_CONTEXT_BASE_SIZE + + ( TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR * + ( ( key_bits + 7 ) / 8 ) ); + } + + return( key_buffer_size ); +} #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.data b/tests/suites/test_suite_psa_crypto_driver_wrappers.data index 251388378..5fbfac66a 100644 --- a/tests/suites/test_suite_psa_crypto_driver_wrappers.data +++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.data @@ -267,3 +267,57 @@ builtin_pubkey_export:MBEDTLS_PSA_KEY_ID_BUILTIN_MIN + 1:PSA_KEY_TYPE_ECC_KEY_PA PSA opaque driver builtin pubkey export: not a public key builtin_pubkey_export:MBEDTLS_PSA_KEY_ID_BUILTIN_MIN:PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1):256:PSA_ALG_ECDSA(PSA_ALG_ANY_HASH):"0485f64d89f00be66c88dd937efd6d7c445648dcb701150b8a9509295850f41c1931e571fb8f8c78317a20b380e866584bbc2516c3d2702d792f131a922095fd6c":PSA_ERROR_INVALID_ARGUMENT + +Hash compute: SHA-256, computed by the driver +depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 +hash_compute:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_SUCCESS:PSA_SUCCESS + +Hash compute: SHA-256, fallback +depends_on:MBEDTLS_PSA_BUILTIN_ALG_SHA_256 +hash_compute:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED:PSA_SUCCESS + +Hash compute: SHA-256, no fallback +depends_on:!MBEDTLS_PSA_BUILTIN_ALG_SHA_256 +hash_compute:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED:PSA_ERROR_NOT_SUPPORTED + +Hash compute: SHA-256, INSUFFICIENT_MEMORY +hash_compute:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_INSUFFICIENT_MEMORY:PSA_ERROR_INSUFFICIENT_MEMORY + +Hash multi-part setup: SHA-256, computed by the driver +depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 +hash_multipart_setup:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_SUCCESS:PSA_SUCCESS + +Hash multi-part setup: SHA-256, fallback +depends_on:MBEDTLS_PSA_BUILTIN_ALG_SHA_256 +hash_multipart_setup:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED:PSA_SUCCESS + +Hash multi-part setup: SHA-256, no fallback +depends_on:!MBEDTLS_PSA_BUILTIN_ALG_SHA_256 +hash_multipart_setup:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED:PSA_ERROR_NOT_SUPPORTED + +Hash multi-part setup: SHA-256, INSUFFICIENT_MEMORY +hash_multipart_setup:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_INSUFFICIENT_MEMORY:PSA_ERROR_INSUFFICIENT_MEMORY + +Hash multi-part update: SHA-256, update successful +depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 +hash_multipart_update:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_SUCCESS + +Hash multi-part update: SHA-256, update failure +depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 +hash_multipart_update:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED + +Hash multi-part finish: SHA-256, finish successful +depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 +hash_multipart_update:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_SUCCESS + +Hash multi-part finish: SHA-256, finish failure +depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 +hash_multipart_update:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED + +Hash clone: SHA-256, clone successful +depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 +hash_clone:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_SUCCESS + +Hash clone: SHA-256, clone failure +depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 +hash_clone:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.function b/tests/suites/test_suite_psa_crypto_driver_wrappers.function index f16d1d52e..a0b719ef6 100644 --- a/tests/suites/test_suite_psa_crypto_driver_wrappers.function +++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.function @@ -23,7 +23,8 @@ void ecdsa_sign( int force_status_arg, uint8_t signature[64]; size_t signature_length = 0xdeadbeef; 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_set_key_type( &attributes, @@ -34,11 +35,13 @@ void ecdsa_sign( int force_status_arg, key_input->x, key_input->len, &key ); - test_driver_signature_sign_hooks.forced_status = force_status; + mbedtls_test_driver_signature_sign_hooks.forced_status = force_status; if( fake_output == 1 ) { - test_driver_signature_sign_hooks.forced_output = expected_output->x; - test_driver_signature_sign_hooks.forced_output_length = expected_output->len; + mbedtls_test_driver_signature_sign_hooks.forced_output = + expected_output->x; + mbedtls_test_driver_signature_sign_hooks.forced_output_length = + expected_output->len; } actual_status = psa_sign_hash( key, alg, @@ -51,13 +54,14 @@ void ecdsa_sign( int force_status_arg, ASSERT_COMPARE( signature, signature_length, 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: psa_reset_key_attributes( &attributes ); psa_destroy_key( key ); 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 */ @@ -75,7 +79,8 @@ void ecdsa_verify( int force_status_arg, psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; psa_algorithm_t alg = PSA_ALG_DETERMINISTIC_ECDSA( PSA_ALG_SHA_256 ); 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( ) ); if( register_public_key ) @@ -99,19 +104,20 @@ void ecdsa_verify( int force_status_arg, &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, data_input->x, data_input->len, signature_input->x, signature_input->len ); 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: psa_reset_key_attributes( &attributes ); psa_destroy_key( key ); 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 */ @@ -130,7 +136,8 @@ void generate_key( int force_status_arg, psa_status_t actual_status; uint8_t actual_output[PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(256)] = {0}; 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_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 ) { - expected_output = test_driver_key_management_hooks.forced_output = fake_output->x; - expected_output_length = test_driver_key_management_hooks.forced_output_length = + expected_output = + 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; } - test_driver_key_management_hooks.hits = 0; - test_driver_key_management_hooks.forced_status = force_status; + mbedtls_test_driver_key_management_hooks.hits = 0; + mbedtls_test_driver_key_management_hooks.forced_status = force_status; PSA_ASSERT( psa_crypto_init( ) ); 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 ); if( actual_status == PSA_SUCCESS ) @@ -178,7 +189,8 @@ exit: psa_reset_key_attributes( &attributes ); psa_destroy_key( key ); 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 */ @@ -194,25 +206,27 @@ void validate_key( int force_status_arg, mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; 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, key_type ); psa_set_key_bits( &attributes, 0 ); 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( ) ); 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 ); exit: psa_reset_key_attributes( &attributes ); psa_destroy_key( key ); 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 */ @@ -236,7 +250,8 @@ void export_key( int force_status_arg, psa_status_t actual_status; uint8_t actual_output[PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(256)] = {0}; 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_bits( &attributes, 256 ); @@ -247,8 +262,12 @@ void export_key( int force_status_arg, if( fake_output->len > 0 ) { - expected_output_ptr = test_driver_key_management_hooks.forced_output = fake_output->x; - expected_output_length = test_driver_key_management_hooks.forced_output_length = + expected_output_ptr = + 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; } else @@ -257,8 +276,8 @@ void export_key( int force_status_arg, expected_output_length = expected_output->len; } - test_driver_key_management_hooks.hits = 0; - test_driver_key_management_hooks.forced_status = force_status; + mbedtls_test_driver_key_management_hooks.hits = 0; + mbedtls_test_driver_key_management_hooks.forced_status = force_status; 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 ); @@ -268,7 +287,7 @@ void export_key( int force_status_arg, if( PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY( output_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 ) { @@ -279,7 +298,8 @@ exit: psa_reset_key_attributes( &attributes ); psa_destroy_key( handle ); 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 */ @@ -303,8 +323,8 @@ void cipher_encrypt( int alg_arg, int key_type_arg, size_t total_output_length = 0; psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - test_driver_cipher_hooks = test_driver_cipher_hooks_init(); - test_driver_cipher_hooks.forced_status = force_status; + mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init(); + mbedtls_test_driver_cipher_hooks.forced_status = force_status; PSA_ASSERT( psa_crypto_init( ) ); @@ -316,12 +336,12 @@ void cipher_encrypt( int alg_arg, int key_type_arg, &key ) ); PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + mbedtls_test_driver_cipher_hooks.hits = 0; 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_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) ); + mbedtls_test_driver_cipher_hooks.hits = 0; output_buffer_size = ( (size_t) input->len + 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 ) { - 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 = expected_output->x; + mbedtls_test_driver_cipher_hooks.forced_output_length = expected_output->len; } PSA_ASSERT( psa_cipher_update( &operation, input->x, input->len, output, output_buffer_size, &function_output_length ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) ); + mbedtls_test_driver_cipher_hooks.hits = 0; if( mock_output_arg ) { - test_driver_cipher_hooks.forced_output = NULL; - test_driver_cipher_hooks.forced_output_length = 0; + mbedtls_test_driver_cipher_hooks.forced_output = NULL; + mbedtls_test_driver_cipher_hooks.forced_output_length = 0; } 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, &function_output_length ); /* 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_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 2 : 0 ) ); + mbedtls_test_driver_cipher_hooks.hits = 0; 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 ) ); // 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, output, total_output_length ); } @@ -372,7 +392,7 @@ exit: mbedtls_free( output ); psa_destroy_key( key ); PSA_DONE( ); - test_driver_cipher_hooks = test_driver_cipher_hooks_init(); + mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init(); } /* END_CASE */ @@ -396,7 +416,7 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg, size_t total_output_length = 0; psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_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( ) ); @@ -408,12 +428,12 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg, &key ) ); PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + mbedtls_test_driver_cipher_hooks.hits = 0; PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + mbedtls_test_driver_cipher_hooks.hits = 0; output_buffer_size = ( (size_t) input->len + 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, output, output_buffer_size, &function_output_length ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + mbedtls_test_driver_cipher_hooks.hits = 0; TEST_ASSERT( function_output_length == output1_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_buffer_size - total_output_length, &function_output_length ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + mbedtls_test_driver_cipher_hooks.hits = 0; TEST_ASSERT( function_output_length == output2_length ); total_output_length += function_output_length; 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, &function_output_length ) ); /* Finish will have called abort as well, so expecting two hits here */ - TEST_EQUAL( test_driver_cipher_hooks.hits, 2 ); - test_driver_cipher_hooks.hits = 0 ; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 ); + mbedtls_test_driver_cipher_hooks.hits = 0 ; total_output_length += function_output_length; 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, output, total_output_length ); @@ -457,7 +477,7 @@ exit: mbedtls_free( output ); psa_destroy_key( key ); PSA_DONE( ); - test_driver_cipher_hooks = test_driver_cipher_hooks_init(); + mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init(); } /* END_CASE */ @@ -481,7 +501,7 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg, size_t total_output_length = 0; psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_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( ) ); @@ -493,12 +513,12 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg, &key ) ); PSA_ASSERT( psa_cipher_decrypt_setup( &operation, key, alg ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + mbedtls_test_driver_cipher_hooks.hits = 0; PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + mbedtls_test_driver_cipher_hooks.hits = 0; output_buffer_size = ( (size_t) input->len + 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, output, output_buffer_size, &function_output_length ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + mbedtls_test_driver_cipher_hooks.hits = 0; TEST_ASSERT( function_output_length == output1_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_buffer_size - total_output_length, &function_output_length ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + mbedtls_test_driver_cipher_hooks.hits = 0; TEST_ASSERT( function_output_length == output2_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, &function_output_length ) ); /* Finish will have called abort as well, so expecting two hits here */ - TEST_EQUAL( test_driver_cipher_hooks.hits, 2 ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 ); + mbedtls_test_driver_cipher_hooks.hits = 0; total_output_length += function_output_length; 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, output, total_output_length ); @@ -544,7 +564,7 @@ exit: mbedtls_free( output ); psa_destroy_key( key ); PSA_DONE( ); - test_driver_cipher_hooks = test_driver_cipher_hooks_init(); + mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init(); } /* END_CASE */ @@ -568,8 +588,8 @@ void cipher_decrypt( int alg_arg, int key_type_arg, size_t total_output_length = 0; psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - test_driver_cipher_hooks = test_driver_cipher_hooks_init(); - test_driver_cipher_hooks.forced_status = force_status; + mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init(); + mbedtls_test_driver_cipher_hooks.forced_status = force_status; PSA_ASSERT( psa_crypto_init( ) ); @@ -581,12 +601,12 @@ void cipher_decrypt( int alg_arg, int key_type_arg, &key ) ); PSA_ASSERT( psa_cipher_decrypt_setup( &operation, key, alg ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + mbedtls_test_driver_cipher_hooks.hits = 0; 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_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) ); + mbedtls_test_driver_cipher_hooks.hits = 0; output_buffer_size = ( (size_t) input->len + 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 ) { - 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 = expected_output->x; + mbedtls_test_driver_cipher_hooks.forced_output_length = expected_output->len; } PSA_ASSERT( psa_cipher_update( &operation, input->x, input->len, output, output_buffer_size, &function_output_length ) ); - TEST_EQUAL( test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 1 : 0 ) ); + mbedtls_test_driver_cipher_hooks.hits = 0; if( mock_output_arg ) { - test_driver_cipher_hooks.forced_output = NULL; - test_driver_cipher_hooks.forced_output_length = 0; + mbedtls_test_driver_cipher_hooks.forced_output = NULL; + mbedtls_test_driver_cipher_hooks.forced_output_length = 0; } 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, &function_output_length ); /* 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_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, ( force_status == PSA_SUCCESS ? 2 : 0 ) ); + mbedtls_test_driver_cipher_hooks.hits = 0; total_output_length += function_output_length; TEST_EQUAL( status, expected_status ); @@ -626,7 +646,7 @@ void cipher_decrypt( int alg_arg, int key_type_arg, if( expected_status == PSA_SUCCESS ) { 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, output, total_output_length ); } @@ -636,7 +656,7 @@ exit: mbedtls_free( output ); psa_destroy_key( key ); PSA_DONE( ); - test_driver_cipher_hooks = test_driver_cipher_hooks_init(); + mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init(); } /* END_CASE */ @@ -654,7 +674,7 @@ void cipher_entry_points( int alg_arg, int key_type_arg, size_t function_output_length = 0; psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_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 ); output_buffer_size = input->len + 16; @@ -669,136 +689,136 @@ void cipher_entry_points( int alg_arg, int key_type_arg, &key ) ); /* 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 ); /* When setup fails, it shouldn't call any further entry points */ - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); + mbedtls_test_driver_cipher_hooks.hits = 0; status = psa_cipher_set_iv( &operation, iv->x, iv->len ); 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 */ status = psa_cipher_decrypt_setup( &operation, key, alg ); /* When setup fails, it shouldn't call any further entry points */ - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); + mbedtls_test_driver_cipher_hooks.hits = 0; status = psa_cipher_set_iv( &operation, iv->x, iv->len ); 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_driver_cipher_hooks.forced_status = PSA_SUCCESS; + mbedtls_test_driver_cipher_hooks.forced_status = PSA_SUCCESS; status = psa_cipher_encrypt_setup( &operation, key, alg ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); + 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 ); /* When setting the IV fails, it should call abort too */ - TEST_EQUAL( test_driver_cipher_hooks.hits, 2 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); /* 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, input->x, input->len, output, output_buffer_size, &function_output_length ); 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 ); /* 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 ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); + 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 ); /* When generating the IV fails, it should call abort too */ - TEST_EQUAL( test_driver_cipher_hooks.hits, 2 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); /* 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, input->x, input->len, output, output_buffer_size, &function_output_length ); 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 ); /* 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 ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); + mbedtls_test_driver_cipher_hooks.hits = 0; status = psa_cipher_set_iv( &operation, iv->x, iv->len ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); + 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, input->x, input->len, output, output_buffer_size, &function_output_length ); /* When the update call fails, it should call abort too */ - TEST_EQUAL( test_driver_cipher_hooks.hits, 2 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); /* 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, input->x, input->len, output, output_buffer_size, &function_output_length ); 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 ); /* 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 ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); + mbedtls_test_driver_cipher_hooks.hits = 0; status = psa_cipher_set_iv( &operation, iv->x, iv->len ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); + mbedtls_test_driver_cipher_hooks.hits = 0; status = psa_cipher_update( &operation, input->x, input->len, output, output_buffer_size, &function_output_length ); - TEST_EQUAL( test_driver_cipher_hooks.hits, 1 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); - test_driver_cipher_hooks.hits = 0; + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); + 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, output + function_output_length, output_buffer_size - function_output_length, &function_output_length ); /* When the finish call fails, it should call abort too */ - TEST_EQUAL( test_driver_cipher_hooks.hits, 2 ); - TEST_EQUAL( status, test_driver_cipher_hooks.forced_status ); + TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 2 ); + TEST_EQUAL( status, mbedtls_test_driver_cipher_hooks.forced_status ); /* 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, input->x, input->len, output, output_buffer_size, &function_output_length ); 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 ); exit: @@ -806,7 +826,7 @@ exit: mbedtls_free( output ); psa_destroy_key( key ); PSA_DONE( ); - test_driver_cipher_hooks = test_driver_cipher_hooks_init(); + mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init(); } /* END_CASE */ @@ -829,7 +849,7 @@ void aead_encrypt( int key_type_arg, data_t *key_data, size_t output_length = 0; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; 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( ) ); @@ -852,15 +872,15 @@ void aead_encrypt( int key_type_arg, data_t *key_data, PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE( input_data->len ) ); 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, nonce->x, nonce->len, additional_data->x, additional_data->len, input_data->x, input_data->len, output_data, output_size, &output_length ); - TEST_EQUAL( test_driver_aead_hooks.hits, 1 ); - TEST_EQUAL( test_driver_aead_hooks.driver_status, forced_status ); + TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_aead_hooks.driver_status, forced_status ); TEST_EQUAL( status, ( forced_status == PSA_ERROR_NOT_SUPPORTED ) ? PSA_SUCCESS : forced_status ); @@ -875,7 +895,7 @@ exit: psa_destroy_key( key ); mbedtls_free( output_data ); PSA_DONE( ); - test_driver_aead_hooks = test_driver_aead_hooks_init(); + mbedtls_test_driver_aead_hooks = mbedtls_test_driver_aead_hooks_init(); } /* END_CASE */ @@ -898,7 +918,7 @@ void aead_decrypt( int key_type_arg, data_t *key_data, size_t output_length = 0; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; 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( ) ); @@ -915,7 +935,7 @@ void aead_decrypt( int key_type_arg, data_t *key_data, alg ); 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, nonce->x, nonce->len, additional_data->x, @@ -923,8 +943,8 @@ void aead_decrypt( int key_type_arg, data_t *key_data, input_data->x, input_data->len, output_data, output_size, &output_length ); - TEST_EQUAL( test_driver_aead_hooks.hits, 1 ); - TEST_EQUAL( test_driver_aead_hooks.driver_status, forced_status ); + TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_aead_hooks.driver_status, forced_status ); TEST_EQUAL( status, ( forced_status == PSA_ERROR_NOT_SUPPORTED ) ? PSA_SUCCESS : forced_status ); @@ -939,7 +959,7 @@ exit: psa_destroy_key( key ); mbedtls_free( output_data ); PSA_DONE( ); - test_driver_aead_hooks = test_driver_aead_hooks_init(); + mbedtls_test_driver_aead_hooks = mbedtls_test_driver_aead_hooks_init(); } /* END_CASE */ @@ -1046,3 +1066,256 @@ exit: PSA_DONE( ); } /* END_CASE */ + +/* BEGIN_CASE */ +void hash_compute( int alg_arg, + data_t *input, data_t *hash, + int forced_status_arg, + int expected_status_arg ) +{ + psa_algorithm_t alg = alg_arg; + psa_status_t forced_status = forced_status_arg; + psa_status_t expected_status = expected_status_arg; + unsigned char *output = NULL; + size_t output_length; + + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); + mbedtls_test_driver_hash_hooks.forced_status = forced_status; + + PSA_ASSERT( psa_crypto_init( ) ); + ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) ); + + TEST_EQUAL( psa_hash_compute( alg, input->x, input->len, + output, PSA_HASH_LENGTH( alg ), + &output_length ), expected_status ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status ); + + if( expected_status == PSA_SUCCESS ) + { + ASSERT_COMPARE( output, output_length, hash->x, hash->len ); + } + +exit: + mbedtls_free( output ); + PSA_DONE( ); + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); +} +/* END_CASE */ + +/* BEGIN_CASE */ +void hash_multipart_setup( int alg_arg, + data_t *input, data_t *hash, + int forced_status_arg, + int expected_status_arg ) +{ + psa_algorithm_t alg = alg_arg; + psa_status_t forced_status = forced_status_arg; + psa_status_t expected_status = expected_status_arg; + unsigned char *output = NULL; + psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT; + size_t output_length; + + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); + ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) ); + + PSA_ASSERT( psa_crypto_init( ) ); + + mbedtls_test_driver_hash_hooks.forced_status = forced_status; + TEST_EQUAL( psa_hash_setup( &operation, alg ), expected_status ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status ); + + if( expected_status == PSA_SUCCESS ) + { + PSA_ASSERT( psa_hash_update( &operation, input->x, input->len ) ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, + forced_status == PSA_ERROR_NOT_SUPPORTED ? 1 : 2 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status ); + + PSA_ASSERT( psa_hash_finish( &operation, + output, PSA_HASH_LENGTH( alg ), + &output_length ) ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, + forced_status == PSA_ERROR_NOT_SUPPORTED ? 1 : 4 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status ); + + ASSERT_COMPARE( output, output_length, hash->x, hash->len ); + } + +exit: + psa_hash_abort( &operation ); + mbedtls_free( output ); + PSA_DONE( ); + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); +} +/* END_CASE */ + +/* BEGIN_CASE */ +void hash_multipart_update( int alg_arg, + data_t *input, data_t *hash, + int forced_status_arg ) +{ + psa_algorithm_t alg = alg_arg; + psa_status_t forced_status = forced_status_arg; + unsigned char *output = NULL; + psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT; + size_t output_length; + + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); + ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) ); + + PSA_ASSERT( psa_crypto_init( ) ); + + /* + * Update inactive operation, the driver shouldn't be called. + */ + TEST_EQUAL( psa_hash_update( &operation, input->x, input->len ), + PSA_ERROR_BAD_STATE ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 0 ); + + PSA_ASSERT( psa_hash_setup( &operation, alg ) ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + + mbedtls_test_driver_hash_hooks.forced_status = forced_status; + TEST_EQUAL( psa_hash_update( &operation, input->x, input->len ), + forced_status ); + /* One or two more calls to the driver interface: update or update + abort */ + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, + forced_status == PSA_SUCCESS ? 2 : 3 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status ); + + if( forced_status == PSA_SUCCESS ) + { + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); + PSA_ASSERT( psa_hash_finish( &operation, + output, PSA_HASH_LENGTH( alg ), + &output_length ) ); + /* Two calls to the driver interface: update + abort */ + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 2 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + + ASSERT_COMPARE( output, output_length, hash->x, hash->len ); + } + +exit: + psa_hash_abort( &operation ); + mbedtls_free( output ); + PSA_DONE( ); + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); +} +/* END_CASE */ + +/* BEGIN_CASE */ +void hash_multipart_finish( int alg_arg, + data_t *input, data_t *hash, + int forced_status_arg ) +{ + psa_algorithm_t alg = alg_arg; + psa_status_t forced_status = forced_status_arg; + unsigned char *output = NULL; + psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT; + size_t output_length; + + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); + ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) ); + + PSA_ASSERT( psa_crypto_init( ) ); + + /* + * Finish inactive operation, the driver shouldn't be called. + */ + TEST_EQUAL( psa_hash_finish( &operation, output, PSA_HASH_LENGTH( alg ), + &output_length ), + PSA_ERROR_BAD_STATE ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 0 ); + + PSA_ASSERT( psa_hash_setup( &operation, alg ) ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + + PSA_ASSERT( psa_hash_update( &operation, input->x, input->len ) ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 2 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + + mbedtls_test_driver_hash_hooks.forced_status = forced_status; + TEST_EQUAL( psa_hash_finish( &operation, + output, PSA_HASH_LENGTH( alg ), + &output_length ), + forced_status ); + /* Two more calls to the driver interface: finish + abort */ + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 4 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status ); + + if( forced_status == PSA_SUCCESS ) + ASSERT_COMPARE( output, output_length, hash->x, hash->len ); + +exit: + psa_hash_abort( &operation ); + mbedtls_free( output ); + PSA_DONE( ); + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); +} +/* END_CASE */ + +/* BEGIN_CASE */ +void hash_clone( int alg_arg, + data_t *input, data_t *hash, + int forced_status_arg ) +{ + psa_algorithm_t alg = alg_arg; + psa_status_t forced_status = forced_status_arg; + unsigned char *output = NULL; + psa_hash_operation_t source_operation = PSA_HASH_OPERATION_INIT; + psa_hash_operation_t target_operation = PSA_HASH_OPERATION_INIT; + size_t output_length; + + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); + ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) ); + + PSA_ASSERT( psa_crypto_init( ) ); + + /* + * Clone inactive operation, the driver shouldn't be called. + */ + TEST_EQUAL( psa_hash_clone( &source_operation, &target_operation ), + PSA_ERROR_BAD_STATE ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 0 ); + + PSA_ASSERT( psa_hash_setup( &source_operation, alg ) ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + + mbedtls_test_driver_hash_hooks.forced_status = forced_status; + TEST_EQUAL( psa_hash_clone( &source_operation, &target_operation ), + forced_status ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, + forced_status == PSA_SUCCESS ? 2 : 3 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status ); + + if( forced_status == PSA_SUCCESS ) + { + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); + PSA_ASSERT( psa_hash_update( &target_operation, + input->x, input->len ) ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + + PSA_ASSERT( psa_hash_finish( &target_operation, + output, PSA_HASH_LENGTH( alg ), + &output_length ) ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 3 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + + ASSERT_COMPARE( output, output_length, hash->x, hash->len ); + } + +exit: + psa_hash_abort( &source_operation ); + psa_hash_abort( &target_operation ); + mbedtls_free( output ); + PSA_DONE( ); + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); +} +/* END_CASE */ diff --git a/tests/suites/test_suite_ssl.data b/tests/suites/test_suite_ssl.data index e59c9055f..44279d9be 100644 --- a/tests/suites/test_suite_ssl.data +++ b/tests/suites/test_suite_ssl.data @@ -9219,7 +9219,7 @@ ssl_tls1_3_derive_secret:MBEDTLS_MD_SHA256:"9b2188e9b2fc6d64d71dc329900e20bb4191 SSL TLS 1.3 Key schedule: Derive-Secret( ., "c hs traffic", hash) # Vector from RFC 8448 -ssl_tls1_3_derive_secret:MBEDTLS_MD_SHA256:"005cb112fd8eb4ccc623bb88a07c64b3ede1605363fc7d0df8c7ce4ff0fb4ae6":tls1_3_label_c_hs_traffic:"f736cb34fe25e701551bee6fd24c1cc7102a7daf9405cb15d97aafe16f757d03"::32:MBEDTLS_SSL_TLS1_3_CONTEXT_HASHED:"2faac08f851d35fea3604fcb4de82dc62c9b164a70974d0462e27f1ab278700f" +ssl_tls1_3_derive_secret:MBEDTLS_MD_SHA256:"005cb112fd8eb4ccc623bb88a07c64b3ede1605363fc7d0df8c7ce4ff0fb4ae6":tls1_3_label_c_hs_traffic:"f736cb34fe25e701551bee6fd24c1cc7102a7daf9405cb15d97aafe16f757d03":32:MBEDTLS_SSL_TLS1_3_CONTEXT_HASHED:"2faac08f851d35fea3604fcb4de82dc62c9b164a70974d0462e27f1ab278700f" SSL TLS 1.3 Key schedule: Derive-Secret( ., "s hs traffic", hash) # Vector from RFC 8448 diff --git a/visualc/VS2010/mbedTLS.vcxproj b/visualc/VS2010/mbedTLS.vcxproj index eda1caef8..c3e1d026a 100644 --- a/visualc/VS2010/mbedTLS.vcxproj +++ b/visualc/VS2010/mbedTLS.vcxproj @@ -232,6 +232,7 @@ + @@ -374,6 +375,7 @@ +