/* 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 void _fill_msg_tweak( uint8_t prefix, const uint8_t N[NONCE_BYTES], size_t block_index, uint8_t tweak[TWEAK_BYTES] ) { /* With an s-bit block index, the t-bit tweak is filled as follows: * * - bits [ 1, t-|N|-4]: block index * [ 1, s]: actual 64-bit block index * [ s+1, t-|N|-4]: 0-padding * - bits [t-|N|-4, t-4]: nonce * - bits [ t-3, t]: 4-bit prefix */ copy_block_index(block_index, tweak); tweak[sizeof(block_index)] = lower_nibble(N[0]) << 4; for (size_t i=1; i