mirror of
https://github.com/tillitis/tillitis-key1.git
synced 2025-08-03 12:16:24 -04:00
fw: Rename partition digest to checksum
- Rename functions, defines, et c to indicate that it's a checksum over the partition, not necessarily a cryptographic hash digest even though we use a version of BLAKE2s. - Add comments describing where the checksum is stored and what it is used for. Co-authored-by: Mikael Ågren <mikael@tillitis.se>
This commit is contained in:
parent
106a7a5613
commit
66ea8df1d9
2 changed files with 16 additions and 12 deletions
|
@ -17,11 +17,13 @@ enum part_status part_get_status(void)
|
|||
return part_status;
|
||||
}
|
||||
|
||||
static void part_digest(struct partition_table *part_table, uint8_t *out_digest,
|
||||
size_t out_len);
|
||||
static void part_checksum(struct partition_table *part_table,
|
||||
uint8_t *out_digest, size_t out_len);
|
||||
|
||||
static void part_digest(struct partition_table *part_table, uint8_t *out_digest,
|
||||
size_t out_len)
|
||||
// part_digest computes a checksum over the partition table to detect
|
||||
// flash problems
|
||||
static void part_checksum(struct partition_table *part_table,
|
||||
uint8_t *out_digest, size_t out_len)
|
||||
{
|
||||
int blake2err = 0;
|
||||
|
||||
|
@ -50,7 +52,7 @@ int part_table_read(struct partition_table_storage *storage)
|
|||
ADDR_PARTITION_TABLE_0,
|
||||
ADDR_PARTITION_TABLE_1,
|
||||
};
|
||||
uint8_t check_digest[PART_DIGEST_SIZE] = {0};
|
||||
uint8_t check_digest[PART_CHECKSUM_SIZE] = {0};
|
||||
|
||||
if (storage == NULL) {
|
||||
return -1;
|
||||
|
@ -64,10 +66,10 @@ int part_table_read(struct partition_table_storage *storage)
|
|||
sizeof(*storage)) != 0) {
|
||||
return -1;
|
||||
}
|
||||
part_digest(&storage->table, check_digest,
|
||||
sizeof(check_digest));
|
||||
part_checksum(&storage->table, check_digest,
|
||||
sizeof(check_digest));
|
||||
|
||||
if (memeq(check_digest, storage->check_digest,
|
||||
if (memeq(check_digest, storage->checksum,
|
||||
sizeof(check_digest))) {
|
||||
if (i == 1) {
|
||||
part_status = PART_SLOT0_INVALID;
|
||||
|
@ -91,8 +93,8 @@ int part_table_write(struct partition_table_storage *storage)
|
|||
return -1;
|
||||
}
|
||||
|
||||
part_digest(&storage->table, storage->check_digest,
|
||||
sizeof(storage->check_digest));
|
||||
part_checksum(&storage->table, storage->checksum,
|
||||
sizeof(storage->checksum));
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
flash_sector_erase(offset[i]);
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
#define SIZE_STORAGE_AREA 0x20000UL // 128KiB
|
||||
#define N_STORAGE_AREA 4
|
||||
|
||||
#define PART_DIGEST_SIZE 16
|
||||
#define PART_CHECKSUM_SIZE 16
|
||||
|
||||
enum part_status {
|
||||
PART_SLOT0_INVALID = 1,
|
||||
|
@ -70,6 +70,8 @@ enum part_status {
|
|||
/* - 1 byte status. */
|
||||
/* - 16 bytes random nonce. */
|
||||
/* - 16 bytes authentication tag. */
|
||||
/**/
|
||||
/*- Checksum over the above */
|
||||
|
||||
struct auth_metadata {
|
||||
uint8_t nonce[16];
|
||||
|
@ -99,7 +101,7 @@ struct partition_table {
|
|||
|
||||
struct partition_table_storage {
|
||||
struct partition_table table;
|
||||
uint8_t check_digest[PART_DIGEST_SIZE];
|
||||
uint8_t checksum[PART_CHECKSUM_SIZE]; // Helps detect flash problems
|
||||
} __attribute__((packed));
|
||||
|
||||
enum part_status part_get_status(void);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue