Apply feedback from PR review
* Moved test data to .data file
* Bundled test driver hook variables in a struct
* Style fixes
Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
diff --git a/tests/.gitignore b/tests/.gitignore
index d49611c..d9f4b51 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -11,4 +11,5 @@
include/test/instrument_record_status.h
src/*.o
+src/drivers/*.o
src/libmbed*
diff --git a/tests/include/drivers/keygen.h b/tests/include/drivers/keygen.h
index af1f499..b72c65c 100644
--- a/tests/include/drivers/keygen.h
+++ b/tests/include/drivers/keygen.h
@@ -29,11 +29,25 @@
#if defined(PSA_CRYPTO_DRIVER_TEST)
#include <psa/crypto_driver_common.h>
-extern void *test_driver_keygen_forced_output;
-extern size_t test_driver_keygen_forced_output_length;
+typedef struct {
+ /* If non-null, on success, copy this to the output. */
+ void *forced_output;
+ size_t forced_output_length;
+ /* 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. */
+ unsigned long hits;
+} test_driver_keygen_hooks_t;
-extern psa_status_t test_transparent_keygen_status;
-extern unsigned long test_transparent_keygen_hit;
+#define TEST_DRIVER_KEYGEN_INIT { NULL, 0, PSA_ERROR_NOT_SUPPORTED, 0 }
+static inline test_driver_keygen_hooks_t test_driver_keygen_hooks_init( void )
+{
+ const test_driver_keygen_hooks_t v = TEST_DRIVER_KEYGEN_INIT;
+ return( v );
+}
+
+extern test_driver_keygen_hooks_t test_driver_keygen_hooks;
psa_status_t test_transparent_generate_key(
const psa_key_attributes_t *attributes,
diff --git a/tests/include/drivers/signature.h b/tests/include/drivers/signature.h
index 1506bac..e41892e 100644
--- a/tests/include/drivers/signature.h
+++ b/tests/include/drivers/signature.h
@@ -29,14 +29,26 @@
#if defined(PSA_CRYPTO_DRIVER_TEST)
#include <psa/crypto_driver_common.h>
-extern void *test_driver_forced_output;
-extern size_t test_driver_forced_output_length;
+typedef struct {
+ /* If non-null, on success, copy this to the output. */
+ void *forced_output;
+ size_t forced_output_length;
+ /* 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. */
+ unsigned long hits;
+} test_driver_signature_hooks_t;
-extern psa_status_t test_transparent_signature_sign_hash_status;
-extern unsigned long test_transparent_signature_sign_hash_hit;
+#define TEST_DRIVER_SIGNATURE_INIT { NULL, 0, PSA_ERROR_NOT_SUPPORTED, 0 }
+static inline test_driver_signature_hooks_t test_driver_signature_hooks_init( void )
+{
+ const test_driver_signature_hooks_t v = TEST_DRIVER_SIGNATURE_INIT;
+ return( v );
+}
-extern psa_status_t test_transparent_signature_verify_hash_status;
-extern unsigned long test_transparent_signature_verify_hash_hit;
+extern test_driver_signature_hooks_t test_driver_signature_sign_hooks;
+extern test_driver_signature_hooks_t test_driver_signature_verify_hooks;
psa_status_t test_transparent_signature_sign_hash(
const psa_key_attributes_t *attributes,
diff --git a/tests/src/drivers/keygen.c b/tests/src/drivers/keygen.c
index a21ec27..d493ab3 100644
--- a/tests/src/drivers/keygen.c
+++ b/tests/src/drivers/keygen.c
@@ -36,29 +36,24 @@
#include <string.h>
-/* If non-null, on success, copy this to the output. */
-void *test_driver_keygen_forced_output = NULL;
-size_t test_driver_keygen_forced_output_length = 0;
-
-psa_status_t test_transparent_keygen_status = PSA_ERROR_NOT_SUPPORTED;
-unsigned long test_transparent_keygen_hit = 0;
+test_driver_keygen_hooks_t test_driver_keygen_hooks = TEST_DRIVER_KEYGEN_INIT;
psa_status_t test_transparent_generate_key(
const psa_key_attributes_t *attributes,
uint8_t *key, size_t key_size, size_t *key_length )
{
- ++test_transparent_keygen_hit;
+ ++test_driver_keygen_hooks.hits;
- if( test_transparent_keygen_status != PSA_SUCCESS )
- return( test_transparent_keygen_status );
+ if( test_driver_keygen_hooks.forced_status != PSA_SUCCESS )
+ return( test_driver_keygen_hooks.forced_status );
- if( test_driver_keygen_forced_output != NULL )
+ if( test_driver_keygen_hooks.forced_output != NULL )
{
- if( test_driver_keygen_forced_output_length > key_size )
+ if( test_driver_keygen_hooks.forced_output_length > key_size )
return( PSA_ERROR_BUFFER_TOO_SMALL );
- memcpy( key, test_driver_keygen_forced_output,
- test_driver_keygen_forced_output_length );
- *key_length = test_driver_keygen_forced_output_length;
+ memcpy( key, test_driver_keygen_hooks.forced_output,
+ test_driver_keygen_hooks.forced_output_length );
+ *key_length = test_driver_keygen_hooks.forced_output_length;
return( PSA_SUCCESS );
}
diff --git a/tests/src/drivers/signature.c b/tests/src/drivers/signature.c
index d1a6009..5299a96 100644
--- a/tests/src/drivers/signature.c
+++ b/tests/src/drivers/signature.c
@@ -39,15 +39,8 @@
#include <string.h>
-/* If non-null, on success, copy this to the output. */
-void *test_driver_forced_output = NULL;
-size_t test_driver_forced_output_length = 0;
-
-psa_status_t test_transparent_signature_sign_hash_status = PSA_ERROR_NOT_SUPPORTED;
-unsigned long test_transparent_signature_sign_hash_hit = 0;
-
-psa_status_t test_transparent_signature_verify_hash_status = PSA_ERROR_NOT_SUPPORTED;
-unsigned long test_transparent_signature_verify_hash_hit = 0;
+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;
psa_status_t test_transparent_signature_sign_hash(
const psa_key_attributes_t *attributes,
@@ -56,18 +49,18 @@
const uint8_t *hash, size_t hash_length,
uint8_t *signature, size_t signature_size, size_t *signature_length )
{
- ++test_transparent_signature_sign_hash_hit;
+ ++test_driver_signature_sign_hooks.hits;
- if( test_transparent_signature_sign_hash_status != PSA_SUCCESS )
- return( test_transparent_signature_sign_hash_status );
+ if( test_driver_signature_sign_hooks.forced_status != PSA_SUCCESS )
+ return( test_driver_signature_sign_hooks.forced_status );
- if( test_driver_forced_output != NULL )
+ if( test_driver_signature_sign_hooks.forced_output != NULL )
{
- if( test_driver_forced_output_length > signature_size )
+ if( test_driver_signature_sign_hooks.forced_output_length > signature_size )
return( PSA_ERROR_BUFFER_TOO_SMALL );
- memcpy( signature, test_driver_forced_output,
- test_driver_forced_output_length );
- *signature_length = test_driver_forced_output_length;
+ 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;
return( PSA_SUCCESS );
}
@@ -178,10 +171,10 @@
const uint8_t *hash, size_t hash_length,
const uint8_t *signature, size_t signature_length )
{
- ++test_transparent_signature_verify_hash_hit;
+ ++test_driver_signature_verify_hooks.hits;
- if( test_transparent_signature_verify_hash_status != PSA_SUCCESS )
- return( test_transparent_signature_verify_hash_status );
+ if( test_driver_signature_verify_hooks.forced_status != PSA_SUCCESS )
+ return( test_driver_signature_verify_hooks.forced_status );
psa_status_t status = PSA_ERROR_NOT_SUPPORTED;
diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.data b/tests/suites/test_suite_psa_crypto_driver_wrappers.data
index ddf283f..74e6172 100644
--- a/tests/suites/test_suite_psa_crypto_driver_wrappers.data
+++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.data
@@ -1,41 +1,41 @@
sign_hash through transparent driver: calculate in driver
-ecdsa_sign:PSA_SUCCESS:0:PSA_SUCCESS
+ecdsa_sign:PSA_SUCCESS:"ab45435712649cb30bbddac49197eebf2740ffc7f874d9244c3460f54f322d3a":"9ac4335b469bbd791439248504dd0d49c71349a295fee5a1c68507f45a9e1c7b":"6a3399f69421ffe1490377adf2ea1f117d81a63cf5bf22e918d51175eb259151ce95d7c26cc04e25503e2f7a1ec3573e3c2412534bb4a19b3a7811742f49f50f":0:PSA_SUCCESS
sign_hash through transparent driver: fallback
-ecdsa_sign:PSA_ERROR_NOT_SUPPORTED:0:PSA_SUCCESS
+ecdsa_sign:PSA_ERROR_NOT_SUPPORTED:"ab45435712649cb30bbddac49197eebf2740ffc7f874d9244c3460f54f322d3a":"9ac4335b469bbd791439248504dd0d49c71349a295fee5a1c68507f45a9e1c7b":"6a3399f69421ffe1490377adf2ea1f117d81a63cf5bf22e918d51175eb259151ce95d7c26cc04e25503e2f7a1ec3573e3c2412534bb4a19b3a7811742f49f50f":0:PSA_SUCCESS
sign_hash through transparent driver: error
-ecdsa_sign:PSA_ERROR_GENERIC_ERROR:0:PSA_ERROR_GENERIC_ERROR
+ecdsa_sign:PSA_ERROR_GENERIC_ERROR:"ab45435712649cb30bbddac49197eebf2740ffc7f874d9244c3460f54f322d3a":"9ac4335b469bbd791439248504dd0d49c71349a295fee5a1c68507f45a9e1c7b":"6a3399f69421ffe1490377adf2ea1f117d81a63cf5bf22e918d51175eb259151ce95d7c26cc04e25503e2f7a1ec3573e3c2412534bb4a19b3a7811742f49f50f":0:PSA_ERROR_GENERIC_ERROR
sign_hash through transparent driver: fake
-ecdsa_sign:PSA_SUCCESS:1:PSA_SUCCESS
+ecdsa_sign:PSA_SUCCESS:"ab45435712649cb30bbddac49197eebf2740ffc7f874d9244c3460f54f322d3a":"9ac4335b469bbd791439248504dd0d49c71349a295fee5a1c68507f45a9e1c7b":"000102030405060708090A0B0C0D0E0F":1:PSA_SUCCESS
verify_hash using private key through transparent driver: calculate in driver
-ecdsa_verify:PSA_SUCCESS:0:PSA_SUCCESS
+ecdsa_verify:PSA_SUCCESS:0:"ab45435712649cb30bbddac49197eebf2740ffc7f874d9244c3460f54f322d3a":"9ac4335b469bbd791439248504dd0d49c71349a295fee5a1c68507f45a9e1c7b":"6a3399f69421ffe1490377adf2ea1f117d81a63cf5bf22e918d51175eb259151ce95d7c26cc04e25503e2f7a1ec3573e3c2412534bb4a19b3a7811742f49f50f":PSA_SUCCESS
verify_hash using private key through transparent driver: fallback
-ecdsa_verify:PSA_ERROR_NOT_SUPPORTED:0:PSA_SUCCESS
+ecdsa_verify:PSA_ERROR_NOT_SUPPORTED:0:"ab45435712649cb30bbddac49197eebf2740ffc7f874d9244c3460f54f322d3a":"9ac4335b469bbd791439248504dd0d49c71349a295fee5a1c68507f45a9e1c7b":"6a3399f69421ffe1490377adf2ea1f117d81a63cf5bf22e918d51175eb259151ce95d7c26cc04e25503e2f7a1ec3573e3c2412534bb4a19b3a7811742f49f50f":PSA_SUCCESS
verify_hash using private key through transparent driver: error
-ecdsa_verify:PSA_ERROR_GENERIC_ERROR:0:PSA_ERROR_GENERIC_ERROR
+ecdsa_verify:PSA_ERROR_GENERIC_ERROR:0:"ab45435712649cb30bbddac49197eebf2740ffc7f874d9244c3460f54f322d3a":"9ac4335b469bbd791439248504dd0d49c71349a295fee5a1c68507f45a9e1c7b":"6a3399f69421ffe1490377adf2ea1f117d81a63cf5bf22e918d51175eb259151ce95d7c26cc04e25503e2f7a1ec3573e3c2412534bb4a19b3a7811742f49f50f":PSA_ERROR_GENERIC_ERROR
verify_hash using public key through transparent driver: calculate in driver
-ecdsa_verify:PSA_SUCCESS:1:PSA_SUCCESS
+ecdsa_verify:PSA_SUCCESS:1:"04dea5e45d0ea37fc566232a508f4ad20ea13d47e4bf5fa4d54a57a0ba012042087097496efc583fed8b24a5b9be9a51de063f5a00a8b698a16fd7f29b5485f320":"9ac4335b469bbd791439248504dd0d49c71349a295fee5a1c68507f45a9e1c7b":"6a3399f69421ffe1490377adf2ea1f117d81a63cf5bf22e918d51175eb259151ce95d7c26cc04e25503e2f7a1ec3573e3c2412534bb4a19b3a7811742f49f50f":PSA_SUCCESS
verify_hash using public key through transparent driver: fallback
-ecdsa_verify:PSA_ERROR_NOT_SUPPORTED:1:PSA_SUCCESS
+ecdsa_verify:PSA_ERROR_NOT_SUPPORTED:1:"04dea5e45d0ea37fc566232a508f4ad20ea13d47e4bf5fa4d54a57a0ba012042087097496efc583fed8b24a5b9be9a51de063f5a00a8b698a16fd7f29b5485f320":"9ac4335b469bbd791439248504dd0d49c71349a295fee5a1c68507f45a9e1c7b":"6a3399f69421ffe1490377adf2ea1f117d81a63cf5bf22e918d51175eb259151ce95d7c26cc04e25503e2f7a1ec3573e3c2412534bb4a19b3a7811742f49f50f":PSA_SUCCESS
-verify_hash through transparent driver: error
-ecdsa_verify:PSA_ERROR_GENERIC_ERROR:1:PSA_ERROR_GENERIC_ERROR
+verify_hash using public key through transparent driver: error
+ecdsa_verify:PSA_ERROR_GENERIC_ERROR:1:"04dea5e45d0ea37fc566232a508f4ad20ea13d47e4bf5fa4d54a57a0ba012042087097496efc583fed8b24a5b9be9a51de063f5a00a8b698a16fd7f29b5485f320":"9ac4335b469bbd791439248504dd0d49c71349a295fee5a1c68507f45a9e1c7b":"6a3399f69421ffe1490377adf2ea1f117d81a63cf5bf22e918d51175eb259151ce95d7c26cc04e25503e2f7a1ec3573e3c2412534bb4a19b3a7811742f49f50f":PSA_ERROR_GENERIC_ERROR
generate_key through transparent driver: fake
-generate_key:PSA_SUCCESS:1:PSA_SUCCESS
+generate_key:PSA_SUCCESS:"ab45435712649cb30bbddac49197eebf2740ffc7f874d9244c3460f54f322d3a":PSA_SUCCESS
generate_key through transparent driver: in-driver
-generate_key:PSA_SUCCESS:0:PSA_SUCCESS
+generate_key:PSA_SUCCESS:"":PSA_SUCCESS
generate_key through transparent driver: fallback
-generate_key:PSA_ERROR_NOT_SUPPORTED:0:PSA_SUCCESS
+generate_key:PSA_ERROR_NOT_SUPPORTED:"":PSA_SUCCESS
generate_key through transparent driver: error
-generate_key:PSA_ERROR_GENERIC_ERROR:0:PSA_ERROR_GENERIC_ERROR
+generate_key:PSA_ERROR_GENERIC_ERROR:"":PSA_ERROR_GENERIC_ERROR
diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.function b/tests/suites/test_suite_psa_crypto_driver_wrappers.function
index f8ea80d..c3830a7 100644
--- a/tests/suites/test_suite_psa_crypto_driver_wrappers.function
+++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.function
@@ -2,59 +2,18 @@
#include "test/psa_crypto_helpers.h"
#include "drivers/test_driver.h"
-
-uint8_t test_secp256r1_key_data[32] = {
- 0xab, 0x45, 0x43, 0x57, 0x12, 0x64, 0x9c, 0xb3,
- 0x0b, 0xbd, 0xda, 0xc4, 0x91, 0x97, 0xee, 0xbf,
- 0x27, 0x40, 0xff, 0xc7, 0xf8, 0x74, 0xd9, 0x24,
- 0x4c, 0x34, 0x60, 0xf5, 0x4f, 0x32, 0x2d, 0x3a,
-};
-uint8_t test_hash_32[32] = {
- 0x9a, 0xc4, 0x33, 0x5b, 0x46, 0x9b, 0xbd, 0x79,
- 0x14, 0x39, 0x24, 0x85, 0x04, 0xdd, 0x0d, 0x49,
- 0xc7, 0x13, 0x49, 0xa2, 0x95, 0xfe, 0xe5, 0xa1,
- 0xc6, 0x85, 0x07, 0xf4, 0x5a, 0x9e, 0x1c, 0x7b,
-};
-uint8_t test_signature_hash_32_with_secp256r1[64] = {
- 0x6a, 0x33, 0x99, 0xf6, 0x94, 0x21, 0xff, 0xe1,
- 0x49, 0x03, 0x77, 0xad, 0xf2, 0xea, 0x1f, 0x11,
- 0x7d, 0x81, 0xa6, 0x3c, 0xf5, 0xbf, 0x22, 0xe9,
- 0x18, 0xd5, 0x11, 0x75, 0xeb, 0x25, 0x91, 0x51,
- 0xce, 0x95, 0xd7, 0xc2, 0x6c, 0xc0, 0x4e, 0x25,
- 0x50, 0x3e, 0x2f, 0x7a, 0x1e, 0xc3, 0x57, 0x3e,
- 0x3c, 0x24, 0x12, 0x53, 0x4b, 0xb4, 0xa1, 0x9b,
- 0x3a, 0x78, 0x11, 0x74, 0x2f, 0x49, 0xf5, 0x0f,
-};
-uint8_t test_secp256r1_public_key_data[65] = {
- 0x04,
- 0xde, 0xa5, 0xe4, 0x5d, 0x0e, 0xa3, 0x7f, 0xc5,
- 0x66, 0x23, 0x2a, 0x50, 0x8f, 0x4a, 0xd2, 0x0e,
- 0xa1, 0x3d, 0x47, 0xe4, 0xbf, 0x5f, 0xa4, 0xd5,
- 0x4a, 0x57, 0xa0, 0xba, 0x01, 0x20, 0x42, 0x08,
- 0x70, 0x97, 0x49, 0x6e, 0xfc, 0x58, 0x3f, 0xed,
- 0x8b, 0x24, 0xa5, 0xb9, 0xbe, 0x9a, 0x51, 0xde,
- 0x06, 0x3f, 0x5a, 0x00, 0xa8, 0xb6, 0x98, 0xa1,
- 0x6f, 0xd7, 0xf2, 0x9b, 0x54, 0x85, 0xf3, 0x20
-};
-
-uint8_t test_fake_output[] = "INJECTED OUTPUT";
-
-typedef enum
-{
- EXPECT_FAILURE,
- EXPECT_CORRECT_OUTPUT,
- EXPECT_FAKE_OUTPUT,
-} expected_output_t;
-
/* END_HEADER */
/* BEGIN_DEPENDENCIES
- * depends_on:MBEDTLS_PSA_CRYPTO_C:MBEDTLS_PSA_CRYPTO_DRIVERS:MBEDTLS_PSA_CRYPTO_DRIVER_TEST
+ * depends_on:MBEDTLS_PSA_CRYPTO_C:MBEDTLS_PSA_CRYPTO_DRIVERS:PSA_CRYPTO_DRIVER_TEST
* END_DEPENDENCIES
*/
/* BEGIN_CASE depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECDSA_DETERMINISTIC:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C */
void ecdsa_sign( int force_status_arg,
+ data_t *key_input,
+ data_t *data_input,
+ data_t *expected_output,
int fake_output,
int expected_status_arg )
{
@@ -65,9 +24,8 @@
psa_algorithm_t alg = PSA_ALG_DETERMINISTIC_ECDSA( PSA_ALG_SHA_256 );
uint8_t signature[64];
size_t signature_length = 0xdeadbeef;
- const uint8_t *expected_output;
- size_t expected_output_length;
psa_status_t actual_status;
+ test_driver_signature_sign_hooks = test_driver_signature_hooks_init();
PSA_ASSERT( psa_crypto_init( ) );
psa_set_key_type( &attributes,
@@ -75,48 +33,42 @@
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_HASH );
psa_set_key_algorithm( &attributes, alg );
psa_import_key( &attributes,
- test_secp256r1_key_data, sizeof( test_secp256r1_key_data ),
+ key_input->x, key_input->len,
&handle );
- test_transparent_signature_sign_hash_hit = 0;
- test_transparent_signature_sign_hash_status = force_status;
- if( fake_output )
+ test_driver_signature_sign_hooks.forced_status = force_status;
+ if( fake_output == 1 )
{
- expected_output = test_driver_forced_output = test_fake_output;
- expected_output_length = test_driver_forced_output_length =
- sizeof( test_fake_output );
- }
- else
- {
- expected_output = test_signature_hash_32_with_secp256r1;
- expected_output_length = sizeof( test_signature_hash_32_with_secp256r1 );
+ test_driver_signature_sign_hooks.forced_output = expected_output->x;
+ test_driver_signature_sign_hooks.forced_output_length = expected_output->len;
}
actual_status = psa_sign_hash( handle, alg,
- test_hash_32, sizeof( test_hash_32 ),
+ data_input->x, data_input->len,
signature, sizeof( signature ),
&signature_length );
TEST_EQUAL( actual_status, expected_status );
if( expected_status == PSA_SUCCESS )
{
ASSERT_COMPARE( signature, signature_length,
- expected_output, expected_output_length );
+ expected_output->x, expected_output->len );
}
- TEST_EQUAL( test_transparent_signature_sign_hash_hit, 1 );
+ TEST_EQUAL( test_driver_signature_sign_hooks.hits, 1 );
exit:
psa_reset_key_attributes( &attributes );
psa_destroy_key( handle );
PSA_DONE( );
- test_transparent_signature_sign_hash_status = PSA_ERROR_NOT_SUPPORTED;
- test_driver_forced_output = NULL;
- test_driver_forced_output_length = 0;
+ test_driver_signature_sign_hooks = test_driver_signature_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECDSA_DETERMINISTIC:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C */
void ecdsa_verify( int force_status_arg,
int register_public_key,
+ data_t *key_input,
+ data_t *data_input,
+ data_t *signature_input,
int expected_status_arg )
{
psa_status_t force_status = force_status_arg;
@@ -124,9 +76,8 @@
psa_key_handle_t handle = 0;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_algorithm_t alg = PSA_ALG_DETERMINISTIC_ECDSA( PSA_ALG_SHA_256 );
- const uint8_t *expected_output;
- size_t expected_output_length;
psa_status_t actual_status;
+ test_driver_signature_verify_hooks = test_driver_signature_hooks_init();
PSA_ASSERT( psa_crypto_init( ) );
if( register_public_key )
@@ -136,7 +87,7 @@
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_HASH );
psa_set_key_algorithm( &attributes, alg );
psa_import_key( &attributes,
- test_secp256r1_public_key_data, sizeof( test_secp256r1_public_key_data ),
+ key_input->x, key_input->len,
&handle );
}
else
@@ -146,35 +97,29 @@
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_HASH );
psa_set_key_algorithm( &attributes, alg );
psa_import_key( &attributes,
- test_secp256r1_key_data, sizeof( test_secp256r1_key_data ),
+ key_input->x, key_input->len,
&handle );
}
- test_transparent_signature_verify_hash_hit = 0;
- test_transparent_signature_verify_hash_status = force_status;
-
- expected_output = test_signature_hash_32_with_secp256r1;
- expected_output_length = sizeof( test_signature_hash_32_with_secp256r1 );
+ test_driver_signature_verify_hooks.forced_status = force_status;
actual_status = psa_verify_hash( handle, alg,
- test_hash_32, sizeof( test_hash_32 ),
- expected_output, expected_output_length );
+ data_input->x, data_input->len,
+ signature_input->x, signature_input->len );
TEST_EQUAL( actual_status, expected_status );
- TEST_EQUAL( test_transparent_signature_verify_hash_hit, 1 );
+ TEST_EQUAL( test_driver_signature_verify_hooks.hits, 1 );
exit:
psa_reset_key_attributes( &attributes );
psa_destroy_key( handle );
PSA_DONE( );
- test_transparent_signature_sign_hash_status = PSA_ERROR_NOT_SUPPORTED;
- test_driver_forced_output = NULL;
- test_driver_forced_output_length = 0;
+ test_driver_signature_verify_hooks = test_driver_signature_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED */
void generate_key( int force_status_arg,
- int fake_output,
+ data_t *fake_output,
int expected_status_arg )
{
psa_status_t force_status = force_status_arg;
@@ -182,11 +127,12 @@
psa_key_handle_t handle = 0;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_algorithm_t alg = PSA_ALG_ECDSA( PSA_ALG_SHA_256 );
- const uint8_t *expected_output;
- size_t expected_output_length;
+ const uint8_t *expected_output = NULL;
+ size_t expected_output_length = 0;
psa_status_t actual_status;
- uint8_t actual_output[sizeof(test_secp256r1_key_data)] = {0};
+ uint8_t actual_output[PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(256)] = {0};
size_t actual_output_length;
+ test_driver_keygen_hooks = test_driver_keygen_hooks_init();
psa_set_key_type( &attributes,
PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_CURVE_SECP_R1 ) );
@@ -194,29 +140,27 @@
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_EXPORT );
psa_set_key_algorithm( &attributes, alg );
- if( fake_output )
+ if( fake_output->len > 0 )
{
- expected_output = test_driver_keygen_forced_output = test_secp256r1_key_data;
- expected_output_length = test_driver_keygen_forced_output_length =
- sizeof( test_secp256r1_key_data );
+ expected_output = test_driver_keygen_hooks.forced_output = fake_output->x;
+ expected_output_length = test_driver_keygen_hooks.forced_output_length =
+ fake_output->len;
}
- test_transparent_keygen_hit = 0;
- test_transparent_keygen_status = force_status;
+ test_driver_keygen_hooks.hits = 0;
+ test_driver_keygen_hooks.forced_status = force_status;
PSA_ASSERT( psa_crypto_init( ) );
actual_status = psa_generate_key( &attributes, &handle );
- fprintf(stdout, "rteturn %d\n", actual_status);
-
- TEST_EQUAL( test_transparent_keygen_hit, 1 );
+ TEST_EQUAL( test_driver_keygen_hooks.hits, 1 );
TEST_EQUAL( actual_status, expected_status );
if( actual_status == PSA_SUCCESS )
{
psa_export_key( handle, actual_output, sizeof(actual_output), &actual_output_length );
- if( fake_output )
+ if( fake_output->len > 0 )
{
ASSERT_COMPARE( actual_output, actual_output_length,
expected_output, expected_output_length );
@@ -236,8 +180,6 @@
psa_reset_key_attributes( &attributes );
psa_destroy_key( handle );
PSA_DONE( );
- test_transparent_signature_sign_hash_status = PSA_ERROR_NOT_SUPPORTED;
- test_driver_keygen_forced_output = NULL;
- test_driver_keygen_forced_output_length = 0;
+ test_driver_keygen_hooks = test_driver_keygen_hooks_init();
}
/* END_CASE */