#include #include #include /* debug */ #include #include "cipher.h" #include "parameters.h" #include "tweakey.h" #include "debug.h" enum permutation { PERMUTATION_ENCRYPTION = 0, PERMUTATION_DECRYPTION = 1, PERMUTATION_NONE }; typedef enum permutation permutation; const uint8_t PERMUTATIONS[2][BLOCK_BYTES] = { /* PI(i) */ [0] = { 13, 9, 14, 8, 10, 11, 12, 15, 4, 5, 3, 1, 2, 6, 0, 7 }, /* PI^-1(i) */ [1] = { 14, 11, 12, 10, 8, 9, 13, 15, 3, 1, 4, 5, 6, 0, 2, 7 } }; struct cipher_state { uint8_t X[BLOCK_BYTES]; FILE* debug; }; typedef struct cipher_state cipher_state; static void _state_init(cipher_state *X, const uint8_t message[BLOCK_BYTES], FILE* debug) { memcpy(X->X, message, sizeof(X->X)); X->debug = debug; } static void _compute_round_tweakeys( const uint8_t key[KEY_BYTES], const uint8_t tweak[TWEAK_BYTES], uint8_t RTK[ROUNDS][ROUND_TWEAKEY_BYTES] ) { tweakey_state TK; tweakey_state_init(&TK, key, tweak, NULL); tweakey_state_extract(&TK, RTK[0], 0); for (uint8_t i=1; i