Skip to content

Commit ae0e5db

Browse files
author
Andrzej Kurek
committed
Add writing and reading raw data into/from a slot
1 parent bae7de4 commit ae0e5db

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

atecc608a_se.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,42 @@ psa_status_t atecc608a_asymmetric_verify(psa_key_slot_number_t key_slot,
367367
return status;
368368
}
369369

370+
psa_status_t atecc608a_write(uint16_t slot, size_t offset, const uint8_t *data, size_t length)
371+
{
372+
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
373+
374+
/* The hardware has slots 0-15 */
375+
if (slot > 15)
376+
{
377+
return PSA_ERROR_INVALID_ARGUMENT;
378+
}
379+
380+
ASSERT_SUCCESS_PSA(atecc608a_init());
381+
ASSERT_SUCCESS(atcab_write_bytes_zone(ATCA_ZONE_DATA, slot, offset, data, length));
382+
383+
exit:
384+
atecc608a_deinit();
385+
return status;
386+
}
387+
388+
psa_status_t atecc608a_read(uint16_t slot, size_t offset, uint8_t *data, size_t length)
389+
{
390+
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
391+
392+
/* The hardware has slots 0-15 */
393+
if (slot > 15)
394+
{
395+
return PSA_ERROR_INVALID_ARGUMENT;
396+
}
397+
398+
ASSERT_SUCCESS_PSA(atecc608a_init());
399+
ASSERT_SUCCESS(atcab_read_bytes_zone(ATCA_ZONE_DATA, slot, offset, data, length));
400+
401+
exit:
402+
atecc608a_deinit();
403+
return status;
404+
}
405+
370406
#define PSA_ATECC608A_LIFETIME 0xdeadbeefU
371407

372408
static psa_drv_se_asymmetric_t atecc608a_asymmetric =

atecc608a_se.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,14 @@ psa_status_t atecc608a_init();
3434

3535
psa_status_t atecc608a_deinit();
3636

37+
/** Read from a given slot at an offset. Data zone has to be locked for this
38+
* function to work. */
39+
psa_status_t atecc608a_read(uint16_t slot, size_t offset, uint8_t *data, size_t length);
40+
41+
/** Write to a given slot at an offset. If the data zone is locked, offset and
42+
* length must be multiples of a word (4 bytes). If the data zone is unlocked,
43+
* only 32-byte writes are allowed, and the offset and length must be
44+
* multiples of 32. */
45+
psa_status_t atecc608a_write(uint16_t slot, size_t offset, const uint8_t *data, size_t length);
46+
3747
#endif /* ATECC608A_SE_H */

0 commit comments

Comments
 (0)