Skip to content

Commit b61e60f

Browse files
author
Andrzej Kurek
committed
Test clear text writing to and reading from a slot
Generate random data, write it to a slot and verify with a read
1 parent 8061ace commit b61e60f

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

atecc608a_utils.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,20 @@ psa_status_t atecc608a_check_config_locked()
6161
}
6262
return status;
6363
}
64+
65+
psa_status_t atecc608a_random(uint8_t *rand_out)
66+
{
67+
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
68+
69+
if (rand_out == NULL)
70+
{
71+
return PSA_ERROR_INVALID_ARGUMENT;
72+
}
73+
74+
ASSERT_SUCCESS_PSA(atecc608a_init());
75+
ASSERT_SUCCESS(atcab_random(rand_out));
76+
77+
exit:
78+
atecc608a_deinit();
79+
return status;
80+
}

atecc608a_utils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,7 @@ 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+
/** Generate a 32 byte random number from the CryptoAuth device. */
65+
psa_status_t atecc608a_random(uint8_t *rand_out);
66+
6467
#endif /* ATECC608A_SE_H */

main.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,24 @@ psa_status_t atecc608a_print_config_zone()
117117
return status;
118118
}
119119

120+
#define TEST_WRITE_READ_SIZE 32
121+
psa_status_t test_write_read_slot(uint16_t slot)
122+
{
123+
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
124+
uint8_t data_write[TEST_WRITE_READ_SIZE] = {};
125+
uint8_t data_read[TEST_WRITE_READ_SIZE] = {};
126+
127+
ASSERT_SUCCESS_PSA(atecc608a_random(data_write));
128+
ASSERT_SUCCESS_PSA(atecc608a_write(slot, 0, data_write, TEST_WRITE_READ_SIZE));
129+
ASSERT_SUCCESS_PSA(atecc608a_read(slot, 0, data_read, TEST_WRITE_READ_SIZE));
130+
ASSERT_STATUS(memcmp(data_write, data_read, TEST_WRITE_READ_SIZE),
131+
0, PSA_ERROR_HARDWARE_FAILURE);
132+
133+
printf("test_write_read_slot succesful!\n");
134+
exit:
135+
return status;
136+
}
137+
120138
int main(void)
121139
{
122140
enum {
@@ -172,6 +190,8 @@ int main(void)
172190
/* Verify that the device has a locked config before doing anything */
173191
ASSERT_SUCCESS_PSA(atecc608a_check_config_locked());
174192

193+
test_write_read_slot(8);
194+
175195
ASSERT_SUCCESS_PSA(atecc608a_drv_info.p_key_management->p_export(
176196
atecc608a_key_slot_device, pubkey, sizeof(pubkey),
177197
&pubkey_len));

tests/atecc608a.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ Success!
44
SHA-256:
55
Success!
66
- Config locked: 1
7+
test_write_read_slot succesful!
78
Verification successful!

0 commit comments

Comments
 (0)