Enhancements: Crypto
Details : Re-structure test data structures across tests and in turn
re-use the test data effectively.
Reduce overall RAM requirement(.data and .bss) which
effectively minimize the overall boot time.
The RAM consumption reduced to ~12K from ~105K.
With modified test data structures, the test logic code looks
cleaner and readable.
Note : Re-work for some of the left out tests will be done as part
of future release.
Signed-off-by: Vinay Kumar Kotegowder <vinaykumar.kotegowder@arm.com>
diff --git a/api-tests/CMakeLists.txt b/api-tests/CMakeLists.txt
index e855d1e..d0a9101 100644
--- a/api-tests/CMakeLists.txt
+++ b/api-tests/CMakeLists.txt
@@ -420,6 +420,7 @@
add_definitions(-D${SUITE})
add_definitions(-DVERBOSE=${VERBOSE})
add_definitions(-DPLATFORM_PSA_ISOLATION_LEVEL=${PLATFORM_PSA_ISOLATION_LEVEL})
+add_definitions(-D${TARGET})
if(${SP_HEAP_MEM_SUPP} EQUAL 1)
add_definitions(-DSP_HEAP_MEM_SUPP)
diff --git a/api-tests/dev_apis/crypto/common/test_crypto_common.c b/api-tests/dev_apis/crypto/common/test_crypto_common.c
new file mode 100644
index 0000000..7244022
--- /dev/null
+++ b/api-tests/dev_apis/crypto/common/test_crypto_common.c
@@ -0,0 +1,430 @@
+/** @file
+ * Copyright (c) 2020, Arm Limited or its affiliates. All rights reserved.
+ * SPDX-License-Identifier : Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+**/
+
+#include "test_crypto_common.h"
+
+const uint8_t key_data[] = {
+ 0x01, 0x03, 0x0E, 0x0F, 0x1F, 0x3F, 0xEF, 0XFF,
+ 0x02, 0x0A, 0x2A, 0xAA, 0x04, 0x24, 0x88, 0x03,
+ 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, 0x49, 0x6e, 0xfc, 0x58, 0x3f, 0xed, 0x8b,
+ 0x24, 0xa5, 0xb9, 0xbe, 0x9a, 0x51, 0xde, 0x06, 0x3f, 0x5a, 0x00, 0xa8, 0xb6, 0x98,
+ 0xa1, 0x6f, 0xd7, 0xf2, 0x9b, 0x54, 0x85, 0xf3, 0x20};
+
+const uint8_t ec_key_pair[] = {
+ 0x68, 0x49, 0xf9, 0x7d, 0x10, 0x66, 0xf6, 0x99, 0x77, 0x59, 0x63, 0x7c, 0x7e, 0x38,
+ 0x99, 0x46, 0x4c, 0xee, 0x3e, 0xc7, 0xac, 0x97, 0x06, 0x53, 0xa0, 0xbe, 0x07, 0x42};
+
+const uint8_t ec_keypair[] = {
+ 0xab, 0x45, 0x43, 0x57, 0x12, 0x64, 0x9c, 0xb3, 0x0b, 0xbd, 0xda, 0xc4, 0x91, 0x97, 0xee, 0xbf,
+ 0x27, 0x40, 0xff, 0xc7, 0xf8, 0x74, 0xd9, 0x24, 0x4c, 0x34, 0x60, 0xf5, 0x4f, 0x32, 0x2d, 0x3a};
+
+const uint8_t md2_hash[] = {
+ 0x8c, 0x9c, 0x17, 0x66, 0x5d, 0x25, 0xb3, 0x5f, 0xc4, 0x13, 0xc4, 0x18, 0x05, 0xc6, 0x79, 0xcf};
+
+const uint8_t md4_hash[] = {
+ 0x18, 0xc3, 0x3f, 0x97, 0x29, 0x7e, 0xfe, 0x5f, 0x8a, 0x73, 0x22, 0x58, 0x28, 0x9f, 0xda, 0x25};
+
+const uint8_t md5_hash[] = {
+ 0xab, 0xae, 0x57, 0xcb, 0x56, 0x2e, 0xcf, 0x29, 0x5b, 0x4a, 0x37, 0xa7, 0x6e, 0xfe, 0x61, 0xfb};
+
+const uint8_t ripemd_160_hash[] = {
+ 0x50, 0x89, 0x26, 0x5e, 0xe5, 0xd9, 0xaf, 0x75, 0xd1, 0x2d,
+ 0xbf, 0x7e, 0xa2, 0xf2, 0x7d, 0xbd, 0xee, 0x43, 0x5b, 0x37};
+
+const uint8_t sha_1_hash[] = {
+ 0x90, 0x34, 0xaa, 0xf4, 0x51, 0x43, 0x99, 0x6a, 0x2b, 0x14,
+ 0x46, 0x5c, 0x35, 0x2a, 0xb0, 0xc6, 0xfa, 0x26, 0xb2, 0x21};
+
+const uint8_t sha_224_hash[] = {
+ 0xb1, 0xe4, 0x6b, 0xb9, 0xef, 0xe4, 0x5a, 0xf5, 0x54, 0x36, 0x34, 0x49, 0xc6, 0x94,
+ 0x5a, 0x0d, 0x61, 0x69, 0xfc, 0x3a, 0x5a, 0x39, 0x6a, 0x56, 0xcb, 0x97, 0xcb, 0x57};
+
+const uint8_t sha_256_hash[] = {
+ 0x68, 0x32, 0x57, 0x20, 0xaa, 0xbd, 0x7c, 0x82, 0xf3, 0x0f, 0x55, 0x4b, 0x31, 0x3d, 0x05, 0x70,
+ 0xc9, 0x5a, 0xcc, 0xbb, 0x7d, 0xc4, 0xb5, 0xaa, 0xe1, 0x12, 0x04, 0xc0, 0x8f, 0xfe, 0x73, 0x2b};
+
+const uint8_t sha_256_incorrect_hash[] = {
+ 0x68, 0x32, 0x57, 0x20, 0xab, 0xbd, 0x7c, 0x82, 0xf3, 0x0f, 0x55, 0x4b, 0x31, 0x3d, 0x05, 0x70,
+ 0xc9, 0x5a, 0xcc, 0xbb, 0x7d, 0xc4, 0xb5, 0xaa, 0xe1, 0x12, 0x04, 0xc0, 0x8f, 0xfe, 0x73, 0x78};
+
+const uint8_t sha_384_hash[] = {
+ 0x43, 0x72, 0xe3, 0x8a, 0x92, 0xa2, 0x8b, 0x5d, 0x2c, 0x39, 0x1e, 0x62, 0x45, 0x2a, 0x86, 0xd5,
+ 0x0e, 0x02, 0x67, 0x22, 0x8b, 0xe1, 0x76, 0xc7, 0x7d, 0x24, 0x02, 0xef, 0xfe, 0x9f, 0xa5, 0x0d,
+ 0xe4, 0x07, 0xbb, 0xb8, 0x51, 0xb3, 0x7d, 0x59, 0x04, 0xab, 0xa2, 0xde, 0xde, 0x74, 0xda, 0x2a};
+
+const uint8_t sha_512_hash[] = {
+ 0x29, 0x6e, 0x22, 0x67, 0xd7, 0x4c, 0x27, 0x8d, 0xaa, 0xaa, 0x94, 0x0d, 0x17, 0xb0, 0xcf, 0xb7,
+ 0x4a, 0x50, 0x83, 0xf8, 0xe0, 0x69, 0x72, 0x6d, 0x8c, 0x84, 0x1c, 0xbe, 0x59, 0x6e, 0x04, 0x31,
+ 0xcb, 0x77, 0x41, 0xa5, 0xb5, 0x0f, 0x71, 0x66, 0x6c, 0xfd, 0x54, 0xba, 0xcb, 0x7b, 0x00, 0xae,
+ 0xa8, 0x91, 0x49, 0x9c, 0xf4, 0xef, 0x6a, 0x03, 0xc8, 0xa8, 0x3f, 0xe3, 0x7c, 0x3f, 0x7b, 0xaf};
+
+const uint8_t ecdh_secp_256_r1_prv_key[ECDH_SECP_256_R1_PRV_KEY_LEN] = {
+ 0xc8, 0x8f, 0x01, 0xf5, 0x10, 0xd9, 0xac, 0x3f, 0x70, 0xa2, 0x92, 0xda, 0xa2, 0x31, 0x6d, 0xe5,
+ 0x44, 0xe9, 0xaa, 0xb8, 0xaf, 0xe8, 0x40, 0x49, 0xc6, 0x2a, 0x9c, 0x57, 0x86, 0x2d, 0x14, 0x33};
+
+const uint8_t ecdh_secp_256_r1_pub_key[ECDH_SECP_256_R1_PUB_KEY_LEN] = {
+ 0x04, 0xd1, 0x2d, 0xfb, 0x52, 0x89, 0xc8, 0xd4, 0xf8, 0x12, 0x08, 0xb7, 0x02,
+ 0x70, 0x39, 0x8c, 0x34, 0x22, 0x96, 0x97, 0x0a, 0x0b, 0xcc, 0xb7, 0x4c, 0x73,
+ 0x6f, 0xc7, 0x55, 0x44, 0x94, 0xbf, 0x63, 0x56, 0xfb, 0xf3, 0xca, 0x36, 0x6c,
+ 0xc2, 0x3e, 0x81, 0x57, 0x85, 0x4c, 0x13, 0xc5, 0x8d, 0x6a, 0xac, 0x23, 0xf0,
+ 0x46, 0xad, 0xa3, 0x0f, 0x83, 0x53, 0xe7, 0x4f, 0x33, 0x03, 0x98, 0x72, 0xab};
+
+const uint8_t ecdh_secp_384_r1_prv_key[ECDH_SECP_384_R1_PRV_KEY_LEN] = {
+ 0x09, 0x9f, 0x3c, 0x70, 0x34, 0xd4, 0xa2, 0xc6, 0x99, 0x88, 0x4d, 0x73, 0xa3, 0x75, 0xa6, 0x7f,
+ 0x76, 0x24, 0xef, 0x7c, 0x6b, 0x3c, 0x0f, 0x16, 0x06, 0x47, 0xb6, 0x74, 0x14, 0xdc, 0xe6, 0x55,
+ 0xe3, 0x5b, 0x53, 0x80, 0x41, 0xe6, 0x49, 0xee, 0x3f, 0xae, 0xf8, 0x96, 0x78, 0x3a, 0xb1, 0x94};
+
+const uint8_t ecdh_secp_384_r1_pub_key[ECDH_SECP_384_R1_PUB_KEY_LEN] = {
+ 0x04, 0xe5, 0x58, 0xdb, 0xef, 0x53, 0xee, 0xcd, 0xe3, 0xd3, 0xfc, 0xcf, 0xc1, 0xae, 0xa0, 0x8a,
+ 0x89, 0xa9, 0x87, 0x47, 0x5d, 0x12, 0xfd, 0x95, 0x0d, 0x83, 0xcf, 0xa4, 0x17, 0x32, 0xbc, 0x50,
+ 0x9d, 0x0d, 0x1a, 0xc4, 0x3a, 0x03, 0x36, 0xde, 0xf9, 0x6f, 0xda, 0x41, 0xd0, 0x77, 0x4a, 0x35,
+ 0x71, 0xdc, 0xfb, 0xec, 0x7a, 0xac, 0xf3, 0x19, 0x64, 0x72, 0x16, 0x9e, 0x83, 0x84, 0x30, 0x36,
+ 0x7f, 0x66, 0xee, 0xbe, 0x3c, 0x6e, 0x70, 0xc4, 0x16, 0xdd, 0x5f, 0x0c, 0x68, 0x75, 0x9d, 0xd1,
+ 0xff, 0xf8, 0x3f, 0xa4, 0x01, 0x42, 0x20, 0x9d, 0xff, 0x5e, 0xaa, 0xd9, 0x6d, 0xb9, 0xe6, 0x38,
+ 0x6c};
+
+const uint8_t nonce[] = {
+ 0x00, 0x41, 0x2B, 0x4E, 0xA9, 0xCD, 0xBE, 0x3C, 0x96, 0x96, 0x76, 0x6C, 0xFA};
+
+const uint8_t additional_data[] = {
+ 0x40, 0xa2, 0x7c, 0x1d, 0x1e, 0x23, 0xea, 0x3d, 0xbe, 0x80, 0x56, 0xb2, 0x77, 0x48, 0x61, 0xa4,
+ 0xa2, 0x01, 0xcc, 0xe4, 0x9f, 0x19, 0x99, 0x7d, 0x19, 0x20, 0x6d, 0x8c, 0x8a, 0x34, 0x39, 0x51};
+
+const uint8_t plaintext[] = {
+ 0x45, 0x35, 0xd1, 0x2b, 0x43, 0x77, 0x92, 0x8a,
+ 0x7c, 0x0a, 0x61, 0xc9, 0xf8, 0x25, 0xa4, 0x86,
+ 0x71, 0xea, 0x05, 0x91, 0x07, 0x48, 0xc8, 0xef};
+
+const uint8_t aead_ciphertext_1[AEAD_CIPHERTEXT_LEN_1] = {
+ 0xFA, 0xBF, 0x93, 0x49, 0xE7, 0x24, 0xA5, 0x33, 0x4B, 0xC0, 0xBF, 0x01, 0x17, 0xAF, 0x04, 0x3D,
+ 0xC0, 0xC9, 0xDE, 0x51, 0xD9, 0xC7, 0xA5, 0x77, 0xDD, 0x30, 0x36, 0x55, 0xCD, 0xE6, 0xB3, 0x16,
+ 0xB7, 0x0A, 0xC0, 0x8C, 0xBA, 0x78, 0xD6};
+
+const uint8_t aead_ciphertext_2[AEAD_CIPHERTEXT_LEN_2] = {
+ 0xFA, 0xBF, 0x93, 0x49, 0xE7, 0x24, 0xA5, 0x33, 0x4B, 0xC0, 0xBF, 0x01, 0x17, 0xAF, 0x04, 0x3D,
+ 0xC0, 0xC9, 0xDE, 0x51, 0xD9, 0xC7, 0xA5, 0x96, 0x7E, 0x15, 0x73, 0xF2, 0x0B, 0xD2, 0x8A, 0x59,
+ 0x4A, 0x9C, 0x95, 0x82, 0x60, 0x56, 0x24, 0x18};
+
+const uint8_t aead_invalid_ciphertext_2[AEAD_CIPHERTEXT_LEN_2] = {
+ 0x93, 0x40, 0xD4, 0x54, 0xAF, 0xCB, 0xD1, 0xBF, 0x05, 0xCA, 0x56, 0x94, 0xAD, 0x47, 0xC1, 0x0D,
+ 0x13, 0x05, 0x96, 0xF4, 0x2F, 0x69, 0xAC, 0xD8, 0x20, 0x7C, 0x67, 0x53, 0x73, 0x88, 0x6B, 0x2B,
+ 0x3C, 0x0F, 0x8A, 0x6C, 0x01, 0x2E, 0x51, 0x77};
+
+const uint8_t aead_ciphertext_3[AEAD_CIPHERTEXT_LEN_3] = {
+ 0xFA, 0xBF, 0x93, 0x49, 0xE7, 0x24, 0xA5, 0x33, 0x4B, 0xC0, 0xBF, 0x01, 0x17, 0xAF, 0x04, 0x3D,
+ 0xC0, 0xC9, 0xDE, 0x51, 0xD9, 0xC7, 0xA5, 0x96, 0xE5, 0x2B, 0x6F, 0x9B};
+
+const uint8_t aead_ciphertext_4[AEAD_CIPHERTEXT_LEN_4] = {
+ 0xFA, 0xBF, 0x93, 0x49, 0xE7, 0x24, 0xA5, 0x33, 0x4B, 0xC0, 0xBF, 0x01, 0x17, 0xAF, 0x04, 0x3D,
+ 0xC0, 0xC9, 0xDE, 0x51, 0xD9, 0xC7, 0xA5, 0x96, 0xB1, 0x36, 0x17, 0xD4, 0xF7, 0x0A, 0xFB, 0xA5,
+ 0xED, 0x83, 0x08, 0xC1, 0xB2, 0x1D, 0x19, 0x27};
+
+const uint8_t aead_ciphertext_5[AEAD_CIPHERTEXT_LEN_5] = {
+ 0x65, 0x46, 0x6B, 0xB0, 0xEA, 0x01, 0xE4, 0x8F, 0x94, 0xA2, 0x3C, 0xA6, 0x5C, 0x15, 0x56, 0x17};
+
+const uint8_t aead_ciphertext_6[AEAD_CIPHERTEXT_LEN_6] = {
+ 0x1D, 0xEC, 0xC1, 0xED, 0x4B, 0x1A, 0x0F, 0x94, 0x64, 0x3C, 0xBB, 0x22, 0x89, 0xB5, 0xE3, 0x46,
+ 0x21, 0x11, 0x43, 0x20, 0x2D, 0xEA, 0x2B, 0x66, 0xB7, 0x27, 0x77, 0x27, 0x67, 0xDF, 0x44, 0xEC,
+ 0xD8, 0xDA, 0xA8, 0x7C, 0xB4, 0x9B, 0xB3, 0x2B};
+
+const unsigned char iv[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
+
+const unsigned char ciphertext_1[] = {
+ 0xDB, 0x03, 0x77, 0xF5, 0x59, 0x9F, 0x22, 0xB8, 0x5A, 0xFC, 0x13, 0xC3, 0x73, 0x01, 0xD7, 0x8D,
+ 0xC7, 0x2D, 0x52, 0x0C, 0x24, 0x8C, 0xDD, 0x61, 0x45, 0xDD, 0x05, 0xF0, 0xD3, 0xEE, 0x0D, 0xCD};
+
+const unsigned char ciphertext_2[] = {
+ 0xE1, 0x98, 0x2E, 0x59, 0xAC, 0x61, 0x75, 0x7B, 0x83, 0xBE, 0xB4, 0x03, 0xF0, 0xDA, 0x7F, 0xCC};
+
+const unsigned char ciphertext_3[] = {
+ 0x85, 0x6C, 0xF7, 0xD8, 0x1F, 0xA6, 0xA6, 0xEE};
+
+const unsigned char ciphertext_4[] = {
+ 0x7A, 0x88, 0x56, 0xF2, 0xCA, 0xF5, 0xF8, 0x95};
+
+const unsigned char ciphertext_5[] = {
+ 0xE3, 0xB7, 0xD2, 0x70, 0xDF, 0x41, 0x1A, 0x86};
+
+const unsigned char ciphertext_6[] = {
+ 0xC3, 0x32, 0x1D, 0x6B, 0x81, 0x44, 0x6D, 0xF4, 0xA6, 0x5D, 0xBF, 0x6A, 0xB5, 0x0A, 0x55, 0xBC};
+
+const uint8_t salt[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
+
+const uint8_t ciphertext_7[] = {
+ 0x0B, 0x1B, 0x3F, 0xC1, 0xA3, 0x94, 0x9A, 0x5E, 0x1F, 0xE2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x93,
+ 0x6F, 0xFD, 0x7E, 0xFC, 0x5D, 0x74, 0x88, 0x2B, 0xEA, 0x02, 0x64, 0x0D, 0x12, 0x76, 0x98, 0x43,
+ 0xE7, 0xD5, 0xFF, 0x94, 0x81, 0xAD, 0x59, 0x87, 0x13, 0xB4, 0xEE, 0x98, 0x41, 0xA4, 0xDE, 0x30,
+ 0x84, 0xC3, 0xB1, 0x04, 0x85, 0x5B, 0xCA, 0x86, 0xA4, 0xF3, 0x64, 0xE5, 0x20, 0x21, 0x1B, 0xE0,
+ 0x55, 0x40, 0x24, 0x74, 0x95, 0x2A, 0x34, 0xF1, 0xC2, 0x79, 0x6A, 0x6D, 0x3C, 0xAB, 0xBD, 0xA0};
+
+const uint8_t signature_3[] = {
+ 0xC6, 0x54, 0x59, 0xB1, 0xC9, 0x50, 0x8F, 0xE6, 0xBD, 0x97, 0x3F, 0x43, 0xAA, 0xBF, 0x58, 0x12,
+ 0xAF, 0xF6, 0xA8, 0xDB, 0x40, 0x2F, 0x77, 0x3D, 0x74, 0x0E, 0xF1, 0x41, 0x8D, 0xDC, 0x54, 0xA8,
+ 0xD6, 0xFE, 0x52, 0x4C, 0xD3, 0x78, 0xEB, 0xE2, 0xC2, 0xAF, 0x80, 0xF6, 0xAF, 0xFC, 0x0F, 0xB0,
+ 0x4B, 0xEA, 0x36, 0x0C, 0x92, 0xE5, 0x64, 0x4A, 0x60, 0x41, 0xB2, 0xF4, 0x53, 0x49, 0xD4, 0x22};
+
+/* test inputs */
+const uint8_t hash_input = 0xbd;
+const uint8_t input_bytes_data[INPUT_BYTES_DATA_LEN] = "abcdefghijklmnop";
+const uint8_t input_salt[INPUT_SALT_LEN] = "Salt";
+const uint8_t input_info[INPUT_INFO_LEN] = "Info";
+const uint8_t input_seed[INPUT_SEED_LEN] = "Seed";
+const uint8_t input_label[INPUT_LABEL_LEN] = "Label";
+
+/* output buffers */
+uint8_t expected_output[BUFFER_SIZE];
diff --git a/api-tests/dev_apis/crypto/common/test_crypto_common.h b/api-tests/dev_apis/crypto/common/test_crypto_common.h
new file mode 100644
index 0000000..c4da93b
--- /dev/null
+++ b/api-tests/dev_apis/crypto/common/test_crypto_common.h
@@ -0,0 +1,107 @@
+/** @file
+ * Copyright (c) 2020, Arm Limited or its affiliates. All rights reserved.
+ * SPDX-License-Identifier : Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+**/
+
+#ifndef _TEST_CRYPTO_COMMON_H_
+#define _TEST_CRYPTO_COMMON_H_
+
+#include "val_crypto.h"
+
+#define INPUT_BYTES_DATA_LEN 16
+#define ECDH_SECP_256_R1_PRV_KEY_LEN 32
+#define ECDH_SECP_256_R1_PUB_KEY_LEN 65
+#define ECDH_SECP_384_R1_PRV_KEY_LEN 48
+#define ECDH_SECP_384_R1_PUB_KEY_LEN 97
+
+#define AEAD_CIPHERTEXT_LEN_1 39
+#define AEAD_CIPHERTEXT_LEN_2 40
+#define AEAD_CIPHERTEXT_LEN_3 28
+#define AEAD_CIPHERTEXT_LEN_4 40
+#define AEAD_CIPHERTEXT_LEN_5 16
+#define AEAD_CIPHERTEXT_LEN_6 40
+
+#define INPUT_SALT_LEN 4
+#define INPUT_INFO_LEN 4
+#define INPUT_SEED_LEN 4
+#define INPUT_LABEL_LEN 5
+
+extern const uint8_t key_data[];
+
+extern const uint8_t rsa_128_key_pair[];
+extern const uint8_t rsa_128_key_data[];
+extern const uint8_t rsa_256_key_pair[];
+extern const uint8_t rsa_256_key_data[];
+
+extern const uint8_t ec_key_data[];
+extern const uint8_t ec_key_pair[];
+extern const uint8_t ec_keypair[];
+
+extern const uint8_t md2_hash[];
+extern const uint8_t md4_hash[];
+extern const uint8_t md5_hash[];
+extern const uint8_t ripemd_160_hash[];
+extern const uint8_t sha_1_hash[];
+extern const uint8_t sha_224_hash[];
+extern const uint8_t sha_256_hash[];
+extern const uint8_t sha_256_incorrect_hash[];
+extern const uint8_t sha_384_hash[];
+extern const uint8_t sha_512_hash[];
+
+extern const uint8_t ecdh_secp_256_r1_prv_key[];
+extern const uint8_t ecdh_secp_256_r1_pub_key[];
+extern const uint8_t ecdh_secp_384_r1_prv_key[];
+extern const uint8_t ecdh_secp_384_r1_pub_key[];
+
+extern const uint8_t nonce[];
+extern const uint8_t additional_data[];
+extern const uint8_t plaintext[];
+extern const uint8_t aead_ciphertext_1[AEAD_CIPHERTEXT_LEN_1];
+extern const uint8_t aead_ciphertext_2[AEAD_CIPHERTEXT_LEN_2];
+extern const uint8_t aead_invalid_ciphertext_2[AEAD_CIPHERTEXT_LEN_2];
+extern const uint8_t aead_ciphertext_3[AEAD_CIPHERTEXT_LEN_3];
+extern const uint8_t aead_ciphertext_4[AEAD_CIPHERTEXT_LEN_4];
+extern const uint8_t aead_ciphertext_5[AEAD_CIPHERTEXT_LEN_5];
+extern const uint8_t aead_ciphertext_6[AEAD_CIPHERTEXT_LEN_6];
+
+extern const uint8_t hash_input;
+extern const uint8_t input_bytes_data[INPUT_BYTES_DATA_LEN];
+extern const uint8_t input_salt[INPUT_SALT_LEN];
+extern const uint8_t input_info[INPUT_INFO_LEN];
+extern const uint8_t input_seed[INPUT_SEED_LEN];
+extern const uint8_t input_label[INPUT_LABEL_LEN];
+
+extern const unsigned char iv[];
+
+extern const unsigned char ciphertext_1[];
+extern const unsigned char ciphertext_2[];
+extern const unsigned char ciphertext_3[];
+extern const unsigned char ciphertext_4[];
+extern const unsigned char ciphertext_5[];
+extern const unsigned char ciphertext_6[];
+
+extern const uint8_t salt[];
+extern const unsigned char ciphertext_7[];
+extern const unsigned char ciphertext_8[];
+extern const unsigned char ciphertext_9[];
+
+extern const uint8_t signature_1[];
+extern const uint8_t signature_2[];
+extern const uint8_t signature_2_invalid[];
+extern const uint8_t signature_3[];
+
+extern uint8_t expected_output[BUFFER_SIZE];
+
+#endif /* _TEST_CRYPTO_COMMON_H_ */
diff --git a/api-tests/dev_apis/crypto/suite.cmake b/api-tests/dev_apis/crypto/suite.cmake
index 6f1050f..40c1a0d 100644
--- a/api-tests/dev_apis/crypto/suite.cmake
+++ b/api-tests/dev_apis/crypto/suite.cmake
@@ -33,6 +33,8 @@
add_definitions(${CC_OPTIONS})
add_definitions(${AS_OPTIONS})
+# append common crypto file to list of source collected
+list(APPEND SUITE_CC_SOURCE ${PSA_SUITE_DIR}/common/test_crypto_common.c)
add_library(${PSA_TARGET_TEST_COMBINE_LIB} STATIC ${SUITE_CC_SOURCE} ${SUITE_AS_SOURCE})
# Test related Include directories
@@ -54,4 +56,5 @@
${PSA_ROOT_DIR}/platform/targets/common/nspe
${PSA_ROOT_DIR}/platform/targets/common/nspe/crypto
${PSA_ROOT_DIR}/platform/targets/${TARGET}/nspe
+ ${PSA_SUITE_DIR}/common/
)
diff --git a/api-tests/dev_apis/crypto/test_c001/test_c001.c b/api-tests/dev_apis/crypto/test_c001/test_c001.c
index 67cd11d..bee43b2 100644
--- a/api-tests/dev_apis/crypto/test_c001/test_c001.c
+++ b/api-tests/dev_apis/crypto/test_c001/test_c001.c
@@ -37,9 +37,9 @@
/* Generate random bytes */
status = val->crypto_function(VAL_CRYPTO_GENERATE_RANDOM, output, GENERATE_SIZE);
if (status == PSA_SUCCESS)
- return RESULT_SKIP(VAL_STATUS_INIT_ALREADY_DONE);
+ return VAL_STATUS_SUCCESS;
else
- TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(1));
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(3));
return VAL_STATUS_SUCCESS;
}
@@ -66,7 +66,7 @@
{
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(2));
}
return VAL_STATUS_SUCCESS;
diff --git a/api-tests/dev_apis/crypto/test_c002/test_c002.c b/api-tests/dev_apis/crypto/test_c002/test_c002.c
index 065a379..83e1740 100644
--- a/api-tests/dev_apis/crypto/test_c002/test_c002.c
+++ b/api-tests/dev_apis/crypto/test_c002/test_c002.c
@@ -19,7 +19,6 @@
#include "val_target.h"
#include "test_c002.h"
#include "test_data.h"
-#include "val_crypto.h"
const client_test_t test_c002_crypto_list[] = {
NULL,
@@ -27,18 +26,13 @@
NULL,
};
-static int g_test_count = 1;
-
int32_t psa_import_key_test(caller_security_t caller __UNUSED)
{
int32_t i, status;
- uint8_t data[BUFFER_SIZE];
- size_t length;
- const uint8_t *key_data;
- psa_key_type_t get_key_type;
- size_t get_key_bits;
- int num_checks = sizeof(check1)/sizeof(check1[0]);
- psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+ psa_key_type_t get_type;
+ size_t get_bits;
+ int num_checks = sizeof(check1)/sizeof(check1[0]);
+ psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t get_attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_handle_t key_handle;
@@ -55,52 +49,21 @@
/* Set the key data buffer to the input base on algorithm */
for (i = 0; i < num_checks; i++)
{
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] ", i+1);
val->print(PRINT_TEST, check1[i].test_desc, 0);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type))
- {
- if (check1[i].key_type == PSA_KEY_TYPE_RSA_KEY_PAIR)
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keypair;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keypair;
- else
- return VAL_STATUS_INVALID;
- }
- else
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keydata;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keydata;
- else
- return VAL_STATUS_INVALID;
- }
- }
- else if (PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
- {
- if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(check1[i].key_type))
- key_data = ec_keypair;
- else
- key_data = ec_keydata;
- }
- else
- key_data = check1[i].key_data;
-
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_BITS, &attributes, check1[i].attr_bits);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_BITS, &attributes, check1[i].bits);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage_flags);
/* Import the key data into the key slot */
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, key_data,
- check1[i].key_length, &key_handle);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(3));
/* If failure is expected, continue with the next data set */
@@ -112,44 +75,23 @@
&get_attributes);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
- val->crypto_function(VAL_CRYPTO_GET_KEY_TYPE, &get_attributes, &get_key_type);
- TEST_ASSERT_EQUAL(get_key_type, check1[i].key_type, TEST_CHECKPOINT_NUM(5));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_TYPE, &get_attributes, &get_type);
+ TEST_ASSERT_EQUAL(get_type, check1[i].type, TEST_CHECKPOINT_NUM(5));
- val->crypto_function(VAL_CRYPTO_GET_KEY_BITS, &get_attributes, &get_key_bits);
- TEST_ASSERT_EQUAL(get_key_bits, check1[i].expected_bit_length, TEST_CHECKPOINT_NUM(6));
-
- /* Export a key in binary format */
- status = val->crypto_function(VAL_CRYPTO_EXPORT_KEY, key_handle, data,
- BUFFER_SIZE, &length);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(7));
-
- /* Check the attributes of the exported key */
- TEST_ASSERT_EQUAL(length, check1[i].expected_key_length, TEST_CHECKPOINT_NUM(8));
-
- if (PSA_KEY_TYPE_IS_UNSTRUCTURED(check1[i].key_type))
- {
- TEST_ASSERT_MEMCMP(data, check1[i].key_data, length, TEST_CHECKPOINT_NUM(9));
- }
- else if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type) || PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
- {
- TEST_ASSERT_MEMCMP(key_data, data, length, TEST_CHECKPOINT_NUM(10));
- }
- else
- {
- return VAL_STATUS_INVALID;
- }
+ val->crypto_function(VAL_CRYPTO_GET_KEY_BITS, &get_attributes, &get_bits);
+ TEST_ASSERT_EQUAL(get_bits, check1[i].bits, TEST_CHECKPOINT_NUM(6));
/* Reset the key attributes and check if psa_import_key fails */
val->crypto_function(VAL_CRYPTO_RESET_KEY_ATTRIBUTES, &attributes);
val->crypto_function(VAL_CRYPTO_DESTROY_KEY, key_handle);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(11));
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(7));
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, key_data,
- check1[i].key_length, &key_handle);
- TEST_ASSERT_NOT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(12));
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
+ TEST_ASSERT_NOT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(8));
- TEST_ASSERT_EQUAL(key_handle, 0, TEST_CHECKPOINT_NUM(13));
+ TEST_ASSERT_EQUAL(key_handle, 0, TEST_CHECKPOINT_NUM(9));
}
return VAL_STATUS_SUCCESS;
diff --git a/api-tests/dev_apis/crypto/test_c002/test_data.h b/api-tests/dev_apis/crypto/test_c002/test_data.h
index 116ccd3..ed999e4 100644
--- a/api-tests/dev_apis/crypto/test_c002/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c002/test_data.h
@@ -15,271 +15,188 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- psa_key_type_t key_type;
- uint8_t key_data[34];
- uint32_t key_length;
- size_t attr_bits;
- psa_key_usage_t usage;
- psa_algorithm_t key_alg;
- uint32_t expected_bit_length;
- uint32_t expected_key_length;
+ psa_key_type_t type;
+ const uint8_t *data;
+ size_t data_length;
+ size_t bits;
+ psa_key_usage_t usage_flags;
psa_status_t expected_status;
} test_data;
-static const uint8_t rsa_384_keypair[1];
-static const uint8_t rsa_384_keydata[1];
-
-static const uint8_t rsa_256_keypair[] = {
- 0x30, 0x82, 0x04, 0xA5, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xC0,
- 0x95, 0x08, 0xE1, 0x57, 0x41, 0xF2, 0x71, 0x6D, 0xB7, 0xD2, 0x45, 0x41, 0x27,
- 0x01, 0x65, 0xC6, 0x45, 0xAE, 0xF2, 0xBC, 0x24, 0x30, 0xB8, 0x95, 0xCE, 0x2F,
- 0x4E, 0xD6, 0xF6, 0x1C, 0x88, 0xBC, 0x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, 0x00, 0x01};
-
-static const uint8_t ec_keydata[] = {
- 0x04, 0xde, 0xa5, 0xe4, 0x5d, 0x0e, 0xa3, 0x7f, 0xc5, 0x66, 0x23, 0x2a, 0x50, 0x8f,
- 0x4a, 0xd2, 0x0e, 0xa1, 0x3d, 0x47, 0xe4, 0xbf, 0x5f, 0xa4, 0xd5, 0x4a, 0x57, 0xa0,
- 0xba, 0x01, 0x20, 0x42, 0x08, 0x70, 0x97, 0x49, 0x6e, 0xfc, 0x58, 0x3f, 0xed, 0x8b,
- 0x24, 0xa5, 0xb9, 0xbe, 0x9a, 0x51, 0xde, 0x06, 0x3f, 0x5a, 0x00, 0xa8, 0xb6, 0x98,
- 0xa1, 0x6f, 0xd7, 0xf2, 0x9b, 0x54, 0x85, 0xf3, 0x20};
-
-static const uint8_t ec_keypair[] = {
- 0x68, 0x49, 0xf9, 0x7d, 0x10, 0x66, 0xf6, 0x99, 0x77, 0x59, 0x63, 0x7c, 0x7e, 0x38,
- 0x99, 0x46, 0x4c, 0xee, 0x3e, 0xc7, 0xac, 0x97, 0x06, 0x53, 0xa0, 0xbe, 0x07, 0x42};
-
static const test_data check1[] = {
-
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
-{"Test psa_import_key 16 Byte AES\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0x77},
- AES_16B_KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
- BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_SUCCESS
+{
+ .test_desc = "Test psa_import_key 16 bytes AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_status = PSA_SUCCESS
},
+
#endif
#ifdef ARCH_TEST_AES_192
-{"Test psa_import_key 24 Byte AES\n", PSA_KEY_TYPE_AES,
-{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
- 0x40, 0xAC, 0xA3, 0x90, 0x77, 0x83, 0x52, 0x31, 0x74, 0xF9, 0x05},
- AES_24B_KEY_SIZE, BYTES_TO_BITS(AES_24B_KEY_SIZE), PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
- BYTES_TO_BITS(AES_24B_KEY_SIZE), AES_24B_KEY_SIZE, PSA_SUCCESS
+{
+ .test_desc = "Test psa_import_key 24 bytes AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_24B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_24B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_256
-{"Test psa_import_key 32 Byte AES\n", PSA_KEY_TYPE_AES,
-{0xEA, 0xD5, 0xE6, 0xC8, 0x51, 0xF9, 0xEC, 0xBB, 0x9B, 0x57, 0x7C, 0xED, 0xD2,
- 0x4B, 0x82, 0x84, 0x9F, 0x9F, 0xE6, 0x73, 0x21, 0x3D, 0x1A, 0x05, 0xC9, 0xED,
- 0xDF, 0x25, 0x17, 0x68, 0x86, 0xAE},
- AES_32B_KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
- BYTES_TO_BITS(AES_32B_KEY_SIZE), AES_32B_KEY_SIZE, PSA_SUCCESS
+{
+ .test_desc = "Test psa_import_key 32 bytes AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_32B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_32B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_status = PSA_SUCCESS
},
#endif
+#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
#ifdef ARCH_TEST_RSA_2048
-{"Test psa_import_key 2048 RSA public key\n", PSA_KEY_TYPE_RSA_PUBLIC_KEY,
- {0},
- 270, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
- 2048, 270, PSA_SUCCESS
+{
+ .test_desc = "Test psa_import_key 2048 RSA public key\n",
+ .type = PSA_KEY_TYPE_RSA_PUBLIC_KEY,
+ .data = rsa_256_key_data,
+ .data_length = 270,
+ .bits = BYTES_TO_BITS(256),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_import_key with RSA 2048 keypair\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
- {0},
- 1193, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
- 2048, 1193, PSA_SUCCESS
+{
+ .test_desc = "Test psa_import_key with RSA 2048 keypair\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_256_key_pair,
+ .data_length = 1193,
+ .bits = BYTES_TO_BITS(256),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_DES_1KEY
-{"Test psa_import_key with DES 64 bit key\n", PSA_KEY_TYPE_DES,
- {0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
- DES_8B_KEY_SIZE, BYTES_TO_BITS(DES_8B_KEY_SIZE), PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
- BYTES_TO_BITS(DES_8B_KEY_SIZE), DES_8B_KEY_SIZE, PSA_SUCCESS
+{
+ .test_desc = "Test psa_import_key with DES 8 bytes key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES_8B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(DES_8B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_2KEY
-{"Test psa_import_key with Triple DES 2-Key\n", PSA_KEY_TYPE_DES,
-{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
- DES3_2KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
- BYTES_TO_BITS(DES3_2KEY_SIZE), DES3_2KEY_SIZE, PSA_SUCCESS
+{
+ .test_desc = "Test psa_import_key with Triple DES 2-Key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_2B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(DES3_2B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_3KEY
-{"Test psa_import_key with Triple DES 3-Key\n", PSA_KEY_TYPE_DES,
-{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
- 0xF1, 0xE0, 0xD3, 0xC2, 0xB5, 0xA4, 0x97, 0x86,
- 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10},
- DES3_3KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
- BYTES_TO_BITS(DES3_3KEY_SIZE), DES3_3KEY_SIZE, PSA_SUCCESS
+{
+ .test_desc = "Test psa_import_key with Triple DES 3-Key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_3B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(DES3_3B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_ECDSA
#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
-{"Test psa_import_key with EC Public key\n",
- PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
- {0},
- 65, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_ECDSA_ANY,
- 256, 65, PSA_SUCCESS
+{
+ .test_desc = "Test psa_import_key with EC Public key\n",
+ .type = PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
+ .data = ec_key_data,
+ .data_length = 65,
+ .bits = 256,
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_ECC_CURVE_SECP224R1
-{"Test psa_import_key with EC keypair\n",
- PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP224R1),
- {0},
- 28, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_ECDSA_ANY,
- 224, 28, PSA_SUCCESS
+{
+ .test_desc = "Test psa_import_key with EC keypair\n",
+ .type = PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP224R1),
+ .data = ec_key_pair,
+ .data_length = 28,
+ .bits = 224,
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES
-{"Test psa_import_key with key data greater than the algorithm size\n", PSA_KEY_TYPE_AES,
-{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
- 0x40, 0xAC, 0xA3, 0x90, 0x77, 0x83, 0x52, 0x31, 0x74, 0xF9, 0x05, 0xC9, 0xED,
- 0xDF, 0x25, 0x17, 0x68, 0x86, 0xAE},
- AES_34B_KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
- BYTES_TO_BITS(AES_34B_KEY_SIZE), AES_34B_KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_import_key 16 bytes AES with invalid bits\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE)+1,
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
-{"Test psa_import_key with incorrect key data size\n", PSA_KEY_TYPE_AES,
-{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
- 0x40, 0xAC, 0xA3, 0x90, 0x77},
-AES_18B_KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
-BYTES_TO_BITS(AES_18B_KEY_SIZE), AES_18B_KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_import_key with key data greater than the algorithm size\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_34B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_34B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
+},
+
+{
+ .test_desc = "Test psa_import_key with incorrect key data size\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_18B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_18B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
-{"Test psa_import_key with incorrect key type\n", PSA_KEY_TYPE_VENDOR_FLAG,
-{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
- 0x40, 0xAC, 0xA3, 0x90, 0x77, 0x83, 0x52, 0x31, 0x74, 0xF9, 0x05},
-AES_24B_KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
-BYTES_TO_BITS(AES_24B_KEY_SIZE), AES_24B_KEY_SIZE, PSA_ERROR_NOT_SUPPORTED,
+{
+ .test_desc = "Test psa_import_key with invalid key type value\n",
+ .type = PSA_KEY_TYPE_NONE,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_status = PSA_ERROR_NOT_SUPPORTED
},
-#endif
+
#endif
};
diff --git a/api-tests/dev_apis/crypto/test_c003/test_c003.c b/api-tests/dev_apis/crypto/test_c003/test_c003.c
index 5a0d805..37fb89a 100644
--- a/api-tests/dev_apis/crypto/test_c003/test_c003.c
+++ b/api-tests/dev_apis/crypto/test_c003/test_c003.c
@@ -26,14 +26,10 @@
NULL,
};
-static int g_test_count = 1;
-static uint8_t data[BUFFER_SIZE];
-
int32_t psa_export_key_test(caller_security_t caller __UNUSED)
{
int32_t i, status;
- size_t length;
- const uint8_t *key_data;
+ size_t expected_data_length;
int num_checks = sizeof(check1)/sizeof(check1[0]);
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_handle_t key_handle;
@@ -51,59 +47,28 @@
/* Set the key data buffer to the input base on algorithm */
for (i = 0; i < num_checks; i++)
{
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] ", i+1);
val->print(PRINT_TEST, check1[i].test_desc, 0);
- memset(data, 0, BUFFER_SIZE);
+ memset(check1[i].expected_data, 0, BUFFER_SIZE);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type))
- {
- if (check1[i].key_type == PSA_KEY_TYPE_RSA_KEY_PAIR)
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keypair;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keypair;
- else
- return VAL_STATUS_INVALID;
- }
- else
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keydata;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keydata;
- else
- return VAL_STATUS_INVALID;
- }
- }
- else if (PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
- {
- if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(check1[i].key_type))
- key_data = ec_keypair;
- else
- key_data = ec_keydata;
- }
- else
- key_data = check1[i].key_data;
-
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_BITS, &attributes, check1[i].attr_bits);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_BITS, &attributes, check1[i].bits);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage_flags);
/* Import the key data into the key slot */
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, key_data,
- check1[i].key_length, &key_handle);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Export a key in binary format */
- status = val->crypto_function(VAL_CRYPTO_EXPORT_KEY, key_handle, data,
- check1[i].buffer_size, &length);
+ status = val->crypto_function(VAL_CRYPTO_EXPORT_KEY, key_handle, check1[i].expected_data,
+ check1[i].data_size, &expected_data_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(4));
/* If failure is expected, continue with the next data set */
@@ -111,28 +76,19 @@
continue;
/* Check the attributes of the exported key */
- TEST_ASSERT_EQUAL(length, check1[i].expected_key_length, TEST_CHECKPOINT_NUM(5));
+ TEST_ASSERT_EQUAL(expected_data_length, check1[i].expected_data_length,
+ TEST_CHECKPOINT_NUM(5));
- if (PSA_KEY_TYPE_IS_UNSTRUCTURED(check1[i].key_type))
- {
- TEST_ASSERT_MEMCMP(data, check1[i].key_data, length, TEST_CHECKPOINT_NUM(6));
- }
- else if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type) || PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
- {
- TEST_ASSERT_MEMCMP(key_data, data, length, TEST_CHECKPOINT_NUM(7));
- }
- else
- {
- return VAL_STATUS_INVALID;
- }
+ TEST_ASSERT_MEMCMP(check1[i].expected_data, check1[i].data, expected_data_length,
+ TEST_CHECKPOINT_NUM(6));
/* Destroy the key handle and check if export key fails */
status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, key_handle);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(8));
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(7));
- status = val->crypto_function(VAL_CRYPTO_EXPORT_KEY, key_handle, data,
- check1[i].buffer_size, &length);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(9));
+ status = val->crypto_function(VAL_CRYPTO_EXPORT_KEY, key_handle, check1[i].expected_data,
+ check1[i].data_size, &expected_data_length);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(8));
}
return VAL_STATUS_SUCCESS;
diff --git a/api-tests/dev_apis/crypto/test_c003/test_data.h b/api-tests/dev_apis/crypto/test_c003/test_data.h
index 2197f37..090bc7e 100644
--- a/api-tests/dev_apis/crypto/test_c003/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c003/test_data.h
@@ -15,261 +15,204 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- psa_key_type_t key_type;
- uint8_t key_data[34];
- uint32_t key_length;
- size_t attr_bits;
- psa_key_usage_t usage;
- psa_algorithm_t key_alg;
- size_t buffer_size;
- uint32_t expected_bit_length;
- uint32_t expected_key_length;
+ psa_key_type_t type;
+ const uint8_t *data;
+ size_t data_length;
+ size_t bits;
+ psa_key_usage_t usage_flags;
+ uint8_t *expected_data;
+ size_t data_size;
+ size_t expected_data_length;
psa_status_t expected_status;
} test_data;
-static const uint8_t rsa_384_keypair[1];
-static const uint8_t rsa_384_keydata[1];
-static const uint8_t rsa_256_keypair[] = {
- 0x30, 0x82, 0x04, 0xA5, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xC0,
- 0x95, 0x08, 0xE1, 0x57, 0x41, 0xF2, 0x71, 0x6D, 0xB7, 0xD2, 0x45, 0x41, 0x27,
- 0x01, 0x65, 0xC6, 0x45, 0xAE, 0xF2, 0xBC, 0x24, 0x30, 0xB8, 0x95, 0xCE, 0x2F,
- 0x4E, 0xD6, 0xF6, 0x1C, 0x88, 0xBC, 0x7C, 0x9F, 0xFB, 0xA8, 0x67, 0x7F, 0xFE,
- 0x5C, 0x9C, 0x51, 0x75, 0xF7, 0x8A, 0xCA, 0x07, 0xE7, 0x35, 0x2F, 0x8F, 0xE1,
- 0xBD, 0x7B, 0xC0, 0x2F, 0x7C, 0xAB, 0x64, 0xA8, 0x17, 0xFC, 0xCA, 0x5D, 0x7B,
- 0xBA, 0xE0, 0x21, 0xE5, 0x72, 0x2E, 0x6F, 0x2E, 0x86, 0xD8, 0x95, 0x73, 0xDA,
- 0xAC, 0x1B, 0x53, 0xB9, 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0xbe, 0x9a, 0x51, 0xde, 0x06, 0x3f, 0x5a, 0x00, 0xa8, 0xb6, 0x98,
- 0xa1, 0x6f, 0xd7, 0xf2, 0x9b, 0x54, 0x85, 0xf3, 0x20};
-
-static const uint8_t ec_keypair[] = {
- 0x68, 0x49, 0xf9, 0x7d, 0x10, 0x66, 0xf6, 0x99, 0x77, 0x59, 0x63, 0x7c, 0x7e, 0x38,
- 0x99, 0x46, 0x4c, 0xee, 0x3e, 0xc7, 0xac, 0x97, 0x06, 0x53, 0xa0, 0xbe, 0x07, 0x42};
-
static const test_data check1[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
-{"Test psa_export_key 16 Byte AES\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0x77},
- AES_16B_KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
- BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_SUCCESS
+{
+ .test_desc = "Test psa_export_key 16 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .data_size = BUFFER_SIZE,
+ .expected_data_length = AES_16B_KEY_SIZE,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_192
-{"Test psa_export_key 24 Byte AES\n", PSA_KEY_TYPE_AES,
-{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
- 0x40, 0xAC, 0xA3, 0x90, 0x77, 0x83, 0x52, 0x31, 0x74, 0xF9, 0x05},
- AES_24B_KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
- BYTES_TO_BITS(AES_24B_KEY_SIZE), AES_24B_KEY_SIZE, PSA_SUCCESS
+{
+ .test_desc = "Test psa_export_key 24 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_24B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_24B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .data_size = BUFFER_SIZE,
+ .expected_data_length = AES_24B_KEY_SIZE,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_256
-{"Test psa_export_key 32 Byte AES\n", PSA_KEY_TYPE_AES,
-{0xEA, 0xD5, 0xE6, 0xC8, 0x51, 0xF9, 0xEC, 0xBB, 0x9B, 0x57, 0x7C, 0xED, 0xD2,
- 0x4B, 0x82, 0x84, 0x9F, 0x9F, 0xE6, 0x73, 0x21, 0x3D, 0x1A, 0x05, 0xC9, 0xED,
- 0xDF, 0x25, 0x17, 0x68, 0x86, 0xAE},
- AES_32B_KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
- BYTES_TO_BITS(AES_32B_KEY_SIZE), AES_32B_KEY_SIZE, PSA_SUCCESS
+{
+ .test_desc = "Test psa_export_key 32 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_32B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_32B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .data_size = BUFFER_SIZE,
+ .expected_data_length = AES_32B_KEY_SIZE,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
#ifdef ARCH_TEST_RSA_2048
-{"Test psa_export_key 2048 RSA public key\n", PSA_KEY_TYPE_RSA_PUBLIC_KEY,
- {0},
- 270, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW, BUFFER_SIZE,
- 2048, 270, PSA_SUCCESS
+{
+ .test_desc = "Test psa_export_key 2048 RSA public key\n",
+ .type = PSA_KEY_TYPE_RSA_PUBLIC_KEY,
+ .data = rsa_256_key_data,
+ .data_length = 270,
+ .bits = BYTES_TO_BITS(256),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .data_size = BUFFER_SIZE,
+ .expected_data_length = 270,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_export_key with RSA 2048 keypair\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
- {0},
- 1193, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW, BUFFER_SIZE,
- 2048, 1193, PSA_SUCCESS
+{
+ .test_desc = "Test psa_export_key with RSA 2048 keypair\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_256_key_pair,
+ .data_length = 1193,
+ .bits = BYTES_TO_BITS(256),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .data_size = BUFFER_SIZE,
+ .expected_data_length = 1193,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_DES_1KEY
-{"Test psa_export_key with DES 64 bit key\n", PSA_KEY_TYPE_DES,
- {0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
- DES_8B_KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
- BYTES_TO_BITS(DES_8B_KEY_SIZE), DES_8B_KEY_SIZE, PSA_SUCCESS
+{
+ .test_desc = "Test psa_export_key with DES 64 bit key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES_8B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(DES_8B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .data_size = BUFFER_SIZE,
+ .expected_data_length = DES_8B_KEY_SIZE,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_2KEY
-{"Test psa_export_key with Triple DES 2-Key\n", PSA_KEY_TYPE_DES,
-{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
- DES3_2KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
- BYTES_TO_BITS(DES3_2KEY_SIZE), DES3_2KEY_SIZE, PSA_SUCCESS
+{
+ .test_desc = "Test psa_export_key with Triple DES 2-Key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_2B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(DES3_2B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .data_size = BUFFER_SIZE,
+ .expected_data_length = DES3_2B_KEY_SIZE,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_3KEY
-{"Test psa_export_key with Triple DES 3-Key\n", PSA_KEY_TYPE_DES,
-{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
- 0xF1, 0xE0, 0xD3, 0xC2, 0xB5, 0xA4, 0x97, 0x86,
- 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10},
- DES3_3KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
- BYTES_TO_BITS(DES3_3KEY_SIZE), DES3_3KEY_SIZE, PSA_SUCCESS
+{
+ .test_desc = "Test psa_export_key with Triple DES 3-Key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_3B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(DES3_3B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .data_size = BUFFER_SIZE,
+ .expected_data_length = DES3_3B_KEY_SIZE,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_ASYMMETRIC_ENCRYPTION
#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
-{"Test psa_export_key with EC Public key\n",
- PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
- {0},
- 65, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION, BUFFER_SIZE,
- 256, 65, PSA_SUCCESS
+{
+ .test_desc = "Test psa_export_key with EC Public key\n",
+ .type = PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
+ .data = ec_key_data,
+ .data_length = 65,
+ .bits = 256,
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .data_size = BUFFER_SIZE,
+ .expected_data_length = 65,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_ECC_CURVE_SECP224R1
-{"Test psa_export_key with EC keypair\n",
- PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP224R1),
- {0},
- 28, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION, BUFFER_SIZE,
- 224, 28, PSA_SUCCESS
+{
+ .test_desc = "Test psa_export_key with EC keypair\n",
+ .type = PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP224R1),
+ .data = ec_key_pair,
+ .data_length = 28,
+ .bits = BYTES_TO_BITS(28),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .data_size = BUFFER_SIZE,
+ .expected_data_length = 28,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
-{"Test psa_export_key with key policy verify\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0x05},
- AES_16B_KEY_SIZE, 0, PSA_KEY_USAGE_VERIFY, PSA_ALG_CTR, BUFFER_SIZE,
- BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_ERROR_NOT_PERMITTED
+{
+ .test_desc = "Test psa_export_key with key policy verify\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_VERIFY,
+ .expected_data = expected_output,
+ .data_size = BUFFER_SIZE,
+ .expected_data_length = AES_16B_KEY_SIZE,
+ .expected_status = PSA_ERROR_NOT_PERMITTED
},
-{"Test psa_export_key with less buffer size\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0x05},
- AES_16B_KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, 14,
- BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_ERROR_BUFFER_TOO_SMALL
+{
+ .test_desc = "Test psa_export_key with less buffer size\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .data_size = 14,
+ .expected_data_length = AES_16B_KEY_SIZE,
+ .expected_status = PSA_ERROR_BUFFER_TOO_SMALL
},
#endif
#endif
diff --git a/api-tests/dev_apis/crypto/test_c004/test_c004.c b/api-tests/dev_apis/crypto/test_c004/test_c004.c
index 8f24c59..eb99bb6 100644
--- a/api-tests/dev_apis/crypto/test_c004/test_c004.c
+++ b/api-tests/dev_apis/crypto/test_c004/test_c004.c
@@ -26,14 +26,11 @@
NULL,
};
-static int g_test_count = 1;
-static uint8_t data[BUFFER_SIZE];
-
int32_t test_psa_export_public_key(caller_security_t caller __UNUSED)
{
int32_t i, status;
- size_t length;
- const uint8_t *key_data;
+ size_t expected_data_length;
+ const uint8_t *data;
int num_checks = sizeof(check1)/sizeof(check1[0]);
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_handle_t key_handle;
@@ -51,93 +48,55 @@
/* Set the key data buffer to the input base on algorithm */
for (i = 0; i < num_checks; i++)
{
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] ", i+1);
val->print(PRINT_TEST, check1[i].test_desc, 0);
- memset(data, 0, BUFFER_SIZE);
+ memset(check1[i].expected_data, 0, BUFFER_SIZE);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type))
- {
- if (check1[i].key_type == PSA_KEY_TYPE_RSA_KEY_PAIR)
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keypair;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keypair;
- else
- return VAL_STATUS_INVALID;
- }
- else
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keydata;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keydata;
- else
- return VAL_STATUS_INVALID;
- }
- }
- else if (PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
- {
- if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(check1[i].key_type))
- key_data = ec_keypair;
- else
- key_data = ec_keydata;
- }
- else
- key_data = check1[i].key_data;
-
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_BITS, &attributes, check1[i].attr_bits);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_BITS, &attributes, check1[i].bits);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage_flags);
/* Import the key data into the key slot */
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, key_data,
- check1[i].key_length, &key_handle);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Export a key in binary format */
- status = val->crypto_function(VAL_CRYPTO_EXPORT_PUBLIC_KEY, key_handle, data,
- check1[i].buffer_size, &length);
+ status = val->crypto_function(VAL_CRYPTO_EXPORT_PUBLIC_KEY, key_handle,
+ check1[i].expected_data, check1[i].data_size,
+ &expected_data_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(4));
/* If failure is expected, continue with the next data set */
if (check1[i].expected_status != PSA_SUCCESS)
continue;
- TEST_ASSERT_EQUAL(length, check1[i].expected_key_length, TEST_CHECKPOINT_NUM(5));
+ TEST_ASSERT_EQUAL(expected_data_length, check1[i].expected_data_length,
+ TEST_CHECKPOINT_NUM(5));
/* Check if original key data matches with the exported data */
- if (PSA_KEY_TYPE_IS_UNSTRUCTURED(check1[i].key_type))
- {
- TEST_ASSERT_MEMCMP(check1[i].key_data, data, length, TEST_CHECKPOINT_NUM(6));
- }
- else if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type) || PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
- {
- if (check1[i].key_type == PSA_KEY_TYPE_RSA_KEY_PAIR)
- key_data = expected_rsa_256_pubprv;
-
- else if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(check1[i].key_type))
- key_data = expected_ec_pubprv;
-
- TEST_ASSERT_MEMCMP(key_data, data, length, TEST_CHECKPOINT_NUM(7));
- }
+ if (check1[i].type == PSA_KEY_TYPE_RSA_KEY_PAIR)
+ data = expected_rsa_256_pubprv;
+ else if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(check1[i].type))
+ data = expected_ec_pubprv;
else
- {
- return VAL_STATUS_INVALID;
- }
+ data = check1[i].data;
+ TEST_ASSERT_MEMCMP(data, check1[i].expected_data, expected_data_length,
+ TEST_CHECKPOINT_NUM(6));
/* Destroy the key handle and check if export key fails */
status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(8));
- status = val->crypto_function(VAL_CRYPTO_EXPORT_PUBLIC_KEY, key_handle, data,
- check1[i].buffer_size, &length);
+ status = val->crypto_function(VAL_CRYPTO_EXPORT_PUBLIC_KEY, key_handle,
+ check1[i].expected_data, check1[i].data_size,
+ &expected_data_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(9));
}
diff --git a/api-tests/dev_apis/crypto/test_c004/test_data.h b/api-tests/dev_apis/crypto/test_c004/test_data.h
index 428a112..a2a3e33 100644
--- a/api-tests/dev_apis/crypto/test_c004/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c004/test_data.h
@@ -15,24 +15,21 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- psa_key_type_t key_type;
- uint8_t key_data[34];
- uint32_t key_length;
- size_t attr_bits;
- psa_key_usage_t usage;
- psa_algorithm_t key_alg;
- size_t buffer_size;
- uint32_t expected_bit_length;
- uint32_t expected_key_length;
+ psa_key_type_t type;
+ const uint8_t *data;
+ size_t data_length;
+ size_t bits;
+ psa_key_usage_t usage_flags;
+ uint8_t *expected_data;
+ size_t data_size;
+ size_t expected_data_length;
psa_status_t expected_status;
} test_data;
-static const uint8_t rsa_384_keypair[1];
-static const uint8_t rsa_384_keydata[1];
static const uint8_t expected_rsa_256_pubprv[] = {
0x30, 0x82,
0x01, 0x0A, 0x02, 0x82, 0x01, 0x01, 0x00, 0xC0, 0x95, 0x08, 0xE1, 0x57, 0x41,
@@ -64,236 +61,177 @@
0xb1, 0x3c, 0x1a, 0x24, 0xce, 0x44, 0x91, 0x45, 0x71, 0xa9, 0x54, 0x40, 0xae,
0x01, 0x4a, 0x00, 0xcb, 0xf7};
-static const uint8_t rsa_256_keypair[] = {
- 0x30, 0x82, 0x04, 0xA5, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xC0,
- 0x95, 0x08, 0xE1, 0x57, 0x41, 0xF2, 0x71, 0x6D, 0xB7, 0xD2, 0x45, 0x41, 0x27,
- 0x01, 0x65, 0xC6, 0x45, 0xAE, 0xF2, 0xBC, 0x24, 0x30, 0xB8, 0x95, 0xCE, 0x2F,
- 0x4E, 0xD6, 0xF6, 0x1C, 0x88, 0xBC, 0x7C, 0x9F, 0xFB, 0xA8, 0x67, 0x7F, 0xFE,
- 0x5C, 0x9C, 0x51, 0x75, 0xF7, 0x8A, 0xCA, 0x07, 0xE7, 0x35, 0x2F, 0x8F, 0xE1,
- 0xBD, 0x7B, 0xC0, 0x2F, 0x7C, 0xAB, 0x64, 0xA8, 0x17, 0xFC, 0xCA, 0x5D, 0x7B,
- 0xBA, 0xE0, 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01, 0x20, 0x42, 0x08, 0x70, 0x97, 0x49, 0x6e, 0xfc, 0x58, 0x3f, 0xed, 0x8b,
- 0x24, 0xa5, 0xb9, 0xbe, 0x9a, 0x51, 0xde, 0x06, 0x3f, 0x5a, 0x00, 0xa8, 0xb6, 0x98,
- 0xa1, 0x6f, 0xd7, 0xf2, 0x9b, 0x54, 0x85, 0xf3, 0x20};
-
-static const uint8_t ec_keypair[] = {
- 0x68, 0x49, 0xf9, 0x7d, 0x10, 0x66, 0xf6, 0x99, 0x77, 0x59, 0x63, 0x7c, 0x7e, 0x38,
- 0x99, 0x46, 0x4c, 0xee, 0x3e, 0xc7, 0xac, 0x97, 0x06, 0x53, 0xa0, 0xbe, 0x07, 0x42};
-
static const test_data check1[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
-{"Test psa_export_public_key 16 Byte AES\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9},
- AES_16B_KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
- BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_export_public_key 16 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .data_size = BUFFER_SIZE,
+ .expected_data_length = AES_16B_KEY_SIZE,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#ifdef ARCH_TEST_AES_192
-{"Test psa_export_public_key 24 Byte AES\n", PSA_KEY_TYPE_AES,
-{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
- 0x40, 0xAC, 0xA3, 0x90, 0x77, 0x83, 0x52, 0x31, 0x74, 0xF9},
- AES_24B_KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
- BYTES_TO_BITS(AES_24B_KEY_SIZE), AES_24B_KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_export_public_key 24 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_24B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_24B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .data_size = BUFFER_SIZE,
+ .expected_data_length = AES_24B_KEY_SIZE,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#ifdef ARCH_TEST_AES_256
-{"Test psa_export_public_key 32 Byte AES\n", PSA_KEY_TYPE_AES,
-{0xEA, 0xD5, 0xE6, 0xC8, 0x51, 0xF9, 0xEC, 0xBB, 0x9B, 0x57, 0x7C, 0xED, 0xD2,
- 0x4B, 0x82, 0x84, 0x9F, 0x9F, 0xE6, 0x73, 0x21, 0x3D, 0x1A, 0x05, 0xC9, 0xED,
- 0xDF, 0x25, 0x17, 0x68, 0x86, 0xAE},
- AES_32B_KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
- BYTES_TO_BITS(AES_32B_KEY_SIZE), AES_32B_KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_export_public_key 32 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_32B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_32B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .data_size = BUFFER_SIZE,
+ .expected_data_length = AES_32B_KEY_SIZE,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
#ifdef ARCH_TEST_RSA_2048
-{"Test psa_export_public_key 2048 RSA public key\n", PSA_KEY_TYPE_RSA_PUBLIC_KEY,
- {0},
- 270, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW, BUFFER_SIZE,
- 2048, 270, PSA_SUCCESS
+{
+ .test_desc = "Test psa_export_public_key 2048 RSA public key\n",
+ .type = PSA_KEY_TYPE_RSA_PUBLIC_KEY,
+ .data = rsa_256_key_data,
+ .data_length = 270,
+ .bits = BYTES_TO_BITS(256),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .data_size = BUFFER_SIZE,
+ .expected_data_length = 270,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_export_public_key with RSA 2048 keypair\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
- {0},
- 1193, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW, BUFFER_SIZE,
- 2048, 270, PSA_SUCCESS
+{
+ .test_desc = "Test psa_export_public_key with RSA 2048 keypair\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_256_key_pair,
+ .data_length = 1193,
+ .bits = BYTES_TO_BITS(256),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .data_size = BUFFER_SIZE,
+ .expected_data_length = 270,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_DES_1KEY
-{"Test psa_export_public_key with DES 64 bit key\n", PSA_KEY_TYPE_DES,
- {0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
- DES_8B_KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
- BYTES_TO_BITS(DES_8B_KEY_SIZE), DES_8B_KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_export_public_key with DES 64 bit key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES_8B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(DES_8B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .data_size = BUFFER_SIZE,
+ .expected_data_length = DES_8B_KEY_SIZE,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#ifdef ARCH_TEST_DES_2KEY
-{"Test psa_export_public_key with Triple DES 2-Key\n", PSA_KEY_TYPE_DES,
-{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
- DES3_2KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
- BYTES_TO_BITS(DES3_2KEY_SIZE), DES3_2KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_export_public_key with Triple DES 2-Key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_2B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(DES3_2B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .data_size = BUFFER_SIZE,
+ .expected_data_length = DES3_2B_KEY_SIZE,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#ifdef ARCH_TEST_DES_3KEY
-{"Test psa_export_public_key with Triple DES 3-Key\n", PSA_KEY_TYPE_DES,
-{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
- 0xF1, 0xE0, 0xD3, 0xC2, 0xB5, 0xA4, 0x97, 0x86,
- 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10},
- DES3_3KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
- BYTES_TO_BITS(DES3_3KEY_SIZE), DES3_3KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_export_public_key with Triple DES 3-Key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_3B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(DES3_3B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .data_size = BUFFER_SIZE,
+ .expected_data_length = DES3_3B_KEY_SIZE,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
#ifdef ARCH_TEST_ASYMMETRIC_ENCRYPTION
#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
-{"Test psa_export_public_key with EC Public key\n",
- PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
- {0},
- 65, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION, BUFFER_SIZE,
- 256, 65, PSA_SUCCESS
+{
+ .test_desc = "Test psa_export_public_key with EC Public key\n",
+ .type = PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
+ .data = ec_key_data,
+ .data_length = 65,
+ .bits = 256,
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .data_size = BUFFER_SIZE,
+ .expected_data_length = 65,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_ECC_CURVE_SECP224R1
-{"Test psa_export_public_key with EC keypair\n",
- PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP224R1),
- {0},
- 28, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION, BUFFER_SIZE,
- 224, 57, PSA_SUCCESS
+{
+ .test_desc = "Test psa_export_public_key with EC keypair\n",
+ .type = PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP224R1),
+ .data = ec_key_pair,
+ .data_length = 28,
+ .bits = BYTES_TO_BITS(28),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .data_size = BUFFER_SIZE,
+ .expected_data_length = 57,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
#ifdef ARCH_TEST_RSA
-{"Test psa_export_public_key with less buffer size\n", PSA_KEY_TYPE_RSA_PUBLIC_KEY,
-{0},
-270, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW, 200,
-2048, 270, PSA_ERROR_BUFFER_TOO_SMALL
+{
+ .test_desc = "Test psa_export_public_key with less buffer size\n",
+ .type = PSA_KEY_TYPE_RSA_PUBLIC_KEY,
+ .data = rsa_256_key_data,
+ .data_length = 270,
+ .bits = BYTES_TO_BITS(256),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .data_size = 200,
+ .expected_data_length = 270,
+ .expected_status = PSA_ERROR_BUFFER_TOO_SMALL
},
#endif
#endif
diff --git a/api-tests/dev_apis/crypto/test_c005/test_c005.c b/api-tests/dev_apis/crypto/test_c005/test_c005.c
index c6ee0d8..fa95d00 100644
--- a/api-tests/dev_apis/crypto/test_c005/test_c005.c
+++ b/api-tests/dev_apis/crypto/test_c005/test_c005.c
@@ -26,18 +26,15 @@
NULL,
};
-static int g_test_count = 1;
-
int32_t psa_destroy_key_test(caller_security_t caller __UNUSED)
{
int32_t i, status;
- const uint8_t *key_data;
- psa_key_type_t get_key_type;
- psa_key_id_t get_key_id;
- psa_key_lifetime_t get_key_lifetime;
- psa_key_usage_t get_key_usage_flags;
- psa_algorithm_t get_key_algorithm;
- size_t get_key_bits;
+ psa_key_type_t get_type;
+ psa_key_id_t get_id;
+ psa_key_lifetime_t get_lifetime;
+ psa_key_usage_t get_usage_flags;
+ psa_algorithm_t get_alg;
+ size_t get_bits;
int num_checks = sizeof(check1)/sizeof(check1[0]);
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t set_attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -56,60 +53,30 @@
/* Set the key data buffer to the input base on algorithm */
for (i = 0; i < num_checks; i++)
{
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] ", i+1);
val->print(PRINT_TEST, check1[i].test_desc, 0);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type))
- {
- if (check1[i].key_type == PSA_KEY_TYPE_RSA_KEY_PAIR)
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keypair;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keypair;
- else
- return VAL_STATUS_INVALID;
- }
- else
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keydata;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keydata;
- else
- return VAL_STATUS_INVALID;
- }
- }
- else if (PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
- {
- if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(check1[i].key_type))
- key_data = ec_keypair;
- else
- key_data = ec_keydata;
- }
- else
- key_data = check1[i].key_data;
-
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &set_attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_BITS, &set_attributes, check1[i].attr_bits);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &set_attributes, check1[i].usage);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ID, &set_attributes, check1[i].key_id);
- val->crypto_function(VAL_CRYPTO_SET_KEY_LIFETIME, &set_attributes, check1[i].key_lifetime);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &set_attributes, check1[i].key_alg);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &set_attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_BITS, &set_attributes, check1[i].bits);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &set_attributes,
+ check1[i].usage_flags);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ID, &set_attributes, check1[i].id);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_LIFETIME, &set_attributes, check1[i].lifetime);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &set_attributes, check1[i].alg);
/* Import the key data into the key slot */
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &set_attributes, key_data,
- check1[i].key_length, &key_handle);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &set_attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Destroy the key handle */
status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, key_handle);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
+ TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(4));
/* Getting the attributes of the destroyed key should return error */
status = val->crypto_function(VAL_CRYPTO_GET_KEY_ATTRIBUTES, key_handle,
@@ -117,23 +84,23 @@
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(5));
/* Check if all the attributes are erased */
- val->crypto_function(VAL_CRYPTO_GET_KEY_TYPE, &attributes, &get_key_type);
- TEST_ASSERT_EQUAL(get_key_type, 0, TEST_CHECKPOINT_NUM(6));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_TYPE, &attributes, &get_type);
+ TEST_ASSERT_EQUAL(get_type, 0, TEST_CHECKPOINT_NUM(6));
- val->crypto_function(VAL_CRYPTO_GET_KEY_ID, &attributes, &get_key_id);
- TEST_ASSERT_EQUAL(get_key_id, 0, TEST_CHECKPOINT_NUM(7));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_ID, &attributes, &get_id);
+ TEST_ASSERT_EQUAL(get_id, 0, TEST_CHECKPOINT_NUM(7));
- val->crypto_function(VAL_CRYPTO_GET_KEY_LIFETIME, &attributes, &get_key_lifetime);
- TEST_ASSERT_EQUAL(get_key_lifetime, 0, TEST_CHECKPOINT_NUM(8));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_LIFETIME, &attributes, &get_lifetime);
+ TEST_ASSERT_EQUAL(get_lifetime, 0, TEST_CHECKPOINT_NUM(8));
- val->crypto_function(VAL_CRYPTO_GET_KEY_USAGE_FLAGS, &attributes, &get_key_usage_flags);
- TEST_ASSERT_EQUAL(get_key_usage_flags, 0, TEST_CHECKPOINT_NUM(9));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_USAGE_FLAGS, &attributes, &get_usage_flags);
+ TEST_ASSERT_EQUAL(get_usage_flags, 0, TEST_CHECKPOINT_NUM(9));
- val->crypto_function(VAL_CRYPTO_GET_KEY_ALGORITHM, &attributes, &get_key_algorithm);
- TEST_ASSERT_EQUAL(get_key_algorithm, 0, TEST_CHECKPOINT_NUM(10));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_ALGORITHM, &attributes, &get_alg);
+ TEST_ASSERT_EQUAL(get_alg, 0, TEST_CHECKPOINT_NUM(10));
- val->crypto_function(VAL_CRYPTO_GET_KEY_BITS, &attributes, &get_key_bits);
- TEST_ASSERT_EQUAL(get_key_bits, 0, TEST_CHECKPOINT_NUM(11));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_BITS, &attributes, &get_bits);
+ TEST_ASSERT_EQUAL(get_bits, 0, TEST_CHECKPOINT_NUM(11));
/* Destroying an empty key handle should return error */
status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, key_handle);
diff --git a/api-tests/dev_apis/crypto/test_c005/test_data.h b/api-tests/dev_apis/crypto/test_c005/test_data.h
index e693af9..2dd9d36 100644
--- a/api-tests/dev_apis/crypto/test_c005/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c005/test_data.h
@@ -15,256 +15,177 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- psa_key_type_t key_type;
- uint8_t key_data[34];
- uint32_t key_length;
- size_t attr_bits;
- psa_key_usage_t usage;
- psa_algorithm_t key_alg;
- psa_key_id_t key_id;
- psa_key_lifetime_t key_lifetime;
- uint32_t expected_bit_length;
+ psa_key_type_t type;
+ const uint8_t *data;
+ size_t data_length;
+ size_t bits;
+ psa_key_usage_t usage_flags;
+ psa_algorithm_t alg;
+ psa_key_id_t id;
+ psa_key_lifetime_t lifetime;
psa_status_t expected_status;
} test_data;
-static const uint8_t rsa_384_keypair[1];
-static const uint8_t rsa_384_keydata[1];
-static const uint8_t rsa_256_keypair[] = {
- 0x30, 0x82, 0x04, 0xA5, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xC0,
- 0x95, 0x08, 0xE1, 0x57, 0x41, 0xF2, 0x71, 0x6D, 0xB7, 0xD2, 0x45, 0x41, 0x27,
- 0x01, 0x65, 0xC6, 0x45, 0xAE, 0xF2, 0xBC, 0x24, 0x30, 0xB8, 0x95, 0xCE, 0x2F,
- 0x4E, 0xD6, 0xF6, 0x1C, 0x88, 0xBC, 0x7C, 0x9F, 0xFB, 0xA8, 0x67, 0x7F, 0xFE,
- 0x5C, 0x9C, 0x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, 0x5d, 0x0e, 0xa3, 0x7f, 0xc5, 0x66, 0x23, 0x2a, 0x50, 0x8f,
- 0x4a, 0xd2, 0x0e, 0xa1, 0x3d, 0x47, 0xe4, 0xbf, 0x5f, 0xa4, 0xd5, 0x4a, 0x57, 0xa0,
- 0xba, 0x01, 0x20, 0x42, 0x08, 0x70, 0x97, 0x49, 0x6e, 0xfc, 0x58, 0x3f, 0xed, 0x8b,
- 0x24, 0xa5, 0xb9, 0xbe, 0x9a, 0x51, 0xde, 0x06, 0x3f, 0x5a, 0x00, 0xa8, 0xb6, 0x98,
- 0xa1, 0x6f, 0xd7, 0xf2, 0x9b, 0x54, 0x85, 0xf3, 0x20};
-
-static const uint8_t ec_keypair[] = {
- 0x68, 0x49, 0xf9, 0x7d, 0x10, 0x66, 0xf6, 0x99, 0x77, 0x59, 0x63, 0x7c, 0x7e, 0x38,
- 0x99, 0x46, 0x4c, 0xee, 0x3e, 0xc7, 0xac, 0x97, 0x06, 0x53, 0xa0, 0xbe, 0x07, 0x42};
-
static const test_data check1[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
-{"Test psa_destroy_key 16 Byte AES\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9},
- AES_16B_KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
- 0x12, PSA_KEY_LIFETIME_VOLATILE,
- BYTES_TO_BITS(AES_16B_KEY_SIZE), PSA_SUCCESS
+{
+ .test_desc = "Test psa_destroy_key 16 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .alg = PSA_ALG_CTR,
+ .id = 0x12,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_192
-{"Test psa_destroy_key 24 Byte AES\n", PSA_KEY_TYPE_AES,
-{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
- 0x40, 0xAC, 0xA3, 0x90, 0x77, 0x83, 0x52, 0x31, 0x74, 0xF9},
- AES_24B_KEY_SIZE, BYTES_TO_BITS(AES_24B_KEY_SIZE), PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
- 0x34, PSA_KEY_LIFETIME_VOLATILE,
- BYTES_TO_BITS(AES_24B_KEY_SIZE), PSA_SUCCESS
+{
+ .test_desc = "Test psa_destroy_key 24 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_24B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_24B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .alg = PSA_ALG_CTR,
+ .id = 0x34,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_256
-{"Test psa_destroy_key 32 Byte AES\n", PSA_KEY_TYPE_AES,
-{0xEA, 0xD5, 0xE6, 0xC8, 0x51, 0xF9, 0xEC, 0xBB, 0x9B, 0x57, 0x7C, 0xED, 0xD2,
- 0x4B, 0x82, 0x84, 0x9F, 0x9F, 0xE6, 0x73, 0x21, 0x3D, 0x1A, 0x05, 0xC9, 0xED,
- 0xDF, 0x25, 0x17, 0x68, 0x86, 0xAE},
- AES_32B_KEY_SIZE, BYTES_TO_BITS(AES_32B_KEY_SIZE), PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
- 0x56, PSA_KEY_LIFETIME_VOLATILE,
- BYTES_TO_BITS(AES_32B_KEY_SIZE), PSA_SUCCESS
+{
+ .test_desc = "Test psa_destroy_key 32 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_32B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_32B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .alg = PSA_ALG_CTR,
+ .id = 0x56,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
#ifdef ARCH_TEST_RSA_2048
-{"Test psa_destroy_key 2048 RSA public key\n", PSA_KEY_TYPE_RSA_PUBLIC_KEY,
- {0},
- 270, 2048, PSA_KEY_USAGE_EXPORT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
- 0x78, PSA_KEY_LIFETIME_VOLATILE,
- 2048, PSA_SUCCESS
+{
+ .test_desc = "Test psa_destroy_key 2048 RSA public key\n",
+ .type = PSA_KEY_TYPE_RSA_PUBLIC_KEY,
+ .data = rsa_256_key_data,
+ .data_length = 270,
+ .bits = BYTES_TO_BITS(256),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
+ .id = 0x78,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_destroy_key with RSA 2048 keypair\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
- {0},
- 1193, 2048, PSA_KEY_USAGE_EXPORT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
- 0x89, PSA_KEY_LIFETIME_VOLATILE,
- 2048, PSA_SUCCESS
+{
+ .test_desc = "Test psa_destroy_key with RSA 2048 keypair\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_256_key_pair,
+ .data_length = 1193,
+ .bits = BYTES_TO_BITS(256),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
+ .id = 0x89,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_DES_1KEY
-{"Test psa_destroy_key with DES 64 bit key\n", PSA_KEY_TYPE_DES,
- {0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
- DES_8B_KEY_SIZE, BYTES_TO_BITS(DES_8B_KEY_SIZE), PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
- 0xAB, PSA_KEY_LIFETIME_VOLATILE,
- BYTES_TO_BITS(DES_8B_KEY_SIZE), PSA_SUCCESS
+{
+ .test_desc = "Test psa_destroy_key with DES 64 bit key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES_8B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(DES_8B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .alg = PSA_ALG_CTR,
+ .id = 0xAB,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_2KEY
-{"Test psa_destroy_key with Triple DES 2-Key\n", PSA_KEY_TYPE_DES,
-{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
- DES3_2KEY_SIZE, BYTES_TO_BITS(DES3_2KEY_SIZE), PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
- 0xBC, PSA_KEY_LIFETIME_VOLATILE,
- BYTES_TO_BITS(DES3_2KEY_SIZE), PSA_SUCCESS
+{
+ .test_desc = "Test psa_destroy_key with Triple DES 2-Key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_2B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(DES3_2B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .alg = PSA_ALG_CTR,
+ .id = 0xBC,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_3KEY
-{"Test psa_destroy_key with Triple DES 3-Key\n", PSA_KEY_TYPE_DES,
-{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
- 0xF1, 0xE0, 0xD3, 0xC2, 0xB5, 0xA4, 0x97, 0x86,
- 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10},
- DES3_3KEY_SIZE, BYTES_TO_BITS(DES3_3KEY_SIZE), PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
- 0xCD, PSA_KEY_LIFETIME_VOLATILE,
- BYTES_TO_BITS(DES3_3KEY_SIZE), PSA_SUCCESS
+{
+ .test_desc = "Test psa_destroy_key with Triple DES 3-Key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_3B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(DES3_3B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .alg = PSA_ALG_CTR,
+ .id = 0xCD,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_ECDSA
#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
-{"Test psa_destroy_key with EC Public key\n",
- PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
- {0},
- 65, 256, PSA_KEY_USAGE_EXPORT, PSA_ALG_ECDSA_ANY,
- 0xEF, PSA_KEY_LIFETIME_VOLATILE,
- 256, PSA_SUCCESS
+{
+ .test_desc = "Test psa_destroy_key with EC Public key\n",
+ .type = PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
+ .data = ec_key_data,
+ .data_length = 65,
+ .bits = 256,
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .alg = PSA_ALG_ECDSA_ANY,
+ .id = 0xEF,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_ASYMMETRIC_ENCRYPTION
#ifdef ARCH_TEST_ECC_CURVE_SECP224R1
-{"Test psa_destroy_key with EC keypair\n",
- PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP224R1),
- {0},
- 28, 224, PSA_KEY_USAGE_EXPORT, PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION,
- 0x123, PSA_KEY_LIFETIME_VOLATILE,
- 224, PSA_SUCCESS
+{
+ .test_desc = "Test psa_destroy_key with EC keypair\n",
+ .type = PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP224R1),
+ .data = ec_key_pair,
+ .data_length = 28,
+ .bits = BYTES_TO_BITS(28),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .alg = PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION,
+ .id = 0x123,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
diff --git a/api-tests/dev_apis/crypto/test_c006/test_c006.c b/api-tests/dev_apis/crypto/test_c006/test_c006.c
index f6cd6f9..5e755a4 100644
--- a/api-tests/dev_apis/crypto/test_c006/test_c006.c
+++ b/api-tests/dev_apis/crypto/test_c006/test_c006.c
@@ -19,7 +19,6 @@
#include "val_target.h"
#include "test_c006.h"
#include "test_data.h"
-#include "val_crypto.h"
const client_test_t test_c006_crypto_list[] = {
NULL,
@@ -27,15 +26,11 @@
NULL,
};
-static int g_test_count = 1;
-
int32_t psa_hash_compute_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
- const char *expected_hash;
- char hash[HASH_64B];
- size_t hash_length;
+ size_t expected_hash_length;
if (num_checks == 0)
{
@@ -49,23 +44,21 @@
for (i = 0; i < num_checks; i++)
{
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] ", i+1);
val->print(PRINT_TEST, check1[i].test_desc, 0);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- if (check1[i].alg == PSA_ALG_SHA_384)
- expected_hash = sha384_hash;
- else if (check1[i].alg == PSA_ALG_SHA_512)
- expected_hash = sha512_hash;
- else
- expected_hash = check1[i].hash;
-
/* Calculate the hash (digest) of a message */
- status = val->crypto_function(VAL_CRYPTO_HASH_COMPUTE, check1[i].alg, &check1[i].input,
- check1[i].input_length, hash, check1[i].hash_length, &hash_length);
+ status = val->crypto_function(VAL_CRYPTO_HASH_COMPUTE,
+ check1[i].alg,
+ check1[i].input,
+ check1[i].input_length,
+ check1[i].hash,
+ check1[i].hash_size,
+ &expected_hash_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(3));
if (check1[i].expected_status != PSA_SUCCESS)
@@ -73,8 +66,10 @@
continue;
}
- TEST_ASSERT_EQUAL(hash_length, PSA_HASH_SIZE(check1[i].alg), TEST_CHECKPOINT_NUM(4));
- TEST_ASSERT_MEMCMP(hash, expected_hash, hash_length, TEST_CHECKPOINT_NUM(5));
+ TEST_ASSERT_EQUAL(expected_hash_length, check1[i].expected_hash_length,
+ TEST_CHECKPOINT_NUM(4));
+ TEST_ASSERT_MEMCMP(check1[i].hash, check1[i].expected_hash, expected_hash_length,
+ TEST_CHECKPOINT_NUM(5));
}
return VAL_STATUS_SUCCESS;
diff --git a/api-tests/dev_apis/crypto/test_c006/test_data.h b/api-tests/dev_apis/crypto/test_c006/test_data.h
index f238ef7..6da03eb 100644
--- a/api-tests/dev_apis/crypto/test_c006/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c006/test_data.h
@@ -15,111 +15,170 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[50];
psa_algorithm_t alg;
- char input;
+ const uint8_t *input;
size_t input_length;
- char hash[32];
- size_t hash_length;
+ uint8_t *hash;
+ size_t hash_size;
+ const uint8_t *expected_hash;
+ size_t expected_hash_length;
psa_status_t expected_status;
} test_data;
-static const char sha384_hash[] = {
-0x43, 0x72, 0xe3, 0x8a, 0x92, 0xa2, 0x8b, 0x5d, 0x2c, 0x39, 0x1e, 0x62,
-0x45, 0x2a, 0x86, 0xd5, 0x0e, 0x02, 0x67, 0x22, 0x8b, 0xe1, 0x76, 0xc7, 0x7d, 0x24, 0x02, 0xef,
-0xfe, 0x9f, 0xa5, 0x0d, 0xe4, 0x07, 0xbb, 0xb8, 0x51, 0xb3, 0x7d, 0x59, 0x04, 0xab, 0xa2, 0xde,
-0xde, 0x74, 0xda, 0x2a};
-
-static const char sha512_hash[] = {
-0x29, 0x6e, 0x22, 0x67, 0xd7, 0x4c, 0x27, 0x8d, 0xaa, 0xaa, 0x94, 0x0d,
-0x17, 0xb0, 0xcf, 0xb7, 0x4a, 0x50, 0x83, 0xf8, 0xe0, 0x69, 0x72, 0x6d, 0x8c, 0x84, 0x1c, 0xbe,
-0x59, 0x6e, 0x04, 0x31, 0xcb, 0x77, 0x41, 0xa5, 0xb5, 0x0f, 0x71, 0x66, 0x6c, 0xfd, 0x54, 0xba,
-0xcb, 0x7b, 0x00, 0xae, 0xa8, 0x91, 0x49, 0x9c, 0xf4, 0xef, 0x6a, 0x03, 0xc8, 0xa8, 0x3f, 0xe3,
-0x7c, 0x3f, 0x7b, 0xaf};
-
static const test_data check1[] = {
#ifdef ARCH_TEST_MD2
-{"Test psa_hash_compute with MD2 algorithm\n",
- PSA_ALG_MD2, 0xbd, 1,
- {0x8c, 0x9c, 0x17, 0x66, 0x5d, 0x25, 0xb3, 0x5f, 0xc4, 0x13, 0xc4, 0x18, 0x05, 0xc6, 0x79, 0xcf},
- 16, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_compute with MD2 algorithm\n",
+ .alg = PSA_ALG_MD2,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = expected_output,
+ .hash_size = BUFFER_SIZE,
+ .expected_hash = md2_hash,
+ .expected_hash_length = 16,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD4
-{"Test psa_hash_compute with MD4 algorithm\n",
- PSA_ALG_MD4, 0xbd, 1,
- {0x18, 0xc3, 0x3f, 0x97, 0x29, 0x7e, 0xfe, 0x5f, 0x8a, 0x73, 0x22, 0x58, 0x28, 0x9f, 0xda, 0x25},
- 16, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_compute with MD4 algorithm\n",
+ .alg = PSA_ALG_MD4,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = expected_output,
+ .hash_size = BUFFER_SIZE,
+ .expected_hash = md4_hash,
+ .expected_hash_length = 16,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD5
-{"Test psa_hash_compute with MD5 algorithm\n",
- PSA_ALG_MD5, 0xbd, 1,
- {0xab, 0xae, 0x57, 0xcb, 0x56, 0x2e, 0xcf, 0x29, 0x5b, 0x4a, 0x37, 0xa7, 0x6e, 0xfe, 0x61, 0xfb},
- 16, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_compute with MD5 algorithm\n",
+ .alg = PSA_ALG_MD5,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = expected_output,
+ .hash_size = BUFFER_SIZE,
+ .expected_hash = md5_hash,
+ .expected_hash_length = 16,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_RIPEMD160
-{"Test psa_hash_compute with RIPEMD160 algorithm\n",
- PSA_ALG_RIPEMD160, 0xbd, 1,
- {0x50, 0x89, 0x26, 0x5e, 0xe5, 0xd9, 0xaf, 0x75, 0xd1, 0x2d, 0xbf, 0x7e, 0xa2, 0xf2, 0x7d, 0xbd,
- 0xee, 0x43, 0x5b, 0x37},
- 20, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_compute with RIPEMD160 algorithm\n",
+ .alg = PSA_ALG_RIPEMD160,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = expected_output,
+ .hash_size = BUFFER_SIZE,
+ .expected_hash = ripemd_160_hash,
+ .expected_hash_length = 20,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA1
-{"Test psa_hash_compute with SHA1 algorithm\n",
- PSA_ALG_SHA_1, 0xbd, 1,
- {0x90, 0x34, 0xaa, 0xf4, 0x51, 0x43, 0x99, 0x6a, 0x2b, 0x14, 0x46, 0x5c, 0x35, 0x2a, 0xb0, 0xc6,
- 0xfa, 0x26, 0xb2, 0x21},
- 20, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_compute with SHA1 algorithm\n",
+ .alg = PSA_ALG_SHA_1,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = expected_output,
+ .hash_size = BUFFER_SIZE,
+ .expected_hash = sha_1_hash,
+ .expected_hash_length = 20,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA224
-{"Test psa_hash_compute with SHA224 algorithm\n",
- PSA_ALG_SHA_224, 0xbd, 1,
- {0xb1, 0xe4, 0x6b, 0xb9, 0xef, 0xe4, 0x5a, 0xf5, 0x54, 0x36, 0x34, 0x49, 0xc6, 0x94, 0x5a, 0x0d,
- 0x61, 0x69, 0xfc, 0x3a, 0x5a, 0x39, 0x6a, 0x56, 0xcb, 0x97, 0xcb, 0x57},
- 28, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_compute with SHA224 algorithm\n",
+ .alg = PSA_ALG_SHA_224,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = expected_output,
+ .hash_size = BUFFER_SIZE,
+ .expected_hash = sha_224_hash,
+ .expected_hash_length = 28,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA256
-{"Test psa_hash_compute with SHA256 algorithm\n",
- PSA_ALG_SHA_256, 0xbd, 1,
- {0x68, 0x32, 0x57, 0x20, 0xaa, 0xbd, 0x7c, 0x82, 0xf3, 0x0f, 0x55, 0x4b, 0x31, 0x3d, 0x05, 0x70,
- 0xc9, 0x5a, 0xcc, 0xbb, 0x7d, 0xc4, 0xb5, 0xaa, 0xe1, 0x12, 0x04, 0xc0, 0x8f, 0xfe, 0x73, 0x2b},
- 32, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_compute with SHA256 algorithm\n",
+ .alg = PSA_ALG_SHA_256,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = expected_output,
+ .hash_size = BUFFER_SIZE,
+ .expected_hash = sha_256_hash,
+ .expected_hash_length = 32,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA384
-{"Test psa_hash_compute with SHA384 algorithm\n",
- PSA_ALG_SHA_384, 0xbd, 1, {0}, 48, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_compute with SHA384 algorithm\n",
+ .alg = PSA_ALG_SHA_384,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = expected_output,
+ .hash_size = BUFFER_SIZE,
+ .expected_hash = sha_384_hash,
+ .expected_hash_length = 48,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA512
-{"Test psa_hash_compute with SHA512 algorithm\n",
- PSA_ALG_SHA_512, 0xbd, 1, {0}, 64, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_compute with SHA512 algorithm\n",
+ .alg = PSA_ALG_SHA_512,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = expected_output,
+ .hash_size = BUFFER_SIZE,
+ .expected_hash = sha_512_hash,
+ .expected_hash_length = 64,
+ .expected_status = PSA_SUCCESS,
},
#ifdef ARCH_TEST_SHA512
-{"Test psa_hash_compute with small buffer size\n",
- PSA_ALG_SHA_512, 0xbd, 1, {0}, 60, PSA_ERROR_BUFFER_TOO_SMALL,
+{
+ .test_desc = "Test psa_hash_compute with small buffer size\n",
+ .alg = PSA_ALG_SHA_512,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = expected_output,
+ .hash_size = 60,
+ .expected_hash = expected_output,
+ .expected_hash_length = 64,
+ .expected_status = PSA_ERROR_BUFFER_TOO_SMALL,
},
#endif
#endif
-{"Test psa_hash_compute with invalid algorithm\n",
- PSA_HASH_ALG_INVALID, 0xbd, 1, {0}, 64, PSA_ERROR_NOT_SUPPORTED,
+{
+ .test_desc = "Test psa_hash_compute with invalid algorithm\n",
+ .alg = PSA_HASH_ALG_INVALID,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = expected_output,
+ .hash_size = BUFFER_SIZE,
+ .expected_hash = sha_512_hash,
+ .expected_hash_length = 64,
+ .expected_status = PSA_ERROR_NOT_SUPPORTED,
},
};
diff --git a/api-tests/dev_apis/crypto/test_c007/test_c007.c b/api-tests/dev_apis/crypto/test_c007/test_c007.c
index 9a4e859..39e3e7a 100644
--- a/api-tests/dev_apis/crypto/test_c007/test_c007.c
+++ b/api-tests/dev_apis/crypto/test_c007/test_c007.c
@@ -19,7 +19,6 @@
#include "val_target.h"
#include "test_c007.h"
#include "test_data.h"
-#include "val_crypto.h"
const client_test_t test_c007_crypto_list[] = {
NULL,
@@ -27,13 +26,10 @@
NULL,
};
-static int g_test_count = 1;
-
int32_t psa_hash_compare_test(caller_security_t caller __UNUSED)
{
int num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
- const char *hash;
if (num_checks == 0)
{
@@ -47,23 +43,20 @@
for (i = 0; i < num_checks; i++)
{
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] ", i+1);
val->print(PRINT_TEST, check1[i].test_desc, 0);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- if (check1[i].alg == PSA_ALG_SHA_384)
- hash = sha384_hash;
- else if (check1[i].alg == PSA_ALG_SHA_512)
- hash = sha512_hash;
- else
- hash = check1[i].hash;
-
/* Calculate the hash (digest) of a message and compare it with a reference value */
- status = val->crypto_function(VAL_CRYPTO_HASH_COMPARE, check1[i].alg, &check1[i].input,
- check1[i].input_length, hash, check1[i].hash_length);
+ status = val->crypto_function(VAL_CRYPTO_HASH_COMPARE,
+ check1[i].alg,
+ check1[i].input,
+ check1[i].input_length,
+ check1[i].hash,
+ check1[i].hash_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(3));
}
diff --git a/api-tests/dev_apis/crypto/test_c007/test_data.h b/api-tests/dev_apis/crypto/test_c007/test_data.h
index c2a04bc..22ca0b9 100644
--- a/api-tests/dev_apis/crypto/test_c007/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c007/test_data.h
@@ -15,117 +15,156 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[50];
psa_algorithm_t alg;
- char input;
+ const uint8_t *input;
size_t input_length;
- char hash[32];
- size_t hash_length;
+ const uint8_t *hash;
+ const size_t hash_length;
psa_status_t expected_status;
} test_data;
-static const char sha384_hash[] = {
-0x43, 0x72, 0xe3, 0x8a, 0x92, 0xa2, 0x8b, 0x5d, 0x2c, 0x39, 0x1e, 0x62,
-0x45, 0x2a, 0x86, 0xd5, 0x0e, 0x02, 0x67, 0x22, 0x8b, 0xe1, 0x76, 0xc7, 0x7d, 0x24, 0x02, 0xef,
-0xfe, 0x9f, 0xa5, 0x0d, 0xe4, 0x07, 0xbb, 0xb8, 0x51, 0xb3, 0x7d, 0x59, 0x04, 0xab, 0xa2, 0xde,
-0xde, 0x74, 0xda, 0x2a};
-
-static const char sha512_hash[] = {
-0x29, 0x6e, 0x22, 0x67, 0xd7, 0x4c, 0x27, 0x8d, 0xaa, 0xaa, 0x94, 0x0d,
-0x17, 0xb0, 0xcf, 0xb7, 0x4a, 0x50, 0x83, 0xf8, 0xe0, 0x69, 0x72, 0x6d, 0x8c, 0x84, 0x1c, 0xbe,
-0x59, 0x6e, 0x04, 0x31, 0xcb, 0x77, 0x41, 0xa5, 0xb5, 0x0f, 0x71, 0x66, 0x6c, 0xfd, 0x54, 0xba,
-0xcb, 0x7b, 0x00, 0xae, 0xa8, 0x91, 0x49, 0x9c, 0xf4, 0xef, 0x6a, 0x03, 0xc8, 0xa8, 0x3f, 0xe3,
-0x7c, 0x3f, 0x7b, 0xaf};
-
static const test_data check1[] = {
#ifdef ARCH_TEST_MD2
-{"Test psa_hash_compare with MD2 algorithm\n",
- PSA_ALG_MD2, 0xbd, 1,
- {0x8c, 0x9c, 0x17, 0x66, 0x5d, 0x25, 0xb3, 0x5f, 0xc4, 0x13, 0xc4, 0x18, 0x05, 0xc6, 0x79, 0xcf},
- 16, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_compare with MD2 algorithm\n",
+ .alg = PSA_ALG_MD2,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = md2_hash,
+ .hash_length = 16,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD4
-{"Test psa_hash_compare with MD4 algorithm\n",
- PSA_ALG_MD4, 0xbd, 1,
- {0x18, 0xc3, 0x3f, 0x97, 0x29, 0x7e, 0xfe, 0x5f, 0x8a, 0x73, 0x22, 0x58, 0x28, 0x9f, 0xda, 0x25},
- 16, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_compare with MD4 algorithm\n",
+ .alg = PSA_ALG_MD4,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = md4_hash,
+ .hash_length = 16,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD5
-{"Test psa_hash_compare with MD5 algorithm\n",
- PSA_ALG_MD5, 0xbd, 1,
- {0xab, 0xae, 0x57, 0xcb, 0x56, 0x2e, 0xcf, 0x29, 0x5b, 0x4a, 0x37, 0xa7, 0x6e, 0xfe, 0x61, 0xfb},
- 16, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_compare with MD5 algorithm\n",
+ .alg = PSA_ALG_MD5,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = md5_hash,
+ .hash_length = 16,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_RIPEMD160
-{"Test psa_hash_compare with RIPEMD160 algorithm\n",
- PSA_ALG_RIPEMD160, 0xbd, 1,
- {0x50, 0x89, 0x26, 0x5e, 0xe5, 0xd9, 0xaf, 0x75, 0xd1, 0x2d, 0xbf, 0x7e, 0xa2, 0xf2, 0x7d, 0xbd,
- 0xee, 0x43, 0x5b, 0x37},
- 20, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_compare with RIPEMD160 algorithm\n",
+ .alg = PSA_ALG_RIPEMD160,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = ripemd_160_hash,
+ .hash_length = 20,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA1
-{"Test psa_hash_compare with SHA1 algorithm\n",
- PSA_ALG_SHA_1, 0xbd, 1,
- {0x90, 0x34, 0xaa, 0xf4, 0x51, 0x43, 0x99, 0x6a, 0x2b, 0x14, 0x46, 0x5c, 0x35, 0x2a, 0xb0, 0xc6,
- 0xfa, 0x26, 0xb2, 0x21},
- 20, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_compare with SHA1 algorithm\n",
+ .alg = PSA_ALG_SHA_1,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = sha_1_hash,
+ .hash_length = 20,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA224
-{"Test psa_hash_compare with SHA224 algorithm\n",
- PSA_ALG_SHA_224, 0xbd, 1,
- {0xb1, 0xe4, 0x6b, 0xb9, 0xef, 0xe4, 0x5a, 0xf5, 0x54, 0x36, 0x34, 0x49, 0xc6, 0x94, 0x5a, 0x0d,
- 0x61, 0x69, 0xfc, 0x3a, 0x5a, 0x39, 0x6a, 0x56, 0xcb, 0x97, 0xcb, 0x57},
- 28, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_compare with SHA224 algorithm\n",
+ .alg = PSA_ALG_SHA_224,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = sha_224_hash,
+ .hash_length = 28,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA256
-{"Test psa_hash_compare with SHA256 algorithm\n",
- PSA_ALG_SHA_256, 0xbd, 1,
- {0x68, 0x32, 0x57, 0x20, 0xaa, 0xbd, 0x7c, 0x82, 0xf3, 0x0f, 0x55, 0x4b, 0x31, 0x3d, 0x05, 0x70,
- 0xc9, 0x5a, 0xcc, 0xbb, 0x7d, 0xc4, 0xb5, 0xaa, 0xe1, 0x12, 0x04, 0xc0, 0x8f, 0xfe, 0x73, 0x2b},
- 32, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_compare with SHA256 algorithm\n",
+ .alg = PSA_ALG_SHA_256,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = sha_256_hash,
+ .hash_length = 32,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA384
-{"Test psa_hash_compare with SHA384 algorithm\n",
- PSA_ALG_SHA_384, 0xbd, 1, {0}, 48, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_compare with SHA384 algorithm\n",
+ .alg = PSA_ALG_SHA_384,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = sha_384_hash,
+ .hash_length = 48,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA512
-{"Test psa_hash_compare with SHA512 algorithm\n",
- PSA_ALG_SHA_512, 0xbd, 1, {0}, 64, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_compare with SHA512 algorithm\n",
+ .alg = PSA_ALG_SHA_512,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = sha_512_hash,
+ .hash_length = 64,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA256
-{"Test psa_hash_compare with incorrect hash\n",
- PSA_ALG_SHA_256, 0xbd, 1,
- {0x68, 0x32, 0x57, 0x20, 0xab, 0xbd, 0x7c, 0x82, 0xf3, 0x0f, 0x55, 0x4b, 0x31, 0x3d, 0x05, 0x70,
- 0xc9, 0x5a, 0xcc, 0xbb, 0x7d, 0xc4, 0xb5, 0xaa, 0xe1, 0x12, 0x04, 0xc0, 0x8f, 0xfe, 0x73, 0x78},
- 32, PSA_ERROR_INVALID_SIGNATURE,
+{
+ .test_desc = "Test psa_hash_compare with incorrect hash\n",
+ .alg = PSA_ALG_SHA_256,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = sha_256_incorrect_hash,
+ .hash_length = 32,
+ .expected_status = PSA_ERROR_INVALID_SIGNATURE,
},
-{"Test psa_hash_compare with incorrect hash length\n",
- PSA_ALG_SHA_256, 0xbd, 1,
- {0x68, 0x32, 0x57, 0x20, 0xaa, 0xbd, 0x7c, 0x82, 0xf3, 0x0f, 0x55, 0x4b, 0x31, 0x3d, 0x05, 0x70,
- 0xc9, 0x5a, 0xcc, 0xbb, 0x7d, 0xc4, 0xb5, 0xaa, 0xe1, 0x12, 0x04, 0xc0, 0x8f, 0xfe, 0x73, 0x2b},
- 31, PSA_ERROR_INVALID_SIGNATURE,
+{
+ .test_desc = "Test psa_hash_compare with incorrect hash length\n",
+ .alg = PSA_ALG_SHA_256,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input)/sizeof(uint8_t),
+ .hash = sha_256_hash,
+ .hash_length = 31,
+ .expected_status = PSA_ERROR_INVALID_SIGNATURE,
+},
+
+{
+ .test_desc = "Test psa_hash_compare with invalid algorithm\n",
+ .alg = PSA_HASH_ALG_INVALID,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = sha_256_hash,
+ .hash_length = 32,
+ .expected_status = PSA_ERROR_NOT_SUPPORTED,
},
#endif
};
diff --git a/api-tests/dev_apis/crypto/test_c008/test_c008.c b/api-tests/dev_apis/crypto/test_c008/test_c008.c
index 2ee5dd5..5b4a95d 100644
--- a/api-tests/dev_apis/crypto/test_c008/test_c008.c
+++ b/api-tests/dev_apis/crypto/test_c008/test_c008.c
@@ -19,7 +19,6 @@
#include "val_target.h"
#include "test_c008.h"
#include "test_data.h"
-#include "val_crypto.h"
const client_test_t test_c008_crypto_list[] = {
NULL,
@@ -27,12 +26,10 @@
NULL,
};
-static int g_test_count = 1;
-
int32_t psa_key_derivation_setup_test(caller_security_t caller __UNUSED)
{
int32_t i, status;
- int num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
if (num_checks == 0)
@@ -48,7 +45,7 @@
/* Set the key data buffer to the input base on algorithm */
for (i = 0; i < num_checks; i++)
{
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] ", i+1);
val->print(PRINT_TEST, check1[i].test_desc, 0);
/* Setting up the watchdog timer for each check */
diff --git a/api-tests/dev_apis/crypto/test_c008/test_data.h b/api-tests/dev_apis/crypto/test_c008/test_data.h
index f5e356f..9afd6ea 100644
--- a/api-tests/dev_apis/crypto/test_c008/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c008/test_data.h
@@ -15,7 +15,7 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
@@ -24,23 +24,27 @@
} test_data;
static const test_data check1[] = {
-{"Test psa_key_derivation_setup - ECDH + HKDF-SHA-256\n",
- PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_key_derivation_setup - ECDH + HKDF-SHA-256\n",
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_key_derivation_setup - ECDH, unknown KDF\n",
- PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(0)),
- PSA_ERROR_NOT_SUPPORTED
+{
+ .test_desc = "Test psa_key_derivation_setup - ECDH, unknown KDF\n",
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(0)),
+ .expected_status = PSA_ERROR_NOT_SUPPORTED
},
-{"Test psa_key_derivation_setup - bad key derivation algorithm\n",
- PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_HASH_ALG_INVALID),
- PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_key_derivation_setup - bad key derivation algorithm\n",
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_HASH_ALG_INVALID),
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
-{"Test psa_key_derivation_setup - Invalid Algorithm\n",
- PSA_ALG_INVALID,
- PSA_ERROR_INVALID_ARGUMENT,
+{
+ .test_desc = "Test psa_key_derivation_setup - Invalid Algorithm\n",
+ .alg = PSA_ALG_INVALID,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT,
},
};
diff --git a/api-tests/dev_apis/crypto/test_c009/test_c009.c b/api-tests/dev_apis/crypto/test_c009/test_c009.c
index 3f0775b..a2b5177 100644
--- a/api-tests/dev_apis/crypto/test_c009/test_c009.c
+++ b/api-tests/dev_apis/crypto/test_c009/test_c009.c
@@ -19,7 +19,6 @@
#include "val_target.h"
#include "test_c009.h"
#include "test_data.h"
-#include "val_crypto.h"
const client_test_t test_c009_crypto_list[] = {
NULL,
@@ -27,12 +26,10 @@
NULL,
};
-static int g_test_count = 1;
-
int32_t psa_key_derivation_input_bytes_test(caller_security_t caller __UNUSED)
{
int32_t i, status;
- int num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
if (num_checks == 0)
@@ -48,7 +45,7 @@
/* Set the key data buffer to the input base on algorithm */
for (i = 0; i < num_checks; i++)
{
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] ", i+1);
val->print(PRINT_TEST, check1[i].test_desc, 0);
/* Setting up the watchdog timer for each check */
diff --git a/api-tests/dev_apis/crypto/test_c009/test_data.h b/api-tests/dev_apis/crypto/test_c009/test_data.h
index bf8e7b6..4d5de38 100644
--- a/api-tests/dev_apis/crypto/test_c009/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c009/test_data.h
@@ -15,57 +15,69 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
psa_algorithm_t alg;
- uint8_t data[32];
+ const uint8_t *data;
size_t data_length;
psa_key_derivation_step_t step;
psa_status_t expected_status;
} test_data;
static const test_data check1[] = {
-{"Test psa_key_derivation_input_bytes - Step as Info\n",
- PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
- "abcdefghijklmnop", 16,
- PSA_KEY_DERIVATION_INPUT_INFO,
- PSA_SUCCESS,
+{
+ .test_desc = "Test psa_key_derivation_input_bytes - Step as Info\n",
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
+ .data = input_bytes_data,
+ .data_length = INPUT_BYTES_DATA_LEN,
+ .step = PSA_KEY_DERIVATION_INPUT_INFO,
+ .expected_status = PSA_SUCCESS,
},
-{"Test psa_key_derivation_input_bytes - Step as secret\n",
- PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
- "abcdefghijklmnop", 16,
- PSA_KEY_DERIVATION_INPUT_SECRET,
- PSA_ERROR_INVALID_ARGUMENT,
+{
+ .test_desc = "Test psa_key_derivation_input_bytes - Step as secret\n",
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
+ .data = input_bytes_data,
+ .data_length = INPUT_BYTES_DATA_LEN,
+ .step = PSA_KEY_DERIVATION_INPUT_SECRET,
+ .expected_status = PSA_SUCCESS,
},
-{"Test psa_key_derivation_input_bytes - Step as salt\n",
- PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
- "abcdefghijklmnop", 16,
- PSA_KEY_DERIVATION_INPUT_SALT,
- PSA_SUCCESS,
+{
+ .test_desc = "Test psa_key_derivation_input_bytes - Step as salt\n",
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
+ .data = input_bytes_data,
+ .data_length = INPUT_BYTES_DATA_LEN,
+ .step = PSA_KEY_DERIVATION_INPUT_SALT,
+ .expected_status = PSA_SUCCESS,
},
-{"Test psa_key_derivation_input_bytes - Step as label\n",
- PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
- "abcdefghijklmnop", 16,
- PSA_KEY_DERIVATION_INPUT_LABEL,
- PSA_ERROR_INVALID_ARGUMENT,
+{
+ .test_desc = "Test psa_key_derivation_input_bytes - Step as label\n",
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
+ .data = input_bytes_data,
+ .data_length = INPUT_BYTES_DATA_LEN,
+ .step = PSA_KEY_DERIVATION_INPUT_LABEL,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT,
},
-{"Test psa_key_derivation_input_bytes - Step as seed\n",
- PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
- "abcdefghijklmnop", 16,
- PSA_KEY_DERIVATION_INPUT_SEED,
- PSA_ERROR_INVALID_ARGUMENT,
+{
+ .test_desc = "Test psa_key_derivation_input_bytes - Step as seed\n",
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
+ .data = input_bytes_data,
+ .data_length = INPUT_BYTES_DATA_LEN,
+ .step = PSA_KEY_DERIVATION_INPUT_SEED,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT,
},
-{"Test psa_key_derivation_input_bytes - Invalid step\n",
- PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
- "abcdefghijklmnop", 16,
- PSA_KEY_DERIVATION_STEP_INVALID,
- PSA_ERROR_INVALID_ARGUMENT,
+{
+ .test_desc = "Test psa_key_derivation_input_bytes - Invalid step\n",
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
+ .data = input_bytes_data,
+ .data_length = INPUT_BYTES_DATA_LEN,
+ .step = PSA_KEY_DERIVATION_STEP_INVALID,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT,
},
};
diff --git a/api-tests/dev_apis/crypto/test_c010/test_c010.c b/api-tests/dev_apis/crypto/test_c010/test_c010.c
index 68a8701..99fa62a 100644
--- a/api-tests/dev_apis/crypto/test_c010/test_c010.c
+++ b/api-tests/dev_apis/crypto/test_c010/test_c010.c
@@ -19,7 +19,6 @@
#include "val_target.h"
#include "test_c010.h"
#include "test_data.h"
-#include "val_crypto.h"
const client_test_t test_c010_crypto_list[] = {
NULL,
@@ -27,18 +26,16 @@
NULL,
};
-static int g_test_count = 1;
-
int32_t psa_key_attributes_set_get_test(caller_security_t caller __UNUSED)
{
int32_t i, status;
- psa_key_type_t get_key_type;
- psa_key_id_t get_key_id;
- psa_key_lifetime_t get_key_lifetime;
- psa_key_usage_t get_key_usage_flags;
- psa_algorithm_t get_key_algorithm;
- size_t get_key_bits;
- int num_checks = sizeof(check1)/sizeof(check1[0]);
+ psa_key_type_t get_type;
+ psa_key_id_t get_id;
+ psa_key_lifetime_t get_lifetime;
+ psa_key_usage_t get_usage_flags;
+ psa_algorithm_t get_alg;
+ size_t get_bits;
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
if (num_checks == 0)
@@ -54,7 +51,7 @@
/* Set the key data buffer to the input base on algorithm */
for (i = 0; i < num_checks; i++)
{
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] ", i+1);
val->print(PRINT_TEST, check1[i].test_desc, 0);
/* Setting up the watchdog timer for each check */
@@ -62,72 +59,72 @@
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Check if all the attributes are initialized to zero */
- val->crypto_function(VAL_CRYPTO_GET_KEY_TYPE, &attributes, &get_key_type);
- TEST_ASSERT_EQUAL(get_key_type, 0, TEST_CHECKPOINT_NUM(3));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_TYPE, &attributes, &get_type);
+ TEST_ASSERT_EQUAL(get_type, 0, TEST_CHECKPOINT_NUM(3));
- val->crypto_function(VAL_CRYPTO_GET_KEY_ID, &attributes, &get_key_id);
- TEST_ASSERT_EQUAL(get_key_id, 0, TEST_CHECKPOINT_NUM(4));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_ID, &attributes, &get_id);
+ TEST_ASSERT_EQUAL(get_id, 0, TEST_CHECKPOINT_NUM(4));
- val->crypto_function(VAL_CRYPTO_GET_KEY_LIFETIME, &attributes, &get_key_lifetime);
- TEST_ASSERT_EQUAL(get_key_lifetime, 0, TEST_CHECKPOINT_NUM(5));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_LIFETIME, &attributes, &get_lifetime);
+ TEST_ASSERT_EQUAL(get_lifetime, 0, TEST_CHECKPOINT_NUM(5));
- val->crypto_function(VAL_CRYPTO_GET_KEY_USAGE_FLAGS, &attributes, &get_key_usage_flags);
- TEST_ASSERT_EQUAL(get_key_usage_flags, 0, TEST_CHECKPOINT_NUM(6));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_USAGE_FLAGS, &attributes, &get_usage_flags);
+ TEST_ASSERT_EQUAL(get_usage_flags, 0, TEST_CHECKPOINT_NUM(6));
- val->crypto_function(VAL_CRYPTO_GET_KEY_ALGORITHM, &attributes, &get_key_algorithm);
- TEST_ASSERT_EQUAL(get_key_algorithm, 0, TEST_CHECKPOINT_NUM(7));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_ALGORITHM, &attributes, &get_alg);
+ TEST_ASSERT_EQUAL(get_alg, 0, TEST_CHECKPOINT_NUM(7));
- val->crypto_function(VAL_CRYPTO_GET_KEY_BITS, &attributes, &get_key_bits);
- TEST_ASSERT_EQUAL(get_key_bits, 0, TEST_CHECKPOINT_NUM(8));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_BITS, &attributes, &get_bits);
+ TEST_ASSERT_EQUAL(get_bits, 0, TEST_CHECKPOINT_NUM(8));
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_BITS, &attributes, check1[i].attr_bits);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ID, &attributes, check1[i].key_id);
- val->crypto_function(VAL_CRYPTO_SET_KEY_LIFETIME, &attributes, check1[i].key_lifetime);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].key_alg);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_BITS, &attributes, check1[i].bits);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage_flags);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ID, &attributes, check1[i].id);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_LIFETIME, &attributes, check1[i].lifetime);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].alg);
/* Check if all the attributes are as per the input */
- val->crypto_function(VAL_CRYPTO_GET_KEY_TYPE, &attributes, &get_key_type);
- TEST_ASSERT_EQUAL(get_key_type, check1[i].key_type, TEST_CHECKPOINT_NUM(9));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_TYPE, &attributes, &get_type);
+ TEST_ASSERT_EQUAL(get_type, check1[i].type, TEST_CHECKPOINT_NUM(9));
- val->crypto_function(VAL_CRYPTO_GET_KEY_ID, &attributes, &get_key_id);
- TEST_ASSERT_EQUAL(get_key_id, check1[i].key_id, TEST_CHECKPOINT_NUM(10));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_ID, &attributes, &get_id);
+ TEST_ASSERT_EQUAL(get_id, check1[i].id, TEST_CHECKPOINT_NUM(10));
- val->crypto_function(VAL_CRYPTO_GET_KEY_LIFETIME, &attributes, &get_key_lifetime);
- TEST_ASSERT_EQUAL(get_key_lifetime, check1[i].key_lifetime, TEST_CHECKPOINT_NUM(11));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_LIFETIME, &attributes, &get_lifetime);
+ TEST_ASSERT_EQUAL(get_lifetime, check1[i].lifetime, TEST_CHECKPOINT_NUM(11));
- val->crypto_function(VAL_CRYPTO_GET_KEY_USAGE_FLAGS, &attributes, &get_key_usage_flags);
- TEST_ASSERT_EQUAL(get_key_usage_flags, check1[i].usage, TEST_CHECKPOINT_NUM(12));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_USAGE_FLAGS, &attributes, &get_usage_flags);
+ TEST_ASSERT_EQUAL(get_usage_flags, check1[i].usage_flags, TEST_CHECKPOINT_NUM(12));
- val->crypto_function(VAL_CRYPTO_GET_KEY_ALGORITHM, &attributes, &get_key_algorithm);
- TEST_ASSERT_EQUAL(get_key_algorithm, check1[i].key_alg, TEST_CHECKPOINT_NUM(13));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_ALGORITHM, &attributes, &get_alg);
+ TEST_ASSERT_EQUAL(get_alg, check1[i].alg, TEST_CHECKPOINT_NUM(13));
- val->crypto_function(VAL_CRYPTO_GET_KEY_BITS, &attributes, &get_key_bits);
- TEST_ASSERT_EQUAL(get_key_bits, check1[i].attr_bits, TEST_CHECKPOINT_NUM(14));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_BITS, &attributes, &get_bits);
+ TEST_ASSERT_EQUAL(get_bits, check1[i].bits, TEST_CHECKPOINT_NUM(14));
/* Reset the attributes */
val->crypto_function(VAL_CRYPTO_RESET_KEY_ATTRIBUTES, &attributes);
/* Check if all the attributes are erased */
- val->crypto_function(VAL_CRYPTO_GET_KEY_TYPE, &attributes, &get_key_type);
- TEST_ASSERT_EQUAL(get_key_type, 0, TEST_CHECKPOINT_NUM(15));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_TYPE, &attributes, &get_type);
+ TEST_ASSERT_EQUAL(get_type, 0, TEST_CHECKPOINT_NUM(15));
- val->crypto_function(VAL_CRYPTO_GET_KEY_ID, &attributes, &get_key_id);
- TEST_ASSERT_EQUAL(get_key_id, 0, TEST_CHECKPOINT_NUM(16));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_ID, &attributes, &get_id);
+ TEST_ASSERT_EQUAL(get_id, 0, TEST_CHECKPOINT_NUM(16));
- val->crypto_function(VAL_CRYPTO_GET_KEY_LIFETIME, &attributes, &get_key_lifetime);
- TEST_ASSERT_EQUAL(get_key_lifetime, 0, TEST_CHECKPOINT_NUM(17));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_LIFETIME, &attributes, &get_lifetime);
+ TEST_ASSERT_EQUAL(get_lifetime, 0, TEST_CHECKPOINT_NUM(17));
- val->crypto_function(VAL_CRYPTO_GET_KEY_USAGE_FLAGS, &attributes, &get_key_usage_flags);
- TEST_ASSERT_EQUAL(get_key_usage_flags, 0, TEST_CHECKPOINT_NUM(18));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_USAGE_FLAGS, &attributes, &get_usage_flags);
+ TEST_ASSERT_EQUAL(get_usage_flags, 0, TEST_CHECKPOINT_NUM(18));
- val->crypto_function(VAL_CRYPTO_GET_KEY_ALGORITHM, &attributes, &get_key_algorithm);
- TEST_ASSERT_EQUAL(get_key_algorithm, 0, TEST_CHECKPOINT_NUM(19));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_ALGORITHM, &attributes, &get_alg);
+ TEST_ASSERT_EQUAL(get_alg, 0, TEST_CHECKPOINT_NUM(19));
- val->crypto_function(VAL_CRYPTO_GET_KEY_BITS, &attributes, &get_key_bits);
- TEST_ASSERT_EQUAL(get_key_bits, 0, TEST_CHECKPOINT_NUM(20));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_BITS, &attributes, &get_bits);
+ TEST_ASSERT_EQUAL(get_bits, 0, TEST_CHECKPOINT_NUM(20));
}
return VAL_STATUS_SUCCESS;
diff --git a/api-tests/dev_apis/crypto/test_c010/test_data.h b/api-tests/dev_apis/crypto/test_c010/test_data.h
index c8ece76..4b88665 100644
--- a/api-tests/dev_apis/crypto/test_c010/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c010/test_data.h
@@ -15,21 +15,26 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- psa_key_type_t key_type;
- size_t attr_bits;
- psa_key_usage_t usage;
- psa_algorithm_t key_alg;
- psa_key_id_t key_id;
- psa_key_lifetime_t key_lifetime;
+ psa_key_type_t type;
+ size_t bits;
+ psa_key_usage_t usage_flags;
+ psa_algorithm_t alg;
+ psa_key_id_t id;
+ psa_key_lifetime_t lifetime;
} test_data;
static const test_data check1[] = {
-{"Test set/get key attributes\n", PSA_KEY_TYPE_AES, BYTES_TO_BITS(AES_16B_KEY_SIZE),
- PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT, PSA_ALG_CCM, 0x1234,
- PSA_KEY_LIFETIME_PERSISTENT
+{
+ .test_desc = "Test set/get key attributes\n",
+ .type = PSA_KEY_TYPE_AES,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CCM,
+ .id = 0x1234,
+ .lifetime = PSA_KEY_LIFETIME_PERSISTENT
},
};
diff --git a/api-tests/dev_apis/crypto/test_c011/test_c011.c b/api-tests/dev_apis/crypto/test_c011/test_c011.c
index 9362046..d0ae92b 100644
--- a/api-tests/dev_apis/crypto/test_c011/test_c011.c
+++ b/api-tests/dev_apis/crypto/test_c011/test_c011.c
@@ -19,7 +19,6 @@
#include "val_target.h"
#include "test_c011.h"
#include "test_data.h"
-#include "val_crypto.h"
const client_test_t test_c011_crypto_list[] = {
NULL,
@@ -27,11 +26,9 @@
NULL,
};
-static int g_test_count = 1;
-
int32_t psa_hash_setup_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
psa_hash_operation_t operation;
@@ -47,10 +44,8 @@
for (i = 0; i < num_checks; i++)
{
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] ", i+1);
val->print(PRINT_TEST, check1[i].test_desc, 0);
-
- /* Initialize the structure */
memset(&operation, 0, sizeof(operation));
/* Setting up the watchdog timer for each check */
diff --git a/api-tests/dev_apis/crypto/test_c011/test_data.h b/api-tests/dev_apis/crypto/test_c011/test_data.h
index b2300c9..f3d2abc 100644
--- a/api-tests/dev_apis/crypto/test_c011/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c011/test_data.h
@@ -15,7 +15,7 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[50];
@@ -25,105 +25,141 @@
static const test_data check1[] = {
#ifdef ARCH_TEST_MD2
-{"Test psa_hash_setup with MD2 algorithm\n",
- PSA_ALG_MD2, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_setup with MD2 algorithm\n",
+ .alg = PSA_ALG_MD2,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD4
-{"Test psa_hash_setup with MD4 algorithm\n",
- PSA_ALG_MD4, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_setup with MD4 algorithm\n",
+ .alg = PSA_ALG_MD4,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD5
-{"Test psa_hash_setup with MD5 algorithm\n",
- PSA_ALG_MD5, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_setup with MD5 algorithm\n",
+ .alg = PSA_ALG_MD5,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_RIPEMD160
-{"Test psa_hash_setup with RIPEMD160 algorithm\n",
- PSA_ALG_RIPEMD160, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_setup with RIPEMD160 algorithm\n",
+ .alg = PSA_ALG_RIPEMD160,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA1
-{"Test psa_hash_setup with SHA1 algorithm\n",
- PSA_ALG_SHA_1, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_setup with SHA1 algorithm\n",
+ .alg = PSA_ALG_SHA_1,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA224
-{"Test psa_hash_setup with SHA224 algorithm\n",
- PSA_ALG_SHA_224, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_setup with SHA224 algorithm\n",
+ .alg = PSA_ALG_SHA_224,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA256
-{"Test psa_hash_setup with SHA256 algorithm\n",
- PSA_ALG_SHA_256, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_setup with SHA256 algorithm\n",
+ .alg = PSA_ALG_SHA_256,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA384
-{"Test psa_hash_setup with SHA384 algorithm\n",
- PSA_ALG_SHA_384, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_setup with SHA384 algorithm\n",
+ .alg = PSA_ALG_SHA_384,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA512
-{"Test psa_hash_setup with SHA512 algorithm\n",
- PSA_ALG_SHA_512, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_setup with SHA512 algorithm\n",
+ .alg = PSA_ALG_SHA_512,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA512_224
-{"Test psa_hash_setup with SHA512_224 algorithm\n",
- PSA_ALG_SHA_512_224, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_setup with SHA512_224 algorithm\n",
+ .alg = PSA_ALG_SHA_512_224,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA512_256
-{"Test psa_hash_setup with SHA512_256 algorithm\n",
- PSA_ALG_SHA_512_256, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_setup with SHA512_256 algorithm\n",
+ .alg = PSA_ALG_SHA_512_256,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA3_224
-{"Test psa_hash_setup with SHA3_224 algorithm\n",
- PSA_ALG_SHA3_224, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_setup with SHA3_224 algorithm\n",
+ .alg = PSA_ALG_SHA3_224,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA3_256
-{"Test psa_hash_setup with SHA3_256 algorithm\n",
- PSA_ALG_SHA3_256, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_setup with SHA3_256 algorithm\n",
+ .alg = PSA_ALG_SHA3_256,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA3_384
-{"Test psa_hash_setup with SHA3_384 algorithm\n",
- PSA_ALG_SHA3_384, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_setup with SHA3_384 algorithm\n",
+ .alg = PSA_ALG_SHA3_384,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA3_512
-{"Test psa_hash_setup with SHA3_512 algorithm\n",
- PSA_ALG_SHA3_512, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_setup with SHA3_512 algorithm\n",
+ .alg = PSA_ALG_SHA3_512,
+ .expected_status = PSA_SUCCESS,
},
#endif
-{"Test psa_hash_setup with Invalid hash algorithm\n",
- PSA_HASH_ALG_INVALID, PSA_ERROR_NOT_SUPPORTED,
+{
+ .test_desc = "Test psa_hash_setup with Invalid hash algorithm\n",
+ .alg = PSA_HASH_ALG_INVALID,
+ .expected_status = PSA_ERROR_NOT_SUPPORTED,
},
-{"Test psa_hash_setup with Invalid algorithm\n",
- PSA_ALG_INVALID, PSA_ERROR_INVALID_ARGUMENT,
+{
+ .test_desc = "Test psa_hash_setup with Invalid algorithm\n",
+ .alg = PSA_ALG_INVALID,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT,
},
-{"Test psa_hash_setup with CTR algorithm\n",
- PSA_ALG_CTR, PSA_ERROR_INVALID_ARGUMENT,
+{
+ .test_desc = "Test psa_hash_setup with CTR algorithm\n",
+ .alg = PSA_ALG_CTR,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT,
},
};
diff --git a/api-tests/dev_apis/crypto/test_c012/test_c012.c b/api-tests/dev_apis/crypto/test_c012/test_c012.c
index 8ddcf67..742bd63 100644
--- a/api-tests/dev_apis/crypto/test_c012/test_c012.c
+++ b/api-tests/dev_apis/crypto/test_c012/test_c012.c
@@ -19,7 +19,6 @@
#include "val_target.h"
#include "test_c012.h"
#include "test_data.h"
-#include "val_crypto.h"
const client_test_t test_c012_crypto_list[] = {
NULL,
@@ -29,11 +28,12 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
+static int32_t valid_test_input_index = -1;
int32_t psa_hash_update_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
psa_hash_operation_t operation;
@@ -51,8 +51,6 @@
{
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, check1[i].test_desc, 0);
-
- /* Initialize the hash structure */
memset(&operation, 0, sizeof(operation));
/* Setting up the watchdog timer for each check */
@@ -64,13 +62,18 @@
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Add a message fragment to a multipart hash operation */
- status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE, &operation,
- check1[i].input, check1[i].input_length);
+ status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE,
+ &operation,
+ check1[i].input,
+ check1[i].input_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(4));
/*Abort the hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &operation);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
+
+ if (valid_test_input_index < 0)
+ valid_test_input_index = i;
}
return VAL_STATUS_SUCCESS;
@@ -78,11 +81,12 @@
int32_t psa_hash_update_invalid_handle(caller_security_t caller __UNUSED)
{
- psa_hash_operation_t operation;
- uint8_t input[] = "Hello World";
- size_t input_length = sizeof(input);
+ psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
int32_t status;
+ if (valid_test_input_index < 0)
+ return RESULT_SKIP(VAL_STATUS_NO_TESTS);
+
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
@@ -90,15 +94,15 @@
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, "Test psa_hash_update without hash setup\n", 0);
- /* Initialize the hash structure */
- memset(&operation, 0, sizeof(operation));
-
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Add a message fragment to a multipart hash operation */
- status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE, &operation, input, input_length);
+ status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE,
+ &operation,
+ check1[valid_test_input_index].input,
+ check1[valid_test_input_index].input_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(3));
/*Abort the hash operation */
@@ -110,44 +114,48 @@
int32_t psa_hash_update_with_completed_handle(caller_security_t caller __UNUSED)
{
- psa_hash_operation_t operation;
- uint8_t input[] = {0xbd};
- size_t input_length = sizeof(input);
- psa_algorithm_t alg = PSA_ALG_SHA_256;
- uint8_t hash[] = {0x68, 0x32, 0x57, 0x20, 0xAA, 0xBD, 0x7C, 0x82, 0xF3, 0x0F,
- 0x55, 0x4B, 0x31, 0x3D, 0x05, 0x70, 0xC9, 0x5A, 0xCC, 0xBB,
- 0x7D, 0xC4, 0xB5, 0xAA, 0xE1, 0x12, 0x04, 0xC0, 0x8F, 0xFE,
- 0x73, 0x2B};
- size_t hash_length = sizeof(hash);
+ psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
int32_t status;
+ if (valid_test_input_index < 0)
+ return RESULT_SKIP(VAL_STATUS_NO_TESTS);
+
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, "Test psa_hash_update with completed opertaion handle \n", 0);
- memset(&operation, 0, sizeof(operation));
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Start a multipart hash operation */
- status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &operation, alg);
+ status = val->crypto_function(VAL_CRYPTO_HASH_SETUP,
+ &operation,
+ check1[valid_test_input_index].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Add a message fragment to a multipart hash operation */
- status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE, &operation,
- input, input_length);
+ status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE,
+ &operation,
+ check1[valid_test_input_index].input,
+ check1[valid_test_input_index].input_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Finish the calculation of the hash of a message and compare it with an expected value*/
- status = val->crypto_function(VAL_CRYPTO_HASH_VERIFY, &operation, hash, hash_length);
+ status = val->crypto_function(VAL_CRYPTO_HASH_VERIFY,
+ &operation,
+ check1[valid_test_input_index].hash,
+ check1[valid_test_input_index].hash_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Add a message fragment to a multipart hash operation */
- status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE, &operation, input, input_length);
+ status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE,
+ &operation,
+ check1[valid_test_input_index].input,
+ check1[valid_test_input_index].input_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(6));
/*Abort the hash operation */
diff --git a/api-tests/dev_apis/crypto/test_c012/test_data.h b/api-tests/dev_apis/crypto/test_c012/test_data.h
index fdbef81..928b91b 100644
--- a/api-tests/dev_apis/crypto/test_c012/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c012/test_data.h
@@ -15,68 +15,124 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[50];
psa_algorithm_t alg;
- char input[15];
+ const uint8_t *input;
size_t input_length;
+ const uint8_t *hash;
+ size_t hash_length;
psa_status_t expected_status;
} test_data;
static const test_data check1[] = {
#ifdef ARCH_TEST_MD2
-{"Test psa_hash_update with MD2 algorithm\n",
- PSA_ALG_MD2, "Hello World", 11, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_update with MD2 algorithm\n",
+ .alg = PSA_ALG_MD2,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = md2_hash,
+ .hash_length = 16,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD4
-{"Test psa_hash_update with MD4 algorithm\n",
- PSA_ALG_MD4, "Hello World", 11, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_update with MD4 algorithm\n",
+ .alg = PSA_ALG_MD4,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = md4_hash,
+ .hash_length = 16,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD5
-{"Test psa_hash_update with MD5 algorithm\n",
- PSA_ALG_MD5, "Hello World", 11, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_update with MD5 algorithm\n",
+ .alg = PSA_ALG_MD5,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = md5_hash,
+ .hash_length = 16,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_RIPEMD160
-{"Test psa_hash_update with RIPEMD160 algorithm\n",
- PSA_ALG_RIPEMD160, "Hello World", 11, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_update with RIPEMD160 algorithm\n",
+ .alg = PSA_ALG_RIPEMD160,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = ripemd_160_hash,
+ .hash_length = 20,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA1
-{"Test psa_hash_update with SHA1 algorithm\n",
- PSA_ALG_SHA_1, "Hello World", 11, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_update with SHA1 algorithm\n",
+ .alg = PSA_ALG_SHA_1,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = sha_1_hash,
+ .hash_length = 20,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA224
-{"Test psa_hash_update with SHA224 algorithm\n",
- PSA_ALG_SHA_224, "Hello World", 11, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_update with SHA224 algorithm\n",
+ .alg = PSA_ALG_SHA_224,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = sha_224_hash,
+ .hash_length = 28,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA256
-{"Test psa_hash_update with SHA256 algorithm\n",
- PSA_ALG_SHA_256, "Hello World", 11, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_update with SHA256 algorithm\n",
+ .alg = PSA_ALG_SHA_256,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = sha_256_hash,
+ .hash_length = 32,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA384
-{"Test psa_hash_update with SHA384 algorithm\n",
- PSA_ALG_SHA_384, "Hello World", 11, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_update with SHA384 algorithm\n",
+ .alg = PSA_ALG_SHA_384,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = sha_384_hash,
+ .hash_length = 48,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA512
-{"Test psa_hash_update with SHA512 algorithm\n",
- PSA_ALG_SHA_512, "Hello World", 11, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_update with SHA512 algorithm\n",
+ .alg = PSA_ALG_SHA_512,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = sha_512_hash,
+ .hash_length = 64,
+ .expected_status = PSA_SUCCESS,
},
#endif
};
diff --git a/api-tests/dev_apis/crypto/test_c013/test_c013.c b/api-tests/dev_apis/crypto/test_c013/test_c013.c
index 97f0a40..08a1d08 100644
--- a/api-tests/dev_apis/crypto/test_c013/test_c013.c
+++ b/api-tests/dev_apis/crypto/test_c013/test_c013.c
@@ -19,7 +19,6 @@
#include "val_target.h"
#include "test_c013.h"
#include "test_data.h"
-#include "val_crypto.h"
const client_test_t test_c013_crypto_list[] = {
NULL,
@@ -28,14 +27,14 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
+static int32_t valid_test_input_index = -1;
int32_t psa_hash_verify_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
psa_hash_operation_t operation;
- const char *hash;
if (num_checks == 0)
{
@@ -57,30 +56,26 @@
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- if (check1[i].alg == PSA_ALG_SHA_384)
- hash = sha384_hash;
- else if (check1[i].alg == PSA_ALG_SHA_512)
- hash = sha512_hash;
- else
- hash = check1[i].hash;
-
/* Start a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &operation, check1[i].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Add a message fragment to a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE, &operation,
- &check1[i].input, check1[i].input_length);
+ check1[i].input, check1[i].input_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Finish the calculation of the hash of a message and compare it with an expected value*/
- status = val->crypto_function(VAL_CRYPTO_HASH_VERIFY, &operation, hash,
+ status = val->crypto_function(VAL_CRYPTO_HASH_VERIFY, &operation, check1[i].hash,
check1[i].hash_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(5));
/*Abort the hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &operation);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
+
+ if (valid_test_input_index < 0)
+ valid_test_input_index = i;
}
return VAL_STATUS_SUCCESS;
@@ -88,49 +83,51 @@
int32_t psa_hash_verify_inactive_operation_handle(caller_security_t caller __UNUSED)
{
- psa_hash_operation_t operation, invalid_operation;
- char input = 0xbd;
- size_t input_length = 1;
- psa_algorithm_t alg = PSA_ALG_SHA_256;
- size_t hash_length = PSA_HASH_SIZE(alg);
- char hash[] = {0x68, 0x32, 0x57, 0x20, 0xaa, 0xbd, 0x7c, 0x82, 0xf3, 0x0f,
- 0x55, 0x4b, 0x31, 0x3d, 0x05, 0x70, 0xc9, 0x5a, 0xcc, 0xbb,
- 0x7d, 0xc4, 0xb5, 0xaa, 0xe1, 0x12, 0x04, 0xc0, 0x8f, 0xfe,
- 0x73, 0x2b};
+ psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
+ psa_hash_operation_t invalid_operation = PSA_HASH_OPERATION_INIT;
int32_t status;
+ if (valid_test_input_index < 0)
+ return RESULT_SKIP(VAL_STATUS_NO_TESTS);
+
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, "test psa_hash_verify with inactive & invalid operation handle\n", 0);
- memset(&operation, 0, sizeof(operation));
- memset(&invalid_operation, 0, sizeof(invalid_operation));
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Start a multipart hash operation */
- status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &operation, alg);
+ status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &operation,
+ check1[valid_test_input_index].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Add a message fragment to a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE, &operation,
- &input, input_length);
+ check1[valid_test_input_index].input,
+ check1[valid_test_input_index]. input_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Finish the calculation of the hash of a message and compare it with an expected value*/
- status = val->crypto_function(VAL_CRYPTO_HASH_VERIFY, &operation, hash, hash_length);
+ status = val->crypto_function(VAL_CRYPTO_HASH_VERIFY, &operation,
+ check1[valid_test_input_index].hash,
+ check1[valid_test_input_index].hash_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Retry the operation with completed operation handle */
- status = val->crypto_function(VAL_CRYPTO_HASH_VERIFY, &operation, hash, hash_length);
+ status = val->crypto_function(VAL_CRYPTO_HASH_VERIFY, &operation,
+ check1[valid_test_input_index].hash,
+ check1[valid_test_input_index].hash_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(6));
/* Retry the operation with invalid operation handle */
- status = val->crypto_function(VAL_CRYPTO_HASH_VERIFY, &invalid_operation, hash, hash_length);
+ status = val->crypto_function(VAL_CRYPTO_HASH_VERIFY, &invalid_operation,
+ check1[valid_test_input_index].hash,
+ check1[valid_test_input_index].hash_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(7));
/*Abort the hash operation */
diff --git a/api-tests/dev_apis/crypto/test_c013/test_data.h b/api-tests/dev_apis/crypto/test_c013/test_data.h
index 463e4e3..4df184f 100644
--- a/api-tests/dev_apis/crypto/test_c013/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c013/test_data.h
@@ -15,117 +15,146 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[50];
psa_algorithm_t alg;
- char input;
+ const uint8_t *input;
size_t input_length;
- char hash[32];
+ const uint8_t *hash;
size_t hash_length;
psa_status_t expected_status;
} test_data;
-static const char sha384_hash[] = {
-0x43, 0x72, 0xe3, 0x8a, 0x92, 0xa2, 0x8b, 0x5d, 0x2c, 0x39, 0x1e, 0x62,
-0x45, 0x2a, 0x86, 0xd5, 0x0e, 0x02, 0x67, 0x22, 0x8b, 0xe1, 0x76, 0xc7, 0x7d, 0x24, 0x02, 0xef,
-0xfe, 0x9f, 0xa5, 0x0d, 0xe4, 0x07, 0xbb, 0xb8, 0x51, 0xb3, 0x7d, 0x59, 0x04, 0xab, 0xa2, 0xde,
-0xde, 0x74, 0xda, 0x2a};
-
-static const char sha512_hash[] = {
-0x29, 0x6e, 0x22, 0x67, 0xd7, 0x4c, 0x27, 0x8d, 0xaa, 0xaa, 0x94, 0x0d,
-0x17, 0xb0, 0xcf, 0xb7, 0x4a, 0x50, 0x83, 0xf8, 0xe0, 0x69, 0x72, 0x6d, 0x8c, 0x84, 0x1c, 0xbe,
-0x59, 0x6e, 0x04, 0x31, 0xcb, 0x77, 0x41, 0xa5, 0xb5, 0x0f, 0x71, 0x66, 0x6c, 0xfd, 0x54, 0xba,
-0xcb, 0x7b, 0x00, 0xae, 0xa8, 0x91, 0x49, 0x9c, 0xf4, 0xef, 0x6a, 0x03, 0xc8, 0xa8, 0x3f, 0xe3,
-0x7c, 0x3f, 0x7b, 0xaf};
-
static const test_data check1[] = {
#ifdef ARCH_TEST_MD2
-{"Test psa_hash_verify with MD2 algorithm\n",
- PSA_ALG_MD2, 0xbd, 1,
- {0x8c, 0x9c, 0x17, 0x66, 0x5d, 0x25, 0xb3, 0x5f, 0xc4, 0x13, 0xc4, 0x18, 0x05, 0xc6, 0x79, 0xcf},
- 16, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_verify with MD2 algorithm\n",
+ .alg = PSA_ALG_MD2,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = md2_hash,
+ .hash_length = 16,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD4
-{"Test psa_hash_verify with MD4 algorithm\n",
- PSA_ALG_MD4, 0xbd, 1,
- {0x18, 0xc3, 0x3f, 0x97, 0x29, 0x7e, 0xfe, 0x5f, 0x8a, 0x73, 0x22, 0x58, 0x28, 0x9f, 0xda, 0x25},
- 16, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_verify with MD4 algorithm\n",
+ .alg = PSA_ALG_MD4,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = md4_hash,
+ .hash_length = 16,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD5
-{"Test psa_hash_verify with MD5 algorithm\n",
- PSA_ALG_MD5, 0xbd, 1,
- {0xab, 0xae, 0x57, 0xcb, 0x56, 0x2e, 0xcf, 0x29, 0x5b, 0x4a, 0x37, 0xa7, 0x6e, 0xfe, 0x61, 0xfb},
- 16, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_verify with MD5 algorithm\n",
+ .alg = PSA_ALG_MD5,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = md5_hash,
+ .hash_length = 16,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_RIPEMD160
-{"Test psa_hash_verify with RIPEMD160 algorithm\n",
- PSA_ALG_RIPEMD160, 0xbd, 1,
- {0x50, 0x89, 0x26, 0x5e, 0xe5, 0xd9, 0xaf, 0x75, 0xd1, 0x2d, 0xbf, 0x7e, 0xa2, 0xf2, 0x7d, 0xbd,
- 0xee, 0x43, 0x5b, 0x37},
- 20, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_verify with RIPEMD160 algorithm\n",
+ .alg = PSA_ALG_RIPEMD160,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = ripemd_160_hash,
+ .hash_length = 20,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA1
-{"Test psa_hash_verify with SHA1 algorithm\n",
- PSA_ALG_SHA_1, 0xbd, 1,
- {0x90, 0x34, 0xaa, 0xf4, 0x51, 0x43, 0x99, 0x6a, 0x2b, 0x14, 0x46, 0x5c, 0x35, 0x2a, 0xb0, 0xc6,
- 0xfa, 0x26, 0xb2, 0x21},
- 20, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_verify with SHA1 algorithm\n",
+ .alg = PSA_ALG_SHA_1,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = sha_1_hash,
+ .hash_length = 20,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA224
-{"Test psa_hash_verify with SHA224 algorithm\n",
- PSA_ALG_SHA_224, 0xbd, 1,
- {0xb1, 0xe4, 0x6b, 0xb9, 0xef, 0xe4, 0x5a, 0xf5, 0x54, 0x36, 0x34, 0x49, 0xc6, 0x94, 0x5a, 0x0d,
- 0x61, 0x69, 0xfc, 0x3a, 0x5a, 0x39, 0x6a, 0x56, 0xcb, 0x97, 0xcb, 0x57},
- 28, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_verify with SHA224 algorithm\n",
+ .alg = PSA_ALG_SHA_224,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = sha_224_hash,
+ .hash_length = 28,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA256
-{"Test psa_hash_verify with SHA256 algorithm\n",
- PSA_ALG_SHA_256, 0xbd, 1,
- {0x68, 0x32, 0x57, 0x20, 0xaa, 0xbd, 0x7c, 0x82, 0xf3, 0x0f, 0x55, 0x4b, 0x31, 0x3d, 0x05, 0x70,
- 0xc9, 0x5a, 0xcc, 0xbb, 0x7d, 0xc4, 0xb5, 0xaa, 0xe1, 0x12, 0x04, 0xc0, 0x8f, 0xfe, 0x73, 0x2b},
- 32, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_verify with SHA256 algorithm\n",
+ .alg = PSA_ALG_SHA_256,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = sha_256_hash,
+ .hash_length = 32,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA384
-{"Test psa_hash_verify with SHA384 algorithm\n",
- PSA_ALG_SHA_384, 0xbd, 1, {0}, 48, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_verify with SHA384 algorithm\n",
+ .alg = PSA_ALG_SHA_384,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = sha_384_hash,
+ .hash_length = 48,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA512
-{"Test psa_hash_verify with SHA512 algorithm\n",
- PSA_ALG_SHA_512, 0xbd, 1, {0}, 64, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_verify with SHA512 algorithm\n",
+ .alg = PSA_ALG_SHA_512,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = sha_512_hash,
+ .hash_length = 64,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA256
-{"Test psa_hash_verify with incorrect expected hash\n",
- PSA_ALG_SHA_256, 0xbd, 1,
- {0x68, 0x32, 0x57, 0x20, 0xab, 0xbd, 0x7c, 0x82, 0xf3, 0x0f, 0x55, 0x4b, 0x31, 0x3d, 0x05, 0x70,
- 0xc9, 0x5a, 0xcc, 0xbb, 0x7d, 0xc4, 0xb5, 0xaa, 0xe1, 0x12, 0x04, 0xc0, 0x8f, 0xfe, 0x73, 0x78},
- 32, PSA_ERROR_INVALID_SIGNATURE,
+{
+ .test_desc = "Test psa_hash_verify with incorrect expected hash\n",
+ .alg = PSA_ALG_SHA_256,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = sha_256_incorrect_hash,
+ .hash_length = 32,
+ .expected_status = PSA_ERROR_INVALID_SIGNATURE,
},
-{"Test psa_hash_verify with incorrect hash length\n",
- PSA_ALG_SHA_256, 0xbd, 1,
- {0x68, 0x32, 0x57, 0x20, 0xaa, 0xbd, 0x7c, 0x82, 0xf3, 0x0f, 0x55, 0x4b, 0x31, 0x3d, 0x05, 0x70,
- 0xc9, 0x5a, 0xcc, 0xbb, 0x7d, 0xc4, 0xb5, 0xaa, 0xe1, 0x12, 0x04, 0xc0, 0x8f, 0xfe, 0x73, 0x2b},
- 31, PSA_ERROR_INVALID_SIGNATURE,
+{
+ .test_desc = "Test psa_hash_verify with incorrect hash length\n",
+ .alg = PSA_ALG_SHA_256,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = sha_256_hash,
+ .hash_length = 31,
+ .expected_status = PSA_ERROR_INVALID_SIGNATURE,
},
#endif
};
diff --git a/api-tests/dev_apis/crypto/test_c014/test_c014.c b/api-tests/dev_apis/crypto/test_c014/test_c014.c
index 73f8348..f796404 100644
--- a/api-tests/dev_apis/crypto/test_c014/test_c014.c
+++ b/api-tests/dev_apis/crypto/test_c014/test_c014.c
@@ -19,26 +19,23 @@
#include "val_target.h"
#include "test_c014.h"
#include "test_data.h"
-#include "val_crypto.h"
const client_test_t test_c014_crypto_list[] = {
NULL,
psa_hash_finish_test,
psa_hash_finish_inactive_operation_handle,
- psa_hash_finish_invalid_hash_buffer_size,
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
+static int32_t valid_test_input_index = -1;
int32_t psa_hash_finish_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
psa_hash_operation_t operation;
- const char *expected_hash;
- char hash[HASH_64B];
- size_t hash_length, hash_size = sizeof(hash);
+ size_t expected_hash_length;
if (num_checks == 0)
{
@@ -60,25 +57,18 @@
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- if (check1[i].alg == PSA_ALG_SHA_384)
- expected_hash = sha384_hash;
- else if (check1[i].alg == PSA_ALG_SHA_512)
- expected_hash = sha512_hash;
- else
- expected_hash = check1[i].hash;
-
/* Start a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &operation, check1[i].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Add a message fragment to a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE, &operation,
- &check1[i].input, check1[i].input_length);
+ check1[i].input, check1[i].input_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Finish the calculation of the hash of a message */
- status = val->crypto_function(VAL_CRYPTO_HASH_FINISH, &operation, hash, hash_size,
- &hash_length);
+ status = val->crypto_function(VAL_CRYPTO_HASH_FINISH, &operation, check1[i].expected_hash,
+ check1[i].hash_size, &expected_hash_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(5));
if (check1[i].expected_status != PSA_SUCCESS)
@@ -86,12 +76,16 @@
continue;
}
- TEST_ASSERT_EQUAL(hash_length, PSA_HASH_SIZE(check1[i].alg), TEST_CHECKPOINT_NUM(6));
- TEST_ASSERT_MEMCMP(hash, expected_hash, hash_length, TEST_CHECKPOINT_NUM(7));
+ TEST_ASSERT_EQUAL(expected_hash_length, check1[i].hash_size, TEST_CHECKPOINT_NUM(6));
+ TEST_ASSERT_MEMCMP(check1[i].expected_hash, check1[i].verify_hash,
+ expected_hash_length, TEST_CHECKPOINT_NUM(7));
/*Abort the hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &operation);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(8));
+
+ if (valid_test_input_index < 0)
+ valid_test_input_index = i;
}
return VAL_STATUS_SUCCESS;
@@ -99,43 +93,50 @@
int32_t psa_hash_finish_inactive_operation_handle(caller_security_t caller __UNUSED)
{
- psa_hash_operation_t operation;
- char input = 0xbd;
- size_t input_length = 1;
- psa_algorithm_t alg = PSA_ALG_SHA_256;
- char hash[HASH_64B];
- size_t hash_length, hash_size = sizeof(hash);
+ psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
+ size_t expected_hash_length;
int32_t status;
+ if (valid_test_input_index < 0)
+ return RESULT_SKIP(VAL_STATUS_NO_TESTS);
+
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, "test psa_hash_finish with inactive operation handle\n", 0);
- memset(&operation, 0, sizeof(operation));
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Start a multipart hash operation */
- status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &operation, alg);
+ status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &operation,
+ check1[valid_test_input_index].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Add a message fragment to a multipart hash operation */
- status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE, &operation,
- &input, input_length);
+ status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE,
+ &operation,
+ check1[valid_test_input_index].input,
+ check1[valid_test_input_index].input_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Finish the calculation of the hash of a message */
- status = val->crypto_function(VAL_CRYPTO_HASH_FINISH, &operation, hash, hash_size,
- &hash_length);
+ status = val->crypto_function(VAL_CRYPTO_HASH_FINISH,
+ &operation,
+ check1[valid_test_input_index].expected_hash,
+ check1[valid_test_input_index].hash_size,
+ &expected_hash_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Retry the operation with completed operation handle */
- status = val->crypto_function(VAL_CRYPTO_HASH_FINISH, &operation, hash, hash_size,
- &hash_length);
+ status = val->crypto_function(VAL_CRYPTO_HASH_FINISH,
+ &operation,
+ check1[valid_test_input_index].expected_hash,
+ check1[valid_test_input_index].hash_size,
+ &expected_hash_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(6));
/*Abort the hash operation */
@@ -144,45 +145,3 @@
return VAL_STATUS_SUCCESS;
}
-
-int32_t psa_hash_finish_invalid_hash_buffer_size(caller_security_t caller __UNUSED)
-{
- psa_hash_operation_t operation;
- char input = 0xbd;
- size_t input_length = 1;
- psa_algorithm_t alg = PSA_ALG_SHA_256;
- char hash[HASH_64B];
- size_t hash_length, hash_size = 10;
- int32_t status;
-
- /* Initialize the PSA crypto library*/
- status = val->crypto_function(VAL_CRYPTO_INIT);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
-
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
- val->print(PRINT_TEST, "test psa_hash_finish with invalid hash buffer size\n", 0);
- memset(&operation, 0, sizeof(operation));
-
- /* Setting up the watchdog timer for each check */
- status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
- TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
-
- /* Start a multipart hash operation */
- status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &operation, alg);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
-
- /* Add a message fragment to a multipart hash operation */
- status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE, &operation, &input, input_length);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
-
- /* Finish the calculation of the hash of a message */
- status = val->crypto_function(VAL_CRYPTO_HASH_FINISH, &operation, hash, hash_size,
- &hash_length);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_BUFFER_TOO_SMALL, TEST_CHECKPOINT_NUM(5));
-
- /*Abort the hash operation */
- status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &operation);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
-
- return VAL_STATUS_SUCCESS;
-}
diff --git a/api-tests/dev_apis/crypto/test_c014/test_data.h b/api-tests/dev_apis/crypto/test_c014/test_data.h
index b8d77f6..4f3d8f6 100644
--- a/api-tests/dev_apis/crypto/test_c014/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c014/test_data.h
@@ -15,101 +15,147 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
- char test_desc[50];
+ char test_desc[75];
psa_algorithm_t alg;
- char input;
+ const uint8_t *input;
size_t input_length;
- char hash[32];
- size_t hash_length;
+ uint8_t *expected_hash;
+ size_t hash_size;
+ const uint8_t *verify_hash;
psa_status_t expected_status;
} test_data;
-static const char sha384_hash[] = {
-0x43, 0x72, 0xe3, 0x8a, 0x92, 0xa2, 0x8b, 0x5d, 0x2c, 0x39, 0x1e, 0x62,
-0x45, 0x2a, 0x86, 0xd5, 0x0e, 0x02, 0x67, 0x22, 0x8b, 0xe1, 0x76, 0xc7, 0x7d, 0x24, 0x02, 0xef,
-0xfe, 0x9f, 0xa5, 0x0d, 0xe4, 0x07, 0xbb, 0xb8, 0x51, 0xb3, 0x7d, 0x59, 0x04, 0xab, 0xa2, 0xde,
-0xde, 0x74, 0xda, 0x2a};
-
-static const char sha512_hash[] = {
-0x29, 0x6e, 0x22, 0x67, 0xd7, 0x4c, 0x27, 0x8d, 0xaa, 0xaa, 0x94, 0x0d,
-0x17, 0xb0, 0xcf, 0xb7, 0x4a, 0x50, 0x83, 0xf8, 0xe0, 0x69, 0x72, 0x6d, 0x8c, 0x84, 0x1c, 0xbe,
-0x59, 0x6e, 0x04, 0x31, 0xcb, 0x77, 0x41, 0xa5, 0xb5, 0x0f, 0x71, 0x66, 0x6c, 0xfd, 0x54, 0xba,
-0xcb, 0x7b, 0x00, 0xae, 0xa8, 0x91, 0x49, 0x9c, 0xf4, 0xef, 0x6a, 0x03, 0xc8, 0xa8, 0x3f, 0xe3,
-0x7c, 0x3f, 0x7b, 0xaf};
-
static const test_data check1[] = {
#ifdef ARCH_TEST_MD2
-{"Test psa_hash_finish with MD2 algorithm\n",
- PSA_ALG_MD2, 0xbd, 1,
- {0x8c, 0x9c, 0x17, 0x66, 0x5d, 0x25, 0xb3, 0x5f, 0xc4, 0x13, 0xc4, 0x18, 0x05, 0xc6, 0x79, 0xcf},
- 16, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_finish with MD2 algorithm\n",
+ .alg = PSA_ALG_MD2,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .expected_hash = expected_output,
+ .hash_size = 16,
+ .verify_hash = md2_hash,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD4
-{"Test psa_hash_finish with MD4 algorithm\n",
- PSA_ALG_MD4, 0xbd, 1,
- {0x18, 0xc3, 0x3f, 0x97, 0x29, 0x7e, 0xfe, 0x5f, 0x8a, 0x73, 0x22, 0x58, 0x28, 0x9f, 0xda, 0x25},
- 16, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_finish with MD4 algorithm\n",
+ .alg = PSA_ALG_MD4,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .expected_hash = expected_output,
+ .hash_size = 16,
+ .verify_hash = md4_hash,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD5
-{"Test psa_hash_finish with MD5 algorithm\n",
- PSA_ALG_MD5, 0xbd, 1,
- {0xab, 0xae, 0x57, 0xcb, 0x56, 0x2e, 0xcf, 0x29, 0x5b, 0x4a, 0x37, 0xa7, 0x6e, 0xfe, 0x61, 0xfb},
- 16, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_finish with MD5 algorithm\n",
+ .alg = PSA_ALG_MD5,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .expected_hash = expected_output,
+ .hash_size = 16,
+ .verify_hash = md5_hash,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_RIPEMD160
-{"Test psa_hash_finish with RIPEMD160 algorithm\n",
- PSA_ALG_RIPEMD160, 0xbd, 1,
- {0x50, 0x89, 0x26, 0x5e, 0xe5, 0xd9, 0xaf, 0x75, 0xd1, 0x2d, 0xbf, 0x7e, 0xa2, 0xf2, 0x7d, 0xbd,
- 0xee, 0x43, 0x5b, 0x37},
- 20, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_finish with RIPEMD160 algorithm\n",
+ .alg = PSA_ALG_RIPEMD160,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .expected_hash = expected_output,
+ .hash_size = 20,
+ .verify_hash = ripemd_160_hash,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA1
-{"Test psa_hash_finish with SHA1 algorithm\n",
- PSA_ALG_SHA_1, 0xbd, 1,
- {0x90, 0x34, 0xaa, 0xf4, 0x51, 0x43, 0x99, 0x6a, 0x2b, 0x14, 0x46, 0x5c, 0x35, 0x2a, 0xb0, 0xc6,
- 0xfa, 0x26, 0xb2, 0x21},
- 20, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_finish with SHA1 algorithm\n",
+ .alg = PSA_ALG_SHA_1,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .expected_hash = expected_output,
+ .hash_size = 20,
+ .verify_hash = sha_1_hash,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA224
-{"Test psa_hash_finish with SHA224 algorithm\n",
- PSA_ALG_SHA_224, 0xbd, 1,
- {0xb1, 0xe4, 0x6b, 0xb9, 0xef, 0xe4, 0x5a, 0xf5, 0x54, 0x36, 0x34, 0x49, 0xc6, 0x94, 0x5a, 0x0d,
- 0x61, 0x69, 0xfc, 0x3a, 0x5a, 0x39, 0x6a, 0x56, 0xcb, 0x97, 0xcb, 0x57},
- 28, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_finish with SHA224 algorithm\n",
+ .alg = PSA_ALG_SHA_224,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .expected_hash = expected_output,
+ .hash_size = 28,
+ .verify_hash = sha_224_hash,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA256
-{"Test psa_hash_finish with SHA256 algorithm\n",
- PSA_ALG_SHA_256, 0xbd, 1,
- {0x68, 0x32, 0x57, 0x20, 0xaa, 0xbd, 0x7c, 0x82, 0xf3, 0x0f, 0x55, 0x4b, 0x31, 0x3d, 0x05, 0x70,
- 0xc9, 0x5a, 0xcc, 0xbb, 0x7d, 0xc4, 0xb5, 0xaa, 0xe1, 0x12, 0x04, 0xc0, 0x8f, 0xfe, 0x73, 0x2b},
- 32, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_finish with SHA256 algorithm\n",
+ .alg = PSA_ALG_SHA_256,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .expected_hash = expected_output,
+ .hash_size = 32,
+ .verify_hash = sha_256_hash,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA384
-{"Test psa_hash_finish with SHA384 algorithm\n",
- PSA_ALG_SHA_384, 0xbd, 1, {0}, 48, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_finish with SHA384 algorithm\n",
+ .alg = PSA_ALG_SHA_384,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .expected_hash = expected_output,
+ .hash_size = 48,
+ .verify_hash = sha_384_hash,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA512
-{"Test psa_hash_finish with SHA512 algorithm\n",
- PSA_ALG_SHA_512, 0xbd, 1, {0}, 64, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_finish with SHA512 algorithm\n",
+ .alg = PSA_ALG_SHA_512,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .expected_hash = expected_output,
+ .hash_size = 64,
+ .verify_hash = sha_512_hash,
+ .expected_status = PSA_SUCCESS,
+},
+#endif
+
+#ifdef ARCH_TEST_SHA256
+{
+ .test_desc = "Test psa_hash_finish with invalid hash buffer size\n",
+ .alg = PSA_ALG_SHA_256,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .expected_hash = expected_output,
+ .hash_size = 10,
+ .verify_hash = sha_256_hash,
+ .expected_status = PSA_ERROR_BUFFER_TOO_SMALL,
},
#endif
};
diff --git a/api-tests/dev_apis/crypto/test_c015/test_c015.c b/api-tests/dev_apis/crypto/test_c015/test_c015.c
index a7b1447..d378296 100644
--- a/api-tests/dev_apis/crypto/test_c015/test_c015.c
+++ b/api-tests/dev_apis/crypto/test_c015/test_c015.c
@@ -19,7 +19,6 @@
#include "val_target.h"
#include "test_c015.h"
#include "test_data.h"
-#include "val_crypto.h"
const client_test_t test_c015_crypto_list[] = {
NULL,
@@ -28,11 +27,12 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
+static int32_t valid_test_input_index = -1;
int32_t psa_hash_abort_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
psa_hash_operation_t operation;
@@ -68,6 +68,9 @@
status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &operation);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(5));
+ if (valid_test_input_index < 0)
+ valid_test_input_index = i;
+
}
return VAL_STATUS_SUCCESS;
@@ -76,13 +79,12 @@
int32_t psa_hash_abort_before_operation_finish(caller_security_t caller __UNUSED)
{
psa_hash_operation_t operation;
- char input = 0xbd;
- size_t input_length = 1;
- psa_algorithm_t alg = PSA_ALG_SHA_256;
- char hash[HASH_64B];
- size_t hash_length, hash_size = sizeof(hash);
+ size_t expected_hash_length;
int32_t status;
+ if (valid_test_input_index < 0)
+ return RESULT_SKIP(VAL_STATUS_NO_TESTS);
+
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
@@ -96,11 +98,15 @@
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Start a multipart hash operation */
- status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &operation, alg);
+ status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &operation,
+ check1[valid_test_input_index].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Add a message fragment to a multipart hash operation */
- status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE, &operation, &input, input_length);
+ status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE,
+ &operation,
+ check1[valid_test_input_index].input,
+ check1[valid_test_input_index].input_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Abort a hash operation */
@@ -108,8 +114,11 @@
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Finish the calculation of the hash of a message */
- status = val->crypto_function(VAL_CRYPTO_HASH_FINISH, &operation, hash, hash_size,
- &hash_length);
+ status = val->crypto_function(VAL_CRYPTO_HASH_FINISH,
+ &operation,
+ check1[valid_test_input_index].hash,
+ check1[valid_test_input_index].hash_size,
+ &expected_hash_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(6));
return VAL_STATUS_SUCCESS;
diff --git a/api-tests/dev_apis/crypto/test_c015/test_data.h b/api-tests/dev_apis/crypto/test_c015/test_data.h
index a9c20f8..290a983 100644
--- a/api-tests/dev_apis/crypto/test_c015/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c015/test_data.h
@@ -15,66 +15,124 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[50];
psa_algorithm_t alg;
+ const uint8_t *input;
+ size_t input_length;
+ uint8_t *hash;
+ size_t hash_size;
psa_status_t expected_status;
} test_data;
static const test_data check1[] = {
#ifdef ARCH_TEST_MD2
-{"Test psa_hash_abort with MD2 algorithm\n",
- PSA_ALG_MD2, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_abort with MD2 algorithm\n",
+ .alg = PSA_ALG_MD2,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = expected_output,
+ .hash_size = 16,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD4
-{"Test psa_hash_abort with MD4 algorithm\n",
- PSA_ALG_MD4, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_abort with MD4 algorithm\n",
+ .alg = PSA_ALG_MD4,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = expected_output,
+ .hash_size = 16,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD5
-{"Test psa_hash_abort with MD5 algorithm\n",
- PSA_ALG_MD5, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_abort with MD5 algorithm\n",
+ .alg = PSA_ALG_MD5,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = expected_output,
+ .hash_size = 16,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_RIPEMD160
-{"Test psa_hash_abort with RIPEMD160 algorithm\n",
- PSA_ALG_RIPEMD160, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_abort with RIPEMD160 algorithm\n",
+ .alg = PSA_ALG_RIPEMD160,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = expected_output,
+ .hash_size = 20,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA1
-{"Test psa_hash_abort with SHA1 algorithm\n",
- PSA_ALG_SHA_1, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_abort with SHA1 algorithm\n",
+ .alg = PSA_ALG_SHA_1,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = expected_output,
+ .hash_size = 20,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA224
-{"Test psa_hash_abort with SHA224 algorithm\n",
- PSA_ALG_SHA_224, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_abort with SHA224 algorithm\n",
+ .alg = PSA_ALG_SHA_224,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = expected_output,
+ .hash_size = 28,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA256
-{"Test psa_hash_abort with SHA256 algorithm\n",
- PSA_ALG_SHA_256, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_abort with SHA256 algorithm\n",
+ .alg = PSA_ALG_SHA_256,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = expected_output,
+ .hash_size = 32,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA384
-{"Test psa_hash_abort with SHA384 algorithm\n",
- PSA_ALG_SHA_384, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_abort with SHA384 algorithm\n",
+ .alg = PSA_ALG_SHA_384,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = expected_output,
+ .hash_size = 48,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA512
-{"Test psa_hash_abort with SHA512 algorithm\n",
- PSA_ALG_SHA_512, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_abort with SHA512 algorithm\n",
+ .alg = PSA_ALG_SHA_512,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .hash = expected_output,
+ .hash_size = 64,
+ .expected_status = PSA_SUCCESS,
},
#endif
};
diff --git a/api-tests/dev_apis/crypto/test_c016/test_c016.c b/api-tests/dev_apis/crypto/test_c016/test_c016.c
index 265d8a1..eeca485 100644
--- a/api-tests/dev_apis/crypto/test_c016/test_c016.c
+++ b/api-tests/dev_apis/crypto/test_c016/test_c016.c
@@ -19,7 +19,6 @@
#include "val_target.h"
#include "test_c016.h"
#include "test_data.h"
-#include "val_crypto.h"
const client_test_t test_c016_crypto_list[] = {
NULL,
@@ -27,19 +26,16 @@
NULL,
};
-static int g_test_count = 1;
-static uint8_t data[BUFFER_SIZE];
-
int32_t psa_generate_key_test(caller_security_t caller __UNUSED)
{
int32_t i, status;
- size_t length;
- psa_key_type_t get_key_type;
- psa_key_usage_t get_key_usage;
- psa_algorithm_t get_key_alg;
- size_t get_key_bits;
- int num_checks = sizeof(check1)/sizeof(check1[0]);
- psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+ size_t expected_data_length;
+ psa_key_type_t get_type;
+ psa_key_usage_t get_usage_flags;
+ psa_algorithm_t get_alg;
+ size_t get_bits;
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
+ psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t get_attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_handle_t key_handle;
@@ -56,7 +52,7 @@
/* Set the key data buffer to the input base on algorithm */
for (i = 0; i < num_checks; i++)
{
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] ", i+1);
val->print(PRINT_TEST, check1[i].test_desc, 0);
/* Setting up the watchdog timer for each check */
@@ -64,10 +60,10 @@
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_BITS, &attributes, check1[i].attr_bits);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].key_alg);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_BITS, &attributes, check1[i].bits);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage_flags);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].alg);
/* Generate the key */
status = val->crypto_function(VAL_CRYPTO_GENERATE_KEY, &attributes, &key_handle);
@@ -81,25 +77,26 @@
&get_attributes);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
- val->crypto_function(VAL_CRYPTO_GET_KEY_TYPE, &get_attributes, &get_key_type);
- TEST_ASSERT_EQUAL(get_key_type, check1[i].key_type, TEST_CHECKPOINT_NUM(5));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_TYPE, &get_attributes, &get_type);
+ TEST_ASSERT_EQUAL(get_type, check1[i].type, TEST_CHECKPOINT_NUM(5));
- val->crypto_function(VAL_CRYPTO_GET_KEY_BITS, &get_attributes, &get_key_bits);
- TEST_ASSERT_EQUAL(get_key_bits, check1[i].expected_bit_length, TEST_CHECKPOINT_NUM(6));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_BITS, &get_attributes, &get_bits);
+ TEST_ASSERT_EQUAL(get_bits, check1[i].bits, TEST_CHECKPOINT_NUM(6));
- val->crypto_function(VAL_CRYPTO_GET_KEY_USAGE_FLAGS, &get_attributes, &get_key_usage);
- TEST_ASSERT_EQUAL(get_key_usage, check1[i].usage, TEST_CHECKPOINT_NUM(7));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_USAGE_FLAGS, &get_attributes, &get_usage_flags);
+ TEST_ASSERT_EQUAL(get_usage_flags, check1[i].usage_flags, TEST_CHECKPOINT_NUM(7));
- val->crypto_function(VAL_CRYPTO_GET_KEY_ALGORITHM, &get_attributes, &get_key_alg);
- TEST_ASSERT_EQUAL(get_key_alg, check1[i].key_alg, TEST_CHECKPOINT_NUM(8));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_ALGORITHM, &get_attributes, &get_alg);
+ TEST_ASSERT_EQUAL(get_alg, check1[i].alg, TEST_CHECKPOINT_NUM(8));
/* Export a key in binary format */
- status = val->crypto_function(VAL_CRYPTO_EXPORT_KEY, key_handle, data,
- BUFFER_SIZE, &length);
+ status = val->crypto_function(VAL_CRYPTO_EXPORT_KEY, key_handle, expected_output,
+ BUFFER_SIZE, &expected_data_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(9));
/* Check the attributes of the exported key */
- TEST_ASSERT_RANGE(length, check1[i].expected_range[0], check1[i].expected_range[1], TEST_CHECKPOINT_NUM(10));
+ TEST_ASSERT_RANGE(expected_data_length, check1[i].expected_range[0],
+ check1[i].expected_range[1], TEST_CHECKPOINT_NUM(10));
/* Reset the attributes */
val->crypto_function(VAL_CRYPTO_RESET_KEY_ATTRIBUTES, &attributes);
diff --git a/api-tests/dev_apis/crypto/test_c016/test_data.h b/api-tests/dev_apis/crypto/test_c016/test_data.h
index 4f5b026..0157e54 100644
--- a/api-tests/dev_apis/crypto/test_c016/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c016/test_data.h
@@ -15,15 +15,14 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- psa_key_type_t key_type;
- psa_key_usage_t usage;
- psa_algorithm_t key_alg;
- size_t attr_bits;
- uint32_t expected_bit_length;
+ psa_key_type_t type;
+ psa_key_usage_t usage_flags;
+ psa_algorithm_t alg;
+ size_t bits;
uint32_t expected_range[2];
psa_status_t expected_status;
} test_data;
@@ -31,44 +30,74 @@
static const test_data check1[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
-{"Test psa_generate_key 16 Byte AES\n", PSA_KEY_TYPE_AES,
- PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BYTES_TO_BITS(AES_16B_KEY_SIZE),
- BYTES_TO_BITS(AES_16B_KEY_SIZE), {AES_16B_KEY_SIZE, AES_16B_KEY_SIZE}, PSA_SUCCESS
+{
+ .test_desc = "Test psa_generate_key 16 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .alg = PSA_ALG_CTR,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .expected_range = {AES_16B_KEY_SIZE, AES_16B_KEY_SIZE},
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_192
-{"Test psa_generate_key 24 Byte AES\n", PSA_KEY_TYPE_AES,
- PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BYTES_TO_BITS(AES_24B_KEY_SIZE),
- BYTES_TO_BITS(AES_24B_KEY_SIZE), {AES_24B_KEY_SIZE, AES_24B_KEY_SIZE}, PSA_SUCCESS
+{
+ .test_desc = "Test psa_generate_key 24 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .alg = PSA_ALG_CTR,
+ .bits = BYTES_TO_BITS(AES_24B_KEY_SIZE),
+ .expected_range = {AES_24B_KEY_SIZE, AES_24B_KEY_SIZE},
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_256
-{"Test psa_generate_key 32 Byte AES\n", PSA_KEY_TYPE_AES,
- PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BYTES_TO_BITS(AES_32B_KEY_SIZE),
- BYTES_TO_BITS(AES_32B_KEY_SIZE), {AES_32B_KEY_SIZE, AES_32B_KEY_SIZE}, PSA_SUCCESS
+{
+ .test_desc = "Test psa_generate_key 32 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .alg = PSA_ALG_CTR,
+ .bits = BYTES_TO_BITS(AES_32B_KEY_SIZE),
+ .expected_range = {AES_32B_KEY_SIZE, AES_32B_KEY_SIZE},
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_1KEY
-{"Test psa_generate_key with DES 64 bit key\n", PSA_KEY_TYPE_DES,
- PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BYTES_TO_BITS(DES_8B_KEY_SIZE),
- BYTES_TO_BITS(DES_8B_KEY_SIZE), {DES_8B_KEY_SIZE, DES_8B_KEY_SIZE}, PSA_SUCCESS
+{
+ .test_desc = "Test psa_generate_key with DES 64 bit key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .alg = PSA_ALG_CTR,
+ .bits = BYTES_TO_BITS(DES_8B_KEY_SIZE),
+ .expected_range = {DES_8B_KEY_SIZE, DES_8B_KEY_SIZE},
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_2KEY
-{"Test psa_generate_key with Triple DES 2-Key\n", PSA_KEY_TYPE_DES,
- PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BYTES_TO_BITS(DES3_2KEY_SIZE),
- BYTES_TO_BITS(DES3_2KEY_SIZE), {DES3_2KEY_SIZE, DES3_2KEY_SIZE}, PSA_SUCCESS
+{
+ .test_desc = "Test psa_generate_key with Triple DES 2-Key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .alg = PSA_ALG_CTR,
+ .bits = BYTES_TO_BITS(DES3_2B_KEY_SIZE),
+ .expected_range = {DES3_2B_KEY_SIZE, DES3_2B_KEY_SIZE},
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_3KEY
-{"Test psa_generate_key with Triple DES 3-Key\n", PSA_KEY_TYPE_DES,
- PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BYTES_TO_BITS(DES3_3KEY_SIZE),
- BYTES_TO_BITS(DES3_3KEY_SIZE), {DES3_3KEY_SIZE, DES3_3KEY_SIZE}, PSA_SUCCESS
+{
+ .test_desc = "Test psa_generate_key with Triple DES 3-Key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .alg = PSA_ALG_CTR,
+ .bits = BYTES_TO_BITS(DES3_3B_KEY_SIZE),
+ .expected_range = {DES3_3B_KEY_SIZE, DES3_3B_KEY_SIZE},
+ .expected_status = PSA_SUCCESS
},
#endif
@@ -77,9 +106,14 @@
#ifdef ARCH_TEST_RSA
#ifdef ARCH_TEST_RSA_2048
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
-{"Test psa_generate_key with RSA 2048 Keypair\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
- PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
- 2048, 2048, {1190, 1194}, PSA_SUCCESS
+{
+ .test_desc = "Test psa_generate_key with RSA 2048 Keypair\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .usage_flags = PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
+ .bits = 2048,
+ .expected_range = {1190, 1194},
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
@@ -87,30 +121,49 @@
#ifdef ARCH_TEST_ECC_CURVE_SECP224R1
#ifdef ARCH_TEST_ASYMMETRIC_ENCRYPTION
-{"Test psa_generate_key with ECC KeyPair\n",
- PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP224R1),
- PSA_KEY_USAGE_EXPORT, PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION, 224,
- 224, {28, 28}, PSA_SUCCESS
+{
+ .test_desc = "Test psa_generate_key with ECC KeyPair\n",
+ .type = PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP224R1),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .alg = PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION,
+ .bits = 224,
+ .expected_range = {28, 28},
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
#ifdef ARCH_TEST_RSA_2048
-{"Test psa_generate_key with RSA 2048 Public key\n", PSA_KEY_TYPE_RSA_PUBLIC_KEY,
- PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
- 2048, 2048, {1190, 1194}, PSA_ERROR_NOT_SUPPORTED
+{
+ .test_desc = "Test psa_generate_key with RSA 2048 Public key\n",
+ .type = PSA_KEY_TYPE_RSA_PUBLIC_KEY,
+ .usage_flags = PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
+ .bits = 2048,
+ .expected_range = {1190, 1194},
+ .expected_status = PSA_ERROR_NOT_SUPPORTED
},
#endif
#endif
-{"Test psa_generate_key with invalid key type\n", 0,
- PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BYTES_TO_BITS(AES_16B_KEY_SIZE),
- BYTES_TO_BITS(AES_16B_KEY_SIZE), {AES_16B_KEY_SIZE, AES_16B_KEY_SIZE}, PSA_ERROR_NOT_SUPPORTED
+{
+ .test_desc = "Test psa_generate_key with invalid key type\n",
+ .type = 0,
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .alg = PSA_ALG_CTR,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .expected_range = {AES_16B_KEY_SIZE, AES_16B_KEY_SIZE},
+ .expected_status = PSA_ERROR_NOT_SUPPORTED
},
-{"Test psa_generate_key with invalid usage flags\n", PSA_KEY_TYPE_AES,
- PSA_KEY_USAGE_INVALID, PSA_ALG_CTR, BYTES_TO_BITS(AES_16B_KEY_SIZE),
- BYTES_TO_BITS(AES_16B_KEY_SIZE), {AES_16B_KEY_SIZE, AES_16B_KEY_SIZE}, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_generate_key with invalid usage flags\n",
+ .type = PSA_KEY_TYPE_AES,
+ .usage_flags = PSA_KEY_USAGE_INVALID,
+ .alg = PSA_ALG_CTR,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .expected_range = {AES_16B_KEY_SIZE, AES_16B_KEY_SIZE},
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
};
diff --git a/api-tests/dev_apis/crypto/test_c017/test_c017.c b/api-tests/dev_apis/crypto/test_c017/test_c017.c
index 1d413b8..feec30c 100644
--- a/api-tests/dev_apis/crypto/test_c017/test_c017.c
+++ b/api-tests/dev_apis/crypto/test_c017/test_c017.c
@@ -19,7 +19,6 @@
#include "val_target.h"
#include "test_c017.h"
#include "test_data.h"
-#include "val_crypto.h"
const client_test_t test_c017_crypto_list[] = {
NULL,
@@ -27,12 +26,11 @@
NULL,
};
-static int g_test_count = 1;
-static uint8_t data[BUFFER_SIZE], changed[BUFFER_SIZE];
+static uint8_t changed[BUFFER_SIZE];
int32_t psa_generate_random_test(caller_security_t caller __UNUSED)
{
- int i, num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t i, num_checks = sizeof(check1)/sizeof(check1[0]);
uint32_t j, run;
uint8_t trail[] = "don't overwrite me";
int32_t status;
@@ -49,11 +47,11 @@
for (i = 0; i < num_checks; i++)
{
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] ", i+1);
val->print(PRINT_TEST, check1[i].test_desc, 0);
- memset(data, 0, sizeof(data));
- memcpy(data + check1[i].size, trail, sizeof(trail));
+ memset(check1[i].output, 0, BUFFER_SIZE);
+ memcpy(check1[i].output + check1[i].output_size, trail, sizeof(trail));
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
@@ -65,19 +63,20 @@
*/
for (run = 0; run < 10; run++)
{
- memset(data, 0, check1[i].size);
+ memset(check1[i].output, 0, check1[i].output_size);
/* Generate random bytes */
- status = val->crypto_function(VAL_CRYPTO_GENERATE_RANDOM, data, check1[i].size);
+ status = val->crypto_function(VAL_CRYPTO_GENERATE_RANDOM, check1[i].output,
+ check1[i].output_size);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(3));
/* Check that no more than bytes have been overwritten */
- status = memcmp(data + check1[i].size, trail, sizeof(trail));
+ status = memcmp(check1[i].output + check1[i].output_size, trail, sizeof(trail));
TEST_ASSERT_EQUAL(status, 0, TEST_CHECKPOINT_NUM(4));
- for (j = 0; j < check1[i].size; j++)
+ for (j = 0; j < check1[i].output_size; j++)
{
- if (data[j] != 0)
+ if (check1[i].output[j] != 0)
++changed[j];
}
}
@@ -86,10 +85,8 @@
* validates that psa_generate_random is overwriting every byte of
* the output buffer.
*/
- for (j = 0; j < check1[i].size; j++)
- {
+ for (j = 0; j < check1[i].output_size; j++)
TEST_ASSERT_NOT_EQUAL(changed[j], 0, TEST_CHECKPOINT_NUM(5));
- }
}
return VAL_STATUS_SUCCESS;
diff --git a/api-tests/dev_apis/crypto/test_c017/test_data.h b/api-tests/dev_apis/crypto/test_c017/test_data.h
index 49b7a5f..9453c3b 100644
--- a/api-tests/dev_apis/crypto/test_c017/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c017/test_data.h
@@ -15,39 +15,76 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- size_t size;
+ uint8_t *output;
+ size_t output_size;
psa_status_t expected_status;
} test_data;
static const test_data check1[] = {
-{"Test psa_generate_random to get 0 Byte data\n", 0, PSA_SUCCESS
+{
+ .test_desc = "Test psa_generate_random to get 0 Byte data\n",
+ .output = expected_output,
+ .output_size = 0,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_generate_random to get 16 Byte data\n", 16, PSA_SUCCESS
+{
+ .test_desc = "Test psa_generate_random to get 16 Byte data\n",
+ .output = expected_output,
+ .output_size = 16,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_generate_random to get 24 Byte data\n", 24, PSA_SUCCESS
+{
+ .test_desc = "Test psa_generate_random to get 24 Byte data\n",
+ .output = expected_output,
+ .output_size = 24,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_generate_random to get 32 Byte data\n", 32, PSA_SUCCESS
+{
+ .test_desc = "Test psa_generate_random to get 32 Byte data\n",
+ .output = expected_output,
+ .output_size = 32,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_generate_random to get 64 Byte data\n", 64, PSA_SUCCESS
+{
+ .test_desc = "Test psa_generate_random to get 64 Byte data\n",
+ .output = expected_output,
+ .output_size = 64,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_generate_random to get 128 Byte data\n", 128, PSA_SUCCESS
+{
+ .test_desc = "Test psa_generate_random to get 128 Byte data\n",
+ .output = expected_output,
+ .output_size = 128,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_generate_random to get 256 Byte data\n", 256, PSA_SUCCESS
+{
+ .test_desc = "Test psa_generate_random to get 256 Byte data\n",
+ .output = expected_output,
+ .output_size = 256,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_generate_random to get 512 Byte data\n", 512, PSA_SUCCESS
+{
+ .test_desc = "Test psa_generate_random to get 512 Byte data\n",
+ .output = expected_output,
+ .output_size = 512,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_generate_random to get 1000 Byte data\n", 100, PSA_SUCCESS
+{
+ .test_desc = "Test psa_generate_random to get 1000 Byte data\n",
+ .output = expected_output,
+ .output_size = 1000,
+ .expected_status = PSA_SUCCESS
},
};
diff --git a/api-tests/dev_apis/crypto/test_c018/test_c018.c b/api-tests/dev_apis/crypto/test_c018/test_c018.c
index e8679dc..4ad4856 100644
--- a/api-tests/dev_apis/crypto/test_c018/test_c018.c
+++ b/api-tests/dev_apis/crypto/test_c018/test_c018.c
@@ -19,7 +19,6 @@
#include "val_target.h"
#include "test_c018.h"
#include "test_data.h"
-#include "val_crypto.h"
const client_test_t test_c018_crypto_list[] = {
NULL,
@@ -28,14 +27,14 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
+static int32_t valid_test_input_index = -1;
int32_t psa_key_derivation_input_key_test(caller_security_t caller __UNUSED)
{
int32_t i, status;
- const uint8_t *key_data;
- int num_checks = sizeof(check1)/sizeof(check1[0]);
- psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
+ psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_handle_t key_handle;
@@ -59,46 +58,15 @@
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type))
- {
- if (check1[i].key_type == PSA_KEY_TYPE_RSA_KEY_PAIR)
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keypair;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keypair;
- else
- return VAL_STATUS_INVALID;
- }
- else
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keydata;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keydata;
- else
- return VAL_STATUS_INVALID;
- }
- }
- else if (PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
- {
- if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(check1[i].key_type))
- key_data = ec_keypair;
- else
- key_data = ec_keydata;
- }
- else
- key_data = check1[i].key_data;
-
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_BITS, &attributes, check1[i].attr_bits);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].key_alg);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_BITS, &attributes, check1[i].bits);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage_flags);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].alg);
/* Import the key data into the key slot */
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, key_data,
- check1[i].key_length, &key_handle);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
if (check1[i].expected_status == PSA_SUCCESS)
@@ -113,7 +81,7 @@
/* Set up a key derivation operation */
status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_SETUP, &operation,
- check1[i].alg);
+ check1[i].setup_alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Provide an input for key derivation or key agreement */
@@ -144,6 +112,12 @@
/* Reset the key attributes and check if psa_import_key fails */
val->crypto_function(VAL_CRYPTO_RESET_KEY_ATTRIBUTES, &attributes);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_NOT_SUPPORTED, TEST_CHECKPOINT_NUM(11));
+
+ if (valid_test_input_index < 0)
+ valid_test_input_index = i;
}
return VAL_STATUS_SUCCESS;
@@ -151,49 +125,58 @@
int32_t psa_key_derivation_input_key_negative_test(caller_security_t caller __UNUSED)
{
- int32_t i, status;
- int num_checks = sizeof(check2)/sizeof(check2[0]);
- psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
+ int32_t status;
+ psa_key_derivation_operation_t operation;
psa_key_handle_t key_handle = 11;
+ if (valid_test_input_index < 0)
+ return RESULT_SKIP(VAL_STATUS_NO_TESTS);
+
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
- /* Set the key data buffer to the input base on algorithm */
- for (i = 0; i < num_checks; i++)
- {
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
- val->print(PRINT_TEST, check2[i].test_desc, 0);
+ /* Setting up the watchdog timer for each check */
+ status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
+ TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- /* Setting up the watchdog timer for each check */
- status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
- TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
+ val->print(PRINT_TEST, "[Check %d] Test psa_cipher_decrypt_setup - Invalid key handle\n",
+ g_test_count++);
- /* Set up a key derivation operation */
- status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_SETUP, &operation,
- check2[i].alg);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
+ memset(&operation, 0, sizeof(operation));
- /* Provide an input for key derivation or key agreement */
- status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_INPUT_KEY, &operation,
- check2[i].step, key_handle);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(4));
+ /* Set up a key derivation operation */
+ status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_SETUP, &operation,
+ check1[valid_test_input_index].setup_alg);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
- /* Abort the key derivation operation */
- status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_ABORT, &operation);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
+ /* Provide an input for key derivation or key agreement */
+ status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_INPUT_KEY, &operation,
+ check1[valid_test_input_index].step, key_handle);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(4));
- /* Set up a key derivation operation */
- status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_SETUP, &operation,
- check2[i].alg);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
+ /* Abort the key derivation operation */
+ status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_ABORT, &operation);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
- /* Provide an input for key derivation or key agreement */
- status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_INPUT_KEY, &operation,
- check2[i].step, 0);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(7));
- }
+ /* Set up a key derivation operation */
+ status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_SETUP, &operation,
+ check1[valid_test_input_index].setup_alg);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
+
+ val->print(PRINT_TEST, "[Check %d] Test psa_cipher_decrypt_setup - Zero as key handle\n",
+ g_test_count++);
+
+ memset(&operation, 0, sizeof(operation));
+
+ /* Provide an input for key derivation or key agreement */
+ status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_INPUT_KEY, &operation,
+ check1[valid_test_input_index].step, 0);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(7));
+
+ /* Abort the key derivation operation */
+ status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_ABORT, &operation);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(8));
return VAL_STATUS_SUCCESS;
}
diff --git a/api-tests/dev_apis/crypto/test_c018/test_data.h b/api-tests/dev_apis/crypto/test_c018/test_data.h
index 14d777b..832b5da 100644
--- a/api-tests/dev_apis/crypto/test_c018/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c018/test_data.h
@@ -15,256 +15,169 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- psa_key_type_t key_type;
- uint8_t key_data[34];
- uint32_t key_length;
- size_t attr_bits;
- psa_key_usage_t usage;
- psa_algorithm_t key_alg;
- psa_key_derivation_step_t step;
+ psa_key_type_t type;
+ const uint8_t *data;
+ size_t data_length;
+ size_t bits;
+ psa_key_usage_t usage_flags;
psa_algorithm_t alg;
- uint32_t expected_bit_length;
- uint32_t expected_key_length;
+ psa_key_derivation_step_t step;
+ psa_algorithm_t setup_alg;
psa_status_t expected_status;
} test_data;
-static const uint8_t rsa_384_keypair[1];
-static const uint8_t rsa_384_keydata[1];
-
-static const uint8_t rsa_256_keypair[] = {
- 0x30, 0x82, 0x04, 0xA5, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xC0,
- 0x95, 0x08, 0xE1, 0x57, 0x41, 0xF2, 0x71, 0x6D, 0xB7, 0xD2, 0x45, 0x41, 0x27,
- 0x01, 0x65, 0xC6, 0x45, 0xAE, 0xF2, 0xBC, 0x24, 0x30, 0xB8, 0x95, 0xCE, 0x2F,
- 0x4E, 0xD6, 0xF6, 0x1C, 0x88, 0xBC, 0x7C, 0x9F, 0xFB, 0xA8, 0x67, 0x7F, 0xFE,
- 0x5C, 0x9C, 0x51, 0x75, 0xF7, 0x8A, 0xCA, 0x07, 0xE7, 0x35, 0x2F, 0x8F, 0xE1,
- 0xBD, 0x7B, 0xC0, 0x2F, 0x7C, 0xAB, 0x64, 0xA8, 0x17, 0xFC, 0xCA, 0x5D, 0x7B,
- 0xBA, 0xE0, 0x21, 0xE5, 0x72, 0x2E, 0x6F, 0x2E, 0x86, 0xD8, 0x95, 0x73, 0xDA,
- 0xAC, 0x1B, 0x53, 0xB9, 0x5F, 0x3F, 0xD7, 0x19, 0x0D, 0x25, 0x4F, 0xE1, 0x63,
- 0x63, 0x51, 0x8B, 0x0B, 0x64, 0x3F, 0xAD, 0x43, 0xB8, 0xA5, 0x1C, 0x5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const uint8_t ec_keypair[] = {
- 0x68, 0x49, 0xf9, 0x7d, 0x10, 0x66, 0xf6, 0x99, 0x77, 0x59, 0x63, 0x7c, 0x7e, 0x38,
- 0x99, 0x46, 0x4c, 0xee, 0x3e, 0xc7, 0xac, 0x97, 0x06, 0x53, 0xa0, 0xbe, 0x07, 0x42};
-
static const test_data check1[] = {
-{"Test psa_key_derivation_input_key 16 Byte Key\n", PSA_KEY_TYPE_DERIVE,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0x77},
- AES_16B_KEY_SIZE, 0, PSA_KEY_USAGE_DERIVE, PSA_ALG_HKDF(PSA_ALG_SHA_256),
- PSA_KEY_DERIVATION_INPUT_SECRET, PSA_ALG_HKDF(PSA_ALG_SHA_256),
- BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_SUCCESS
+{
+ .test_desc = "Test psa_key_derivation_input_key 16 Byte Key\n",
+ .type = PSA_KEY_TYPE_DERIVE,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .step = PSA_KEY_DERIVATION_INPUT_SECRET,
+ .setup_alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_key_derivation_input_key with invalid usage\n", PSA_KEY_TYPE_DERIVE,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0x77},
- AES_16B_KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_HKDF(PSA_ALG_SHA_256),
- PSA_KEY_DERIVATION_INPUT_SECRET, PSA_ALG_HKDF(PSA_ALG_SHA_256),
- BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_ERROR_NOT_PERMITTED
+{
+ .test_desc = "Test psa_key_derivation_input_key with invalid usage\n",
+ .type = PSA_KEY_TYPE_DERIVE,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .step = PSA_KEY_DERIVATION_INPUT_SECRET,
+ .setup_alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .expected_status = PSA_ERROR_NOT_PERMITTED
},
-{"Test psa_key_derivation_input_key with step as label\n", PSA_KEY_TYPE_DERIVE,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0x77},
- AES_16B_KEY_SIZE, 0, PSA_KEY_USAGE_DERIVE, PSA_ALG_HKDF(PSA_ALG_SHA_256),
- PSA_KEY_DERIVATION_INPUT_LABEL, PSA_ALG_HKDF(PSA_ALG_SHA_256),
- BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_key_derivation_input_key with step as label\n",
+ .type = PSA_KEY_TYPE_DERIVE,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .step = PSA_KEY_DERIVATION_INPUT_LABEL,
+ .setup_alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
-{"Test psa_key_derivation_input_key with step as info\n", PSA_KEY_TYPE_DERIVE,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0x77},
- AES_16B_KEY_SIZE, 0, PSA_KEY_USAGE_DERIVE, PSA_ALG_HKDF(PSA_ALG_SHA_256),
- PSA_KEY_DERIVATION_INPUT_INFO, PSA_ALG_HKDF(PSA_ALG_SHA_256),
- BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_key_derivation_input_key with step as info\n",
+ .type = PSA_KEY_TYPE_DERIVE,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .step = PSA_KEY_DERIVATION_INPUT_INFO,
+ .setup_alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
-{"Test psa_key_derivation_input_key with step as seed\n", PSA_KEY_TYPE_DERIVE,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0x77},
- AES_16B_KEY_SIZE, 0, PSA_KEY_USAGE_DERIVE, PSA_ALG_HKDF(PSA_ALG_SHA_256),
- PSA_KEY_DERIVATION_INPUT_SEED, PSA_ALG_HKDF(PSA_ALG_SHA_256),
- BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_key_derivation_input_key with step as seed\n",
+ .type = PSA_KEY_TYPE_DERIVE,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .step = PSA_KEY_DERIVATION_INPUT_SEED,
+ .setup_alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
-{"Test psa_key_derivation_input_key with step as salt\n", PSA_KEY_TYPE_DERIVE,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0x77},
- AES_16B_KEY_SIZE, 0, PSA_KEY_USAGE_DERIVE, PSA_ALG_HKDF(PSA_ALG_SHA_256),
- PSA_KEY_DERIVATION_INPUT_SALT, PSA_ALG_HKDF(PSA_ALG_SHA_256),
- BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_key_derivation_input_key with step as salt\n",
+ .type = PSA_KEY_TYPE_DERIVE,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .step = PSA_KEY_DERIVATION_INPUT_SALT,
+ .setup_alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#ifdef ARCH_TEST_AES_192
-{"Test psa_key_derivation_input_key with key type as AES(not derive)\n", PSA_KEY_TYPE_AES,
-{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
- 0x40, 0xAC, 0xA3, 0x90, 0x77, 0x83, 0x52, 0x31, 0x74, 0xF9, 0x05},
- AES_24B_KEY_SIZE, 0, PSA_KEY_USAGE_DERIVE, PSA_ALG_HKDF(PSA_ALG_SHA_256),
- PSA_KEY_DERIVATION_INPUT_SECRET, PSA_ALG_HKDF(PSA_ALG_SHA_256),
- BYTES_TO_BITS(AES_24B_KEY_SIZE), AES_24B_KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT,
+{
+ .test_desc = "Test psa_key_derivation_input_key with key type as AES(not derive)\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_24B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_24B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .step = PSA_KEY_DERIVATION_INPUT_SECRET,
+ .setup_alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT,
},
#endif
-{"Test psa_key_derivation_input_key incorrect key algorithm\n", PSA_KEY_TYPE_DERIVE,
-{0xEA, 0xD5, 0xE6, 0xC8, 0x51, 0xF9, 0xEC, 0xBB, 0x9B, 0x57, 0x7C, 0xED, 0xD2,
- 0x4B, 0x82, 0x84, 0x9F, 0x9F, 0xE6, 0x73, 0x21, 0x3D, 0x1A, 0x05, 0xC9, 0xED,
- 0xDF, 0x25, 0x17, 0x68, 0x86, 0xAE},
- AES_32B_KEY_SIZE, 0, PSA_KEY_USAGE_DERIVE, PSA_ALG_CTR, PSA_KEY_DERIVATION_INPUT_SECRET,
- PSA_ALG_HKDF(PSA_ALG_SHA_256),
- BYTES_TO_BITS(AES_32B_KEY_SIZE), AES_32B_KEY_SIZE, PSA_ERROR_NOT_PERMITTED
+{
+ .test_desc = "Test psa_key_derivation_input_key incorrect key algorithm\n",
+ .type = PSA_KEY_TYPE_DERIVE,
+ .data = key_data,
+ .data_length = AES_32B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_32B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_CTR,
+ .step = PSA_KEY_DERIVATION_INPUT_SECRET,
+ .setup_alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .expected_status = PSA_ERROR_NOT_PERMITTED
},
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
#ifdef ARCH_TEST_RSA_2048
-{"Test psa_key_derivation_input_key 2048 RSA public key\n", PSA_KEY_TYPE_RSA_PUBLIC_KEY,
- {0},
- 270, 0, PSA_KEY_USAGE_DERIVE, PSA_ALG_HKDF(PSA_ALG_SHA_256), PSA_KEY_DERIVATION_INPUT_SECRET,
- PSA_ALG_HKDF(PSA_ALG_SHA_256),
- 2048, 270, PSA_ERROR_INVALID_ARGUMENT,
+{
+ .test_desc = "Test psa_key_derivation_input_key with key type as 2048 RSA public key\n",
+ .type = PSA_KEY_TYPE_RSA_PUBLIC_KEY,
+ .data = rsa_256_key_data,
+ .data_length = 270,
+ .bits = BYTES_TO_BITS(256),
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .step = PSA_KEY_DERIVATION_INPUT_SECRET,
+ .setup_alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT,
},
-{"Test psa_key_derivation_input_key with RSA 2048 keypair\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
- {0},
- 1193, 0, PSA_KEY_USAGE_DERIVE, PSA_ALG_HKDF(PSA_ALG_SHA_256), PSA_KEY_DERIVATION_INPUT_SECRET,
- PSA_ALG_HKDF(PSA_ALG_SHA_256),
- 2048, 1193, PSA_ERROR_INVALID_ARGUMENT,
+{
+ .test_desc = "Test psa_key_derivation_input_key with key type as RSA 2048 keypair\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_256_key_pair,
+ .data_length = 1193,
+ .bits = BYTES_TO_BITS(256),
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .step = PSA_KEY_DERIVATION_INPUT_SECRET,
+ .setup_alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT,
},
#endif
#endif
-{"Test psa_key_derivation_input_key with zero as step\n", PSA_KEY_TYPE_DERIVE,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0x77},
- AES_16B_KEY_SIZE, 0, PSA_KEY_USAGE_DERIVE, PSA_ALG_HKDF(PSA_ALG_SHA_256),
- 0, PSA_ALG_HKDF(PSA_ALG_SHA_256),
- BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
-},
-};
-
-static const test_data check2[] = {
-
-{"Test psa_key_derivation_input_key invalid handle\n", PSA_KEY_TYPE_DERIVE,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0x77},
- AES_16B_KEY_SIZE, 0, PSA_KEY_USAGE_DERIVE, PSA_ALG_HKDF(PSA_ALG_SHA_256),
- PSA_KEY_DERIVATION_INPUT_SECRET, PSA_ALG_HKDF(PSA_ALG_SHA_256),
- BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_ERROR_INVALID_HANDLE
+{
+ .test_desc = "Test psa_key_derivation_input_key with zero as step\n",
+ .type = PSA_KEY_TYPE_DERIVE,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .step = 0,
+ .setup_alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
};
diff --git a/api-tests/dev_apis/crypto/test_c019/test_c019.c b/api-tests/dev_apis/crypto/test_c019/test_c019.c
index 66cfa8d..1c0d2de 100644
--- a/api-tests/dev_apis/crypto/test_c019/test_c019.c
+++ b/api-tests/dev_apis/crypto/test_c019/test_c019.c
@@ -27,14 +27,15 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
+static int32_t valid_test_input_index = -1;
int32_t psa_key_derivation_key_agreement_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
+ psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
psa_key_handle_t key_handle;
if (num_checks == 0)
@@ -57,24 +58,26 @@
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].key_alg);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].alg);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage_flags);
/* Import the key data into the key slot */
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].key_data,
- check1[i].key_length, &key_handle);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Set up a key agreement operation */
- status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_SETUP, &operation,
- check1[i].key_alg);
+ status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_SETUP, &operation, check1[i].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Perform a key agreement */
- status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_KEY_AGREEMENT, &operation,
- check1[i].step, key_handle, check1[i].peer_key,
- check1[i].peer_key_length);
+ status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_KEY_AGREEMENT,
+ &operation,
+ check1[i].step,
+ key_handle,
+ check1[i].peer_key,
+ check1[i].peer_key_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(5));
/* Abort the key derivation operation */
@@ -90,6 +93,9 @@
/* Destroy a key and restore the slot to its default state */
status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(7));
+
+ if (valid_test_input_index < 0)
+ valid_test_input_index = i;
}
return VAL_STATUS_SUCCESS;
@@ -97,42 +103,52 @@
int32_t psa_key_derivation_key_agreement_negative_test(caller_security_t caller __UNUSED)
{
- int32_t i, status;
- int num_checks = sizeof(check2)/sizeof(check2[0]);
- psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
+ int32_t status;
+ psa_key_derivation_operation_t operation;
psa_key_handle_t key_handle = 8;
+ if (valid_test_input_index < 0)
+ return RESULT_SKIP(VAL_STATUS_NO_TESTS);
+
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
- for (i = 0; i < num_checks; i++)
- {
- /* Setting up the watchdog timer for each check */
- status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
- TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
+ /* Setting up the watchdog timer for each check */
+ status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
+ TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_SETUP, &operation,
- check2[i].key_alg);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
+ status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_SETUP, &operation,
+ check1[valid_test_input_index].alg);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
- val->print(PRINT_TEST, "[Check %d] Test psa_key_derivation_key_agreement "
- "- Invalid handle\n", g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] Test psa_key_derivation_key_agreement "
+ "- Invalid handle\n", g_test_count++);
- /* Set up a key agreement operation */
- status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_KEY_AGREEMENT, &operation,
- check2[i].step, key_handle, check2[i].peer_key,
- check2[i].peer_key_length);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(4));
+ /* Set up a key agreement operation */
+ status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_KEY_AGREEMENT,
+ &operation,
+ check1[valid_test_input_index].step,
+ key_handle,
+ check1[valid_test_input_index].peer_key,
+ check1[valid_test_input_index].peer_key_length);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(4));
- val->print(PRINT_TEST, "[Check %d] Test psa_key_derivation_key_agreement"
- " - Zero as handle\n", g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] Test psa_key_derivation_key_agreement"
+ " - Zero as handle\n", g_test_count++);
- /* Set up a key agreement operation */
- status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_KEY_AGREEMENT, &operation,
- check2[i].step, 0, check2[i].peer_key, check2[i].peer_key_length);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(5));
- }
+ /* Set up a key agreement operation */
+ status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_KEY_AGREEMENT,
+ &operation,
+ check1[valid_test_input_index].step,
+ 0,
+ check1[valid_test_input_index].peer_key,
+ check1[valid_test_input_index].peer_key_length);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(5));
+
+ /* Abort the key derivation operation */
+ status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_ABORT, &operation);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
return VAL_STATUS_SUCCESS;
}
diff --git a/api-tests/dev_apis/crypto/test_c019/test_data.h b/api-tests/dev_apis/crypto/test_c019/test_data.h
index 0e6f24b..7d32078 100644
--- a/api-tests/dev_apis/crypto/test_c019/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c019/test_data.h
@@ -15,17 +15,17 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[85];
- psa_key_type_t key_type;
- uint8_t key_data[91];
- uint32_t key_length;
- psa_key_usage_t usage;
- psa_algorithm_t key_alg;
+ psa_key_type_t type;
+ const uint8_t *data;
+ size_t data_length;
+ psa_key_usage_t usage_flags;
+ psa_algorithm_t alg;
psa_key_derivation_step_t step;
- uint8_t peer_key[120];
+ const uint8_t *peer_key;
size_t peer_key_length;
psa_status_t expected_status;
} test_data;
@@ -34,75 +34,61 @@
static const test_data check1[] = {
#ifdef ARCH_TEST_ECDH
#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
-{"Test psa_key_derivation_key_agreement - ECDH SECP256R1\n",
- PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP256R1),
-{0xc8, 0x8f, 0x01, 0xf5, 0x10, 0xd9, 0xac, 0x3f, 0x70, 0xa2, 0x92, 0xda, 0xa2,
- 0x31, 0x6d, 0xe5, 0x44, 0xe9, 0xaa, 0xb8, 0xaf, 0xe8, 0x40, 0x49, 0xc6, 0x2a,
- 0x9c, 0x57, 0x86, 0x2d, 0x14, 0x33}, 32, PSA_KEY_USAGE_DERIVE,
- PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
- PSA_KEY_DERIVATION_INPUT_SECRET,
-{0x04, 0xd1, 0x2d, 0xfb, 0x52, 0x89, 0xc8, 0xd4, 0xf8, 0x12, 0x08, 0xb7, 0x02,
- 0x70, 0x39, 0x8c, 0x34, 0x22, 0x96, 0x97, 0x0a, 0x0b, 0xcc, 0xb7, 0x4c, 0x73,
- 0x6f, 0xc7, 0x55, 0x44, 0x94, 0xbf, 0x63, 0x56, 0xfb, 0xf3, 0xca, 0x36, 0x6c,
- 0xc2, 0x3e, 0x81, 0x57, 0x85, 0x4c, 0x13, 0xc5, 0x8d, 0x6a, 0xac, 0x23, 0xf0,
- 0x46, 0xad, 0xa3, 0x0f, 0x83, 0x53, 0xe7, 0x4f, 0x33, 0x03, 0x98, 0x72, 0xab},
- 65, PSA_SUCCESS
+{
+ .test_desc = "Test psa_key_derivation_key_agreement - ECDH SECP256R1\n",
+ .type = PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP256R1),
+ .data = ecdh_secp_256_r1_prv_key,
+ .data_length = ECDH_SECP_256_R1_PRV_KEY_LEN,
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
+ .step = PSA_KEY_DERIVATION_INPUT_SECRET,
+ .peer_key = ecdh_secp_256_r1_pub_key,
+ .peer_key_length = ECDH_SECP_256_R1_PUB_KEY_LEN,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_key_derivation_key_agreement - Invalid step\n",
- PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP256R1),
-{0xc8, 0x8f, 0x01, 0xf5, 0x10, 0xd9, 0xac, 0x3f, 0x70, 0xa2, 0x92, 0xda, 0xa2,
- 0x31, 0x6d, 0xe5, 0x44, 0xe9, 0xaa, 0xb8, 0xaf, 0xe8, 0x40, 0x49, 0xc6, 0x2a,
- 0x9c, 0x57, 0x86, 0x2d, 0x14, 0x33}, 32, PSA_KEY_USAGE_DERIVE,
- PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
- PSA_KEY_DERIVATION_INPUT_LABEL,
-{0x04, 0xd1, 0x2d, 0xfb, 0x52, 0x89, 0xc8, 0xd4, 0xf8, 0x12, 0x08, 0xb7, 0x02,
- 0x70, 0x39, 0x8c, 0x34, 0x22, 0x96, 0x97, 0x0a, 0x0b, 0xcc, 0xb7, 0x4c, 0x73,
- 0x6f, 0xc7, 0x55, 0x44, 0x94, 0xbf, 0x63, 0x56, 0xfb, 0xf3, 0xca, 0x36, 0x6c,
- 0xc2, 0x3e, 0x81, 0x57, 0x85, 0x4c, 0x13, 0xc5, 0x8d, 0x6a, 0xac, 0x23, 0xf0,
- 0x46, 0xad, 0xa3, 0x0f, 0x83, 0x53, 0xe7, 0x4f, 0x33, 0x03, 0x98, 0x72, 0xab},
- 65, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_key_derivation_key_agreement - Invalid step\n",
+ .type = PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP256R1),
+ .data = ecdh_secp_256_r1_prv_key,
+ .data_length = ECDH_SECP_256_R1_PRV_KEY_LEN,
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
+ .step = PSA_KEY_DERIVATION_INPUT_LABEL,
+ .peer_key = ecdh_secp_256_r1_pub_key,
+ .peer_key_length = ECDH_SECP_256_R1_PUB_KEY_LEN,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#ifdef ARCH_TEST_ECC_CURVE_SECP384R1
-{"Test psa_key_derivation_key_agreement - ECDH SECP384R1\n",
- PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP384R1),
-{0x09, 0x9f, 0x3c, 0x70, 0x34, 0xd4, 0xa2, 0xc6, 0x99, 0x88, 0x4d, 0x73, 0xa3,
- 0x75, 0xa6, 0x7f, 0x76, 0x24, 0xef, 0x7c, 0x6b, 0x3c, 0x0f, 0x16, 0x06, 0x47,
- 0xb6, 0x74, 0x14, 0xdc, 0xe6, 0x55, 0xe3, 0x5b, 0x53, 0x80, 0x41, 0xe6, 0x49,
- 0xee, 0x3f, 0xae, 0xf8, 0x96, 0x78, 0x3a, 0xb1, 0x94}, 48, PSA_KEY_USAGE_DERIVE,
- PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
- PSA_KEY_DERIVATION_INPUT_SECRET,
-{0x04, 0xe5, 0x58,
- 0xdb, 0xef, 0x53, 0xee, 0xcd, 0xe3, 0xd3, 0xfc, 0xcf, 0xc1, 0xae, 0xa0, 0x8a,
- 0x89, 0xa9, 0x87, 0x47, 0x5d, 0x12, 0xfd, 0x95, 0x0d, 0x83, 0xcf, 0xa4, 0x17,
- 0x32, 0xbc, 0x50, 0x9d, 0x0d, 0x1a, 0xc4, 0x3a, 0x03, 0x36, 0xde, 0xf9, 0x6f,
- 0xda, 0x41, 0xd0, 0x77, 0x4a, 0x35, 0x71, 0xdc, 0xfb, 0xec, 0x7a, 0xac, 0xf3,
- 0x19, 0x64, 0x72, 0x16, 0x9e, 0x83, 0x84, 0x30, 0x36, 0x7f, 0x66, 0xee, 0xbe,
- 0x3c, 0x6e, 0x70, 0xc4, 0x16, 0xdd, 0x5f, 0x0c, 0x68, 0x75, 0x9d, 0xd1, 0xff,
- 0xf8, 0x3f, 0xa4, 0x01, 0x42, 0x20, 0x9d, 0xff, 0x5e, 0xaa, 0xd9, 0x6d, 0xb9,
- 0xe6, 0x38, 0x6c}, 97,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_key_derivation_key_agreement - ECDH SECP384R1\n",
+ .type = PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP384R1),
+ .data = ecdh_secp_384_r1_prv_key,
+ .data_length = ECDH_SECP_384_R1_PRV_KEY_LEN,
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
+ .step = PSA_KEY_DERIVATION_INPUT_SECRET,
+ .peer_key = ecdh_secp_384_r1_pub_key,
+ .peer_key_length = ECDH_SECP_384_R1_PUB_KEY_LEN,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
-{"Test psa_key_derivation_key_agreement - Invalid usage\n",
- PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP256R1),
-{0xc8, 0x8f, 0x01, 0xf5, 0x10, 0xd9, 0xac, 0x3f, 0x70, 0xa2, 0x92, 0xda, 0xa2,
- 0x31, 0x6d, 0xe5, 0x44, 0xe9, 0xaa, 0xb8, 0xaf, 0xe8, 0x40, 0x49, 0xc6, 0x2a,
- 0x9c, 0x57, 0x86, 0x2d, 0x14, 0x33}, 32, PSA_KEY_USAGE_ENCRYPT,
- PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
- PSA_KEY_DERIVATION_INPUT_SECRET,
-{0x04, 0xd1, 0x2d, 0xfb, 0x52, 0x89, 0xc8, 0xd4, 0xf8, 0x12, 0x08, 0xb7, 0x02,
- 0x70, 0x39, 0x8c, 0x34, 0x22, 0x96, 0x97, 0x0a, 0x0b, 0xcc, 0xb7, 0x4c, 0x73,
- 0x6f, 0xc7, 0x55, 0x44, 0x94, 0xbf, 0x63, 0x56, 0xfb, 0xf3, 0xca, 0x36, 0x6c,
- 0xc2, 0x3e, 0x81, 0x57, 0x85, 0x4c, 0x13, 0xc5, 0x8d, 0x6a, 0xac, 0x23, 0xf0,
- 0x46, 0xad, 0xa3, 0x0f, 0x83, 0x53, 0xe7, 0x4f, 0x33, 0x03, 0x98, 0x72, 0xab},
- 65,
- PSA_ERROR_NOT_PERMITTED
+{
+ .test_desc = "Test psa_key_derivation_key_agreement - Invalid usage\n",
+ .type = PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP256R1),
+ .data = ecdh_secp_256_r1_prv_key,
+ .data_length = ECDH_SECP_256_R1_PRV_KEY_LEN,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
+ .step = PSA_KEY_DERIVATION_INPUT_SECRET,
+ .peer_key = ecdh_secp_256_r1_pub_key,
+ .peer_key_length = ECDH_SECP_256_R1_PUB_KEY_LEN,
+ .expected_status = PSA_ERROR_NOT_PERMITTED
},
#endif
#endif
@@ -110,81 +96,46 @@
#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
#ifdef ARCH_TEST_SHA256
#ifdef ARCH_TEST_HKDF
-{"Test psa_key_derivation_key_agreement - KDF instead of a key agreement algorithm\n",
- PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP256R1),
-{0xc8, 0x8f, 0x01, 0xf5, 0x10, 0xd9, 0xac, 0x3f, 0x70, 0xa2, 0x92, 0xda, 0xa2,
- 0x31, 0x6d, 0xe5, 0x44, 0xe9, 0xaa, 0xb8, 0xaf, 0xe8, 0x40, 0x49, 0xc6, 0x2a,
- 0x9c, 0x57, 0x86, 0x2d, 0x14, 0x33}, 32, PSA_KEY_USAGE_DERIVE, PSA_ALG_HKDF(PSA_ALG_SHA_256),
- PSA_KEY_DERIVATION_INPUT_SECRET,
-{0x04, 0xd1, 0x2d, 0xfb, 0x52, 0x89, 0xc8, 0xd4, 0xf8, 0x12, 0x08, 0xb7, 0x02,
- 0x70, 0x39, 0x8c, 0x34, 0x22, 0x96, 0x97, 0x0a, 0x0b, 0xcc, 0xb7, 0x4c, 0x73,
- 0x6f, 0xc7, 0x55, 0x44, 0x94, 0xbf, 0x63, 0x56, 0xfb, 0xf3, 0xca, 0x36, 0x6c,
- 0xc2, 0x3e, 0x81, 0x57, 0x85, 0x4c, 0x13, 0xc5, 0x8d, 0x6a, 0xac, 0x23, 0xf0,
- 0x46, 0xad, 0xa3, 0x0f, 0x83, 0x53, 0xe7, 0x4f, 0x33, 0x03, 0x98, 0x72, 0xab},
- 65,
- PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_key_derivation_key_agreement - KDF not a key agreement alg\n",
+ .type = PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP256R1),
+ .data = ecdh_secp_256_r1_prv_key,
+ .data_length = ECDH_SECP_256_R1_PRV_KEY_LEN,
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .step = PSA_KEY_DERIVATION_INPUT_SECRET,
+ .peer_key = ecdh_secp_256_r1_pub_key,
+ .peer_key_length = ECDH_SECP_256_R1_PUB_KEY_LEN,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
#ifdef ARCH_TEST_ECDH
-{"Test psa_key_derivation_key_agreement - Public key on different curve\n",
- PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP256R1),
-{0xc8, 0x8f, 0x01, 0xf5, 0x10, 0xd9, 0xac, 0x3f, 0x70, 0xa2, 0x92, 0xda, 0xa2,
- 0x31, 0x6d, 0xe5, 0x44, 0xe9, 0xaa, 0xb8, 0xaf, 0xe8, 0x40, 0x49, 0xc6, 0x2a,
- 0x9c, 0x57, 0x86, 0x2d, 0x14, 0x33}, 32, PSA_KEY_USAGE_DERIVE,
- PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
- PSA_KEY_DERIVATION_INPUT_SECRET,
-{0x04, 0xe5, 0x58,
- 0xdb, 0xef, 0x53, 0xee, 0xcd, 0xe3, 0xd3, 0xfc, 0xcf, 0xc1, 0xae, 0xa0, 0x8a,
- 0x89, 0xa9, 0x87, 0x47, 0x5d, 0x12, 0xfd, 0x95, 0x0d, 0x83, 0xcf, 0xa4, 0x17,
- 0x32, 0xbc, 0x50, 0x9d, 0x0d, 0x1a, 0xc4, 0x3a, 0x03, 0x36, 0xde, 0xf9, 0x6f,
- 0xda, 0x41, 0xd0, 0x77, 0x4a, 0x35, 0x71, 0xdc, 0xfb, 0xec, 0x7a, 0xac, 0xf3,
- 0x19, 0x64, 0x72, 0x16, 0x9e, 0x83, 0x84, 0x30, 0x36, 0x7f, 0x66, 0xee, 0xbe,
- 0x3c, 0x6e, 0x70, 0xc4, 0x16, 0xdd, 0x5f, 0x0c, 0x68, 0x75, 0x9d, 0xd1, 0xff,
- 0xf8, 0x3f, 0xa4, 0x01, 0x42, 0x20, 0x9d, 0xff, 0x5e, 0xaa, 0xd9, 0x6d, 0xb9,
- 0xe6, 0x38, 0x6c}, 97,
- PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_key_derivation_key_agreement - Public key of different curve\n",
+ .type = PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP256R1),
+ .data = ecdh_secp_256_r1_prv_key,
+ .data_length = ECDH_SECP_256_R1_PRV_KEY_LEN,
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
+ .step = PSA_KEY_DERIVATION_INPUT_SECRET,
+ .peer_key = ecdh_secp_384_r1_pub_key,
+ .peer_key_length = ECDH_SECP_384_R1_PUB_KEY_LEN,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
-{"Test psa_key_derivation_key_agreement - Public key instead of private key\n",
- PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
-{0x04, 0xd1, 0x2d, 0xfb, 0x52, 0x89, 0xc8, 0xd4, 0xf8, 0x12, 0x08, 0xb7, 0x02,
- 0x70, 0x39, 0x8c, 0x34, 0x22, 0x96, 0x97, 0x0a, 0x0b, 0xcc, 0xb7, 0x4c, 0x73,
- 0x6f, 0xc7, 0x55, 0x44, 0x94, 0xbf, 0x63, 0x56, 0xfb, 0xf3, 0xca, 0x36, 0x6c,
- 0xc2, 0x3e, 0x81, 0x57, 0x85, 0x4c, 0x13, 0xc5, 0x8d, 0x6a, 0xac, 0x23, 0xf0,
- 0x46, 0xad, 0xa3, 0x0f, 0x83, 0x53, 0xe7, 0x4f, 0x33, 0x03, 0x98, 0x72, 0xab},
- 65, PSA_KEY_USAGE_DERIVE,
- PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
- PSA_KEY_DERIVATION_INPUT_SECRET,
-{0x04, 0xd1, 0x2d, 0xfb, 0x52, 0x89, 0xc8, 0xd4, 0xf8, 0x12, 0x08, 0xb7, 0x02,
- 0x70, 0x39, 0x8c, 0x34, 0x22, 0x96, 0x97, 0x0a, 0x0b, 0xcc, 0xb7, 0x4c, 0x73,
- 0x6f, 0xc7, 0x55, 0x44, 0x94, 0xbf, 0x63, 0x56, 0xfb, 0xf3, 0xca, 0x36, 0x6c,
- 0xc2, 0x3e, 0x81, 0x57, 0x85, 0x4c, 0x13, 0xc5, 0x8d, 0x6a, 0xac, 0x23, 0xf0,
- 0x46, 0xad, 0xa3, 0x0f, 0x83, 0x53, 0xe7, 0x4f, 0x33, 0x03, 0x98, 0x72, 0xab},
- 65, PSA_ERROR_INVALID_ARGUMENT
-},
-#endif
-#endif
-};
-
-static const test_data check2[] = {
-#ifdef ARCH_TEST_ECDH
-#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
-{"Test psa_key_derivation_key_agreement - Negative case\n",
- PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP256R1),
-{0xc8, 0x8f, 0x01, 0xf5, 0x10, 0xd9, 0xac, 0x3f, 0x70, 0xa2, 0x92, 0xda, 0xa2,
- 0x31, 0x6d, 0xe5, 0x44, 0xe9, 0xaa, 0xb8, 0xaf, 0xe8, 0x40, 0x49, 0xc6, 0x2a,
- 0x9c, 0x57, 0x86, 0x2d, 0x14, 0x33}, 32, PSA_KEY_USAGE_DERIVE,
- PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
- PSA_KEY_DERIVATION_INPUT_SECRET,
-{0x04, 0xd1, 0x2d, 0xfb, 0x52, 0x89, 0xc8, 0xd4, 0xf8, 0x12, 0x08, 0xb7, 0x02,
- 0x70, 0x39, 0x8c, 0x34, 0x22, 0x96, 0x97, 0x0a, 0x0b, 0xcc, 0xb7, 0x4c, 0x73,
- 0x6f, 0xc7, 0x55, 0x44, 0x94, 0xbf, 0x63, 0x56, 0xfb, 0xf3, 0xca, 0x36, 0x6c,
- 0xc2, 0x3e, 0x81, 0x57, 0x85, 0x4c, 0x13, 0xc5, 0x8d, 0x6a, 0xac, 0x23, 0xf0,
- 0x46, 0xad, 0xa3, 0x0f, 0x83, 0x53, 0xe7, 0x4f, 0x33, 0x03, 0x98, 0x72, 0xab},
- 65,
- PSA_ERROR_INVALID_HANDLE
+{
+ .test_desc = "Test psa_key_derivation_key_agreement - Pub key instead of Prv key\n",
+ .type = PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
+ .data = ecdh_secp_256_r1_pub_key,
+ .data_length = ECDH_SECP_256_R1_PUB_KEY_LEN,
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
+ .step = PSA_KEY_DERIVATION_INPUT_SECRET,
+ .peer_key = ecdh_secp_256_r1_pub_key,
+ .peer_key_length = ECDH_SECP_256_R1_PUB_KEY_LEN,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
diff --git a/api-tests/dev_apis/crypto/test_c020/test_c020.c b/api-tests/dev_apis/crypto/test_c020/test_c020.c
index 166841a..12c2bfc 100644
--- a/api-tests/dev_apis/crypto/test_c020/test_c020.c
+++ b/api-tests/dev_apis/crypto/test_c020/test_c020.c
@@ -19,7 +19,6 @@
#include "val_target.h"
#include "test_c020.h"
#include "test_data.h"
-#include "val_crypto.h"
const client_test_t test_c020_crypto_list[] = {
NULL,
@@ -27,17 +26,14 @@
NULL,
};
-static int g_test_count = 1;
-static uint8_t output[BUFFER_SIZE];
-
int32_t psa_key_derivation_output_bytes_test(caller_security_t caller __UNUSED)
{
int32_t status;
- int i;
- int num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t i, inIdx;
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
- psa_key_handle_t key_handle;
+ psa_key_derivation_operation_t operation;
+ psa_key_handle_t handle;
if (num_checks == 0)
{
@@ -51,87 +47,75 @@
for (i = 0; i < num_checks; i++)
{
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] ", i+1);
val->print(PRINT_TEST, check1[i].test_desc, 0);
+ memset(&operation, 0, sizeof(operation));
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- /* Import the key if the derivation input is key */
- if (check1[i].step == PSA_KEY_DERIVATION_INPUT_SECRET)
- {
- /* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].key_alg);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage);
+ /* Setup the attributes for the key */
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].alg);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage_flags);
- /* Import the key data into the key slot */
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].key_data,
- check1[i].key_length, &key_handle);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
- }
+ /* Import the key data into the key slot */
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &handle);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Start the key derivation operation */
- status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_SETUP, &operation,
- check1[i].key_alg);
+ status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_SETUP, &operation, check1[i].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Set the capacity for the generator */
status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_SET_CAPACITY, &operation,
- check1[i].capacity);
+ check1[i].capacity);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
- /* Provide input as key or data depending on the step */
- if (check1[i].step == PSA_KEY_DERIVATION_INPUT_SECRET)
+ /* Loop through the available steps */
+ /* Provide an input for key derivation or key agreement */
+ for (inIdx = 0; inIdx < DERIVATION_INPUT_CNT; inIdx++)
{
- /* Provide an input for key derivation or key agreement */
- status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_INPUT_KEY, &operation,
- check1[i].step, key_handle);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
- }
- else
- {
- status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_INPUT_BYTES, &operation,
- check1[i].step, check1[i].data, check1[i].data_length);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(7));
+ if ((check1[i].derv_inputs[inIdx].step == 0) &&
+ (check1[i].derv_inputs[inIdx].data == NULL) &&
+ (check1[i].derv_inputs[inIdx].data_length == 0))
+ continue;
+
+ if (check1[i].derv_inputs[inIdx].step == PSA_KEY_DERIVATION_INPUT_SECRET)
+ {
+ status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_INPUT_KEY, &operation,
+ check1[i].derv_inputs[inIdx].step, handle);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
+ } else {
+ status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_INPUT_BYTES, &operation,
+ check1[i].derv_inputs[inIdx].step,
+ check1[i].derv_inputs[inIdx].data,
+ check1[i].derv_inputs[inIdx].data_length);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(7));
+ }
}
/* Read some data from a key derivation operation */
- status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_OUTPUT_BYTES, &operation, output,
- check1[i].output_size);
+ status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_OUTPUT_BYTES, &operation,
+ check1[i].output, check1[i].output_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(8));
- if (check1[i].step == PSA_KEY_DERIVATION_INPUT_SECRET)
- {
- status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, key_handle);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(9));
+ status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, handle);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(9));
- /* Reset the key attributes and check if psa_import_key fails */
- val->crypto_function(VAL_CRYPTO_RESET_KEY_ATTRIBUTES, &attributes);
- }
-
- if (check1[i].expected_status != PSA_SUCCESS)
- {
- status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_ABORT, &operation);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(10));
-
- continue;
- }
-
- /* Read some data from a key derivation operation with no data in the operation */
- status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_OUTPUT_BYTES, &operation, output,
- check1[i].output_size);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_INSUFFICIENT_DATA, TEST_CHECKPOINT_NUM(11));
+ /* Reset the key attributes */
+ val->crypto_function(VAL_CRYPTO_RESET_KEY_ATTRIBUTES, &attributes);
/* Abort the derivation operation */
status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_ABORT, &operation);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(12));
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(10));
/* Expect bad state when derivation is called on an aborted operation */
status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_OUTPUT_BYTES, &operation,
- output, 0);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(13));
+ check1[i].output, check1[i].output_length);
+ 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_c020/test_data.h b/api-tests/dev_apis/crypto/test_c020/test_data.h
index 5490e70..4f279dc 100644
--- a/api-tests/dev_apis/crypto/test_c020/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c020/test_data.h
@@ -15,51 +15,268 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
+
+#define DERIVATION_INPUT_CNT 3
+
+typedef struct {
+ psa_key_derivation_step_t step;
+ const uint8_t *data;
+ size_t data_length;
+} key_derivation_input_t;
typedef struct {
char test_desc[75];
- psa_key_type_t key_type;
- uint8_t key_data[34];
- uint32_t key_length;
- size_t output_size;
- psa_key_usage_t usage;
- psa_algorithm_t key_alg;
- psa_key_derivation_step_t step;
+ psa_key_type_t type;
+ psa_key_usage_t usage_flags;
+ psa_algorithm_t alg;
size_t capacity;
- uint8_t data[16];
+ const uint8_t *data;
size_t data_length;
+ key_derivation_input_t derv_inputs[DERIVATION_INPUT_CNT];
+ uint8_t *output;
+ size_t output_length;
psa_status_t expected_status;
} test_data;
static const test_data check1[] = {
-{"Test psa_key_derivation_output_bytes - Key\n", PSA_KEY_TYPE_DERIVE,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0x77},
- AES_16B_KEY_SIZE, 42, PSA_KEY_USAGE_DERIVE,
- PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
- PSA_KEY_DERIVATION_INPUT_SECRET, 42, {0}, 0,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_key_derivation_output_bytes - HKDF\n",
+ .type = PSA_KEY_TYPE_DERIVE,
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
+ .capacity = 42,
+ .data = input_bytes_data,
+ .data_length = INPUT_BYTES_DATA_LEN,
+ .derv_inputs = {
+ {
+ .step = PSA_KEY_DERIVATION_INPUT_SALT,
+ .data = input_salt,
+ .data_length = INPUT_SALT_LEN
+ },
+ {
+ .step = PSA_KEY_DERIVATION_INPUT_SECRET,
+ .data = NULL,
+ .data_length = 0
+ },
+ {
+ .step = PSA_KEY_DERIVATION_INPUT_INFO,
+ .data = input_info,
+ .data_length = INPUT_INFO_LEN
+ }
+ },
+ .output = expected_output,
+ .output_length = 42,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_key_derivation_output_bytes - Info\n", PSA_KEY_TYPE_DERIVE,
-{0}, 0, 42, 0, PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
- PSA_KEY_DERIVATION_INPUT_INFO, 42, "This is the info", 16,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_key_derivation_output_bytes - optional salt\n",
+ .type = PSA_KEY_TYPE_DERIVE,
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
+ .capacity = 42,
+ .data = input_bytes_data,
+ .data_length = INPUT_BYTES_DATA_LEN,
+ .derv_inputs = {
+ {
+ .step = PSA_KEY_DERIVATION_INPUT_SECRET,
+ .data = NULL,
+ .data_length = 0
+ },
+ {
+ .step = PSA_KEY_DERIVATION_INPUT_INFO,
+ .data = input_info,
+ .data_length = INPUT_INFO_LEN
+ },
+ {
+ .step = 0,
+ .data = NULL,
+ .data_length = 0
+ },
+ },
+ .output = expected_output,
+ .output_length = 42,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_key_derivation_output_bytes - Salt\n", PSA_KEY_TYPE_DERIVE,
-{0}, 0, 42, 0, PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
- PSA_KEY_DERIVATION_INPUT_SALT, 42, "This is the info", 16,
- PSA_ERROR_BAD_STATE
+{
+ .test_desc = "Test psa_key_derivation_output_bytes - capacity < output_length\n",
+ .type = PSA_KEY_TYPE_DERIVE,
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
+ .capacity = 42,
+ .data = input_bytes_data,
+ .data_length = INPUT_BYTES_DATA_LEN,
+ .derv_inputs = {
+ {
+ .step = PSA_KEY_DERIVATION_INPUT_SALT,
+ .data = input_salt,
+ .data_length = INPUT_SALT_LEN
+ },
+ {
+ .step = PSA_KEY_DERIVATION_INPUT_SECRET,
+ .data = NULL,
+ .data_length = 0
+ },
+ {
+ .step = PSA_KEY_DERIVATION_INPUT_INFO,
+ .data = input_info,
+ .data_length = INPUT_INFO_LEN
+ }
+ },
+ .output = expected_output,
+ .output_length = 43,
+ .expected_status = PSA_ERROR_INSUFFICIENT_DATA
},
-{"Test psa_key_derivation_output_bytes - Greater Capacity than available\n", PSA_KEY_TYPE_DERIVE,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0x77},
- AES_16B_KEY_SIZE, BUFFER_SIZE, PSA_KEY_USAGE_DERIVE,
- PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
- PSA_KEY_DERIVATION_INPUT_SECRET, 42, {0}, 0,
- PSA_ERROR_INSUFFICIENT_DATA,
+{
+ .test_desc = "Test psa_key_derivation_output_bytes - missing info\n",
+ .type = PSA_KEY_TYPE_DERIVE,
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
+ .capacity = 42,
+ .data = input_bytes_data,
+ .data_length = INPUT_BYTES_DATA_LEN,
+ .derv_inputs = {
+ {
+ .step = PSA_KEY_DERIVATION_INPUT_SALT,
+ .data = input_salt,
+ .data_length = INPUT_SALT_LEN
+ },
+ {
+ .step = PSA_KEY_DERIVATION_INPUT_SECRET,
+ .data = NULL,
+ .data_length = 0
+ },
+ {
+ .step = 0,
+ .data = NULL,
+ .data_length = 0
+ },
+ },
+ .output = expected_output,
+ .output_length = 42,
+ .expected_status = PSA_ERROR_BAD_STATE
+},
+
+{
+ .test_desc = "Test psa_key_derivation_output_bytes - missing salt/secret/info\n",
+ .type = PSA_KEY_TYPE_DERIVE,
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
+ .capacity = 42,
+ .data = input_bytes_data,
+ .data_length = INPUT_BYTES_DATA_LEN,
+ .derv_inputs = {
+ {
+ .step = 0,
+ .data = NULL,
+ .data_length = 0
+ },
+ {
+ .step = 0,
+ .data = NULL,
+ .data_length = 0
+ },
+ {
+ .step = 0,
+ .data = NULL,
+ .data_length = 0
+ },
+ },
+ .output = expected_output,
+ .output_length = 42,
+ .expected_status = PSA_ERROR_BAD_STATE
+},
+
+{
+ .test_desc = "Test psa_key_derivation_output_bytes - TLS12_PRF\n",
+ .type = PSA_KEY_TYPE_DERIVE,
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_TLS12_PRF(PSA_ALG_SHA_256)),
+ .capacity = 42,
+ .data = input_bytes_data,
+ .data_length = INPUT_BYTES_DATA_LEN,
+ .derv_inputs = {
+ {
+ .step = PSA_KEY_DERIVATION_INPUT_SEED,
+ .data = input_seed,
+ .data_length = INPUT_SEED_LEN
+ },
+ {
+ .step = PSA_KEY_DERIVATION_INPUT_SECRET,
+ .data = NULL,
+ .data_length = 0
+ },
+ {
+ .step = PSA_KEY_DERIVATION_INPUT_LABEL,
+ .data = input_label,
+ .data_length = INPUT_LABEL_LEN
+ },
+ },
+ .output = expected_output,
+ .output_length = 42,
+ .expected_status = PSA_SUCCESS
+},
+
+{
+ .test_desc = "Test psa_key_derivation_output_bytes - capacity < output_length\n",
+ .type = PSA_KEY_TYPE_DERIVE,
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_TLS12_PRF(PSA_ALG_SHA_256)),
+ .capacity = 42,
+ .data = input_bytes_data,
+ .data_length = INPUT_BYTES_DATA_LEN,
+ .derv_inputs = {
+ {
+ .step = PSA_KEY_DERIVATION_INPUT_SEED,
+ .data = input_seed,
+ .data_length = INPUT_SEED_LEN
+ },
+ {
+ .step = PSA_KEY_DERIVATION_INPUT_SECRET,
+ .data = NULL,
+ .data_length = 0
+ },
+ {
+ .step = PSA_KEY_DERIVATION_INPUT_LABEL,
+ .data = input_label,
+ .data_length = INPUT_LABEL_LEN
+ },
+ },
+ .output = expected_output,
+ .output_length = 43,
+ .expected_status = PSA_ERROR_INSUFFICIENT_DATA
+},
+
+{
+ .test_desc = "Test psa_key_derivation_output_bytes - missing seed/secret/label\n",
+ .type = PSA_KEY_TYPE_DERIVE,
+ .usage_flags = PSA_KEY_USAGE_DERIVE,
+ .alg = PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_TLS12_PRF(PSA_ALG_SHA_256)),
+ .capacity = 42,
+ .data = input_bytes_data,
+ .data_length = INPUT_BYTES_DATA_LEN,
+ .derv_inputs = {
+ {
+ .step = 0,
+ .data = NULL,
+ .data_length = 0
+ },
+ {
+ .step = 0,
+ .data = NULL,
+ .data_length = 0
+ },
+ {
+ .step = 0,
+ .data = NULL,
+ .data_length = 0
+ },
+ },
+ .output = expected_output,
+ .output_length = 42,
+ .expected_status = PSA_ERROR_BAD_STATE
},
};
diff --git a/api-tests/dev_apis/crypto/test_c021/test_c021.c b/api-tests/dev_apis/crypto/test_c021/test_c021.c
index 79ade63..2c0aef7 100644
--- a/api-tests/dev_apis/crypto/test_c021/test_c021.c
+++ b/api-tests/dev_apis/crypto/test_c021/test_c021.c
@@ -30,7 +30,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
int32_t psa_key_derivation_output_key_test(caller_security_t caller __UNUSED)
{
diff --git a/api-tests/dev_apis/crypto/test_c021/test_data.h b/api-tests/dev_apis/crypto/test_c021/test_data.h
index afd806a..706f8e3 100644
--- a/api-tests/dev_apis/crypto/test_c021/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c021/test_data.h
@@ -75,7 +75,7 @@
AES_16B_KEY_SIZE, PSA_KEY_USAGE_DERIVE,
PSA_ALG_KEY_AGREEMENT(PSA_ALG_ECDH, PSA_ALG_HKDF(PSA_ALG_SHA_256)),
PSA_KEY_DERIVATION_INPUT_SECRET, 32, {0}, 0,
- PSA_KEY_TYPE_DES, BYTES_TO_BITS(DES3_3KEY_SIZE), PSA_KEY_USAGE_EXPORT,
+ PSA_KEY_TYPE_DES, BYTES_TO_BITS(DES3_3B_KEY_SIZE), PSA_KEY_USAGE_EXPORT,
PSA_ALG_CTR,
PSA_SUCCESS
},
diff --git a/api-tests/dev_apis/crypto/test_c022/test_c022.c b/api-tests/dev_apis/crypto/test_c022/test_c022.c
index cc57ee0..d26c47c 100644
--- a/api-tests/dev_apis/crypto/test_c022/test_c022.c
+++ b/api-tests/dev_apis/crypto/test_c022/test_c022.c
@@ -19,8 +19,6 @@
#include "val_target.h"
#include "test_c022.h"
#include "test_data.h"
-#include "val_crypto.h"
-
const client_test_t test_c022_crypto_list[] = {
NULL,
@@ -28,12 +26,9 @@
NULL,
};
-static int g_test_count = 1;
-static uint8_t output[BUFFER_SIZE];
-
int32_t psa_key_derivation_abort_test(caller_security_t caller __UNUSED)
{
- int32_t status;
+ int32_t status, i;
psa_key_derivation_operation_t func = psa_key_derivation_operation_init();
psa_key_derivation_operation_t init = PSA_KEY_DERIVATION_OPERATION_INIT;
psa_key_derivation_operation_t zero;
@@ -48,7 +43,8 @@
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
+ i = 1;
+ val->print(PRINT_TEST, "[Check %d] ", i++);
val->print(PRINT_TEST, "Test psa_key_derivation_abort\n", 0);
status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_ABORT, &func);
@@ -61,7 +57,7 @@
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Read some data from a key derivation operation with no data in the operation */
- status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_OUTPUT_BYTES, &func, output,
+ status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_OUTPUT_BYTES, &func, expected_output,
BUFFER_SIZE);
TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(6));
diff --git a/api-tests/dev_apis/crypto/test_c022/test_data.h b/api-tests/dev_apis/crypto/test_c022/test_data.h
index dc0c03e..95253ba 100644
--- a/api-tests/dev_apis/crypto/test_c022/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c022/test_data.h
@@ -1,5 +1,5 @@
/** @file
- * Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
+ * Copyright (c) 2019-2020, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,6 +15,6 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
/* Keeping this file empty incase if future support is needed */
diff --git a/api-tests/dev_apis/crypto/test_c023/test_c023.c b/api-tests/dev_apis/crypto/test_c023/test_c023.c
index 96a40fd..06d30d5 100644
--- a/api-tests/dev_apis/crypto/test_c023/test_c023.c
+++ b/api-tests/dev_apis/crypto/test_c023/test_c023.c
@@ -19,7 +19,6 @@
#include "val_target.h"
#include "test_c023.h"
#include "test_data.h"
-#include "val_crypto.h"
const client_test_t test_c023_crypto_list[] = {
NULL,
@@ -27,14 +26,12 @@
NULL,
};
-static int g_test_count = 1;
-
int32_t psa_key_derivation_set_get_capacity_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check1)/sizeof(check1[0]);
- int32_t i, status;
- size_t capacity = 0;
- psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t i, status;
+ size_t get_capacity = 0;
+ psa_key_derivation_operation_t operation;
if (num_checks == 0)
{
@@ -48,8 +45,9 @@
for (i = 0; i < num_checks; i++)
{
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] ", i+1);
val->print(PRINT_TEST, check1[i].test_desc, 0);
+ memset(&operation, 0, sizeof(operation));
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
@@ -57,12 +55,12 @@
/* Start the key derivation operation */
status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_SETUP, &operation,
- check1[i].key_alg);
+ check1[i].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Set the capacity for the generator */
status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_SET_CAPACITY, &operation,
- check1[i].capacity);
+ check1[i].capacity);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(4));
if (check1[i].expected_status != PSA_SUCCESS)
@@ -74,11 +72,11 @@
/* Get the capacity for the generator */
status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_GET_CAPACITY, &operation,
- &capacity);
+ &get_capacity);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
/* Check if the capacity as per the expected value */
- TEST_ASSERT_EQUAL(capacity, check1[i].capacity, TEST_CHECKPOINT_NUM(7));
+ TEST_ASSERT_EQUAL(get_capacity, check1[i].capacity, TEST_CHECKPOINT_NUM(7));
/* Abort the operation */
status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_ABORT, &operation);
@@ -86,15 +84,47 @@
/* Setting the capacity on an aborted operation should be an error */
status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_SET_CAPACITY, &operation,
- check1[i].capacity);
+ check1[i].capacity);
TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(9));
/* Getting the capacity on an aborted operation should be an error */
status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_GET_CAPACITY, &operation,
- &capacity);
+ &get_capacity);
TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(10));
}
+ /* When the capacity is larger than the operation's current capacity,
+ the operation object remains valid and its capacity remains unchanged */
+ get_capacity = 0;
+ memset(&operation, 0, sizeof(operation));
+ val->print(PRINT_TEST, "[Check %d] ", i+1);
+ val->print(PRINT_TEST, "Test psa_key_derivation_set_get_capacity - unchanged capacity\n", 0);
+ /* Start the key derivation operation */
+ status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_SETUP, &operation, check1[0].alg);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(11));
+
+ /* Set the capacity for the generator */
+ status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_SET_CAPACITY, &operation,
+ check1[0].capacity);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(12));
+
+ /* Try to set capacity larger than the operation's capacity */
+ status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_SET_CAPACITY, &operation,
+ check1[2].capacity);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_ARGUMENT, TEST_CHECKPOINT_NUM(13));
+
+ /* Get the capacity for the generator */
+ status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_GET_CAPACITY, &operation,
+ &get_capacity);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(14));
+
+ /* Check if the previous capacity remains unchanged */
+ TEST_ASSERT_EQUAL(get_capacity, check1[0].capacity, TEST_CHECKPOINT_NUM(15));
+
+ /* Abort the operation */
+ status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_ABORT, &operation);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(16));
+
return VAL_STATUS_SUCCESS;
}
diff --git a/api-tests/dev_apis/crypto/test_c023/test_data.h b/api-tests/dev_apis/crypto/test_c023/test_data.h
index 86be318..b20c4bc 100644
--- a/api-tests/dev_apis/crypto/test_c023/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c023/test_data.h
@@ -15,25 +15,34 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- psa_algorithm_t key_alg;
+ psa_algorithm_t alg;
size_t capacity;
psa_status_t expected_status;
} test_data;
static const test_data check1[] = {
-{"Test psa_key_derivation_set_get_capacity - Less than operation's capacity\n",
- PSA_ALG_HKDF(PSA_ALG_SHA_256), 42, PSA_SUCCESS
+{
+ .test_desc = "Test psa_key_derivation_set_get_capacity - < operation's capacity\n",
+ .alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .capacity = 42,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_key_derivation_set_get_capacity - Equal to operation's capacity\n",
- PSA_ALG_HKDF(PSA_ALG_SHA_256), 8160, PSA_SUCCESS
+{
+ .test_desc = "Test psa_key_derivation_set_get_capacity - = operation's capacity\n",
+ .alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .capacity = 8160,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_key_derivation_set_get_capacity - More than operation's capacity\n",
- PSA_ALG_HKDF(PSA_ALG_SHA_256), 10000, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_key_derivation_set_get_capacity - > operation's capacity\n",
+ .alg = PSA_ALG_HKDF(PSA_ALG_SHA_256),
+ .capacity = 10000,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
};
diff --git a/api-tests/dev_apis/crypto/test_c024/test_c024.c b/api-tests/dev_apis/crypto/test_c024/test_c024.c
index 36f2436..721661c 100644
--- a/api-tests/dev_apis/crypto/test_c024/test_c024.c
+++ b/api-tests/dev_apis/crypto/test_c024/test_c024.c
@@ -26,31 +26,13 @@
NULL,
};
-static int g_test_count = 1;
-
-static bool_t is_buffer_empty(uint8_t *buffer, size_t size)
-{
- int i;
-
- for (i = 0; i < (int)size; i++)
- {
- if (buffer[i] != 0)
- return FALSE;
- }
-
- return TRUE;
-}
-
int32_t psa_aead_encrypt_test(caller_security_t caller __UNUSED)
{
- int32_t status;
- int i;
- uint8_t ciphertext[BUFFER_SIZE];
- size_t ciphertext_length;
+ int32_t status, i;
+ size_t get_ciphertext_length;
int num_checks = sizeof(check1)/sizeof(check1[0]);
- uint8_t *nonce, *additional_data;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- psa_key_handle_t key_handle;
+ psa_key_handle_t handle;
if (num_checks == 0)
{
@@ -64,7 +46,7 @@
for (i = 0; i < num_checks; i++)
{
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] ", i+1);
val->print(PRINT_TEST, check1[i].test_desc, 0);
/* Setting up the watchdog timer for each check */
@@ -72,71 +54,77 @@
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].key_alg);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage_flags);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].alg);
/* Import the key data into the key slot */
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].key_data,
- check1[i].key_length, &key_handle);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY,
+ &attributes,
+ check1[i].data,
+ check1[i].data_length,
+ &handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
- if (is_buffer_empty(check1[i].nonce, check1[i].nonce_length) == TRUE)
- {
- nonce = NULL;
- check1[i].nonce_length = 0;
- }
- else
- nonce = check1[i].nonce;
-
- if (is_buffer_empty(check1[i].additional_data, check1[i].additional_data_length) == TRUE)
- {
- additional_data = NULL;
- check1[i].additional_data_length = 0;
- }
- else
- additional_data = check1[i].additional_data;
-
/* Process an authenticated encryption operation */
- status = val->crypto_function(VAL_CRYPTO_AEAD_ENCRYPT, key_handle,
- check1[i].key_alg, nonce, check1[i].nonce_length, additional_data,
- check1[i].additional_data_length, check1[i].plaintext,
- check1[i].plaintext_length, ciphertext, check1[i].ciphertext_size,
- &ciphertext_length);
+ status = val->crypto_function(VAL_CRYPTO_AEAD_ENCRYPT,
+ handle,
+ check1[i].alg,
+ check1[i].nonce,
+ check1[i].nonce_length,
+ check1[i].additional_data,
+ check1[i].additional_data_length,
+ check1[i].plaintext,
+ check1[i].plaintext_length,
+ check1[i].ciphertext,
+ check1[i].ciphertext_size,
+ &get_ciphertext_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(4));
if (check1[i].expected_status != PSA_SUCCESS)
{
/* Destroy the key */
- status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, key_handle);
+ status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
continue;
}
/* Check if the length matches */
- TEST_ASSERT_EQUAL(ciphertext_length,
- check1[i].expected_ciphertext_length,
- TEST_CHECKPOINT_NUM(6));
+ TEST_ASSERT_EQUAL(get_ciphertext_length, check1[i].expected_ciphertext_length,
+ TEST_CHECKPOINT_NUM(6));
/* Check if the data matches */
- TEST_ASSERT_MEMCMP(ciphertext, check1[i].expected_ciphertext, ciphertext_length,
- TEST_CHECKPOINT_NUM(7));
-
- /* Destroy the key */
- status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, key_handle);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(8));
+ TEST_ASSERT_MEMCMP(check1[i].ciphertext, check1[i].expected_ciphertext,
+ get_ciphertext_length, TEST_CHECKPOINT_NUM(7));
/* Reset the key attributes and check if psa_import_key fails */
val->crypto_function(VAL_CRYPTO_RESET_KEY_ATTRIBUTES, &attributes);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY,
+ &attributes,
+ check1[i].data,
+ check1[i].data_length,
+ &handle);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_NOT_SUPPORTED, TEST_CHECKPOINT_NUM(8));
+
+ /* Destroy the key */
+ status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, handle);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(9));
/* Process an authenticated encryption operation on a destroyed key*/
- status = val->crypto_function(VAL_CRYPTO_AEAD_ENCRYPT, key_handle,
- check1[i].key_alg, nonce, check1[i].nonce_length, additional_data,
- check1[i].additional_data_length, check1[i].plaintext,
- check1[i].plaintext_length, ciphertext, check1[i].ciphertext_size,
- &ciphertext_length);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(9));
+ status = val->crypto_function(VAL_CRYPTO_AEAD_ENCRYPT,
+ handle,
+ check1[i].alg,
+ check1[i].nonce,
+ check1[i].nonce_length,
+ check1[i].additional_data,
+ check1[i].additional_data_length,
+ check1[i].plaintext,
+ check1[i].plaintext_length,
+ check1[i].ciphertext,
+ check1[i].ciphertext_size,
+ &get_ciphertext_length);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(10));
}
return VAL_STATUS_SUCCESS;
diff --git a/api-tests/dev_apis/crypto/test_c024/test_data.h b/api-tests/dev_apis/crypto/test_c024/test_data.h
index 6a493b2..0246723 100644
--- a/api-tests/dev_apis/crypto/test_c024/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c024/test_data.h
@@ -15,146 +15,257 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- psa_key_type_t key_type;
- uint8_t key_data[32];
- uint32_t key_length;
- psa_key_usage_t usage;
- psa_algorithm_t key_alg;
- uint8_t nonce[16];
+ psa_key_type_t type;
+ const uint8_t *data;
+ size_t data_length;
+ psa_key_usage_t usage_flags;
+ psa_algorithm_t alg;
+ const uint8_t *nonce;
size_t nonce_length;
- uint8_t additional_data[32];
+ const uint8_t *additional_data;
size_t additional_data_length;
- uint8_t plaintext[30];
+ const uint8_t *plaintext;
size_t plaintext_length;
- uint8_t expected_ciphertext[45];
+ uint8_t *ciphertext;
+ const uint8_t *expected_ciphertext;
size_t ciphertext_size;
size_t expected_ciphertext_length;
psa_status_t expected_status;
} test_data;
-static test_data check1[] = {
+static const test_data check1[] = {
#ifdef ARCH_TEST_CCM
#ifdef ARCH_TEST_AES_128
-{"Test psa_aead_encrypt - CCM - 16B AES - 13B nounce & 8B addi data\n", PSA_KEY_TYPE_AES,
-{0xD7, 0x82, 0x8D, 0x13, 0xB2, 0xB0, 0xBD, 0xC3, 0x25, 0xA7, 0x62, 0x36, 0xDF,
- 0x93, 0xCC, 0x6B},
- AES_16B_KEY_SIZE, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CCM,
-{0x00, 0x41, 0x2B, 0x4E, 0xA9, 0xCD, 0xBE, 0x3C, 0x96, 0x96, 0x76, 0x6C, 0xFA},
- 13,
-{0x0B, 0xE1, 0xA8, 0x8B, 0xAC, 0xE0, 0x18, 0xB1}, 8,
-{0x08, 0xE8, 0xCF, 0x97, 0xD8, 0x20, 0xEA, 0x25, 0x84, 0x60, 0xE9, 0x6A, 0xD9,
- 0xCF, 0x52, 0x89, 0x05, 0x4D, 0x89, 0x5C, 0xEA, 0xC4, 0x7C}, 23,
-{0x4C, 0xB9, 0x7F, 0x86, 0xA2, 0xA4, 0x68, 0x9A, 0x87, 0x79, 0x47, 0xAB, 0x80,
- 0x91, 0xEF, 0x53, 0x86, 0xA6, 0xFF, 0xBD, 0xD0, 0x80, 0xF8, 0x12, 0x03, 0x33,
- 0xD1, 0xFC, 0xB6, 0x91, 0xF3, 0x40, 0x6C, 0xBF, 0x53, 0x1F, 0x83, 0xA4, 0xD8},
- BUFFER_SIZE, 39, PSA_SUCCESS
+{
+ .test_desc = "Test psa_aead_encrypt - CCM - AES - 13B nonce & 8B add data\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CCM,
+ .nonce = nonce,
+ .nonce_length = 13,
+ .additional_data = additional_data,
+ .additional_data_length = 8,
+ .plaintext = plaintext,
+ .plaintext_length = 23,
+ .ciphertext = expected_output,
+ .expected_ciphertext = aead_ciphertext_1,
+ .ciphertext_size = BUFFER_SIZE,
+ .expected_ciphertext_length = AEAD_CIPHERTEXT_LEN_1,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_aead_encrypt - AES-CCM\n", PSA_KEY_TYPE_AES,
-{0x41, 0x89, 0x35, 0x1B, 0x5C, 0xAE, 0xA3, 0x75, 0xA0, 0x29, 0x9E, 0x81, 0xC6,
- 0x21, 0xBF, 0x43}, AES_16B_KEY_SIZE, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CCM,
-{0x48, 0xc0, 0x90, 0x69, 0x30, 0x56, 0x1e, 0x0a, 0xb0, 0xef, 0x4c, 0xd9, 0x72},
- 13,
-{0x40, 0xa2, 0x7c, 0x1d, 0x1e, 0x23, 0xea, 0x3d, 0xbe, 0x80, 0x56, 0xb2, 0x77,
- 0x48, 0x61, 0xa4, 0xa2, 0x01, 0xcc, 0xe4, 0x9f, 0x19, 0x99, 0x7d, 0x19, 0x20,
- 0x6d, 0x8c, 0x8a, 0x34, 0x39, 0x51}, 32,
-{0x45, 0x35, 0xd1, 0x2b, 0x43, 0x77, 0x92, 0x8a, 0x7c, 0x0a, 0x61, 0xc9, 0xf8,
- 0x25, 0xa4, 0x86, 0x71, 0xea, 0x05, 0x91, 0x07, 0x48, 0xc8, 0xef}, 24,
-{0x26, 0xc5, 0x69, 0x61, 0xc0, 0x35, 0xa7, 0xe4, 0x52, 0xcc, 0xe6, 0x1b, 0xc6,
- 0xee, 0x22, 0x0d, 0x77, 0xb3, 0xf9, 0x4d, 0x18, 0xfd, 0x10, 0xb6, 0xd8, 0x0e,
- 0x8b, 0xf8, 0x0f, 0x4a, 0x46, 0xca, 0xb0, 0x6d, 0x43, 0x13, 0xf0, 0xdb, 0x9b,
- 0xe9}, BUFFER_SIZE, 40, PSA_SUCCESS
+{
+ .test_desc = "Test psa_aead_encrypt - CCM - AES - 13B nonce & 32B add data\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CCM,
+ .nonce = nonce,
+ .nonce_length = 13,
+ .additional_data = additional_data,
+ .additional_data_length = 32,
+ .plaintext = plaintext,
+ .plaintext_length = 24,
+ .ciphertext = expected_output,
+ .expected_ciphertext = aead_ciphertext_2,
+ .ciphertext_size = BUFFER_SIZE,
+ .expected_ciphertext_length = AEAD_CIPHERTEXT_LEN_2,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_aead_encrypt - AES-CCM 24 bytes Tag length = 4\n", PSA_KEY_TYPE_AES,
-{0x41, 0x89, 0x35, 0x1B, 0x5C, 0xAE, 0xA3, 0x75, 0xA0, 0x29, 0x9E, 0x81, 0xC6,
- 0x21, 0xBF, 0x43}, AES_16B_KEY_SIZE, PSA_KEY_USAGE_ENCRYPT,
- PSA_ALG_AEAD_WITH_TAG_LENGTH(PSA_ALG_CCM, 4),
-{0x48, 0xc0, 0x90, 0x69, 0x30, 0x56, 0x1e, 0x0a, 0xb0, 0xef, 0x4c, 0xd9, 0x72},
- 13,
-{0x40, 0xa2, 0x7c, 0x1d, 0x1e, 0x23, 0xea, 0x3d, 0xbe, 0x80, 0x56, 0xb2, 0x77,
- 0x48, 0x61, 0xa4, 0xa2, 0x01, 0xcc, 0xe4, 0x9f, 0x19, 0x99, 0x7d, 0x19, 0x20,
- 0x6d, 0x8c, 0x8a, 0x34, 0x39, 0x51}, 32,
-{0x45, 0x35, 0xd1, 0x2b, 0x43, 0x77, 0x92, 0x8a, 0x7c, 0x0a, 0x61, 0xc9, 0xf8,
- 0x25, 0xa4, 0x86, 0x71, 0xea, 0x05, 0x91, 0x07, 0x48, 0xc8, 0xef}, 24,
-{0x26, 0xc5, 0x69, 0x61, 0xc0, 0x35, 0xa7, 0xe4, 0x52, 0xcc, 0xe6, 0x1b, 0xc6,
- 0xee, 0x22, 0x0d, 0x77, 0xb3, 0xf9, 0x4d, 0x18, 0xfd, 0x10, 0xb6, 0x64, 0x3b,
- 0x4f, 0x39},
- BUFFER_SIZE, 28, PSA_SUCCESS
+{
+ .test_desc = "Test psa_aead_encrypt - CCM - AES - 24 bytes Tag length = 4\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_AEAD_WITH_TAG_LENGTH(PSA_ALG_CCM, 4),
+ .nonce = nonce,
+ .nonce_length = 13,
+ .additional_data = additional_data,
+ .additional_data_length = 32,
+ .plaintext = plaintext,
+ .plaintext_length = 24,
+ .ciphertext = expected_output,
+ .expected_ciphertext = aead_ciphertext_3,
+ .ciphertext_size = BUFFER_SIZE,
+ .expected_ciphertext_length = AEAD_CIPHERTEXT_LEN_3,
+ .expected_status = PSA_SUCCESS
+},
+
+{
+ .test_desc = "Test psa_aead_encrypt - CCM - AES - Zero additional data\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CCM,
+ .nonce = nonce,
+ .nonce_length = 13,
+ .additional_data = NULL,
+ .additional_data_length = 0,
+ .plaintext = plaintext,
+ .plaintext_length = 24,
+ .ciphertext = expected_output,
+ .expected_ciphertext = aead_ciphertext_4,
+ .ciphertext_size = BUFFER_SIZE,
+ .expected_ciphertext_length = AEAD_CIPHERTEXT_LEN_4,
+ .expected_status = PSA_SUCCESS
+},
+
+{
+ .test_desc = "Test psa_aead_encrypt - CCM - AES - Zero plaintext\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CCM,
+ .nonce = nonce,
+ .nonce_length = 13,
+ .additional_data = additional_data,
+ .additional_data_length = 32,
+ .plaintext = NULL,
+ .plaintext_length = 0,
+ .ciphertext = expected_output,
+ .expected_ciphertext = aead_ciphertext_5,
+ .ciphertext_size = BUFFER_SIZE,
+ .expected_ciphertext_length = AEAD_CIPHERTEXT_LEN_5,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_GCM
#ifdef ARCH_TEST_AES_128
-{"Test psa_aead_encrypt - GCM - 16B AES - 12B Nounce & 12B addi data\n",
-PSA_KEY_TYPE_AES,
-{0x3d, 0xe0, 0x98, 0x74, 0xb3, 0x88, 0xe6, 0x49, 0x19, 0x88, 0xd0, 0xc3, 0x60,
- 0x7e, 0xae, 0x1f}, AES_16B_KEY_SIZE, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_GCM,
-{0x57, 0x69, 0x0e, 0x43, 0x4e, 0x28, 0x00, 0x00, 0xa2, 0xfc, 0xa1, 0xa3}, 12,
-{0x42, 0xf6, 0x7e, 0x3f, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10}, 12,
-{0x45, 0x00, 0x00, 0x1c, 0x42, 0xa2, 0x00, 0x00, 0x80, 0x01, 0x44, 0x1f, 0x40,
- 0x67, 0x93, 0xb6, 0xe0, 0x00, 0x00, 0x02, 0x0a, 0x00, 0xf5, 0xff, 0x01, 0x02,
- 0x02, 0x01}, 28,
-{0xFB, 0xA2, 0xCA, 0x84, 0x5E, 0x5D, 0xF9, 0xF0, 0xF2, 0x2C, 0x3E, 0x6E, 0x86,
- 0xDD, 0x83, 0x1E, 0x1F, 0xC6, 0x57, 0x92, 0xCD, 0x1A, 0xF9, 0x13, 0x0E, 0x13,
- 0x79, 0xED, 0x36, 0x9F, 0x07, 0x1F, 0x35, 0xE0, 0x34, 0xBE, 0x95, 0xF1, 0x12,
- 0xE4, 0xE7, 0xD0, 0x5D, 0x35},
- BUFFER_SIZE, 44, PSA_SUCCESS
+{
+ .test_desc = "Test psa_aead_encrypt - GCM - AES - 12B nonce & 12B add data\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_GCM,
+ .nonce = nonce,
+ .nonce_length = 12,
+ .additional_data = additional_data,
+ .additional_data_length = 12,
+ .plaintext = plaintext,
+ .plaintext_length = 24,
+ .ciphertext = expected_output,
+ .expected_ciphertext = aead_ciphertext_6,
+ .ciphertext_size = BUFFER_SIZE,
+ .expected_ciphertext_length = AEAD_CIPHERTEXT_LEN_6,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CCM
-#ifdef ARCH_TEST_DES_1KEY
-{"Test psa_aead_encrypt - DES Key\n", PSA_KEY_TYPE_DES,
-{0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29}, DES_8B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CCM,
-{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B}, 12,
-{0xEC, 0x46, 0xBB, 0x63, 0xB0, 0x25, 0x20, 0xC3, 0x3C, 0x49, 0xFD, 0x70}, 12,
-{0xB9, 0x6B, 0x49, 0xE2, 0x1D, 0x62, 0x17, 0x41, 0x63, 0x28, 0x75, 0xDB, 0x7F,
- 0x6C, 0x92, 0x43, 0xD2, 0xD7, 0xC2}, 19,
-{0}, BUFFER_SIZE, 0, PSA_ERROR_NOT_SUPPORTED
+{
+ .test_desc = "Test psa_aead_encrypt - Unsupported algorithm\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES_8B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CCM,
+ .nonce = NULL,
+ .nonce_length = 0,
+ .additional_data = NULL,
+ .additional_data_length = 0,
+ .plaintext = NULL,
+ .plaintext_length = 0,
+ .ciphertext = NULL,
+ .expected_ciphertext = NULL,
+ .ciphertext_size = 0,
+ .expected_ciphertext_length = 0,
+ .expected_status = PSA_ERROR_NOT_SUPPORTED
},
-#endif
-#endif
#ifdef ARCH_TEST_AES_128
-#ifdef ARCH_TEST_CIPER_MODE_CFB
-{"Test psa_aead_encrypt - Unsupported Algorithm\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9}, AES_16B_KEY_SIZE, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CFB,
-{0}, 13, {0}, 0, "hello world", 11,
-{0x5D, 0xC1, 0x72, 0x23, 0x66, 0x96, 0xFD, 0xFC, 0x93, 0x06, 0x27, 0x52, 0xC7,
- 0x0A, 0xCB, 0x36, 0x55, 0x30, 0xC9, 0x48, 0x8F, 0x5E, 0xA5, 0xB9, 0x51, 0xFB,
- 0x4E},
- BUFFER_SIZE, 27, PSA_ERROR_NOT_SUPPORTED
-},
-#endif
-
-#ifdef ARCH_TEST_GCM
-{"Test psa_aead_encrypt - Invalid key usage\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9}, AES_16B_KEY_SIZE, PSA_KEY_USAGE_DECRYPT, PSA_ALG_GCM,
-{0}, 13, {0}, 0, "hello world", 11,
-{0x5D, 0xC1, 0x72, 0x23, 0x66, 0x96, 0xFD, 0xFC, 0x93, 0x06, 0x27, 0x52, 0xC7,
- 0x0A, 0xCB, 0x36, 0x55, 0x30, 0xC9, 0x48, 0x8F, 0x5E, 0xA5, 0xB9, 0x51, 0xFB,
- 0x4E},
- BUFFER_SIZE, 27, PSA_ERROR_NOT_PERMITTED
+{
+ .test_desc = "Test psa_aead_encrypt - Invalid usage flag\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CCM,
+ .nonce = NULL,
+ .nonce_length = 0,
+ .additional_data = NULL,
+ .additional_data_length = 0,
+ .plaintext = NULL,
+ .plaintext_length = 0,
+ .ciphertext = NULL,
+ .expected_ciphertext = NULL,
+ .ciphertext_size = 0,
+ .expected_ciphertext_length = 0,
+ .expected_status = PSA_ERROR_NOT_PERMITTED
},
-{"Test psa_aead_encrypt - Small output buffer size\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9}, AES_16B_KEY_SIZE, PSA_KEY_USAGE_DECRYPT, PSA_ALG_GCM,
-{0}, 13, {0}, 0, "hello world", 11,
-{0x5D, 0xC1, 0x72, 0x23, 0x66, 0x96, 0xFD, 0xFC, 0x93, 0x06, 0x27, 0x52, 0xC7,
- 0x0A, 0xCB, 0x36, 0x55, 0x30, 0xC9, 0x48, 0x8F, 0x5E, 0xA5, 0xB9, 0x51, 0xFB,
- 0x4E},
- 10, 27, PSA_ERROR_NOT_PERMITTED
+{
+ .test_desc = "Test psa_aead_encrypt - Invalid ciphertext_size\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CCM,
+ .nonce = nonce,
+ .nonce_length = 13,
+ .additional_data = additional_data,
+ .additional_data_length = 32,
+ .plaintext = plaintext,
+ .plaintext_length = 24,
+ .ciphertext = expected_output,
+ .expected_ciphertext = aead_ciphertext_2,
+ .ciphertext_size = AEAD_CIPHERTEXT_LEN_2-1,
+ .expected_ciphertext_length = AEAD_CIPHERTEXT_LEN_2,
+ .expected_status = PSA_ERROR_BUFFER_TOO_SMALL
+},
+
+{
+ .test_desc = "Test psa_aead_encrypt - Invalid nonce\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CCM,
+ .nonce = NULL,
+ .nonce_length = 0,
+ .additional_data = additional_data,
+ .additional_data_length = 32,
+ .plaintext = plaintext,
+ .plaintext_length = 24,
+ .ciphertext = expected_output,
+ .expected_ciphertext = aead_ciphertext_2,
+ .ciphertext_size = BUFFER_SIZE,
+ .expected_ciphertext_length = AEAD_CIPHERTEXT_LEN_2,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
+},
+
+{
+ .test_desc = "Test psa_aead_encrypt - Invalid tag length 0\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_AEAD_WITH_TAG_LENGTH(PSA_ALG_CCM, 0),
+ .nonce = nonce,
+ .nonce_length = 13,
+ .additional_data = additional_data,
+ .additional_data_length = 32,
+ .plaintext = plaintext,
+ .plaintext_length = 24,
+ .ciphertext = expected_output,
+ .expected_ciphertext = aead_ciphertext_2,
+ .ciphertext_size = BUFFER_SIZE,
+ .expected_ciphertext_length = AEAD_CIPHERTEXT_LEN_2,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
diff --git a/api-tests/dev_apis/crypto/test_c025/test_c025.c b/api-tests/dev_apis/crypto/test_c025/test_c025.c
index 49c8369..e83e27d 100644
--- a/api-tests/dev_apis/crypto/test_c025/test_c025.c
+++ b/api-tests/dev_apis/crypto/test_c025/test_c025.c
@@ -26,28 +26,11 @@
NULL,
};
-static int g_test_count = 1;
-
-static bool_t is_buffer_empty(uint8_t *buffer, size_t size)
-{
- int i;
-
- for (i = 0; i < (int)size; i++)
- {
- if (buffer[i] != 0)
- return FALSE;
- }
-
- return TRUE;
-}
-
int32_t psa_aead_decrypt_test(caller_security_t caller __UNUSED)
{
- int32_t i, status;
- uint8_t plaintext[BUFFER_SIZE];
- size_t plaintext_length;
- int num_checks = sizeof(check1)/sizeof(check1[0]);
- uint8_t *nonce, *additional_data;
+ int32_t i, status;
+ size_t expected_plaintext_length;
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_handle_t key_handle;
@@ -63,7 +46,7 @@
for (i = 0; i < num_checks; i++)
{
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] ", i+1);
val->print(PRINT_TEST, check1[i].test_desc, 0);
/* Setting up the watchdog timer for each check */
@@ -71,36 +54,22 @@
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].key_alg);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage_flags);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].alg);
/* Import the key data into the key slot */
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].key_data,
- check1[i].key_length, &key_handle);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
- if (is_buffer_empty(check1[i].nonce, check1[i].nonce_length) == TRUE)
- {
- nonce = NULL;
- check1[i].nonce_length = 0;
- }
- else
- nonce = check1[i].nonce;
-
- if (is_buffer_empty(check1[i].additional_data, check1[i].additional_data_length) == TRUE)
- {
- additional_data = NULL;
- check1[i].additional_data_length = 0;
- }
- else
- additional_data = check1[i].additional_data;
-
/* Process an authenticated decryption operation */
- status = val->crypto_function(VAL_CRYPTO_AEAD_DECRYPT, key_handle,
- check1[i].key_alg, nonce, check1[i].nonce_length, additional_data,
- check1[i].additional_data_length, check1[i].ciphertext, check1[i].ciphertext_size,
- plaintext, check1[i].plaintext_size, &plaintext_length);
+ status = val->crypto_function(VAL_CRYPTO_AEAD_DECRYPT, key_handle, check1[i].alg,
+ check1[i].nonce, check1[i].nonce_length,
+ check1[i].additional_data, check1[i].additional_data_length,
+ check1[i].ciphertext, check1[i].ciphertext_length,
+ check1[i].plaintext, check1[i].plaintext_size,
+ &expected_plaintext_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(4));
if (check1[i].expected_status != PSA_SUCCESS)
@@ -113,26 +82,31 @@
}
/* Check if the length matches */
- TEST_ASSERT_EQUAL(plaintext_length, check1[i].expected_plaintext_length,
+ TEST_ASSERT_EQUAL(expected_plaintext_length, check1[i].expected_plaintext_length,
TEST_CHECKPOINT_NUM(6));
/* Check if the data matches */
- TEST_ASSERT_MEMCMP(plaintext, check1[i].expected_plaintext, plaintext_length,
- TEST_CHECKPOINT_NUM(7));
-
- /* Destroy the key */
- status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, key_handle);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(8));
+ TEST_ASSERT_MEMCMP(check1[i].plaintext, check1[i].expected_plaintext,
+ expected_plaintext_length, TEST_CHECKPOINT_NUM(7));
/* Reset the key attributes and check if psa_import_key fails */
val->crypto_function(VAL_CRYPTO_RESET_KEY_ATTRIBUTES, &attributes);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_NOT_SUPPORTED, TEST_CHECKPOINT_NUM(8));
+
+ /* Destroy the key */
+ status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, key_handle);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(9));
/* Process an authenticated decryption operation on a destroyed key handle */
- status = val->crypto_function(VAL_CRYPTO_AEAD_DECRYPT, key_handle,
- check1[i].key_alg, nonce, check1[i].nonce_length, additional_data,
- check1[i].additional_data_length, check1[i].ciphertext, check1[i].ciphertext_size,
- plaintext, check1[i].plaintext_size, &plaintext_length);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(9));
+ status = val->crypto_function(VAL_CRYPTO_AEAD_DECRYPT, key_handle, check1[i].alg,
+ check1[i].nonce, check1[i].nonce_length,
+ check1[i].additional_data, check1[i].additional_data_length,
+ check1[i].ciphertext, check1[i].ciphertext_length,
+ check1[i].plaintext, check1[i].plaintext_size,
+ &expected_plaintext_length);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(10));
}
return VAL_STATUS_SUCCESS;
diff --git a/api-tests/dev_apis/crypto/test_c025/test_data.h b/api-tests/dev_apis/crypto/test_c025/test_data.h
index 7aed327..a7856f8 100644
--- a/api-tests/dev_apis/crypto/test_c025/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c025/test_data.h
@@ -1,5 +1,5 @@
/** @file
- * Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
+ * Copyright (c) 2019-2020, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,192 +15,295 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- psa_key_type_t key_type;
- uint8_t key_data[32];
- uint32_t key_length;
- psa_key_usage_t usage;
- psa_algorithm_t key_alg;
- uint8_t nonce[16];
+ psa_key_type_t type;
+ const uint8_t *data;
+ size_t data_length;
+ psa_key_usage_t usage_flags;
+ psa_algorithm_t alg;
+ const uint8_t *nonce;
size_t nonce_length;
- uint8_t additional_data[32];
+ const uint8_t *additional_data;
size_t additional_data_length;
- uint8_t expected_plaintext[30];
+ const uint8_t *ciphertext;
+ size_t ciphertext_length;
+ uint8_t *plaintext;
+ const uint8_t *expected_plaintext;
size_t plaintext_size;
- uint8_t ciphertext[45];
- size_t ciphertext_size;
size_t expected_plaintext_length;
psa_status_t expected_status;
} test_data;
-static test_data check1[] = {
+static const test_data check1[] = {
#ifdef ARCH_TEST_AES_128
#ifdef ARCH_TEST_CCM
-{"Test psa_aead_decrypt - CCM - 16B AES - 13B nounce & 8B addi data\n", PSA_KEY_TYPE_AES,
-{0xD7, 0x82, 0x8D, 0x13, 0xB2, 0xB0, 0xBD, 0xC3, 0x25, 0xA7, 0x62, 0x36, 0xDF,
- 0x93, 0xCC, 0x6B},
- AES_16B_KEY_SIZE, PSA_KEY_USAGE_DECRYPT, PSA_ALG_CCM,
-{0x00, 0x41, 0x2B, 0x4E, 0xA9, 0xCD, 0xBE, 0x3C, 0x96, 0x96, 0x76, 0x6C, 0xFA},
- 13,
-{0x0B, 0xE1, 0xA8, 0x8B, 0xAC, 0xE0, 0x18, 0xB1}, 8,
-{0x08, 0xE8, 0xCF, 0x97, 0xD8, 0x20, 0xEA, 0x25, 0x84, 0x60, 0xE9, 0x6A, 0xD9,
- 0xCF, 0x52, 0x89, 0x05, 0x4D, 0x89, 0x5C, 0xEA, 0xC4, 0x7C}, BUFFER_SIZE,
-{0x4C, 0xB9, 0x7F, 0x86, 0xA2, 0xA4, 0x68, 0x9A, 0x87, 0x79, 0x47, 0xAB, 0x80,
- 0x91, 0xEF, 0x53, 0x86, 0xA6, 0xFF, 0xBD, 0xD0, 0x80, 0xF8, 0x12, 0x03, 0x33,
- 0xD1, 0xFC, 0xB6, 0x91, 0xF3, 0x40, 0x6C, 0xBF, 0x53, 0x1F, 0x83, 0xA4, 0xD8},
- 39, 23, PSA_SUCCESS
+{
+ .test_desc = "Test psa_aead_decrypt - CCM - AES - 13B nonce & 8B add data\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CCM,
+ .nonce = nonce,
+ .nonce_length = 13,
+ .additional_data = additional_data,
+ .additional_data_length = 8,
+ .ciphertext = aead_ciphertext_1,
+ .ciphertext_length = AEAD_CIPHERTEXT_LEN_1,
+ .plaintext = expected_output,
+ .expected_plaintext = plaintext,
+ .plaintext_size = BUFFER_SIZE,
+ .expected_plaintext_length = 23,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_aead_decrypt - AES-CCM\n", PSA_KEY_TYPE_AES,
-{0x41, 0x89, 0x35, 0x1B, 0x5C, 0xAE, 0xA3, 0x75, 0xA0, 0x29, 0x9E, 0x81, 0xC6,
- 0x21, 0xBF, 0x43}, AES_16B_KEY_SIZE, PSA_KEY_USAGE_DECRYPT, PSA_ALG_CCM,
-{0x48, 0xc0, 0x90, 0x69, 0x30, 0x56, 0x1e, 0x0a, 0xb0, 0xef, 0x4c, 0xd9, 0x72},
- 13,
-{0x40, 0xa2, 0x7c, 0x1d, 0x1e, 0x23, 0xea, 0x3d, 0xbe, 0x80, 0x56, 0xb2, 0x77,
- 0x48, 0x61, 0xa4, 0xa2, 0x01, 0xcc, 0xe4, 0x9f, 0x19, 0x99, 0x7d, 0x19, 0x20,
- 0x6d, 0x8c, 0x8a, 0x34, 0x39, 0x51}, 32,
-{0x45, 0x35, 0xd1, 0x2b, 0x43, 0x77, 0x92, 0x8a, 0x7c, 0x0a, 0x61, 0xc9, 0xf8,
- 0x25, 0xa4, 0x86, 0x71, 0xea, 0x05, 0x91, 0x07, 0x48, 0xc8, 0xef}, BUFFER_SIZE,
-{0x26, 0xc5, 0x69, 0x61, 0xc0, 0x35, 0xa7, 0xe4, 0x52, 0xcc, 0xe6, 0x1b, 0xc6,
- 0xee, 0x22, 0x0d, 0x77, 0xb3, 0xf9, 0x4d, 0x18, 0xfd, 0x10, 0xb6, 0xd8, 0x0e,
- 0x8b, 0xf8, 0x0f, 0x4a, 0x46, 0xca, 0xb0, 0x6d, 0x43, 0x13, 0xf0, 0xdb, 0x9b,
- 0xe9}, 40, 24, PSA_SUCCESS
+{
+ .test_desc = "Test psa_aead_decrypt - CCM - AES - 13B nonce & 32B add data\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CCM,
+ .nonce = nonce,
+ .nonce_length = 13,
+ .additional_data = additional_data,
+ .additional_data_length = 32,
+ .ciphertext = aead_ciphertext_2,
+ .ciphertext_length = AEAD_CIPHERTEXT_LEN_2,
+ .plaintext = expected_output,
+ .expected_plaintext = plaintext,
+ .plaintext_size = BUFFER_SIZE,
+ .expected_plaintext_length = 24,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_aead_decrypt - AES-CCM 24 bytes Tag length = 4\n", PSA_KEY_TYPE_AES,
-{0x41, 0x89, 0x35, 0x1B, 0x5C, 0xAE, 0xA3, 0x75, 0xA0, 0x29, 0x9E, 0x81, 0xC6,
- 0x21, 0xBF, 0x43}, AES_16B_KEY_SIZE, PSA_KEY_USAGE_DECRYPT,
- PSA_ALG_AEAD_WITH_TAG_LENGTH(PSA_ALG_CCM, 4),
-{0x48, 0xc0, 0x90, 0x69, 0x30, 0x56, 0x1e, 0x0a, 0xb0, 0xef, 0x4c, 0xd9, 0x72},
- 13,
-{0x40, 0xa2, 0x7c, 0x1d, 0x1e, 0x23, 0xea, 0x3d, 0xbe, 0x80, 0x56, 0xb2, 0x77,
- 0x48, 0x61, 0xa4, 0xa2, 0x01, 0xcc, 0xe4, 0x9f, 0x19, 0x99, 0x7d, 0x19, 0x20,
- 0x6d, 0x8c, 0x8a, 0x34, 0x39, 0x51}, 32,
-{0x45, 0x35, 0xd1, 0x2b, 0x43, 0x77, 0x92, 0x8a, 0x7c, 0x0a, 0x61, 0xc9, 0xf8,
- 0x25, 0xa4, 0x86, 0x71, 0xea, 0x05, 0x91, 0x07, 0x48, 0xc8, 0xef}, BUFFER_SIZE,
-{0x26, 0xc5, 0x69, 0x61, 0xc0, 0x35, 0xa7, 0xe4, 0x52, 0xcc, 0xe6, 0x1b, 0xc6,
- 0xee, 0x22, 0x0d, 0x77, 0xb3, 0xf9, 0x4d, 0x18, 0xfd, 0x10, 0xb6, 0x64, 0x3b,
- 0x4f, 0x39},
- 28, 24, PSA_SUCCESS
+{
+ .test_desc = "Test psa_aead_decrypt - CCM - AES - 24 bytes Tag length = 4\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_AEAD_WITH_TAG_LENGTH(PSA_ALG_CCM, 4),
+ .nonce = nonce,
+ .nonce_length = 13,
+ .additional_data = additional_data,
+ .additional_data_length = 32,
+ .ciphertext = aead_ciphertext_3,
+ .ciphertext_length = AEAD_CIPHERTEXT_LEN_3,
+ .plaintext = expected_output,
+ .expected_plaintext = plaintext,
+ .plaintext_size = BUFFER_SIZE,
+ .expected_plaintext_length = 24,
+ .expected_status = PSA_SUCCESS
+},
+
+{
+ .test_desc = "Test psa_aead_decrypt - CCM - AES - Zero additional data\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CCM,
+ .nonce = nonce,
+ .nonce_length = 13,
+ .additional_data = NULL,
+ .additional_data_length = 0,
+ .ciphertext = aead_ciphertext_4,
+ .ciphertext_length = AEAD_CIPHERTEXT_LEN_4,
+ .plaintext = expected_output,
+ .expected_plaintext = plaintext,
+ .plaintext_size = BUFFER_SIZE,
+ .expected_plaintext_length = 24,
+ .expected_status = PSA_SUCCESS
+},
+
+{
+ .test_desc = "Test psa_aead_decrypt - CCM - AES - Zero plaintext\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CCM,
+ .nonce = nonce,
+ .nonce_length = 13,
+ .additional_data = additional_data,
+ .additional_data_length = 32,
+ .ciphertext = aead_ciphertext_5,
+ .ciphertext_length = AEAD_CIPHERTEXT_LEN_5,
+ .plaintext = expected_output,
+ .expected_plaintext = plaintext,
+ .plaintext_size = BUFFER_SIZE,
+ .expected_plaintext_length = 0,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_GCM
-{"Test psa_aead_decrypt - GCM - 16B AES - 12B Nounce & 12B addi data\n", PSA_KEY_TYPE_AES,
-{0x3d, 0xe0, 0x98, 0x74, 0xb3, 0x88, 0xe6, 0x49, 0x19, 0x88, 0xd0, 0xc3, 0x60,
- 0x7e, 0xae, 0x1f}, AES_16B_KEY_SIZE, PSA_KEY_USAGE_DECRYPT, PSA_ALG_GCM,
-{0x57, 0x69, 0x0e, 0x43, 0x4e, 0x28, 0x00, 0x00, 0xa2, 0xfc, 0xa1, 0xa3}, 12,
-{0x42, 0xf6, 0x7e, 0x3f, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10}, 12,
-{0x45, 0x00, 0x00, 0x1c, 0x42, 0xa2, 0x00, 0x00, 0x80, 0x01, 0x44, 0x1f, 0x40,
- 0x67, 0x93, 0xb6, 0xe0, 0x00, 0x00, 0x02, 0x0a, 0x00, 0xf5, 0xff, 0x01, 0x02,
- 0x02, 0x01}, BUFFER_SIZE,
-{0xFB, 0xA2, 0xCA, 0x84, 0x5E, 0x5D, 0xF9, 0xF0, 0xF2, 0x2C, 0x3E, 0x6E, 0x86,
- 0xDD, 0x83, 0x1E, 0x1F, 0xC6, 0x57, 0x92, 0xCD, 0x1A, 0xF9, 0x13, 0x0E, 0x13,
- 0x79, 0xED, 0x36, 0x9F, 0x07, 0x1F, 0x35, 0xE0, 0x34, 0xBE, 0x95, 0xF1, 0x12,
- 0xE4, 0xE7, 0xD0, 0x5D, 0x35},
- 44, 28, PSA_SUCCESS
+{
+ .test_desc = "Test psa_aead_decrypt - GCM - AES - 12B nonce & 12B add data\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_GCM,
+ .nonce = nonce,
+ .nonce_length = 12,
+ .additional_data = additional_data,
+ .additional_data_length = 12,
+ .ciphertext = aead_ciphertext_6,
+ .ciphertext_length = AEAD_CIPHERTEXT_LEN_6,
+ .plaintext = expected_output,
+ .expected_plaintext = plaintext,
+ .plaintext_size = BUFFER_SIZE,
+ .expected_plaintext_length = 24,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CCM
-#ifdef ARCH_TEST_DES_1KEY
-{"Test psa_aead_decrypt - DES Key\n", PSA_KEY_TYPE_DES,
-{0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29}, DES_8B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CCM,
-{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B}, 12,
-{0xEC, 0x46, 0xBB, 0x63, 0xB0, 0x25, 0x20, 0xC3, 0x3C, 0x49, 0xFD, 0x70}, 12,
-{0xB9, 0x6B, 0x49, 0xE2, 0x1D, 0x62, 0x17, 0x41, 0x63, 0x28, 0x75, 0xDB, 0x7F,
- 0x6C, 0x92, 0x43, 0xD2, 0xD7, 0xC2}, BUFFER_SIZE,
-{0}, 11, 0, PSA_ERROR_NOT_SUPPORTED
+{
+ .test_desc = "Test psa_aead_decrypt - Unsupported algorithm\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES_8B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CCM,
+ .nonce = NULL,
+ .nonce_length = 0,
+ .additional_data = NULL,
+ .additional_data_length = 0,
+ .ciphertext = NULL,
+ .ciphertext_length = 0,
+ .plaintext = NULL,
+ .expected_plaintext = NULL,
+ .plaintext_size = 0,
+ .expected_plaintext_length = 0,
+ .expected_status = PSA_ERROR_NOT_SUPPORTED
},
-#endif
-#endif
#ifdef ARCH_TEST_AES_128
-#ifdef ARCH_TEST_CIPER_MODE_CFB
-{"Test psa_aead_decrypt - Unsupported Algorithm\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9}, AES_16B_KEY_SIZE, PSA_KEY_USAGE_DECRYPT, PSA_ALG_CFB,
-{0}, 13, {0}, 0, "hello world", BUFFER_SIZE,
-{0x5D, 0xC1, 0x72, 0x23, 0x66, 0x96, 0xFD, 0xFC, 0x93, 0x06, 0x27, 0x52, 0xC7,
- 0x0A, 0xCB, 0x36, 0x55, 0x30, 0xC9, 0x48, 0x8F, 0x5E, 0xA5, 0xB9, 0x51, 0xFB,
- 0x4E},
- 27, 11, PSA_ERROR_NOT_SUPPORTED
-},
-#endif
-
-#ifdef ARCH_TEST_GCM
-{"Test psa_aead_decypt - Invalid key usage\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9}, AES_16B_KEY_SIZE, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_GCM,
-{0}, 13, {0}, 0, "hello world", BUFFER_SIZE,
-{0x5D, 0xC1, 0x72, 0x23, 0x66, 0x96, 0xFD, 0xFC, 0x93, 0x06, 0x27, 0x52, 0xC7,
- 0x0A, 0xCB, 0x36, 0x55, 0x30, 0xC9, 0x48, 0x8F, 0x5E, 0xA5, 0xB9, 0x51, 0xFB,
- 0x4E},
- 27, 11, PSA_ERROR_NOT_PERMITTED
+{
+ .test_desc = "Test psa_aead_decrypt - Invalid usage flag\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CCM,
+ .nonce = NULL,
+ .nonce_length = 0,
+ .additional_data = NULL,
+ .additional_data_length = 0,
+ .ciphertext = NULL,
+ .ciphertext_length = 0,
+ .plaintext = NULL,
+ .expected_plaintext = NULL,
+ .plaintext_size = 0,
+ .expected_plaintext_length = 0,
+ .expected_status = PSA_ERROR_NOT_PERMITTED
},
-{"Test psa_aead_decrypt - Small output buffer size\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9}, AES_16B_KEY_SIZE, PSA_KEY_USAGE_DECRYPT, PSA_ALG_GCM,
-{0}, 13, {0}, 0, "hello world", 10,
-{0x5D, 0xC1, 0x72, 0x23, 0x66, 0x96, 0xFD, 0xFC, 0x93, 0x06, 0x27, 0x52, 0xC7,
- 0x0A, 0xCB, 0x36, 0x55, 0x30, 0xC9, 0x48, 0x8F, 0x5E, 0xA5, 0xB9, 0x51, 0xFB,
- 0x4E},
- 27, 11, PSA_ERROR_BUFFER_TOO_SMALL
-},
-#endif
-
-#ifdef ARCH_TEST_CCM
-{"Test psa_aead_decrypt - Invalid cipher text\n", PSA_KEY_TYPE_AES,
-{0xD7, 0x82, 0x8D, 0x13, 0xB2, 0xB0, 0xBD, 0xC3, 0x25, 0xA7, 0x62, 0x36, 0xDF,
- 0x93, 0xCC, 0x6B},
- AES_16B_KEY_SIZE, PSA_KEY_USAGE_DECRYPT, PSA_ALG_CCM,
-{0x00, 0x41, 0x2B, 0x4E, 0xA9, 0xCD, 0xBE, 0x3C, 0x96, 0x96, 0x76, 0x6C, 0xFA},
- 13,
-{0x0B, 0xE1, 0xA8, 0x8B, 0xAC, 0xE0, 0x18, 0xB1}, 8,
-{0x08, 0xE8, 0xCF, 0x97, 0xD8, 0x20, 0xEA, 0x25, 0x84, 0x60, 0xE9, 0x6A, 0xD9,
- 0xCF, 0x52, 0x89, 0x05, 0x4D, 0x89, 0x5C, 0xEA, 0xC4, 0x7C}, BUFFER_SIZE,
-{0x4C, 0xB8, 0x7F, 0x86, 0xA2, 0xA4, 0x68, 0x9A, 0x87, 0x79, 0x47, 0xAB, 0x80,
- 0x91, 0xEF, 0x53, 0x86, 0xA6, 0xFF, 0xBD, 0xD0, 0x80, 0xF8, 0x12, 0x03, 0x33,
- 0xD1, 0xFC, 0xB6, 0x91, 0xF3, 0x40, 0x6C, 0xBF, 0x53, 0x1F, 0x83, 0xA4, 0xD8},
- 39, 23, PSA_ERROR_INVALID_SIGNATURE
+{
+ .test_desc = "Test psa_aead_decrypt - Invalid plaintext_size\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CCM,
+ .nonce = nonce,
+ .nonce_length = 13,
+ .additional_data = additional_data,
+ .additional_data_length = 32,
+ .ciphertext = aead_ciphertext_2,
+ .ciphertext_length = AEAD_CIPHERTEXT_LEN_2,
+ .plaintext = expected_output,
+ .expected_plaintext = plaintext,
+ .plaintext_size = 23,
+ .expected_plaintext_length = 24,
+ .expected_status = PSA_ERROR_BUFFER_TOO_SMALL
},
-{"Test psa_aead_decrypt - Invalid cipher text size\n", PSA_KEY_TYPE_AES,
-{0xD7, 0x82, 0x8D, 0x13, 0xB2, 0xB0, 0xBD, 0xC3, 0x25, 0xA7, 0x62, 0x36, 0xDF,
- 0x93, 0xCC, 0x6B},
- AES_16B_KEY_SIZE, PSA_KEY_USAGE_DECRYPT, PSA_ALG_CCM,
-{0x00, 0x41, 0x2B, 0x4E, 0xA9, 0xCD, 0xBE, 0x3C, 0x96, 0x96, 0x76, 0x6C, 0xFA},
- 13,
-{0x0B, 0xE1, 0xA8, 0x8B, 0xAC, 0xE0, 0x18, 0xB1}, 8,
-{0x08, 0xE8, 0xCF, 0x97, 0xD8, 0x20, 0xEA, 0x25, 0x84, 0x60, 0xE9, 0x6A, 0xD9,
- 0xCF, 0x52, 0x89, 0x05, 0x4D, 0x89, 0x5C, 0xEA, 0xC4, 0x7C}, BUFFER_SIZE,
-{0x4C, 0xB9, 0x7F, 0x86, 0xA2, 0xA4, 0x68, 0x9A, 0x87, 0x79, 0x47, 0xAB, 0x80,
- 0x91, 0xEF, 0x53, 0x86, 0xA6, 0xFF, 0xBD, 0xD0, 0x80, 0xF8, 0x12, 0x03, 0x33,
- 0xD1, 0xFC, 0xB6, 0x91, 0xF3, 0x40, 0x6C, 0xBF, 0x53, 0x1F, 0x83, 0xA4},
- 38, 23, PSA_ERROR_INVALID_SIGNATURE
+{
+ .test_desc = "Test psa_aead_decrypt - Invalid nonce\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CCM,
+ .nonce = NULL,
+ .nonce_length = 0,
+ .additional_data = additional_data,
+ .additional_data_length = 32,
+ .ciphertext = aead_ciphertext_2,
+ .ciphertext_length = AEAD_CIPHERTEXT_LEN_2,
+ .plaintext = expected_output,
+ .expected_plaintext = plaintext,
+ .plaintext_size = BUFFER_SIZE,
+ .expected_plaintext_length = 24,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
-{"Test psa_aead_decrypt - Invalid tag length 0\n", PSA_KEY_TYPE_AES,
-{0xD7, 0x82, 0x8D, 0x13, 0xB2, 0xB0, 0xBD, 0xC3, 0x25, 0xA7, 0x62, 0x36, 0xDF,
- 0x93, 0xCC, 0x6B},
- AES_16B_KEY_SIZE, PSA_KEY_USAGE_DECRYPT, PSA_ALG_AEAD_WITH_TAG_LENGTH(PSA_ALG_CCM, 0),
-{0x48, 0xc0, 0x90, 0x69, 0x30, 0x56, 0x1e, 0x0a, 0xb0, 0xef, 0x4c, 0xd9, 0x72},
- 13,
-{0x40, 0xa2, 0x7c, 0x1d, 0x1e, 0x23, 0xea, 0x3d, 0xbe, 0x80, 0x56, 0xb2, 0x77,
- 0x48, 0x61, 0xa4, 0xa2, 0x01, 0xcc, 0xe4, 0x9f, 0x19, 0x99, 0x7d, 0x19, 0x20,
- 0x6d, 0x8c, 0x8a, 0x34, 0x39, 0x51}, 32,
-{0x45, 0x35, 0xd1, 0x2b, 0x43, 0x77, 0x92, 0x8a, 0x7c, 0x0a, 0x61, 0xc9, 0xf8,
- 0x25, 0xa4, 0x86, 0x71, 0xea, 0x05, 0x91, 0x07, 0x48, 0xc8, 0xef}, BUFFER_SIZE,
-{0x26, 0xc5, 0x69, 0x61, 0xc0, 0x35, 0xa7, 0xe4, 0x52, 0xcc, 0xe6, 0x1b, 0xc6,
- 0xee, 0x22, 0x0d, 0x77, 0xb3, 0xf9, 0x4d, 0x18, 0xfd, 0x10, 0xb6, 0xd8, 0x0e,
- 0x8b, 0xf8, 0x0f, 0x4a, 0x46, 0xca, 0xb0, 0x6d, 0x43, 0x13, 0xf0, 0xdb, 0x9b,
- 0xe9}, 40, 24, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_aead_decrypt - Invalid cihpertext\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CCM,
+ .nonce = nonce,
+ .nonce_length = 13,
+ .additional_data = additional_data,
+ .additional_data_length = 32,
+ .ciphertext = aead_invalid_ciphertext_2,
+ .ciphertext_length = AEAD_CIPHERTEXT_LEN_2,
+ .plaintext = expected_output,
+ .expected_plaintext = plaintext,
+ .plaintext_size = BUFFER_SIZE,
+ .expected_plaintext_length = 24,
+ .expected_status = PSA_ERROR_INVALID_SIGNATURE
+},
+
+{
+ .test_desc = "Test psa_aead_decrypt - Invalid cihpertext_size\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CCM,
+ .nonce = nonce,
+ .nonce_length = 13,
+ .additional_data = additional_data,
+ .additional_data_length = 32,
+ .ciphertext = aead_ciphertext_2,
+ .ciphertext_length = AEAD_CIPHERTEXT_LEN_2-1,
+ .plaintext = expected_output,
+ .expected_plaintext = plaintext,
+ .plaintext_size = BUFFER_SIZE,
+ .expected_plaintext_length = 24,
+ .expected_status = PSA_ERROR_INVALID_SIGNATURE
+},
+
+{
+ .test_desc = "Test psa_aead_decrypt - Invalid tag length 0\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_AEAD_WITH_TAG_LENGTH(PSA_ALG_CCM, 0),
+ .nonce = nonce,
+ .nonce_length = 13,
+ .additional_data = additional_data,
+ .additional_data_length = 32,
+ .ciphertext = aead_ciphertext_2,
+ .ciphertext_length = AEAD_CIPHERTEXT_LEN_2,
+ .plaintext = expected_output,
+ .expected_plaintext = plaintext,
+ .plaintext_size = BUFFER_SIZE,
+ .expected_plaintext_length = 24,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
diff --git a/api-tests/dev_apis/crypto/test_c026/test_c026.c b/api-tests/dev_apis/crypto/test_c026/test_c026.c
index 22e10fb..a6437ed 100644
--- a/api-tests/dev_apis/crypto/test_c026/test_c026.c
+++ b/api-tests/dev_apis/crypto/test_c026/test_c026.c
@@ -27,7 +27,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
static psa_mac_operation_t operation;
int32_t psa_mac_sign_setup_test(caller_security_t caller __UNUSED)
diff --git a/api-tests/dev_apis/crypto/test_c027/test_c027.c b/api-tests/dev_apis/crypto/test_c027/test_c027.c
index 1b8f0ce..656df88 100644
--- a/api-tests/dev_apis/crypto/test_c027/test_c027.c
+++ b/api-tests/dev_apis/crypto/test_c027/test_c027.c
@@ -27,7 +27,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
static uint8_t data[BUFFER_SIZE];
int32_t psa_mac_update_test(caller_security_t caller __UNUSED)
diff --git a/api-tests/dev_apis/crypto/test_c028/test_c028.c b/api-tests/dev_apis/crypto/test_c028/test_c028.c
index b0c0242..5f4ee73 100644
--- a/api-tests/dev_apis/crypto/test_c028/test_c028.c
+++ b/api-tests/dev_apis/crypto/test_c028/test_c028.c
@@ -26,7 +26,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
static uint8_t data[BUFFER_SIZE];
int32_t psa_mac_sign_finish_test(caller_security_t caller __UNUSED)
diff --git a/api-tests/dev_apis/crypto/test_c029/test_c029.c b/api-tests/dev_apis/crypto/test_c029/test_c029.c
index 4496e85..91d479e 100644
--- a/api-tests/dev_apis/crypto/test_c029/test_c029.c
+++ b/api-tests/dev_apis/crypto/test_c029/test_c029.c
@@ -27,7 +27,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
static psa_mac_operation_t operation;
int32_t psa_mac_verify_setup_test(caller_security_t caller __UNUSED)
diff --git a/api-tests/dev_apis/crypto/test_c030/test_c030.c b/api-tests/dev_apis/crypto/test_c030/test_c030.c
index 3fe477d..ee81d29 100644
--- a/api-tests/dev_apis/crypto/test_c030/test_c030.c
+++ b/api-tests/dev_apis/crypto/test_c030/test_c030.c
@@ -26,7 +26,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
int32_t psa_mac_verify_finish_test(caller_security_t caller __UNUSED)
{
diff --git a/api-tests/dev_apis/crypto/test_c031/test_c031.c b/api-tests/dev_apis/crypto/test_c031/test_c031.c
index b98ce82..659b051 100644
--- a/api-tests/dev_apis/crypto/test_c031/test_c031.c
+++ b/api-tests/dev_apis/crypto/test_c031/test_c031.c
@@ -27,7 +27,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
static uint8_t data[BUFFER_SIZE];
int32_t psa_mac_abort_test(caller_security_t caller __UNUSED)
diff --git a/api-tests/dev_apis/crypto/test_c032/test_c032.c b/api-tests/dev_apis/crypto/test_c032/test_c032.c
index fdd7249..e858954 100644
--- a/api-tests/dev_apis/crypto/test_c032/test_c032.c
+++ b/api-tests/dev_apis/crypto/test_c032/test_c032.c
@@ -27,15 +27,15 @@
NULL,
};
-static int g_test_count = 1;
-static psa_cipher_operation_t operation;
+static uint32_t g_test_count = 1;
+static int32_t valid_test_input_index = -1;
int32_t psa_cipher_encrypt_setup_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
- const uint8_t *key_data;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+ psa_cipher_operation_t operation;
psa_key_handle_t key_handle;
if (num_checks == 0)
@@ -53,56 +53,26 @@
{
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, check1[i].test_desc, 0);
+ memset(&operation, 0, sizeof(operation));
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type))
- {
- if (check1[i].key_type == PSA_KEY_TYPE_RSA_KEY_PAIR)
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keypair;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keypair;
- else
- return VAL_STATUS_INVALID;
- }
- else
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keydata;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keydata;
- else
- return VAL_STATUS_INVALID;
- }
- }
- else if (PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
- {
- if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(check1[i].key_type))
- key_data = ec_keypair;
- else
- key_data = ec_keydata;
- }
- else
- key_data = check1[i].key_data;
-
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_BITS, &attributes, check1[i].attr_bits);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].key_alg);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_BITS, &attributes, check1[i].bits);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].alg);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage_flags);
/* Import the key data into the key slot */
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, key_data,
- check1[i].key_length, &key_handle);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Set the key for a multipart symmetric encryption operation */
status = val->crypto_function(VAL_CRYPTO_CIPHER_ENCRYPT_SETUP, &operation,
- key_handle, check1[i].key_alg);
+ key_handle, check1[i].alg);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(4));
/* Whether setup succeeded or failed, abort must succeed.
@@ -114,7 +84,7 @@
if (check1[i].expected_status != PSA_SUCCESS)
{
status = val->crypto_function(VAL_CRYPTO_CIPHER_ENCRYPT_SETUP, &operation,
- key_handle, check1[i].key_alg);
+ key_handle, check1[i].alg);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(6));
status = val->crypto_function(VAL_CRYPTO_CIPHER_ABORT, &operation);
@@ -127,6 +97,12 @@
/* Reset the key attributes and check if psa_import_key fails */
val->crypto_function(VAL_CRYPTO_RESET_KEY_ATTRIBUTES, &attributes);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_NOT_SUPPORTED, TEST_CHECKPOINT_NUM(9));
+
+ if (valid_test_input_index < 0)
+ valid_test_input_index = i;
}
return VAL_STATUS_SUCCESS;
@@ -134,37 +110,38 @@
int32_t psa_cipher_encrypt_setup_negative_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check2)/sizeof(check2[0]);
- int32_t i, status;
+ int32_t status;
+ psa_cipher_operation_t operation;
psa_key_handle_t key_handle = 16;
+ if (valid_test_input_index < 0)
+ return RESULT_SKIP(VAL_STATUS_NO_TESTS);
+
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
- for (i = 0; i < num_checks; i++)
- {
- /* Setting up the watchdog timer for each check */
- status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
- TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
+ /* Setting up the watchdog timer for each check */
+ status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
+ TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
+ memset(&operation, 0, sizeof(operation));
- val->print(PRINT_TEST, "[Check %d] Test psa_cipher_encrypt_setup - Invalid key handle\n",
- g_test_count++);
- /* Set the key for a multipart symmetric encryption operation */
- status = val->crypto_function(VAL_CRYPTO_CIPHER_ENCRYPT_SETUP, &operation,
- key_handle, check2[i].key_alg);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(3));
+ val->print(PRINT_TEST, "[Check %d] Test psa_cipher_encrypt_setup - Invalid key handle\n",
+ g_test_count++);
+ /* Set the key for a multipart symmetric encryption operation */
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_ENCRYPT_SETUP, &operation,
+ key_handle, check1[valid_test_input_index].alg);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(3));
- val->print(PRINT_TEST, "[Check %d] Test psa_cipher_encrypt_setup - Zero as key handle\n",
- g_test_count++);
- /* Set the key for a multipart symmetric encryption operation */
- status = val->crypto_function(VAL_CRYPTO_CIPHER_ENCRYPT_SETUP, &operation,
- 0, check2[i].key_alg);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(4));
+ val->print(PRINT_TEST, "[Check %d] Test psa_cipher_encrypt_setup - Zero as key handle\n",
+ g_test_count++);
+ /* Set the key for a multipart symmetric encryption operation */
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_ENCRYPT_SETUP, &operation,
+ 0, check1[valid_test_input_index].alg);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(4));
- status = val->crypto_function(VAL_CRYPTO_CIPHER_ABORT, &operation);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
- }
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_ABORT, &operation);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
return VAL_STATUS_SUCCESS;
}
diff --git a/api-tests/dev_apis/crypto/test_c032/test_data.h b/api-tests/dev_apis/crypto/test_c032/test_data.h
index c512c01..a8cef10 100644
--- a/api-tests/dev_apis/crypto/test_c032/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c032/test_data.h
@@ -15,300 +15,219 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- psa_key_type_t key_type;
- uint8_t key_data[64];
- uint32_t key_length;
- size_t attr_bits;
- psa_key_usage_t usage;
- psa_algorithm_t key_alg;
- size_t expected_bit_length;
+ psa_key_type_t type;
+ const uint8_t *data;
+ size_t data_length;
+ size_t bits;
+ psa_key_usage_t usage_flags;
+ psa_algorithm_t alg;
psa_status_t expected_status;
} test_data;
-static const uint8_t rsa_384_keypair[1];
-static const uint8_t rsa_384_keydata[1];
-
-static const uint8_t rsa_256_keypair[] = {
- 0x30, 0x82, 0x04, 0xA5, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xC0,
- 0x95, 0x08, 0xE1, 0x57, 0x41, 0xF2, 0x71, 0x6D, 0xB7, 0xD2, 0x45, 0x41, 0x27,
- 0x01, 0x65, 0xC6, 0x45, 0xAE, 0xF2, 0xBC, 0x24, 0x30, 0xB8, 0x95, 0xCE, 0x2F,
- 0x4E, 0xD6, 0xF6, 0x1C, 0x88, 0xBC, 0x7C, 0x9F, 0xFB, 0xA8, 0x67, 0x7F, 0xFE,
- 0x5C, 0x9C, 0x51, 0x75, 0xF7, 0x8A, 0xCA, 0x07, 0xE7, 0x35, 0x2F, 0x8F, 0xE1,
- 0xBD, 0x7B, 0xC0, 0x2F, 0x7C, 0xAB, 0x64, 0xA8, 0x17, 0xFC, 0xCA, 0x5D, 0x7B,
- 0xBA, 0xE0, 0x21, 0xE5, 0x72, 0x2E, 0x6F, 0x2E, 0x86, 0xD8, 0x95, 0x73, 0xDA,
- 0xAC, 0x1B, 0x53, 0xB9, 0x5F, 0x3F, 0xD7, 0x19, 0x0D, 0x25, 0x4F, 0xE1, 0x63,
- 0x63, 0x51, 0x8B, 0x0B, 0x64, 0x3F, 0xAD, 0x43, 0xB8, 0xA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3, 0x20};
-
-static const uint8_t ec_keypair[] = {
- 0x68, 0x49, 0xf9, 0x7d, 0x10, 0x66, 0xf6, 0x99, 0x77, 0x59, 0x63, 0x7c, 0x7e, 0x38,
- 0x99, 0x46, 0x4c, 0xee, 0x3e, 0xc7, 0xac, 0x97, 0x06, 0x53, 0xa0, 0xbe, 0x07, 0x42};
-
static const test_data check1[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
-{"Test psa_cipher_encrypt_setup 16 Byte AES\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0xD0}, AES_16B_KEY_SIZE, BYTES_TO_BITS(AES_16B_KEY_SIZE),
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR, BYTES_TO_BITS(AES_16B_KEY_SIZE),
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_encrypt_setup 16 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CTR,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_192
-{"Test psa_cipher_encrypt_setup 24 Byte AES\n", PSA_KEY_TYPE_AES,
-{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
- 0x40, 0xAC, 0xA3, 0x90, 0x77, 0x83, 0x52, 0x31, 0x74, 0xF9}, AES_24B_KEY_SIZE, 0,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR, BYTES_TO_BITS(AES_24B_KEY_SIZE),
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_encrypt_setup 24 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_24B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_24B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CTR,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_256
-{"Test psa_cipher_encrypt_setup 32 Byte AES\n", PSA_KEY_TYPE_AES,
-{0xEA, 0xD5, 0xE6, 0xC8, 0x51, 0xF9, 0xEC, 0xBB, 0x9B, 0x57, 0x7C, 0xED, 0xD2,
- 0x4B, 0x82, 0x84, 0x9F, 0x9F, 0xE6, 0x73, 0x21, 0x3D, 0x1A, 0x05, 0xC9, 0xED,
- 0xDF, 0x25, 0x17, 0x68, 0x86, 0xAE}, AES_32B_KEY_SIZE, 0,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR, BYTES_TO_BITS(AES_32B_KEY_SIZE),
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_encrypt_setup 32 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_32B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_32B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CTR,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CBC_NO_PADDING
#ifdef ARCH_TEST_DES_1KEY
-{"Test psa_cipher_encrypt_setup DES 64 bit key\n", PSA_KEY_TYPE_DES,
- {0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
- DES_8B_KEY_SIZE, 0, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING, BYTES_TO_BITS(DES_8B_KEY_SIZE),
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_encrypt_setup DES 64 bit key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES_8B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(DES_8B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_2KEY
-{"Test psa_cipher_encrypt_setup Triple DES 2-Key\n", PSA_KEY_TYPE_DES,
-{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
- DES3_2KEY_SIZE, 0, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING, BYTES_TO_BITS(DES3_2KEY_SIZE),
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_encrypt_setup Triple DES 2-Key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_2B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(DES3_2B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_3KEY
-{"Test psa_cipher_encrypt_setup Triple DES 3-Key\n", PSA_KEY_TYPE_DES,
-{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
- 0xF1, 0xE0, 0xD3, 0xC2, 0xB5, 0xA4, 0x97, 0x86,
- 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10},
- DES3_3KEY_SIZE, 0, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING, BYTES_TO_BITS(DES3_3KEY_SIZE),
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_encrypt_setup Triple DES 3-Key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_3B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(DES3_3B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
-{"Test psa_cipher_encrypt_setup 16 Byte raw data\n", PSA_KEY_TYPE_RAW_DATA,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0xD0}, AES_16B_KEY_SIZE, 0,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR, BYTES_TO_BITS(AES_16B_KEY_SIZE),
- PSA_ERROR_NOT_SUPPORTED
+{
+ .test_desc = "Test psa_cipher_encrypt_setup 16 Byte raw data\n",
+ .type = PSA_KEY_TYPE_RAW_DATA,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CTR,
+ .expected_status = PSA_ERROR_NOT_SUPPORTED
},
#endif
#ifdef ARCH_TEST_AES_128
#ifdef ARCH_TEST_CMAC
-{"Test psa_cipher_encrypt_setup - not a cipher algorithm\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0xD0}, AES_16B_KEY_SIZE, 0,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CMAC, BYTES_TO_BITS(AES_16B_KEY_SIZE),
- PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_cipher_encrypt_setup - not a cipher algorithm\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CMAC,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#ifdef ARCH_TEST_CIPER
-{"Test psa_cipher_encrypt_setup - unknown cipher algorithm\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0xD0}, AES_16B_KEY_SIZE, 0,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CATEGORY_CIPHER, BYTES_TO_BITS(AES_16B_KEY_SIZE),
- PSA_ERROR_NOT_SUPPORTED
+{
+ .test_desc = "Test psa_cipher_encrypt_setup - unknown cipher algorithm\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CATEGORY_CIPHER,
+ .expected_status = PSA_ERROR_NOT_SUPPORTED
},
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_ARC4
-{"Test psa_cipher_encrypt_setup - incompatible key ARC4\n", PSA_KEY_TYPE_ARC4,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0xD0}, AES_16B_KEY_SIZE, 0,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR, BYTES_TO_BITS(AES_16B_KEY_SIZE),
- PSA_ERROR_NOT_SUPPORTED
+{
+ .test_desc = "Test psa_cipher_encrypt_setup - incompatible key ARC4\n",
+ .type = PSA_KEY_TYPE_ARC4,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CTR,
+ .expected_status = PSA_ERROR_NOT_SUPPORTED
},
#endif
-{"Test psa_cipher_encrypt_setup - incorrect usage\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0xD0}, AES_16B_KEY_SIZE, 0,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CTR, BYTES_TO_BITS(AES_16B_KEY_SIZE),
- PSA_ERROR_NOT_PERMITTED
+{
+ .test_desc = "Test psa_cipher_encrypt_setup - incorrect usage\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CTR,
+ .expected_status = PSA_ERROR_NOT_PERMITTED
},
#endif
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
#ifdef ARCH_TEST_RSA_2048
-{"Test psa_cipher_encrypt_setup - RSA public key\n", PSA_KEY_TYPE_RSA_PUBLIC_KEY,
-{0}, 270, 0,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW, 2048,
- PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_cipher_encrypt_setup - RSA public key\n",
+ .type = PSA_KEY_TYPE_RSA_PUBLIC_KEY,
+ .data = rsa_256_key_data,
+ .data_length = 270,
+ .bits = BYTES_TO_BITS(256),
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
-{"Test psa_cipher_encrypt_setup - RSA keypair\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 1193, 0,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW, 2048,
- PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_cipher_encrypt_setup - RSA keypair\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_256_key_pair,
+ .data_length = 1193,
+ .bits = BYTES_TO_BITS(256),
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
#ifdef ARCH_TEST_ASYMMETRIC_ENCRYPTION
#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
-{"Test psa_cipher_encrypt_setup - EC Public key\n",
- PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1), {0}, 65, 0,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION, 256,
- PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_cipher_encrypt_setup - EC Public key\n",
+ .type = PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
+ .data = ec_key_data,
+ .data_length = 65,
+ .bits = 256,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#ifdef ARCH_TEST_ECC_CURVE_SECP224R1
-{"Test psa_cipher_encrypt_setup - EC keypair\n",
- PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP224R1), {0}, 28, 0,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION, 224,
- PSA_ERROR_INVALID_ARGUMENT
-},
-#endif
-#endif
-};
-
-static const test_data check2[] = {
-#ifdef ARCH_TEST_CIPER_MODE_CTR
-#ifdef ARCH_TEST_AES_128
-{"Test psa_cipher_encrypt_setup negative cases\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0xD0}, AES_16B_KEY_SIZE, 0,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR, BYTES_TO_BITS(AES_16B_KEY_SIZE),
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_encrypt_setup - EC keypair\n",
+ .type = PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP224R1),
+ .data = ec_key_pair,
+ .data_length = 28,
+ .bits = 224,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
diff --git a/api-tests/dev_apis/crypto/test_c033/test_c033.c b/api-tests/dev_apis/crypto/test_c033/test_c033.c
index 3462afb..5447ee1 100644
--- a/api-tests/dev_apis/crypto/test_c033/test_c033.c
+++ b/api-tests/dev_apis/crypto/test_c033/test_c033.c
@@ -27,15 +27,15 @@
NULL,
};
-static int g_test_count = 1;
-static psa_cipher_operation_t operation;
+static uint32_t g_test_count = 1;
+static int32_t valid_test_input_index = -1;
int32_t psa_cipher_decrypt_setup_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
- const uint8_t *key_data;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+ psa_cipher_operation_t operation;
psa_key_handle_t key_handle;
if (num_checks == 0)
@@ -53,55 +53,25 @@
{
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, check1[i].test_desc, 0);
+ memset(&operation, 0, sizeof(operation));
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type))
- {
- if (check1[i].key_type == PSA_KEY_TYPE_RSA_KEY_PAIR)
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keypair;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keypair;
- else
- return VAL_STATUS_INVALID;
- }
- else
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keydata;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keydata;
- else
- return VAL_STATUS_INVALID;
- }
- }
- else if (PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
- {
- if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(check1[i].key_type))
- key_data = ec_keypair;
- else
- key_data = ec_keydata;
- }
- else
- key_data = check1[i].key_data;
-
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].key_alg);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].alg);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage_flags);
/* Import the key data into the key slot */
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, key_data,
- check1[i].key_length, &key_handle);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Set the key for a multipart symmetric decryption operation */
- status = val->crypto_function(VAL_CRYPTO_CIPHER_DECRYPT_SETUP, &operation,
- key_handle, check1[i].key_alg);
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_DECRYPT_SETUP, &operation, key_handle,
+ check1[i].alg);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(4));
/* Whether setup succeeded or failed, abort must succeed.
@@ -112,8 +82,8 @@
if (check1[i].expected_status != PSA_SUCCESS)
{
- status = val->crypto_function(VAL_CRYPTO_CIPHER_DECRYPT_SETUP, &operation,
- key_handle, check1[i].key_alg);
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_DECRYPT_SETUP, &operation, key_handle,
+ check1[i].alg);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(6));
/* Abort a cipher operation */
@@ -127,6 +97,12 @@
/* Reset the key attributes and check if psa_import_key fails */
val->crypto_function(VAL_CRYPTO_RESET_KEY_ATTRIBUTES, &attributes);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_NOT_SUPPORTED, TEST_CHECKPOINT_NUM(9));
+
+ if (valid_test_input_index < 0)
+ valid_test_input_index = i;
}
return VAL_STATUS_SUCCESS;
@@ -134,37 +110,42 @@
int32_t psa_cipher_decrypt_setup_negative_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check2)/sizeof(check2[0]);
- int32_t i, status;
+ int32_t status;
+ psa_cipher_operation_t operation;
psa_key_handle_t key_handle = 16;
+ if (valid_test_input_index < 0)
+ return RESULT_SKIP(VAL_STATUS_NO_TESTS);
+
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
- for (i = 0; i < num_checks; i++)
- {
- /* Setting up the watchdog timer for each check */
- status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
- TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
+ memset(&operation, 0, sizeof(operation));
- val->print(PRINT_TEST, "[Check %d] Test psa_cipher_decrypt_setup - Invalid key handle\n",
- g_test_count++);
- /* Set the key for a multipart symmetric decryption operation */
- status = val->crypto_function(VAL_CRYPTO_CIPHER_DECRYPT_SETUP, &operation,
- key_handle, check2[i].key_alg);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(3));
+ /* Setting up the watchdog timer for each check */
+ status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
+ TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- val->print(PRINT_TEST, "[Check %d] Test psa_cipher_decrypt_setup - Zero as key handle\n",
- g_test_count++);
- /* Set the key for a multipart symmetric decryption operation */
- status = val->crypto_function(VAL_CRYPTO_CIPHER_DECRYPT_SETUP, &operation,
- 0, check2[i].key_alg);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(4));
+ val->print(PRINT_TEST, "[Check %d] Test psa_cipher_decrypt_setup - Invalid key handle\n",
+ g_test_count++);
+ /* Set the key for a multipart symmetric decryption operation */
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_DECRYPT_SETUP, &operation, key_handle,
+ check1[valid_test_input_index].alg);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(3));
- status = val->crypto_function(VAL_CRYPTO_CIPHER_ABORT, &operation);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
- }
+ val->print(PRINT_TEST, "[Check %d] Test psa_cipher_decrypt_setup - Zero as key handle\n",
+ g_test_count++);
+
+ memset(&operation, 0, sizeof(operation));
+
+ /* Set the key for a multipart symmetric decryption operation */
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_DECRYPT_SETUP, &operation, 0,
+ check1[valid_test_input_index].alg);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(4));
+
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_ABORT, &operation);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
return VAL_STATUS_SUCCESS;
}
diff --git a/api-tests/dev_apis/crypto/test_c033/test_data.h b/api-tests/dev_apis/crypto/test_c033/test_data.h
index c847a08..a1a9d3b 100644
--- a/api-tests/dev_apis/crypto/test_c033/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c033/test_data.h
@@ -15,299 +15,203 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- psa_key_type_t key_type;
- uint8_t key_data[64];
- uint32_t key_length;
- psa_key_usage_t usage;
- psa_algorithm_t key_alg;
- size_t expected_bit_length;
+ psa_key_type_t type;
+ const uint8_t *data;
+ size_t data_length;
+ psa_key_usage_t usage_flags;
+ psa_algorithm_t alg;
psa_status_t expected_status;
} test_data;
-static const uint8_t rsa_384_keypair[1];
-static const uint8_t rsa_384_keydata[1];
-
-static const uint8_t rsa_256_keypair[] = {
- 0x30, 0x82, 0x04, 0xA5, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xC0,
- 0x95, 0x08, 0xE1, 0x57, 0x41, 0xF2, 0x71, 0x6D, 0xB7, 0xD2, 0x45, 0x41, 0x27,
- 0x01, 0x65, 0xC6, 0x45, 0xAE, 0xF2, 0xBC, 0x24, 0x30, 0xB8, 0x95, 0xCE, 0x2F,
- 0x4E, 0xD6, 0xF6, 0x1C, 0x88, 0xBC, 0x7C, 0x9F, 0x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-
-static const uint8_t ec_keydata[] = {
- 0x04, 0xde, 0xa5, 0xe4, 0x5d, 0x0e, 0xa3, 0x7f, 0xc5, 0x66, 0x23, 0x2a, 0x50, 0x8f,
- 0x4a, 0xd2, 0x0e, 0xa1, 0x3d, 0x47, 0xe4, 0xbf, 0x5f, 0xa4, 0xd5, 0x4a, 0x57, 0xa0,
- 0xba, 0x01, 0x20, 0x42, 0x08, 0x70, 0x97, 0x49, 0x6e, 0xfc, 0x58, 0x3f, 0xed, 0x8b,
- 0x24, 0xa5, 0xb9, 0xbe, 0x9a, 0x51, 0xde, 0x06, 0x3f, 0x5a, 0x00, 0xa8, 0xb6, 0x98,
- 0xa1, 0x6f, 0xd7, 0xf2, 0x9b, 0x54, 0x85, 0xf3, 0x20};
-
-static const uint8_t ec_keypair[] = {
- 0x68, 0x49, 0xf9, 0x7d, 0x10, 0x66, 0xf6, 0x99, 0x77, 0x59, 0x63, 0x7c, 0x7e, 0x38,
- 0x99, 0x46, 0x4c, 0xee, 0x3e, 0xc7, 0xac, 0x97, 0x06, 0x53, 0xa0, 0xbe, 0x07, 0x42};
-
static const test_data check1[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
-{"Test psa_cipher_decrypt_setup 16 Byte AES\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0xD0}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CTR, BYTES_TO_BITS(AES_16B_KEY_SIZE),
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_decrypt_setup 16 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CTR,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_192
-{"Test psa_cipher_decrypt_setup 24 Byte AES\n", PSA_KEY_TYPE_AES,
-{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
- 0x40, 0xAC, 0xA3, 0x90, 0x77, 0x83, 0x52, 0x31, 0x74, 0xF9}, AES_24B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CTR, BYTES_TO_BITS(AES_24B_KEY_SIZE),
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_decrypt_setup 24 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_24B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CTR,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_256
-{"Test psa_cipher_decrypt_setup 32 Byte AES\n", PSA_KEY_TYPE_AES,
-{0xEA, 0xD5, 0xE6, 0xC8, 0x51, 0xF9, 0xEC, 0xBB, 0x9B, 0x57, 0x7C, 0xED, 0xD2,
- 0x4B, 0x82, 0x84, 0x9F, 0x9F, 0xE6, 0x73, 0x21, 0x3D, 0x1A, 0x05, 0xC9, 0xED,
- 0xDF, 0x25, 0x17, 0x68, 0x86, 0xAE}, AES_32B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CTR, BYTES_TO_BITS(AES_32B_KEY_SIZE),
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_decrypt_setup 32 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_32B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CTR,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CBC_NO_PADDING
#ifdef ARCH_TEST_DES_1KEY
-{"Test psa_cipher_decrypt_setup DES 64 bit key\n", PSA_KEY_TYPE_DES,
- {0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
- DES_8B_KEY_SIZE, PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING, BYTES_TO_BITS(DES_8B_KEY_SIZE),
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_decrypt_setup DES 64 bit key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES_8B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_2KEY
-{"Test psa_cipher_decrypt_setup Triple DES 2-Key\n", PSA_KEY_TYPE_DES,
-{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
- DES3_2KEY_SIZE, PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING, BYTES_TO_BITS(DES3_2KEY_SIZE),
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_decrypt_setup Triple DES 2-Key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_2B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_3KEY
-{"Test psa_cipher_decrypt_setup Triple DES 3-Key\n", PSA_KEY_TYPE_DES,
-{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
- 0xF1, 0xE0, 0xD3, 0xC2, 0xB5, 0xA4, 0x97, 0x86,
- 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10},
- DES3_3KEY_SIZE, PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING, BYTES_TO_BITS(DES3_3KEY_SIZE),
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_decrypt_setup Triple DES 3-Key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_3B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_AES_128
#ifdef ARCH_TEST_CIPER_MODE_CTR
-{"Test psa_cipher_decrypt_setup 16 Byte raw data\n", PSA_KEY_TYPE_RAW_DATA,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0xD0}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CTR, BYTES_TO_BITS(AES_16B_KEY_SIZE),
- PSA_ERROR_NOT_SUPPORTED
+{
+ .test_desc = "Test psa_cipher_decrypt_setup 16 Byte raw data\n",
+ .type = PSA_KEY_TYPE_RAW_DATA,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CTR,
+ .expected_status = PSA_ERROR_NOT_SUPPORTED
},
#endif
#ifdef ARCH_TEST_CMAC
-{"Test psa_cipher_decrypt_setup - not a cipher algorithm\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0xD0}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CMAC, BYTES_TO_BITS(AES_16B_KEY_SIZE),
- PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_cipher_decrypt_setup - not a cipher algorithm\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CMAC,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#ifdef ARCH_TEST_CIPER
-{"Test psa_cipher_decrypt_setup - unknown cipher algorithm\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0xD0}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CATEGORY_CIPHER, BYTES_TO_BITS(AES_16B_KEY_SIZE),
- PSA_ERROR_NOT_SUPPORTED
+{
+ .test_desc = "Test psa_cipher_decrypt_setup - unknown cipher algorithm\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CATEGORY_CIPHER,
+ .expected_status = PSA_ERROR_NOT_SUPPORTED
},
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_ARC4
-{"Test psa_cipher_decrypt_setup - incompatible key ARC4\n", PSA_KEY_TYPE_ARC4,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0xD0}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CTR, BYTES_TO_BITS(AES_16B_KEY_SIZE),
- PSA_ERROR_NOT_SUPPORTED
+{
+ .test_desc = "Test psa_cipher_decrypt_setup - incompatible key ARC4\n",
+ .type = PSA_KEY_TYPE_ARC4,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CTR,
+ .expected_status = PSA_ERROR_NOT_SUPPORTED
},
#endif
-{"Test psa_cipher_decrypt_setup - incorrect usage\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0xD0}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR, BYTES_TO_BITS(AES_16B_KEY_SIZE),
- PSA_ERROR_NOT_PERMITTED
+{
+ .test_desc = "Test psa_cipher_decrypt_setup - incorrect usage\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CTR,
+ .expected_status = PSA_ERROR_NOT_PERMITTED
},
#endif
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
#ifdef ARCH_TEST_RSA_2048
-{"Test psa_cipher_decrypt_setup - RSA public key\n", PSA_KEY_TYPE_RSA_PUBLIC_KEY,
-{0}, 270,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW, 2048,
- PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_cipher_decrypt_setup - RSA public key\n",
+ .type = PSA_KEY_TYPE_RSA_PUBLIC_KEY,
+ .data = rsa_256_key_data,
+ .data_length = 270,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
-{"Test psa_cipher_decrypt_setup - RSA keypair\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 1193,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW, 2048,
- PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_cipher_decrypt_setup - RSA keypair\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_256_key_pair,
+ .data_length = 1193,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
-#ifdef ARCH_TEST_RSA_PKCS1V15_CRYPT
+#ifdef ARCH_TEST_ASYMMETRIC_ENCRYPTION
#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
-{"Test psa_cipher_decrypt_setup - EC Public key\n",
- PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1), {0}, 65,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_RSA_PKCS1V15_CRYPT, 192,
- PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_cipher_decrypt_setup - EC Public key\n",
+ .type = PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
+ .data = ec_key_data,
+ .data_length = 65,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#ifdef ARCH_TEST_ECC_CURVE_SECP224R1
-{"Test psa_cipher_decrypt_setup - EC keypair\n",
- PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP224R1), {0}, 28,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_RSA_PKCS1V15_CRYPT, 224,
- PSA_ERROR_INVALID_ARGUMENT
-},
-#endif
-#endif
-};
-
-static const test_data check2[] = {
-#ifdef ARCH_TEST_CIPER_MODE_CTR
-#ifdef ARCH_TEST_AES_128
-{"Test psa_cipher_decrypt_setup - negative test\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0xD0}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CTR, BYTES_TO_BITS(AES_16B_KEY_SIZE),
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_decrypt_setup - EC keypair\n",
+ .type = PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP224R1),
+ .data = ec_key_pair,
+ .data_length = 28,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
diff --git a/api-tests/dev_apis/crypto/test_c034/test_c034.c b/api-tests/dev_apis/crypto/test_c034/test_c034.c
index 9c7885f..b248185 100644
--- a/api-tests/dev_apis/crypto/test_c034/test_c034.c
+++ b/api-tests/dev_apis/crypto/test_c034/test_c034.c
@@ -20,21 +20,17 @@
#include "test_c034.h"
#include "test_data.h"
-
const client_test_t test_c034_crypto_list[] = {
NULL,
psa_cipher_generate_iv_test,
NULL,
};
-static int g_test_count = 1;
-
int32_t psa_cipher_generate_iv_test(caller_security_t caller __UNUSED)
{
- int i, num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t i, num_checks = sizeof(check1)/sizeof(check1[0]);
uint32_t j, iv_sum;
- uint8_t iv[32];
- size_t iv_length;
+ size_t expected_iv_length;
psa_cipher_operation_t operation;
int32_t status;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -52,7 +48,7 @@
for (i = 0; i < num_checks; i++)
{
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] ", i+1);
val->print(PRINT_TEST, check1[i].test_desc, 0);
memset(&operation, 0, sizeof(operation));
@@ -61,23 +57,23 @@
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].key_alg);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].alg);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage_flags);
/* Import the key data into the key slot */
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].key_data,
- check1[i].key_length, &key_handle);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Set the key for a multipart symmetric encryption operation */
- status = val->crypto_function(VAL_CRYPTO_CIPHER_ENCRYPT_SETUP, &operation,
- key_handle, check1[i].key_alg);
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_ENCRYPT_SETUP, &operation, key_handle,
+ check1[i].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Generate an IV for a symmetric encryption operation */
- status = val->crypto_function(VAL_CRYPTO_CIPHER_GENERATE_IV, &operation, iv,
- check1[i].iv_size, &iv_length);
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_GENERATE_IV, &operation, check1[i].iv,
+ check1[i].iv_size, &expected_iv_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(5));
if (check1[i].expected_status != PSA_SUCCESS)
@@ -94,13 +90,11 @@
}
/* Check that if generated iv length match the expected length */
- TEST_ASSERT_EQUAL(iv_length, check1[i].expected_iv_length, TEST_CHECKPOINT_NUM(8));
+ TEST_ASSERT_EQUAL(expected_iv_length, check1[i].expected_iv_length, TEST_CHECKPOINT_NUM(8));
iv_sum = 0;
- for (j = 0; j < iv_length; j++)
- {
- iv_sum += iv[j];
- }
+ for (j = 0; j < expected_iv_length; j++)
+ iv_sum += check1[i].iv[j];
/* Check that if generated iv are not zero */
TEST_ASSERT_NOT_EQUAL(iv_sum, 0, TEST_CHECKPOINT_NUM(9));
@@ -108,8 +102,8 @@
/* Generating an IV for a symmetric encryption operation using the same operator
* should fail
*/
- status = val->crypto_function(VAL_CRYPTO_CIPHER_GENERATE_IV, &operation, iv,
- check1[i].iv_size, &iv_length);
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_GENERATE_IV, &operation, check1[i].iv,
+ check1[i].iv_size, &expected_iv_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(10));
/* Abort a cipher operation */
@@ -122,6 +116,9 @@
/* Reset the key attributes and check if psa_import_key fails */
val->crypto_function(VAL_CRYPTO_RESET_KEY_ATTRIBUTES, &attributes);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_NOT_SUPPORTED, TEST_CHECKPOINT_NUM(3));
}
return VAL_STATUS_SUCCESS;
diff --git a/api-tests/dev_apis/crypto/test_c034/test_data.h b/api-tests/dev_apis/crypto/test_c034/test_data.h
index d03dae9..79212bf 100644
--- a/api-tests/dev_apis/crypto/test_c034/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c034/test_data.h
@@ -1,5 +1,5 @@
/** @file
- * Copyright (c) 2019-2020 Arm Limited or its affiliates. All rights reserved.
+ * Copyright (c) 2019-2020, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,15 +15,16 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- psa_key_type_t key_type;
- uint8_t key_data[32];
- uint32_t key_length;
- psa_key_usage_t usage;
- psa_algorithm_t key_alg;
+ psa_key_type_t type;
+ const uint8_t *data;
+ size_t data_length;
+ psa_key_usage_t usage_flags;
+ psa_algorithm_t alg;
+ unsigned char *iv;
size_t iv_size;
size_t expected_iv_length;
psa_status_t expected_status;
@@ -32,106 +33,128 @@
static const test_data check1[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
-{"Test psa_cipher_generate_iv 16 Byte AES\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0xD0}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR, 16, 16,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_generate_iv 16 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CTR,
+ .iv = expected_output,
+ .iv_size = BUFFER_SIZE,
+ .expected_iv_length = 16,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_192
-{"Test psa_cipher_generate_iv 24 Byte AES\n", PSA_KEY_TYPE_AES,
-{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
- 0x40, 0xAC, 0xA3, 0x90, 0x77, 0x83, 0x52, 0x31, 0x74, 0xF9}, AES_24B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR, 16, 16,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_generate_iv 24 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_24B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CTR,
+ .iv = expected_output,
+ .iv_size = BUFFER_SIZE,
+ .expected_iv_length = 16,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_256
-{"Test psa_cipher_generate_iv 32 Byte AES\n", PSA_KEY_TYPE_AES,
-{0xEA, 0xD5, 0xE6, 0xC8, 0x51, 0xF9, 0xEC, 0xBB, 0x9B, 0x57, 0x7C, 0xED, 0xD2,
- 0x4B, 0x82, 0x84, 0x9F, 0x9F, 0xE6, 0x73, 0x21, 0x3D, 0x1A, 0x05, 0xC9, 0xED,
- 0xDF, 0x25, 0x17, 0x68, 0x86, 0xAE}, AES_32B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR, 16, 16,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_generate_iv 32 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_32B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CTR,
+ .iv = expected_output,
+ .iv_size = BUFFER_SIZE,
+ .expected_iv_length = 16,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CBC_NO_PADDING
#ifdef ARCH_TEST_DES_1KEY
-{"Test psa_cipher_generate_iv DES 64 bit key\n", PSA_KEY_TYPE_DES,
- {0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
- DES_8B_KEY_SIZE, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
- 8, 8,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_generate_iv DES 64 bit key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES_8B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = expected_output,
+ .iv_size = BUFFER_SIZE,
+ .expected_iv_length = 8,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_2KEY
-{"Test psa_cipher_generate_iv Triple DES 2-Key\n", PSA_KEY_TYPE_DES,
-{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
- DES3_2KEY_SIZE, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
- 8, 8,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_generate_iv DES 2-Key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_2B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = expected_output,
+ .iv_size = BUFFER_SIZE,
+ .expected_iv_length = 8,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_3KEY
-{"Test psa_cipher_generate_iv Triple DES 3-Key\n", PSA_KEY_TYPE_DES,
-{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
- 0xF1, 0xE0, 0xD3, 0xC2, 0xB5, 0xA4, 0x97, 0x86,
- 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10},
- DES3_3KEY_SIZE, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
- 8, 8,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_generate_iv DES 3-Key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_3B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = expected_output,
+ .iv_size = BUFFER_SIZE,
+ .expected_iv_length = 8,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
-{"Test psa_cipher_generate_iv AES - small iv buffer\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0xD0}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR, 8, 16,
- PSA_ERROR_BUFFER_TOO_SMALL
+{
+ .test_desc = "Test psa_cipher_generate_iv AES - small iv buffer\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CTR,
+ .iv = expected_output,
+ .iv_size = 8,
+ .expected_iv_length = 16,
+ .expected_status = PSA_ERROR_BUFFER_TOO_SMALL
},
#endif
#endif
#ifdef ARCH_TEST_CBC_NO_PADDING
#ifdef ARCH_TEST_DES_1KEY
-{"Test psa_cipher_generate_iv DES - small iv buffer\n", PSA_KEY_TYPE_DES,
- {0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
- DES_8B_KEY_SIZE, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
- 4, 8,
- PSA_ERROR_BUFFER_TOO_SMALL
-},
-#endif
-#endif
-
-#ifdef ARCH_TEST_CIPER_MODE_CTR
-#ifdef ARCH_TEST_AES_128
-{"Test psa_cipher_generate_iv AES - large iv buffer\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0xD0}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR, 32, 16,
- PSA_SUCCESS
-},
-#endif
-#endif
-
-#ifdef ARCH_TEST_CBC_NO_PADDING
-#ifdef ARCH_TEST_DES_1KEY
-{"Test psa_cipher_generate_iv DES - large iv buffer\n", PSA_KEY_TYPE_DES,
- {0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
- DES_8B_KEY_SIZE, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
- 16, 8,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_generate_iv DES - small iv buffer\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES_8B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = expected_output,
+ .iv_size = 4,
+ .expected_iv_length = 8,
+ .expected_status = PSA_ERROR_BUFFER_TOO_SMALL
},
#endif
#endif
diff --git a/api-tests/dev_apis/crypto/test_c035/test_c035.c b/api-tests/dev_apis/crypto/test_c035/test_c035.c
index 2fd4f35..43fed89 100644
--- a/api-tests/dev_apis/crypto/test_c035/test_c035.c
+++ b/api-tests/dev_apis/crypto/test_c035/test_c035.c
@@ -20,18 +20,15 @@
#include "test_c035.h"
#include "test_data.h"
-
const client_test_t test_c035_crypto_list[] = {
NULL,
psa_cipher_set_iv_test,
NULL,
};
-static int g_test_count = 1;
-
int32_t psa_cipher_set_iv_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
psa_cipher_operation_t operation;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -49,7 +46,7 @@
for (i = 0; i < num_checks; i++)
{
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] ", i+1);
val->print(PRINT_TEST, check1[i].test_desc, 0);
memset(&operation, 0, sizeof(operation));
@@ -58,30 +55,30 @@
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].key_alg);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].alg);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage_flags);
/* Import the key data into the key slot */
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].key_data,
- check1[i].key_length, &key_handle);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Set the key for a multipart symmetric encryption operation */
- status = val->crypto_function(VAL_CRYPTO_CIPHER_ENCRYPT_SETUP, &operation,
- key_handle, check1[i].key_alg);
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_ENCRYPT_SETUP, &operation, key_handle,
+ check1[i].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Set an IV for a symmetric encryption operation */
status = val->crypto_function(VAL_CRYPTO_CIPHER_SET_IV, &operation, check1[i].iv,
- check1[i].iv_size);
+ check1[i].iv_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(5));
/* Setting an IV for a symmetric encryption operation using the same operator
* should fail for both previous success and failure cases
*/
status = val->crypto_function(VAL_CRYPTO_CIPHER_SET_IV, &operation, check1[i].iv,
- check1[i].iv_size);
+ check1[i].iv_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(6));
/* Abort a cipher operation */
@@ -94,6 +91,9 @@
/* Reset the key attributes and check if psa_import_key fails */
val->crypto_function(VAL_CRYPTO_RESET_KEY_ATTRIBUTES, &attributes);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_NOT_SUPPORTED, TEST_CHECKPOINT_NUM(9));
}
return VAL_STATUS_SUCCESS;
diff --git a/api-tests/dev_apis/crypto/test_c035/test_data.h b/api-tests/dev_apis/crypto/test_c035/test_data.h
index 9f4d653..ae2e880 100644
--- a/api-tests/dev_apis/crypto/test_c035/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c035/test_data.h
@@ -15,135 +15,169 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- psa_key_type_t key_type;
- uint8_t key_data[32];
- uint32_t key_length;
- psa_key_usage_t usage;
- psa_algorithm_t key_alg;
- uint8_t iv[32];
- size_t iv_size;
+ psa_key_type_t type;
+ const uint8_t *data;
+ size_t data_length;
+ psa_key_usage_t usage_flags;
+ psa_algorithm_t alg;
+ const unsigned char *iv;
+ size_t iv_length;
psa_status_t expected_status;
} test_data;
static const test_data check1[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
-{"Test psa_cipher_set_iv 16 Byte AES\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0xD0}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR,
-{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
- 0x0D, 0x0E, 0x0F}, 16,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_set_iv 16 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CTR,
+ .iv = iv,
+ .iv_length = 16,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_192
-{"Test psa_cipher_set_iv 24 Byte AES\n", PSA_KEY_TYPE_AES,
-{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
- 0x40, 0xAC, 0xA3, 0x90, 0x77, 0x83, 0x52, 0x31, 0x74, 0xF9}, AES_24B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR,
-{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
- 0x0D, 0x0E, 0x0F}, 16,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_set_iv 24 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_24B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CTR,
+ .iv = iv,
+ .iv_length = 16,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_256
-{"Test psa_cipher_set_iv 32 Byte AES\n", PSA_KEY_TYPE_AES,
-{0xEA, 0xD5, 0xE6, 0xC8, 0x51, 0xF9, 0xEC, 0xBB, 0x9B, 0x57, 0x7C, 0xED, 0xD2,
- 0x4B, 0x82, 0x84, 0x9F, 0x9F, 0xE6, 0x73, 0x21, 0x3D, 0x1A, 0x05, 0xC9, 0xED,
- 0xDF, 0x25, 0x17, 0x68, 0x86, 0xAE}, AES_32B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR,
-{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
- 0x0D, 0x0E, 0x0F}, 16,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_set_iv 32 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_32B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CTR,
+ .iv = iv,
+ .iv_length = 16,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CBC_AES_NO_PADDING
#ifdef ARCH_TEST_DES_1KEY
-{"Test psa_cipher_set_iv DES 64 bit key\n", PSA_KEY_TYPE_DES,
- {0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
- DES_8B_KEY_SIZE, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
- {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, 8,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_set_iv DES 64 bit key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES_8B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 8,
+ .expected_status = PSA_SUCCESS
},
-
#endif
#ifdef ARCH_TEST_DES_2KEY
-{"Test psa_cipher_set_iv Triple DES 2-Key\n", PSA_KEY_TYPE_DES,
-{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
- DES3_2KEY_SIZE, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
- {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, 8,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_set_iv DES 2-Key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_2B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 8,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_3KEY
-{"Test psa_cipher_set_iv Triple DES 3-Key\n", PSA_KEY_TYPE_DES,
-{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
- 0xF1, 0xE0, 0xD3, 0xC2, 0xB5, 0xA4, 0x97, 0x86,
- 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10},
- DES3_3KEY_SIZE, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
- {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, 8,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_set_iv DES 3-Key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_3B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 8,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
-{"Test psa_cipher_set_iv AES - small iv buffer\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0xD0}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR,
- {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, 8,
- PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_cipher_set_iv AES - small iv buffer\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CTR,
+ .iv = iv,
+ .iv_length = 8,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
#ifdef ARCH_TEST_CBC_AES_NO_PADDING
#ifdef ARCH_TEST_DES_1KEY
-{"Test psa_cipher_set_iv DES - small iv buffer\n", PSA_KEY_TYPE_DES,
- {0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
- DES_8B_KEY_SIZE, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x00, 0x01, 0x02, 0x03,}, 4,
- PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_cipher_set_iv DES - small iv buffer\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES_8B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 4,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
-{"Test psa_cipher_set_iv AES - large iv buffer\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0xD0}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR,
-{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
- 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
- 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F}, 32,
- PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_cipher_set_iv AES - large iv buffer\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CTR,
+ .iv = iv,
+ .iv_length = 17,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
#ifdef ARCH_TEST_CBC_AES_NO_PADDING
#ifdef ARCH_TEST_DES_1KEY
-{"Test psa_cipher_set_iv DES - large iv buffer\n", PSA_KEY_TYPE_DES,
- {0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
- DES_8B_KEY_SIZE, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
- 0x0D, 0x0E, 0x0F}, 16,
- PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_cipher_set_iv DES - large iv buffer\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES_8B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 16,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
diff --git a/api-tests/dev_apis/crypto/test_c036/test_c036.c b/api-tests/dev_apis/crypto/test_c036/test_c036.c
index 9ce3ad1..4320005 100644
--- a/api-tests/dev_apis/crypto/test_c036/test_c036.c
+++ b/api-tests/dev_apis/crypto/test_c036/test_c036.c
@@ -20,7 +20,6 @@
#include "test_c036.h"
#include "test_data.h"
-
const client_test_t test_c036_crypto_list[] = {
NULL,
psa_cipher_update_test,
@@ -28,15 +27,13 @@
NULL,
};
-static int g_test_count = 1;
-static uint8_t input[SIZE_32B];
-static uint8_t output[SIZE_32B];
+static uint32_t g_test_count = 1;
int32_t psa_cipher_update_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
- size_t length;
+ size_t expected_output_length;
psa_cipher_operation_t operation;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_handle_t key_handle;
@@ -62,37 +59,50 @@
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].key_alg);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].alg);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage_flags);
/* Import the key data into the key slot */
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].key_data,
- check1[i].key_length, &key_handle);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY,
+ &attributes,
+ check1[i].data,
+ check1[i].data_length,
+ &key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
- if (check1[i].usage == PSA_KEY_USAGE_ENCRYPT)
+ if (check1[i].usage_flags == PSA_KEY_USAGE_ENCRYPT)
{
/* Set the key for a multipart symmetric encryption operation */
- status = val->crypto_function(VAL_CRYPTO_CIPHER_ENCRYPT_SETUP, &operation,
- key_handle, check1[i].key_alg);
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_ENCRYPT_SETUP,
+ &operation,
+ key_handle,
+ check1[i].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
- }
- else if (check1[i].usage == PSA_KEY_USAGE_DECRYPT)
+ } else if (check1[i].usage_flags == PSA_KEY_USAGE_DECRYPT)
{
- status = val->crypto_function(VAL_CRYPTO_CIPHER_DECRYPT_SETUP, &operation,
- key_handle, check1[i].key_alg);
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_DECRYPT_SETUP,
+ &operation,
+ key_handle,
+ check1[i].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
}
/* Set an IV for a symmetric encryption operation */
- status = val->crypto_function(VAL_CRYPTO_CIPHER_SET_IV, &operation, check1[i].iv,
- check1[i].iv_size);
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_SET_IV,
+ &operation,
+ check1[i].iv,
+ check1[i].iv_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
/* Encrypt or decrypt a message fragment in an active cipher operation */
- status = val->crypto_function(VAL_CRYPTO_CIPHER_UPDATE, &operation, check1[i].input,
- check1[i].input_length, output, check1[i].output_size, &length);
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_UPDATE,
+ &operation,
+ check1[i].input,
+ check1[i].input_length,
+ check1[i].output,
+ check1[i].output_size,
+ &expected_output_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(7));
if (check1[i].expected_status != PSA_SUCCESS)
@@ -108,10 +118,12 @@
}
/* Check if the output length matches the expected length */
- TEST_ASSERT_EQUAL(length, check1[i].expected_output_length, TEST_CHECKPOINT_NUM(10));
+ TEST_ASSERT_EQUAL(expected_output_length, check1[i].expected_output_length,
+ TEST_CHECKPOINT_NUM(10));
/* Check if the output data matches the expected data */
- TEST_ASSERT_MEMCMP(output, check1[i].expected_output, length, TEST_CHECKPOINT_NUM(11));
+ TEST_ASSERT_MEMCMP(check1[i].output, check1[i].expected_output, expected_output_length,
+ TEST_CHECKPOINT_NUM(11));
/* Abort a cipher operation */
status = val->crypto_function(VAL_CRYPTO_CIPHER_ABORT, &operation);
@@ -123,6 +135,12 @@
/* Reset the key attributes and check if psa_import_key fails */
val->crypto_function(VAL_CRYPTO_RESET_KEY_ATTRIBUTES, &attributes);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY,
+ &attributes,
+ check1[i].data,
+ check1[i].data_length,
+ &key_handle);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_NOT_SUPPORTED, TEST_CHECKPOINT_NUM(14));
}
return VAL_STATUS_SUCCESS;
@@ -136,7 +154,6 @@
int32_t operation_count = sizeof(operations)/sizeof(operations[0]);
size_t length;
- memset(output, 0, sizeof(output));
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, "Test psa_cipher_update without cipher setup\n", 0);
@@ -146,8 +163,13 @@
for (i = 0; i < operation_count; i++)
{
- status = val->crypto_function(VAL_CRYPTO_CIPHER_UPDATE, &operations[i], input,
- sizeof(input), output, sizeof(output), &length);
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_UPDATE,
+ &operations[i],
+ NULL,
+ 0,
+ NULL,
+ 0,
+ &length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(2));
/* Abort a cipher operation */
@@ -157,4 +179,3 @@
return VAL_STATUS_SUCCESS;
}
-
diff --git a/api-tests/dev_apis/crypto/test_c036/test_data.h b/api-tests/dev_apis/crypto/test_c036/test_data.h
index 9d1db05..0a2aec1 100644
--- a/api-tests/dev_apis/crypto/test_c036/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c036/test_data.h
@@ -15,21 +15,22 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- psa_key_type_t key_type;
- uint8_t key_data[32];
- uint32_t key_length;
- psa_key_usage_t usage;
- psa_algorithm_t key_alg;
- uint8_t iv[16];
- size_t iv_size;
- uint8_t input[32];
+ psa_key_type_t type;
+ const uint8_t *data;
+ size_t data_length;
+ psa_key_usage_t usage_flags;
+ psa_algorithm_t alg;
+ const unsigned char *iv;
+ size_t iv_length;
+ const uint8_t *input;
size_t input_length;
+ unsigned char *output;
size_t output_size;
- uint8_t expected_output[32];
+ const unsigned char *expected_output;
size_t expected_output_length;
psa_status_t expected_status;
} test_data;
@@ -37,215 +38,359 @@
static const test_data check1[] = {
#ifdef ARCH_TEST_AES_128
#ifdef ARCH_TEST_CBC_NO_PADDING
-{"Test psa_cipher_update - Encrypt - AES CBC_NO_PADDING\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17, 0x2a}, 16, 16,
-{0xA0, 0x76, 0xEC, 0x9D, 0xFB, 0xE4, 0x7D, 0x52, 0xAF, 0xC3, 0x57, 0x33, 0x6F,
- 0x20, 0x74, 0x3B}, 16, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_update - Encrypt - AES CBC_NO_PADDING\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 16,
+ .input = plaintext,
+ .input_length = 16,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = ciphertext_1,
+ .expected_output_length = 16,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_cipher_update - Encrypt - AES CBC_NO_PADDING (Short input)\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x23}, 5, 16,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x23}, 0, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_update - Encrypt - AES CBC_NO_PADDING (Short in)\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 16,
+ .input = plaintext,
+ .input_length = 5,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = NULL,
+ .expected_output_length = 0,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_CBC_PKCS7
-{"Test psa_cipher_update - Encrypt - AES CBC_PKCS7\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_PKCS7,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17, 0x2a}, 16, 16,
-{0xa0, 0x76, 0xec, 0x9d, 0xfb, 0xe4, 0x7d, 0x52, 0xaf, 0xc3, 0x57, 0x33, 0x6f,
- 0x20, 0x74, 0x3b}, 16, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_update - Encrypt - AES CBC_PKCS7\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_PKCS7,
+ .iv = iv,
+ .iv_length = 16,
+ .input = plaintext,
+ .input_length = 16,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = ciphertext_1,
+ .expected_output_length = 16,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_cipher_update - Encrypt - AES CBC_PKCS7 (Short input)\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_PKCS7,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17}, 15, 16,
-{0}, 0, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_update - Encrypt - AES CBC_PKCS7 (Short input)\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_PKCS7,
+ .iv = iv,
+ .iv_length = 16,
+ .input = plaintext,
+ .input_length = 15,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = NULL,
+ .expected_output_length = 0,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
-{"Test psa_cipher_update - Encrypt - AES CTR\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17, 0x2a}, 16, 16,
-{0x8f, 0x94, 0x08, 0xfe, 0x80, 0xa8, 0x1d, 0x3e, 0x81, 0x3d, 0xa3, 0xc7, 0xb0,
- 0xb2, 0xbd, 0x32}, 16, PSA_SUCCESS
-},
-#endif
-
-#ifdef ARCH_TEST_CBC_NO_PADDING
-#ifdef ARCH_TEST_DES_1KEY
-{"Test psa_cipher_update - Encrypt - DES CBC (nopad)\n", PSA_KEY_TYPE_DES,
-{0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e}, DES_8B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a}, 8,
-{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 8, 8,
-{0x64, 0xf9, 0x17, 0xb0, 0x15, 0x2f, 0x8f, 0x05}, 8, PSA_SUCCESS
-},
-#endif
-#endif
-#endif
-
-#ifdef ARCH_TEST_CBC_NO_PADDING
-#ifdef ARCH_TEST_DES_2KEY
-{"Test psa_cipher_update - Encrypt - 2-key 3DE -CBC (nopad)\n", PSA_KEY_TYPE_DES,
-{0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e, 0xc1, 0xc2, 0xc4, 0xc7, 0xc8,
- 0xcb, 0xcd, 0xce}, DES3_2KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a}, 8,
-{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 8, 8,
-{0x5d, 0x06, 0x52, 0x42, 0x9c, 0x5b, 0x0a, 0xc7}, 8, PSA_SUCCESS
-},
-#endif
-
-#ifdef ARCH_TEST_DES_3KEY
-{"Test psa_cipher_update - Encrypt - 3-key 3DE -CBC (nopad)\n", PSA_KEY_TYPE_DES,
-{0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e, 0xc1, 0xc2, 0xc4, 0xc7, 0xc8,
- 0xcb, 0xcd, 0xce, 0x31, 0x32, 0x34, 0x37, 0x38, 0x3b, 0x3d, 0x3e}, DES3_3KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a}, 8,
-{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 8, 8,
-{0x81, 0x7c, 0xa7, 0xd6, 0x9b, 0x80, 0xd8, 0x6a}, 8, PSA_SUCCESS
-},
-#endif
-
-#ifdef ARCH_TEST_AES_128
-{"Test psa_cipher_update - small output buffer size\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17, 0x2a}, 16, 15,
-{0xA0, 0x76, 0xEC, 0x9D, 0xFB, 0xE4, 0x7D, 0x52, 0xAF, 0xC3, 0x57, 0x33, 0x6F,
- 0x20, 0x74, 0x3B}, 16, PSA_ERROR_BUFFER_TOO_SMALL
-},
-
-{"Test psa_cipher_update - Decrypt - AES CBC_NO_PADDING\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0xA0, 0x76, 0xEC, 0x9D, 0xFB, 0xE4, 0x7D, 0x52, 0xAF, 0xC3, 0x57, 0x33, 0x6F,
- 0x20, 0x74, 0x3B}, 16, 16,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17, 0x2a}, 16, PSA_SUCCESS
-},
-
-{"Test psa_cipher_update - Decrypt - AES CBC_NO_PADDING (Short input)\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x23}, 5, 16,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x23}, 0, PSA_SUCCESS
-},
-#endif
-#endif
-
-#ifdef ARCH_TEST_AES_128
-#ifdef ARCH_TEST_CBC_PKCS7
-{"Test psa_cipher_update - Decrypt - AES CBC_PKCS7\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_PKCS7,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0xa0, 0x76, 0xec, 0x9d, 0xfb, 0xe4, 0x7d, 0x52, 0xaf, 0xc3, 0x57, 0x33, 0x6f,
- 0x20, 0x74, 0x3b}, 16, 16,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17, 0x2a}, 0, PSA_SUCCESS
-},
-
-{"Test psa_cipher_update - Decrypt - AES CBC_PKCS7 (Short input)\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_PKCS7,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0xa0, 0x76, 0xec, 0x9d, 0xfb, 0xe4, 0x7d, 0x52, 0xaf, 0xc3, 0x57, 0x33, 0x6f,
- 0x20, 0x74, 0x3b, 0xca, 0x7e, 0x8a, 0x15, 0xdc, 0x3c, 0x77, 0x64, 0x36, 0x31,
- 0x42, 0x93, 0x03, 0x1c, 0xd4, 0xf3}, 32, 32,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17, 0x2a}, 16, PSA_SUCCESS
-},
-#endif
-
-#ifdef ARCH_TEST_CIPER_MODE_CTR
-{"Test psa_cipher_update - Decrypt - AES CTR\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CTR,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0x8f, 0x94, 0x08, 0xfe, 0x80, 0xa8, 0x1d, 0x3e, 0x81, 0x3d, 0xa3, 0xc7, 0xb0,
- 0xb2, 0xbd, 0x32}, 16, 16,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17, 0x2a}, 16, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_update - Encrypt - AES CTR\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CTR,
+ .iv = iv,
+ .iv_length = 16,
+ .input = plaintext,
+ .input_length = 16,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = ciphertext_2,
+ .expected_output_length = 16,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CBC_NO_PADDING
#ifdef ARCH_TEST_DES_1KEY
-{"Test psa_cipher_update - Decrypt - DES CBC (nopad)\n", PSA_KEY_TYPE_DES,
-{0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e}, DES_8B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a}, 8,
-{0x64, 0xf9, 0x17, 0xb0, 0x15, 0x2f, 0x8f, 0x05}, 8, 8,
-{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 8, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_update - Encrypt - DES CBC (nopad)\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES_8B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 8,
+ .input = plaintext,
+ .input_length = 8,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = ciphertext_3,
+ .expected_output_length = 8,
+ .expected_status = PSA_SUCCESS
},
#endif
+#endif
+#ifdef ARCH_TEST_CBC_NO_PADDING
#ifdef ARCH_TEST_DES_2KEY
-{"Test psa_cipher_update - Decrypt - 2-key 3DE -CBC (nopad)\n", PSA_KEY_TYPE_DES,
-{0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e, 0xc1, 0xc2, 0xc4, 0xc7, 0xc8,
- 0xcb, 0xcd, 0xce}, DES3_2KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a}, 8,
-{0x5d, 0x06, 0x52, 0x42, 0x9c, 0x5b, 0x0a, 0xc7}, 8, 8,
-{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 8, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_update - Encrypt - 2-key 3DE -CBC (nopad)\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_2B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 8,
+ .input = plaintext,
+ .input_length = 8,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = ciphertext_4,
+ .expected_output_length = 8,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_3KEY
-{"Test psa_cipher_update - Decrypt - 3-key 3DE -CBC (nopad)\n", PSA_KEY_TYPE_DES,
-{0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e, 0xc1, 0xc2, 0xc4, 0xc7, 0xc8,
- 0xcb, 0xcd, 0xce, 0x31, 0x32, 0x34, 0x37, 0x38, 0x3b, 0x3d, 0x3e}, DES3_3KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a}, 8,
-{0x81, 0x7c, 0xa7, 0xd6, 0x9b, 0x80, 0xd8, 0x6a}, 8, 8,
-{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 8, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_update - Encrypt - 3-key 3DE -CBC (nopad)\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_3B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 8,
+ .input = plaintext,
+ .input_length = 8,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = ciphertext_5,
+ .expected_output_length = 8,
+ .expected_status = PSA_SUCCESS
},
#endif
+
+#ifdef ARCH_TEST_AES_128
+{
+ .test_desc = "Test psa_cipher_update - Encrypt - small output buffer size\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 16,
+ .input = plaintext,
+ .input_length = 16,
+ .output = expected_output,
+ .output_size = 15,
+ .expected_output = NULL,
+ .expected_output_length = 0,
+ .expected_status = PSA_ERROR_BUFFER_TOO_SMALL
+},
+
+{
+ .test_desc = "Test psa_cipher_update - Decrypt - AES CBC_NO_PADDING\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 16,
+ .input = ciphertext_1,
+ .input_length = 16,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = plaintext,
+ .expected_output_length = 16,
+ .expected_status = PSA_SUCCESS
+},
+
+{
+ .test_desc = "Test psa_cipher_update - Decrypt - AES CBC_NO_PADDING (Short in)\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 16,
+ .input = ciphertext_1,
+ .input_length = 5,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = NULL,
+ .expected_output_length = 0,
+ .expected_status = PSA_SUCCESS
+},
+#endif
+#endif
+
+#ifdef ARCH_TEST_AES_128
+#ifdef ARCH_TEST_CBC_PKCS7
+{
+ .test_desc = "Test psa_cipher_update - Decrypt - AES CBC_PKCS7\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_PKCS7,
+ .iv = iv,
+ .iv_length = 16,
+ .input = ciphertext_1,
+ .input_length = 16,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = plaintext,
+ .expected_output_length = 0,
+ .expected_status = PSA_SUCCESS
+},
+
+{
+ .test_desc = "Test psa_cipher_update - Decrypt - AES CBC_PKCS7 (Short input)\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_PKCS7,
+ .iv = iv,
+ .iv_length = 16,
+ .input = ciphertext_1,
+ .input_length = 15,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = NULL,
+ .expected_output_length = 0,
+ .expected_status = PSA_SUCCESS
+},
+#endif
+
+#ifdef ARCH_TEST_CIPER_MODE_CTR
+{
+ .test_desc = "Test psa_cipher_update - Decrypt - AES CTR\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CTR,
+ .iv = iv,
+ .iv_length = 16,
+ .input = ciphertext_2,
+ .input_length = 16,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = plaintext,
+ .expected_output_length = 16,
+ .expected_status = PSA_SUCCESS
+},
+#endif
+#endif
+
+#ifdef ARCH_TEST_CBC_NO_PADDING
+#ifdef ARCH_TEST_DES_1KEY
+{
+ .test_desc = "Test psa_cipher_update - Decrypt - DES CBC (nopad)\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES_8B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 8,
+ .input = ciphertext_3,
+ .input_length = 8,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = plaintext,
+ .expected_output_length = 8,
+ .expected_status = PSA_SUCCESS
+},
+#endif
+
+#ifdef ARCH_TEST_DES_2KEY
+{
+ .test_desc = "Test psa_cipher_update - Decrypt - 2-key 3DE -CBC (nopad)\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_2B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 8,
+ .input = ciphertext_4,
+ .input_length = 8,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = plaintext,
+ .expected_output_length = 8,
+ .expected_status = PSA_SUCCESS
+},
+#endif
+
+#ifdef ARCH_TEST_DES_3KEY
+{
+ .test_desc = "Test psa_cipher_update - Decrypt - 3-key 3DE -CBC (nopad)\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_3B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 8,
+ .input = ciphertext_5,
+ .input_length = 8,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = plaintext,
+ .expected_output_length = 8,
+ .expected_status = PSA_SUCCESS
+},
+#endif
+
+{
+ .test_desc = "Test psa_cipher_update - Decrypt - small output buffer size\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 16,
+ .input = ciphertext_1,
+ .input_length = 16,
+ .output = expected_output,
+ .output_size = 15,
+ .expected_output = NULL,
+ .expected_output_length = 0,
+ .expected_status = PSA_ERROR_BUFFER_TOO_SMALL
+},
#endif
};
diff --git a/api-tests/dev_apis/crypto/test_c037/test_c037.c b/api-tests/dev_apis/crypto/test_c037/test_c037.c
index 9b31c24..fef6c0c 100644
--- a/api-tests/dev_apis/crypto/test_c037/test_c037.c
+++ b/api-tests/dev_apis/crypto/test_c037/test_c037.c
@@ -20,23 +20,17 @@
#include "test_c037.h"
#include "test_data.h"
-#define SLOT_1 0
-#define SLOT_2 1
-
const client_test_t test_c037_crypto_list[] = {
NULL,
psa_cipher_finish_test,
NULL,
};
-static int g_test_count = 1;
-static uint8_t output[SIZE_32B];
-
int32_t psa_cipher_finish_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
- size_t update_length, finish_length;
+ size_t get_update_output_length, get_finish_output_length;
psa_cipher_operation_t operation, invalid_operation;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_handle_t key_handle;
@@ -53,7 +47,7 @@
for (i = 0; i < num_checks; i++)
{
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] ", i+1);
val->print(PRINT_TEST, check1[i].test_desc, 0);
memset(&operation, 0, sizeof(operation));
memset(&invalid_operation, 0, sizeof(invalid_operation));
@@ -63,43 +57,45 @@
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].key_alg);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].alg);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage_flags);
/* Import the key data into the key slot */
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].key_data,
- check1[i].key_length, &key_handle);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
- if (check1[i].usage == PSA_KEY_USAGE_ENCRYPT)
+ if (check1[i].usage_flags == PSA_KEY_USAGE_ENCRYPT)
{
/* Set the key for a multipart symmetric encryption operation */
- status = val->crypto_function(VAL_CRYPTO_CIPHER_ENCRYPT_SETUP, &operation,
- key_handle, check1[i].key_alg);
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_ENCRYPT_SETUP, &operation, key_handle,
+ check1[i].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
- }
- else if (check1[i].usage == PSA_KEY_USAGE_DECRYPT)
+ } else if (check1[i].usage_flags == PSA_KEY_USAGE_DECRYPT)
{
/* Set the key for a multipart symmetric decryption operation */
- status = val->crypto_function(VAL_CRYPTO_CIPHER_DECRYPT_SETUP, &operation,
- key_handle, check1[i].key_alg);
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_DECRYPT_SETUP, &operation, key_handle,
+ check1[i].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
}
/* Set an IV for a symmetric encryption operation */
status = val->crypto_function(VAL_CRYPTO_CIPHER_SET_IV, &operation, check1[i].iv,
- check1[i].iv_size);
+ check1[i].iv_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
/* Encrypt or decrypt a message fragment in an active cipher operation */
status = val->crypto_function(VAL_CRYPTO_CIPHER_UPDATE, &operation, check1[i].input,
- check1[i].input_length, output, check1[i].output_size[SLOT_1], &update_length);
+ check1[i].input_length, check1[i].output,
+ check1[i].output_size, &get_update_output_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(7));
/* Finish encrypting or decrypting a message in a cipher operation */
status = val->crypto_function(VAL_CRYPTO_CIPHER_FINISH, &operation,
- output + update_length, check1[i].output_size[SLOT_2], &finish_length);
+ check1[i].output + get_update_output_length,
+ check1[i].output_size - get_update_output_length,
+ &get_finish_output_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(8));
if (check1[i].expected_status != PSA_SUCCESS)
@@ -115,16 +111,19 @@
}
/* Check if the output length matches the expected length */
- TEST_ASSERT_EQUAL(finish_length, check1[i].expected_output_length, TEST_CHECKPOINT_NUM(11));
+ TEST_ASSERT_EQUAL(get_finish_output_length, check1[i].expected_output_length,
+ TEST_CHECKPOINT_NUM(11));
/* Check if the output data matches the expected data */
- TEST_ASSERT_MEMCMP(output, check1[i].expected_output,
- (update_length + finish_length),
+ TEST_ASSERT_MEMCMP(check1[i].output, check1[i].expected_output,
+ (get_update_output_length + get_finish_output_length),
TEST_CHECKPOINT_NUM(12));
/* Finish encrypting or decrypting a message using an invalid operation should fail */
- status = val->crypto_function(VAL_CRYPTO_CIPHER_FINISH, &invalid_operation, output,
- check1[i].output_size[SLOT_2], &finish_length);
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_FINISH, &invalid_operation,
+ check1[i].output + get_update_output_length,
+ check1[i].output_size - get_update_output_length,
+ &get_finish_output_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(13));
/* Abort a cipher operation */
@@ -141,6 +140,9 @@
/* Reset the key attributes and check if psa_import_key fails */
val->crypto_function(VAL_CRYPTO_RESET_KEY_ATTRIBUTES, &attributes);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_NOT_SUPPORTED, TEST_CHECKPOINT_NUM(3));
}
return VAL_STATUS_SUCCESS;
diff --git a/api-tests/dev_apis/crypto/test_c037/test_data.h b/api-tests/dev_apis/crypto/test_c037/test_data.h
index 8e3c901..d8b080e 100644
--- a/api-tests/dev_apis/crypto/test_c037/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c037/test_data.h
@@ -15,21 +15,22 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- psa_key_type_t key_type;
- uint8_t key_data[32];
- uint32_t key_length;
- psa_key_usage_t usage;
- psa_algorithm_t key_alg;
- uint8_t iv[16];
- size_t iv_size;
- uint8_t input[32];
+ psa_key_type_t type;
+ const uint8_t *data;
+ size_t data_length;
+ psa_key_usage_t usage_flags;
+ psa_algorithm_t alg;
+ const unsigned char *iv;
+ size_t iv_length;
+ const uint8_t *input;
size_t input_length;
- size_t output_size[2];
- uint8_t expected_output[32];
+ unsigned char *output;
+ size_t output_size;
+ const unsigned char *expected_output;
size_t expected_output_length;
psa_status_t expected_status;
} test_data;
@@ -37,243 +38,377 @@
static const test_data check1[] = {
#ifdef ARCH_TEST_AES_128
#ifdef ARCH_TEST_CBC_NO_PADDING
-{"Test psa_cipher_finish - Encrypt - AES CBC_NO_PADDING\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17, 0x2a}, 16, {SIZE_32B, SIZE_32B},
-{0xA0, 0x76, 0xEC, 0x9D, 0xFB, 0xE4, 0x7D, 0x52, 0xAF, 0xC3, 0x57, 0x33, 0x6F,
- 0x20, 0x74, 0x3B}, 0, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_finish - Encrypt - AES CBC_NO_PADDING\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 16,
+ .input = plaintext,
+ .input_length = 16,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = ciphertext_1,
+ .expected_output_length = 0,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_cipher_finish - Encrypt - AES CBC_NO_PADDING (Short input)\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x23}, 5, {16, 16},
-{0x6b, 0xc1, 0xbe, 0xe2, 0x23}, 0, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_cipher_finish - Encrypt - AES CBC_NO_PADDING (Short in)\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 16,
+ .input = plaintext,
+ .input_length = 5,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = ciphertext_1,
+ .expected_output_length = 0,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#ifdef ARCH_TEST_CBC_PKCS7
-{"Test psa_cipher_finish - Encrypt - AES CBC_PKCS7\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_PKCS7,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17, 0x2a}, 16, {SIZE_32B, SIZE_32B},
-{0xa0, 0x76, 0xec, 0x9d, 0xfb, 0xe4, 0x7d, 0x52, 0xaf, 0xc3, 0x57, 0x33, 0x6f,
- 0x20, 0x74, 0x3b, 0xca, 0x7e, 0x8a, 0x15, 0xdc, 0x3c, 0x77, 0x64, 0x36, 0x31,
- 0x42, 0x93, 0x03, 0x1c, 0xd4, 0xf3}, 16, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_finish - Encrypt - AES CBC_PKCS7\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_PKCS7,
+ .iv = iv,
+ .iv_length = 16,
+ .input = plaintext,
+ .input_length = 16,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = ciphertext_1,
+ .expected_output_length = 16,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_cipher_finish - Encrypt - AES CBC_PKCS7 (Short input)\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_PKCS7,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17}, 15, {SIZE_32B, SIZE_32B},
-{0x62, 0x79, 0xb4, 0x9d, 0x7f, 0x7a, 0x8d, 0xd8, 0x7b, 0x68, 0x51, 0x75, 0xd4,
- 0x27, 0x6e, 0x24}, 16, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_finish - Encrypt - AES CBC_PKCS7 (Short input)\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_PKCS7,
+ .iv = iv,
+ .iv_length = 16,
+ .input = plaintext,
+ .input_length = 15,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = ciphertext_6,
+ .expected_output_length = 16,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
-{"Test psa_cipher_finish - Encrypt - AES CTR\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17, 0x2a}, 16, {SIZE_32B, SIZE_32B},
-{0x8f, 0x94, 0x08, 0xfe, 0x80, 0xa8, 0x1d, 0x3e, 0x81, 0x3d, 0xa3, 0xc7, 0xb0,
- 0xb2, 0xbd, 0x32}, 0, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_finish - Encrypt - AES CTR\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CTR,
+ .iv = iv,
+ .iv_length = 16,
+ .input = plaintext,
+ .input_length = 16,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = ciphertext_2,
+ .expected_output_length = 0,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_cipher_finish - Encrypt - AES CTR (short input)\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17}, 15, {SIZE_32B, SIZE_32B},
-{0x8f, 0x94, 0x08, 0xfe, 0x80, 0xa8, 0x1d, 0x3e, 0x81, 0x3d, 0xa3, 0xc7, 0xb0,
- 0xb2, 0xbd}, 0, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_finish - Encrypt - AES CTR (short input)\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CTR,
+ .iv = iv,
+ .iv_length = 16,
+ .input = plaintext,
+ .input_length = 15,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = ciphertext_2,
+ .expected_output_length = 0,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CBC_NO_PADDING
#ifdef ARCH_TEST_DES_1KEY
-{"Test psa_cipher_finish - Encrypt - DES CBC (nopad)\n", PSA_KEY_TYPE_DES,
-{0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e}, DES_8B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a}, 8,
-{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 8, {SIZE_32B, SIZE_32B},
-{0x64, 0xf9, 0x17, 0xb0, 0x15, 0x2f, 0x8f, 0x05}, 0, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_finish - Encrypt - DES CBC (nopad)\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES_8B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 8,
+ .input = plaintext,
+ .input_length = 8,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = ciphertext_3,
+ .expected_output_length = 0,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_2KEY
-{"Test psa_cipher_finish - Encrypt - 2-key 3DE -CBC (nopad)\n", PSA_KEY_TYPE_DES,
-{0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e, 0xc1, 0xc2, 0xc4, 0xc7, 0xc8,
- 0xcb, 0xcd, 0xce}, DES3_2KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a}, 8,
-{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 8, {SIZE_32B, SIZE_32B},
-{0x5d, 0x06, 0x52, 0x42, 0x9c, 0x5b, 0x0a, 0xc7}, 0, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_finish - Encrypt - 2-key 3DE -CBC (nopad)\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_2B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 8,
+ .input = plaintext,
+ .input_length = 8,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = ciphertext_4,
+ .expected_output_length = 0,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_3KEY
-{"Test psa_cipher_finish - Encrypt - 3-key 3DE -CBC (nopad)\n", PSA_KEY_TYPE_DES,
-{0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e, 0xc1, 0xc2, 0xc4, 0xc7, 0xc8,
- 0xcb, 0xcd, 0xce, 0x31, 0x32, 0x34, 0x37, 0x38, 0x3b, 0x3d, 0x3e}, DES3_3KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a}, 8,
-{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 8, {SIZE_32B, SIZE_32B},
-{0x81, 0x7c, 0xa7, 0xd6, 0x9b, 0x80, 0xd8, 0x6a}, 0, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_finish - Encrypt - 3-key 3DE -CBC (nopad)\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_3B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 8,
+ .input = plaintext,
+ .input_length = 8,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = ciphertext_5,
+ .expected_output_length = 0,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_AES_128
#ifdef ARCH_TEST_CBC_PKCS7
-{"Test psa_cipher_finish - small output buffer size\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_PKCS7,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17, 0x2a}, 16, {SIZE_32B, 15},
-{0xa0, 0x76, 0xec, 0x9d, 0xfb, 0xe4, 0x7d, 0x52, 0xaf, 0xc3, 0x57, 0x33, 0x6f,
- 0x20, 0x74, 0x3b, 0xca, 0x7e, 0x8a, 0x15, 0xdc, 0x3c, 0x77, 0x64, 0x36, 0x31,
- 0x42, 0x93, 0x03, 0x1c, 0xd4, 0xf3}, 16, PSA_ERROR_BUFFER_TOO_SMALL
+{
+ .test_desc = "Test psa_cipher_finish - Encrypt - small output buffer size\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_PKCS7,
+ .iv = iv,
+ .iv_length = 16,
+ .input = plaintext,
+ .input_length = 16,
+ .output = expected_output,
+ .output_size = 20,
+ .expected_output = NULL,
+ .expected_output_length = 0,
+ .expected_status = PSA_ERROR_BUFFER_TOO_SMALL
},
#endif
#ifdef ARCH_TEST_CBC_NO_PADDING
-{"Test psa_cipher_finish - Decrypt - AES CBC_NO_PADDING\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0xA0, 0x76, 0xEC, 0x9D, 0xFB, 0xE4, 0x7D, 0x52, 0xAF, 0xC3, 0x57, 0x33, 0x6F,
- 0x20, 0x74, 0x3B},
- 16, {SIZE_32B, SIZE_32B},
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17, 0x2a}, 0, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_finish - Decrypt - AES CBC_NO_PADDING\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 16,
+ .input = ciphertext_1,
+ .input_length = 16,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = plaintext,
+ .expected_output_length = 0,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_cipher_finish - Decrypt - AES CBC_NO_PADDING (Short input)\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x23}, 5, {16, 16},
-{0x6b, 0xc1, 0xbe, 0xe2, 0x23}, 0, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_cipher_finish - Decrypt - AES CBC_NO_PADDING (Short in)\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 16,
+ .input = ciphertext_1,
+ .input_length = 5,
+ .output = NULL,
+ .output_size = 0,
+ .expected_output = NULL,
+ .expected_output_length = 0,
+ .expected_status = PSA_ERROR_BAD_STATE
},
+
#endif
#ifdef ARCH_TEST_CBC_PKCS7
-{"Test psa_cipher_finish - Decrypt - AES CBC_PKCS7\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_PKCS7,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0xa0, 0x76, 0xec, 0x9d, 0xfb, 0xe4, 0x7d, 0x52, 0xaf, 0xc3, 0x57, 0x33, 0x6f,
- 0x20, 0x74, 0x3b, 0xca, 0x7e, 0x8a, 0x15, 0xdc, 0x3c, 0x77, 0x64, 0x36, 0x31,
- 0x42, 0x93, 0x03, 0x1c, 0xd4, 0xf3}, 32, {SIZE_32B, SIZE_32B},
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17, 0x2a}, 0, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_update - Decrypt - AES CBC_PKCS7\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_PKCS7,
+ .iv = iv,
+ .iv_length = 16,
+ .input = ciphertext_1,
+ .input_length = 32,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = plaintext,
+ .expected_output_length = 0,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_cipher_finish - Decrypt - AES CBC_PKCS7 (Short input)\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_PKCS7,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0x62, 0x79, 0xb4, 0x9d, 0x7f, 0x7a, 0x8d, 0xd8, 0x7b, 0x68, 0x51, 0x75, 0xd4,
- 0x27, 0x6e, 0x24}, 16, {SIZE_32B, SIZE_32B},
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17}, 15, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_finish - Decrypt - AES CBC_PKCS7 (Short input)\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_PKCS7,
+ .iv = iv,
+ .iv_length = 16,
+ .input = ciphertext_6,
+ .input_length = 16,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = plaintext,
+ .expected_output_length = 15,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
-{"Test psa_cipher_finish - Decrypt - AES CTR\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CTR,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0x8f, 0x94, 0x08, 0xfe, 0x80, 0xa8, 0x1d, 0x3e, 0x81, 0x3d, 0xa3, 0xc7, 0xb0,
- 0xb2, 0xbd, 0x32}, 16, {SIZE_32B, SIZE_32B},
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17, 0x2a},
- 0, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_finish - Decrypt - AES CTR\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CTR,
+ .iv = iv,
+ .iv_length = 16,
+ .input = ciphertext_2,
+ .input_length = 16,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = plaintext,
+ .expected_output_length = 0,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_cipher_finish - Decrypt - AES CTR (short input)\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CTR,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a}, 16,
-{0x8f, 0x94, 0x08, 0xfe, 0x80, 0xa8, 0x1d, 0x3e, 0x81, 0x3d, 0xa3, 0xc7, 0xb0,
- 0xb2, 0xbd}, 15, {SIZE_32B, SIZE_32B},
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17}, 0, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_finish - Decrypt - AES CTR (short input)\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CTR,
+ .iv = iv,
+ .iv_length = 16,
+ .input = ciphertext_2,
+ .input_length = 16,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = plaintext,
+ .expected_output_length = 0,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CBC_NO_PADDING
#ifdef ARCH_TEST_DES_1KEY
-{"Test psa_cipher_finish - Decrypt - DES CBC (nopad)\n", PSA_KEY_TYPE_DES,
-{0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e}, DES_8B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a}, 8,
-{0x64, 0xf9, 0x17, 0xb0, 0x15, 0x2f, 0x8f, 0x05}, 8, {SIZE_32B, SIZE_32B},
-{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 0, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_finish - Decrypt - DES CBC (nopad)\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES_8B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 8,
+ .input = ciphertext_3,
+ .input_length = 8,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = plaintext,
+ .expected_output_length = 0,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_2KEY
-{"Test psa_cipher_finish - Decrypt - 2-key 3DE -CBC (nopad)\n", PSA_KEY_TYPE_DES,
-{0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e, 0xc1, 0xc2, 0xc4, 0xc7, 0xc8,
- 0xcb, 0xcd, 0xce}, DES3_2KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a}, 8,
-{0x5d, 0x06, 0x52, 0x42, 0x9c, 0x5b, 0x0a, 0xc7}, 8, {SIZE_32B, SIZE_32B},
-{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 0, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_finish - Decrypt - 2-key 3DE -CBC (nopad)\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_2B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 8,
+ .input = ciphertext_4,
+ .input_length = 8,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = plaintext,
+ .expected_output_length = 0,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_3KEY
-{"Test psa_cipher_finish - 3-key 3DE -CBC (nopad)\n", PSA_KEY_TYPE_DES,
-{0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e, 0xc1, 0xc2, 0xc4, 0xc7, 0xc8,
- 0xcb, 0xcd, 0xce, 0x31, 0x32, 0x34, 0x37, 0x38, 0x3b, 0x3d, 0x3e}, DES3_3KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a}, 8,
-{0x81, 0x7c, 0xa7, 0xd6, 0x9b, 0x80, 0xd8, 0x6a}, 8, {SIZE_32B, SIZE_32B},
-{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 0, PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_finish - Decrypt - 3-key 3DE -CBC (nopad)\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_3B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .iv = iv,
+ .iv_length = 8,
+ .input = ciphertext_5,
+ .input_length = 8,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = plaintext,
+ .expected_output_length = 0,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
diff --git a/api-tests/dev_apis/crypto/test_c038/test_c038.c b/api-tests/dev_apis/crypto/test_c038/test_c038.c
index 792c52d..249f209 100644
--- a/api-tests/dev_apis/crypto/test_c038/test_c038.c
+++ b/api-tests/dev_apis/crypto/test_c038/test_c038.c
@@ -27,12 +27,12 @@
NULL,
};
-static int g_test_count = 1;
-static uint8_t output[SIZE_32B];
+static uint32_t g_test_count = 1;
+static int32_t valid_test_input_index = -1;
int32_t psa_cipher_abort_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t num_checks = sizeof(check1)/sizeof(check1[valid_test_input_index]);
int32_t i, status;
psa_cipher_operation_t operation;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -59,27 +59,26 @@
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].key_alg);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].alg);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage_flags);
/* Import the key data into the key slot */
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].key_data,
- check1[i].key_length, &key_handle);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
- if (check1[i].usage == PSA_KEY_USAGE_ENCRYPT)
+ if (check1[i].usage_flags == PSA_KEY_USAGE_ENCRYPT)
{
/* Set the key for a multipart symmetric encryption operation */
- status = val->crypto_function(VAL_CRYPTO_CIPHER_ENCRYPT_SETUP, &operation,
- key_handle, check1[i].key_alg);
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_ENCRYPT_SETUP, &operation, key_handle,
+ check1[i].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
- }
- else if (check1[i].usage == PSA_KEY_USAGE_DECRYPT)
+ } else if (check1[i].usage_flags == PSA_KEY_USAGE_DECRYPT)
{
/* Set the key for a multipart symmetric decryption operation */
- status = val->crypto_function(VAL_CRYPTO_CIPHER_DECRYPT_SETUP, &operation,
- key_handle, check1[i].key_alg);
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_DECRYPT_SETUP, &operation, key_handle,
+ check1[i].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
}
@@ -97,6 +96,9 @@
/* Reset the key attributes and check if psa_import_key fails */
val->crypto_function(VAL_CRYPTO_RESET_KEY_ATTRIBUTES, &attributes);
+
+ if (valid_test_input_index < 0)
+ valid_test_input_index = i;
}
return VAL_STATUS_SUCCESS;
@@ -104,24 +106,15 @@
int32_t psa_cipher_abort_before_update_test(caller_security_t caller __UNUSED)
{
- size_t length;
- psa_algorithm_t key_alg = PSA_ALG_CBC_NO_PADDING;
- psa_key_usage_t usage = PSA_KEY_USAGE_ENCRYPT;
- psa_key_handle_t key_handle = 13;
- psa_key_type_t key_type = PSA_KEY_TYPE_AES;
+ size_t get_output_length;
+ psa_key_handle_t key_handle;
psa_cipher_operation_t operation;
- uint8_t key_data[] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab,
- 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
- uint8_t input[] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9,
- 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a};
- uint8_t iv[] = {0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
- 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a};
- size_t key_length = sizeof(key_data);
- size_t input_length = sizeof(input);
- size_t iv_size = sizeof(iv);
int32_t status;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+ if (valid_test_input_index < 0)
+ return RESULT_SKIP(VAL_STATUS_NO_TESTS);
+
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
@@ -135,22 +128,26 @@
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, key_alg);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, usage);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE,
+ &attributes, check1[valid_test_input_index].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM,
+ &attributes, check1[valid_test_input_index].alg);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS,
+ &attributes, check1[valid_test_input_index].usage_flags);
/* Import the key data into the key slot */
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, key_data,
- key_length, &key_handle);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY,
+ &attributes, check1[valid_test_input_index].data,
+ check1[valid_test_input_index].data_length, &key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Set the key for a multipart symmetric encryption operation */
- status = val->crypto_function(VAL_CRYPTO_CIPHER_ENCRYPT_SETUP, &operation,
- key_handle, key_alg);
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_ENCRYPT_SETUP, &operation, key_handle,
+ check1[valid_test_input_index].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Set an IV for a symmetric encryption operation */
- status = val->crypto_function(VAL_CRYPTO_CIPHER_SET_IV, &operation, iv, iv_size);
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_SET_IV, &operation, iv, 16);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Abort a cipher operation */
@@ -158,8 +155,8 @@
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
/* Encrypt or decrypt a message fragment in an active cipher operation */
- status = val->crypto_function(VAL_CRYPTO_CIPHER_UPDATE, &operation, input,
- input_length, output, SIZE_32B, &length);
+ status = val->crypto_function(VAL_CRYPTO_CIPHER_UPDATE, &operation, plaintext, 16,
+ expected_output, BUFFER_SIZE, &get_output_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(7));
/* Destroy the key */
diff --git a/api-tests/dev_apis/crypto/test_c038/test_data.h b/api-tests/dev_apis/crypto/test_c038/test_data.h
index f3b6788..1dfbbc8 100644
--- a/api-tests/dev_apis/crypto/test_c038/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c038/test_data.h
@@ -15,129 +15,167 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- psa_key_type_t key_type;
- uint8_t key_data[32];
- uint32_t key_length;
- psa_key_usage_t usage;
- psa_algorithm_t key_alg;
+ psa_key_type_t type;
+ const uint8_t *data;
+ size_t data_length;
+ psa_key_usage_t usage_flags;
+ psa_algorithm_t alg;
psa_status_t expected_status;
} test_data;
static const test_data check1[] = {
#ifdef ARCH_TEST_AES_128
#ifdef ARCH_TEST_CBC_NO_PADDING
-{"Test psa_cipher_abort - Encrypt - AES CBC_NO_PADDING\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_abort - Encrypt - AES CBC_NO_PADDING\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_CBC_PKCS7
-{"Test psa_cipher_abort - Encrypt - AES CBC_PKCS7\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_PKCS7,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_abort - Encrypt - AES CBC_PKCS7\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_PKCS7,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
-{"Test psa_cipher_abort - Encrypt - AES CTR\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_abort - Encrypt - AES CTR\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CTR,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CBC_NO_PADDING
#ifdef ARCH_TEST_DES_1KEY
-{"Test psa_cipher_abort - Encrypt - DES CBC (nopad)\n", PSA_KEY_TYPE_DES,
-{0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e}, DES_8B_KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_abort - Encrypt - DES CBC (nopad)\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES_8B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_2KEY
-{"Test psa_cipher_abort - Encrypt - 2-key 3DE -CBC (nopad)\n", PSA_KEY_TYPE_DES,
-{0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e, 0xc1, 0xc2, 0xc4, 0xc7, 0xc8,
- 0xcb, 0xcd, 0xce}, DES3_2KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_abort - Encrypt - 2-key 3DE -CBC (nopad)\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_2B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_3KEY
-{"Test psa_cipher_abort - Encrypt - 3-key 3DE -CBC (nopad)\n", PSA_KEY_TYPE_DES,
-{0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e, 0xc1, 0xc2, 0xc4, 0xc7, 0xc8,
- 0xcb, 0xcd, 0xce, 0x31, 0x32, 0x34, 0x37, 0x38, 0x3b, 0x3d, 0x3e}, DES3_3KEY_SIZE,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_abort - Encrypt - 3-key 3DE -CBC (nopad)\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_3B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_AES_128
#ifdef ARCH_TEST_CBC_NO_PADDING
-{"Test psa_cipher_abort - Decrypt - AES CBC_NO_PADDING\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_abort - Decrypt - AES CBC_NO_PADDING\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_CBC_PKCS7
-{"Test psa_cipher_abort - Decrypt - AES CBC_PKCS7\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_PKCS7,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_abort - Decrypt - AES CBC_PKCS7\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_PKCS7,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
-{"Test psa_cipher_abort - Decrypt - AES CTR\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CTR,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_abort - Decrypt - AES CTR\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CTR,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CBC_NO_PADDING
#ifdef ARCH_TEST_DES_1KEY
-{"Test psa_cipher_abort - Decrypt - DES CBC (nopad)\n", PSA_KEY_TYPE_DES,
-{0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e}, DES_8B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_abort - Decrypt - DES CBC (nopad)\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES_8B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_2KEY
-{"Test psa_cipher_abort - Decrypt - 2-key 3DE -CBC (nopad)\n", PSA_KEY_TYPE_DES,
-{0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e, 0xc1, 0xc2, 0xc4, 0xc7, 0xc8,
- 0xcb, 0xcd, 0xce}, DES3_2KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_abort - Decrypt - 2-key 3DE -CBC (nopad)\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_2B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_3KEY
-{"Test psa_cipher_abort - Decrypt - 3-key 3DE -CBC (nopad)\n", PSA_KEY_TYPE_DES,
-{0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e, 0xc1, 0xc2, 0xc4, 0xc7, 0xc8,
- 0xcb, 0xcd, 0xce, 0x31, 0x32, 0x34, 0x37, 0x38, 0x3b, 0x3d, 0x3e}, DES3_3KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING,
- PSA_SUCCESS
+{
+ .test_desc = "Test psa_cipher_abort - Decrypt - 3-key 3DE -CBC (nopad)\n",
+ .type = PSA_KEY_TYPE_DES,
+ .data = key_data,
+ .data_length = DES3_3B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_CBC_NO_PADDING,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
diff --git a/api-tests/dev_apis/crypto/test_c039/test_c039.c b/api-tests/dev_apis/crypto/test_c039/test_c039.c
index 24a989a..3e872d5 100644
--- a/api-tests/dev_apis/crypto/test_c039/test_c039.c
+++ b/api-tests/dev_apis/crypto/test_c039/test_c039.c
@@ -27,29 +27,14 @@
NULL,
};
-static bool_t is_buffer_empty(uint8_t *buffer, size_t size)
-{
- int i;
-
- for (i = 0; i < (int)size; i++)
- {
- if (buffer[i] != 0)
- return FALSE;
- }
-
- return TRUE;
-}
-
-static int g_test_count = 1;
-static uint8_t output[SIZE_128B];
+static uint32_t g_test_count = 1;
+static int32_t valid_test_input_index = -1;
int32_t psa_asymmetric_encrypt_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t num_checks = sizeof(check1)/sizeof(check1[valid_test_input_index]);
int32_t i, status;
- const uint8_t *key_data;
- uint8_t *salt;
- size_t length;
+ size_t get_output_length;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_handle_t key_handle;
@@ -72,66 +57,27 @@
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- memset(output, 0, sizeof(output));
-
- /* Set the key data based on key type */
- if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type))
- {
- if (check1[i].key_type == PSA_KEY_TYPE_RSA_KEY_PAIR)
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keypair;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keypair;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(128))
- key_data = rsa_128_keypair;
- else
- return VAL_STATUS_INVALID;
- }
- else
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keydata;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keydata;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(128))
- key_data = rsa_128_keydata;
- else
- return VAL_STATUS_INVALID;
- }
- }
- else if (PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
- {
- if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(check1[i].key_type))
- key_data = ec_keypair;
- else
- key_data = ec_keydata;
- }
- else
- key_data = check1[i].key_data;
-
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].key_alg);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].alg);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage_flags);
/* Import the key data into the key slot */
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, key_data,
- check1[i].key_length, &key_handle);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
- if (is_buffer_empty(check1[i].salt, check1[i].salt_length) == TRUE)
- {
- salt = NULL;
- check1[i].salt_length = 0;
- }
- else
- salt = check1[i].salt;
-
/* Encrypt a short message with a public key */
- status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_ENCRYPT, key_handle,
- check1[i].key_alg, check1[i].input, check1[i].input_length, salt,
- check1[i].salt_length, output, check1[i].output_size, &length);
+ status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_ENCRYPT,
+ key_handle,
+ check1[i].alg,
+ check1[i].input,
+ check1[i].input_length,
+ check1[i].salt,
+ check1[i].salt_length,
+ check1[i].output,
+ check1[i].output_size,
+ &get_output_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(4));
if (check1[i].expected_status != PSA_SUCCESS)
@@ -140,27 +86,38 @@
status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
+ /* Reset the key attributes and check if psa_import_key fails */
+ val->crypto_function(VAL_CRYPTO_RESET_KEY_ATTRIBUTES, &attributes);
continue;
}
/* Check if the output length matches with the expected output length */
- TEST_ASSERT_EQUAL(length, check1[i].expected_output_length, TEST_CHECKPOINT_NUM(6));
+ TEST_ASSERT_EQUAL(get_output_length, check1[i].expected_output_length,
+ TEST_CHECKPOINT_NUM(6));
/* We test encryption by checking that encrypt-then-decrypt gives back
* the original plaintext because of the non-optional random
* part of encryption process which prevents using fixed vectors. */
- if ((check1[i].usage & PSA_KEY_USAGE_DECRYPT) == PSA_KEY_USAGE_DECRYPT)
+ if ((check1[i].usage_flags & PSA_KEY_USAGE_DECRYPT) == PSA_KEY_USAGE_DECRYPT)
{
status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_DECRYPT,
- key_handle, check1[i].key_alg, output, length, salt,
- check1[i].salt_length, output, check1[i].output_size, &length);
+ key_handle,
+ check1[i].alg,
+ check1[i].output,
+ get_output_length,
+ check1[i].salt,
+ check1[i].salt_length,
+ check1[i].output + get_output_length,
+ check1[i].output_size - get_output_length,
+ &get_output_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(7));
/* Check if the output length matches with the input length */
- TEST_ASSERT_EQUAL(length, check1[i].input_length, TEST_CHECKPOINT_NUM(8));
+ TEST_ASSERT_EQUAL(get_output_length, check1[i].input_length, TEST_CHECKPOINT_NUM(8));
/* Check if the output matches with the given input data */
- TEST_ASSERT_MEMCMP(output, check1[i].input, length, TEST_CHECKPOINT_NUM(9));
+ TEST_ASSERT_MEMCMP(check1[i].output + check1[i].expected_output_length, check1[i].input,
+ get_output_length, TEST_CHECKPOINT_NUM(9));
}
/* Destroy the key */
@@ -169,6 +126,12 @@
/* Reset the key attributes and check if psa_import_key fails */
val->crypto_function(VAL_CRYPTO_RESET_KEY_ATTRIBUTES, &attributes);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_NOT_SUPPORTED, TEST_CHECKPOINT_NUM(11));
+
+ if (valid_test_input_index < 0)
+ valid_test_input_index = i;
}
return VAL_STATUS_SUCCESS;
@@ -176,46 +139,50 @@
int32_t psa_asymmetric_encrypt_negative_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check2)/sizeof(check2[0]);
- int32_t i, status;
- uint8_t *salt = NULL;
- size_t length;
+ int32_t status;
+ size_t get_output_length;
psa_key_handle_t key_handle = 11;
+ if (valid_test_input_index < 0)
+ return RESULT_SKIP(VAL_STATUS_NO_TESTS);
+
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
- for (i = 0; i < num_checks; i++)
- {
- /* Setting up the watchdog timer for each check */
- status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
- TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
+ /* Setting up the watchdog timer for each check */
+ status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
+ TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- if (is_buffer_empty(check2[i].salt, check2[i].salt_length) == TRUE)
- {
- salt = NULL;
- check2[i].salt_length = 0;
- }
- else
- salt = check2[i].salt;
+ val->print(PRINT_TEST, "[Check %d] Test psa_asymmetric_encrypt - Invalid key handle\n",
+ g_test_count++);
+ /* Encrypt a short message with a public key */
+ status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_ENCRYPT,
+ key_handle,
+ check1[valid_test_input_index].alg,
+ check1[valid_test_input_index].input,
+ check1[valid_test_input_index].input_length,
+ check1[valid_test_input_index].salt,
+ check1[valid_test_input_index].salt_length,
+ check1[valid_test_input_index].output,
+ check1[valid_test_input_index].output_size,
+ &get_output_length);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(3));
- val->print(PRINT_TEST, "[Check %d] Test psa_asymmetric_encrypt - Invalid key handle\n",
- g_test_count++);
- /* Encrypt a short message with a public key */
- status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_ENCRYPT, key_handle,
- check2[i].key_alg, check2[i].input, check2[i].input_length, salt,
- check2[i].salt_length, output, check2[i].output_size, &length);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(3));
-
- val->print(PRINT_TEST, "[Check %d] Test psa_asymmetric_encrypt - Zero as key handle\n",
- g_test_count++);
- /* Encrypt a short message with a public key */
- status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_ENCRYPT, 0,
- check2[i].key_alg, check2[i].input, check2[i].input_length, salt,
- check2[i].salt_length, output, check2[i].output_size, &length);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(4));
- }
+ val->print(PRINT_TEST, "[Check %d] Test psa_asymmetric_encrypt - Zero as key handle\n",
+ g_test_count++);
+ /* Encrypt a short message with a public key */
+ status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_ENCRYPT,
+ 0,
+ check1[valid_test_input_index].alg,
+ check1[valid_test_input_index].input,
+ check1[valid_test_input_index].input_length,
+ check1[valid_test_input_index].salt,
+ check1[valid_test_input_index].salt_length,
+ check1[valid_test_input_index].output,
+ check1[valid_test_input_index].output_size,
+ &get_output_length);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(4));
return VAL_STATUS_SUCCESS;
}
diff --git a/api-tests/dev_apis/crypto/test_c039/test_data.h b/api-tests/dev_apis/crypto/test_c039/test_data.h
index 93e59a6..620c12d 100644
--- a/api-tests/dev_apis/crypto/test_c039/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c039/test_data.h
@@ -15,200 +15,229 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- psa_key_type_t key_type;
- uint8_t key_data[16];
- uint32_t key_length;
- psa_key_usage_t usage;
- psa_algorithm_t key_alg;
- uint8_t salt[16];
- size_t salt_length;
- uint8_t input[32];
+ psa_key_type_t type;
+ const uint8_t *data;
+ size_t data_length;
+ psa_key_usage_t usage_flags;
+ psa_algorithm_t alg;
+ const uint8_t *input;
size_t input_length;
+ const uint8_t *salt;
+ size_t salt_length;
+ uint8_t *output;
size_t output_size;
size_t expected_output_length;
- size_t expected_bit_length;
psa_status_t expected_status;
} test_data;
-static const uint8_t rsa_384_keypair[1];
-static const uint8_t rsa_384_keydata[1];
-static const uint8_t rsa_256_keypair[1];
-static const uint8_t rsa_256_keydata[1];
-
-static const uint8_t ec_keydata[] = {
- 0x04, 0xde, 0xa5, 0xe4, 0x5d, 0x0e, 0xa3, 0x7f, 0xc5, 0x66, 0x23, 0x2a, 0x50, 0x8f,
- 0x4a, 0xd2, 0x0e, 0xa1, 0x3d, 0x47, 0xe4, 0xbf, 0x5f, 0xa4, 0xd5, 0x4a, 0x57, 0xa0,
- 0xba, 0x01, 0x20, 0x42, 0x08, 0x70, 0x97, 0x49, 0x6e, 0xfc, 0x58, 0x3f, 0xed, 0x8b,
- 0x24, 0xa5, 0xb9, 0xbe, 0x9a, 0x51, 0xde, 0x06, 0x3f, 0x5a, 0x00, 0xa8, 0xb6, 0x98,
- 0xa1, 0x6f, 0xd7, 0xf2, 0x9b, 0x54, 0x85, 0xf3, 0x20};
-
-static const uint8_t ec_keypair[] = {
- 0x30, 0x5F, 0x02, 0x01, 0x01, 0x04, 0x18, 0x33, 0x8E, 0x86, 0xA8, 0x81, 0xE2, 0x38,
- 0xF5, 0x49, 0xBD, 0x6F, 0x05, 0x53, 0x49, 0x4B, 0x73, 0xE3, 0xD6, 0x11, 0x30, 0xFD,
- 0xC6, 0xC9, 0x6D, 0xA0, 0x0A, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01,
- 0x01, 0xA1, 0x34, 0x03, 0x32, 0x00, 0x04, 0x51, 0x75, 0xBC, 0xDF, 0x30, 0xA3, 0x70,
- 0xF3, 0x9D, 0x53, 0x93, 0xE6, 0x12, 0x72, 0x88, 0xD8, 0x01, 0x67, 0xB5, 0xF4, 0xB4,
- 0xB7, 0x76, 0xC6, 0x74, 0xF7, 0xC6, 0xF3, 0x54, 0xB7, 0xD2, 0x24, 0x06, 0x2C, 0x1F,
- 0x68, 0x54, 0xB5, 0xA7, 0xAF, 0x0F, 0xE5, 0x78, 0xEA, 0xF2, 0x58, 0xF0, 0x27};
-
-static const uint8_t rsa_128_keydata[] = {
- 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
- 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02,
- 0x81, 0x81, 0x00, 0xaf, 0x05, 0x7d, 0x39, 0x6e, 0xe8, 0x4f, 0xb7, 0x5f, 0xdb,
- 0xb5, 0xc2, 0xb1, 0x3c, 0x7f, 0xe5, 0xa6, 0x54, 0xaa, 0x8a, 0xa2, 0x47, 0x0b,
- 0x54, 0x1e, 0xe1, 0xfe, 0xb0, 0xb1, 0x2d, 0x25, 0xc7, 0x97, 0x11, 0x53, 0x12,
- 0x49, 0xe1, 0x12, 0x96, 0x28, 0x04, 0x2d, 0xbb, 0xb6, 0xc1, 0x20, 0xd1, 0x44,
- 0x35, 0x24, 0xef, 0x4c, 0x0e, 0x6e, 0x1d, 0x89, 0x56, 0xee, 0xb2, 0x07, 0x7a,
- 0xf1, 0x23, 0x49, 0xdd, 0xee, 0xe5, 0x44, 0x83, 0xbc, 0x06, 0xc2, 0xc6, 0x19,
- 0x48, 0xcd, 0x02, 0xb2, 0x02, 0xe7, 0x96, 0xae, 0xbd, 0x94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
-0x39, 0xf1, 0x0c, 0xbb, 0x9b, 0x0c, 0x73, 0x9d, 0x0c, 0x80, 0x99, 0x68, 0xd6,
-0x44, 0xa9, 0x4e, 0x3f, 0xd6, 0xed, 0x92, 0x87, 0x07, 0x7a, 0x14, 0x58, 0x3f,
-0x37, 0x90, 0x58, 0xf7, 0x6a, 0x8a, 0xec, 0xd4, 0x3c, 0x62, 0xdc, 0x8c, 0x0f,
-0x41, 0x76, 0x66, 0x50, 0xd7, 0x25, 0x27, 0x5a, 0xc4, 0xa1, 0x02, 0x41, 0x00,
-0xbb, 0x32, 0xd1, 0x33, 0xed, 0xc2, 0xe0, 0x48, 0xd4, 0x63, 0x38, 0x8b, 0x7b,
-0xe9, 0xcb, 0x4b, 0xe2, 0x9f, 0x4b, 0x62, 0x50, 0xbe, 0x60, 0x3e, 0x70, 0xe3,
-0x64, 0x75, 0x01, 0xc9, 0x7d, 0xdd, 0xe2, 0x0a, 0x4e, 0x71, 0xbe, 0x95, 0xfd,
-0x5e, 0x71, 0x78, 0x4e, 0x25, 0xac, 0xa4, 0xba, 0xf2, 0x5b, 0xe5, 0x73, 0x8a,
-0xae, 0x59, 0xbb, 0xfe, 0x1c, 0x99, 0x77, 0x81, 0x44, 0x7a, 0x2b, 0x24};
-
-static test_data check1[] = {
+static const test_data check1[] = {
#ifdef ARCH_TEST_RSA_1024
#ifdef ARCH_TEST_RSA_PKCS1V15_CRYPT
-{"Test psa_asymmetric_encrypt - RSA PKCS1V15\n", PSA_KEY_TYPE_RSA_PUBLIC_KEY,
-{0}, 162, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_RSA_PKCS1V15_CRYPT,
-{0}, 0,
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}, 22, 128,
- 128, 1024, PSA_SUCCESS
+{
+ .test_desc = "Test psa_asymmetric_encrypt - RSA PKCS1V15\n",
+ .type = PSA_KEY_TYPE_RSA_PUBLIC_KEY,
+ .data = rsa_128_key_data,
+ .data_length = 162,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_RSA_PKCS1V15_CRYPT,
+ .input = plaintext,
+ .input_length = 22,
+ .salt = NULL,
+ .salt_length = 0,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output_length = 128,
+ .expected_status = PSA_SUCCESS
},
+
+{
+ .test_desc = "Test psa_asymmetric_encrypt - RSA KEY_PAIR PKCS1V15\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_RSA_PKCS1V15_CRYPT,
+ .input = plaintext,
+ .input_length = 22,
+ .salt = NULL,
+ .salt_length = 0,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output_length = 128,
+ .expected_status = PSA_SUCCESS
+},
+#endif
#endif
#ifdef ARCH_TEST_SHA256
#ifdef ARCH_TEST_RSA_OAEP
-{"Test psa_asymmetric_encrypt - RSA OAEP SHA256\n", PSA_KEY_TYPE_RSA_PUBLIC_KEY,
-{0}, 162, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_RSA_OAEP(PSA_ALG_SHA_256),
-{0}, 0,
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}, 22, 128,
- 128, 1024, PSA_SUCCESS
+{
+ .test_desc = "Test psa_asymmetric_encrypt - RSA OAEP SHA256\n",
+ .type = PSA_KEY_TYPE_RSA_PUBLIC_KEY,
+ .data = rsa_128_key_data,
+ .data_length = 162,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_RSA_OAEP(PSA_ALG_SHA_256),
+ .input = plaintext,
+ .input_length = 22,
+ .salt = NULL,
+ .salt_length = 0,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output_length = 128,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_asymmetric_encrypt - RSA OAEP SHA256 with label\n", PSA_KEY_TYPE_RSA_PUBLIC_KEY,
-{0}, 162, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_RSA_OAEP(PSA_ALG_SHA_256),
-{0x74, 0x68, 0x69, 0x73, 0x00, 0x69, 0x73, 0x00, 0x61, 0x00, 0x6c, 0x61, 0x62,
- 0x65, 0x6c, 0x00}, 16,
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}, 22, 128,
- 128, 1024, PSA_SUCCESS
+{
+ .test_desc = "Test psa_asymmetric_encrypt - RSA OAEP SHA256 with label\n",
+ .type = PSA_KEY_TYPE_RSA_PUBLIC_KEY,
+ .data = rsa_128_key_data,
+ .data_length = 162,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_RSA_OAEP(PSA_ALG_SHA_256),
+ .input = plaintext,
+ .input_length = 22,
+ .salt = salt,
+ .salt_length = 16,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output_length = 128,
+ .expected_status = PSA_SUCCESS
+},
+
+{
+ .test_desc = "Test psa_asymmetric_encrypt - RSA KEY_PAIR OAEP SHA256\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_RSA_OAEP(PSA_ALG_SHA_256),
+ .input = plaintext,
+ .input_length = 22,
+ .salt = NULL,
+ .salt_length = 0,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output_length = 128,
+ .expected_status = PSA_SUCCESS
+},
+
+{
+ .test_desc = "Test psa_asymmetric_encrypt - RSA KEY_PAIR OAEP SHA256 with label\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_RSA_OAEP(PSA_ALG_SHA_256),
+ .input = plaintext,
+ .input_length = 22,
+ .salt = salt,
+ .salt_length = 16,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output_length = 128,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
+#ifdef ARCH_TEST_RSA_1024
#ifdef ARCH_TEST_RSA_PKCS1V15_CRYPT
-{"Test psa_asymmetric_encrypt - RSA KEY_PAIR PKCS1V15\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT, PSA_ALG_RSA_PKCS1V15_CRYPT,
-{0}, 0,
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}, 22, 128,
- 128, 1024, PSA_SUCCESS
+{
+ .test_desc = "Test psa_asymmetric_encrypt - Small output buffer\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_RSA_PKCS1V15_CRYPT,
+ .input = plaintext,
+ .input_length = 22,
+ .salt = NULL,
+ .salt_length = 0,
+ .output = expected_output,
+ .output_size = 127,
+ .expected_output_length = 128,
+ .expected_status = PSA_ERROR_BUFFER_TOO_SMALL
},
-
-{"Test psa_asymmetric_encrypt - Small output buffer\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT, PSA_ALG_RSA_PKCS1V15_CRYPT,
-{0}, 0,
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}, 22, 120,
- 128, 1024, PSA_ERROR_BUFFER_TOO_SMALL
-},
+#endif
#endif
#ifdef ARCH_TEST_SHA256
-{"Test psa_asymmetric_encrypt - Invalid algorithm\n", PSA_KEY_TYPE_RSA_PUBLIC_KEY,
-{0}, 162, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_SHA_256,
-{0}, 0,
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}, 22, 128,
- 128, 1024, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_asymmetric_encrypt - Invalid algorithm\n",
+ .type = PSA_KEY_TYPE_RSA_PUBLIC_KEY,
+ .data = rsa_128_key_data,
+ .data_length = 162,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_SHA_256,
+ .input = NULL,
+ .input_length = 0,
+ .salt = NULL,
+ .salt_length = 0,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output_length = 0,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
-#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_CRYPT
#ifdef ARCH_TEST_AES_128
-{"Test psa_asymmetric_encrypt - Invalid key type\n", PSA_KEY_TYPE_AES,
-{0x30, 0x82, 0x02, 0x5e, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xaf, 0x05,
- 0x7d, 0x39, 0x6e}, 16,
- PSA_KEY_USAGE_ENCRYPT, PSA_ALG_RSA_PKCS1V15_CRYPT,
-{0}, 0,
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}, 22, 128,
- 0, BYTES_TO_BITS(AES_16B_KEY_SIZE), PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_asymmetric_encrypt - Invalid key type\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_RSA_PKCS1V15_CRYPT,
+ .input = NULL,
+ .input_length = 0,
+ .salt = NULL,
+ .salt_length = 0,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output_length = 0,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#ifdef ARCH_TEST_RSA_1024
-{"Test psa_asymmetric_encrypt - Invalid usage\n", PSA_KEY_TYPE_RSA_PUBLIC_KEY,
-{0}, 162, PSA_KEY_USAGE_DECRYPT, PSA_ALG_RSA_PKCS1V15_CRYPT,
-{0}, 0,
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}, 22, 128,
- 128, 1024, PSA_ERROR_NOT_PERMITTED
+{
+ .test_desc = "Test psa_asymmetric_encrypt - Invalid usage\n",
+ .type = PSA_KEY_TYPE_RSA_PUBLIC_KEY,
+ .data = rsa_128_key_data,
+ .data_length = 162,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_RSA_PKCS1V15_CRYPT,
+ .input = NULL,
+ .input_length = 0,
+ .salt = NULL,
+ .salt_length = 0,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output_length = 0,
+ .expected_status = PSA_ERROR_NOT_PERMITTED
+},
+
+{
+ .test_desc = "Test psa_asymmetric_encrypt - RSA PKCS1V15 - Salt\n",
+ .type = PSA_KEY_TYPE_RSA_PUBLIC_KEY,
+ .data = rsa_128_key_data,
+ .data_length = 162,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_RSA_PKCS1V15_CRYPT,
+ .input = NULL,
+ .input_length = 0,
+ .salt = salt,
+ .salt_length = 16,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output_length = 0,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
@@ -216,41 +245,23 @@
#ifdef ARCH_TEST_ECDSA
#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
#ifdef ARCH_TEST_ECC_ASYMMETRIC_API_SUPPORT
-{"Test psa_asymmetric_encrypt - ECC public key\n",
- PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
-{0}, 65, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION,
-{0}, 0,
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}, 22, 128,
- 128, 256, PSA_SUCCESS
+{
+ .test_desc = "Test psa_asymmetric_encrypt - ECC public key\n",
+ .type = PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
+ .data = ec_key_data,
+ .data_length = 65,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION,
+ .input = NULL,
+ .input_length = 0,
+ .salt = NULL,
+ .salt_length = 0,
+ .output = NULL,
+ .output_size = 0,
+ .expected_output_length = 0,
+ .expected_status = PSA_ERROR_NOT_SUPPORTED
},
-
-{"Test psa_asymmetric_encrypt - ECC keypair\n",
- PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP256R1),
-{0}, 97, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_DETERMINISTIC_ECDSA(PSA_ALG_SHA_256),
-{0}, 0,
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}, 22, 128,
- 128, 256, PSA_SUCCESS
-}
#endif
#endif
#endif
};
-
-static test_data check2[] = {
-#ifdef ARCH_TEST_RSA_PKCS1V15_CRYPT
-#ifdef ARCH_TEST_RSA_1024
-{"Test psa_asymmetric_encrypt - Negative case\n", PSA_KEY_TYPE_RSA_PUBLIC_KEY,
-{0}, 162, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_RSA_PKCS1V15_CRYPT,
-{0}, 0,
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}, 22, 128,
- 128, 1024, PSA_SUCCESS
-},
-#endif
-#endif
-};
diff --git a/api-tests/dev_apis/crypto/test_c040/test_c040.c b/api-tests/dev_apis/crypto/test_c040/test_c040.c
index ae9b91e..2aadef5 100644
--- a/api-tests/dev_apis/crypto/test_c040/test_c040.c
+++ b/api-tests/dev_apis/crypto/test_c040/test_c040.c
@@ -27,29 +27,14 @@
NULL,
};
-static bool_t is_buffer_empty(uint8_t *buffer, size_t size)
-{
- int i;
-
- for (i = 0; i < (int)size; i++)
- {
- if (buffer[i] != 0)
- return FALSE;
- }
-
- return TRUE;
-}
-
-static int g_test_count = 1;
-static uint8_t output[SIZE_128B];
+static uint32_t g_test_count = 1;
+static int32_t valid_test_input_index = -1;
int32_t psa_asymmetric_decrypt_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
- const uint8_t *key_data;
- uint8_t *salt;
- size_t length;
+ size_t get_output_length;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_handle_t key_handle;
@@ -72,66 +57,27 @@
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- memset(output, 0, sizeof(output));
-
- /* Set the key data based on key type */
- if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type))
- {
- if (check1[i].key_type == PSA_KEY_TYPE_RSA_KEY_PAIR)
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keypair;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keypair;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(128))
- key_data = rsa_128_keypair;
- else
- return VAL_STATUS_INVALID;
- }
- else
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keydata;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keydata;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(128))
- key_data = rsa_128_keydata;
- else
- return VAL_STATUS_INVALID;
- }
- }
- else if (PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
- {
- if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(check1[i].key_type))
- key_data = ec_keypair;
- else
- key_data = ec_keydata;
- }
- else
- key_data = check1[i].key_data;
-
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].key_alg);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].alg);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage_flags);
/* Import the key data into the key slot */
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, key_data,
- check1[i].key_length, &key_handle);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
- if (is_buffer_empty(check1[i].salt, check1[i].salt_length) == TRUE)
- {
- salt = NULL;
- check1[i].salt_length = 0;
- }
- else
- salt = check1[i].salt;
-
/* Decrypt a short message with a private key */
- status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_DECRYPT, key_handle,
- check1[i].key_alg, check1[i].input, check1[i].input_length, salt,
- check1[i].salt_length, output, check1[i].output_size, &length);
+ status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_DECRYPT,
+ key_handle,
+ check1[i].alg,
+ check1[i].input,
+ check1[i].input_length,
+ check1[i].salt,
+ check1[i].salt_length,
+ check1[i].output,
+ check1[i].output_size,
+ &get_output_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(4));
if (check1[i].expected_status != PSA_SUCCESS)
@@ -144,10 +90,12 @@
}
/* Check if the output length matches with the expected length */
- TEST_ASSERT_EQUAL(length, check1[i].expected_output_length, TEST_CHECKPOINT_NUM(6));
+ TEST_ASSERT_EQUAL(get_output_length, check1[i].expected_output_length,
+ TEST_CHECKPOINT_NUM(6));
/* Check if the output matches with the expected data */
- TEST_ASSERT_MEMCMP(output, check1[i].expected_output, length, TEST_CHECKPOINT_NUM(7));
+ TEST_ASSERT_MEMCMP(check1[i].output, check1[i].expected_output, get_output_length,
+ TEST_CHECKPOINT_NUM(7));
/* Destroy the key */
status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, key_handle);
@@ -155,6 +103,12 @@
/* Reset the key attributes and check if psa_import_key fails */
val->crypto_function(VAL_CRYPTO_RESET_KEY_ATTRIBUTES, &attributes);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_NOT_SUPPORTED, TEST_CHECKPOINT_NUM(9));
+
+ if (valid_test_input_index < 0)
+ valid_test_input_index = i;
}
return VAL_STATUS_SUCCESS;
@@ -162,49 +116,50 @@
int32_t psa_asymmetric_decrypt_negative_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check2)/sizeof(check2[0]);
- int32_t i, status;
- uint8_t *salt;
- size_t length;
+ int32_t status;
+ size_t get_output_length;
psa_key_handle_t key_handle = 1;
+ if (valid_test_input_index < 0)
+ return RESULT_SKIP(VAL_STATUS_NO_TESTS);
+
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
- for (i = 0; i < num_checks; i++)
- {
+ /* Setting up the watchdog timer for each check */
+ status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
+ TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- /* Setting up the watchdog timer for each check */
- status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
- TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
+ val->print(PRINT_TEST, "[Check %d] Test psa_asymmetric_decrypt - Invalid key handle\n",
+ g_test_count++);
+ /* Encrypt a short message with a public key */
+ status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_DECRYPT,
+ key_handle,
+ check1[valid_test_input_index].alg,
+ check1[valid_test_input_index].input,
+ check1[valid_test_input_index].input_length,
+ check1[valid_test_input_index].salt,
+ check1[valid_test_input_index].salt_length,
+ check1[valid_test_input_index].output,
+ check1[valid_test_input_index].output_size,
+ &get_output_length);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(3));
- if (is_buffer_empty(check2[i].salt, check2[i].salt_length) == TRUE)
- {
- salt = NULL;
- check2[i].salt_length = 0;
- }
- else
- salt = check1[i].salt;
-
- val->print(PRINT_TEST, "[Check %d] Test psa_asymmetric_decrypt - Invalid key handle\n",
- g_test_count++);
- /* Encrypt a short message with a public key */
- status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_DECRYPT, key_handle,
- check2[i].key_alg, check2[i].input, check2[i].input_length, salt,
- check2[i].salt_length, output, check2[i].output_size, &length);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(3));
-
- val->print(PRINT_TEST, "[Check %d] Test psa_asymmetric_decrypt - Zero as key handle\n",
- g_test_count++);
- /* Encrypt a short message with a public key */
- status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_DECRYPT, 0,
- check2[i].key_alg, check2[i].input, check2[i].input_length, salt,
- check2[i].salt_length, output, check2[i].output_size, &length);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(4));
- }
+ val->print(PRINT_TEST, "[Check %d] Test psa_asymmetric_decrypt - Zero as key handle\n",
+ g_test_count++);
+ /* Encrypt a short message with a public key */
+ status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_DECRYPT,
+ 0,
+ check1[valid_test_input_index].alg,
+ check1[valid_test_input_index].input,
+ check1[valid_test_input_index].input_length,
+ check1[valid_test_input_index].salt,
+ check1[valid_test_input_index].salt_length,
+ check1[valid_test_input_index].output,
+ check1[valid_test_input_index].output_size,
+ &get_output_length);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(4));
return VAL_STATUS_SUCCESS;
}
-
-
diff --git a/api-tests/dev_apis/crypto/test_c040/test_data.h b/api-tests/dev_apis/crypto/test_c040/test_data.h
index 348065c..fe8ab15 100644
--- a/api-tests/dev_apis/crypto/test_c040/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c040/test_data.h
@@ -1,5 +1,5 @@
/** @file
- * Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
+ * Copyright (c) 2019-2020, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,313 +15,202 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- psa_key_type_t key_type;
- uint8_t key_data[16];
- uint32_t key_length;
- psa_key_usage_t usage;
- psa_algorithm_t key_alg;
- uint8_t salt[16];
+ psa_key_type_t type;
+ const uint8_t *data;
+ size_t data_length;
+ psa_key_usage_t usage_flags;
+ psa_algorithm_t alg;
+ const uint8_t *salt;
size_t salt_length;
- uint8_t input[128];
+ const uint8_t *input;
size_t input_length;
+ uint8_t *output;
size_t output_size;
- uint8_t expected_output[32];
+ const uint8_t *expected_output;
size_t expected_output_length;
- size_t expected_bit_length;
psa_status_t expected_status;
} test_data;
-static const uint8_t rsa_384_keypair[1];
-static const uint8_t rsa_384_keydata[1];
-static const uint8_t rsa_256_keypair[1];
-static const uint8_t rsa_256_keydata[1];
-
-static const uint8_t ec_keydata[] = {
- 0x30, 0x49, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01, 0x06,
- 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x01, 0x03, 0x32, 0x00, 0x04, 0xBC,
- 0x79, 0x7D, 0xB3, 0xAE, 0x7F, 0x08, 0xEC, 0x3D, 0x49, 0x6B, 0x4F, 0xB4, 0x11, 0xB3,
- 0xF6, 0x20, 0xA5, 0x58, 0xA5, 0x01, 0xE0, 0x22, 0x2D, 0x08, 0xCF, 0xE0, 0xDC, 0x8A,
- 0xEC, 0x8B, 0x1A, 0x7B, 0xF2, 0x4B, 0xE9, 0x29, 0x51, 0xCC, 0x5B, 0xA1, 0xBE, 0xBB,
- 0x24, 0x74, 0x90, 0x9A, 0xE0};
-
-static const uint8_t ec_keypair[] = {
- 0x30, 0x5F, 0x02, 0x01, 0x01, 0x04, 0x18, 0x33, 0x8E, 0x86, 0xA8, 0x81, 0xE2, 0x38,
- 0xF5, 0x49, 0xBD, 0x6F, 0x05, 0x53, 0x49, 0x4B, 0x73, 0xE3, 0xD6, 0x11, 0x30, 0xFD,
- 0xC6, 0xC9, 0x6D, 0xA0, 0x0A, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01,
- 0x01, 0xA1, 0x34, 0x03, 0x32, 0x00, 0x04, 0x51, 0x75, 0xBC, 0xDF, 0x30, 0xA3, 0x70,
- 0xF3, 0x9D, 0x53, 0x93, 0xE6, 0x12, 0x72, 0x88, 0xD8, 0x01, 0x67, 0xB5, 0xF4, 0xB4,
- 0xB7, 0x76, 0xC6, 0x74, 0xF7, 0xC6, 0xF3, 0x54, 0xB7, 0xD2, 0x24, 0x06, 0x2C, 0x1F,
- 0x68, 0x54, 0xB5, 0xA7, 0xAF, 0x0F, 0xE5, 0x78, 0xEA, 0xF2, 0x58, 0xF0, 0x27};
-
-static const uint8_t rsa_128_keydata[] = {
- 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
- 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02,
- 0x81, 0x81, 0x00, 0xaf, 0x05, 0x7d, 0x39, 0x6e, 0xe8, 0x4f, 0xb7, 0x5f, 0xdb,
- 0xb5, 0xc2, 0xb1, 0x3c, 0x7f, 0xe5, 0xa6, 0x54, 0xaa, 0x8a, 0xa2, 0x47, 0x0b,
- 0x54, 0x1e, 0xe1, 0xfe, 0xb0, 0xb1, 0x2d, 0x25, 0xc7, 0x97, 0x11, 0x53, 0x12,
- 0x49, 0xe1, 0x12, 0x96, 0x28, 0x04, 0x2d, 0xbb, 0xb6, 0xc1, 0x20, 0xd1, 0x44,
- 0x35, 0x24, 0xef, 0x4c, 0x0e, 0x6e, 0x1d, 0x89, 0x56, 0xee, 0xb2, 0x07, 0x7a,
- 0xf1, 0x23, 0x49, 0xdd, 0xee, 0xe5, 0x44, 0x83, 0xbc, 0x06, 0xc2, 0xc6, 0x19,
- 0x48, 0xcd, 0x02, 0xb2, 0x02, 0xe7, 0x96, 0xae, 0xbd, 0x94, 0xd3, 0xa7, 0xcb,
- 0xf8, 0x59, 0xc2, 0xc1, 0x81, 0x9c, 0x32, 0x4c, 0xb8, 0x2b, 0x9c, 0xd3, 0x4e,
- 0xde, 0x26, 0x3a, 0x2a, 0xbf, 0xfe, 0x47, 0x33, 0xf0, 0x77, 0x86, 0x9e, 0x86,
- 0x60, 0xf7, 0xd6, 0x83, 0x4d, 0xa5, 0x3d, 0x69, 0x0e, 0xf7, 0x98, 0x5f, 0x6b,
- 0xc3, 0x02, 0x03, 0x01, 0x00, 0x01};
-
-static const uint8_t rsa_128_keypair[] = {
-0x30, 0x82, 0x02, 0x5e, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xaf, 0x05,
-0x7d, 0x39, 0x6e, 0xe8, 0x4f, 0xb7, 0x5f, 0xdb, 0xb5, 0xc2, 0xb1, 0x3c, 0x7f,
-0xe5, 0xa6, 0x54, 0xaa, 0x8a, 0xa2, 0x47, 0x0b, 0x54, 0x1e, 0xe1, 0xfe, 0xb0,
-0xb1, 0x2d, 0x25, 0xc7, 0x97, 0x11, 0x53, 0x12, 0x49, 0xe1, 0x12, 0x96, 0x28,
-0x04, 0x2d, 0xbb, 0xb6, 0xc1, 0x20, 0xd1, 0x44, 0x35, 0x24, 0xef, 0x4c, 0x0e,
-0x6e, 0x1d, 0x89, 0x56, 0xee, 0xb2, 0x07, 0x7a, 0xf1, 0x23, 0x49, 0xdd, 0xee,
-0xe5, 0x44, 0x83, 0xbc, 0x06, 0xc2, 0xc6, 0x19, 0x48, 0xcd, 0x02, 0xb2, 0x02,
-0xe7, 0x96, 0xae, 0xbd, 0x94, 0xd3, 0xa7, 0xcb, 0xf8, 0x59, 0xc2, 0xc1, 0x81,
-0x9c, 0x32, 0x4c, 0xb8, 0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, 0xfa, 0xfa, 0x4d, 0x02, 0x40, 0x71, 0x19,
-0x5e, 0xec, 0x37, 0xe8, 0xd2, 0x57, 0xde, 0xcf, 0xc6, 0x72, 0xb0, 0x7a, 0xe6,
-0x39, 0xf1, 0x0c, 0xbb, 0x9b, 0x0c, 0x73, 0x9d, 0x0c, 0x80, 0x99, 0x68, 0xd6,
-0x44, 0xa9, 0x4e, 0x3f, 0xd6, 0xed, 0x92, 0x87, 0x07, 0x7a, 0x14, 0x58, 0x3f,
-0x37, 0x90, 0x58, 0xf7, 0x6a, 0x8a, 0xec, 0xd4, 0x3c, 0x62, 0xdc, 0x8c, 0x0f,
-0x41, 0x76, 0x66, 0x50, 0xd7, 0x25, 0x27, 0x5a, 0xc4, 0xa1, 0x02, 0x41, 0x00,
-0xbb, 0x32, 0xd1, 0x33, 0xed, 0xc2, 0xe0, 0x48, 0xd4, 0x63, 0x38, 0x8b, 0x7b,
-0xe9, 0xcb, 0x4b, 0xe2, 0x9f, 0x4b, 0x62, 0x50, 0xbe, 0x60, 0x3e, 0x70, 0xe3,
-0x64, 0x75, 0x01, 0xc9, 0x7d, 0xdd, 0xe2, 0x0a, 0x4e, 0x71, 0xbe, 0x95, 0xfd,
-0x5e, 0x71, 0x78, 0x4e, 0x25, 0xac, 0xa4, 0xba, 0xf2, 0x5b, 0xe5, 0x73, 0x8a,
-0xae, 0x59, 0xbb, 0xfe, 0x1c, 0x99, 0x77, 0x81, 0x44, 0x7a, 0x2b, 0x24};
-
-static test_data check1[] = {
+static const test_data check1[] = {
#ifdef ARCH_TEST_RSA_1024
#ifdef ARCH_TEST_RSA_PKCS1V15_CRYPT
-{"Test psa_asymmetric_decrypt - RSA KEY_PAIR PKCS1V15\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_DECRYPT, PSA_ALG_RSA_PKCS1V15_CRYPT,
-{0}, 0,
-{0x99, 0xff, 0xde, 0x2f, 0xcc, 0x00, 0xc9, 0xcc, 0x01, 0x97, 0x2e, 0xbf, 0xa7,
- 0x77, 0x9b, 0x29, 0x8d, 0xbb, 0xaf, 0x7f, 0x50, 0x70, 0x7a, 0x74, 0x05, 0x29,
- 0x6d, 0xd2, 0x78, 0x34, 0x56, 0xfc, 0x79, 0x20, 0x02, 0xf4, 0x62, 0xe7, 0x60,
- 0x50, 0x0e, 0x02, 0xaf, 0xa2, 0x5a, 0x85, 0x9a, 0xce, 0x87, 0x01, 0xcb, 0x5d,
- 0x3b, 0x02, 0x62, 0x11, 0x64, 0x31, 0xc4, 0x3a, 0xf8, 0xeb, 0x08, 0xf5, 0xa8,
- 0x83, 0x01, 0x05, 0x7c, 0xf1, 0xc1, 0x56, 0xa2, 0xa5, 0x19, 0x3c, 0x14, 0x3e,
- 0x7a, 0x5b, 0x03, 0xfa, 0xc1, 0x32, 0xb7, 0xe8, 0x9e, 0x6d, 0xcd, 0x8f, 0x4c,
- 0x82, 0xc9, 0xb2, 0x84, 0x52, 0x32, 0x9c, 0x26, 0x0d, 0x30, 0xbc, 0x39, 0xb3,
- 0x81, 0x6b, 0x7c, 0x46, 0xb4, 0x1b, 0x37, 0xb4, 0x85, 0x0d, 0x2a, 0xe7, 0x4e,
- 0x72, 0x9f, 0x99, 0xc6, 0x62, 0x1f, 0xbb, 0xe2, 0xe4, 0x68, 0x72},
- 128, 128,
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad},
- 32, 1024, PSA_SUCCESS
+{
+ .test_desc = "Test psa_asymmetric_decrypt - RSA KEY_PAIR PKCS1V15\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_RSA_PKCS1V15_CRYPT,
+ .input = ciphertext_7,
+ .input_length = 128,
+ .salt = NULL,
+ .salt_length = 0,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = plaintext,
+ .expected_output_length = 22,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_SHA256
#ifdef ARCH_TEST_RSA_OAEP
-{"Test psa_asymmetric_decrypt - RSA KEY_PAIR OAEP SHA256\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_DECRYPT, PSA_ALG_RSA_OAEP(PSA_ALG_SHA_256),
-{0}, 0,
-{0x3d, 0x31, 0x46, 0xb1, 0xc9, 0x82, 0x00, 0x42, 0x73, 0xa9, 0xeb, 0xb9, 0xb0,
- 0x63, 0xe6, 0xae, 0x53, 0xb1, 0xa8, 0x5b, 0xfc, 0x80, 0x23, 0x24, 0xbc, 0xdd,
- 0x04, 0xfa, 0xa0, 0xf7, 0x21, 0x1f, 0xb2, 0xbd, 0xee, 0xa4, 0x03, 0x58, 0x09,
- 0x55, 0x54, 0xdf, 0x9c, 0x25, 0x08, 0x66, 0xc7, 0x36, 0x1e, 0x73, 0x8f, 0x0d,
- 0x27, 0x0e, 0xaa, 0x27, 0x73, 0x8e, 0x87, 0x92, 0x8c, 0x5e, 0x31, 0x81, 0x55,
- 0x06, 0x34, 0x67, 0x27, 0x90, 0x0f, 0xf0, 0x3c, 0xef, 0x0b, 0xe6, 0xf9, 0xdd,
- 0x6b, 0xba, 0x63, 0xce, 0x89, 0x07, 0x4e, 0x81, 0x94, 0xfe, 0x68, 0xb5, 0xa5,
- 0x73, 0x94, 0x22, 0xd4, 0xf1, 0x38, 0xbb, 0xbb, 0x61, 0xf4, 0x9b, 0x76, 0xcf,
- 0x1f, 0x18, 0xde, 0xf2, 0xc9, 0x93, 0xe3, 0x11, 0x3b, 0x08, 0xc1, 0x91, 0xea,
- 0x1d, 0xa0, 0xfe, 0xb9, 0x4f, 0x8f, 0xd9, 0xb3, 0x01, 0x09, 0xa1},
- 128, 128,
-{0},
- 0, 1024, PSA_SUCCESS
+{
+ .test_desc = "Test psa_asymmetric_decrypt - RSA KEY_PAIR OAEP SHA256\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_RSA_OAEP(PSA_ALG_SHA_256),
+ .input = ciphertext_8,
+ .input_length = 128,
+ .salt = NULL,
+ .salt_length = 0,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = plaintext,
+ .expected_output_length = 22,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_asymmetric_decrypt - RSA KEY_PAIR OAEP SHA256 with label\n",
- PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_DECRYPT, PSA_ALG_RSA_OAEP(PSA_ALG_SHA_256),
-{0x74, 0x68, 0x69, 0x73, 0x00, 0x69, 0x73, 0x00, 0x61, 0x00, 0x6c, 0x61, 0x62,
- 0x65, 0x6c, 0x00}, 16,
-{0x46, 0xed, 0xc9, 0x98, 0x4a, 0x6d, 0x4b, 0x7c, 0x7f, 0xd8, 0x8f, 0xda, 0x9e,
- 0xa9, 0x1d, 0xdb, 0xd3, 0x0b, 0x28, 0xa0, 0x79, 0x3c, 0xc7, 0x5a, 0x9f, 0xcd,
- 0xd9, 0x4d, 0x86, 0x7c, 0x69, 0x09, 0x0a, 0x69, 0x7d, 0x46, 0xa6, 0xf3, 0x36,
- 0xa3, 0xe4, 0x8a, 0x12, 0x2d, 0xd3, 0xee, 0x3b, 0x51, 0x56, 0x6b, 0x44, 0x5f,
- 0xf7, 0x8a, 0xdb, 0x61, 0x3d, 0x09, 0xb7, 0xd8, 0xc5, 0x9c, 0x25, 0xa2, 0x7d,
- 0x8c, 0xf7, 0xf5, 0xe3, 0x64, 0x55, 0xf2, 0xe7, 0x1f, 0xf6, 0xc6, 0xee, 0x98,
- 0xd5, 0x74, 0x0e, 0x66, 0xb2, 0x37, 0x94, 0xac, 0xc7, 0x29, 0x06, 0x56, 0x19,
- 0x51, 0xc2, 0xbe, 0x50, 0x64, 0xf6, 0xa2, 0x50, 0x64, 0x6a, 0xb6, 0x27, 0xec,
- 0xbf, 0xa4, 0x8c, 0x02, 0xf8, 0x2c, 0x29, 0xfe, 0x9b, 0x8c, 0x8e, 0x6b, 0xe8,
- 0xeb, 0x75, 0x24, 0x32, 0x12, 0x49, 0x74, 0x37, 0x3b, 0x54, 0x2c},
- 128, 128,
-{0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x6e, 0x6f, 0x20, 0x73, 0x71,
- 0x75, 0x65, 0x61, 0x6d, 0x69, 0x73, 0x68, 0x20, 0x6f, 0x73, 0x73, 0x69, 0x66,
- 0x72, 0x61, 0x67, 0x65},
- 30, 1024, PSA_SUCCESS
+{
+ .test_desc = "Test psa_asymmetric_decrypt - RSA KEY_PAIR OAEP SHA256 with label\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_RSA_OAEP(PSA_ALG_SHA_256),
+ .input = ciphertext_9,
+ .input_length = 128,
+ .salt = salt,
+ .salt_length = 16,
+ .output = expected_output,
+ .output_size = BUFFER_SIZE,
+ .expected_output = plaintext,
+ .expected_output_length = 22,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_CRYPT
-{"Test psa_asymmetric_decrypt - Invalid key type (RSA public key)\n",
-PSA_KEY_TYPE_RSA_PUBLIC_KEY,
-{0}, 162, PSA_KEY_USAGE_DECRYPT, PSA_ALG_RSA_PKCS1V15_CRYPT,
-{0}, 0,
-{0x3d, 0x31, 0x46, 0xb1, 0xc9, 0x82, 0x00, 0x42, 0x73, 0xa9, 0xeb, 0xb9, 0xb0,
- 0x63, 0xe6, 0xae, 0x53, 0xb1, 0xa8, 0x5b, 0xfc, 0x80, 0x23, 0x24, 0xbc, 0xdd,
- 0x04, 0xfa, 0xa0, 0xf7, 0x21, 0x1f, 0xb2, 0xbd, 0xee, 0xa4, 0x03, 0x58, 0x09,
- 0x55, 0x54, 0xdf, 0x9c, 0x25, 0x08, 0x66, 0xc7, 0x36, 0x1e, 0x73, 0x8f, 0x0d,
- 0x27, 0x0e, 0xaa, 0x27, 0x73, 0x8e, 0x87, 0x92, 0x8c, 0x5e, 0x31, 0x81, 0x55,
- 0x06, 0x34, 0x67, 0x27, 0x90, 0x0f, 0xf0, 0x3c, 0xef, 0x0b, 0xe6, 0xf9, 0xdd,
- 0x6b, 0xba, 0x63, 0xce, 0x89, 0x07, 0x4e, 0x81, 0x94, 0xfe, 0x68, 0xb5, 0xa5,
- 0x73, 0x94, 0x22, 0xd4, 0xf1, 0x38, 0xbb, 0xbb, 0x61, 0xf4, 0x9b, 0x76, 0xcf,
- 0x1f, 0x18, 0xde, 0xf2, 0xc9, 0x93, 0xe3, 0x11, 0x3b, 0x08, 0xc1, 0x91, 0xea,
- 0x1d, 0xa0, 0xfe, 0xb9, 0x4f, 0x8f, 0xd9, 0xb3, 0x01, 0x09, 0xa1},
- 128, 128,
-{0},
- 0, 1024, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_asymmetric_decrypt - Invalid key type (RSA public key)\n",
+ .type = PSA_KEY_TYPE_RSA_PUBLIC_KEY,
+ .data = rsa_128_key_data,
+ .data_length = 162,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_RSA_PKCS1V15_CRYPT,
+ .input = NULL,
+ .input_length = 0,
+ .salt = NULL,
+ .salt_length = 0,
+ .output = NULL,
+ .output_size = 0,
+ .expected_output = NULL,
+ .expected_output_length = 0,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
-{"Test psa_asymmetric_decrypt - Small output buffer\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_DECRYPT, PSA_ALG_RSA_PKCS1V15_CRYPT,
-{0}, 0,
-{0x99, 0xff, 0xde, 0x2f, 0xcc, 0x00, 0xc9, 0xcc, 0x01, 0x97, 0x2e, 0xbf, 0xa7,
- 0x77, 0x9b, 0x29, 0x8d, 0xbb, 0xaf, 0x7f, 0x50, 0x70, 0x7a, 0x74, 0x05, 0x29,
- 0x6d, 0xd2, 0x78, 0x34, 0x56, 0xfc, 0x79, 0x20, 0x02, 0xf4, 0x62, 0xe7, 0x60,
- 0x50, 0x0e, 0x02, 0xaf, 0xa2, 0x5a, 0x85, 0x9a, 0xce, 0x87, 0x01, 0xcb, 0x5d,
- 0x3b, 0x02, 0x62, 0x11, 0x64, 0x31, 0xc4, 0x3a, 0xf8, 0xeb, 0x08, 0xf5, 0xa8,
- 0x83, 0x01, 0x05, 0x7c, 0xf1, 0xc1, 0x56, 0xa2, 0xa5, 0x19, 0x3c, 0x14, 0x3e,
- 0x7a, 0x5b, 0x03, 0xfa, 0xc1, 0x32, 0xb7, 0xe8, 0x9e, 0x6d, 0xcd, 0x8f, 0x4c,
- 0x82, 0xc9, 0xb2, 0x84, 0x52, 0x32, 0x9c, 0x26, 0x0d, 0x30, 0xbc, 0x39, 0xb3,
- 0x81, 0x6b, 0x7c, 0x46, 0xb4, 0x1b, 0x37, 0xb4, 0x85, 0x0d, 0x2a, 0xe7, 0x4e,
- 0x72, 0x9f, 0x99, 0xc6, 0x62, 0x1f, 0xbb, 0xe2, 0xe4, 0x68, 0x72},
- 128, 30,
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad},
- 32, 1024, PSA_ERROR_BUFFER_TOO_SMALL
+{
+ .test_desc = "Test psa_asymmetric_decrypt - Small output buffer\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_RSA_PKCS1V15_CRYPT,
+ .input = ciphertext_7,
+ .input_length = 128,
+ .salt = NULL,
+ .salt_length = 0,
+ .output = expected_output,
+ .output_size = 21,
+ .expected_output = plaintext,
+ .expected_output_length = 22,
+ .expected_status = PSA_ERROR_BUFFER_TOO_SMALL
},
#endif
#ifdef ARCH_TEST_SHA256
-{"Test psa_asymmetric_decrypt - Invalid algorithm\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_DECRYPT, PSA_ALG_SHA_256,
-{0}, 0,
-{0x99, 0xff, 0xde, 0x2f, 0xcc, 0x00, 0xc9, 0xcc, 0x01, 0x97, 0x2e, 0xbf, 0xa7,
- 0x77, 0x9b, 0x29, 0x8d, 0xbb, 0xaf, 0x7f, 0x50, 0x70, 0x7a, 0x74, 0x05, 0x29,
- 0x6d, 0xd2, 0x78, 0x34, 0x56, 0xfc, 0x79, 0x20, 0x02, 0xf4, 0x62, 0xe7, 0x60,
- 0x50, 0x0e, 0x02, 0xaf, 0xa2, 0x5a, 0x85, 0x9a, 0xce, 0x87, 0x01, 0xcb, 0x5d,
- 0x3b, 0x02, 0x62, 0x11, 0x64, 0x31, 0xc4, 0x3a, 0xf8, 0xeb, 0x08, 0xf5, 0xa8,
- 0x83, 0x01, 0x05, 0x7c, 0xf1, 0xc1, 0x56, 0xa2, 0xa5, 0x19, 0x3c, 0x14, 0x3e,
- 0x7a, 0x5b, 0x03, 0xfa, 0xc1, 0x32, 0xb7, 0xe8, 0x9e, 0x6d, 0xcd, 0x8f, 0x4c,
- 0x82, 0xc9, 0xb2, 0x84, 0x52, 0x32, 0x9c, 0x26, 0x0d, 0x30, 0xbc, 0x39, 0xb3,
- 0x81, 0x6b, 0x7c, 0x46, 0xb4, 0x1b, 0x37, 0xb4, 0x85, 0x0d, 0x2a, 0xe7, 0x4e,
- 0x72, 0x9f, 0x99, 0xc6, 0x62, 0x1f, 0xbb, 0xe2, 0xe4, 0x68, 0x72},
- 128, 128,
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad},
- 32, 1024, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_asymmetric_decrypt - Invalid algorithm\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_SHA_256,
+ .input = NULL,
+ .input_length = 0,
+ .salt = NULL,
+ .salt_length = 0,
+ .output = NULL,
+ .output_size = 0,
+ .expected_output = NULL,
+ .expected_output_length = 0,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_CRYPT
#ifdef ARCH_TEST_AES_128
-{"Test psa_asymmetric_decrypt - Invalid key type (AES Key)\n", PSA_KEY_TYPE_AES,
-{0x30, 0x82, 0x02, 0x5e, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xaf, 0x05,
- 0x7d, 0x39, 0x6e}, AES_16B_KEY_SIZE, PSA_KEY_USAGE_DECRYPT, PSA_ALG_RSA_PKCS1V15_CRYPT,
-{0}, 0,
-{0x99, 0xff, 0xde, 0x2f, 0xcc, 0x00, 0xc9, 0xcc, 0x01, 0x97, 0x2e, 0xbf, 0xa7,
- 0x77, 0x9b, 0x29, 0x8d, 0xbb, 0xaf, 0x7f, 0x50, 0x70, 0x7a, 0x74, 0x05, 0x29,
- 0x6d, 0xd2, 0x78, 0x34, 0x56, 0xfc, 0x79, 0x20, 0x02, 0xf4, 0x62, 0xe7, 0x60,
- 0x50, 0x0e, 0x02, 0xaf, 0xa2, 0x5a, 0x85, 0x9a, 0xce, 0x87, 0x01, 0xcb, 0x5d,
- 0x3b, 0x02, 0x62, 0x11, 0x64, 0x31, 0xc4, 0x3a, 0xf8, 0xeb, 0x08, 0xf5, 0xa8,
- 0x83, 0x01, 0x05, 0x7c, 0xf1, 0xc1, 0x56, 0xa2, 0xa5, 0x19, 0x3c, 0x14, 0x3e,
- 0x7a, 0x5b, 0x03, 0xfa, 0xc1, 0x32, 0xb7, 0xe8, 0x9e, 0x6d, 0xcd, 0x8f, 0x4c,
- 0x82, 0xc9, 0xb2, 0x84, 0x52, 0x32, 0x9c, 0x26, 0x0d, 0x30, 0xbc, 0x39, 0xb3,
- 0x81, 0x6b, 0x7c, 0x46, 0xb4, 0x1b, 0x37, 0xb4, 0x85, 0x0d, 0x2a, 0xe7, 0x4e,
- 0x72, 0x9f, 0x99, 0xc6, 0x62, 0x1f, 0xbb, 0xe2, 0xe4, 0x68, 0x72},
- 128, 128,
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad},
- 32, BYTES_TO_BITS(AES_16B_KEY_SIZE), PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_asymmetric_decrypt - Invalid key type (AES Key)\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_RSA_PKCS1V15_CRYPT,
+ .input = NULL,
+ .input_length = 0,
+ .salt = NULL,
+ .salt_length = 0,
+ .output = NULL,
+ .output_size = 0,
+ .expected_output = NULL,
+ .expected_output_length = 0,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#ifdef ARCH_TEST_RSA_1024
-{"Test psa_asymmetric_decrypt - Invalid usage\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_RSA_PKCS1V15_CRYPT,
-{0}, 0,
-{0x99, 0xff, 0xde, 0x2f, 0xcc, 0x00, 0xc9, 0xcc, 0x01, 0x97, 0x2e, 0xbf, 0xa7,
- 0x77, 0x9b, 0x29, 0x8d, 0xbb, 0xaf, 0x7f, 0x50, 0x70, 0x7a, 0x74, 0x05, 0x29,
- 0x6d, 0xd2, 0x78, 0x34, 0x56, 0xfc, 0x79, 0x20, 0x02, 0xf4, 0x62, 0xe7, 0x60,
- 0x50, 0x0e, 0x02, 0xaf, 0xa2, 0x5a, 0x85, 0x9a, 0xce, 0x87, 0x01, 0xcb, 0x5d,
- 0x3b, 0x02, 0x62, 0x11, 0x64, 0x31, 0xc4, 0x3a, 0xf8, 0xeb, 0x08, 0xf5, 0xa8,
- 0x83, 0x01, 0x05, 0x7c, 0xf1, 0xc1, 0x56, 0xa2, 0xa5, 0x19, 0x3c, 0x14, 0x3e,
- 0x7a, 0x5b, 0x03, 0xfa, 0xc1, 0x32, 0xb7, 0xe8, 0x9e, 0x6d, 0xcd, 0x8f, 0x4c,
- 0x82, 0xc9, 0xb2, 0x84, 0x52, 0x32, 0x9c, 0x26, 0x0d, 0x30, 0xbc, 0x39, 0xb3,
- 0x81, 0x6b, 0x7c, 0x46, 0xb4, 0x1b, 0x37, 0xb4, 0x85, 0x0d, 0x2a, 0xe7, 0x4e,
- 0x72, 0x9f, 0x99, 0xc6, 0x62, 0x1f, 0xbb, 0xe2, 0xe4, 0x68, 0x72},
- 128, 128,
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad},
- 32, 1024, PSA_ERROR_NOT_PERMITTED
+{
+ .test_desc = "Test psa_asymmetric_decrypt - Invalid usage\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_RSA_PKCS1V15_CRYPT,
+ .input = NULL,
+ .input_length = 0,
+ .salt = NULL,
+ .salt_length = 0,
+ .output = NULL,
+ .output_size = 0,
+ .expected_output = NULL,
+ .expected_output_length = 0,
+ .expected_status = PSA_ERROR_NOT_PERMITTED
},
-#endif
-#endif
-};
-static test_data check2[] = {
-#ifdef ARCH_TEST_RSA_PKCS1V15_CRYPT
-#ifdef ARCH_TEST_RSA_1024
-{"Test psa_asymmetric_decrypt - Negative case\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_DECRYPT, PSA_ALG_RSA_PKCS1V15_CRYPT,
-{0}, 0,
-{0x99, 0xff, 0xde, 0x2f, 0xcc, 0x00, 0xc9, 0xcc, 0x01, 0x97, 0x2e, 0xbf, 0xa7,
- 0x77, 0x9b, 0x29, 0x8d, 0xbb, 0xaf, 0x7f, 0x50, 0x70, 0x7a, 0x74, 0x05, 0x29,
- 0x6d, 0xd2, 0x78, 0x34, 0x56, 0xfc, 0x79, 0x20, 0x02, 0xf4, 0x62, 0xe7, 0x60,
- 0x50, 0x0e, 0x02, 0xaf, 0xa2, 0x5a, 0x85, 0x9a, 0xce, 0x87, 0x01, 0xcb, 0x5d,
- 0x3b, 0x02, 0x62, 0x11, 0x64, 0x31, 0xc4, 0x3a, 0xf8, 0xeb, 0x08, 0xf5, 0xa8,
- 0x83, 0x01, 0x05, 0x7c, 0xf1, 0xc1, 0x56, 0xa2, 0xa5, 0x19, 0x3c, 0x14, 0x3e,
- 0x7a, 0x5b, 0x03, 0xfa, 0xc1, 0x32, 0xb7, 0xe8, 0x9e, 0x6d, 0xcd, 0x8f, 0x4c,
- 0x82, 0xc9, 0xb2, 0x84, 0x52, 0x32, 0x9c, 0x26, 0x0d, 0x30, 0xbc, 0x39, 0xb3,
- 0x81, 0x6b, 0x7c, 0x46, 0xb4, 0x1b, 0x37, 0xb4, 0x85, 0x0d, 0x2a, 0xe7, 0x4e,
- 0x72, 0x9f, 0x99, 0xc6, 0x62, 0x1f, 0xbb, 0xe2, 0xe4, 0x68, 0x72},
- 128, 128,
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad},
- 32, 1024, PSA_SUCCESS
+{
+ .test_desc = "Test psa_asymmetric_decrypt - RSA PKCS1V15 - Salt\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_DECRYPT,
+ .alg = PSA_ALG_RSA_PKCS1V15_CRYPT,
+ .input = NULL,
+ .input_length = 0,
+ .salt = salt,
+ .salt_length = 16,
+ .output = NULL,
+ .output_size = 0,
+ .expected_output_length = 0,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
diff --git a/api-tests/dev_apis/crypto/test_c041/test_c041.c b/api-tests/dev_apis/crypto/test_c041/test_c041.c
index 7691bf3..c38fff8 100644
--- a/api-tests/dev_apis/crypto/test_c041/test_c041.c
+++ b/api-tests/dev_apis/crypto/test_c041/test_c041.c
@@ -27,15 +27,14 @@
NULL,
};
-static int g_test_count = 1;
-static uint8_t signature[SIZE_128B];
+static uint32_t g_test_count = 1;
+static int32_t valid_test_input_index = -1;
int32_t psa_asymmetric_sign_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
- const uint8_t *key_data;
- size_t length;
+ size_t get_signature_length;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_handle_t key_handle;
@@ -57,58 +56,26 @@
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- memset(signature, 0, sizeof(signature));
-
- /* Set the key data based on key type */
- if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type))
- {
- if (check1[i].key_type == PSA_KEY_TYPE_RSA_KEY_PAIR)
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keypair;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keypair;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(128))
- key_data = rsa_128_keypair;
- else
- return VAL_STATUS_INVALID;
- }
- else
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keydata;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keydata;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(128))
- key_data = rsa_128_keydata;
- else
- return VAL_STATUS_INVALID;
- }
- }
- else if (PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
- {
- if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(check1[i].key_type))
- key_data = ec_keypair;
- else
- key_data = ec_keydata;
- }
- else
- key_data = check1[i].key_data;
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].key_alg);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].alg);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage_flags);
/* Import the key data into the key slot */
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, key_data,
- check1[i].key_length, &key_handle);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Sign a hash or short message with a private key */
- status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_SIGN, key_handle,
- check1[i].key_alg, check1[i].input, check1[i].input_length,
- signature, check1[i].signature_size, &length);
+ status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_SIGN,
+ key_handle,
+ check1[i].alg,
+ check1[i].hash,
+ check1[i].hash_length,
+ check1[i].signature,
+ check1[i].signature_size,
+ &get_signature_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(4));
if (check1[i].expected_status != PSA_SUCCESS)
@@ -121,14 +88,19 @@
}
/* Check if the output length matches with the expected length */
- TEST_ASSERT_EQUAL(length, check1[i].expected_signature_length, TEST_CHECKPOINT_NUM(6));
+ TEST_ASSERT_EQUAL(get_signature_length, check1[i].expected_signature_length,
+ TEST_CHECKPOINT_NUM(6));
/* Check if the output matches with the expected data */
- TEST_ASSERT_MEMCMP(signature, check1[i].expected_signature, length, TEST_CHECKPOINT_NUM(7));
+ TEST_ASSERT_MEMCMP(check1[i].signature, check1[i].expected_signature, get_signature_length,
+ TEST_CHECKPOINT_NUM(7));
/* Destroy the key */
status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(8));
+
+ if (valid_test_input_index < 0)
+ valid_test_input_index = i;
}
return VAL_STATUS_SUCCESS;
@@ -136,37 +108,46 @@
int32_t psa_asymmetric_sign_negative_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check2)/sizeof(check2[0]);
- int32_t i, status;
- size_t length;
+ int32_t status;
+ size_t get_signature_length;
psa_key_handle_t key_handle = 10;
+ if (valid_test_input_index < 0)
+ return RESULT_SKIP(VAL_STATUS_NO_TESTS);
+
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
- for (i = 0; i < num_checks; i++)
- {
- /* Setting up the watchdog timer for each check */
- status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
- TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
+ /* Setting up the watchdog timer for each check */
+ status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
+ TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- val->print(PRINT_TEST, "[Check %d] Test psa_asymmetric_sign - Invalid key handle\n",
- g_test_count++);
- /* Sign a hash or short message with a private key */
- status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_SIGN, key_handle,
- check2[i].key_alg, check2[i].input, check2[i].input_length,
- signature, check2[i].signature_size, &length);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(3));
+ val->print(PRINT_TEST, "[Check %d] Test psa_asymmetric_sign - Invalid key handle\n",
+ g_test_count++);
+ /* Sign a hash or short message with a private key */
+ status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_SIGN,
+ key_handle,
+ check1[valid_test_input_index].alg,
+ check1[valid_test_input_index].hash,
+ check1[valid_test_input_index].hash_length,
+ check1[valid_test_input_index].signature,
+ check1[valid_test_input_index].signature_size,
+ &get_signature_length);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(3));
- val->print(PRINT_TEST, "[Check %d] Test psa_asymmetric_sign - Zero as key handle\n",
- g_test_count++);
- /* Sign a hash or short message with a private key */
- status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_SIGN, 0,
- check2[i].key_alg, check2[i].input, check2[i].input_length,
- signature, check2[i].signature_size, &length);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(4));
- }
+ val->print(PRINT_TEST, "[Check %d] Test psa_asymmetric_sign - Zero as key handle\n",
+ g_test_count++);
+ /* Sign a hash or short message with a private key */
+ status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_SIGN,
+ 0,
+ check1[valid_test_input_index].alg,
+ check1[valid_test_input_index].hash,
+ check1[valid_test_input_index].hash_length,
+ check1[valid_test_input_index].signature,
+ check1[valid_test_input_index].signature_size,
+ &get_signature_length);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(4));
return VAL_STATUS_SUCCESS;
}
diff --git a/api-tests/dev_apis/crypto/test_c041/test_data.h b/api-tests/dev_apis/crypto/test_c041/test_data.h
index cbd1dd1..7af5157 100644
--- a/api-tests/dev_apis/crypto/test_c041/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c041/test_data.h
@@ -15,137 +15,60 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- psa_key_type_t key_type;
- uint8_t key_data[16];
- uint32_t key_length;
- psa_key_usage_t usage;
- psa_algorithm_t key_alg;
- uint8_t input[32];
- size_t input_length;
+ psa_key_type_t type;
+ const uint8_t *data;
+ size_t data_length;
+ psa_key_usage_t usage_flags;
+ psa_algorithm_t alg;
+ const uint8_t *hash;
+ size_t hash_length;
+ uint8_t *signature;
size_t signature_size;
- uint8_t expected_signature[128];
+ const uint8_t *expected_signature;
size_t expected_signature_length;
- size_t expected_bit_length;
psa_status_t expected_status;
} test_data;
-static const uint8_t rsa_384_keypair[1];
-static const uint8_t rsa_384_keydata[1];
-static const uint8_t rsa_256_keypair[1];
-static const uint8_t rsa_256_keydata[1];
-static const uint8_t ec_keydata[1];
-
-static const uint8_t ec_keypair[] = {
- 0xab, 0x45, 0x43, 0x57, 0x12, 0x64,
- 0x9c, 0xb3, 0x0b, 0xbd, 0xda, 0xc4, 0x91, 0x97, 0xee, 0xbf, 0x27, 0x40, 0xff, 0xc7,
- 0xf8, 0x74, 0xd9, 0x24, 0x4c, 0x34, 0x60, 0xf5, 0x4f, 0x32, 0x2d, 0x3a};
-
-static const uint8_t rsa_128_keydata[] = {
- 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
- 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02,
- 0x81, 0x81, 0x00, 0xaf, 0x05, 0x7d, 0x39, 0x6e, 0xe8, 0x4f, 0xb7, 0x5f, 0xdb,
- 0xb5, 0xc2, 0xb1, 0x3c, 0x7f, 0xe5, 0xa6, 0x54, 0xaa, 0x8a, 0xa2, 0x47, 0x0b,
- 0x54, 0x1e, 0xe1, 0xfe, 0xb0, 0xb1, 0x2d, 0x25, 0xc7, 0x97, 0x11, 0x53, 0x12,
- 0x49, 0xe1, 0x12, 0x96, 0x28, 0x04, 0x2d, 0xbb, 0xb6, 0xc1, 0x20, 0xd1, 0x44,
- 0x35, 0x24, 0xef, 0x4c, 0x0e, 0x6e, 0x1d, 0x89, 0x56, 0xee, 0xb2, 0x07, 0x7a,
- 0xf1, 0x23, 0x49, 0xdd, 0xee, 0xe5, 0x44, 0x83, 0xbc, 0x06, 0xc2, 0xc6, 0x19,
- 0x48, 0xcd, 0x02, 0xb2, 0x02, 0xe7, 0x96, 0xae, 0xbd, 0x94, 0xd3, 0xa7, 0xcb,
- 0xf8, 0x59, 0xc2, 0xc1, 0x81, 0x9c, 0x32, 0x4c, 0xb8, 0x2b, 0x9c, 0xd3, 0x4e,
- 0xde, 0x26, 0x3a, 0x2a, 0xbf, 0xfe, 0x47, 0x33, 0xf0, 0x77, 0x86, 0x9e, 0x86,
- 0x60, 0xf7, 0xd6, 0x83, 0x4d, 0xa5, 0x3d, 0x69, 0x0e, 0xf7, 0x98, 0x5f, 0x6b,
- 0xc3, 0x02, 0x03, 0x01, 0x00, 0x01};
-
-static const uint8_t rsa_128_keypair[] = {
-0x30, 0x82, 0x02, 0x5e, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xaf, 0x05,
-0x7d, 0x39, 0x6e, 0xe8, 0x4f, 0xb7, 0x5f, 0xdb, 0xb5, 0xc2, 0xb1, 0x3c, 0x7f,
-0xe5, 0xa6, 0x54, 0xaa, 0x8a, 0xa2, 0x47, 0x0b, 0x54, 0x1e, 0xe1, 0xfe, 0xb0,
-0xb1, 0x2d, 0x25, 0xc7, 0x97, 0x11, 0x53, 0x12, 0x49, 0xe1, 0x12, 0x96, 0x28,
-0x04, 0x2d, 0xbb, 0xb6, 0xc1, 0x20, 0xd1, 0x44, 0x35, 0x24, 0xef, 0x4c, 0x0e,
-0x6e, 0x1d, 0x89, 0x56, 0xee, 0xb2, 0x07, 0x7a, 0xf1, 0x23, 0x49, 0xdd, 0xee,
-0xe5, 0x44, 0x83, 0xbc, 0x06, 0xc2, 0xc6, 0x19, 0x48, 0xcd, 0x02, 0xb2, 0x02,
-0xe7, 0x96, 0xae, 0xbd, 0x94, 0xd3, 0xa7, 0xcb, 0xf8, 0x59, 0xc2, 0xc1, 0x81,
-0x9c, 0x32, 0x4c, 0xb8, 0x2b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xfa, 0xfa, 0x4d, 0x02, 0x40, 0x71, 0x19,
-0x5e, 0xec, 0x37, 0xe8, 0xd2, 0x57, 0xde, 0xcf, 0xc6, 0x72, 0xb0, 0x7a, 0xe6,
-0x39, 0xf1, 0x0c, 0xbb, 0x9b, 0x0c, 0x73, 0x9d, 0x0c, 0x80, 0x99, 0x68, 0xd6,
-0x44, 0xa9, 0x4e, 0x3f, 0xd6, 0xed, 0x92, 0x87, 0x07, 0x7a, 0x14, 0x58, 0x3f,
-0x37, 0x90, 0x58, 0xf7, 0x6a, 0x8a, 0xec, 0xd4, 0x3c, 0x62, 0xdc, 0x8c, 0x0f,
-0x41, 0x76, 0x66, 0x50, 0xd7, 0x25, 0x27, 0x5a, 0xc4, 0xa1, 0x02, 0x41, 0x00,
-0xbb, 0x32, 0xd1, 0x33, 0xed, 0xc2, 0xe0, 0x48, 0xd4, 0x63, 0x38, 0x8b, 0x7b,
-0xe9, 0xcb, 0x4b, 0xe2, 0x9f, 0x4b, 0x62, 0x50, 0xbe, 0x60, 0x3e, 0x70, 0xe3,
-0x64, 0x75, 0x01, 0xc9, 0x7d, 0xdd, 0xe2, 0x0a, 0x4e, 0x71, 0xbe, 0x95, 0xfd,
-0x5e, 0x71, 0x78, 0x4e, 0x25, 0xac, 0xa4, 0xba, 0xf2, 0x5b, 0xe5, 0x73, 0x8a,
-0xae, 0x59, 0xbb, 0xfe, 0x1c, 0x99, 0x77, 0x81, 0x44, 0x7a, 0x2b, 0x24};
-
static const test_data check1[] = {
#ifdef ARCH_TEST_RSA_1024
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
-{"Test psa_asymmetric_sign - RSA KEY_PAIR PKCS1V15 RAW\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_SIGN, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
-{0x61, 0x62, 0x63}, 3, 128,
-{0x2c, 0x77, 0x44, 0x98, 0x3f, 0x02, 0x3a, 0xc7, 0xbb, 0x1c, 0x55, 0x52, 0x9d,
- 0x83, 0xed, 0x11, 0xa7, 0x6a, 0x78, 0x98, 0xa1, 0xbb, 0x5c, 0xe1, 0x91, 0x37,
- 0x5a, 0x4a, 0xa7, 0x49, 0x5a, 0x63, 0x3d, 0x27, 0x87, 0x9f, 0xf5, 0x8e, 0xba,
- 0x5a, 0x57, 0x37, 0x1c, 0x34, 0xfe, 0xb1, 0x18, 0x0e, 0x8b, 0x85, 0x0d, 0x55,
- 0x24, 0x76, 0xeb, 0xb5, 0x63, 0x4d, 0xf6, 0x20, 0x26, 0x19, 0x92, 0xf1, 0x2e,
- 0xbe, 0xe9, 0x09, 0x70, 0x41, 0xdb, 0xbe, 0xa8, 0x5a, 0x42, 0xd4, 0x5b, 0x34,
- 0x4b, 0xe5, 0x07, 0x3c, 0xeb, 0x77, 0x2f, 0xfc, 0x60, 0x49, 0x54, 0xb9, 0x15,
- 0x8b, 0xa8, 0x1e, 0xc3, 0xdc, 0x4d, 0x9d, 0x65, 0xe3, 0xab, 0x7a, 0xa3, 0x18,
- 0x16, 0x5f, 0x38, 0xc3, 0x6f, 0x84, 0x1f, 0x1c, 0x69, 0xcb, 0x1c, 0xfa, 0x49,
- 0x4a, 0xa5, 0xcb, 0xb4, 0xd6, 0xc0, 0xef, 0xba, 0xfb, 0x04, 0x3a},
- 128, 1024, PSA_SUCCESS
+{
+ .test_desc = "Test psa_asymmetric_sign - RSA KEY_PAIR PKCS1V15 RAW\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_SIGN,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
+ .hash = sha_256_hash,
+ .hash_length = 32,
+ .signature = expected_output,
+ .signature_size = BUFFER_SIZE,
+ .expected_signature = signature_1,
+ .expected_signature_length = 128,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN
#ifdef ARCH_TEST_SHA256
-{"Test psa_asymmetric_sign - RSA KEY_PAIR PKCS1V15 SHA-256\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_SIGN, PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}, 32, 128,
-{0xa7, 0x36, 0x64, 0xd5, 0x5b, 0x39, 0xc7, 0xea, 0x6c, 0x1e, 0x5b, 0x50, 0x11,
- 0x72, 0x4a, 0x11, 0xe1, 0xd7, 0x07, 0x3d, 0x3a, 0x68, 0xf4, 0x8c, 0x83, 0x6f,
- 0xad, 0x15, 0x3a, 0x1d, 0x91, 0xb6, 0xab, 0xdb, 0xc8, 0xf6, 0x9d, 0xa1, 0x3b,
- 0x20, 0x6c, 0xc9, 0x6a, 0xf6, 0x36, 0x3b, 0x11, 0x44, 0x58, 0xb0, 0x26, 0xaf,
- 0x14, 0xb2, 0x4f, 0xab, 0x89, 0x29, 0xed, 0x63, 0x4c, 0x6a, 0x2a, 0xca, 0xce,
- 0x0b, 0xcc, 0x62, 0xd9, 0xbb, 0x6a, 0x98, 0x4a, 0xfb, 0xcb, 0xfc, 0xd3, 0xa0,
- 0x60, 0x8d, 0x32, 0xa2, 0xba, 0xe5, 0x35, 0xb9, 0xcd, 0x1e, 0xcd, 0xf9, 0xdd,
- 0x28, 0x1d, 0xb1, 0xe0, 0x02, 0x5c, 0x3b, 0xfb, 0x55, 0x12, 0x96, 0x3e, 0xc3,
- 0xb9, 0x8d, 0xda, 0xa6, 0x9e, 0x38, 0xbc, 0x3c, 0x84, 0xb1, 0xb6, 0x1a, 0x04,
- 0xe5, 0x64, 0x86, 0x40, 0x85, 0x6a, 0xac, 0xc6, 0xfc, 0x73, 0x11},
- 128, 1024, PSA_SUCCESS
+{
+ .test_desc = "Test psa_asymmetric_sign - RSA KEY_PAIR PKCS1V15 SHA-256\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_SIGN,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
+ .hash = sha_256_hash,
+ .hash_length = 32,
+ .signature = expected_output,
+ .signature_size = BUFFER_SIZE,
+ .expected_signature = signature_2,
+ .expected_signature_length = 128,
+ .expected_status = PSA_SUCCESS,
},
#endif
#endif
@@ -154,97 +77,92 @@
#ifdef ARCH_TEST_SHA256
#ifdef ARCH_TEST_DETERMINISTIC_ECDSA
#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
-{"Test psa_asymmetric_sign - ECDSA SECP256R1 SHA-256\n",
- PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP256R1), {0}, 32,
- PSA_KEY_USAGE_SIGN, PSA_ALG_DETERMINISTIC_ECDSA(PSA_ALG_SHA_256),
-{0x9a, 0xc4, 0x33, 0x5b, 0x46, 0x9b, 0xbd, 0x79, 0x14, 0x39, 0x24, 0x85, 0x04,
- 0xdd, 0x0d, 0x49, 0xc7, 0x13, 0x49, 0xa2, 0x95, 0xfe, 0xe5, 0xa1, 0xc6, 0x85,
- 0x07, 0xf4, 0x5a, 0x9e, 0x1c, 0x7b}, 32, 128,
-{0x6a, 0x33, 0x99, 0xf6, 0x94, 0x21, 0xff, 0xe1, 0x49, 0x03, 0x77, 0xad, 0xf2,
- 0xea, 0x1f, 0x11, 0x7d, 0x81, 0xa6, 0x3c, 0xf5, 0xbf, 0x22, 0xe9, 0x18, 0xd5,
- 0x11, 0x75, 0xeb, 0x25, 0x91, 0x51, 0xce, 0x95, 0xd7, 0xc2, 0x6c, 0xc0, 0x4e,
- 0x25, 0x50, 0x3e, 0x2f, 0x7a, 0x1e, 0xc3, 0x57, 0x3e, 0x3c, 0x24, 0x12, 0x53,
- 0x4b, 0xb4, 0xa1, 0x9b, 0x3a, 0x78, 0x11, 0x74, 0x2f, 0x49, 0xf5, 0x0f},
- 64, 512, PSA_SUCCESS
+{
+ .test_desc = "Test psa_asymmetric_sign - ECDSA SECP256R1 SHA-256\n",
+ .type = PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP256R1),
+ .data = ec_keypair,
+ .data_length = 32,
+ .usage_flags = PSA_KEY_USAGE_SIGN,
+ .alg = PSA_ALG_DETERMINISTIC_ECDSA(PSA_ALG_SHA_256),
+ .hash = sha_256_hash,
+ .hash_length = 32,
+ .signature = expected_output,
+ .signature_size = BUFFER_SIZE,
+ .expected_signature = signature_3,
+ .expected_signature_length = 64,
+ .expected_status = PSA_SUCCESS,
},
#endif
#endif
#ifdef ARCH_TEST_RSA_1024
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN
-{"Test psa_asymmetric_sign - Invalid key type (RSA public key)\n",
-PSA_KEY_TYPE_RSA_PUBLIC_KEY,
-{0}, 162, PSA_KEY_USAGE_SIGN, PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}, 32, 128,
-{0xa7, 0x36, 0x64, 0xd5, 0x5b, 0x39, 0xc7, 0xea, 0x6c, 0x1e, 0x5b, 0x50, 0x11,
- 0x72, 0x4a, 0x11, 0xe1, 0xd7, 0x07, 0x3d, 0x3a, 0x68, 0xf4, 0x8c, 0x83, 0x6f,
- 0xad, 0x15, 0x3a, 0x1d, 0x91, 0xb6, 0xab, 0xdb, 0xc8, 0xf6, 0x9d, 0xa1, 0x3b,
- 0x20, 0x6c, 0xc9, 0x6a, 0xf6, 0x36, 0x3b, 0x11, 0x44, 0x58, 0xb0, 0x26, 0xaf,
- 0x14, 0xb2, 0x4f, 0xab, 0x89, 0x29, 0xed, 0x63, 0x4c, 0x6a, 0x2a, 0xca, 0xce,
- 0x0b, 0xcc, 0x62, 0xd9, 0xbb, 0x6a, 0x98, 0x4a, 0xfb, 0xcb, 0xfc, 0xd3, 0xa0,
- 0x60, 0x8d, 0x32, 0xa2, 0xba, 0xe5, 0x35, 0xb9, 0xcd, 0x1e, 0xcd, 0xf9, 0xdd,
- 0x28, 0x1d, 0xb1, 0xe0, 0x02, 0x5c, 0x3b, 0xfb, 0x55, 0x12, 0x96, 0x3e, 0xc3,
- 0xb9, 0x8d, 0xda, 0xa6, 0x9e, 0x38, 0xbc, 0x3c, 0x84, 0xb1, 0xb6, 0x1a, 0x04,
- 0xe5, 0x64, 0x86, 0x40, 0x85, 0x6a, 0xac, 0xc6, 0xfc, 0x73, 0x11},
- 128, 1024, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_asymmetric_sign - Invalid key type (RSA public key)\n",
+ .type = PSA_KEY_TYPE_RSA_PUBLIC_KEY,
+ .data = rsa_128_key_data,
+ .data_length = 162,
+ .usage_flags = PSA_KEY_USAGE_SIGN,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
+ .hash = NULL,
+ .hash_length = 0,
+ .signature = expected_output,
+ .signature_size = 128,
+ .expected_signature = NULL,
+ .expected_signature_length = 0,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT,
},
-{"Test psa_asymmetric_sign - Small output buffer\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_SIGN, PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}, 32, 120,
-{0xa7, 0x36, 0x64, 0xd5, 0x5b, 0x39, 0xc7, 0xea, 0x6c, 0x1e, 0x5b, 0x50, 0x11,
- 0x72, 0x4a, 0x11, 0xe1, 0xd7, 0x07, 0x3d, 0x3a, 0x68, 0xf4, 0x8c, 0x83, 0x6f,
- 0xad, 0x15, 0x3a, 0x1d, 0x91, 0xb6, 0xab, 0xdb, 0xc8, 0xf6, 0x9d, 0xa1, 0x3b,
- 0x20, 0x6c, 0xc9, 0x6a, 0xf6, 0x36, 0x3b, 0x11, 0x44, 0x58, 0xb0, 0x26, 0xaf,
- 0x14, 0xb2, 0x4f, 0xab, 0x89, 0x29, 0xed, 0x63, 0x4c, 0x6a, 0x2a, 0xca, 0xce,
- 0x0b, 0xcc, 0x62, 0xd9, 0xbb, 0x6a, 0x98, 0x4a, 0xfb, 0xcb, 0xfc, 0xd3, 0xa0,
- 0x60, 0x8d, 0x32, 0xa2, 0xba, 0xe5, 0x35, 0xb9, 0xcd, 0x1e, 0xcd, 0xf9, 0xdd,
- 0x28, 0x1d, 0xb1, 0xe0, 0x02, 0x5c, 0x3b, 0xfb, 0x55, 0x12, 0x96, 0x3e, 0xc3,
- 0xb9, 0x8d, 0xda, 0xa6, 0x9e, 0x38, 0xbc, 0x3c, 0x84, 0xb1, 0xb6, 0x1a, 0x04,
- 0xe5, 0x64, 0x86, 0x40, 0x85, 0x6a, 0xac, 0xc6, 0xfc, 0x73, 0x11},
- 128, 1024, PSA_ERROR_BUFFER_TOO_SMALL
+{
+ .test_desc = "Test psa_asymmetric_sign - Small output buffer\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_SIGN,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
+ .hash = sha_256_hash,
+ .hash_length = 32,
+ .signature = expected_output,
+ .signature_size = 127,
+ .expected_signature = signature_1,
+ .expected_signature_length = 128,
+ .expected_status = PSA_ERROR_BUFFER_TOO_SMALL,
},
#endif
-{"Test psa_asymmetric_sign - Invalid algorithm\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_SIGN, PSA_ALG_SHA_256,
-{0x61, 0x62, 0x63}, 3, 128,
-{0x2c, 0x77, 0x44, 0x98, 0x3f, 0x02, 0x3a, 0xc7, 0xbb, 0x1c, 0x55, 0x52, 0x9d,
- 0x83, 0xed, 0x11, 0xa7, 0x6a, 0x78, 0x98, 0xa1, 0xbb, 0x5c, 0xe1, 0x91, 0x37,
- 0x5a, 0x4a, 0xa7, 0x49, 0x5a, 0x63, 0x3d, 0x27, 0x87, 0x9f, 0xf5, 0x8e, 0xba,
- 0x5a, 0x57, 0x37, 0x1c, 0x34, 0xfe, 0xb1, 0x18, 0x0e, 0x8b, 0x85, 0x0d, 0x55,
- 0x24, 0x76, 0xeb, 0xb5, 0x63, 0x4d, 0xf6, 0x20, 0x26, 0x19, 0x92, 0xf1, 0x2e,
- 0xbe, 0xe9, 0x09, 0x70, 0x41, 0xdb, 0xbe, 0xa8, 0x5a, 0x42, 0xd4, 0x5b, 0x34,
- 0x4b, 0xe5, 0x07, 0x3c, 0xeb, 0x77, 0x2f, 0xfc, 0x60, 0x49, 0x54, 0xb9, 0x15,
- 0x8b, 0xa8, 0x1e, 0xc3, 0xdc, 0x4d, 0x9d, 0x65, 0xe3, 0xab, 0x7a, 0xa3, 0x18,
- 0x16, 0x5f, 0x38, 0xc3, 0x6f, 0x84, 0x1f, 0x1c, 0x69, 0xcb, 0x1c, 0xfa, 0x49,
- 0x4a, 0xa5, 0xcb, 0xb4, 0xd6, 0xc0, 0xef, 0xba, 0xfb, 0x04, 0x3a},
- 128, 1024, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_asymmetric_sign - Invalid algorithm\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_SIGN,
+ .alg = PSA_ALG_SHA_256,
+ .hash = NULL,
+ .hash_length = 0,
+ .signature = expected_output,
+ .signature_size = BUFFER_SIZE,
+ .expected_signature = NULL,
+ .expected_signature_length = 0,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT,
},
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN
#ifdef ARCH_TEST_AES_128
-{"Test psa_asymmetric_sign - Invalid key type (AES Key)\n", PSA_KEY_TYPE_AES,
-{0x30, 0x82, 0x02, 0x5e, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xaf, 0x05,
- 0x7d, 0x39, 0x6e}, AES_16B_KEY_SIZE, PSA_KEY_USAGE_SIGN,
- PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
-{0x61, 0x62, 0x63}, 3, 128,
-{0x2c, 0x77, 0x44, 0x98, 0x3f, 0x02, 0x3a, 0xc7, 0xbb, 0x1c, 0x55, 0x52, 0x9d,
- 0x83, 0xed, 0x11, 0xa7, 0x6a, 0x78, 0x98, 0xa1, 0xbb, 0x5c, 0xe1, 0x91, 0x37,
- 0x5a, 0x4a, 0xa7, 0x49, 0x5a, 0x63, 0x3d, 0x27, 0x87, 0x9f, 0xf5, 0x8e, 0xba,
- 0x5a, 0x57, 0x37, 0x1c, 0x34, 0xfe, 0xb1, 0x18, 0x0e, 0x8b, 0x85, 0x0d, 0x55,
- 0x24, 0x76, 0xeb, 0xb5, 0x63, 0x4d, 0xf6, 0x20, 0x26, 0x19, 0x92, 0xf1, 0x2e,
- 0xbe, 0xe9, 0x09, 0x70, 0x41, 0xdb, 0xbe, 0xa8, 0x5a, 0x42, 0xd4, 0x5b, 0x34,
- 0x4b, 0xe5, 0x07, 0x3c, 0xeb, 0x77, 0x2f, 0xfc, 0x60, 0x49, 0x54, 0xb9, 0x15,
- 0x8b, 0xa8, 0x1e, 0xc3, 0xdc, 0x4d, 0x9d, 0x65, 0xe3, 0xab, 0x7a, 0xa3, 0x18,
- 0x16, 0x5f, 0x38, 0xc3, 0x6f, 0x84, 0x1f, 0x1c, 0x69, 0xcb, 0x1c, 0xfa, 0x49,
- 0x4a, 0xa5, 0xcb, 0xb4, 0xd6, 0xc0, 0xef, 0xba, 0xfb, 0x04, 0x3a},
- 128, BYTES_TO_BITS(AES_16B_KEY_SIZE), PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_asymmetric_sign - Invalid key type (AES Key)\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_SIGN,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
+ .hash = NULL,
+ .hash_length = 0,
+ .signature = expected_output,
+ .signature_size = BUFFER_SIZE,
+ .expected_signature = NULL,
+ .expected_signature_length = 0,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT,
},
#endif
#endif
@@ -252,65 +170,41 @@
#ifdef ARCH_TEST_RSA_1024
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
-{"Test psa_asymmetric_sign - Invalid usage\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
-{0x61, 0x62, 0x63}, 3, 128,
-{0x2c, 0x77, 0x44, 0x98, 0x3f, 0x02, 0x3a, 0xc7, 0xbb, 0x1c, 0x55, 0x52, 0x9d,
- 0x83, 0xed, 0x11, 0xa7, 0x6a, 0x78, 0x98, 0xa1, 0xbb, 0x5c, 0xe1, 0x91, 0x37,
- 0x5a, 0x4a, 0xa7, 0x49, 0x5a, 0x63, 0x3d, 0x27, 0x87, 0x9f, 0xf5, 0x8e, 0xba,
- 0x5a, 0x57, 0x37, 0x1c, 0x34, 0xfe, 0xb1, 0x18, 0x0e, 0x8b, 0x85, 0x0d, 0x55,
- 0x24, 0x76, 0xeb, 0xb5, 0x63, 0x4d, 0xf6, 0x20, 0x26, 0x19, 0x92, 0xf1, 0x2e,
- 0xbe, 0xe9, 0x09, 0x70, 0x41, 0xdb, 0xbe, 0xa8, 0x5a, 0x42, 0xd4, 0x5b, 0x34,
- 0x4b, 0xe5, 0x07, 0x3c, 0xeb, 0x77, 0x2f, 0xfc, 0x60, 0x49, 0x54, 0xb9, 0x15,
- 0x8b, 0xa8, 0x1e, 0xc3, 0xdc, 0x4d, 0x9d, 0x65, 0xe3, 0xab, 0x7a, 0xa3, 0x18,
- 0x16, 0x5f, 0x38, 0xc3, 0x6f, 0x84, 0x1f, 0x1c, 0x69, 0xcb, 0x1c, 0xfa, 0x49,
- 0x4a, 0xa5, 0xcb, 0xb4, 0xd6, 0xc0, 0xef, 0xba, 0xfb, 0x04, 0x3a},
- 128, 1024, PSA_ERROR_NOT_PERMITTED
+{
+ .test_desc = "Test psa_asymmetric_sign - Invalid usage\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
+ .hash = NULL,
+ .hash_length = 0,
+ .signature = expected_output,
+ .signature_size = BUFFER_SIZE,
+ .expected_signature = NULL,
+ .expected_signature_length = 0,
+ .expected_status = PSA_ERROR_NOT_PERMITTED,
},
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN
#ifdef ARCH_TEST_SHA256
-{"Test psa_asymmetric_sign - Wrong hash size\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_SIGN, PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00}, 30, 128,
-{0xa7, 0x36, 0x64, 0xd5, 0x5b, 0x39, 0xc7, 0xea, 0x6c, 0x1e, 0x5b, 0x50, 0x11,
- 0x72, 0x4a, 0x11, 0xe1, 0xd7, 0x07, 0x3d, 0x3a, 0x68, 0xf4, 0x8c, 0x83, 0x6f,
- 0xad, 0x15, 0x3a, 0x1d, 0x91, 0xb6, 0xab, 0xdb, 0xc8, 0xf6, 0x9d, 0xa1, 0x3b,
- 0x20, 0x6c, 0xc9, 0x6a, 0xf6, 0x36, 0x3b, 0x11, 0x44, 0x58, 0xb0, 0x26, 0xaf,
- 0x14, 0xb2, 0x4f, 0xab, 0x89, 0x29, 0xed, 0x63, 0x4c, 0x6a, 0x2a, 0xca, 0xce,
- 0x0b, 0xcc, 0x62, 0xd9, 0xbb, 0x6a, 0x98, 0x4a, 0xfb, 0xcb, 0xfc, 0xd3, 0xa0,
- 0x60, 0x8d, 0x32, 0xa2, 0xba, 0xe5, 0x35, 0xb9, 0xcd, 0x1e, 0xcd, 0xf9, 0xdd,
- 0x28, 0x1d, 0xb1, 0xe0, 0x02, 0x5c, 0x3b, 0xfb, 0x55, 0x12, 0x96, 0x3e, 0xc3,
- 0xb9, 0x8d, 0xda, 0xa6, 0x9e, 0x38, 0xbc, 0x3c, 0x84, 0xb1, 0xb6, 0x1a, 0x04,
- 0xe5, 0x64, 0x86, 0x40, 0x85, 0x6a, 0xac, 0xc6, 0xfc, 0x73, 0x11},
- 128, 1024, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_asymmetric_sign - Wrong hash size\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_SIGN,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
+ .hash = sha_256_hash,
+ .hash_length = 31,
+ .signature = expected_output,
+ .signature_size = BUFFER_SIZE,
+ .expected_signature = NULL,
+ .expected_signature_length = 0,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT,
},
#endif
#endif
#endif
};
-
-static const test_data check2[] = {
-#ifdef ARCH_TEST_RSA_1024
-#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
-{"Test psa_asymmetric_sign - Negative case\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_SIGN, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
-{0x61, 0x62, 0x63}, 3, 128,
-{0x2c, 0x77, 0x44, 0x98, 0x3f, 0x02, 0x3a, 0xc7, 0xbb, 0x1c, 0x55, 0x52, 0x9d,
- 0x83, 0xed, 0x11, 0xa7, 0x6a, 0x78, 0x98, 0xa1, 0xbb, 0x5c, 0xe1, 0x91, 0x37,
- 0x5a, 0x4a, 0xa7, 0x49, 0x5a, 0x63, 0x3d, 0x27, 0x87, 0x9f, 0xf5, 0x8e, 0xba,
- 0x5a, 0x57, 0x37, 0x1c, 0x34, 0xfe, 0xb1, 0x18, 0x0e, 0x8b, 0x85, 0x0d, 0x55,
- 0x24, 0x76, 0xeb, 0xb5, 0x63, 0x4d, 0xf6, 0x20, 0x26, 0x19, 0x92, 0xf1, 0x2e,
- 0xbe, 0xe9, 0x09, 0x70, 0x41, 0xdb, 0xbe, 0xa8, 0x5a, 0x42, 0xd4, 0x5b, 0x34,
- 0x4b, 0xe5, 0x07, 0x3c, 0xeb, 0x77, 0x2f, 0xfc, 0x60, 0x49, 0x54, 0xb9, 0x15,
- 0x8b, 0xa8, 0x1e, 0xc3, 0xdc, 0x4d, 0x9d, 0x65, 0xe3, 0xab, 0x7a, 0xa3, 0x18,
- 0x16, 0x5f, 0x38, 0xc3, 0x6f, 0x84, 0x1f, 0x1c, 0x69, 0xcb, 0x1c, 0xfa, 0x49,
- 0x4a, 0xa5, 0xcb, 0xb4, 0xd6, 0xc0, 0xef, 0xba, 0xfb, 0x04, 0x3a},
- 128, 1024, PSA_SUCCESS
-},
-#endif
-#endif
-};
diff --git a/api-tests/dev_apis/crypto/test_c042/test_c042.c b/api-tests/dev_apis/crypto/test_c042/test_c042.c
index eae93d4..265681f 100644
--- a/api-tests/dev_apis/crypto/test_c042/test_c042.c
+++ b/api-tests/dev_apis/crypto/test_c042/test_c042.c
@@ -27,13 +27,14 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
+static int32_t valid_test_input_index = -1;
+
int32_t psa_asymmetric_verify_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
- const uint8_t *key_data;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_handle_t key_handle;
@@ -56,61 +57,32 @@
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- /* Set the key data based on key type */
- if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type))
- {
- if (check1[i].key_type == PSA_KEY_TYPE_RSA_KEY_PAIR)
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keypair;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keypair;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(128))
- key_data = rsa_128_keypair;
- else
- return VAL_STATUS_INVALID;
- }
- else
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keydata;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keydata;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(128))
- key_data = rsa_128_keydata;
- else
- return VAL_STATUS_INVALID;
- }
- }
- else if (PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
- {
- if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(check1[i].key_type))
- key_data = ec_keypair;
- else
- key_data = ec_keydata;
- }
- else
- key_data = check1[i].key_data;
-
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].key_alg);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &attributes, check1[i].alg);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage_flags);
/* Import the key data into the key slot */
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, key_data,
- check1[i].key_length, &key_handle);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Verify the signature a hash or short message using a public key */
- status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_VERIFY, key_handle,
- check1[i].key_alg, check1[i].input, check1[i].input_length,
- check1[i].signature, check1[i].signature_size);
+ status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_VERIFY,
+ key_handle,
+ check1[i].alg,
+ check1[i].hash,
+ check1[i].hash_length,
+ check1[i].signature,
+ check1[i].signature_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(4));
/* Destroy a key and restore the slot to its default state */
status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
+
+ if (valid_test_input_index < 0)
+ valid_test_input_index = i;
}
return VAL_STATUS_SUCCESS;
@@ -118,39 +90,44 @@
int32_t psa_asymmetric_verify_negative_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check2)/sizeof(check2[0]);
- int32_t i, status;
+ int32_t status;
psa_key_handle_t key_handle = 13;
+ if (valid_test_input_index < 0)
+ return RESULT_SKIP(VAL_STATUS_NO_TESTS);
+
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
- for (i = 0; i < num_checks; i++)
- {
- val->print(PRINT_TEST, "[Check %d] Test psa_asymmetric_verify - Invalid key handle\n",
- g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] Test psa_asymmetric_verify - Invalid key handle\n",
+ g_test_count++);
- /* Setting up the watchdog timer for each check */
- status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
- TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
+ /* Setting up the watchdog timer for each check */
+ status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
+ TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- /* Verify the signature a hash or short message using a public key */
- status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_VERIFY, key_handle,
- check2[i].key_alg, check2[i].input, check2[i].input_length,
- check2[i].signature, check2[i].signature_size);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(3));
+ /* Verify the signature a hash or short message using a public key */
+ status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_VERIFY,
+ key_handle,
+ check1[valid_test_input_index].alg,
+ check1[valid_test_input_index].hash,
+ check1[valid_test_input_index].hash_length,
+ check1[valid_test_input_index].signature,
+ check1[valid_test_input_index].signature_length);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(3));
- val->print(PRINT_TEST, "[Check %d] Test psa_asymmetric_verify - Zero as key handle\n",
- g_test_count++);
- /* Verify the signature a hash or short message using a public key */
- status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_VERIFY, 0,
- check2[i].key_alg, check2[i].input, check2[i].input_length,
- check2[i].signature, check2[i].signature_size);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(4));
-
- }
+ val->print(PRINT_TEST, "[Check %d] Test psa_asymmetric_verify - Zero as key handle\n",
+ g_test_count++);
+ /* Verify the signature a hash or short message using a public key */
+ status = val->crypto_function(VAL_CRYPTO_ASYMMTERIC_VERIFY,
+ 0,
+ check1[valid_test_input_index].alg,
+ check1[valid_test_input_index].hash,
+ check1[valid_test_input_index].hash_length,
+ check1[valid_test_input_index].signature,
+ check1[valid_test_input_index].signature_length);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(4));
return VAL_STATUS_SUCCESS;
}
-
diff --git a/api-tests/dev_apis/crypto/test_c042/test_data.h b/api-tests/dev_apis/crypto/test_c042/test_data.h
index 7ac5096..26c791e 100644
--- a/api-tests/dev_apis/crypto/test_c042/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c042/test_data.h
@@ -15,142 +15,54 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- psa_key_type_t key_type;
- uint8_t key_data[16];
- uint32_t key_length;
- psa_key_usage_t usage;
- psa_algorithm_t key_alg;
- uint8_t input[32];
- size_t input_length;
- uint8_t signature[128];
- size_t signature_size;
- size_t expected_bit_length;
+ psa_key_type_t type;
+ const uint8_t *data;
+ size_t data_length;
+ psa_key_usage_t usage_flags;
+ psa_algorithm_t alg;
+ const uint8_t *hash;
+ size_t hash_length;
+ const uint8_t *signature;
+ size_t signature_length;
psa_status_t expected_status;
} test_data;
-static const uint8_t rsa_384_keypair[1];
-static const uint8_t rsa_384_keydata[1];
-static const uint8_t rsa_256_keypair[1];
-static const uint8_t rsa_256_keydata[1];
-static const uint8_t ec_keydata[] = {
- 0x04, 0xde,
- 0xa5, 0xe4, 0x5d, 0x0e, 0xa3, 0x7f, 0xc5, 0x66, 0x23, 0x2a, 0x50, 0x8f, 0x4a, 0xd2,
- 0x0e, 0xa1, 0x3d, 0x47, 0xe4, 0xbf, 0x5f, 0xa4, 0xd5, 0x4a, 0x57, 0xa0, 0xba, 0x01,
- 0x20, 0x42, 0x08, 0x70, 0x97, 0x49, 0x6e, 0xfc, 0x58, 0x3f, 0xed, 0x8b, 0x24, 0xa5,
- 0xb9, 0xbe, 0x9a, 0x51, 0xde, 0x06, 0x3f, 0x5a, 0x00, 0xa8, 0xb6, 0x98, 0xa1, 0x6f,
- 0xd7, 0xf2, 0x9b, 0x54, 0x85, 0xf3, 0x20};
-
-static const uint8_t ec_keypair[] = {
- 0xab, 0x45, 0x43, 0x57, 0x12, 0x64,
- 0x9c, 0xb3, 0x0b, 0xbd, 0xda, 0xc4, 0x91, 0x97, 0xee, 0xbf, 0x27, 0x40, 0xff, 0xc7,
- 0xf8, 0x74, 0xd9, 0x24, 0x4c, 0x34, 0x60, 0xf5, 0x4f, 0x32, 0x2d, 0x3a};
-
-static const uint8_t rsa_128_keydata[] = {
- 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
- 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02,
- 0x81, 0x81, 0x00, 0xaf, 0x05, 0x7d, 0x39, 0x6e, 0xe8, 0x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73, 0x8a,
-0xae, 0x59, 0xbb, 0xfe, 0x1c, 0x99, 0x77, 0x81, 0x44, 0x7a, 0x2b, 0x24};
-
static const test_data check1[] = {
#ifdef ARCH_TEST_RSA_1024
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
-{"Test psa_asymmetric_verify - RSA KEY_PAIR PKCS1V15 RAW\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_VERIFY, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
-{0x61, 0x62, 0x63}, 3,
-{0x2c, 0x77, 0x44, 0x98, 0x3f, 0x02, 0x3a, 0xc7, 0xbb, 0x1c, 0x55, 0x52, 0x9d,
- 0x83, 0xed, 0x11, 0xa7, 0x6a, 0x78, 0x98, 0xa1, 0xbb, 0x5c, 0xe1, 0x91, 0x37,
- 0x5a, 0x4a, 0xa7, 0x49, 0x5a, 0x63, 0x3d, 0x27, 0x87, 0x9f, 0xf5, 0x8e, 0xba,
- 0x5a, 0x57, 0x37, 0x1c, 0x34, 0xfe, 0xb1, 0x18, 0x0e, 0x8b, 0x85, 0x0d, 0x55,
- 0x24, 0x76, 0xeb, 0xb5, 0x63, 0x4d, 0xf6, 0x20, 0x26, 0x19, 0x92, 0xf1, 0x2e,
- 0xbe, 0xe9, 0x09, 0x70, 0x41, 0xdb, 0xbe, 0xa8, 0x5a, 0x42, 0xd4, 0x5b, 0x34,
- 0x4b, 0xe5, 0x07, 0x3c, 0xeb, 0x77, 0x2f, 0xfc, 0x60, 0x49, 0x54, 0xb9, 0x15,
- 0x8b, 0xa8, 0x1e, 0xc3, 0xdc, 0x4d, 0x9d, 0x65, 0xe3, 0xab, 0x7a, 0xa3, 0x18,
- 0x16, 0x5f, 0x38, 0xc3, 0x6f, 0x84, 0x1f, 0x1c, 0x69, 0xcb, 0x1c, 0xfa, 0x49,
- 0x4a, 0xa5, 0xcb, 0xb4, 0xd6, 0xc0, 0xef, 0xba, 0xfb, 0x04, 0x3a},
- 128, 1024, PSA_SUCCESS
+{
+ .test_desc = "Test psa_asymmetric_verify - RSA KEY_PAIR PKCS1V15 RAW\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_VERIFY,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
+ .hash = sha_256_hash,
+ .hash_length = 32,
+ .signature = signature_1,
+ .signature_length = 128,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN
#ifdef ARCH_TEST_SHA256
-{"Test psa_asymmetric_verify - RSA KEY_PAIR PKCS1V15 SHA-256\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_VERIFY, PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}, 32,
-{0xa7, 0x36, 0x64, 0xd5, 0x5b, 0x39, 0xc7, 0xea, 0x6c, 0x1e, 0x5b, 0x50, 0x11,
- 0x72, 0x4a, 0x11, 0xe1, 0xd7, 0x07, 0x3d, 0x3a, 0x68, 0xf4, 0x8c, 0x83, 0x6f,
- 0xad, 0x15, 0x3a, 0x1d, 0x91, 0xb6, 0xab, 0xdb, 0xc8, 0xf6, 0x9d, 0xa1, 0x3b,
- 0x20, 0x6c, 0xc9, 0x6a, 0xf6, 0x36, 0x3b, 0x11, 0x44, 0x58, 0xb0, 0x26, 0xaf,
- 0x14, 0xb2, 0x4f, 0xab, 0x89, 0x29, 0xed, 0x63, 0x4c, 0x6a, 0x2a, 0xca, 0xce,
- 0x0b, 0xcc, 0x62, 0xd9, 0xbb, 0x6a, 0x98, 0x4a, 0xfb, 0xcb, 0xfc, 0xd3, 0xa0,
- 0x60, 0x8d, 0x32, 0xa2, 0xba, 0xe5, 0x35, 0xb9, 0xcd, 0x1e, 0xcd, 0xf9, 0xdd,
- 0x28, 0x1d, 0xb1, 0xe0, 0x02, 0x5c, 0x3b, 0xfb, 0x55, 0x12, 0x96, 0x3e, 0xc3,
- 0xb9, 0x8d, 0xda, 0xa6, 0x9e, 0x38, 0xbc, 0x3c, 0x84, 0xb1, 0xb6, 0x1a, 0x04,
- 0xe5, 0x64, 0x86, 0x40, 0x85, 0x6a, 0xac, 0xc6, 0xfc, 0x73, 0x11},
- 128, 1024, PSA_SUCCESS
+{
+ .test_desc = "Test psa_asymmetric_verify - RSA KEY_PAIR PKCS1V15 SHA-256\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_VERIFY,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
+ .hash = sha_256_hash,
+ .hash_length = 32,
+ .signature = signature_2,
+ .signature_length = 128,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
@@ -159,214 +71,162 @@
#ifdef ARCH_TEST_SHA256
#ifdef ARCH_TEST_DETERMINISTIC_ECDSA
#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
-{"Test psa_asymmetric_verify - ECDSA KEY_PAIR SECP256R1 SHA-256\n",
- PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP256R1), {0}, 32,
- PSA_KEY_USAGE_VERIFY, PSA_ALG_DETERMINISTIC_ECDSA(PSA_ALG_SHA_256),
-{0x9a, 0xc4, 0x33, 0x5b, 0x46, 0x9b, 0xbd, 0x79, 0x14, 0x39, 0x24, 0x85, 0x04,
- 0xdd, 0x0d, 0x49, 0xc7, 0x13, 0x49, 0xa2, 0x95, 0xfe, 0xe5, 0xa1, 0xc6, 0x85,
- 0x07, 0xf4, 0x5a, 0x9e, 0x1c, 0x7b}, 32,
-{0x6a, 0x33, 0x99, 0xf6, 0x94, 0x21, 0xff, 0xe1, 0x49, 0x03, 0x77, 0xad, 0xf2,
- 0xea, 0x1f, 0x11, 0x7d, 0x81, 0xa6, 0x3c, 0xf5, 0xbf, 0x22, 0xe9, 0x18, 0xd5,
- 0x11, 0x75, 0xeb, 0x25, 0x91, 0x51, 0xce, 0x95, 0xd7, 0xc2, 0x6c, 0xc0, 0x4e,
- 0x25, 0x50, 0x3e, 0x2f, 0x7a, 0x1e, 0xc3, 0x57, 0x3e, 0x3c, 0x24, 0x12, 0x53,
- 0x4b, 0xb4, 0xa1, 0x9b, 0x3a, 0x78, 0x11, 0x74, 0x2f, 0x49, 0xf5, 0x0f},
- 64, 512, PSA_SUCCESS
+{
+ .test_desc = "Test psa_asymmetric_verify - ECDSA KEY_PAIR SECP256R1 SHA-256\n",
+ .type = PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP256R1),
+ .data = ec_keypair,
+ .data_length = 32,
+ .usage_flags = PSA_KEY_USAGE_VERIFY,
+ .alg = PSA_ALG_DETERMINISTIC_ECDSA(PSA_ALG_SHA_256),
+ .hash = sha_256_hash,
+ .hash_length = 32,
+ .signature = signature_3,
+ .signature_length = 64,
+ .expected_status = PSA_SUCCESS
},
+
+{
+ .test_desc = "Test psa_asymmetric_verify - EC public key\n",
+ .type = PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
+ .data = ec_key_data,
+ .data_length = 65,
+ .usage_flags = PSA_KEY_USAGE_VERIFY,
+ .alg = PSA_ALG_DETERMINISTIC_ECDSA(PSA_ALG_SHA_256),
+ .hash = sha_256_hash,
+ .hash_length = 32,
+ .signature = signature_3,
+ .signature_length = 64,
+ .expected_status = PSA_SUCCESS
+},
+#endif
#endif
#endif
#ifdef ARCH_TEST_RSA_1024
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN
-{"Test psa_asymmetric_verify - RSA public key\n",
-PSA_KEY_TYPE_RSA_PUBLIC_KEY,
-{0}, 162, PSA_KEY_USAGE_VERIFY, PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}, 32,
-{0xa7, 0x36, 0x64, 0xd5, 0x5b, 0x39, 0xc7, 0xea, 0x6c, 0x1e, 0x5b, 0x50, 0x11,
- 0x72, 0x4a, 0x11, 0xe1, 0xd7, 0x07, 0x3d, 0x3a, 0x68, 0xf4, 0x8c, 0x83, 0x6f,
- 0xad, 0x15, 0x3a, 0x1d, 0x91, 0xb6, 0xab, 0xdb, 0xc8, 0xf6, 0x9d, 0xa1, 0x3b,
- 0x20, 0x6c, 0xc9, 0x6a, 0xf6, 0x36, 0x3b, 0x11, 0x44, 0x58, 0xb0, 0x26, 0xaf,
- 0x14, 0xb2, 0x4f, 0xab, 0x89, 0x29, 0xed, 0x63, 0x4c, 0x6a, 0x2a, 0xca, 0xce,
- 0x0b, 0xcc, 0x62, 0xd9, 0xbb, 0x6a, 0x98, 0x4a, 0xfb, 0xcb, 0xfc, 0xd3, 0xa0,
- 0x60, 0x8d, 0x32, 0xa2, 0xba, 0xe5, 0x35, 0xb9, 0xcd, 0x1e, 0xcd, 0xf9, 0xdd,
- 0x28, 0x1d, 0xb1, 0xe0, 0x02, 0x5c, 0x3b, 0xfb, 0x55, 0x12, 0x96, 0x3e, 0xc3,
- 0xb9, 0x8d, 0xda, 0xa6, 0x9e, 0x38, 0xbc, 0x3c, 0x84, 0xb1, 0xb6, 0x1a, 0x04,
- 0xe5, 0x64, 0x86, 0x40, 0x85, 0x6a, 0xac, 0xc6, 0xfc, 0x73, 0x11},
- 128, 1024, PSA_SUCCESS
+{
+ .test_desc = "Test psa_asymmetric_verify - RSA public key\n",
+ .type = PSA_KEY_TYPE_RSA_PUBLIC_KEY,
+ .data = rsa_128_key_data,
+ .data_length = 162,
+ .usage_flags = PSA_KEY_USAGE_VERIFY,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
+ .hash = sha_256_hash,
+ .hash_length = 32,
+ .signature = signature_2,
+ .signature_length = 128,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_asymmetric_verify - Small output buffer\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_VERIFY, PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}, 32,
-{0xa7, 0x36, 0x64, 0xd5, 0x5b, 0x39, 0xc7, 0xea, 0x6c, 0x1e, 0x5b, 0x50, 0x11,
- 0x72, 0x4a, 0x11, 0xe1, 0xd7, 0x07, 0x3d, 0x3a, 0x68, 0xf4, 0x8c, 0x83, 0x6f,
- 0xad, 0x15, 0x3a, 0x1d, 0x91, 0xb6, 0xab, 0xdb, 0xc8, 0xf6, 0x9d, 0xa1, 0x3b,
- 0x20, 0x6c, 0xc9, 0x6a, 0xf6, 0x36, 0x3b, 0x11, 0x44, 0x58, 0xb0, 0x26, 0xaf,
- 0x14, 0xb2, 0x4f, 0xab, 0x89, 0x29, 0xed, 0x63, 0x4c, 0x6a, 0x2a, 0xca, 0xce,
- 0x0b, 0xcc, 0x62, 0xd9, 0xbb, 0x6a, 0x98, 0x4a, 0xfb, 0xcb, 0xfc, 0xd3, 0xa0,
- 0x60, 0x8d, 0x32, 0xa2, 0xba, 0xe5, 0x35, 0xb9, 0xcd, 0x1e, 0xcd, 0xf9, 0xdd,
- 0x28, 0x1d, 0xb1, 0xe0, 0x02, 0x5c, 0x3b, 0xfb, 0x55, 0x12, 0x96, 0x3e, 0xc3,
- 0xb9, 0x8d, 0xda, 0xa6, 0x9e, 0x38, 0xbc, 0x3c, 0x84, 0xb1, 0xb6, 0x1a, 0x04,
- 0xe5, 0x64, 0x86, 0x40, 0x85, 0x6a, 0xac, 0xc6, 0xfc, 0x73, 0x11},
- 120, 1024, PSA_ERROR_INVALID_SIGNATURE
+{
+ .test_desc = "Test psa_asymmetric_verify - Small output buffer\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_VERIFY,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
+ .hash = sha_256_hash,
+ .hash_length = 32,
+ .signature = signature_2,
+ .signature_length = 127,
+ .expected_status = PSA_ERROR_INVALID_SIGNATURE
},
#endif
-{"Test psa_asymmetric_verify - Invalid algorithm\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_VERIFY, PSA_ALG_SHA_256,
-{0x61, 0x62, 0x63}, 3,
-{0x2c, 0x77, 0x44, 0x98, 0x3f, 0x02, 0x3a, 0xc7, 0xbb, 0x1c, 0x55, 0x52, 0x9d,
- 0x83, 0xed, 0x11, 0xa7, 0x6a, 0x78, 0x98, 0xa1, 0xbb, 0x5c, 0xe1, 0x91, 0x37,
- 0x5a, 0x4a, 0xa7, 0x49, 0x5a, 0x63, 0x3d, 0x27, 0x87, 0x9f, 0xf5, 0x8e, 0xba,
- 0x5a, 0x57, 0x37, 0x1c, 0x34, 0xfe, 0xb1, 0x18, 0x0e, 0x8b, 0x85, 0x0d, 0x55,
- 0x24, 0x76, 0xeb, 0xb5, 0x63, 0x4d, 0xf6, 0x20, 0x26, 0x19, 0x92, 0xf1, 0x2e,
- 0xbe, 0xe9, 0x09, 0x70, 0x41, 0xdb, 0xbe, 0xa8, 0x5a, 0x42, 0xd4, 0x5b, 0x34,
- 0x4b, 0xe5, 0x07, 0x3c, 0xeb, 0x77, 0x2f, 0xfc, 0x60, 0x49, 0x54, 0xb9, 0x15,
- 0x8b, 0xa8, 0x1e, 0xc3, 0xdc, 0x4d, 0x9d, 0x65, 0xe3, 0xab, 0x7a, 0xa3, 0x18,
- 0x16, 0x5f, 0x38, 0xc3, 0x6f, 0x84, 0x1f, 0x1c, 0x69, 0xcb, 0x1c, 0xfa, 0x49,
- 0x4a, 0xa5, 0xcb, 0xb4, 0xd6, 0xc0, 0xef, 0xba, 0xfb, 0x04, 0x3a},
- 128, 1024, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_asymmetric_verify - Invalid algorithm\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_VERIFY,
+ .alg = PSA_ALG_SHA_256,
+ .hash = sha_256_hash,
+ .hash_length = 32,
+ .signature = signature_2,
+ .signature_length = 128,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN
#ifdef ARCH_TEST_AES_128
-{"Test psa_asymmetric_verify - Invalid key type (AES Key)\n", PSA_KEY_TYPE_AES,
-{0x30, 0x82, 0x02, 0x5e, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xaf, 0x05,
- 0x7d, 0x39, 0x6e}, AES_16B_KEY_SIZE, PSA_KEY_USAGE_VERIFY,
- PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
-{0x61, 0x62, 0x63}, 3,
-{0x2c, 0x77, 0x44, 0x98, 0x3f, 0x02, 0x3a, 0xc7, 0xbb, 0x1c, 0x55, 0x52, 0x9d,
- 0x83, 0xed, 0x11, 0xa7, 0x6a, 0x78, 0x98, 0xa1, 0xbb, 0x5c, 0xe1, 0x91, 0x37,
- 0x5a, 0x4a, 0xa7, 0x49, 0x5a, 0x63, 0x3d, 0x27, 0x87, 0x9f, 0xf5, 0x8e, 0xba,
- 0x5a, 0x57, 0x37, 0x1c, 0x34, 0xfe, 0xb1, 0x18, 0x0e, 0x8b, 0x85, 0x0d, 0x55,
- 0x24, 0x76, 0xeb, 0xb5, 0x63, 0x4d, 0xf6, 0x20, 0x26, 0x19, 0x92, 0xf1, 0x2e,
- 0xbe, 0xe9, 0x09, 0x70, 0x41, 0xdb, 0xbe, 0xa8, 0x5a, 0x42, 0xd4, 0x5b, 0x34,
- 0x4b, 0xe5, 0x07, 0x3c, 0xeb, 0x77, 0x2f, 0xfc, 0x60, 0x49, 0x54, 0xb9, 0x15,
- 0x8b, 0xa8, 0x1e, 0xc3, 0xdc, 0x4d, 0x9d, 0x65, 0xe3, 0xab, 0x7a, 0xa3, 0x18,
- 0x16, 0x5f, 0x38, 0xc3, 0x6f, 0x84, 0x1f, 0x1c, 0x69, 0xcb, 0x1c, 0xfa, 0x49,
- 0x4a, 0xa5, 0xcb, 0xb4, 0xd6, 0xc0, 0xef, 0xba, 0xfb, 0x04, 0x3a},
- 128, BYTES_TO_BITS(AES_16B_KEY_SIZE), PSA_ERROR_NOT_SUPPORTED
+{
+ .test_desc = "Test psa_asymmetric_verify - Invalid key type (AES Key)\n",
+ .type = PSA_KEY_TYPE_AES,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .usage_flags = PSA_KEY_USAGE_VERIFY,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
+ .hash = sha_256_hash,
+ .hash_length = 32,
+ .signature = signature_2,
+ .signature_length = 128,
+ .expected_status = PSA_ERROR_NOT_SUPPORTED
},
#endif
#endif
-#endif
#ifdef ARCH_TEST_RSA_1024
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
-{"Test psa_asymmetric_verify - Invalid usage\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
-{0x61, 0x62, 0x63}, 3,
-{0x2c, 0x77, 0x44, 0x98, 0x3f, 0x02, 0x3a, 0xc7, 0xbb, 0x1c, 0x55, 0x52, 0x9d,
- 0x83, 0xed, 0x11, 0xa7, 0x6a, 0x78, 0x98, 0xa1, 0xbb, 0x5c, 0xe1, 0x91, 0x37,
- 0x5a, 0x4a, 0xa7, 0x49, 0x5a, 0x63, 0x3d, 0x27, 0x87, 0x9f, 0xf5, 0x8e, 0xba,
- 0x5a, 0x57, 0x37, 0x1c, 0x34, 0xfe, 0xb1, 0x18, 0x0e, 0x8b, 0x85, 0x0d, 0x55,
- 0x24, 0x76, 0xeb, 0xb5, 0x63, 0x4d, 0xf6, 0x20, 0x26, 0x19, 0x92, 0xf1, 0x2e,
- 0xbe, 0xe9, 0x09, 0x70, 0x41, 0xdb, 0xbe, 0xa8, 0x5a, 0x42, 0xd4, 0x5b, 0x34,
- 0x4b, 0xe5, 0x07, 0x3c, 0xeb, 0x77, 0x2f, 0xfc, 0x60, 0x49, 0x54, 0xb9, 0x15,
- 0x8b, 0xa8, 0x1e, 0xc3, 0xdc, 0x4d, 0x9d, 0x65, 0xe3, 0xab, 0x7a, 0xa3, 0x18,
- 0x16, 0x5f, 0x38, 0xc3, 0x6f, 0x84, 0x1f, 0x1c, 0x69, 0xcb, 0x1c, 0xfa, 0x49,
- 0x4a, 0xa5, 0xcb, 0xb4, 0xd6, 0xc0, 0xef, 0xba, 0xfb, 0x04, 0x3a},
- 128, 1024, PSA_ERROR_NOT_PERMITTED
+{
+ .test_desc = "Test psa_asymmetric_verify - Invalid usage\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_ENCRYPT,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
+ .hash = sha_256_hash,
+ .hash_length = 32,
+ .signature = signature_2,
+ .signature_length = 128,
+ .expected_status = PSA_ERROR_NOT_PERMITTED
},
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN
#ifdef ARCH_TEST_SHA256
-{"Test psa_asymmetric_verify - Wrong hash size\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_VERIFY, PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00}, 30,
-{0xa7, 0x36, 0x64, 0xd5, 0x5b, 0x39, 0xc7, 0xea, 0x6c, 0x1e, 0x5b, 0x50, 0x11,
- 0x72, 0x4a, 0x11, 0xe1, 0xd7, 0x07, 0x3d, 0x3a, 0x68, 0xf4, 0x8c, 0x83, 0x6f,
- 0xad, 0x15, 0x3a, 0x1d, 0x91, 0xb6, 0xab, 0xdb, 0xc8, 0xf6, 0x9d, 0xa1, 0x3b,
- 0x20, 0x6c, 0xc9, 0x6a, 0xf6, 0x36, 0x3b, 0x11, 0x44, 0x58, 0xb0, 0x26, 0xaf,
- 0x14, 0xb2, 0x4f, 0xab, 0x89, 0x29, 0xed, 0x63, 0x4c, 0x6a, 0x2a, 0xca, 0xce,
- 0x0b, 0xcc, 0x62, 0xd9, 0xbb, 0x6a, 0x98, 0x4a, 0xfb, 0xcb, 0xfc, 0xd3, 0xa0,
- 0x60, 0x8d, 0x32, 0xa2, 0xba, 0xe5, 0x35, 0xb9, 0xcd, 0x1e, 0xcd, 0xf9, 0xdd,
- 0x28, 0x1d, 0xb1, 0xe0, 0x02, 0x5c, 0x3b, 0xfb, 0x55, 0x12, 0x96, 0x3e, 0xc3,
- 0xb9, 0x8d, 0xda, 0xa6, 0x9e, 0x38, 0xbc, 0x3c, 0x84, 0xb1, 0xb6, 0x1a, 0x04,
- 0xe5, 0x64, 0x86, 0x40, 0x85, 0x6a, 0xac, 0xc6, 0xfc, 0x73, 0x11},
- 128, 1024, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_asymmetric_verify - Wrong hash size\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_VERIFY,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
+ .hash = sha_256_hash,
+ .hash_length = 31,
+ .signature = signature_2,
+ .signature_length = 128,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
-{"Test psa_asymmetric_verify - Wrong signature\n",
-PSA_KEY_TYPE_RSA_PUBLIC_KEY,
-{0}, 162, PSA_KEY_USAGE_VERIFY, PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
-{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d,
- 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10,
- 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}, 32,
-{0xa8, 0x36, 0x64, 0xd5, 0x5b, 0x39, 0xc7, 0xea, 0x6c, 0x1e, 0x5b, 0x50, 0x11,
- 0x72, 0x4a, 0x11, 0xe1, 0xd7, 0x07, 0x3d, 0x3a, 0x68, 0xf4, 0x8c, 0x83, 0x6f,
- 0xad, 0x15, 0x3a, 0x1d, 0x91, 0xb6, 0xab, 0xdb, 0xc8, 0xf6, 0x9d, 0xa1, 0x3b,
- 0x20, 0x6c, 0xc9, 0x6a, 0xf6, 0x36, 0x3b, 0x11, 0x44, 0x58, 0xb0, 0x26, 0xaf,
- 0x14, 0xb2, 0x4f, 0xab, 0x89, 0x29, 0xed, 0x63, 0x4c, 0x6a, 0x2a, 0xca, 0xce,
- 0x0b, 0xcc, 0x62, 0xd9, 0xbb, 0x6a, 0x98, 0x4a, 0xfb, 0xcb, 0xfc, 0xd3, 0xa0,
- 0x60, 0x8d, 0x32, 0xa2, 0xba, 0xe5, 0x35, 0xb9, 0xcd, 0x1e, 0xcd, 0xf9, 0xdd,
- 0x28, 0x1d, 0xb1, 0xe0, 0x02, 0x5c, 0x3b, 0xfb, 0x55, 0x12, 0x96, 0x3e, 0xc3,
- 0xb9, 0x8d, 0xda, 0xa6, 0x9e, 0x38, 0xbc, 0x3c, 0x84, 0xb1, 0xb6, 0x1a, 0x04,
- 0xe5, 0x64, 0x86, 0x40, 0x85, 0x6a, 0xac, 0xc6, 0xfc, 0x73, 0x11},
- 128, 1024, PSA_ERROR_INVALID_SIGNATURE
-},
-#endif
-#endif
-#endif
-
-#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
-#ifdef ARCH_TEST_ECDSA
-{"Test psa_asymmetric_verify - EC public key\n",
- PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
-{0}, 65, PSA_KEY_USAGE_VERIFY, PSA_ALG_ECDSA_ANY,
-{0x9a, 0xc4, 0x33, 0x5b, 0x46, 0x9b, 0xbd, 0x79, 0x14, 0x39, 0x24, 0x85, 0x04,
- 0xdd, 0x0d, 0x49, 0xc7, 0x13, 0x49, 0xa2, 0x95, 0xfe, 0xe5, 0xa1, 0xc6, 0x85,
- 0x07, 0xf4, 0x5a, 0x9e, 0x1c, 0x7b}, 32,
-{0x6a, 0x33, 0x99, 0xf6, 0x94, 0x21, 0xff, 0xe1, 0x49, 0x03, 0x77, 0xad, 0xf2,
- 0xea, 0x1f, 0x11, 0x7d, 0x81, 0xa6, 0x3c, 0xf5, 0xbf, 0x22, 0xe9, 0x18, 0xd5,
- 0x11, 0x75, 0xeb, 0x25, 0x91, 0x51, 0xce, 0x95, 0xd7, 0xc2, 0x6c, 0xc0, 0x4e,
- 0x25, 0x50, 0x3e, 0x2f, 0x7a, 0x1e, 0xc3, 0x57, 0x3e, 0x3c, 0x24, 0x12, 0x53,
- 0x4b, 0xb4, 0xa1, 0x9b, 0x3a, 0x78, 0x11, 0x74, 0x2f, 0x49, 0xf5, 0x0f},
- 64, 512, PSA_SUCCESS
+{
+ .test_desc = "Test psa_asymmetric_verify - Wrong signature\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_VERIFY,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
+ .hash = sha_256_hash,
+ .hash_length = 32,
+ .signature = signature_2_invalid,
+ .signature_length = 128,
+ .expected_status = PSA_ERROR_INVALID_SIGNATURE
},
-{"Test psa_asymmetric_verify - Wrong signature size\n",
- PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
-{0}, 65, PSA_KEY_USAGE_VERIFY, PSA_ALG_ECDSA_ANY,
-{0x9a, 0xc4, 0x33, 0x5b, 0x46, 0x9b, 0xbd, 0x79, 0x14, 0x39, 0x24, 0x85, 0x04,
- 0xdd, 0x0d, 0x49, 0xc7, 0x13, 0x49, 0xa2, 0x95, 0xfe, 0xe5, 0xa1, 0xc6, 0x85,
- 0x07, 0xf4, 0x5a, 0x9e, 0x1c, 0x7b}, 32,
-{0x6a, 0x33, 0x99, 0xf6, 0x94, 0x21, 0xff, 0xe1, 0x49, 0x03, 0x77, 0xad, 0xf2,
- 0xea, 0x1f, 0x11, 0x7d, 0x81, 0xa6, 0x3c, 0xf5, 0xbf, 0x22, 0xe9, 0x18, 0xd5,
- 0x11, 0x75, 0xeb, 0x25, 0x91, 0x51, 0xce, 0x95, 0xd7, 0xc2, 0x6c, 0xc0, 0x4e,
- 0x25, 0x50, 0x3e, 0x2f, 0x7a, 0x1e, 0xc3, 0x57, 0x3e, 0x3c, 0x24, 0x12, 0x53,
- 0x4b, 0xb4, 0xa1, 0x9b, 0x3a, 0x78, 0x11, 0x74, 0x2f, 0x49, 0xf5, 0x0f, 0x00},
- 65, 512, PSA_ERROR_INVALID_SIGNATURE
+{
+ .test_desc = "Test psa_asymmetric_verify - Wrong signature size\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .data = rsa_128_key_pair,
+ .data_length = 610,
+ .usage_flags = PSA_KEY_USAGE_VERIFY,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256),
+ .hash = sha_256_hash,
+ .hash_length = 32,
+ .signature = signature_2,
+ .signature_length = 129,
+ .expected_status = PSA_ERROR_INVALID_SIGNATURE
},
#endif
#endif
-};
-
-static const test_data check2[] = {
-#ifdef ARCH_TEST_RSA_1024
-#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
-{"Test psa_asymmetric_verify - Negative case\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
-{0}, 610, PSA_KEY_USAGE_VERIFY, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
-{0x61, 0x62, 0x63}, 3,
-{0x2c, 0x77, 0x44, 0x98, 0x3f, 0x02, 0x3a, 0xc7, 0xbb, 0x1c, 0x55, 0x52, 0x9d,
- 0x83, 0xed, 0x11, 0xa7, 0x6a, 0x78, 0x98, 0xa1, 0xbb, 0x5c, 0xe1, 0x91, 0x37,
- 0x5a, 0x4a, 0xa7, 0x49, 0x5a, 0x63, 0x3d, 0x27, 0x87, 0x9f, 0xf5, 0x8e, 0xba,
- 0x5a, 0x57, 0x37, 0x1c, 0x34, 0xfe, 0xb1, 0x18, 0x0e, 0x8b, 0x85, 0x0d, 0x55,
- 0x24, 0x76, 0xeb, 0xb5, 0x63, 0x4d, 0xf6, 0x20, 0x26, 0x19, 0x92, 0xf1, 0x2e,
- 0xbe, 0xe9, 0x09, 0x70, 0x41, 0xdb, 0xbe, 0xa8, 0x5a, 0x42, 0xd4, 0x5b, 0x34,
- 0x4b, 0xe5, 0x07, 0x3c, 0xeb, 0x77, 0x2f, 0xfc, 0x60, 0x49, 0x54, 0xb9, 0x15,
- 0x8b, 0xa8, 0x1e, 0xc3, 0xdc, 0x4d, 0x9d, 0x65, 0xe3, 0xab, 0x7a, 0xa3, 0x18,
- 0x16, 0x5f, 0x38, 0xc3, 0x6f, 0x84, 0x1f, 0x1c, 0x69, 0xcb, 0x1c, 0xfa, 0x49,
- 0x4a, 0xa5, 0xcb, 0xb4, 0xd6, 0xc0, 0xef, 0xba, 0xfb, 0x04, 0x3a},
- 128, 1024, PSA_SUCCESS
-},
-#endif
#endif
};
diff --git a/api-tests/dev_apis/crypto/test_c043/test_c043.c b/api-tests/dev_apis/crypto/test_c043/test_c043.c
index 8f1c4ea..addc847 100644
--- a/api-tests/dev_apis/crypto/test_c043/test_c043.c
+++ b/api-tests/dev_apis/crypto/test_c043/test_c043.c
@@ -27,7 +27,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
static uint8_t output[SIZE_50B];
int32_t psa_raw_key_agreement_test(caller_security_t caller __UNUSED)
diff --git a/api-tests/dev_apis/crypto/test_c044/test_c044.c b/api-tests/dev_apis/crypto/test_c044/test_c044.c
index 7b5bc77..aae201c 100644
--- a/api-tests/dev_apis/crypto/test_c044/test_c044.c
+++ b/api-tests/dev_apis/crypto/test_c044/test_c044.c
@@ -19,7 +19,6 @@
#include "val_target.h"
#include "test_c044.h"
#include "test_data.h"
-#include "val_crypto.h"
const client_test_t test_c044_crypto_list[] = {
NULL,
@@ -27,23 +26,19 @@
NULL,
};
-static int g_test_count = 1;
-static uint8_t data[BUFFER_SIZE];
-
int32_t psa_copy_key_test(caller_security_t caller __UNUSED)
{
- uint32_t length;
- const uint8_t *key_data;
- psa_key_handle_t target_handle = 0;
- psa_key_usage_t get_key_usage_flags;
- psa_algorithm_t get_key_algorithm;
- size_t get_key_bits;
- psa_key_type_t get_key_type;
- int i, num_checks = sizeof(check1)/sizeof(check1[0]);
+ size_t get_data_length;
+ psa_key_usage_t get_usage_flags;
+ psa_algorithm_t get_alg;
+ size_t get_bits;
+ psa_key_type_t get_type;
+ int32_t i, num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t status, export_status;
psa_key_attributes_t source_attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t target_attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_handle_t key_handle;
+ psa_key_handle_t target_key_handle = 0;
if (num_checks == 0)
{
@@ -58,66 +53,41 @@
/* Set the key data buffer to the input base on algorithm */
for (i = 0; i < num_checks; i++)
{
- val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
+ val->print(PRINT_TEST, "[Check %d] ", i+1);
val->print(PRINT_TEST, check1[i].test_desc, 0);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
-
- if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type))
- {
- if (check1[i].key_type == PSA_KEY_TYPE_RSA_KEY_PAIR)
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keypair;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keypair;
- else
- return VAL_STATUS_INVALID;
- }
- else
- {
- if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
- key_data = rsa_384_keydata;
- else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
- key_data = rsa_256_keydata;
- else
- return VAL_STATUS_INVALID;
- }
- }
- else if (PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
- {
- if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(check1[i].key_type))
- key_data = ec_keypair;
- else
- key_data = ec_keydata;
- }
- else
- key_data = check1[i].key_data;
-
/* Setup the attributes for the key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &source_attributes, check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &source_attributes, check1[i].key_alg);
- val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &source_attributes, check1[i].usage);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &source_attributes, check1[i].type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &source_attributes, check1[i].alg);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &source_attributes,
+ check1[i].usage_flags);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_LIFETIME, &source_attributes,
+ check1[i].lifetime);
/* Import the key data into the key slot */
- status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &source_attributes, key_data,
- check1[i].key_length, &key_handle);
+ status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &source_attributes, check1[i].data,
+ check1[i].data_length, &key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Setup the attributes for the target key */
- val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &target_attributes,
- check1[i].key_type);
- val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &target_attributes,
- check1[i].target_key_alg);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE, &target_attributes,
+ check1[i].target_type);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM, &target_attributes,
+ check1[i].target_alg);
val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &target_attributes,
- check1[i].target_usage);
+ check1[i].target_usage_flags);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_LIFETIME, &target_attributes,
+ check1[i].target_lifetime);
+ val->crypto_function(VAL_CRYPTO_SET_KEY_BITS, &target_attributes,
+ check1[i].target_bits);
/* Make a copy of a key */
- status = val->crypto_function(VAL_CRYPTO_COPY_KEY, key_handle,
- &target_attributes, &target_handle);
+ status = val->crypto_function(VAL_CRYPTO_COPY_KEY, key_handle, &target_attributes,
+ &target_key_handle);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(4));
/* Destroy the source key */
@@ -133,62 +103,48 @@
}
/* Check if the target key attributes is as expected */
- status = val->crypto_function(VAL_CRYPTO_GET_KEY_ATTRIBUTES, target_handle,
- &target_attributes);
+ status = val->crypto_function(VAL_CRYPTO_GET_KEY_ATTRIBUTES, target_key_handle,
+ &target_attributes);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
- val->crypto_function(VAL_CRYPTO_GET_KEY_TYPE, &target_attributes, &get_key_type);
- TEST_ASSERT_EQUAL(get_key_type, check1[i].key_type, TEST_CHECKPOINT_NUM(7));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_TYPE, &target_attributes, &get_type);
+ TEST_ASSERT_EQUAL(get_type, check1[i].target_type, TEST_CHECKPOINT_NUM(7));
val->crypto_function(VAL_CRYPTO_GET_KEY_USAGE_FLAGS, &target_attributes,
- &get_key_usage_flags);
- TEST_ASSERT_EQUAL(get_key_usage_flags, check1[i].expected_usage, TEST_CHECKPOINT_NUM(8));
+ &get_usage_flags);
+ TEST_ASSERT_EQUAL(get_usage_flags, check1[i].expected_usage_flags, TEST_CHECKPOINT_NUM(8));
- val->crypto_function(VAL_CRYPTO_GET_KEY_ALGORITHM, &target_attributes, &get_key_algorithm);
- TEST_ASSERT_EQUAL(get_key_algorithm, check1[i].expected_key_alg, TEST_CHECKPOINT_NUM(9));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_ALGORITHM, &target_attributes, &get_alg);
+ TEST_ASSERT_EQUAL(get_alg, check1[i].target_alg, TEST_CHECKPOINT_NUM(9));
- val->crypto_function(VAL_CRYPTO_GET_KEY_BITS, &target_attributes, &get_key_bits);
- TEST_ASSERT_EQUAL(get_key_bits, check1[i].expected_bit_length, TEST_CHECKPOINT_NUM(10));
+ val->crypto_function(VAL_CRYPTO_GET_KEY_BITS, &target_attributes, &get_bits);
+ TEST_ASSERT_EQUAL(get_bits, check1[i].target_bits, TEST_CHECKPOINT_NUM(10));
/* Export a key in binary format */
- export_status = val->crypto_function(VAL_CRYPTO_EXPORT_KEY, target_handle, data,
- BUFFER_SIZE, &length);
+ export_status = val->crypto_function(VAL_CRYPTO_EXPORT_KEY, target_key_handle,
+ check1[i].expected_data, check1[i].expected_data_size,
+ &get_data_length);
- if (!(check1[i].expected_usage & PSA_KEY_USAGE_EXPORT))
- {
- export_status = PSA_ERROR_NOT_PERMITTED;
- }
- else
+ if (check1[i].expected_usage_flags & PSA_KEY_USAGE_EXPORT)
{
/* Check if the target key data is same as source data */
- export_status = PSA_SUCCESS;
- TEST_ASSERT_EQUAL(status, export_status, TEST_CHECKPOINT_NUM(11));
+ TEST_ASSERT_EQUAL(export_status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(11));
- TEST_ASSERT_EQUAL(length, check1[i].expected_key_length, TEST_CHECKPOINT_NUM(12));
+ TEST_ASSERT_EQUAL(get_data_length, check1[i].expected_data_length,
+ TEST_CHECKPOINT_NUM(12));
- if (PSA_KEY_TYPE_IS_UNSTRUCTURED(check1[i].key_type))
- {
- TEST_ASSERT_MEMCMP(data, check1[i].key_data, length, TEST_CHECKPOINT_NUM(13));
- }
- else if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type)
- || PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
- {
- TEST_ASSERT_MEMCMP(data, key_data, length, TEST_CHECKPOINT_NUM(14));
- }
- else
- {
- return VAL_STATUS_INVALID;
- }
+ TEST_ASSERT_MEMCMP(check1[i].data, check1[i].expected_data, get_data_length,
+ TEST_CHECKPOINT_NUM(13));
}
/* Destroy the target key */
- status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, target_handle);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(15));
+ status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, target_key_handle);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(14));
/* Copy on a destroyed source should be an error */
- status = val->crypto_function(VAL_CRYPTO_COPY_KEY, key_handle,
- &target_attributes, &target_handle);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(16));
+ status = val->crypto_function(VAL_CRYPTO_COPY_KEY, key_handle, &target_attributes,
+ &target_key_handle);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(14));
val->crypto_function(VAL_CRYPTO_RESET_KEY_ATTRIBUTES, &source_attributes);
val->crypto_function(VAL_CRYPTO_RESET_KEY_ATTRIBUTES, &target_attributes);
diff --git a/api-tests/dev_apis/crypto/test_c044/test_data.h b/api-tests/dev_apis/crypto/test_c044/test_data.h
index 0903eb6..20485ce 100644
--- a/api-tests/dev_apis/crypto/test_c044/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c044/test_data.h
@@ -15,338 +15,371 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[75];
- psa_key_type_t key_type;
- uint8_t key_data[34];
- uint32_t key_length;
- psa_key_usage_t usage;
- psa_key_usage_t target_usage;
- psa_key_usage_t expected_usage;
- psa_algorithm_t key_alg;
- psa_algorithm_t target_key_alg;
- psa_algorithm_t expected_key_alg;
- uint32_t expected_bit_length;
- uint32_t expected_key_length;
+ psa_key_type_t type;
+ psa_algorithm_t alg;
+ psa_key_usage_t usage_flags;
+ psa_key_lifetime_t lifetime;
+ const uint8_t *data;
+ size_t data_length;
+ psa_key_type_t target_type;
+ psa_algorithm_t target_alg;
+ psa_key_usage_t target_usage_flags;
+ psa_key_lifetime_t target_lifetime;
+ size_t target_bits;
+ psa_key_usage_t expected_usage_flags;
+ uint8_t *expected_data;
+ size_t expected_data_size;
+ size_t expected_data_length;
psa_status_t expected_status;
} test_data;
-static const uint8_t rsa_384_keypair[1];
-static const uint8_t rsa_384_keydata[1];
-
-static const uint8_t rsa_256_keypair[] = {
- 0x30, 0x82, 0x04, 0xA5, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xC0,
- 0x95, 0x08, 0xE1, 0x57, 0x41, 0xF2, 0x71, 0x6D, 0xB7, 0xD2, 0x45, 0x41, 0x27,
- 0x01, 0x65, 0xC6, 0x45, 0xAE, 0xF2, 0xBC, 0x24, 0x30, 0xB8, 0x95, 0xCE, 0x2F,
- 0x4E, 0xD6, 0xF6, 0x1C, 0x88, 0xBC, 0x7C, 0x9F, 0xFB, 0xA8, 0x67, 0x7F, 0xFE,
- 0x5C, 0x9C, 0x51, 0x75, 0xF7, 0x8A, 0xCA, 0x07, 0xE7, 0x35, 0x2F, 0x8F, 0xE1,
- 0xBD, 0x7B, 0xC0, 0x2F, 0x7C, 0xAB, 0x64, 0xA8, 0x17, 0xFC, 0xCA, 0x5D, 0x7B,
- 0xBA, 0xE0, 0x21, 0xE5, 0x72, 0x2E, 0x6F, 0x2E, 0x86, 0xD8, 0x95, 0x73, 0xDA,
- 0xAC, 0x1B, 0x53, 0xB9, 0x5F, 0x3F, 0xD7, 0x19, 0x0D, 0x25, 0x4F, 0xE1, 0x63,
- 0x63, 0x51, 0x8B, 0x0B, 0x64, 0x3F, 0xAD, 0x43, 0xB8, 0xA5, 0x1C, 0x5C, 0x34,
- 0xB3, 0xAE, 0x00, 0xA0, 0x63, 0xC5, 0xF6, 0x7F, 0x0B, 0x59, 0x68, 0x78, 0x73,
- 0xA6, 0x8C, 0x18, 0xA9, 0x02, 0x6D, 0xAF, 0xC3, 0x19, 0x01, 0x2E, 0xB8, 0x10,
- 0xE3, 0xC6, 0xCC, 0x40, 0xB4, 0x69, 0xA3, 0x46, 0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0xD5, 0x83, 0xD6,
- 0x9D, 0x98, 0x6B, 0x01, 0x3E, 0x81, 0xDC, 0x3C, 0x7A, 0xCA, 0xF9, 0xF3, 0x9C, 0xF7,
- 0xD6, 0x28, 0x1B, 0x27, 0x78, 0x7C, 0xC3, 0xD0, 0xD5, 0x63, 0xA7, 0x81, 0x34, 0x89,
- 0xAD, 0x25, 0x6A, 0xBD, 0xF2, 0xEA, 0xED, 0xFA, 0x57, 0xFC, 0xE5, 0x34, 0xC6, 0xC1,
- 0x0F, 0x71, 0x2D, 0xD2, 0x08, 0x10, 0x1B, 0xAD, 0x44, 0x41, 0xE0, 0xFE, 0x79, 0xA0,
- 0x63, 0x93, 0x8A, 0xB1, 0x5D, 0xE9, 0xB0, 0xEE, 0x6F, 0x02, 0x03, 0x01, 0x00, 0x01};
-
-static const uint8_t ec_keydata[] = {
- 0x04, 0xde, 0xa5, 0xe4, 0x5d, 0x0e, 0xa3, 0x7f, 0xc5, 0x66, 0x23, 0x2a, 0x50, 0x8f,
- 0x4a, 0xd2, 0x0e, 0xa1, 0x3d, 0x47, 0xe4, 0xbf, 0x5f, 0xa4, 0xd5, 0x4a, 0x57, 0xa0,
- 0xba, 0x01, 0x20, 0x42, 0x08, 0x70, 0x97, 0x49, 0x6e, 0xfc, 0x58, 0x3f, 0xed, 0x8b,
- 0x24, 0xa5, 0xb9, 0xbe, 0x9a, 0x51, 0xde, 0x06, 0x3f, 0x5a, 0x00, 0xa8, 0xb6, 0x98,
- 0xa1, 0x6f, 0xd7, 0xf2, 0x9b, 0x54, 0x85, 0xf3, 0x20};
-
-static const uint8_t ec_keypair[] = {
- 0x68, 0x49, 0xf9, 0x7d, 0x10, 0x66, 0xf6, 0x99, 0x77, 0x59, 0x63, 0x7c, 0x7e, 0x38,
- 0x99, 0x46, 0x4c, 0xee, 0x3e, 0xc7, 0xac, 0x97, 0x06, 0x53, 0xa0, 0xbe, 0x07, 0x42};
-
static const test_data check1[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
-{"Test psa_copy_key 16 Byte AES\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0x77},
- AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT, PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_ALG_CTR, PSA_ALG_CTR, PSA_ALG_CTR,
- BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_SUCCESS
+{
+ .test_desc = "Test psa_copy_key - 16 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .alg = PSA_ALG_CTR,
+ .usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .target_type = PSA_KEY_TYPE_AES,
+ .target_alg = PSA_ALG_CTR,
+ .target_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .target_lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .target_bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .expected_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .expected_data_size = BUFFER_SIZE,
+ .expected_data_length = AES_16B_KEY_SIZE,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_copy_key without copy usage\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0x77},
- AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_EXPORT, PSA_KEY_USAGE_EXPORT,
- PSA_KEY_USAGE_EXPORT,
- PSA_ALG_CTR, PSA_ALG_CTR, PSA_ALG_CTR,
- BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_ERROR_NOT_PERMITTED
+{
+ .test_desc = "Test psa_copy_key - without copy usage\n",
+ .type = PSA_KEY_TYPE_AES,
+ .alg = PSA_ALG_CTR,
+ .usage_flags = PSA_KEY_USAGE_EXPORT,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .target_type = PSA_KEY_TYPE_AES,
+ .target_alg = PSA_ALG_CTR,
+ .target_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .target_lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .target_bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .expected_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .expected_data_size = BUFFER_SIZE,
+ .expected_data_length = AES_16B_KEY_SIZE,
+ .expected_status = PSA_ERROR_NOT_PERMITTED
+},
+
+{
+ .test_desc = "Test psa_copy_key - invalid lifetime\n",
+ .type = PSA_KEY_TYPE_AES,
+ .alg = PSA_ALG_CTR,
+ .usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .target_type = PSA_KEY_TYPE_AES,
+ .target_alg = PSA_ALG_CTR,
+ .target_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .target_lifetime = PSA_KEY_LIFETIME_PERSISTENT,
+ .target_bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .expected_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .expected_data_size = BUFFER_SIZE,
+ .expected_data_length = AES_16B_KEY_SIZE,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
+},
+
+{
+ .test_desc = "Test psa_copy_key - invalid key type\n",
+ .type = PSA_KEY_TYPE_AES,
+ .alg = PSA_ALG_CTR,
+ .usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .target_type = PSA_KEY_TYPE_DES,
+ .target_alg = PSA_ALG_CTR,
+ .target_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .target_lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .target_bits = BYTES_TO_BITS(AES_16B_KEY_SIZE),
+ .expected_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .expected_data_size = BUFFER_SIZE,
+ .expected_data_length = AES_16B_KEY_SIZE,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
+},
+
+{
+ .test_desc = "Test psa_copy_key - invalid key bits\n",
+ .type = PSA_KEY_TYPE_AES,
+ .alg = PSA_ALG_CTR,
+ .usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .data = key_data,
+ .data_length = AES_16B_KEY_SIZE,
+ .target_type = PSA_KEY_TYPE_AES,
+ .target_alg = PSA_ALG_CTR,
+ .target_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .target_lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .target_bits = BYTES_TO_BITS(AES_16B_KEY_SIZE)-1,
+ .expected_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .expected_data_size = BUFFER_SIZE,
+ .expected_data_length = AES_16B_KEY_SIZE,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
#endif
#ifdef ARCH_TEST_AES_192
-{"Test psa_copy_key 24 Byte AES\n", PSA_KEY_TYPE_AES,
-{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
- 0x40, 0xAC, 0xA3, 0x90, 0x77, 0x83, 0x52, 0x31, 0x74, 0xF9, 0x05},
- AES_24B_KEY_SIZE,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_ENCRYPT,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_ENCRYPT,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_ENCRYPT,
- PSA_ALG_CTR, PSA_ALG_CTR, PSA_ALG_CTR,
- BYTES_TO_BITS(AES_24B_KEY_SIZE), AES_24B_KEY_SIZE, PSA_SUCCESS
+{
+ .test_desc = "Test psa_copy_key - 24 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .alg = PSA_ALG_CTR,
+ .usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_ENCRYPT,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .data = key_data,
+ .data_length = AES_24B_KEY_SIZE,
+ .target_type = PSA_KEY_TYPE_AES,
+ .target_alg = PSA_ALG_CTR,
+ .target_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_ENCRYPT,
+ .target_lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .target_bits = BYTES_TO_BITS(AES_24B_KEY_SIZE),
+ .expected_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_ENCRYPT,
+ .expected_data = expected_output,
+ .expected_data_size = BUFFER_SIZE,
+ .expected_data_length = AES_24B_KEY_SIZE,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_256
-{"Test psa_copy_key 32 Byte AES\n", PSA_KEY_TYPE_AES,
-{0xEA, 0xD5, 0xE6, 0xC8, 0x51, 0xF9, 0xEC, 0xBB, 0x9B, 0x57, 0x7C, 0xED, 0xD2,
- 0x4B, 0x82, 0x84, 0x9F, 0x9F, 0xE6, 0x73, 0x21, 0x3D, 0x1A, 0x05, 0xC9, 0xED,
- 0xDF, 0x25, 0x17, 0x68, 0x86, 0xAE},
- AES_32B_KEY_SIZE,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_DECRYPT,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_ENCRYPT,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_ALG_CTR, PSA_ALG_CTR, PSA_ALG_CTR,
- BYTES_TO_BITS(AES_32B_KEY_SIZE), AES_32B_KEY_SIZE, PSA_SUCCESS
+{
+ .test_desc = "Test psa_copy_key - 32 Byte AES\n",
+ .type = PSA_KEY_TYPE_AES,
+ .alg = PSA_ALG_CTR,
+ .usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_DECRYPT,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .data = key_data,
+ .data_length = AES_32B_KEY_SIZE,
+ .target_type = PSA_KEY_TYPE_AES,
+ .target_alg = PSA_ALG_CTR,
+ .target_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_ENCRYPT,
+ .target_lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .target_bits = BYTES_TO_BITS(AES_32B_KEY_SIZE),
+ .expected_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .expected_data_size = BUFFER_SIZE,
+ .expected_data_length = AES_32B_KEY_SIZE,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
#ifdef ARCH_TEST_RSA_2048
-{"Test psa_copy_key 2048 RSA public key\n", PSA_KEY_TYPE_RSA_PUBLIC_KEY,
- {0},
- 270,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_SIGN,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_ENCRYPT,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_ALG_RSA_PKCS1V15_SIGN_RAW, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
- PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
- 2048, 270, PSA_SUCCESS
+{
+ .test_desc = "Test psa_copy_key - 2048 RSA public key\n",
+ .type = PSA_KEY_TYPE_RSA_PUBLIC_KEY,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
+ .usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_SIGN,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .data = rsa_256_key_data,
+ .data_length = 270,
+ .target_type = PSA_KEY_TYPE_RSA_PUBLIC_KEY,
+ .target_alg = PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
+ .target_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_ENCRYPT,
+ .target_lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .target_bits = BYTES_TO_BITS(256),
+ .expected_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .expected_data_size = BUFFER_SIZE,
+ .expected_data_length = 270,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_copy_key with RSA 2048 keypair\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
- {0},
- 1193,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_VERIFY,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_ALG_RSA_PKCS1V15_SIGN_RAW, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
- PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
- 2048, 1193, PSA_SUCCESS
+{
+ .test_desc = "Test psa_copy_key - RSA 2048 keypair\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
+ .usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .data = rsa_256_key_pair,
+ .data_length = 1193,
+ .target_type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .target_alg = PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
+ .target_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_VERIFY,
+ .target_lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .target_bits = BYTES_TO_BITS(256),
+ .expected_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .expected_data_size = BUFFER_SIZE,
+ .expected_data_length = 1193,
+ .expected_status = PSA_SUCCESS
},
-{"Test psa_copy_key with Incompatible target policy(source and target)\n",
- PSA_KEY_TYPE_RSA_KEY_PAIR,
- {0},
- 1193,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT, PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_ANY_HASH), PSA_ALG_RSA_PSS(PSA_ALG_ANY_HASH),
- -1,
- 2048, 1193, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_copy_key - Incompatible target policy(source and target)\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_ANY_HASH),
+ .usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .data = rsa_256_key_pair,
+ .data_length = 1193,
+ .target_type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .target_alg = PSA_ALG_RSA_PSS(PSA_ALG_ANY_HASH),
+ .target_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .target_lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .target_bits = BYTES_TO_BITS(256),
+ .expected_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .expected_data_size = BUFFER_SIZE,
+ .expected_data_length = 1193,
+ .expected_status = PSA_ERROR_INVALID_ARGUMENT
},
-{"Test psa_copy_key with Incompatible constraint\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
- {0},
- 1193,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT, PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_ANY_HASH),
- PSA_ALG_RSA_PSS(PSA_ALG_ANY_HASH), -1,
- 2048, 1193, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_copy_key - source key with no export usage\n",
+ .type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .alg = PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
+ .usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_SIGN,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .data = rsa_256_key_pair,
+ .data_length = 1193,
+ .target_type = PSA_KEY_TYPE_RSA_KEY_PAIR,
+ .target_alg = PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
+ .target_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .target_lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .target_bits = BYTES_TO_BITS(256),
+ .expected_usage_flags = PSA_KEY_USAGE_COPY,
+ .expected_data = expected_output,
+ .expected_data_size = BUFFER_SIZE,
+ .expected_data_length = 1193,
+ .expected_status = PSA_SUCCESS
},
-
-{"Test psa_copy_key with unexport source key usage\n", PSA_KEY_TYPE_RSA_KEY_PAIR,
- {0},
- 1193,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_SIGN, PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_KEY_USAGE_COPY,
- PSA_ALG_RSA_PKCS1V15_SIGN_RAW, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
- PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
- 2048, 1193, PSA_SUCCESS
-},
-
#endif
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_DES_1KEY
-{"Test psa_copy_key with DES 64 bit key\n", PSA_KEY_TYPE_DES,
- {0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
- DES_8B_KEY_SIZE,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT, PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_ALG_CTR, PSA_ALG_CTR, PSA_ALG_CTR,
- BYTES_TO_BITS(DES_8B_KEY_SIZE), DES_8B_KEY_SIZE, PSA_SUCCESS
+{
+ .test_desc = "Test psa_copy_key - DES 64 bit key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .alg = PSA_ALG_CTR,
+ .usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .data = key_data,
+ .data_length = DES_8B_KEY_SIZE,
+ .target_type = PSA_KEY_TYPE_DES,
+ .target_alg = PSA_ALG_CTR,
+ .target_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .target_lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .target_bits = BYTES_TO_BITS(DES_8B_KEY_SIZE),
+ .expected_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .expected_data_size = BUFFER_SIZE,
+ .expected_data_length = DES_8B_KEY_SIZE,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_2KEY
-{"Test psa_copy_key with Triple DES 2-Key\n", PSA_KEY_TYPE_DES,
-{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
- DES3_2KEY_SIZE,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT, PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_ALG_CTR, PSA_ALG_CTR, PSA_ALG_CTR,
- BYTES_TO_BITS(DES3_2KEY_SIZE), DES3_2KEY_SIZE, PSA_SUCCESS
+{
+ .test_desc = "Test psa_copy_key - Triple DES 2-Key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .alg = PSA_ALG_CTR,
+ .usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .data = key_data,
+ .data_length = DES3_2B_KEY_SIZE,
+ .target_type = PSA_KEY_TYPE_DES,
+ .target_alg = PSA_ALG_CTR,
+ .target_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .target_lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .target_bits = BYTES_TO_BITS(DES3_2B_KEY_SIZE),
+ .expected_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .expected_data_size = BUFFER_SIZE,
+ .expected_data_length = DES3_2B_KEY_SIZE,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_3KEY
-{"Test psa_copy_key with Triple DES 3-Key\n", PSA_KEY_TYPE_DES,
-{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
- 0xF1, 0xE0, 0xD3, 0xC2, 0xB5, 0xA4, 0x97, 0x86,
- 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10},
- DES3_3KEY_SIZE,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT, PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_ALG_CTR, PSA_ALG_CTR, PSA_ALG_CTR,
- BYTES_TO_BITS(DES3_3KEY_SIZE), DES3_3KEY_SIZE, PSA_SUCCESS
+{
+ .test_desc = "Test psa_copy_key - Triple DES 3-Key\n",
+ .type = PSA_KEY_TYPE_DES,
+ .alg = PSA_ALG_CTR,
+ .usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .data = key_data,
+ .data_length = DES3_3B_KEY_SIZE,
+ .target_type = PSA_KEY_TYPE_DES,
+ .target_alg = PSA_ALG_CTR,
+ .target_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .target_lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .target_bits = BYTES_TO_BITS(DES3_3B_KEY_SIZE),
+ .expected_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .expected_data_size = BUFFER_SIZE,
+ .expected_data_length = DES3_3B_KEY_SIZE,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_ECDSA
#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
-{"Test psa_copy_key with EC Public key\n",
- PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
- {0},
- 65,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT, PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_ALG_ECDSA_ANY, PSA_ALG_ECDSA_ANY, PSA_ALG_ECDSA_ANY,
- 256, 65, PSA_SUCCESS
+{
+ .test_desc = "Test psa_copy_key - EC Public key\n",
+ .type = PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
+ .alg = PSA_ALG_ECDSA_ANY,
+ .usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .data = ec_key_data,
+ .data_length = 65,
+ .target_type = PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
+ .target_alg = PSA_ALG_ECDSA_ANY,
+ .target_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .target_lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .target_bits = 256,
+ .expected_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .expected_data_size = BUFFER_SIZE,
+ .expected_data_length = 65,
+ .expected_status = PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_ECC_CURVE_SECP224R1
-{"Test psa_copy_key with EC keypair\n",
- PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP224R1),
- {0},
- 28,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT, PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_ALG_ECDSA_ANY, PSA_ALG_ECDSA_ANY, PSA_ALG_ECDSA_ANY,
- 224, 28, PSA_SUCCESS
-},
-#endif
-#endif
-
-#ifdef ARCH_TEST_CIPER_MODE_CTR
-#ifdef ARCH_TEST_AES
-{"Test psa_copy_key with Incompatible target policy\n", PSA_KEY_TYPE_AES,
-{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
- 0x5F, 0xC9, 0x77},
- AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT, PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
- PSA_ALG_CTR, PSA_ALG_CBC_NO_PADDING, PSA_ALG_CBC_NO_PADDING,
- BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
+{
+ .test_desc = "Test psa_copy_key - EC keypair\n",
+ .type = PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP224R1),
+ .alg = PSA_ALG_ECDSA_ANY,
+ .usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .data = ec_key_pair,
+ .data_length = 28,
+ .target_type = PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP224R1),
+ .target_alg = PSA_ALG_ECDSA_ANY,
+ .target_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .target_lifetime = PSA_KEY_LIFETIME_VOLATILE,
+ .target_bits = 224,
+ .expected_usage_flags = PSA_KEY_USAGE_COPY | PSA_KEY_USAGE_EXPORT,
+ .expected_data = expected_output,
+ .expected_data_size = BUFFER_SIZE,
+ .expected_data_length = 28,
+ .expected_status = PSA_SUCCESS
},
#endif
#endif
diff --git a/api-tests/dev_apis/crypto/test_c045/test_c045.c b/api-tests/dev_apis/crypto/test_c045/test_c045.c
index 3cb17cd..4944727 100644
--- a/api-tests/dev_apis/crypto/test_c045/test_c045.c
+++ b/api-tests/dev_apis/crypto/test_c045/test_c045.c
@@ -19,25 +19,26 @@
#include "val_target.h"
#include "test_c045.h"
#include "test_data.h"
-#include "val_crypto.h"
const client_test_t test_c045_crypto_list[] = {
NULL,
psa_hash_clone_test,
+ psa_hash_clone_with_inactive_source_operation,
+ psa_hash_clone_with_active_target_operation,
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
+static int32_t valid_test_input_index = -1;
int32_t psa_hash_clone_test(caller_security_t caller __UNUSED)
{
- int num_checks = sizeof(check1)/sizeof(check1[0]);
+ int32_t num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
- const char *expected_hash;
- char hash[HASH_64B];
- size_t hash_length, hash_size = sizeof(hash);
- psa_hash_operation_t source_operation = PSA_HASH_OPERATION_INIT;
- psa_hash_operation_t target_operation = PSA_HASH_OPERATION_INIT;
+ size_t get_source_hash_length;
+ size_t get_target_hash_length;
+ psa_hash_operation_t source_operation;
+ psa_hash_operation_t target_operation;
if (num_checks == 0)
{
@@ -53,60 +54,183 @@
{
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, check1[i].test_desc, 0);
+ memset(&source_operation, 0, sizeof(source_operation));
+ memset(&target_operation, 0, sizeof(target_operation));
+ get_source_hash_length = 0;
+ get_target_hash_length = 0;
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
- if (check1[i].alg == PSA_ALG_SHA_384)
- expected_hash = sha384_hash;
- else if (check1[i].alg == PSA_ALG_SHA_512)
- expected_hash = sha512_hash;
- else
- expected_hash = check1[i].hash;
-
/* Start a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &source_operation, check1[i].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Clone a hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_CLONE, &source_operation, &target_operation);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
+ TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(4));
- /* Add a message fragment to a multipart hash source_operation */
- status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE, &target_operation,
- &check1[i].input, check1[i].input_length);
+ /* Add a message fragment to a multipart for source_operation */
+ status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE,
+ &source_operation,
+ check1[i].input,
+ check1[i].input_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
- /* Cloning to an active hash operation should be an error*/
- status = val->crypto_function(VAL_CRYPTO_HASH_CLONE, &source_operation, &target_operation);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(6));
+ /* Add a message fragment to a multipart for target_operation */
+ status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE,
+ &target_operation,
+ check1[i].input,
+ check1[i].input_length);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
- /* Finish the calculation of the hash of a message */
- status = val->crypto_function(VAL_CRYPTO_HASH_FINISH, &target_operation, hash, hash_size,
- &hash_length);
- TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(7));
+ /* Finish the calculation of the hash of a message for source operation */
+ status = val->crypto_function(VAL_CRYPTO_HASH_FINISH,
+ &source_operation,
+ check1[i].source_hash,
+ check1[i].source_hash_size,
+ &get_source_hash_length);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(7));
- if (check1[i].expected_status != PSA_SUCCESS)
- {
- continue;
- }
+ /* Finish the calculation of the hash of a message for target operation */
+ status = val->crypto_function(VAL_CRYPTO_HASH_FINISH,
+ &target_operation,
+ check1[i].target_hash,
+ check1[i].target_hash_size,
+ &get_target_hash_length);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(8));
- TEST_ASSERT_EQUAL(hash_length, PSA_HASH_SIZE(check1[i].alg), TEST_CHECKPOINT_NUM(8));
- TEST_ASSERT_MEMCMP(hash, expected_hash, hash_length, TEST_CHECKPOINT_NUM(9));
+ /* Check for expected hash length for source and target operation */
+ TEST_ASSERT_EQUAL(get_source_hash_length, check1[i].expected_hash_length,
+ TEST_CHECKPOINT_NUM(9));
+ TEST_ASSERT_EQUAL(get_target_hash_length, check1[i].expected_hash_length,
+ TEST_CHECKPOINT_NUM(10));
+ /* Check for expected hash for source and target operation */
+ TEST_ASSERT_MEMCMP(check1[i].source_hash, check1[i].expected_hash, get_source_hash_length,
+ TEST_CHECKPOINT_NUM(11));
+ TEST_ASSERT_MEMCMP(check1[i].target_hash, check1[i].expected_hash, get_target_hash_length,
+ TEST_CHECKPOINT_NUM(12));
- /*Abort the hash operation */
+ if (valid_test_input_index < 0)
+ valid_test_input_index = i;
+
+ /* Abort the hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &source_operation);
- TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(10));
-
- status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &target_operation);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(11));
- /* Cloning on an aborted operator should be an error */
- status = val->crypto_function(VAL_CRYPTO_HASH_CLONE, &source_operation, &target_operation);
- TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(12));
-
+ status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &target_operation);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(12));
}
return VAL_STATUS_SUCCESS;
}
+
+int32_t psa_hash_clone_with_inactive_source_operation(caller_security_t caller __UNUSED)
+{
+ int32_t status;
+ psa_hash_operation_t source_operation;
+ psa_hash_operation_t target_operation;
+ size_t get_source_hash_length = 0;
+
+ if (valid_test_input_index < 0)
+ return RESULT_SKIP(VAL_STATUS_NO_TESTS);
+
+ /* Initialize the PSA crypto library*/
+ status = val->crypto_function(VAL_CRYPTO_INIT);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
+
+ val->print(PRINT_TEST, "[Check %d] Test psa_hash_clone - from an inactive source operation\n",
+ g_test_count++);
+
+ memset(&source_operation, 0, sizeof(source_operation));
+ memset(&target_operation, 0, sizeof(target_operation));
+
+ /* Setting up the watchdog timer for each check */
+ status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
+ TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
+
+ /* Start a multipart hash operation */
+ status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &source_operation,
+ check1[valid_test_input_index].alg);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
+
+ /* Add a message fragment to a multipart for source_operation */
+ status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE,
+ &source_operation,
+ check1[valid_test_input_index].input,
+ check1[valid_test_input_index].input_length);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
+
+ /* Finish the calculation of the hash of a message for source operation */
+ status = val->crypto_function(VAL_CRYPTO_HASH_FINISH,
+ &source_operation,
+ check1[valid_test_input_index].source_hash,
+ check1[valid_test_input_index].source_hash_size,
+ &get_source_hash_length);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
+
+ /* Check for expected hash length for source operation */
+ TEST_ASSERT_EQUAL(get_source_hash_length, check1[valid_test_input_index].expected_hash_length,
+ TEST_CHECKPOINT_NUM(6));
+ /* Check for expected hash for source operation */
+ TEST_ASSERT_MEMCMP(check1[valid_test_input_index].source_hash,
+ check1[valid_test_input_index].expected_hash, get_source_hash_length,
+ TEST_CHECKPOINT_NUM(7));
+
+ /* Clone from an inactive source operation */
+ status = val->crypto_function(VAL_CRYPTO_HASH_CLONE, &source_operation, &target_operation);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(8));
+
+ /* Abort the hash operation */
+ status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &source_operation);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(9));
+
+ return VAL_STATUS_SUCCESS;
+}
+
+int32_t psa_hash_clone_with_active_target_operation(caller_security_t caller __UNUSED)
+{
+ int32_t status;
+ psa_hash_operation_t source_operation;
+ psa_hash_operation_t target_operation;
+
+ if (valid_test_input_index < 0)
+ return RESULT_SKIP(VAL_STATUS_NO_TESTS);
+
+ /* Initialize the PSA crypto library*/
+ status = val->crypto_function(VAL_CRYPTO_INIT);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
+
+ val->print(PRINT_TEST, "[Check %d] Test psa_hash_clone - on an active target operation\n",
+ g_test_count++);
+
+ memset(&source_operation, 0, sizeof(source_operation));
+ memset(&target_operation, 0, sizeof(target_operation));
+
+ /* Setting up the watchdog timer for each check */
+ status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
+ TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
+
+ /* Start a multipart hash operation */
+ status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &source_operation,
+ check1[valid_test_input_index].alg);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
+
+ /* Clone from an active source operation */
+ status = val->crypto_function(VAL_CRYPTO_HASH_CLONE, &source_operation, &target_operation);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
+
+ /* Try clonig to an active hash operation and expect an error */
+ status = val->crypto_function(VAL_CRYPTO_HASH_CLONE, &source_operation, &target_operation);
+ TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(5));
+
+ /* Abort the hash operation */
+ status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &source_operation);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
+
+ status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &target_operation);
+ TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(7));
+
+ return VAL_STATUS_SUCCESS;
+}
diff --git a/api-tests/dev_apis/crypto/test_c045/test_c045.h b/api-tests/dev_apis/crypto/test_c045/test_c045.h
index aba247e..287d493 100644
--- a/api-tests/dev_apis/crypto/test_c045/test_c045.h
+++ b/api-tests/dev_apis/crypto/test_c045/test_c045.h
@@ -27,4 +27,6 @@
extern const client_test_t test_c045_crypto_list[];
int32_t psa_hash_clone_test(caller_security_t caller);
+int32_t psa_hash_clone_with_inactive_source_operation(caller_security_t caller);
+int32_t psa_hash_clone_with_active_target_operation(caller_security_t caller);
#endif /* _TEST_C045_CLIENT_TESTS_H_ */
diff --git a/api-tests/dev_apis/crypto/test_c045/test_data.h b/api-tests/dev_apis/crypto/test_c045/test_data.h
index a284be0..7cbd091 100644
--- a/api-tests/dev_apis/crypto/test_c045/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c045/test_data.h
@@ -15,101 +15,164 @@
* limitations under the License.
**/
-#include "val_crypto.h"
+#include "test_crypto_common.h"
typedef struct {
char test_desc[50];
psa_algorithm_t alg;
- char input;
+ const uint8_t *input;
size_t input_length;
- char hash[32];
- size_t hash_length;
+ uint8_t *source_hash;
+ size_t source_hash_size;
+ uint8_t *target_hash;
+ size_t target_hash_size;
+ const uint8_t *expected_hash;
+ size_t expected_hash_length;
psa_status_t expected_status;
} test_data;
-static const char sha384_hash[] = {
-0x43, 0x72, 0xe3, 0x8a, 0x92, 0xa2, 0x8b, 0x5d, 0x2c, 0x39, 0x1e, 0x62,
-0x45, 0x2a, 0x86, 0xd5, 0x0e, 0x02, 0x67, 0x22, 0x8b, 0xe1, 0x76, 0xc7, 0x7d, 0x24, 0x02, 0xef,
-0xfe, 0x9f, 0xa5, 0x0d, 0xe4, 0x07, 0xbb, 0xb8, 0x51, 0xb3, 0x7d, 0x59, 0x04, 0xab, 0xa2, 0xde,
-0xde, 0x74, 0xda, 0x2a};
-
-static const char sha512_hash[] = {
-0x29, 0x6e, 0x22, 0x67, 0xd7, 0x4c, 0x27, 0x8d, 0xaa, 0xaa, 0x94, 0x0d,
-0x17, 0xb0, 0xcf, 0xb7, 0x4a, 0x50, 0x83, 0xf8, 0xe0, 0x69, 0x72, 0x6d, 0x8c, 0x84, 0x1c, 0xbe,
-0x59, 0x6e, 0x04, 0x31, 0xcb, 0x77, 0x41, 0xa5, 0xb5, 0x0f, 0x71, 0x66, 0x6c, 0xfd, 0x54, 0xba,
-0xcb, 0x7b, 0x00, 0xae, 0xa8, 0x91, 0x49, 0x9c, 0xf4, 0xef, 0x6a, 0x03, 0xc8, 0xa8, 0x3f, 0xe3,
-0x7c, 0x3f, 0x7b, 0xaf};
-
static const test_data check1[] = {
#ifdef ARCH_TEST_MD2
-{"Test psa_hash_clone with MD2 algorithm\n",
- PSA_ALG_MD2, 0xbd, 1,
- {0x8c, 0x9c, 0x17, 0x66, 0x5d, 0x25, 0xb3, 0x5f, 0xc4, 0x13, 0xc4, 0x18, 0x05, 0xc6, 0x79, 0xcf},
- 16, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_clone - MD2 algorithm\n",
+ .alg = PSA_ALG_MD2,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .source_hash = expected_output,
+ .source_hash_size = BUFFER_SIZE/2,
+ .target_hash = (expected_output + BUFFER_SIZE/2),
+ .target_hash_size = BUFFER_SIZE/2,
+ .expected_hash = md2_hash,
+ .expected_hash_length = 16,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD4
-{"Test psa_hash_clone with MD4 algorithm\n",
- PSA_ALG_MD4, 0xbd, 1,
- {0x18, 0xc3, 0x3f, 0x97, 0x29, 0x7e, 0xfe, 0x5f, 0x8a, 0x73, 0x22, 0x58, 0x28, 0x9f, 0xda, 0x25},
- 16, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_clone - MD4 algorithm\n",
+ .alg = PSA_ALG_MD4,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .source_hash = expected_output,
+ .source_hash_size = BUFFER_SIZE/2,
+ .target_hash = (expected_output + BUFFER_SIZE/2),
+ .target_hash_size = BUFFER_SIZE/2,
+ .expected_hash = md4_hash,
+ .expected_hash_length = 16,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD5
-{"Test psa_hash_clone with MD5 algorithm\n",
- PSA_ALG_MD5, 0xbd, 1,
- {0xab, 0xae, 0x57, 0xcb, 0x56, 0x2e, 0xcf, 0x29, 0x5b, 0x4a, 0x37, 0xa7, 0x6e, 0xfe, 0x61, 0xfb},
- 16, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_clone - MD5 algorithm\n",
+ .alg = PSA_ALG_MD5,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .source_hash = expected_output,
+ .source_hash_size = BUFFER_SIZE/2,
+ .target_hash = (expected_output + BUFFER_SIZE/2),
+ .target_hash_size = BUFFER_SIZE/2,
+ .expected_hash = md5_hash,
+ .expected_hash_length = 16,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_RIPEMD160
-{"Test psa_hash_clone with RIPEMD160 algorithm\n",
- PSA_ALG_RIPEMD160, 0xbd, 1,
- {0x50, 0x89, 0x26, 0x5e, 0xe5, 0xd9, 0xaf, 0x75, 0xd1, 0x2d, 0xbf, 0x7e, 0xa2, 0xf2, 0x7d, 0xbd,
- 0xee, 0x43, 0x5b, 0x37},
- 20, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_clone - RIPEMD160 algorithm\n",
+ .alg = PSA_ALG_RIPEMD160,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .source_hash = expected_output,
+ .source_hash_size = BUFFER_SIZE/2,
+ .target_hash = (expected_output + BUFFER_SIZE/2),
+ .target_hash_size = BUFFER_SIZE/2,
+ .expected_hash = ripemd_160_hash,
+ .expected_hash_length = 20,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA1
-{"Test psa_hash_clone with SHA1 algorithm\n",
- PSA_ALG_SHA_1, 0xbd, 1,
- {0x90, 0x34, 0xaa, 0xf4, 0x51, 0x43, 0x99, 0x6a, 0x2b, 0x14, 0x46, 0x5c, 0x35, 0x2a, 0xb0, 0xc6,
- 0xfa, 0x26, 0xb2, 0x21},
- 20, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_clone - SHA1 algorithm\n",
+ .alg = PSA_ALG_SHA_1,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .source_hash = expected_output,
+ .source_hash_size = BUFFER_SIZE/2,
+ .target_hash = (expected_output + BUFFER_SIZE/2),
+ .target_hash_size = BUFFER_SIZE/2,
+ .expected_hash = sha_1_hash,
+ .expected_hash_length = 20,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA224
-{"Test psa_hash_clone with SHA224 algorithm\n",
- PSA_ALG_SHA_224, 0xbd, 1,
- {0xb1, 0xe4, 0x6b, 0xb9, 0xef, 0xe4, 0x5a, 0xf5, 0x54, 0x36, 0x34, 0x49, 0xc6, 0x94, 0x5a, 0x0d,
- 0x61, 0x69, 0xfc, 0x3a, 0x5a, 0x39, 0x6a, 0x56, 0xcb, 0x97, 0xcb, 0x57},
- 28, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_clone - SHA224 algorithm\n",
+ .alg = PSA_ALG_SHA_224,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .source_hash = expected_output,
+ .source_hash_size = BUFFER_SIZE/2,
+ .target_hash = (expected_output + BUFFER_SIZE/2),
+ .target_hash_size = BUFFER_SIZE/2,
+ .expected_hash = sha_224_hash,
+ .expected_hash_length = 28,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA256
-{"Test psa_hash_clone with SHA256 algorithm\n",
- PSA_ALG_SHA_256, 0xbd, 1,
- {0x68, 0x32, 0x57, 0x20, 0xaa, 0xbd, 0x7c, 0x82, 0xf3, 0x0f, 0x55, 0x4b, 0x31, 0x3d, 0x05, 0x70,
- 0xc9, 0x5a, 0xcc, 0xbb, 0x7d, 0xc4, 0xb5, 0xaa, 0xe1, 0x12, 0x04, 0xc0, 0x8f, 0xfe, 0x73, 0x2b},
- 32, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_clone - SHA256 algorithm\n",
+ .alg = PSA_ALG_SHA_256,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .source_hash = expected_output,
+ .source_hash_size = BUFFER_SIZE/2,
+ .target_hash = (expected_output + BUFFER_SIZE/2),
+ .target_hash_size = BUFFER_SIZE/2,
+ .expected_hash = sha_256_hash,
+ .expected_hash_length = 32,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA384
-{"Test psa_hash_clone with SHA384 algorithm\n",
- PSA_ALG_SHA_384, 0xbd, 1, {0}, 48, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_clone - SHA384 algorithm\n",
+ .alg = PSA_ALG_SHA_384,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .source_hash = expected_output,
+ .source_hash_size = BUFFER_SIZE/2,
+ .target_hash = (expected_output + BUFFER_SIZE/2),
+ .target_hash_size = BUFFER_SIZE/2,
+ .expected_hash = sha_384_hash,
+ .expected_hash_length = 48,
+ .expected_status = PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA512
-{"Test psa_hash_clone with SHA512 algorithm\n",
- PSA_ALG_SHA_512, 0xbd, 1, {0}, 64, PSA_SUCCESS,
+{
+ .test_desc = "Test psa_hash_clone - SHA512 algorithm\n",
+ .alg = PSA_ALG_SHA_512,
+ .input = &hash_input,
+ .input_length = sizeof(hash_input),
+ .source_hash = expected_output,
+ .source_hash_size = BUFFER_SIZE/2,
+ .target_hash = (expected_output + BUFFER_SIZE/2),
+ .target_hash_size = BUFFER_SIZE/2,
+ .expected_hash = sha_512_hash,
+ .expected_hash_length = 64,
+ .expected_status = PSA_SUCCESS,
},
#endif
};
diff --git a/api-tests/dev_apis/crypto/test_c046/test_c046.c b/api-tests/dev_apis/crypto/test_c046/test_c046.c
index 3b7bd52..593bd93 100644
--- a/api-tests/dev_apis/crypto/test_c046/test_c046.c
+++ b/api-tests/dev_apis/crypto/test_c046/test_c046.c
@@ -26,7 +26,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
static uint8_t data[BUFFER_SIZE];
int32_t psa_mac_compute_test(caller_security_t caller __UNUSED)
diff --git a/api-tests/dev_apis/crypto/test_c047/test_c047.c b/api-tests/dev_apis/crypto/test_c047/test_c047.c
index 99a4894..e3a093f 100644
--- a/api-tests/dev_apis/crypto/test_c047/test_c047.c
+++ b/api-tests/dev_apis/crypto/test_c047/test_c047.c
@@ -26,7 +26,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
int32_t psa_mac_verify_test(caller_security_t caller __UNUSED)
{
diff --git a/api-tests/dev_apis/crypto/test_c048/test_c048.c b/api-tests/dev_apis/crypto/test_c048/test_c048.c
index 7cb5fb7..ba579e2 100644
--- a/api-tests/dev_apis/crypto/test_c048/test_c048.c
+++ b/api-tests/dev_apis/crypto/test_c048/test_c048.c
@@ -26,7 +26,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
static uint8_t output[SIZE_32B];
int32_t psa_cipher_encrypt_test(caller_security_t caller __UNUSED)
diff --git a/api-tests/dev_apis/crypto/test_c048/test_data.h b/api-tests/dev_apis/crypto/test_c048/test_data.h
index bf67c1a..d26cc52 100644
--- a/api-tests/dev_apis/crypto/test_c048/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c048/test_data.h
@@ -113,7 +113,7 @@
#ifdef ARCH_TEST_DES_2KEY
{"Test psa_cipher_encrypt - Encrypt - 2-key 3DE -CBC (nopad)\n", PSA_KEY_TYPE_DES,
{0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e, 0xc1, 0xc2, 0xc4, 0xc7, 0xc8,
- 0xcb, 0xcd, 0xce}, DES3_2KEY_SIZE,
+ 0xcb, 0xcd, 0xce}, DES3_2B_KEY_SIZE,
PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 8, SIZE_32B,
{0x5d, 0x06, 0x52, 0x42, 0x9c, 0x5b, 0x0a, 0xc7}, 0, PSA_SUCCESS
@@ -123,7 +123,7 @@
#ifdef ARCH_TEST_DES_3KEY
{"Test psa_cipher_encrypt - Encrypt - 3-key 3DE -CBC (nopad)\n", PSA_KEY_TYPE_DES,
{0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e, 0xc1, 0xc2, 0xc4, 0xc7, 0xc8,
- 0xcb, 0xcd, 0xce, 0x31, 0x32, 0x34, 0x37, 0x38, 0x3b, 0x3d, 0x3e}, DES3_3KEY_SIZE,
+ 0xcb, 0xcd, 0xce, 0x31, 0x32, 0x34, 0x37, 0x38, 0x3b, 0x3d, 0x3e}, DES3_3B_KEY_SIZE,
PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 8, SIZE_32B,
{0x81, 0x7c, 0xa7, 0xd6, 0x9b, 0x80, 0xd8, 0x6a}, 0, PSA_SUCCESS
diff --git a/api-tests/dev_apis/crypto/test_c049/test_c049.c b/api-tests/dev_apis/crypto/test_c049/test_c049.c
index 1c3abeb..4aacaae 100644
--- a/api-tests/dev_apis/crypto/test_c049/test_c049.c
+++ b/api-tests/dev_apis/crypto/test_c049/test_c049.c
@@ -26,7 +26,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
static uint8_t output[SIZE_32B];
int32_t psa_cipher_decrypt_test(caller_security_t caller __UNUSED)
diff --git a/api-tests/dev_apis/crypto/test_c049/test_data.h b/api-tests/dev_apis/crypto/test_c049/test_data.h
index 7d75297..e862677 100644
--- a/api-tests/dev_apis/crypto/test_c049/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c049/test_data.h
@@ -139,7 +139,7 @@
#ifdef ARCH_TEST_DES_2KEY
{"Test psa_cipher_decrypt - Decrypt - 2-key 3DE -CBC (nopad)\n", PSA_KEY_TYPE_DES,
{0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e, 0xc1, 0xc2, 0xc4, 0xc7, 0xc8,
- 0xcb, 0xcd, 0xce}, DES3_2KEY_SIZE,
+ 0xcb, 0xcd, 0xce}, DES3_2B_KEY_SIZE,
PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING,
{0x5d, 0x06, 0x52, 0x42, 0x9c, 0x5b, 0x0a, 0xc7}, 8, SIZE_32B,
{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 0, PSA_SUCCESS
@@ -149,7 +149,7 @@
#ifdef ARCH_TEST_DES_3KEY
{"Test psa_cipher_decrypt - 3-key 3DE -CBC (nopad)\n", PSA_KEY_TYPE_DES,
{0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e, 0xc1, 0xc2, 0xc4, 0xc7, 0xc8,
- 0xcb, 0xcd, 0xce, 0x31, 0x32, 0x34, 0x37, 0x38, 0x3b, 0x3d, 0x3e}, DES3_3KEY_SIZE,
+ 0xcb, 0xcd, 0xce, 0x31, 0x32, 0x34, 0x37, 0x38, 0x3b, 0x3d, 0x3e}, DES3_3B_KEY_SIZE,
PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING,
{0x81, 0x7c, 0xa7, 0xd6, 0x9b, 0x80, 0xd8, 0x6a}, 8, SIZE_32B,
{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 0, PSA_SUCCESS
diff --git a/api-tests/dev_apis/crypto/test_c050/test_c050.c b/api-tests/dev_apis/crypto/test_c050/test_c050.c
index 2ee22da..2021f97 100644
--- a/api-tests/dev_apis/crypto/test_c050/test_c050.c
+++ b/api-tests/dev_apis/crypto/test_c050/test_c050.c
@@ -27,7 +27,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
static uint8_t data[BUFFER_SIZE];
int32_t psa_open_key_test(caller_security_t caller __UNUSED)
diff --git a/api-tests/dev_apis/crypto/test_c050/test_data.h b/api-tests/dev_apis/crypto/test_c050/test_data.h
index 24fa169..fde6bec 100644
--- a/api-tests/dev_apis/crypto/test_c050/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c050/test_data.h
@@ -224,8 +224,8 @@
{"Test psa_open_key with Triple DES 2-Key\n", PSA_KEY_TYPE_DES, 0x123,
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
- DES3_2KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, PSA_KEY_LIFETIME_PERSISTENT,
- BYTES_TO_BITS(DES3_2KEY_SIZE), DES3_2KEY_SIZE, PSA_SUCCESS
+ DES3_2B_KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, PSA_KEY_LIFETIME_PERSISTENT,
+ BYTES_TO_BITS(DES3_2B_KEY_SIZE), DES3_2B_KEY_SIZE, PSA_SUCCESS
},
#endif
@@ -234,8 +234,8 @@
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
0xF1, 0xE0, 0xD3, 0xC2, 0xB5, 0xA4, 0x97, 0x86,
0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10},
- DES3_3KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, PSA_KEY_LIFETIME_PERSISTENT,
- BYTES_TO_BITS(DES3_3KEY_SIZE), DES3_3KEY_SIZE, PSA_SUCCESS
+ DES3_3B_KEY_SIZE, 0, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, PSA_KEY_LIFETIME_PERSISTENT,
+ BYTES_TO_BITS(DES3_3B_KEY_SIZE), DES3_3B_KEY_SIZE, PSA_SUCCESS
},
#endif
#endif
diff --git a/api-tests/dev_apis/crypto/test_c051/test_c051.c b/api-tests/dev_apis/crypto/test_c051/test_c051.c
index f50076a..d6a3485 100644
--- a/api-tests/dev_apis/crypto/test_c051/test_c051.c
+++ b/api-tests/dev_apis/crypto/test_c051/test_c051.c
@@ -26,7 +26,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
int32_t psa_close_key_test(caller_security_t caller __UNUSED)
{
diff --git a/api-tests/dev_apis/crypto/test_c051/test_data.h b/api-tests/dev_apis/crypto/test_c051/test_data.h
index 5e77062..b6b9e6c 100644
--- a/api-tests/dev_apis/crypto/test_c051/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c051/test_data.h
@@ -227,9 +227,9 @@
{"Test psa_close_key with Triple DES 2-Key\n", PSA_KEY_TYPE_DES,
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
- DES3_2KEY_SIZE, BYTES_TO_BITS(DES3_2KEY_SIZE), PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
+ DES3_2B_KEY_SIZE, BYTES_TO_BITS(DES3_2B_KEY_SIZE), PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
0xBC, PSA_KEY_LIFETIME_PERSISTENT,
- BYTES_TO_BITS(DES3_2KEY_SIZE), PSA_SUCCESS
+ BYTES_TO_BITS(DES3_2B_KEY_SIZE), PSA_SUCCESS
},
#endif
@@ -238,9 +238,9 @@
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
0xF1, 0xE0, 0xD3, 0xC2, 0xB5, 0xA4, 0x97, 0x86,
0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10},
- DES3_3KEY_SIZE, BYTES_TO_BITS(DES3_3KEY_SIZE), PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
+ DES3_3B_KEY_SIZE, BYTES_TO_BITS(DES3_3B_KEY_SIZE), PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
0xCD, PSA_KEY_LIFETIME_PERSISTENT,
- BYTES_TO_BITS(DES3_3KEY_SIZE), PSA_SUCCESS
+ BYTES_TO_BITS(DES3_3B_KEY_SIZE), PSA_SUCCESS
},
#endif
#endif
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 bdb16da..b558900 100644
--- a/api-tests/dev_apis/crypto/test_c052/test_c052.c
+++ b/api-tests/dev_apis/crypto/test_c052/test_c052.c
@@ -26,7 +26,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
int32_t psa_aead_encrypt_setup_test(caller_security_t caller __UNUSED)
{
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 153442e..ccd9242 100644
--- a/api-tests/dev_apis/crypto/test_c053/test_c053.c
+++ b/api-tests/dev_apis/crypto/test_c053/test_c053.c
@@ -26,7 +26,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
int32_t psa_aead_decrypt_setup_test(caller_security_t caller __UNUSED)
{
diff --git a/api-tests/dev_apis/crypto/test_c054/test_c054.c b/api-tests/dev_apis/crypto/test_c054/test_c054.c
index 928c112..6fd3e0e 100644
--- a/api-tests/dev_apis/crypto/test_c054/test_c054.c
+++ b/api-tests/dev_apis/crypto/test_c054/test_c054.c
@@ -26,7 +26,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
int32_t psa_aead_generate_nonce_test(caller_security_t caller __UNUSED)
{
diff --git a/api-tests/dev_apis/crypto/test_c055/test_c055.c b/api-tests/dev_apis/crypto/test_c055/test_c055.c
index 3494a1e..6c65b50 100644
--- a/api-tests/dev_apis/crypto/test_c055/test_c055.c
+++ b/api-tests/dev_apis/crypto/test_c055/test_c055.c
@@ -26,7 +26,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
int32_t psa_aead_set_nonce_test(caller_security_t caller __UNUSED)
{
diff --git a/api-tests/dev_apis/crypto/test_c056/test_c056.c b/api-tests/dev_apis/crypto/test_c056/test_c056.c
index a740e59..bfc9ec9 100644
--- a/api-tests/dev_apis/crypto/test_c056/test_c056.c
+++ b/api-tests/dev_apis/crypto/test_c056/test_c056.c
@@ -26,7 +26,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
int32_t psa_aead_set_lengths_test(caller_security_t caller __UNUSED)
{
diff --git a/api-tests/dev_apis/crypto/test_c057/test_c057.c b/api-tests/dev_apis/crypto/test_c057/test_c057.c
index 5eea36c..8822828 100644
--- a/api-tests/dev_apis/crypto/test_c057/test_c057.c
+++ b/api-tests/dev_apis/crypto/test_c057/test_c057.c
@@ -26,7 +26,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
int32_t psa_aead_update_ad_test(caller_security_t caller __UNUSED)
{
diff --git a/api-tests/dev_apis/crypto/test_c058/test_c058.c b/api-tests/dev_apis/crypto/test_c058/test_c058.c
index db9b17b..dfe85f9 100644
--- a/api-tests/dev_apis/crypto/test_c058/test_c058.c
+++ b/api-tests/dev_apis/crypto/test_c058/test_c058.c
@@ -26,7 +26,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
int32_t psa_aead_update_test(caller_security_t caller __UNUSED)
{
diff --git a/api-tests/dev_apis/crypto/test_c059/test_c059.c b/api-tests/dev_apis/crypto/test_c059/test_c059.c
index ff127a0..16532e4 100644
--- a/api-tests/dev_apis/crypto/test_c059/test_c059.c
+++ b/api-tests/dev_apis/crypto/test_c059/test_c059.c
@@ -26,7 +26,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
static uint8_t output[BUFFER_SIZE], tag[SIZE_128B];
int32_t psa_aead_finish_test(caller_security_t caller __UNUSED)
diff --git a/api-tests/dev_apis/crypto/test_c060/test_c060.c b/api-tests/dev_apis/crypto/test_c060/test_c060.c
index 6d6a80f..c2c15fe 100644
--- a/api-tests/dev_apis/crypto/test_c060/test_c060.c
+++ b/api-tests/dev_apis/crypto/test_c060/test_c060.c
@@ -27,7 +27,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
int32_t psa_aead_abort_test(caller_security_t caller __UNUSED)
{
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 c3cd9e5..435380b 100644
--- a/api-tests/dev_apis/crypto/test_c061/test_c061.c
+++ b/api-tests/dev_apis/crypto/test_c061/test_c061.c
@@ -26,7 +26,7 @@
NULL,
};
-static int g_test_count = 1;
+static uint32_t g_test_count = 1;
static uint8_t output[BUFFER_SIZE], tag[SIZE_128B];
int32_t psa_aead_verify_test(caller_security_t caller __UNUSED)
diff --git a/api-tests/platform/targets/common/nspe/crypto/pal_crypto_intf.c b/api-tests/platform/targets/common/nspe/crypto/pal_crypto_intf.c
index 6776d4f..92f94b2 100644
--- a/api-tests/platform/targets/common/nspe/crypto/pal_crypto_intf.c
+++ b/api-tests/platform/targets/common/nspe/crypto/pal_crypto_intf.c
@@ -36,10 +36,13 @@
const uint8_t *nonce, *additional_data, *salt, *peer;
size_t *length, size, ciphertext_size, nonce_length;
size_t salt_length, peer_length, additional_data_length;
-#ifdef NOT_SUPPORTED
- size_t *tag_length, plaintext_size;
- psa_aead_operation_t *aead_operation;
+#ifdef tgt_dev_apis_stdc
+ size_t plaintext_size;
#endif
+#ifdef NO_SUPPORT
+ size_t *tag_length;
+#endif
+ psa_aead_operation_t *aead_operation;
psa_key_attributes_t *attributes;
psa_key_handle_t *handle, key_handle;
psa_key_type_t *key_type_out, key_type;
@@ -53,6 +56,8 @@
psa_key_derivation_operation_t *derive_operation;
psa_key_derivation_step_t step;
+ (void)aead_operation;
+
switch (type)
{
case PAL_CRYPTO_INIT:
@@ -174,7 +179,7 @@
case PAL_CRYPTO_HASH_ABORT:
hash_operation = va_arg(valist, psa_hash_operation_t*);
return psa_hash_abort(hash_operation);
-#ifdef NOT_SUPPORTED
+#ifdef tgt_dev_apis_stdc
case PAL_CRYPTO_HASH_COMPUTE:
alg = va_arg(valist, psa_algorithm_t);
plaintext = va_arg(valist, uint8_t*);
diff --git a/api-tests/tools/cmake/compiler/ARMCLANG.cmake b/api-tests/tools/cmake/compiler/ARMCLANG.cmake
index 119ab6c..60e222b 100644
--- a/api-tests/tools/cmake/compiler/ARMCLANG.cmake
+++ b/api-tests/tools/cmake/compiler/ARMCLANG.cmake
@@ -58,6 +58,6 @@
set(TARGET_SWITCH "-march=armv8-m.base -mcmse")
endif()
-set(CMAKE_C_FLAGS "--target=arm-arm-none-eabi ${TARGET_SWITCH} -Wall -Werror -Wextra -fshort-enums -fshort-wchar -funsigned-char -fdata-sections -ffunction-sections -mno-unaligned-access -mfpu=none")
+set(CMAKE_C_FLAGS "--target=arm-arm-none-eabi ${TARGET_SWITCH} -g -Wall -Werror -Wextra -fshort-enums -fshort-wchar -funsigned-char -fdata-sections -ffunction-sections -mno-unaligned-access -mfpu=none")
set(CMAKE_ASM_FLAGS "${TARGET_SWITCH} -mthumb")
set(CMAKE_EXE_LINKER_FLAGS "--strict --map --symbols --xref --info=summarysizes,sizes,totals,unused,veneers --diag_warning=L6204")
diff --git a/api-tests/tools/cmake/compiler/GNUARM.cmake b/api-tests/tools/cmake/compiler/GNUARM.cmake
index 62a0b76..20102e1 100644
--- a/api-tests/tools/cmake/compiler/GNUARM.cmake
+++ b/api-tests/tools/cmake/compiler/GNUARM.cmake
@@ -58,6 +58,6 @@
set(TARGET_SWITCH "-march=armv8-m.base -mcmse")
endif()
-set(CMAKE_C_FLAGS "${TARGET_SWITCH} -Wall -Werror -Wextra -fdata-sections -ffunction-sections -mno-unaligned-access")
+set(CMAKE_C_FLAGS "${TARGET_SWITCH} -g -Wall -Werror -Wextra -fdata-sections -ffunction-sections -mno-unaligned-access")
set(CMAKE_ASM_FLAGS "${TARGET_SWITCH} -mthumb")
set(CMAKE_EXE_LINKER_FLAGS "-Xlinker --fatal-warnings -Xlinker --gc-sections -z max-page-size=0x400 -lgcc -lc -lnosys")
diff --git a/api-tests/tools/cmake/compiler/HOST_GCC.cmake b/api-tests/tools/cmake/compiler/HOST_GCC.cmake
index e7be183..b26ed76 100644
--- a/api-tests/tools/cmake/compiler/HOST_GCC.cmake
+++ b/api-tests/tools/cmake/compiler/HOST_GCC.cmake
@@ -47,5 +47,6 @@
foreach(_LNG IN ITEMS "C" "ASM")
set(CMAKE_${_LNG}_COMPILER ${_C_TOOLCHAIN_PATH})
+ set(CMAKE_C_FLAGS "-g -Wall -Werror -Werror")
message(STATUS "[PSA] : ${_LNG} compiler used '${CMAKE_${_LNG}_COMPILER}'")
endforeach()
diff --git a/api-tests/val/nspe/val_crypto.h b/api-tests/val/nspe/val_crypto.h
index 8956d56..7270a40 100644
--- a/api-tests/val/nspe/val_crypto.h
+++ b/api-tests/val/nspe/val_crypto.h
@@ -1,5 +1,5 @@
/** @file
- * Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
+ * Copyright (c) 2018-2020, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,8 +29,8 @@
#define AES_18B_KEY_SIZE 18
#define AES_34B_KEY_SIZE 34
#define DES_8B_KEY_SIZE 8
-#define DES3_2KEY_SIZE 16
-#define DES3_3KEY_SIZE 24
+#define DES3_2B_KEY_SIZE 16
+#define DES3_3B_KEY_SIZE 24
#define SIZE_32B 32
#define SIZE_50B 50
#define SIZE_128B 128