Style and language fixes from review
Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
diff --git a/tests/include/test/drivers/cipher.h b/tests/include/test/drivers/cipher.h
index 96ab295..ef787f7 100644
--- a/tests/include/test/drivers/cipher.h
+++ b/tests/include/test/drivers/cipher.h
@@ -52,7 +52,7 @@
/* If not PSA_SUCCESS, return this error code instead of processing the
* function call. */
psa_status_t forced_status;
- /* Count the amount of times one of the keygen driver functions is called. */
+ /* Count the amount of times one of the cipher driver functions is called. */
unsigned long hits;
} test_driver_cipher_hooks_t;
diff --git a/tests/src/drivers/cipher.c b/tests/src/drivers/cipher.c
index 0a4a347..c8eb1d3 100644
--- a/tests/src/drivers/cipher.c
+++ b/tests/src/drivers/cipher.c
@@ -35,11 +35,11 @@
#include <string.h>
-/* Test driver implements AES-CTR by default when it's status is not overridden.
+/* 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.
- * Keep in mind this code is only exercised with the crypto drivers test target,
- * meaning the other test runs will only test the non-driver implementation. */
+ * fallback even for AES-CTR. */
test_driver_cipher_hooks_t test_driver_cipher_hooks = TEST_DRIVER_CIPHER_INIT;
psa_status_t test_transparent_cipher_encrypt(
@@ -112,10 +112,11 @@
if( operation->alg != 0 )
return( PSA_ERROR_BAD_STATE );
- /* write our struct, this will trigger memory corruption failures
- * in test when we go outside of bounds, or when the function is called
- * without first destroying the context object. */
- memset( operation, 0, sizeof( test_transparent_cipher_operation_t ) );
+ /* 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 corruption
+ * errors should the core not have allocated (enough) memory for our context
+ * struct. */
+ memset( operation, 0, sizeof( *operation ) );
/* Test driver supports AES-CTR only, to verify operation calls. */
if( alg != PSA_ALG_CTR ||
@@ -173,10 +174,11 @@
if( operation->alg != 0 )
return( PSA_ERROR_BAD_STATE );
- /* write our struct, this will trigger memory corruption failures
- * in test when we go outside of bounds, or when the function is called
- * without first destroying the context object. */
- memset( operation, 0, sizeof( test_transparent_cipher_operation_t ) );
+ /* 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 corruption
+ * errors should the core not have allocated (enough) memory for our context
+ * struct. */
+ memset( operation, 0, sizeof( *operation ) );
/* Test driver supports AES-CTR only, to verify operation calls. */
if( alg != PSA_ALG_CTR || psa_get_key_type( attributes ) != PSA_KEY_TYPE_AES )
@@ -225,9 +227,11 @@
mbedtls_cipher_free( &operation->cipher );
- /* write our struct, this will trigger memory corruption failures
- * in test when we go outside of bounds. */
- memset( operation, 0, sizeof( test_transparent_cipher_operation_t ) );
+ /* 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 corruption
+ * errors should the core not have allocated (enough) memory for our context
+ * struct. */
+ memset( operation, 0, sizeof( *operation ) );
test_driver_cipher_hooks.hits++;
return( PSA_SUCCESS );
diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.function b/tests/suites/test_suite_psa_crypto_driver_wrappers.function
index 1daf9bb..470c438 100644
--- a/tests/suites/test_suite_psa_crypto_driver_wrappers.function
+++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.function
@@ -236,6 +236,7 @@
output + total_output_length,
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;
@@ -326,6 +327,7 @@
output + total_output_length,
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 ;
total_output_length += function_output_length;
@@ -413,6 +415,7 @@
output + total_output_length,
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;
total_output_length += function_output_length;
@@ -483,6 +486,7 @@
output + total_output_length,
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;