Skip to content

Commit 650ab67

Browse files
author
Andrzej Kurek
committed
Add writing and reading raw data into/from a slot
1 parent 3b35842 commit 650ab67

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
@@ -363,6 +363,42 @@ psa_status_t atecc608a_asymmetric_verify(psa_key_slot_number_t key_slot,
363363
return status;
364364
}
365365

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

368404
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)