#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); }