diff options
Diffstat (limited to 'crypto_aead/lilliputaei128v1/ref/tweakey.c')
| -rw-r--r-- | crypto_aead/lilliputaei128v1/ref/tweakey.c | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/crypto_aead/lilliputaei128v1/ref/tweakey.c b/crypto_aead/lilliputaei128v1/ref/tweakey.c index 6f5c6d3..dc8064a 100644 --- a/crypto_aead/lilliputaei128v1/ref/tweakey.c +++ b/crypto_aead/lilliputaei128v1/ref/tweakey.c @@ -12,8 +12,15 @@ #define LANES_NB (TWEAKEY_BYTES/LANE_BYTES) -static void _dump_buffer(FILE *output, size_t len, const uint8_t buf[len], int indent) +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, ""); @@ -41,13 +48,9 @@ void tweakey_state_init( memcpy(TK->TK+TWEAK_BYTES, key, KEY_BYTES); TK->debug = debug; - - fprintf(debug, " Tweak is :\n"); - _dump_buffer(debug, TWEAK_BYTES, tweak, 5); - fprintf(debug, " Key is :\n"); - _dump_buffer(debug, KEY_BYTES, key, 5); - fprintf(debug, " Tweakey is :\n"); - _dump_buffer(debug, sizeof(TK->TK), TK->TK, 5); + _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); } @@ -69,10 +72,10 @@ void tweakey_state_extract( round_tweakey[0] ^= i; - fprintf(TK->debug, " Extracting Subtweakey round %"PRIu8"\n", i); - _dump_buffer(TK->debug, sizeof(TK->TK), TK->TK, 5); - fprintf(TK->debug, " Subtweakey :\n"); - _dump_buffer(TK->debug, ROUND_TWEAKEY_BYTES, round_tweakey, 5); + 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); } @@ -112,16 +115,13 @@ static void _multiply_state(tweakey_state *TK) void tweakey_state_update(tweakey_state *TK) { - fprintf(TK->debug, " Input Tweakey :\n"); - _dump_buffer(TK->debug, sizeof(TK->TK), TK->TK, 10); + _dump_buffer(TK->debug, " Input Tweakey :", sizeof(TK->TK), TK->TK, 10); _permute_state(TK); - fprintf(TK->debug, " Post permutation Tweakey :\n"); - _dump_buffer(TK->debug, sizeof(TK->TK), TK->TK, 10); + _dump_buffer(TK->debug, " Post permutation Tweakey :", sizeof(TK->TK), TK->TK, 10); _multiply_state(TK); - fprintf(TK->debug, " Post multiplication Tweakey :\n"); - _dump_buffer(TK->debug, sizeof(TK->TK), TK->TK, 10); + _dump_buffer(TK->debug, " Post multiplication Tweakey :", sizeof(TK->TK), TK->TK, 10); } |
