diff options
Diffstat (limited to 'crypto_aead/lilliputaei128v1/ref/cipher.c')
| -rw-r--r-- | crypto_aead/lilliputaei128v1/ref/cipher.c | 63 |
1 files changed, 7 insertions, 56 deletions
diff --git a/crypto_aead/lilliputaei128v1/ref/cipher.c b/crypto_aead/lilliputaei128v1/ref/cipher.c index 6c9302b..7f1152a 100644 --- a/crypto_aead/lilliputaei128v1/ref/cipher.c +++ b/crypto_aead/lilliputaei128v1/ref/cipher.c @@ -1,6 +1,4 @@ -#include <inttypes.h> /* debug */ -#include <stdbool.h> -#include <stdio.h> /* debug */ +#include <stdint.h> #include <string.h> #include "cipher.h" @@ -8,18 +6,6 @@ #include "parameters.h" #include "tweakey.h" -#include "debug.h" - - -static void _debug_announce_round(FILE* debug, uint8_t i) -{ - if (!debug) - return; - fprintf(debug, "\n"); - fprintf(debug, "One round EGFN round : %"PRIu8"\n", i); - fprintf(debug, " State :\n"); -} - enum permutation { @@ -43,17 +29,15 @@ const uint8_t PERMUTATIONS[2][BLOCK_BYTES] = { 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) +static void _state_init(cipher_state *X, const uint8_t message[BLOCK_BYTES]) { memcpy(X->X, message, sizeof(X->X)); - X->debug = debug; } @@ -64,7 +48,7 @@ static void _compute_round_tweakeys( ) { tweakey_state TK; - tweakey_state_init(&TK, key, tweak, NULL); + tweakey_state_init(&TK, key, tweak); tweakey_state_extract(&TK, RTK[0], 0); for (uint8_t i=1; i<ROUNDS; i++) @@ -77,35 +61,26 @@ static void _compute_round_tweakeys( static void _nonlinear_layer(cipher_state *X, const uint8_t RTK[ROUND_TWEAKEY_BYTES]) { - debug_dump_buffer(X->debug, " Non Linear Layer :", sizeof(X->X), X->X, 10); - debug_dump_buffer(X->debug, " Subtweakey :", ROUND_TWEAKEY_BYTES, RTK, 66); - uint8_t F[ROUND_TWEAKEY_BYTES]; for (size_t j=0; j<sizeof(F); j++) { F[j] = X->X[j] ^ RTK[j]; } - debug_dump_buffer(X->debug, " Variables xored :", sizeof(F), F, 66); for (size_t j=0; j<sizeof(F); j++) { F[j] = S[F[j]]; } - debug_dump_buffer(X->debug, " Variables sboxed :", sizeof(F), F, 66); for (size_t j=0; j<8; j++) { size_t dest_j = 15-j; X->X[dest_j] ^= F[j]; } - - debug_dump_buffer(X->debug, " State non linearized :", sizeof(X->X), X->X, 10); } static void _linear_layer(cipher_state *X) { - debug_dump_buffer(X->debug, " Linear Layer :", sizeof(X->X), X->X, 10); - X->X[15] ^= X->X[1]; X->X[15] ^= X->X[2]; X->X[15] ^= X->X[3]; @@ -120,8 +95,6 @@ static void _linear_layer(cipher_state *X) X->X[11] ^= X->X[7]; X->X[10] ^= X->X[7]; X->X[9] ^= X->X[7]; - - debug_dump_buffer(X->debug, " State linearized :", sizeof(X->X), X->X, 10); } static void _permutation_layer(cipher_state *X, permutation p) @@ -131,8 +104,6 @@ static void _permutation_layer(cipher_state *X, permutation p) return; } - debug_dump_buffer(X->debug, " Permutation Layer :", sizeof(X->X), X->X, 10); - uint8_t X_old[BLOCK_BYTES]; memcpy(X_old, X, sizeof(X_old)); @@ -142,8 +113,6 @@ static void _permutation_layer(cipher_state *X, permutation p) { X->X[pi[j]] = X_old[j]; } - - debug_dump_buffer(X->debug, " State permuted :", sizeof(X->X), X->X, 10); } static void _one_round_egfn(cipher_state *X, const uint8_t RTK[ROUND_TWEAKEY_BYTES], permutation p) @@ -158,62 +127,44 @@ void lilliput_tbc_encrypt( const uint8_t key[KEY_BYTES], const uint8_t tweak[TWEAK_BYTES], const uint8_t message[BLOCK_BYTES], - uint8_t ciphertext[BLOCK_BYTES], - FILE *debug + uint8_t ciphertext[BLOCK_BYTES] ) { - debug_dump_lanes(debug, "Tweak :", TWEAK_BYTES, tweak, 0); - debug_dump_lanes(debug, "Key :", KEY_BYTES, key, 0); - debug_dump_buffer(debug, "Message :", BLOCK_BYTES, message, 0); - cipher_state X; - _state_init(&X, message, debug); + _state_init(&X, message); uint8_t RTK[ROUNDS][ROUND_TWEAKEY_BYTES]; _compute_round_tweakeys(key, tweak, RTK); for (uint8_t i=0; i<ROUNDS-1; i++) { - _debug_announce_round(debug, i); _one_round_egfn(&X, RTK[i], PERMUTATION_ENCRYPTION); } - _debug_announce_round(debug, ROUNDS-1); _one_round_egfn(&X, RTK[ROUNDS-1], PERMUTATION_NONE); memcpy(ciphertext, X.X, BLOCK_BYTES); - - debug_dump_buffer(debug, "\nCiphertext :", BLOCK_BYTES, ciphertext, 0); } void lilliput_tbc_decrypt( const uint8_t key[KEY_BYTES], const uint8_t tweak[TWEAK_BYTES], const uint8_t ciphertext[BLOCK_BYTES], - uint8_t message[BLOCK_BYTES], - FILE *debug + uint8_t message[BLOCK_BYTES] ) { - debug_dump_lanes(debug, "Tweak :", TWEAK_BYTES, tweak, 0); - debug_dump_lanes(debug, "Key :", KEY_BYTES, key, 0); - debug_dump_buffer(debug, "Ciphertext :", BLOCK_BYTES, ciphertext, 0); - cipher_state X; - _state_init(&X, ciphertext, debug); + _state_init(&X, ciphertext); uint8_t RTK[ROUNDS][ROUND_TWEAKEY_BYTES]; _compute_round_tweakeys(key, tweak, RTK); for (uint8_t i=0; i<ROUNDS-1; i++) { - _debug_announce_round(debug, i); _one_round_egfn(&X, RTK[ROUNDS-1-i], PERMUTATION_DECRYPTION); } - _debug_announce_round(debug, ROUNDS-1); _one_round_egfn(&X, RTK[0], PERMUTATION_NONE); memcpy(message, X.X, BLOCK_BYTES); - - debug_dump_buffer(debug, "\nDeciphered :", BLOCK_BYTES, message, 0); } |
