diff options
| -rw-r--r-- | crypto_aead/lilliputaei128v1/ref/debug.h | 29 | ||||
| -rw-r--r-- | crypto_aead/lilliputaei128v1/ref/tweakey.c | 43 |
2 files changed, 39 insertions, 33 deletions
diff --git a/crypto_aead/lilliputaei128v1/ref/debug.h b/crypto_aead/lilliputaei128v1/ref/debug.h new file mode 100644 index 0000000..27b58f8 --- /dev/null +++ b/crypto_aead/lilliputaei128v1/ref/debug.h @@ -0,0 +1,29 @@ +#pragma once + +#include <inttypes.h> +#include <stdio.h> + + +static inline void debug_dump_buffer(FILE *output, const char *header, size_t len, const uint8_t buf[len], int indent) +{ + if (!output) + { + return; + } + + fprintf(output, "%s\n", header); + + for (size_t line=0; line<len/8; line++) + { + fprintf(output, "%*s", indent, ""); + for (size_t b=0; b<8; b++) + { + /* start with MSB */ + size_t byte_index = len-(1+line*8+b); + fprintf(output, "%*s", 5, ""); + fprintf(output, "%02x", buf[byte_index]); + } + fprintf(output, "\n"); + } + fprintf(output, "\n"); +} diff --git a/crypto_aead/lilliputaei128v1/ref/tweakey.c b/crypto_aead/lilliputaei128v1/ref/tweakey.c index dc8064a..4310dc5 100644 --- a/crypto_aead/lilliputaei128v1/ref/tweakey.c +++ b/crypto_aead/lilliputaei128v1/ref/tweakey.c @@ -6,37 +6,14 @@ #include "parameters.h" #include "tweakey.h" +#include "debug.h" + #define LANE_BITS 64 #define LANE_BYTES (LANE_BITS/8) #define LANES_NB (TWEAKEY_BYTES/LANE_BYTES) -static void _dump_buffer(FILE *output, const char *header, size_t len, const uint8_t buf[len], int indent) -{ - if (!output) - { - return; - } - - fprintf(output, "%s\n", header); - - for (size_t line=0; line<len/8; line++) - { - fprintf(output, "%*s", indent, ""); - for (size_t b=0; b<8; b++) - { - /* start with MSB */ - size_t byte_index = len-(1+line*8+b); - fprintf(output, "%*s", 5, ""); - fprintf(output, "%02x", buf[byte_index]); - } - fprintf(output, "\n"); - } - fprintf(output, "\n"); -} - - void tweakey_state_init( tweakey_state *TK, const uint8_t key[KEY_BYTES], @@ -48,9 +25,9 @@ void tweakey_state_init( memcpy(TK->TK+TWEAK_BYTES, key, KEY_BYTES); TK->debug = debug; - _dump_buffer(debug, " Tweak is :", TWEAK_BYTES, tweak, 5); - _dump_buffer(debug, " Key is :", KEY_BYTES, key, 5); - _dump_buffer(debug, " Tweakey is :", sizeof(TK->TK), TK->TK, 5); + debug_dump_buffer(debug, " Tweak is :", TWEAK_BYTES, tweak, 5); + debug_dump_buffer(debug, " Key is :", KEY_BYTES, key, 5); + debug_dump_buffer(debug, " Tweakey is :", sizeof(TK->TK), TK->TK, 5); } @@ -74,8 +51,8 @@ void tweakey_state_extract( char debug[512]; snprintf(debug, sizeof(debug), " Extracting Subtweakey round %"PRIu8, i); - _dump_buffer(TK->debug, debug, sizeof(TK->TK), TK->TK, 5); - _dump_buffer(TK->debug, " Subtweakey :", ROUND_TWEAKEY_BYTES, round_tweakey, 5); + debug_dump_buffer(TK->debug, debug, sizeof(TK->TK), TK->TK, 5); + debug_dump_buffer(TK->debug, " Subtweakey :", ROUND_TWEAKEY_BYTES, round_tweakey, 5); } @@ -115,13 +92,13 @@ static void _multiply_state(tweakey_state *TK) void tweakey_state_update(tweakey_state *TK) { - _dump_buffer(TK->debug, " Input Tweakey :", sizeof(TK->TK), TK->TK, 10); + debug_dump_buffer(TK->debug, " Input Tweakey :", sizeof(TK->TK), TK->TK, 10); _permute_state(TK); - _dump_buffer(TK->debug, " Post permutation Tweakey :", sizeof(TK->TK), TK->TK, 10); + debug_dump_buffer(TK->debug, " Post permutation Tweakey :", sizeof(TK->TK), TK->TK, 10); _multiply_state(TK); - _dump_buffer(TK->debug, " Post multiplication Tweakey :", sizeof(TK->TK), TK->TK, 10); + debug_dump_buffer(TK->debug, " Post multiplication Tweakey :", sizeof(TK->TK), TK->TK, 10); } |
