Skip to content

Commit ec062b4

Browse files
committed
crypto: psa: Enable wrapped key tests and clean up formatting
1. Cleared indentation errors. 2. Resolved build error. Signed-off-by: Aasim Shaik <[email protected]>
1 parent 3aa73c5 commit ec062b4

File tree

5 files changed

+59
-51
lines changed

5 files changed

+59
-51
lines changed

soc/silabs/silabs_siwx917/Kconfig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ config MBEDTLS_USER_CONFIG_FILE
2222
if PSA_CRYPTO_DRIVER_SILABS_SIWX91X
2323

2424
config TEST_WRAPPED_KEYS
25-
bool "wrapper keys"
26-
default n
27-
25+
bool "To enable Wrapper keys"
26+
s
2827
endif
2928
endif

tests/crypto/psa_crypto/src/aead.c

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
const uint8_t aes_key_buf[] = {0xea, 0x4f, 0x6f, 0x3c, 0x2f, 0xed, 0x2b, 0x9d,
1111
0xd9, 0x70, 0x8c, 0x2e, 0x72, 0x1a, 0xe0, 0x0f};
12-
const uint8_t wrapped_aes_key_buf[] = {0x52, 0xb3, 0x41, 0x71, 0xcf, 0xd6,
13-
0xa2, 0x00, 0xe6, 0xe4, 0x75, 0x57, 0xa6, 0xe5, 0x0a, 0x0f};
12+
const uint8_t wrapped_aes_key_buf[] = {0x52, 0xb3, 0x41, 0x71, 0xcf, 0xd6, 0xa2, 0x00,
13+
0xe6, 0xe4, 0x75, 0x57, 0xa6, 0xe5, 0x0a, 0x0f};
1414
const uint8_t aes_nonce_buf[] = {0xf9, 0x75, 0x80, 0x9d, 0xdb, 0x51,
1515
0x72, 0x38, 0x27, 0x45, 0x63, 0x4f};
1616
const uint8_t aes_ad_buf[] = {0x5c, 0x65, 0xd4, 0xf2, 0x61, 0xd2, 0xc5, 0x4f, 0xfe, 0x6a};
@@ -20,10 +20,12 @@ const uint8_t chachapoly_key_buf[] = {0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86,
2020
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
2121
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
2222
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f};
23-
const uint8_t wrapped_chachapoly_key_buf[] = {0x19, 0x67, 0x03, 0x6a, 0x20, 0xe6, 0x32,
24-
0xed, 0x21, 0x2a, 0x4a, 0xdc, 0x2c, 0x5f, 0x19,
25-
0x22, 0x77, 0x56, 0x61, 0x92, 0x2c, 0xf3, 0xdc,
26-
0xe8, 0x8e, 0x81, 0x45, 0x4d, 0xd6, 0xc7, 0x86, 0x0b};
23+
#if defined(CONFIG_TEST_WRAPPED_KEYS) && CONFIG_TEST_WRAPPED_KEYS
24+
const uint8_t wrapped_chachapoly_key_buf[] = {0x19, 0x67, 0x03, 0x6a, 0x20, 0xe6, 0x32, 0xed,
25+
0x21, 0x2a, 0x4a, 0xdc, 0x2c, 0x5f, 0x19, 0x22,
26+
0x77, 0x56, 0x61, 0x92, 0x2c, 0xf3, 0xdc, 0xe8,
27+
0x8e, 0x81, 0x45, 0x4d, 0xd6, 0xc7, 0x86, 0x0b};
28+
#endif
2729
const uint8_t chachapoly_nonce_buf[] = {0x07, 0x00, 0x00, 0x00, 0x40, 0x41,
2830
0x42, 0x43, 0x44, 0x45, 0x46, 0x47};
2931
const uint8_t chachapoly_ad_buf[] = {0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1,
@@ -67,16 +69,17 @@ ZTEST(psa_crypto_test, test_aead_aes_ccm)
6769
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT);
6870
psa_set_key_algorithm(&attributes, alg);
6971

