Skip to content

Commit

Permalink
Fix failure in some configs by being more precise
Browse files Browse the repository at this point in the history
This test was failing in test_psa_crypto_config_accel_cipher_aead
because there are hits to the key management driver from CTR-DRBG.

This is fixed by counting hits not just for the whole key management
area, but for specific entry point, making the test more specific and
more robust.

Also fix the location of psa_crypto_init() relative to forcing errors.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
  • Loading branch information
mpg committed Dec 22, 2023
1 parent 4805fc1 commit 9cf821c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions tests/include/test/drivers/key_management.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ typedef struct {
/* Count the amount of times one of the key management driver functions
* is called. */
unsigned long hits;
/* Subset of hits which only counts key operations with EC key */
/* Subset of hits which only counts specific operations */
unsigned long hits_export_public_key;
unsigned long hits_generate_key;
/* Location of the last key management driver called to import a key. */
psa_key_location_t location;
} mbedtls_test_driver_key_management_hooks_t;
Expand All @@ -36,7 +37,7 @@ typedef struct {
* sense that no PSA specification will assign a meaning to this location
* (stated first in version 1.0.1 of the specification) and that it is not
* used as a location of an opaque test drivers. */
#define MBEDTLS_TEST_DRIVER_KEY_MANAGEMENT_INIT { NULL, 0, PSA_SUCCESS, 0, 0, 0x800000 }
#define MBEDTLS_TEST_DRIVER_KEY_MANAGEMENT_INIT { NULL, 0, PSA_SUCCESS, 0, 0, 0, 0x800000 }
static inline mbedtls_test_driver_key_management_hooks_t
mbedtls_test_driver_key_management_hooks_init(void)
{
Expand Down
1 change: 1 addition & 0 deletions tests/src/drivers/test_driver_key_management.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ psa_status_t mbedtls_test_transparent_generate_key(
uint8_t *key, size_t key_size, size_t *key_length)
{
++mbedtls_test_driver_key_management_hooks.hits;
++mbedtls_test_driver_key_management_hooks.hits_generate_key;

if (mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS) {
return mbedtls_test_driver_key_management_hooks.forced_status;
Expand Down
8 changes: 4 additions & 4 deletions tests/suites/test_suite_psa_crypto_driver_wrappers.function
Original file line number Diff line number Diff line change
Expand Up @@ -782,13 +782,13 @@ void generate_ec_key(int force_status_arg,
fake_output->len;
}

mbedtls_test_driver_key_management_hooks.hits = 0;
mbedtls_test_driver_key_management_hooks.forced_status = force_status;

PSA_ASSERT(psa_crypto_init());

mbedtls_test_driver_key_management_hooks.hits_generate_key = 0;
mbedtls_test_driver_key_management_hooks.forced_status = force_status;

actual_status = psa_generate_key(&attributes, &key);
TEST_EQUAL(mbedtls_test_driver_key_management_hooks.hits, 1);
TEST_EQUAL(mbedtls_test_driver_key_management_hooks.hits_generate_key, 1);
TEST_EQUAL(actual_status, expected_status);

if (actual_status == PSA_SUCCESS) {
Expand Down

0 comments on commit 9cf821c

Please sign in to comment.