@@ -211,6 +211,53 @@ static psa_status_t atecc608a_import_public_key(psa_key_slot_number_t key_slot,
211
211
return status ;
212
212
}
213
213
214
+ static psa_status_t atecc608a_generate_key (psa_key_slot_number_t key_slot ,
215
+ psa_key_type_t type ,
216
+ psa_key_usage_t usage ,
217
+ size_t bits ,
218
+ const void * extra ,
219
+ size_t extra_size ,
220
+ uint8_t * p_pubkey_out ,
221
+ size_t pubkey_out_size ,
222
+ size_t * p_pubkey_length )
223
+ {
224
+ const uint16_t key_id = key_slot ;
225
+ psa_status_t status = PSA_ERROR_GENERIC_ERROR ;
226
+
227
+ /* The hardware has slots 0-15 */
228
+ if (key_slot > 15 )
229
+ {
230
+ return PSA_ERROR_INVALID_ARGUMENT ;
231
+ }
232
+
233
+ if (type != PSA_KEY_TYPE_ECC_KEYPAIR (PSA_ECC_CURVE_SECP256R1 ))
234
+ {
235
+ return PSA_ERROR_NOT_SUPPORTED ;
236
+ }
237
+
238
+ if (bits != PSA_BYTES_TO_BITS (ATCA_PRIV_KEY_SIZE ))
239
+ {
240
+ return PSA_ERROR_NOT_SUPPORTED ;
241
+ }
242
+
243
+ if (p_pubkey_out != NULL && pubkey_out_size < ATCA_PUB_KEY_SIZE )
244
+ {
245
+ return PSA_ERROR_BUFFER_TOO_SMALL ;
246
+ }
247
+
248
+ ASSERT_SUCCESS_PSA (atecc608a_init ());
249
+ ASSERT_SUCCESS (atcab_genkey (key_id , p_pubkey_out ));
250
+
251
+ if (p_pubkey_length != NULL )
252
+ {
253
+ * p_pubkey_length = ATCA_PUB_KEY_SIZE ;
254
+ }
255
+
256
+ exit :
257
+ atecc608a_deinit ();
258
+ return status ;
259
+ }
260
+
214
261
static psa_status_t atecc608a_asymmetric_sign (psa_key_slot_number_t key_slot ,
215
262
psa_algorithm_t alg ,
216
263
const uint8_t * p_hash ,
@@ -311,7 +358,7 @@ static psa_drv_se_key_management_t atecc608a_key_management =
311
358
{
312
359
/* So far there is no public key import function in the API, so use this instead */
313
360
.p_import = atecc608a_import_public_key ,
314
- .p_generate = 0 ,
361
+ .p_generate = atecc608a_generate_key ,
315
362
.p_destroy = 0 ,
316
363
/* So far there is no public key export function in the API, so use this instead */
317
364
.p_export = atecc608a_export_public_key ,
0 commit comments