diff --git a/library/psa_crypto_driver_wrappers.c b/library/psa_crypto_driver_wrappers.c index 91ad37f80..ce49a226b 100644 --- a/library/psa_crypto_driver_wrappers.c +++ b/library/psa_crypto_driver_wrappers.c @@ -1311,10 +1311,10 @@ psa_status_t psa_driver_wrapper_aead_encrypt_setup( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) status = PSA_ERROR_NOT_SUPPORTED; -// status = test_transparent_aead_encrypt_setup( -// operation, attributes, -// key_buffer, key_buffer_size, -// alg ); + status = test_transparent_aead_encrypt_setup( + operation, attributes, + key_buffer, key_buffer_size, + alg ); /* Declared with fallback == true */ if( status == PSA_SUCCESS ) operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; @@ -1363,10 +1363,10 @@ psa_status_t psa_driver_wrapper_aead_decrypt_setup( #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) status = PSA_ERROR_NOT_SUPPORTED; -// status = test_transparent_aead_decrypt_setup( -// operation, attributes, -// key_buffer, key_buffer_size, -// alg ); + status = test_transparent_aead_decrypt_setup( + operation, attributes, + key_buffer, key_buffer_size, + alg ); /* Declared with fallback == true */ if( status == PSA_SUCCESS ) operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; @@ -1413,8 +1413,8 @@ psa_status_t psa_driver_wrapper_aead_set_nonce( #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: return( PSA_ERROR_NOT_SUPPORTED ); -// return( test_transparent_aead_set_nonce( -// operation, nonce, nonce_length ) ); + return( test_transparent_aead_set_nonce( + operation, nonce, nonce_length ) ); /* Add cases for opaque driver here */ @@ -1445,8 +1445,8 @@ psa_status_t psa_driver_wrapper_aead_set_lengths( #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: return( PSA_ERROR_NOT_SUPPORTED ); -// return( test_transparent_aead_set_lengths( -// operation, ad_length, plaintext_length ) ); + return( test_transparent_aead_set_lengths( + operation, ad_length, plaintext_length ) ); /* Add cases for opaque driver here */ @@ -1477,8 +1477,8 @@ psa_status_t psa_driver_wrapper_aead_update_ad( #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: return( PSA_ERROR_NOT_SUPPORTED ); -// return( test_transparent_aead_update_ad( -// operation, input, input_length ) ); + return( test_transparent_aead_update_ad( + operation, input, input_length ) ); /* Add cases for opaque driver here */ @@ -1513,9 +1513,9 @@ psa_status_t psa_driver_wrapper_aead_update( #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: return( PSA_ERROR_NOT_SUPPORTED ); -// return( test_transparent_aead_update( -// operation, input, input_length, ouput, output_size, -// output_length ) ); + return( test_transparent_aead_update( + operation, input, input_length, output, output_size, + output_length ) ); /* Add cases for opaque driver here */ @@ -1554,9 +1554,9 @@ psa_status_t psa_driver_wrapper_aead_finish( #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: return( PSA_ERROR_NOT_SUPPORTED ); -// return( test_transparent_aead_finish( -// operation, ciphertext, ciphertext_size, -// ciphertext_length, tag, tag_size, tag_length ) ); + return( test_transparent_aead_finish( + operation, ciphertext, ciphertext_size, + ciphertext_length, tag, tag_size, tag_length ) ); /* Add cases for opaque driver here */ @@ -1595,9 +1595,9 @@ psa_status_t psa_driver_wrapper_aead_verify( #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: return( PSA_ERROR_NOT_SUPPORTED ); -// return( test_transparent_aead_verify( -// operation, ciphertext, ciphertext_size, -// ciphertext_length, tag, tag_length ) ); + return( test_transparent_aead_verify( + operation, plaintext, plaintext_size, + plaintext_length, tag, tag_length ) ); /* Add cases for opaque driver here */ @@ -1629,7 +1629,7 @@ psa_status_t psa_driver_wrapper_aead_abort( #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: return( PSA_ERROR_NOT_SUPPORTED ); -// return( test_transparent_aead_abort( operation ) ); + return( test_transparent_aead_abort( operation ) ); /* Add cases for opaque driver here */ diff --git a/tests/include/test/drivers/aead.h b/tests/include/test/drivers/aead.h index 2207cb36f..23f32c0a8 100644 --- a/tests/include/test/drivers/aead.h +++ b/tests/include/test/drivers/aead.h @@ -67,5 +67,60 @@ psa_status_t mbedtls_test_transparent_aead_decrypt( const uint8_t *ciphertext, size_t ciphertext_length, uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length ); +psa_status_t test_transparent_aead_encrypt_setup( + psa_aead_operation_t *operation, + const psa_key_attributes_t *attributes, + const uint8_t *key_buffer, size_t key_buffer_size, + psa_algorithm_t alg ); + +psa_status_t test_transparent_aead_decrypt_setup( + psa_aead_operation_t *operation, + const psa_key_attributes_t *attributes, + const uint8_t *key_buffer, size_t key_buffer_size, + psa_algorithm_t alg ); + +psa_status_t test_transparent_aead_set_nonce( + psa_aead_operation_t *operation, + const uint8_t *nonce, + size_t nonce_length ); + +psa_status_t test_transparent_aead_set_lengths( + psa_aead_operation_t *operation, + size_t ad_length, + size_t plaintext_length ); + +psa_status_t test_transparent_aead_update_ad( + psa_aead_operation_t *operation, + const uint8_t *input, + size_t input_length ); + +psa_status_t test_transparent_aead_update( + psa_aead_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_aead_finish( + psa_aead_operation_t *operation, + uint8_t *ciphertext, + size_t ciphertext_size, + size_t *ciphertext_length, + uint8_t *tag, + size_t tag_size, + size_t *tag_length ); + +psa_status_t test_transparent_aead_verify( + psa_aead_operation_t *operation, + uint8_t *plaintext, + size_t plaintext_size, + size_t *plaintext_length, + const uint8_t *tag, + size_t tag_length ); + +psa_status_t test_transparent_aead_abort( + psa_aead_operation_t *operation ); + #endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_TEST_DRIVERS_AEAD_H */ diff --git a/tests/src/drivers/test_driver_aead.c b/tests/src/drivers/test_driver_aead.c index 25396c92f..67118efcb 100644 --- a/tests/src/drivers/test_driver_aead.c +++ b/tests/src/drivers/test_driver_aead.c @@ -93,4 +93,208 @@ psa_status_t mbedtls_test_transparent_aead_decrypt( return( mbedtls_test_driver_aead_hooks.driver_status ); } +psa_status_t test_transparent_aead_encrypt_setup( + psa_aead_operation_t *operation, + const psa_key_attributes_t *attributes, + const uint8_t *key_buffer, size_t key_buffer_size, + psa_algorithm_t alg ) +{ + test_driver_aead_hooks.hits++; + + if( test_driver_aead_hooks.forced_status != PSA_SUCCESS ) + { + test_driver_aead_hooks.driver_status = + test_driver_aead_hooks.forced_status; + } + else + { + test_driver_aead_hooks.driver_status = + mbedtls_psa_aead_encrypt_setup( operation, attributes, key_buffer, + key_buffer_size, alg ); + } + + return( test_driver_aead_hooks.driver_status ); +} + +psa_status_t test_transparent_aead_decrypt_setup( + psa_aead_operation_t *operation, + const psa_key_attributes_t *attributes, + const uint8_t *key_buffer, size_t key_buffer_size, + psa_algorithm_t alg ) +{ + test_driver_aead_hooks.hits++; + + if( test_driver_aead_hooks.forced_status != PSA_SUCCESS ) + { + test_driver_aead_hooks.driver_status = + test_driver_aead_hooks.forced_status; + } + else + { + test_driver_aead_hooks.driver_status = + mbedtls_psa_aead_decrypt_setup( operation, attributes, key_buffer, + key_buffer_size, alg ); + } + + return( test_driver_aead_hooks.driver_status ); +} + +psa_status_t test_transparent_aead_set_nonce( + psa_aead_operation_t *operation, + const uint8_t *nonce, + size_t nonce_length ) +{ + test_driver_aead_hooks.hits++; + + if( test_driver_aead_hooks.forced_status != PSA_SUCCESS ) + { + test_driver_aead_hooks.driver_status = + test_driver_aead_hooks.forced_status; + } + else + { + test_driver_aead_hooks.driver_status = + mbedtls_psa_aead_set_nonce( operation, nonce, nonce_length ); + } + + return( test_driver_aead_hooks.driver_status ); +} + +psa_status_t test_transparent_aead_set_lengths( + psa_aead_operation_t *operation, + size_t ad_length, + size_t plaintext_length ) +{ + test_driver_aead_hooks.hits++; + + if( test_driver_aead_hooks.forced_status != PSA_SUCCESS ) + { + test_driver_aead_hooks.driver_status = + test_driver_aead_hooks.forced_status; + } + else + { + test_driver_aead_hooks.driver_status = + mbedtls_psa_aead_set_lengths( operation, ad_length, plaintext_length ); + } + + return( test_driver_aead_hooks.driver_status ); +} + +psa_status_t test_transparent_aead_update_ad( + psa_aead_operation_t *operation, + const uint8_t *input, + size_t input_length ) +{ + test_driver_aead_hooks.hits++; + + if( test_driver_aead_hooks.forced_status != PSA_SUCCESS ) + { + test_driver_aead_hooks.driver_status = + test_driver_aead_hooks.forced_status; + } + else + { + test_driver_aead_hooks.driver_status = + mbedtls_psa_aead_update_ad( operation, input, input_length ); + } + + return( test_driver_aead_hooks.driver_status ); +} + +psa_status_t test_transparent_aead_update( + psa_aead_operation_t *operation, + const uint8_t *input, + size_t input_length, + uint8_t *output, + size_t output_size, + size_t *output_length ) +{ + test_driver_aead_hooks.hits++; + + if( test_driver_aead_hooks.forced_status != PSA_SUCCESS ) + { + test_driver_aead_hooks.driver_status = + test_driver_aead_hooks.forced_status; + } + else + { + test_driver_aead_hooks.driver_status = + mbedtls_psa_aead_update( operation, input, input_length, output, + output_size, output_length ); + } + + return( test_driver_aead_hooks.driver_status ); +} + +psa_status_t test_transparent_aead_finish( + psa_aead_operation_t *operation, + uint8_t *ciphertext, + size_t ciphertext_size, + size_t *ciphertext_length, + uint8_t *tag, + size_t tag_size, + size_t *tag_length ) +{ + test_driver_aead_hooks.hits++; + + if( test_driver_aead_hooks.forced_status != PSA_SUCCESS ) + { + test_driver_aead_hooks.driver_status = + test_driver_aead_hooks.forced_status; + } + else + { + test_driver_aead_hooks.driver_status = + mbedtls_psa_aead_finish( operation, ciphertext, ciphertext_size, + ciphertext_length, tag, tag_size, tag_length ); + } + + return( test_driver_aead_hooks.driver_status ); +} + +psa_status_t test_transparent_aead_verify( + psa_aead_operation_t *operation, + uint8_t *plaintext, + size_t plaintext_size, + size_t *plaintext_length, + const uint8_t *tag, + size_t tag_length ) +{ + test_driver_aead_hooks.hits++; + + if( test_driver_aead_hooks.forced_status != PSA_SUCCESS ) + { + test_driver_aead_hooks.driver_status = + test_driver_aead_hooks.forced_status; + } + else + { + test_driver_aead_hooks.driver_status = + mbedtls_psa_aead_verify( operation, plaintext, plaintext_size, + plaintext_length, tag, tag_length ); + } + + return( test_driver_aead_hooks.driver_status ); +} + +psa_status_t test_transparent_aead_abort( + psa_aead_operation_t *operation ) +{ + test_driver_aead_hooks.hits++; + + if( test_driver_aead_hooks.forced_status != PSA_SUCCESS ) + { + test_driver_aead_hooks.driver_status = + test_driver_aead_hooks.forced_status; + } + else + { + test_driver_aead_hooks.driver_status = + mbedtls_psa_aead_abort( operation ); + } + + return( test_driver_aead_hooks.driver_status ); +} + #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */