Skip to content

Commit 74caee6

Browse files
author
Andrzej Kurek
committed
Add a test for the public key format received when generating a private key
1 parent 8061ace commit 74caee6

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

main.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,6 @@ int main(void)
148148
atecc608a_print_serial_number();
149149
atecc608a_print_config_zone();
150150

151-
ASSERT_SUCCESS_PSA(atecc608a_drv_info.p_key_management->p_generate(
152-
atecc608a_key_slot_device, keypair_type,
153-
PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY,
154-
key_bits, NULL, 0, pubkey, pubkey_size, &pubkey_len));
155-
156-
atcab_printbin_label("pubKey generated: ", pubkey, pubkey_len);
157-
158151
ASSERT_SUCCESS_PSA(atecc608a_hash_sha256(hash_input1,
159152
sizeof(hash_input1) - 1,
160153
sha256_expected_hash1,
@@ -172,6 +165,21 @@ int main(void)
172165
/* Verify that the device has a locked config before doing anything */
173166
ASSERT_SUCCESS_PSA(atecc608a_check_config_locked());
174167

168+
/* Test that a public key received during a private key generation
169+
* can be imported */
170+
ASSERT_SUCCESS_PSA(atecc608a_drv_info.p_key_management->p_generate(
171+
atecc608a_key_slot_device, keypair_type,
172+
PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY,
173+
key_bits, NULL, 0, pubkey, pubkey_size, &pubkey_len));
174+
175+
ASSERT_SUCCESS_PSA(atecc608a_drv_info.p_key_management->p_import(
176+
atecc608a_public_key_slot,
177+
atecc608a_drv_info.lifetime,
178+
key_type, alg, PSA_KEY_USAGE_VERIFY, pubkey,
179+
pubkey_len));
180+
181+
/* Test that a public key that is exported from a private key - can be
182+
* imported */
175183
ASSERT_SUCCESS_PSA(atecc608a_drv_info.p_key_management->p_export(
176184
atecc608a_key_slot_device, pubkey, sizeof(pubkey),
177185
&pubkey_len));
@@ -182,13 +190,16 @@ int main(void)
182190
key_type, alg, PSA_KEY_USAGE_VERIFY, pubkey,
183191
pubkey_len));
184192

193+
/* Test that signing using the generated private key and verifying using
194+
* the exported public key works */
185195
ASSERT_SUCCESS_PSA(atecc608a_drv_info.p_asym->p_sign(
186196
atecc608a_key_slot_device, alg, hash, sizeof(hash),
187197
signature, sizeof(signature), &signature_length));
188198

189199
ASSERT_SUCCESS_PSA(atecc608a_drv_info.p_asym->p_verify(
190200
atecc608a_public_key_slot, alg, hash, sizeof(hash),
191201
signature, signature_length));
202+
192203
/*
193204
* Import the secure element's public key into a volatile key slot.
194205
*/

0 commit comments

Comments
 (0)