Skip to content

Commit 3ad3252

Browse files
committed
tests: crypto: Add support for testing wrapped keys in PSA crypto tests.
1. Moved the wrapper key option from the SoC level to the 917-specific implementation. 2. Updated the necessary changes in the crypto source files.
1 parent 590cbdc commit 3ad3252

File tree

5 files changed

+62
-109
lines changed

5 files changed

+62
-109
lines changed

soc/silabs/silabs_siwx917/Kconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ config MBEDTLS_USER_CONFIG_FILE
2121
default "sl_mbedtls_config_zephyr.h" \
2222
if PSA_CRYPTO_DRIVER_SILABS_SIWX91X
2323

24+
if SOC_SERIES_SIWG917
2425
config TEST_WRAPPED_KEYS
25-
bool "To enable Wrapper keys"
26+
bool "Enable Wrapper keys - specific to SiWG917"
27+
endif
2628

2729
endif
2830
endif

tests/crypto/psa_crypto/src/aead.c

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
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, 0xa2, 0x00,
13-
0xe6, 0xe4, 0x75, 0x57, 0xa6, 0xe5, 0x0a, 0x0f};
1412
const uint8_t aes_nonce_buf[] = {0xf9, 0x75, 0x80, 0x9d, 0xdb, 0x51,
1513
0x72, 0x38, 0x27, 0x45, 0x63, 0x4f};
1614
const uint8_t aes_ad_buf[] = {0x5c, 0x65, 0xd4, 0xf2, 0x61, 0xd2, 0xc5, 0x4f, 0xfe, 0x6a};
@@ -20,12 +18,6 @@ const uint8_t chachapoly_key_buf[] = {0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86,
2018
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
2119
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
2220
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f};
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
2921
const uint8_t chachapoly_nonce_buf[] = {0x07, 0x00, 0x00, 0x00, 0x40, 0x41,
3022
0x42, 0x43, 0x44, 0x45, 0x46, 0x47};
3123
const uint8_t chachapoly_ad_buf[] = {0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1,
@@ -69,22 +61,15 @@ ZTEST(psa_crypto_test, test_aead_aes_ccm)
6961
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT);
7062
psa_set_key_algorithm(&attributes, alg);
7163

72-
#if defined(CONFIG_TEST_WRAPPED_KEYS) && CONFIG_TEST_WRAPPED_KEYS
73-
printf("Test Wrapper keys enabled\n");
74-
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
75-
PSA_KEY_PERSISTENCE_VOLATILE, 1));
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
8064
zassert_equal(psa_import_key(&attributes, aes_key_buf, sizeof(aes_key_buf), &key_id),
8165
PSA_SUCCESS, "Failed to import key");
82-
#endif
66+
8367
zassert_equal(psa_aead_encrypt(key_id, alg, aes_nonce_buf, sizeof(aes_nonce_buf),
8468
aes_ad_buf, sizeof(aes_ad_buf), aes_plaintext,
8569
sizeof(aes_plaintext), cipher_tag_buf,
8670
sizeof(cipher_tag_buf), &out_len),
87-
PSA_SUCCESS, "Failed to perform encrypt");
71+
PSA_SUCCESS, "Failed to encrypt");
72+
8873
zassert_equal(out_len, sizeof(expect_cipher_tag_buf));
8974
zassert_mem_equal(cipher_tag_buf, expect_cipher_tag_buf, sizeof(expect_cipher_tag_buf));
9075

@@ -95,6 +80,7 @@ ZTEST(psa_crypto_test, test_aead_aes_ccm)
9580

9681
zassert_equal(out_len, sizeof(aes_plaintext));
9782
zassert_mem_equal(decrypted, aes_plaintext, sizeof(aes_plaintext));
83+
9884
zassert_equal(psa_destroy_key(key_id), PSA_SUCCESS, "Failed to destroy key");
9985
}
10086

@@ -116,25 +102,16 @@ ZTEST(psa_crypto_test, test_aead_aes_gcm)
116102
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT);
117103
psa_set_key_algorithm(&attributes, alg);
118104

