/* Implementation of the Lilliput-AE tweakable block cipher. Authors, hereby denoted as "the implementer": Kévin Le Gouguec, 2019. For more information, feedback or questions, refer to our website: https://paclido.fr/lilliput-ae To the extent possible under law, the implementer has waived all copyright and related or neighboring rights to the source code in this file. http://creativecommons.org/publicdomain/zero/1.0/ --- This file implements Lilliput-AE's nonce-respecting mode based on ΘCB3. */ #include #include #include #include "cipher.h" #include "lilliput-ae.h" #include "lilliput-ae-utils.h" static const uint8_t _0n[BLOCK_BYTES] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static uint8_t _upper_nibble(uint8_t i) { return i >> 4; } static uint8_t _lower_nibble(uint8_t i) { return i & 0x0f; } static void _init_msg_tweak(const uint8_t N[NONCE_BYTES], uint8_t tweak[TWEAK_BYTES]) { /* With an s-bit block index, the t-bit tweak is filled as follows: * * [ 1, 4]: 4-bit prefix * [ 5, |N|+4]: nonce * [ |N|+5, t]: block index * [|N|+5, t-s]: 0-padding * [t-s+1, t]: actual block index, from MSB to LSB * * This function sets bits 5 to t-s once and for all. */ tweak[0] = _upper_nibble(N[0]); for (size_t i=1; i