Skip to content

Test clear text writing to and reading from a slot #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions atecc608a_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,25 @@ psa_status_t atecc608a_check_config_locked()
}
return status;
}

psa_status_t atecc608a_random_32_bytes(uint8_t *rand_out, size_t buffer_size)
{
psa_status_t status = PSA_ERROR_GENERIC_ERROR;

if (rand_out == NULL)
{
return PSA_ERROR_INVALID_ARGUMENT;
}

if (buffer_size < 32)
{
return PSA_ERROR_BUFFER_TOO_SMALL;
}

ASSERT_SUCCESS_PSA(atecc608a_init());
ASSERT_SUCCESS(atcab_random(rand_out));

exit:
atecc608a_deinit();
return status;
}
3 changes: 3 additions & 0 deletions atecc608a_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@ psa_status_t atecc608a_get_serial_number(uint8_t *buffer, size_t buffer_size,

psa_status_t atecc608a_check_config_locked();

/** Generate a 32 byte random number from the CryptoAuth device. */
psa_status_t atecc608a_random_32_bytes(uint8_t *rand_out, size_t buffer_size);

#endif /* ATECC608A_SE_H */
22 changes: 22 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@ psa_status_t atecc608a_print_config_zone()
return status;
}

#define TEST_WRITE_READ_SIZE 32
psa_status_t test_write_read_slot(uint16_t slot)
{
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
uint8_t data_write[TEST_WRITE_READ_SIZE] = {};
uint8_t data_read[TEST_WRITE_READ_SIZE] = {};

ASSERT_SUCCESS_PSA(atecc608a_random_32_bytes(data_write, TEST_WRITE_READ_SIZE));
ASSERT_SUCCESS_PSA(atecc608a_write(slot, 0, data_write, TEST_WRITE_READ_SIZE));
ASSERT_SUCCESS_PSA(atecc608a_read(slot, 0, data_read, TEST_WRITE_READ_SIZE));
ASSERT_STATUS(memcmp(data_write, data_read, TEST_WRITE_READ_SIZE),
0, PSA_ERROR_HARDWARE_FAILURE);

printf("test_write_read_slot succesful!\n");
exit:
return status;
}

int main(void)
{
enum {
Expand Down Expand Up @@ -165,6 +183,10 @@ int main(void)
/* Verify that the device has a locked config before doing anything */
ASSERT_SUCCESS_PSA(atecc608a_check_config_locked());

/* Slot 8 is usually used as a clear write and read certificate
* or signature slot, as it is the biggest one (416 bytes of space). */
test_write_read_slot(8);

/* Test that a public key received during a private key generation
* can be imported */
ASSERT_SUCCESS_PSA(atecc608a_drv_info.p_key_management->p_generate(
Expand Down
2 changes: 1 addition & 1 deletion mbed-os-atecc608a.lib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/ARMmbed/mbed-os-atecc608a/#bae7de43d835aea03c4fd7af382232d8b5d26ad7
https://github.com/ARMmbed/mbed-os-atecc608a/#5f7e5687b935703f3507aa30aaa9de3f2bc104d0
1 change: 1 addition & 0 deletions tests/atecc608a.log
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ Success!
SHA-256:
Success!
- Config locked: 1
test_write_read_slot succesful!
Verification successful!