Skip to content

Commit 0aa08fc

Browse files
authored
Merge pull request #4 from AndrzejKurek/private_key_generation
Use the driver version of private key generation
2 parents b767d9a + 020807d commit 0aa08fc

File tree

4 files changed

+19
-21
lines changed

4 files changed

+19
-21
lines changed

atecc608a_utils.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,3 @@ psa_status_t atecc608a_check_config_locked()
6161
}
6262
return status;
6363
}
64-
65-
psa_status_t atecc608a_generate_key(uint16_t slot, uint8_t *pubkey, size_t pubkey_size)
66-
{
67-
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
68-
if (pubkey != NULL && pubkey_size < ATCA_PUB_KEY_SIZE)
69-
{
70-
return PSA_ERROR_BUFFER_TOO_SMALL;
71-
}
72-
73-
ASSERT_SUCCESS_PSA(atecc608a_init());
74-
ASSERT_SUCCESS(atcab_genkey(slot, pubkey));
75-
76-
exit:
77-
atecc608a_deinit();
78-
return status;
79-
}

atecc608a_utils.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,4 @@ psa_status_t atecc608a_get_serial_number(uint8_t *buffer, size_t buffer_size,
6161

6262
psa_status_t atecc608a_check_config_locked();
6363

64-
psa_status_t atecc608a_generate_key(uint16_t slot, uint8_t *pubkey, size_t pubkey_size);
65-
6664
#endif /* ATECC608A_SE_H */

main.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ int main(void)
147147

148148
atecc608a_print_serial_number();
149149
atecc608a_print_config_zone();
150-
ASSERT_SUCCESS_PSA(atecc608a_generate_key(atecc608a_key_slot_device, pubkey, pubkey_size));
151-
atcab_printbin_label("pubKey generated: ", pubkey, ATCA_PUB_KEY_SIZE);
152150

153151
ASSERT_SUCCESS_PSA(atecc608a_hash_sha256(hash_input1,
154152
sizeof(hash_input1) - 1,
@@ -167,6 +165,21 @@ int main(void)
167165
/* Verify that the device has a locked config before doing anything */
168166
ASSERT_SUCCESS_PSA(atecc608a_check_config_locked());
169167

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 */
170183
ASSERT_SUCCESS_PSA(atecc608a_drv_info.p_key_management->p_export(
171184
atecc608a_key_slot_device, pubkey, sizeof(pubkey),
172185
&pubkey_len));
@@ -177,13 +190,16 @@ int main(void)
177190
key_type, alg, PSA_KEY_USAGE_VERIFY, pubkey,
178191
pubkey_len));
179192

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

184199
ASSERT_SUCCESS_PSA(atecc608a_drv_info.p_asym->p_verify(
185200
atecc608a_public_key_slot, alg, hash, sizeof(hash),
186201
signature, signature_length));
202+
187203
/*
188204
* Import the secure element's public key into a volatile key slot.
189205
*/

mbed-os-atecc608a.lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
git@github.com:ARMmbed/mbed-os-atecc608a/#b43091e170053864a0cf1199186160e8e7ffc337
1+
https://github.com/ARMmbed/mbed-os-atecc608a/#bae7de43d835aea03c4fd7af382232d8b5d26ad7

0 commit comments

Comments
 (0)