From d14739644394986cb584acb45ed9b214dff1c501 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Tue, 27 Nov 2018 08:58:46 +0100 Subject: Mise en commun du code TBC et ΘCB3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Il ne devrait pas varier selon les paramètres AFAICT. --- src/tweakey.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/tweakey.c (limited to 'src/tweakey.c') diff --git a/src/tweakey.c b/src/tweakey.c new file mode 100644 index 0000000..da97019 --- /dev/null +++ b/src/tweakey.c @@ -0,0 +1,83 @@ +#include +#include + +#include "constants.h" +#include "parameters.h" +#include "tweakey.h" + + +#define LANE_BITS 64 +#define LANE_BYTES (LANE_BITS/8) +#define LANES_NB (TWEAKEY_BYTES/LANE_BYTES) + + +void tweakey_state_init( + tweakey_state *TK, + const uint8_t key[KEY_BYTES], + const uint8_t tweak[TWEAK_BYTES] +) +{ + memcpy(TK->TK, tweak, TWEAK_BYTES); + memcpy(TK->TK+TWEAK_BYTES, key, KEY_BYTES); +} + + +void tweakey_state_extract( + const tweakey_state *TK, + uint8_t round_tweakey[ROUND_TWEAKEY_BYTES], /* output */ + uint8_t i /* round constant */ +) +{ + memset(round_tweakey, 0, ROUND_TWEAKEY_BYTES); + + for (const uint8_t *lane=TK->TK; laneTK+TWEAKEY_BYTES; lane+=LANE_BYTES) + { + for (size_t j=0; jTK, sizeof(TK_old)); + + /* TODO: homogenize indices; here j=lane; k=byte */ + + for (size_t j=0; jTK[j+h[k]] = TK_old[j+k]; + } + } +} + +static void _multiply_state(tweakey_state *TK) +{ + /* Lane 0 is multiplied by Id; lane 1 by P_0, lane 2 by P_1... */ + + for (size_t lane=1; laneTK[offset] = P_lane[TK->TK[offset]]; + } + } +} + +void tweakey_state_update(tweakey_state *TK) +{ + _permute_state(TK); + _multiply_state(TK); +} -- cgit v1.2.3