/* 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]) { /* The t-bit tweak is filled as follows: * * 1 2 t * [ 1 || tag[2,t] XOR block index ] * * The s-bit block index is XORed to the tag as follows: * * 2 t-s t-s+1 t * [ tag[2, t-s] || tag[t-s+1, t] XOR block index, MSB first ] * * This function sets bits 1 to t-s once and for all. */ memcpy(tweak, tag, TAG_BYTES-sizeof(size_t)); tweak[0] |= 0x80; } static void _fill_msg_tweak(const uint8_t tag[TAG_BYTES], size_t block_index, uint8_t tweak[TWEAK_BYTES]) { /* The t-bit tweak is filled as follows: * * 1 2 t * [ 1 || tag[2,t] XOR block index ] * * The s-bit block index is XORed to the tag as follows: * * 2 t-s t-s+1 t * [ tag[2, t-s] || tag[t-s+1, t] XOR block index, MSB first ] * * This function assumes bits 1 to t-s have already been set, and * only sets bits t-s+1 to t. */ copy_block_index(block_index, tweak); for (size_t i=TWEAK_BYTES-sizeof(size_t); i