diff options
Diffstat (limited to 'crypto_aead/lilliputaei128v1')
| -rw-r--r-- | crypto_aead/lilliputaei128v1/ref/test/tweakey.c | 3 | ||||
| -rw-r--r-- | crypto_aead/lilliputaei128v1/ref/tweakey.c | 40 | ||||
| -rw-r--r-- | crypto_aead/lilliputaei128v1/ref/tweakey.h | 4 |
3 files changed, 39 insertions, 8 deletions
diff --git a/crypto_aead/lilliputaei128v1/ref/test/tweakey.c b/crypto_aead/lilliputaei128v1/ref/test/tweakey.c index 06adc29..4b4d7dd 100644 --- a/crypto_aead/lilliputaei128v1/ref/test/tweakey.c +++ b/crypto_aead/lilliputaei128v1/ref/test/tweakey.c @@ -1,4 +1,4 @@ -#include <stdint.h> +#include <inttypes.h> #include <stdio.h> #include "tweakey.h" @@ -99,6 +99,7 @@ int main() for (uint8_t i=0; i<32; i++) { tweakey_state_extract(&tk, rtk, i); + fprintf(dump, " Round Tweakey %"PRIu8"\n", i+1); tweakey_state_update(&tk); } tweakey_state_extract(&tk, rtk, 32); diff --git a/crypto_aead/lilliputaei128v1/ref/tweakey.c b/crypto_aead/lilliputaei128v1/ref/tweakey.c index 79fa225..173f4be 100644 --- a/crypto_aead/lilliputaei128v1/ref/tweakey.c +++ b/crypto_aead/lilliputaei128v1/ref/tweakey.c @@ -1,8 +1,14 @@ +#include <stdbool.h> #include <string.h> +#include <inttypes.h> /* debug */ #include "tweakey.h" +#define LANE_BITS 64 +#define LANE_BYTES (LANE_BITS/8) + + static void _dump_buffer(FILE *output, size_t len, const uint8_t buf[len], int indent) { for (size_t line=0; line<len/8; line++) @@ -31,6 +37,8 @@ void tweakey_state_init( memcpy(TK->TK, tweak, TWEAK_BYTES); 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"); @@ -41,16 +49,36 @@ void tweakey_state_init( void tweakey_state_extract( - __attribute__((unused)) const tweakey_state *TK, - __attribute__((unused)) uint8_t round_tweakey[ROUND_TWEAKEY_BYTES], /* output */ - __attribute__((unused)) uint8_t i /* round constant */ + 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; lane<TK->TK+TWEAKEY_BYTES; lane+=LANE_BYTES) + { + for (size_t j=0; j<LANE_BYTES; j++) + { + round_tweakey[j] ^= lane[j]; + } + } + + 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); } -void tweakey_state_update(__attribute__((unused)) 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); + fprintf(TK->debug, " Post permutation Tweakey :\n"); + _dump_buffer(TK->debug, sizeof(TK->TK), TK->TK, 10); + fprintf(TK->debug, " Post multiplication Tweakey :\n"); + _dump_buffer(TK->debug, sizeof(TK->TK), TK->TK, 10); } diff --git a/crypto_aead/lilliputaei128v1/ref/tweakey.h b/crypto_aead/lilliputaei128v1/ref/tweakey.h index d5d2be3..6d575b8 100644 --- a/crypto_aead/lilliputaei128v1/ref/tweakey.h +++ b/crypto_aead/lilliputaei128v1/ref/tweakey.h @@ -7,17 +7,19 @@ #define TWEAK_LENGTH_BITS 192 #define KEY_LENGTH_BITS 128 +#define TWEAKEY_LENGTH_BITS (TWEAK_LENGTH_BITS+KEY_LENGTH_BITS) #define ROUND_TWEAKEY_LENGTH_BITS 64 #define TWEAK_BYTES (TWEAK_LENGTH_BITS/8) #define KEY_BYTES (KEY_LENGTH_BITS/8) +#define TWEAKEY_BYTES (TWEAKEY_LENGTH_BITS/8) #define ROUND_TWEAKEY_BYTES (ROUND_TWEAKEY_LENGTH_BITS/8) struct tweakey_state { FILE* debug; - uint8_t TK[TWEAK_BYTES+KEY_BYTES]; + uint8_t TK[TWEAKEY_BYTES]; }; typedef struct tweakey_state tweakey_state; |