70-
#if defined(CONFIG_TEST_WRAPPED_KEYS) && CONFIG_TEST_WRAPPED_KEYS
72+
#if defined(CONFIG_TEST_WRAPPED_KEYS) && CONFIG_TEST_WRAPPED_KEYS
7173
printf("Test Wrapper keys enabled\n");
7274
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
7375
PSA_KEY_PERSISTENCE_VOLATILE, 1));
74-
zassert_equal(psa_import_key(&attributes, wrapped_aes_key_buf, sizeof(wrapped_aes_key_buf), &key_id),
75-
PSA_SUCCESS, "Failed to import key");
76-
#else
76+
zassert_equal(psa_import_key(&attributes, wrapped_aes_key_buf, sizeof(wrapped_aes_key_buf),
77+
&key_id),
78+
PSA_SUCCESS, "Failed to import key");
79+
#else
7780
zassert_equal(psa_import_key(&attributes, aes_key_buf, sizeof(aes_key_buf), &key_id),
7881
PSA_SUCCESS, "Failed to import key");
79-
#endif
82+
#endif
8083
zassert_equal(psa_aead_encrypt(key_id, alg, aes_nonce_buf, sizeof(aes_nonce_buf),
8184
aes_ad_buf, sizeof(aes_ad_buf), aes_plaintext,
8285
sizeof(aes_plaintext), cipher_tag_buf,
@@ -113,16 +116,17 @@ ZTEST(psa_crypto_test, test_aead_aes_gcm)
113116
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT);
114117
psa_set_key_algorithm(&attributes, alg);
115118

116-
#if defined(CONFIG_TEST_WRAPPED_KEYS) && CONFIG_TEST_WRAPPED_KEYS
119+
#if defined(CONFIG_TEST_WRAPPED_KEYS) && CONFIG_TEST_WRAPPED_KEYS
117120
printf("Test Wrapper keys enabled\n");
118-
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
119-
PSA_KEY_PERSISTENCE_VOLATILE, 1));
120-
zassert_equal(psa_import_key(&attributes, wrapped_aes_key_buf, sizeof(wrapped_aes_key_buf), &key_id),
121+
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
122+
PSA_KEY_PERSISTENCE_VOLATILE, 1));
123+
zassert_equal(psa_import_key(&attributes, wrapped_aes_key_buf, sizeof(wrapped_aes_key_buf),
124+
&key_id),
121125
PSA_SUCCESS, "Failed to import key");
122-
#else
126+
#else
123127
zassert_equal(psa_import_key(&attributes, aes_key_buf, sizeof(aes_key_buf), &key_id),
124128
PSA_SUCCESS, "Failed to import key");
125-
#endif
129+
#endif
126130
zassert_equal(psa_aead_encrypt(key_id, alg, aes_nonce_buf, sizeof(aes_nonce_buf),
127131
aes_ad_buf, sizeof(aes_ad_buf), aes_plaintext,
128132
sizeof(aes_plaintext), cipher_tag_buf,
@@ -157,17 +161,18 @@ ZTEST(psa_crypto_test, test_aead_chacha20_poly1305)
157161
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT);
158162
psa_set_key_algorithm(&attributes, alg);
159163

160-
#if defined(CONFIG_TEST_WRAPPED_KEYS) && CONFIG_TEST_WRAPPED_KEYS
164+
#if defined(CONFIG_TEST_WRAPPED_KEYS) && CONFIG_TEST_WRAPPED_KEYS
161165
printf("Test Wrapper keys enabled\n");
162166
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
163-
PSA_KEY_PERSISTENCE_VOLATILE, 1));
167+
PSA_KEY_PERSISTENCE_VOLATILE, 1));
164168
zassert_equal(psa_import_key(&attributes, wrapped_chachapoly_key_buf,
165-
sizeof(wrapped_chachapoly_key_buf), &key_id),
166-
PSA_SUCCESS, "Failed to import key");
167-
#else
168-
zassert_equal(psa_import_key(&attributes, chachapoly_key_buf, sizeof(chachapoly_key_buf), &key_id),
169+
sizeof(wrapped_chachapoly_key_buf), &key_id),
170+
PSA_SUCCESS, "Failed to import key");
171+
#else
172+
zassert_equal(psa_import_key(&attributes, chachapoly_key_buf, sizeof(chachapoly_key_buf),
173+
&key_id),
169174
PSA_SUCCESS, "Failed to import key");
170-
#endif
175+
#endif
171176
zassert_equal(psa_aead_encrypt(key_id, alg, chachapoly_nonce_buf,
172177
sizeof(chachapoly_nonce_buf), chachapoly_ad_buf,
173178
sizeof(chachapoly_ad_buf), chachapoly_plaintext,

tests/crypto/psa_crypto/src/cipher.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ ZTEST(psa_crypto_test, test_cipher_aes_cbc_256_multipart)
4141
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
4242
psa_set_key_bits(&attributes, 256);
4343

44-
zassert_equal(psa_import_key(&attributes, key_256, sizeof(key_256), &key_id),
45-
PSA_SUCCESS, "Failed to import key");
44+
zassert_equal(psa_import_key(&attributes, key_256, sizeof(key_256), &key_id), PSA_SUCCESS,
45+
"Failed to import key");
4646
psa_reset_key_attributes(&attributes);
4747

4848
zassert_equal(psa_cipher_encrypt_setup(&operation, key_id, alg), PSA_SUCCESS,
@@ -98,8 +98,8 @@ ZTEST(psa_crypto_test, test_cipher_aes_cbc_256_single)
9898
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
9999
psa_set_key_bits(&attributes, 256);
100100

101-
zassert_equal(psa_import_key(&attributes, key_256, sizeof(key_256), &key_id),
102-
PSA_SUCCESS, "Failed to import key");
101+
zassert_equal(psa_import_key(&attributes, key_256, sizeof(key_256), &key_id), PSA_SUCCESS,
102+
"Failed to import key");
103103

104104
psa_reset_key_attributes(&attributes);
105105

@@ -133,8 +133,8 @@ ZTEST(psa_crypto_test, test_cipher_aes_ecb_128_single)
133133
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
134134
psa_set_key_bits(&attributes, 128);
135135

136-
zassert_equal(psa_import_key(&attributes, key_128, sizeof(key_128), &key_id),
137-
PSA_SUCCESS, "Failed to import key");
136+
zassert_equal(psa_import_key(&attributes, key_128, sizeof(key_128), &key_id), PSA_SUCCESS,
137+
"Failed to import key");
138138

139139
psa_reset_key_attributes(&attributes);
140140

tests/crypto/psa_crypto/src/hash.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,4 @@ ZTEST(psa_crypto_test, test_hash_sha256_multipart)
6161

6262
zassert_mem_equal(hash_buf, expect_sha256_hash, sizeof(expect_sha256_hash),
6363
"Hash mismatch");
64-
6564
}

tests/crypto/psa_crypto/src/sign.c

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ uint8_t pubkey[65];
1212
uint8_t signature[64];
1313
size_t pubkey_len;
1414
size_t signature_len;
15-
static const unsigned char private_key[] = { 0x95, 0xCD, 0x3A, 0x36, 0x25, 0xD6, 0xF6, 0x06, 0xBD, 0xC8, 0x64,
16-
0x77, 0x8D, 0x4A, 0xA6, 0x50, 0xC2, 0xD7, 0x9A, 0x05, 0x94, 0xDD,
17-
0x10, 0xCF, 0x4C, 0x47, 0x4B, 0x83, 0xD2, 0x87, 0x0D, 0x1A };
18-
static const unsigned char wrapped_private_key[] = { 0xd1, 0xd6, 0x56, 0x96, 0x9a, 0x78, 0x46, 0x36, 0xdd,
19-
0xa8, 0xbc, 0x0c, 0xe2, 0xe5, 0xbb, 0xee, 0x05, 0x33, 0x82,
20-
0x0f, 0x7d, 0xc7, 0x12, 0xf4, 0xd9, 0x34, 0x25, 0x00, 0x72,
21-
0x53, 0x95, 0x7d,};
15+
static const unsigned char private_key[] = {0x95, 0xCD, 0x3A, 0x36, 0x25, 0xD6, 0xF6, 0x06,
16+
0xBD, 0xC8, 0x64, 0x77, 0x8D, 0x4A, 0xA6, 0x50,
17+
0xC2, 0xD7, 0x9A, 0x05, 0x94, 0xDD, 0x10, 0xCF,
18+
0x4C, 0x47, 0x4B, 0x83, 0xD2, 0x87, 0x0D, 0x1A};
19+
#if defined(CONFIG_TEST_WRAPPED_KEYS) && CONFIG_TEST_WRAPPED_KEYS
20+
static const unsigned char wrapped_private_key[] = {
21+
0xd1, 0xd6, 0x56, 0x96, 0x9a, 0x78, 0x46, 0x36, 0xdd, 0xa8, 0xbc,
22+
0x0c, 0xe2, 0xe5, 0xbb, 0xee, 0x05, 0x33, 0x82, 0x0f, 0x7d, 0xc7,
23+
0x12, 0xf4, 0xd9, 0x34, 0x25, 0x00, 0x72, 0x53, 0x95, 0x7d,
24+
};
25+
#endif
2226
#define MESSAGE_SIZE (sizeof(plaintext) / 2)
2327

2428
ZTEST(psa_crypto_test, test_sign_ecdsa_secp256r1)
@@ -33,8 +37,8 @@ ZTEST(psa_crypto_test, test_sign_ecdsa_secp256r1)
3337
PSA_KEY_USAGE_SIGN_MESSAGE | PSA_KEY_USAGE_VERIFY_MESSAGE);
3438
psa_set_key_algorithm(&attributes, PSA_ALG_ECDSA(PSA_ALG_ANY_HASH));
3539

36-
zassert_equal(psa_import_key(&attributes,private_key, sizeof(private_key), &key_id), PSA_SUCCESS,
37-
"Failed to import private key");
40+
zassert_equal(psa_import_key(&attributes, private_key, sizeof(private_key), &key_id),
41+
PSA_SUCCESS, "Failed to import private key");
3842

3943
zassert_equal(psa_export_public_key(key_id, pubkey, sizeof(pubkey), &pubkey_len),
4044
PSA_SUCCESS, "Failed to export public key");
@@ -48,16 +52,17 @@ ZTEST(psa_crypto_test, test_sign_ecdsa_secp256r1)
4852
PSA_KEY_USAGE_SIGN_MESSAGE | PSA_KEY_USAGE_VERIFY_MESSAGE);
4953
psa_set_key_algorithm(&attributes, PSA_ALG_ECDSA(PSA_ALG_ANY_HASH));
5054

