@@ -142,7 +142,10 @@ static psa_status_t atecc608a_export_public_key(psa_key_slot_number_t key,
142
142
uint8_t * p_data , size_t data_size ,
143
143
size_t * p_data_length )
144
144
{
145
- const size_t key_data_len = 65 ;
145
+ const size_t key_data_len = PSA_KEY_EXPORT_MAX_SIZE (
146
+ PSA_KEY_TYPE_ECC_PUBLIC_KEY (
147
+ PSA_ECC_CURVE_SECP256R1 ),
148
+ 256 );
146
149
const uint16_t slot = key ;
147
150
psa_status_t status = PSA_ERROR_GENERIC_ERROR ;
148
151
@@ -223,6 +226,10 @@ static psa_status_t atecc608a_generate_key(psa_key_slot_number_t key_slot,
223
226
{
224
227
const uint16_t key_id = key_slot ;
225
228
psa_status_t status = PSA_ERROR_GENERIC_ERROR ;
229
+ const size_t key_data_len = PSA_KEY_EXPORT_MAX_SIZE (
230
+ PSA_KEY_TYPE_ECC_PUBLIC_KEY (
231
+ PSA_ECC_CURVE_SECP256R1 ),
232
+ 256 );
226
233
227
234
/* The hardware has slots 0-15 */
228
235
if (key_slot > 15 )
@@ -240,17 +247,29 @@ static psa_status_t atecc608a_generate_key(psa_key_slot_number_t key_slot,
240
247
return PSA_ERROR_NOT_SUPPORTED ;
241
248
}
242
249
243
- if (p_pubkey_out != NULL && pubkey_out_size < ATCA_PUB_KEY_SIZE )
250
+ if (p_pubkey_out != NULL && pubkey_out_size < key_data_len )
244
251
{
245
252
return PSA_ERROR_BUFFER_TOO_SMALL ;
246
253
}
247
254
248
255
ASSERT_SUCCESS_PSA (atecc608a_init ());
249
- ASSERT_SUCCESS (atcab_genkey (key_id , p_pubkey_out ));
256
+
257
+ if (p_pubkey_out != NULL )
258
+ {
259
+ /* atcab_genkey returns concatenated x and y values, and the desired
260
+ * format is 0x04 + x + y. Start at &p_pubkey_out[1] and add a 0x04
261
+ * at p_pubkey_out[0]. */
262
+ ASSERT_SUCCESS (atcab_genkey (key_id , & p_pubkey_out [1 ]));
263
+ p_pubkey_out [0 ] = 4 ;
264
+ }
265
+ else
266
+ {
267
+ ASSERT_SUCCESS (atcab_genkey (key_id , NULL ));
268
+ }
250
269
251
270
if (p_pubkey_length != NULL )
252
271
{
253
- * p_pubkey_length = ATCA_PUB_KEY_SIZE ;
272
+ * p_pubkey_length = key_data_len ;
254
273
}
255
274
256
275
exit :
0 commit comments