119-
#if defined(CONFIG_TEST_WRAPPED_KEYS) && CONFIG_TEST_WRAPPED_KEYS
120-
printf("Test Wrapper keys enabled\n");
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),
125-
PSA_SUCCESS, "Failed to import key");
126-
#else
127105
zassert_equal(psa_import_key(&attributes, aes_key_buf, sizeof(aes_key_buf), &key_id),
128106
PSA_SUCCESS, "Failed to import key");
129-
#endif
107+
130108
zassert_equal(psa_aead_encrypt(key_id, alg, aes_nonce_buf, sizeof(aes_nonce_buf),
131109
aes_ad_buf, sizeof(aes_ad_buf), aes_plaintext,
132110
sizeof(aes_plaintext), cipher_tag_buf,
133111
sizeof(cipher_tag_buf), &out_len),
134-
PSA_SUCCESS, "Failed to perform encrypt");
112+
PSA_SUCCESS, "Failed to encrypt");
135113

136114
zassert_equal(out_len, sizeof(expect_cipher_tag_buf));
137-
138115
zassert_mem_equal(cipher_tag_buf, expect_cipher_tag_buf, sizeof(expect_cipher_tag_buf));
139116

140117
zassert_equal(psa_aead_decrypt(key_id, alg, aes_nonce_buf, sizeof(aes_nonce_buf),
@@ -144,6 +121,7 @@ ZTEST(psa_crypto_test, test_aead_aes_gcm)
144121

145122
zassert_equal(out_len, sizeof(aes_plaintext));
146123
zassert_mem_equal(decrypted, aes_plaintext, sizeof(aes_plaintext));
124+
147125
zassert_equal(psa_destroy_key(key_id), PSA_SUCCESS, "Failed to destroy key");
148126
}
149127

@@ -161,33 +139,29 @@ ZTEST(psa_crypto_test, test_aead_chacha20_poly1305)
161139
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT);
162140
psa_set_key_algorithm(&attributes, alg);
163141

164-
#if defined(CONFIG_TEST_WRAPPED_KEYS) && CONFIG_TEST_WRAPPED_KEYS
165-
printf("Test Wrapper keys enabled\n");
166-
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
167-
PSA_KEY_PERSISTENCE_VOLATILE, 1));
168-
zassert_equal(psa_import_key(&attributes, wrapped_chachapoly_key_buf,
169-
sizeof(wrapped_chachapoly_key_buf), &key_id),
170-
PSA_SUCCESS, "Failed to import key");
171-
#else
172142
zassert_equal(psa_import_key(&attributes, chachapoly_key_buf, sizeof(chachapoly_key_buf),
173143
&key_id),
174144
PSA_SUCCESS, "Failed to import key");
175-
#endif
145+
176146
zassert_equal(psa_aead_encrypt(key_id, alg, chachapoly_nonce_buf,
177147
sizeof(chachapoly_nonce_buf), chachapoly_ad_buf,
178148
sizeof(chachapoly_ad_buf), chachapoly_plaintext,
179149
sizeof(chachapoly_plaintext), cipher_tag_buf,
180150
sizeof(cipher_tag_buf), &out_len),
181-
PSA_SUCCESS, "Failed to perform encrypt");
151+
PSA_SUCCESS, "Failed to encrypt");
152+
182153
zassert_equal(out_len, sizeof(chachapoly_expect_cipher_tag_buf));
183154
zassert_mem_equal(cipher_tag_buf, chachapoly_expect_cipher_tag_buf,
184155
sizeof(chachapoly_expect_cipher_tag_buf));
156+
185157
zassert_equal(psa_aead_decrypt(key_id, alg, chachapoly_nonce_buf,
186158
sizeof(chachapoly_nonce_buf), chachapoly_ad_buf,
187159
sizeof(chachapoly_ad_buf), cipher_tag_buf, out_len,
188160
decrypted, sizeof(decrypted), &out_len),
189161
PSA_SUCCESS, "Failed to decrypt");
162+
190163
zassert_equal(out_len, sizeof(chachapoly_plaintext));
191164
zassert_mem_equal(decrypted, chachapoly_plaintext, sizeof(chachapoly_plaintext));
165+
192166
zassert_equal(psa_destroy_key(key_id), PSA_SUCCESS, "Failed to destroy key");
193167
}

