/* 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-misuse-resistant mode based on SCT-2. */ #include #include #include #include "cipher.h" #include "lilliput-ae.h" #include "lilliput-ae-utils.h" static void _init_msg_tweak(const uint8_t tag[TAG_BYTES], uint8_t tweak[TWEAK_BYTES]) { /* With an s-bit block index, the t-bit tweak is filled as follows: * * - bits [ 1, t-1]: tag + block index * [ 1, s]: tag[1..s] XOR block index * [s+1, t-1]: tag[s+1..t-1] * - bit t: 1 * * This function sets bits s+1 to t once and for all. */ memcpy(tweak+sizeof(size_t), tag+sizeof(size_t), TAG_BYTES-sizeof(size_t)); tweak[TWEAK_BYTES-1] |= 0x80; } static void _fill_msg_tweak(const uint8_t tag[TAG_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-1]: tag + block index * [ 1, s]: tag[1..s] XOR block index * [s+1, t-1]: tag[s+1..t-1] * - bit t: 1 * * This function assumes bits s+1 to t have already been set, and * only sets bits 1 to s. */ copy_block_index(block_index, tweak); for (size_t i=0; i