Skip to content

Commit 8ccd8d6

Browse files
author
Andrzej Kurek
committed
Add a buffer_size parameter to random byte generating function
1 parent eb22bfe commit 8ccd8d6

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

atecc608a_utils.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ psa_status_t atecc608a_check_config_locked()
6262
return status;
6363
}
6464

65-
psa_status_t atecc608a_random(uint8_t *rand_out)
65+
psa_status_t atecc608a_random_32_bytes(uint8_t *rand_out, size_t buffer_size)
6666
{
6767
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
6868

@@ -71,6 +71,11 @@ psa_status_t atecc608a_random(uint8_t *rand_out)
7171
return PSA_ERROR_INVALID_ARGUMENT;
7272
}
7373

74+
if (buffer_size < 32)
75+
{
76+
return PSA_ERROR_BUFFER_TOO_SMALL;
77+
}
78+
7479
ASSERT_SUCCESS_PSA(atecc608a_init());
7580
ASSERT_SUCCESS(atcab_random(rand_out));
7681

atecc608a_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ psa_status_t atecc608a_get_serial_number(uint8_t *buffer, size_t buffer_size,
6262
psa_status_t atecc608a_check_config_locked();
6363

6464
/** Generate a 32 byte random number from the CryptoAuth device. */
65-
psa_status_t atecc608a_random(uint8_t *rand_out);
65+
psa_status_t atecc608a_random_32_bytes(uint8_t *rand_out, size_t buffer_size);
6666

6767
#endif /* ATECC608A_SE_H */

main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ psa_status_t test_write_read_slot(uint16_t slot)
124124
uint8_t data_write[TEST_WRITE_READ_SIZE] = {};
125125
uint8_t data_read[TEST_WRITE_READ_SIZE] = {};
126126

127-
ASSERT_SUCCESS_PSA(atecc608a_random(data_write));
127+
ASSERT_SUCCESS_PSA(atecc608a_random_32_bytes(data_write, TEST_WRITE_READ_SIZE));
128128
ASSERT_SUCCESS_PSA(atecc608a_write(slot, 0, data_write, TEST_WRITE_READ_SIZE));
129129
ASSERT_SUCCESS_PSA(atecc608a_read(slot, 0, data_read, TEST_WRITE_READ_SIZE));
130130
ASSERT_STATUS(memcmp(data_write, data_read, TEST_WRITE_READ_SIZE),

0 commit comments

Comments
 (0)