mirror of
https://github.com/cuberite/polarssl.git
synced 2025-10-03 02:23:32 -04:00
Add key_destroyable parameter to exercise_asymmetric_encryption_key
Signed-off-by: Ryan Everett <ryan.everett@arm.com>
This commit is contained in:
parent
6edd40819e
commit
d48fc102d3
@ -438,7 +438,8 @@ exit:
|
|||||||
|
|
||||||
static int exercise_asymmetric_encryption_key(mbedtls_svc_key_id_t key,
|
static int exercise_asymmetric_encryption_key(mbedtls_svc_key_id_t key,
|
||||||
psa_key_usage_t usage,
|
psa_key_usage_t usage,
|
||||||
psa_algorithm_t alg)
|
psa_algorithm_t alg,
|
||||||
|
int key_destroyable)
|
||||||
{
|
{
|
||||||
unsigned char plaintext[PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE] =
|
unsigned char plaintext[PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE] =
|
||||||
"Hello, world...";
|
"Hello, world...";
|
||||||
@ -446,22 +447,30 @@ static int exercise_asymmetric_encryption_key(mbedtls_svc_key_id_t key,
|
|||||||
"(wabblewebblewibblewobblewubble)";
|
"(wabblewebblewibblewobblewubble)";
|
||||||
size_t ciphertext_length = sizeof(ciphertext);
|
size_t ciphertext_length = sizeof(ciphertext);
|
||||||
size_t plaintext_length = 16;
|
size_t plaintext_length = 16;
|
||||||
|
psa_status_t status = PSA_SUCCESS;
|
||||||
if (usage & PSA_KEY_USAGE_ENCRYPT) {
|
if (usage & PSA_KEY_USAGE_ENCRYPT) {
|
||||||
PSA_ASSERT(psa_asymmetric_encrypt(key, alg,
|
status = psa_asymmetric_encrypt(key, alg,
|
||||||
plaintext, plaintext_length,
|
plaintext, plaintext_length,
|
||||||
NULL, 0,
|
NULL, 0,
|
||||||
ciphertext, sizeof(ciphertext),
|
ciphertext, sizeof(ciphertext),
|
||||||
&ciphertext_length));
|
&ciphertext_length);
|
||||||
|
if (key_destroyable && status == PSA_ERROR_INVALID_HANDLE) {
|
||||||
|
/* The key has been destroyed. */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
PSA_ASSERT(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (usage & PSA_KEY_USAGE_DECRYPT) {
|
if (usage & PSA_KEY_USAGE_DECRYPT) {
|
||||||
psa_status_t status =
|
status = psa_asymmetric_decrypt(key, alg,
|
||||||
psa_asymmetric_decrypt(key, alg,
|
|
||||||
ciphertext, ciphertext_length,
|
ciphertext, ciphertext_length,
|
||||||
NULL, 0,
|
NULL, 0,
|
||||||
plaintext, sizeof(plaintext),
|
plaintext, sizeof(plaintext),
|
||||||
&plaintext_length);
|
&plaintext_length);
|
||||||
|
if (key_destroyable && status == PSA_ERROR_INVALID_HANDLE) {
|
||||||
|
/* The key has been destroyed. */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
TEST_ASSERT(status == PSA_SUCCESS ||
|
TEST_ASSERT(status == PSA_SUCCESS ||
|
||||||
((usage & PSA_KEY_USAGE_ENCRYPT) == 0 &&
|
((usage & PSA_KEY_USAGE_ENCRYPT) == 0 &&
|
||||||
(status == PSA_ERROR_INVALID_ARGUMENT ||
|
(status == PSA_ERROR_INVALID_ARGUMENT ||
|
||||||
|
Loading…
x
Reference in New Issue
Block a user