Skip to content

Commit d027f92

Browse files
authored
Merge pull request #5 from AndrzejKurek/write_read_cleartext_slot
Test clear text writing to and reading from a slot
2 parents 0aa08fc + be82f09 commit d027f92

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

atecc608a_utils.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,25 @@ psa_status_t atecc608a_check_config_locked()
6161
}
6262
return status;
6363
}
64+
65+
psa_status_t atecc608a_random_32_bytes(uint8_t *rand_out, size_t buffer_size)
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+
if (buffer_size < 32)
75+
{
76+
return PSA_ERROR_BUFFER_TOO_SMALL;
77+
}
78+
79+
ASSERT_SUCCESS_PSA(atecc608a_init());
80+
ASSERT_SUCCESS(atcab_random(rand_out));
81+
82+
exit:
83+
atecc608a_deinit();
84+
return status;
85+
}

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_32_bytes(uint8_t *rand_out, size_t buffer_size);
66+
6467
#endif /* ATECC608A_SE_H */

main.c

Lines changed: 22 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_32_bytes(data_write, TEST_WRITE_READ_SIZE));
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 {
@@ -165,6 +183,10 @@ int main(void)
165183
/* Verify that the device has a locked config before doing anything */
166184
ASSERT_SUCCESS_PSA(atecc608a_check_config_locked());
167185

186+
/* Slot 8 is usually used as a clear write and read certificate
187+
* or signature slot, as it is the biggest one (416 bytes of space). */
188+
test_write_read_slot(8);
189+
168190
/* Test that a public key received during a private key generation
169191
* can be imported */
170192
ASSERT_SUCCESS_PSA(atecc608a_drv_info.p_key_management->p_generate(

mbed-os-atecc608a.lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/ARMmbed/mbed-os-atecc608a/#bae7de43d835aea03c4fd7af382232d8b5d26ad7
1+
https://github.com/ARMmbed/mbed-os-atecc608a/#5f7e5687b935703f3507aa30aaa9de3f2bc104d0

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)