Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testing for concurrently loading/using/destroying the same key #8924

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
0a271fd
Add key_destroyable parameter to mbedtls_test_psa_exercise_key
Ryan-Everett-arm Mar 12, 2024
f08a93f
Add key_destroyable parameter to check_key_attributes_sanity
Ryan-Everett-arm Mar 12, 2024
7763550
Add key_destroyable parameter to exercise_mac_key
Ryan-Everett-arm Mar 12, 2024
70691f3
Add key_destroyable parameter to psa_exercise_cipher_key
Ryan-Everett-arm Mar 12, 2024
fbe703d
Add key_destroyable parameter to exercise_aead_key
Ryan-Everett-arm Mar 12, 2024
6edd408
Add key_destroyable parameter to exercise_signature_key
Ryan-Everett-arm Mar 12, 2024
d48fc10
Add key_destroyable parameter to exercise_asymmetric_encryption_key
Ryan-Everett-arm Mar 12, 2024
c1cc668
Add key_destroyable parameter to key derivation smoke tests
Ryan-Everett-arm Mar 12, 2024
8163028
Add key_destroyable parameter to raw key agreement smoke tests
Ryan-Everett-arm Mar 12, 2024
73e4ea3
Add key_destroyable parameter to non-raw key agreement smoke tests
Ryan-Everett-arm Mar 12, 2024
fbf815d
Add key_destroyable parameter to key export smoke tests
Ryan-Everett-arm Mar 12, 2024
5061999
Add test function for concurrently using the same persistent key
Ryan-Everett-arm Mar 12, 2024
f111f35
Add test cases for concurrently_use_same_persistent_key
Ryan-Everett-arm Mar 12, 2024
6c48870
Fix typo in thread_import_key
Ryan-Everett-arm Mar 14, 2024
3de040f
Use TEST_FAIL in threaded tests
Ryan-Everett-arm Mar 14, 2024
6de38ac
Add missing PSA_ASSERT in mbedtls_test_psa_raw_key_agreement_with_self
Ryan-Everett-arm Mar 14, 2024
e1b50f3
Document unsupported concurrency scenario in psa_exercise_key
Ryan-Everett-arm Mar 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions tests/include/test/psa_exercise_key.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
* \param input2 The first input to pass.
* \param input2_length The length of \p input2 in bytes.
* \param capacity The capacity to set.
* \param key_destroyable If set to 1, a failure due to the key not existing
* or the key being destroyed mid-operation will only
* be reported if the error code is unexpected.
*
* \return \c 1 on success, \c 0 on failure.
*/
Expand All @@ -132,7 +135,7 @@ int mbedtls_test_psa_setup_key_derivation_wrap(
psa_algorithm_t alg,
const unsigned char *input1, size_t input1_length,
const unsigned char *input2, size_t input2_length,
size_t capacity);
size_t capacity, int key_destroyable);

/** Perform a key agreement using the given key pair against its public key
* using psa_raw_key_agreement().
Expand All @@ -143,12 +146,15 @@ int mbedtls_test_psa_setup_key_derivation_wrap(
*
* \param alg A key agreement algorithm compatible with \p key.
* \param key A key that allows key agreement with \p alg.
* \param key_destroyable If set to 1, a failure due to the key not existing
* or the key being destroyed mid-operation will only
* be reported if the error code is unexpected.
*
* \return \c 1 on success, \c 0 on failure.
*/
psa_status_t mbedtls_test_psa_raw_key_agreement_with_self(
psa_algorithm_t alg,
mbedtls_svc_key_id_t key);
mbedtls_svc_key_id_t key, int key_destroyable);

/** Perform a key agreement using the given key pair against its public key
* using psa_key_derivation_raw_key().
Expand All @@ -162,12 +168,15 @@ psa_status_t mbedtls_test_psa_raw_key_agreement_with_self(
* \p key.
* \param key A key pair object that is suitable for a key
* agreement with \p operation.
* \param key_destroyable If set to 1, a failure due to the key not existing
* or the key being destroyed mid-operation will only
* be reported if the error code is unexpected.
*
* \return \c 1 on success, \c 0 on failure.
*/
psa_status_t mbedtls_test_psa_key_agreement_with_self(
psa_key_derivation_operation_t *operation,
mbedtls_svc_key_id_t key);
mbedtls_svc_key_id_t key, int key_destroyable);

/** Perform sanity checks on the given key representation.
*
Expand Down Expand Up @@ -209,18 +218,34 @@ int mbedtls_test_psa_exported_key_sanity_check(
* ```
* if( ! exercise_key( ... ) ) goto exit;
* ```
*
* \param key The key to exercise. It should be capable of performing
* \p alg.
* \param usage The usage flags to assume.
* \param alg The algorithm to exercise.
* To use this function for multi-threaded tests where the key
* may be destroyed at any point: call this function with key_destroyable set
* to 1, while another thread calls psa_destroy_key on the same key;
* this will test whether destroying the key in use leads to any corruption.
*
* There cannot be a set of concurrent calls:
* `mbedtls_test_psa_exercise_key(ki,...)` such that each ki is a unique
* persistent key not loaded into any key slot, and i is greater than the
* number of free key slots.
* This is because such scenarios can lead to unsupported
* `PSA_ERROR_INSUFFICIENT_MEMORY` return codes.
*
*
* \param key The key to exercise. It should be capable of performing
* \p alg.
* \param usage The usage flags to assume.
* \param alg The algorithm to exercise.
* \param key_destroyable If set to 1, a failure due to the key not existing
* or the key being destroyed mid-operation will only
* be reported if the error code is unexpected.
*
* \retval 0 The key failed the smoke tests.
* \retval 1 The key passed the smoke tests.
*/
int mbedtls_test_psa_exercise_key(mbedtls_svc_key_id_t key,
psa_key_usage_t usage,
psa_algorithm_t alg);
psa_algorithm_t alg,
int key_destroyable);

psa_key_usage_t mbedtls_test_psa_usage_to_exercise(psa_key_type_t type,
psa_algorithm_t alg);
Expand Down
Loading