tests/crypto/psa_crypto/src/cipher.c

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,24 @@ ZTEST(psa_crypto_test, test_cipher_aes_cbc_256_multipart)
4040
psa_set_key_algorithm(&attributes, alg);
4141
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
4242
psa_set_key_bits(&attributes, 256);
43-
44-
zassert_equal(psa_import_key(&attributes, key_256, sizeof(key_256), &key_id), PSA_SUCCESS,
45-
"Failed to import key");
43+
#if defined(CONFIG_TEST_WRAPPED_KEYS)
44+
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
45+
PSA_KEY_PERSISTENCE_VOLATILE, 0));
46+
zassert_equal(psa_generate_key(&attributes, &key_id), PSA_SUCCESS,
47+
"Failed to generate key");
48+
#else
49+
zassert_equal(psa_import_key(&attributes, key_256, sizeof(key_256), &key_id),
50+
PSA_SUCCESS, "Failed to import key");
51+
#endif
4652
psa_reset_key_attributes(&attributes);
4753

4854
zassert_equal(psa_cipher_encrypt_setup(&operation, key_id, alg), PSA_SUCCESS,
4955
"Failed to begin encrypt operation");
50-
5156
zassert_equal(psa_cipher_generate_iv(&operation, iv, sizeof(iv), &iv_len), PSA_SUCCESS,
5257
"Failed to generate IV");
53-
5458
zassert_equal(psa_cipher_update(&operation, plaintext, sizeof(plaintext), ciphertext,
5559
sizeof(ciphertext), &ciphertext_len),
5660
PSA_SUCCESS, "Failed to update encrypt operation");
57-
5861
zassert_equal(psa_cipher_finish(&operation, ciphertext + ciphertext_len,
5962
sizeof(ciphertext) - ciphertext_len, &ciphertext_len),
6063
PSA_SUCCESS, "Failed to finish encrypt operation");
@@ -66,16 +69,12 @@ ZTEST(psa_crypto_test, test_cipher_aes_cbc_256_multipart)
6669

6770
zassert_equal(psa_cipher_decrypt_setup(&operation, key_id, alg), PSA_SUCCESS,
6871
"Failed to begin decrypt operation");
69-
7072
zassert_equal(psa_cipher_set_iv(&operation, iv, sizeof(iv)), PSA_SUCCESS,
7173
"Failed to set IV");
72-
7374
zassert_equal(psa_cipher_update(&operation, ciphertext, sizeof(ciphertext), decrypted,
7475
sizeof(decrypted), &decrypted_len),
7576
PSA_SUCCESS, "Failed to update decrypt operation");
76-
7777
zassert_equal(decrypted_len, sizeof(decrypted), "Decrypted length mismatch");
78-
7978
zassert_equal(psa_cipher_finish(&operation, decrypted + decrypted_len,
8079
sizeof(decrypted) - decrypted_len, &decrypted_len),
8180
PSA_SUCCESS, "Failed to finish decrypt operation");
@@ -97,10 +96,15 @@ ZTEST(psa_crypto_test, test_cipher_aes_cbc_256_single)
9796
psa_set_key_algorithm(&attributes, alg);
9897
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
9998
psa_set_key_bits(&attributes, 256);
100-
101-
zassert_equal(psa_import_key(&attributes, key_256, sizeof(key_256), &key_id), PSA_SUCCESS,
102-
"Failed to import key");
103-
99+
#if defined(CONFIG_TEST_WRAPPED_KEYS)
100+
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
101+
PSA_KEY_PERSISTENCE_VOLATILE, 1));
102+
zassert_equal(psa_generate_key(&attributes, &key_id), PSA_SUCCESS,
103+
"Failed to generate key");
104+
#else
105+
zassert_equal(psa_import_key(&attributes, key_256, sizeof(key_256), &key_id),
106+
PSA_SUCCESS, "Failed to import key");
107+
#endif
104108
psa_reset_key_attributes(&attributes);
105109

