From ce047dd5b1beaba66b8ea615191c421e1c8c8c9a Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Tue, 30 Apr 2019 15:41:59 +0200 Subject: Homogénéisation de la gestion de l'index de bloc dans les tweaks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - "block number" → "block index" - "192" → "t" - boucle de copie de l'index - utilisation de size_t : - par définition, aucune implémentation ne pourra traiter plus d'octets que SIZE_MAX (donc pas plus de blocs), - pas de raison de forcer un index de 64 bits sur ces pauvres ATmega et MSP430. --- src/ref/lilliput-ae-utils.h | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'src/ref/lilliput-ae-utils.h') diff --git a/src/ref/lilliput-ae-utils.h b/src/ref/lilliput-ae-utils.h index ce3f154..0efb776 100644 --- a/src/ref/lilliput-ae-utils.h +++ b/src/ref/lilliput-ae-utils.h @@ -90,24 +90,31 @@ static inline void pad10(size_t X_len, const uint8_t X[X_len], uint8_t padded[BL memcpy(padded+pad_len, X, X_len); } +static inline void copy_block_index(size_t index, uint8_t tweak[TWEAK_BYTES]) +{ + /* NB: little-endian architectures can simply use: + * memcpy(tweak, &index, sizeof(index)); */ + for (size_t i=0; i> 8*i & 0xff; + } +} + static inline void fill_index_tweak( - uint8_t prefix, - uint64_t block_index, - uint8_t tweak[TWEAK_BYTES] + uint8_t prefix, + size_t block_index, + uint8_t tweak[TWEAK_BYTES] ) { - /* The t-bit tweak is filled as follows: + /* With an s-bit block index, the t-bit tweak is filled as follows: * * - bits [ 1, t-4]: block index - * [ 1, 64]: actual 64-bit block index - * [ 65, t-4]: 0-padding - * - bits [t-3, t]: constant 4-bit prefix + * [ 1, s]: actual block index + * [s+1, t-4]: 0-padding + * - bits [t-3, t]: 4-bit prefix */ - for (size_t i=0; i> 8*i & 0xff; - } + copy_block_index(block_index, tweak); /* Assume padding bytes have already been set to 0. */ -- cgit v1.2.3