From f05a2ff9ccb4562ba4bd8a75a3607bbf24a0c074 Mon Sep 17 00:00:00 2001 From: Andrew Kozlik Date: Mon, 11 Feb 2019 17:46:46 +0100 Subject: [PATCH] Fix aliasing issue in storage_set_counter(). --- storage.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/storage.c b/storage.c index d37d964664..9cb396cbf5 100644 --- a/storage.c +++ b/storage.c @@ -105,8 +105,8 @@ // The length of the ChaCha20 block in bytes. #define CHACHA20_BLOCK_SIZE 64 -// The length of the counter tail in bytes. -#define COUNTER_TAIL_LEN 8 +// The length of the counter tail in words. +#define COUNTER_TAIL_WORDS 2 // Values used in the guard key integrity check. #define GUARD_KEY_MODULUS 6311 @@ -979,9 +979,9 @@ secbool storage_set_counter(const uint16_t key, const uint32_t count) // The count is stored as a 32-bit integer followed by a tail of "1" bits, // which is used as a tally. - uint8_t value[sizeof(count) + COUNTER_TAIL_LEN]; + uint32_t value[1 + COUNTER_TAIL_WORDS]; memset(value, 0xff, sizeof(value)); - *((uint32_t*)value) = count; + value[0] = count; return storage_set(key, value, sizeof(value)); }