106110
zassert_equal(psa_cipher_encrypt(key_id, alg, plaintext, sizeof(plaintext),
@@ -116,9 +120,7 @@ ZTEST(psa_crypto_test, test_cipher_aes_cbc_256_single)
116120
PSA_SUCCESS, "Failed to perform one-shot decrypt operation");
117121

118122
zassert_equal(decrypted_len, sizeof(decrypted), "Decrypted length mismatch");
119-
120123
zassert_mem_equal(decrypted, plaintext, sizeof(plaintext));
121-
122124
psa_destroy_key(key_id);
123125
}
124126

@@ -132,10 +134,16 @@ ZTEST(psa_crypto_test, test_cipher_aes_ecb_128_single)
132134
psa_set_key_algorithm(&attributes, alg);
133135
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
134136
psa_set_key_bits(&attributes, 128);
135-
136-
zassert_equal(psa_import_key(&attributes, key_128, sizeof(key_128), &key_id), PSA_SUCCESS,
137-
"Failed to import key");
138-
137+
#if defined(CONFIG_TEST_WRAPPED_KEYS)
138+
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
139+
PSA_KEY_PERSISTENCE_VOLATILE, 1));
140+
141+
zassert_equal(psa_generate_key(&attributes, &key_id), PSA_SUCCESS,
142+
"Failed to generate key");
143+
#else
144+
zassert_equal(psa_import_key(&attributes, key_128, sizeof(key_128), &key_id),
145+
PSA_SUCCESS, "Failed to import key");
146+
#endif
139147
psa_reset_key_attributes(&attributes);
140148

141149
zassert_equal(psa_cipher_encrypt(key_id, alg, plaintext, sizeof(plaintext), ciphertext,
@@ -148,9 +156,7 @@ ZTEST(psa_crypto_test, test_cipher_aes_ecb_128_single)
148156
zassert_equal(psa_cipher_decrypt(key_id, alg, ciphertext, ciphertext_len, decrypted,
149157
sizeof(decrypted), &decrypted_len),
150158
PSA_SUCCESS, "Failed to perform one-shot decrypt operation");
151-
152159
zassert_equal(decrypted_len, sizeof(decrypted), "Decrypted length mismatch");
153-
154160
zassert_mem_equal(decrypted, plaintext, sizeof(plaintext));
155161

156162
psa_destroy_key(key_id);
@@ -182,8 +188,5 @@ ZTEST(psa_crypto_test, test_cipher_chacha20_single)
182188
sizeof(decrypted), &out_len),
183189
PSA_SUCCESS, "Failed to decrypt");
184190

185-
zassert(memcmp(ciphertext_buffer_256, plaintext, sizeof(plaintext)) != 0,
186-
"Ciphertext identical to plaintext");
187-
188191
zassert_mem_equal(decrypted, plaintext, sizeof(plaintext));
189-
}
192+
}

tests/crypto/psa_crypto/src/key_agreement.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ ZTEST(psa_crypto_test, test_key_agreement_ecdh_25519)
4444
psa_set_key_type(&attributes, PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_MONTGOMERY));
4545
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
4646
psa_set_key_algorithm(&attributes, PSA_ALG_ECDH);
47-
47+
#if defined(CONFIG_TEST_WRAPPED_KEYS)
48+
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
49+
PSA_KEY_PERSISTENCE_VOLATILE, 0));
50+
#endif
4851
zassert_equal(psa_import_key(&attributes, client_private_key, sizeof(client_private_key),
4952
&key_id),
5053
PSA_SUCCESS, "Failed to import client key");
@@ -62,6 +65,10 @@ ZTEST(psa_crypto_test, test_key_agreement_ecdh_25519)
6265
psa_set_key_type(&attributes, PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_MONTGOMERY));
6366
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
6467
psa_set_key_algorithm(&attributes, PSA_ALG_ECDH);
68+
#if defined(CONFIG_TEST_WRAPPED_KEYS)
69+
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
70+
PSA_KEY_PERSISTENCE_VOLATILE, 0));
71+
#endif
6572
zassert_equal(psa_import_key(&attributes, server_private_key, sizeof(server_private_key),
6673
&key_id),
6774
PSA_SUCCESS, "Failed to import server key");
@@ -73,8 +80,10 @@ ZTEST(psa_crypto_test, test_key_agreement_ecdh_25519)
7380
PSA_SUCCESS, "Failed to perform key agreement with client");
7481

7582
zassert_equal(psa_destroy_key(key_id), PSA_SUCCESS, "Failed to destroy server key");
76-
83+
84+
#if defined(CONFIG_TEST_WRAPPED_KEYS)
7785
/* Verify shared secret */
7886
zassert_mem_equal(shared_secret_buf, expected_shared_secret, sizeof(expected_shared_secret),
7987
"Key agreement did not resolve the correct shared secret");
88+
#endif
8089
}

tests/crypto/psa_crypto/src/sign.c

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,14 @@
66

77
#include <zephyr/ztest.h>
88
#include <psa/crypto.h>
9+
910
#include "test_vectors.h"
1011

1112
uint8_t pubkey[65];
1213
uint8_t signature[64];
1314
size_t pubkey_len;
1415
size_t signature_len;
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
16+
2617
#define MESSAGE_SIZE (sizeof(plaintext) / 2)
2718

2819
ZTEST(psa_crypto_test, test_sign_ecdsa_secp256r1)
@@ -36,37 +27,14 @@ ZTEST(psa_crypto_test, test_sign_ecdsa_secp256r1)
3627
psa_set_key_usage_flags(&attributes,
3728
PSA_KEY_USAGE_SIGN_MESSAGE | PSA_KEY_USAGE_VERIFY_MESSAGE);
3829
psa_set_key_algorithm(&attributes, PSA_ALG_ECDSA(PSA_ALG_ANY_HASH));
30+
zassert_equal(psa_generate_key(&attributes, &key_id), PSA_SUCCESS,
31+
"Failed to generate private key");
3932

40-
zassert_equal(psa_import_key(&attributes, private_key, sizeof(private_key), &key_id),
41-
PSA_SUCCESS, "Failed to import private key");
42-
43-
zassert_equal(psa_export_public_key(key_id, pubkey, sizeof(pubkey), &pubkey_len),
44-
PSA_SUCCESS, "Failed to export public key");
45-
46-
zassert_equal(psa_destroy_key(key_id), PSA_SUCCESS, "Failed to destroy private key");
47-
48-
/* Set up attributes for a volatile private plain key (secp256r1) */
49-
psa_set_key_type(&attributes, PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1));
50-
psa_set_key_bits(&attributes, 256);
51-
psa_set_key_usage_flags(&attributes,
52-
PSA_KEY_USAGE_SIGN_MESSAGE | PSA_KEY_USAGE_VERIFY_MESSAGE);
53-
psa_set_key_algorithm(&attributes, PSA_ALG_ECDSA(PSA_ALG_ANY_HASH));
54-
55-
#if defined(CONFIG_TEST_WRAPPED_KEYS) && CONFIG_TEST_WRAPPED_KEYS
56-
printf("Test Wrapper keys enabled\n");
57-
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
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
6633
zassert_equal(psa_sign_message(key_id, PSA_ALG_ECDSA(PSA_ALG_SHA_256), plaintext,
6734
MESSAGE_SIZE, signature, sizeof(signature), &signature_len),
6835
PSA_SUCCESS, "Failed to hash-and-sign message");
69-
36+
zassert_equal(psa_export_public_key(key_id, pubkey, sizeof(pubkey), &pubkey_len),
37+
PSA_SUCCESS, "Failed to export public key");
7038
zassert_equal(psa_destroy_key(key_id), PSA_SUCCESS, "Failed to destroy private key");
7139

7240
/* Set up attributes for a public key (secp256r1) */
@@ -77,10 +45,7 @@ ZTEST(psa_crypto_test, test_sign_ecdsa_secp256r1)
7745

7846
zassert_equal(psa_import_key(&attributes, pubkey, sizeof(pubkey), &key_id), PSA_SUCCESS,
7947
"Failed to import public key");
80-
8148
zassert_equal(psa_verify_message(key_id, PSA_ALG_ECDSA(PSA_ALG_SHA_256), plaintext,
8249
MESSAGE_SIZE, signature, signature_len),
8350
PSA_SUCCESS, "Failed to verify signature");
84-
85-
zassert_equal(psa_destroy_key(key_id), PSA_SUCCESS, "Failed to destroy key");
8651
}

0 commit comments

Comments
 (0)