Allow multiple return statuses where reasonable
psa_aead_verify always outputs 0 bytes in Mbed TLS, so accept
PSA_SUCCESS as well in the small buffer test.
Allow psa_aead_setup to return PSA_ERROR_NOT_SUPPORTED for incompatible
algorithm / key type pairs in addition to PSA_ERROR_INVALID_ARGUMENT.
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
diff --git a/api-tests/dev_apis/crypto/test_c052/test_c052.c b/api-tests/dev_apis/crypto/test_c052/test_c052.c
index 480508e..d50237b 100644
--- a/api-tests/dev_apis/crypto/test_c052/test_c052.c
+++ b/api-tests/dev_apis/crypto/test_c052/test_c052.c
@@ -82,7 +82,10 @@
&operation,
key,
check1[i].setup_alg);
- TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(4));
+ TEST_ASSERT_DUAL(status,
+ check1[i].expected_status[0],
+ check1[i].expected_status[1],
+ TEST_CHECKPOINT_NUM(4));
/* Abort the AEAD operation */
status = val->crypto_function(VAL_CRYPTO_AEAD_ABORT,
diff --git a/api-tests/dev_apis/crypto/test_c052/test_data.h b/api-tests/dev_apis/crypto/test_c052/test_data.h
index 30c0a82..e72890c 100644
--- a/api-tests/dev_apis/crypto/test_c052/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c052/test_data.h
@@ -25,7 +25,7 @@
psa_key_usage_t usage_flags;
psa_algorithm_t alg;
psa_algorithm_t setup_alg;
- psa_status_t expected_status;
+ psa_status_t expected_status[2];
} test_data;
static const test_data check1[] = {
@@ -39,7 +39,7 @@
.usage_flags = PSA_KEY_USAGE_ENCRYPT,
.alg = PSA_ALG_CCM,
.setup_alg = PSA_ALG_CCM,
- .expected_status = PSA_SUCCESS
+ .expected_status = {PSA_SUCCESS, PSA_SUCCESS}
},
{
@@ -50,7 +50,7 @@
.usage_flags = PSA_KEY_USAGE_ENCRYPT,
.alg = PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, 4),
.setup_alg = PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, 4),
- .expected_status = PSA_SUCCESS
+ .expected_status = {PSA_SUCCESS, PSA_SUCCESS}
},
{
@@ -61,7 +61,7 @@
.usage_flags = PSA_KEY_USAGE_ENCRYPT,
.alg = PSA_ALG_CCM,
.setup_alg = PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, 4),
- .expected_status = PSA_ERROR_NOT_PERMITTED
+ .expected_status = {PSA_ERROR_NOT_PERMITTED, PSA_ERROR_NOT_PERMITTED}
},
{
@@ -72,7 +72,7 @@
.usage_flags = PSA_KEY_USAGE_ENCRYPT,
.alg = PSA_ALG_CCM,
.setup_alg = PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(PSA_ALG_CCM),
- .expected_status = PSA_SUCCESS
+ .expected_status = {PSA_SUCCESS, PSA_SUCCESS}
},
#endif
#endif
@@ -87,7 +87,7 @@
.usage_flags = PSA_KEY_USAGE_ENCRYPT,
.alg = PSA_ALG_GCM,
.setup_alg = PSA_ALG_GCM,
- .expected_status = PSA_SUCCESS
+ .expected_status = {PSA_SUCCESS, PSA_SUCCESS}
},
#endif
#endif
@@ -102,7 +102,7 @@
.usage_flags = PSA_KEY_USAGE_ENCRYPT,
.alg = PSA_ALG_CCM,
.setup_alg = PSA_ALG_CCM,
- .expected_status = PSA_ERROR_INVALID_ARGUMENT
+ .expected_status = {PSA_ERROR_INVALID_ARGUMENT, PSA_ERROR_NOT_SUPPORTED}
},
#endif
#endif
@@ -117,7 +117,7 @@
.usage_flags = PSA_KEY_USAGE_ENCRYPT,
.alg = PSA_ALG_CFB,
.setup_alg = PSA_ALG_CFB,
- .expected_status = PSA_ERROR_NOT_SUPPORTED
+ .expected_status = {PSA_ERROR_NOT_SUPPORTED, PSA_ERROR_NOT_SUPPORTED}
},
#endif
@@ -130,7 +130,7 @@
.usage_flags = PSA_KEY_USAGE_DECRYPT,
.alg = PSA_ALG_GCM,
.setup_alg = PSA_ALG_GCM,
- .expected_status = PSA_ERROR_NOT_PERMITTED
+ .expected_status = {PSA_ERROR_NOT_PERMITTED, PSA_ERROR_NOT_PERMITTED}
},
#endif
#endif
diff --git a/api-tests/dev_apis/crypto/test_c053/test_c053.c b/api-tests/dev_apis/crypto/test_c053/test_c053.c
index ca8f617..7b58cce 100644
--- a/api-tests/dev_apis/crypto/test_c053/test_c053.c
+++ b/api-tests/dev_apis/crypto/test_c053/test_c053.c
@@ -82,7 +82,10 @@
&operation,
key,
check1[i].setup_alg);
- TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(4));
+ TEST_ASSERT_DUAL(status,
+ check1[i].expected_status[0],
+ check1[i].expected_status[1],
+ TEST_CHECKPOINT_NUM(4));
/* Abort the AEAD operation */
status = val->crypto_function(VAL_CRYPTO_AEAD_ABORT,
diff --git a/api-tests/dev_apis/crypto/test_c053/test_data.h b/api-tests/dev_apis/crypto/test_c053/test_data.h
index dd50f57..907947f 100644
--- a/api-tests/dev_apis/crypto/test_c053/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c053/test_data.h
@@ -25,7 +25,7 @@
psa_key_usage_t usage_flags;
psa_algorithm_t alg;
psa_algorithm_t setup_alg;
- psa_status_t expected_status;
+ psa_status_t expected_status[2];
} test_data;
static const test_data check1[] = {
@@ -39,7 +39,7 @@
.usage_flags = PSA_KEY_USAGE_DECRYPT,
.alg = PSA_ALG_CCM,
.setup_alg = PSA_ALG_CCM,
- .expected_status = PSA_SUCCESS
+ .expected_status = {PSA_SUCCESS, PSA_SUCCESS}
},
{
@@ -50,7 +50,7 @@
.usage_flags = PSA_KEY_USAGE_DECRYPT,
.alg = PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, 4),
.setup_alg = PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, 4),
- .expected_status = PSA_SUCCESS
+ .expected_status = {PSA_SUCCESS, PSA_SUCCESS}
},
{
@@ -61,7 +61,7 @@
.usage_flags = PSA_KEY_USAGE_DECRYPT,
.alg = PSA_ALG_CCM,
.setup_alg = PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, 4),
- .expected_status = PSA_ERROR_NOT_PERMITTED
+ .expected_status = {PSA_ERROR_NOT_PERMITTED, PSA_ERROR_NOT_PERMITTED}
},
{
@@ -72,7 +72,7 @@
.usage_flags = PSA_KEY_USAGE_DECRYPT,
.alg = PSA_ALG_CCM,
.setup_alg = PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(PSA_ALG_CCM),
- .expected_status = PSA_SUCCESS
+ .expected_status = {PSA_SUCCESS, PSA_SUCCESS}
},
#endif
#endif
@@ -87,7 +87,7 @@
.usage_flags = PSA_KEY_USAGE_DECRYPT,
.alg = PSA_ALG_GCM,
.setup_alg = PSA_ALG_GCM,
- .expected_status = PSA_SUCCESS
+ .expected_status = {PSA_SUCCESS, PSA_SUCCESS}
},
#endif
#endif
@@ -102,7 +102,7 @@
.usage_flags = PSA_KEY_USAGE_DECRYPT,
.alg = PSA_ALG_CCM,
.setup_alg = PSA_ALG_CCM,
- .expected_status = PSA_ERROR_INVALID_ARGUMENT
+ .expected_status = {PSA_ERROR_INVALID_ARGUMENT, PSA_ERROR_NOT_SUPPORTED}
},
#endif
#endif
@@ -117,7 +117,7 @@
.usage_flags = PSA_KEY_USAGE_DECRYPT,
.alg = PSA_ALG_CFB,
.setup_alg = PSA_ALG_CFB,
- .expected_status = PSA_ERROR_NOT_SUPPORTED
+ .expected_status = {PSA_ERROR_NOT_SUPPORTED, PSA_ERROR_NOT_SUPPORTED}
},
#endif
@@ -130,7 +130,7 @@
.usage_flags = PSA_KEY_USAGE_ENCRYPT,
.alg = PSA_ALG_GCM,
.setup_alg = PSA_ALG_GCM,
- .expected_status = PSA_ERROR_NOT_PERMITTED
+ .expected_status = {PSA_ERROR_NOT_PERMITTED, PSA_ERROR_NOT_PERMITTED}
},
#endif
#endif
diff --git a/api-tests/dev_apis/crypto/test_c061/test_c061.c b/api-tests/dev_apis/crypto/test_c061/test_c061.c
index 1dfd200..3d0272b 100644
--- a/api-tests/dev_apis/crypto/test_c061/test_c061.c
+++ b/api-tests/dev_apis/crypto/test_c061/test_c061.c
@@ -96,9 +96,12 @@
/* Finish authenticating and decrypting a message in an AEAD operation */
status = val->crypto_function(VAL_CRYPTO_AEAD_VERIFY, &operation, output + length,
check1[i].output_size, &verify_length, check1[i].tag, check1[i].tag_length);
- TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(9));
+ TEST_ASSERT_DUAL(status,
+ check1[i].expected_status[0],
+ check1[i].expected_status[1],
+ TEST_CHECKPOINT_NUM(9));
- if (check1[i].expected_status != PSA_SUCCESS)
+ if (status != PSA_SUCCESS)
{
/* Finish authenticating and decrypting a msg with an inactive operator should fail */
status = val->crypto_function(VAL_CRYPTO_AEAD_VERIFY, &operation, output,
diff --git a/api-tests/dev_apis/crypto/test_c061/test_data.h b/api-tests/dev_apis/crypto/test_c061/test_data.h
index 884cde7..f66c0e4 100644
--- a/api-tests/dev_apis/crypto/test_c061/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c061/test_data.h
@@ -37,7 +37,7 @@
size_t ciphertext_length;
uint8_t tag[64];
size_t tag_length;
- psa_status_t expected_status;
+ psa_status_t expected_status[2];
} test_data;
static const test_data check1[] = {
@@ -59,7 +59,7 @@
24,
{0xd8, 0x0e, 0x8b, 0xf8, 0x0f, 0x4a, 0x46, 0xca, 0xb0, 0x6d, 0x43, 0x13, 0xf0,
0xdb, 0x9b, 0xe9}, 16,
- PSA_SUCCESS
+{PSA_SUCCESS, PSA_SUCCESS}
},
{"Test psa_aead_verify - AES-CCM 24 bytes Tag length = 4\n", PSA_KEY_TYPE_AES,
@@ -76,7 +76,7 @@
{0x26, 0xc5, 0x69, 0x61, 0xc0, 0x35, 0xa7, 0xe4, 0x52, 0xcc, 0xe6, 0x1b, 0xc6,
0xee, 0x22, 0x0d, 0x77, 0xb3, 0xf9, 0x4d, 0x18, 0xfd, 0x10, 0xb6},
24, {0x64, 0x3b, 0x4f, 0x39}, 4,
- PSA_SUCCESS
+{PSA_SUCCESS, PSA_SUCCESS}
},
{"Test psa_aead_verify - Small buffer size\n", PSA_KEY_TYPE_AES,
@@ -95,7 +95,7 @@
24,
{0xd8, 0x0e, 0x8b, 0xf8, 0x0f, 0x4a, 0x46, 0xca, 0xb0, 0x6d, 0x43, 0x13, 0xf0,
0xdb, 0x9b, 0xe9}, 16,
- PSA_ERROR_BUFFER_TOO_SMALL
+{PSA_ERROR_BUFFER_TOO_SMALL, PSA_SUCCESS}
},
{"Test psa_aead_verify - Input length is less than plaintext length\n", PSA_KEY_TYPE_AES,
@@ -113,7 +113,7 @@
24,
{0xd8, 0x0e, 0x8b, 0xf8, 0x0f, 0x4a, 0x46, 0xca, 0xb0, 0x6d, 0x43, 0x13, 0xf0,
0xdb, 0x9b, 0xe9}, 16,
- PSA_ERROR_INVALID_ARGUMENT
+{PSA_ERROR_INVALID_ARGUMENT, PSA_ERROR_INVALID_ARGUMENT}
},
#endif
#endif
@@ -134,7 +134,7 @@
0x79, 0xED}, 28,
{0x36, 0x9F, 0x07, 0x1F, 0x35, 0xE0, 0x34, 0xBE, 0x95, 0xF1, 0x12, 0xE4, 0xE7,
0xD0, 0x5D, 0x35}, 16,
- PSA_SUCCESS
+{PSA_SUCCESS, PSA_SUCCESS}
},
#endif
#endif
diff --git a/api-tests/val/common/val.h b/api-tests/val/common/val.h
index 88bab7b..31b425c 100644
--- a/api-tests/val/common/val.h
+++ b/api-tests/val/common/val.h
@@ -138,8 +138,15 @@
{ \
val->print(PRINT_ERROR, "\tFailed at Checkpoint: %d\n", checkpoint); \
val->print(PRINT_ERROR, "\tActual: %d\n", arg1); \
- val->print(PRINT_ERROR, "\tExpected: %d", status1); \
- val->print(PRINT_ERROR, "or %d\n", status2); \
+ if ((status1) != (status2)) \
+ { \
+ val->print(PRINT_ERROR, "\tExpected: %d", status1); \
+ val->print(PRINT_ERROR, "or %d\n", status2); \
+ } \
+ else \
+ { \
+ val->print(PRINT_ERROR, "\tExpected: %d\n", status1); \
+ } \
return 1; \
} \
} while (0)