51-
#if defined(CONFIG_TEST_WRAPPED_KEYS) && CONFIG_TEST_WRAPPED_KEYS
55+
#if defined(CONFIG_TEST_WRAPPED_KEYS) && CONFIG_TEST_WRAPPED_KEYS
5256
printf("Test Wrapper keys enabled\n");
5357
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
54-
PSA_KEY_PERSISTENCE_VOLATILE, 1));
55-
zassert_equal(psa_import_key(&attributes,wrapped_private_key, sizeof(wrapped_private_key),
56-
&key_id), PSA_SUCCESS,"Failed to import private key");
57-
#else
58-
zassert_equal(psa_import_key(&attributes,private_key, sizeof(private_key), &key_id), PSA_SUCCESS,
59-
"Failed to import private key");
60-
#endif
58+
PSA_KEY_PERSISTENCE_VOLATILE, 1));
59+
zassert_equal(psa_import_key(&attributes, wrapped_private_key, sizeof(wrapped_private_key),
60+
&key_id),
61+
PSA_SUCCESS, "Failed to import private key");
62+
#else
63+
zassert_equal(psa_import_key(&attributes, private_key, sizeof(private_key), &key_id),
64+
PSA_SUCCESS, "Failed to import private key");
65+
#endif
6166
zassert_equal(psa_sign_message(key_id, PSA_ALG_ECDSA(PSA_ALG_SHA_256), plaintext,
6267
MESSAGE_SIZE, signature, sizeof(signature), &signature_len),
6368
PSA_SUCCESS, "Failed to hash-and-sign message");

0 commit comments

Comments
 (0)