Skip to content

Commit 05d77b4

Browse files
authored
Merge pull request #7 from AndrzejKurek/interactive_app
Make the example interactive
2 parents d027f92 + 062d4d6 commit 05d77b4

File tree

4 files changed

+478
-121
lines changed

4 files changed

+478
-121
lines changed

atecc608a_utils.c

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ psa_status_t atecc608a_get_serial_number(uint8_t *buffer,
2929
{
3030
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
3131

32-
if (buffer_size < ATCA_SERIAL_NUM_SIZE)
33-
{
32+
if (buffer_size < ATCA_SERIAL_NUM_SIZE) {
3433
return PSA_ERROR_BUFFER_TOO_SMALL;
3534
}
3635

@@ -44,35 +43,52 @@ psa_status_t atecc608a_get_serial_number(uint8_t *buffer,
4443
return status;
4544
}
4645

47-
psa_status_t atecc608a_check_config_locked()
46+
psa_status_t atecc608a_check_zone_locked(uint8_t zone)
4847
{
49-
bool config_locked;
48+
bool zone_locked;
5049
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
5150

5251
ASSERT_SUCCESS_PSA(atecc608a_init());
5352

54-
ASSERT_SUCCESS(atcab_is_locked(LOCK_ZONE_CONFIG, &config_locked));
53+
ASSERT_SUCCESS(atcab_is_locked(zone, &zone_locked));
5554

5655
exit:
5756
atecc608a_deinit();
58-
if (status == PSA_SUCCESS)
59-
{
60-
status = config_locked? PSA_SUCCESS : PSA_ERROR_HARDWARE_FAILURE;
57+
if (status == PSA_SUCCESS) {
58+
status = zone_locked ? PSA_SUCCESS : PSA_ERROR_HARDWARE_FAILURE;
6159
}
6260
return status;
6361
}
6462

63+
psa_status_t atecc608a_lock_data_zone()
64+
{
65+
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
66+
bool zone_locked;
67+
68+
ASSERT_SUCCESS_PSA(atecc608a_init());
69+
/* atcab_is_locked used instead of atecc608a_check_zone_locked as an
70+
* optimization - this way atecc608a_init won't be called again. */
71+
ASSERT_SUCCESS(atcab_is_locked(LOCK_ZONE_DATA, &zone_locked));
72+
if (zone_locked) {
73+
status = PSA_ERROR_HARDWARE_FAILURE;
74+
goto exit;
75+
}
76+
ASSERT_SUCCESS(atcab_lock_data_zone());
77+
78+
exit:
79+
atecc608a_deinit();
80+
return status;
81+
}
82+
6583
psa_status_t atecc608a_random_32_bytes(uint8_t *rand_out, size_t buffer_size)
6684
{
6785
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
6886

69-
if (rand_out == NULL)
70-
{
87+
if (rand_out == NULL) {
7188
return PSA_ERROR_INVALID_ARGUMENT;
7289
}
7390

74-
if (buffer_size < 32)
75-
{
91+
if (buffer_size < 32) {
7692
return PSA_ERROR_BUFFER_TOO_SMALL;
7793
}
7894

atecc608a_utils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@
5959
psa_status_t atecc608a_get_serial_number(uint8_t *buffer, size_t buffer_size,
6060
size_t *buffer_length);
6161

62-
psa_status_t atecc608a_check_config_locked();
62+
psa_status_t atecc608a_check_zone_locked(uint8_t zone);
63+
64+
psa_status_t atecc608a_lock_data_zone();
6365

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

0 commit comments

Comments
 (0)