From a2ce51624262935417cc5842d8dc225ae34dfc71 Mon Sep 17 00:00:00 2001 From: Stephan Koch Date: Thu, 14 Nov 2024 17:02:46 +0100 Subject: [PATCH 1/2] Fix tests 71, 72, 73 to avoid invalid argument. Fix test 74 wrong macro. Fix tests 76, 77 missing destroy key. Signed-off-by: Stephan Koch --- api-tests/dev_apis/crypto/test_c071/test_c071.c | 3 +-- api-tests/dev_apis/crypto/test_c072/test_c072.c | 3 +-- api-tests/dev_apis/crypto/test_c073/test_c073.c | 3 +-- api-tests/dev_apis/crypto/test_c074/test_c074.c | 2 +- api-tests/dev_apis/crypto/test_c076/test_c076.c | 4 ++++ api-tests/dev_apis/crypto/test_c077/test_c077.c | 6 ++++++ 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/api-tests/dev_apis/crypto/test_c071/test_c071.c b/api-tests/dev_apis/crypto/test_c071/test_c071.c index 87892602..127c1496 100644 --- a/api-tests/dev_apis/crypto/test_c071/test_c071.c +++ b/api-tests/dev_apis/crypto/test_c071/test_c071.c @@ -124,8 +124,7 @@ int32_t psa_pake_set_user_test(caller_security_t caller __UNUSED) /* Expect a bad state when psa_pake_set_user is called on aborted inactive operation object */ status = val->crypto_function(VAL_CRYPTO_PAKE_SET_USER, &operation, - check1[i].user_id, - check1[i].user_id_len); + (const uint8_t*)"user", 4); TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(9)); } diff --git a/api-tests/dev_apis/crypto/test_c072/test_c072.c b/api-tests/dev_apis/crypto/test_c072/test_c072.c index 52ffacf5..bf5d2b6d 100644 --- a/api-tests/dev_apis/crypto/test_c072/test_c072.c +++ b/api-tests/dev_apis/crypto/test_c072/test_c072.c @@ -132,8 +132,7 @@ int32_t psa_pake_set_peer_test(caller_security_t caller __UNUSED) /* Expect a bad state when psa_pake_set_peer is called on aborted inactive operation object */ status = val->crypto_function(VAL_CRYPTO_PAKE_SET_PEER, &operation, - check1[i].peer_id, - check1[i].peer_id_len); + (const uint8_t*)"peer", 4); TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(10)); } return VAL_STATUS_SUCCESS; diff --git a/api-tests/dev_apis/crypto/test_c073/test_c073.c b/api-tests/dev_apis/crypto/test_c073/test_c073.c index 51f26700..b1f74325 100644 --- a/api-tests/dev_apis/crypto/test_c073/test_c073.c +++ b/api-tests/dev_apis/crypto/test_c073/test_c073.c @@ -139,8 +139,7 @@ int32_t psa_pake_set_context_test(caller_security_t caller __UNUSED) /* Expect a bad state if psa_pake_set_context is called on aborted inactive operation object */ status = val->crypto_function(VAL_CRYPTO_PAKE_SET_CONTEXT, &operation, - check1[i].context, - check1[i].context_len); + (const uint8_t*)"context", 7); TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(11)); } return VAL_STATUS_SUCCESS; diff --git a/api-tests/dev_apis/crypto/test_c074/test_c074.c b/api-tests/dev_apis/crypto/test_c074/test_c074.c index 4453e9ef..3a63b594 100644 --- a/api-tests/dev_apis/crypto/test_c074/test_c074.c +++ b/api-tests/dev_apis/crypto/test_c074/test_c074.c @@ -391,7 +391,7 @@ int32_t psa_pake_output_test(caller_security_t caller __UNUSED) } - if (PSA_ALG_JPAKE(PSA_ALG_SHA_256)) + if (PSA_ALG_IS_JPAKE (check1[i].alg)) { /* Abort the PAKE operation object */ status = val->crypto_function(VAL_CRYPTO_PAKE_ABORT, &user); diff --git a/api-tests/dev_apis/crypto/test_c076/test_c076.c b/api-tests/dev_apis/crypto/test_c076/test_c076.c index 71f4a010..036cc22e 100644 --- a/api-tests/dev_apis/crypto/test_c076/test_c076.c +++ b/api-tests/dev_apis/crypto/test_c076/test_c076.c @@ -105,6 +105,10 @@ int32_t psa_pake_abort_test(caller_security_t caller __UNUSED) &operation); TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(6)); + /* Destroy the key */ + status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, key); + TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(7)); + } return VAL_STATUS_SUCCESS; } diff --git a/api-tests/dev_apis/crypto/test_c077/test_c077.c b/api-tests/dev_apis/crypto/test_c077/test_c077.c index aaffab69..82ccad48 100644 --- a/api-tests/dev_apis/crypto/test_c077/test_c077.c +++ b/api-tests/dev_apis/crypto/test_c077/test_c077.c @@ -472,6 +472,12 @@ int32_t psa_pake_get_shared_key_test(caller_security_t caller __UNUSED) TEST_ASSERT_DUAL(status, check1[i].expected_status[0], check1[i].expected_status[1], TEST_CHECKPOINT_NUM(12)); + if (status == PSA_SUCCESS) { + /* Destroy the key */ + status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, shared_key); + TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(14)); + } + status = val->crypto_function(VAL_CRYPTO_PAKE_GET_SHARED_KEY, &server, &attributes, &shared_key); TEST_ASSERT_DUAL(status, check1[i].expected_status[0], From 00e7d629ac45cc8f19230b5907f3147c4f5ca087 Mon Sep 17 00:00:00 2001 From: Stephan Koch Date: Tue, 19 Nov 2024 11:14:26 +0100 Subject: [PATCH 2/2] Use bad state checking pattern. Signed-off-by: Stephan Koch --- api-tests/dev_apis/crypto/test_c071/test_c071.c | 13 ++++++++----- api-tests/dev_apis/crypto/test_c072/test_c072.c | 13 ++++++++----- api-tests/dev_apis/crypto/test_c073/test_c073.c | 13 ++++++++----- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/api-tests/dev_apis/crypto/test_c071/test_c071.c b/api-tests/dev_apis/crypto/test_c071/test_c071.c index 127c1496..baeb79d7 100644 --- a/api-tests/dev_apis/crypto/test_c071/test_c071.c +++ b/api-tests/dev_apis/crypto/test_c071/test_c071.c @@ -121,11 +121,14 @@ int32_t psa_pake_set_user_test(caller_security_t caller __UNUSED) &operation); TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(8)); - /* Expect a bad state when psa_pake_set_user is called on aborted inactive operation object */ - status = val->crypto_function(VAL_CRYPTO_PAKE_SET_USER, - &operation, - (const uint8_t*)"user", 4); - TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(9)); + /* Expect a bad state when psa_pake_set_user is called on aborted inactive operation object */ + if (check1[i].expected_status == PSA_SUCCESS) { + status = val->crypto_function(VAL_CRYPTO_PAKE_SET_USER, + &operation, + check1[i].user_id, + check1[i].user_id_len); + TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(9)); + } } return VAL_STATUS_SUCCESS; diff --git a/api-tests/dev_apis/crypto/test_c072/test_c072.c b/api-tests/dev_apis/crypto/test_c072/test_c072.c index bf5d2b6d..a276b15c 100644 --- a/api-tests/dev_apis/crypto/test_c072/test_c072.c +++ b/api-tests/dev_apis/crypto/test_c072/test_c072.c @@ -129,11 +129,14 @@ int32_t psa_pake_set_peer_test(caller_security_t caller __UNUSED) &operation); TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(9)); - /* Expect a bad state when psa_pake_set_peer is called on aborted inactive operation object */ - status = val->crypto_function(VAL_CRYPTO_PAKE_SET_PEER, - &operation, - (const uint8_t*)"peer", 4); - TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(10)); + /* Expect a bad state when psa_pake_set_peer is called on aborted inactive operation object */ + if (check1[i].expected_status == PSA_SUCCESS) { + status = val->crypto_function(VAL_CRYPTO_PAKE_SET_PEER, + &operation, + check1[i].peer_id, + check1[i].peer_id_len); + TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(10)); + } } return VAL_STATUS_SUCCESS; } diff --git a/api-tests/dev_apis/crypto/test_c073/test_c073.c b/api-tests/dev_apis/crypto/test_c073/test_c073.c index b1f74325..44030902 100644 --- a/api-tests/dev_apis/crypto/test_c073/test_c073.c +++ b/api-tests/dev_apis/crypto/test_c073/test_c073.c @@ -136,11 +136,14 @@ int32_t psa_pake_set_context_test(caller_security_t caller __UNUSED) &operation); TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(10)); - /* Expect a bad state if psa_pake_set_context is called on aborted inactive operation object */ - status = val->crypto_function(VAL_CRYPTO_PAKE_SET_CONTEXT, - &operation, - (const uint8_t*)"context", 7); - TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(11)); + /* Expect a bad state if psa_pake_set_context is called on aborted inactive operation object */ + if (check1[i].expected_status == PSA_SUCCESS) { + status = val->crypto_function(VAL_CRYPTO_PAKE_SET_CONTEXT, + &operation, + check1[i].context, + check1[i].context_len); + TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(11)); + } } return VAL_STATUS_SUCCESS; }