mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-25 00:02:42 +00:00
test_suite_psa_crypto_slot_management: modify check on open key slots
This commit - Reverts changes previously done to psa_crypto_helpers.[c,h] - Implements a new check for open key slots in mbedtls_test_helper_is_psa_leaking(): - when CTR_DRBG does not use AES_C or PSA does not have an external RNG, then we allow 1 key slot (it's the one holding the AES key) - when the above conditions are not met, then we fallback to the usual check for "no open key slots remaining" Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
parent
7ab90723c4
commit
7448367f68
@ -34,7 +34,6 @@
|
|||||||
#define PSA_DONE() \
|
#define PSA_DONE() \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
mbedtls_psa_random_free(); \
|
|
||||||
mbedtls_test_fail_if_psa_leaking(__LINE__, __FILE__); \
|
mbedtls_test_fail_if_psa_leaking(__LINE__, __FILE__); \
|
||||||
mbedtls_test_psa_purge_key_storage(); \
|
mbedtls_test_psa_purge_key_storage(); \
|
||||||
mbedtls_psa_crypto_free(); \
|
mbedtls_psa_crypto_free(); \
|
||||||
@ -126,9 +125,6 @@ const char *mbedtls_test_helper_is_psa_leaking(void);
|
|||||||
|
|
||||||
/** Shut down the PSA Crypto subsystem, allowing persistent keys to survive.
|
/** Shut down the PSA Crypto subsystem, allowing persistent keys to survive.
|
||||||
* Expect a clean shutdown, with no slots in use.
|
* Expect a clean shutdown, with no slots in use.
|
||||||
* mbedtls_psa_random_free() is called before any check for remaining open
|
|
||||||
* keys because when AES_C is not defined, CTR_DRBG relies on PSA to perform
|
|
||||||
* AES-ECB so it holds an open AES key for that since psa_crypto_init().
|
|
||||||
*
|
*
|
||||||
* If some key slots are still in use, record the test case as failed and
|
* If some key slots are still in use, record the test case as failed and
|
||||||
* jump to the `exit` label.
|
* jump to the `exit` label.
|
||||||
@ -136,7 +132,6 @@ const char *mbedtls_test_helper_is_psa_leaking(void);
|
|||||||
#define PSA_SESSION_DONE() \
|
#define PSA_SESSION_DONE() \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
mbedtls_psa_random_free(); \
|
|
||||||
mbedtls_test_psa_purge_key_cache(); \
|
mbedtls_test_psa_purge_key_cache(); \
|
||||||
ASSERT_PSA_PRISTINE(); \
|
ASSERT_PSA_PRISTINE(); \
|
||||||
mbedtls_psa_crypto_free(); \
|
mbedtls_psa_crypto_free(); \
|
||||||
|
@ -70,9 +70,20 @@ const char *mbedtls_test_helper_is_psa_leaking(void)
|
|||||||
|
|
||||||
mbedtls_psa_get_stats(&stats);
|
mbedtls_psa_get_stats(&stats);
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_CTR_DRBG_C) && !defined(MBEDTLS_AES_C) && \
|
||||||
|
!defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
|
||||||
|
/* When AES_C is not defined and PSA does not have an external RNG,
|
||||||
|
* then CTR_DRBG uses PSA to perform AES-ECB. In this scenario 1 key
|
||||||
|
* slot is used internally from PSA to hold the AES key and it should
|
||||||
|
* not be taken into account when evaluating remaining open slots. */
|
||||||
|
if (stats.volatile_slots > 1) {
|
||||||
|
return "A volatile slot has not been closed properly.";
|
||||||
|
}
|
||||||
|
#else
|
||||||
if (stats.volatile_slots != 0) {
|
if (stats.volatile_slots != 0) {
|
||||||
return "A volatile slot has not been closed properly.";
|
return "A volatile slot has not been closed properly.";
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (stats.persistent_slots != 0) {
|
if (stats.persistent_slots != 0) {
|
||||||
return "A persistent slot has not been closed properly.";
|
return "A persistent slot has not been closed properly.";
|
||||||
}
|
}
|
||||||
|
@ -90,10 +90,10 @@ static int invalidate_psa(invalidate_method_t invalidate_method)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* When AES_C is not defined CTR_DRBG relies on PSA to get AES-ECB so it
|
|
||||||
* holds an open key once psa_crypto_init() is called. */
|
|
||||||
ASSERT_PSA_PRISTINE();
|
|
||||||
PSA_ASSERT(psa_crypto_init());
|
PSA_ASSERT(psa_crypto_init());
|
||||||
|
|
||||||
|
ASSERT_PSA_PRISTINE();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user