diff options
| author | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2018-11-20 10:43:35 +0100 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2018-11-20 10:43:35 +0100 |
| commit | 7f55c67099b6774123faf8a3ced7de0548798c86 (patch) | |
| tree | 9527f74c87ad7fb3be49294cb47f671e57ccd84d /crypto_aead/lilliputaei128v1 | |
| parent | f14a2f281a2da7df2dae192cb38eddc288790c4e (diff) | |
| download | lilliput-ae-implem-7f55c67099b6774123faf8a3ced7de0548798c86.tar.xz | |
Initialisation et dump du tweakey
Diffstat (limited to 'crypto_aead/lilliputaei128v1')
| -rw-r--r-- | crypto_aead/lilliputaei128v1/ref/Makefile | 19 | ||||
| -rw-r--r-- | crypto_aead/lilliputaei128v1/ref/test-tweakey.c | 8 | ||||
| -rw-r--r-- | crypto_aead/lilliputaei128v1/ref/tweakey.c | 38 | ||||
| -rw-r--r-- | crypto_aead/lilliputaei128v1/ref/tweakey.h | 19 |
4 files changed, 59 insertions, 25 deletions
diff --git a/crypto_aead/lilliputaei128v1/ref/Makefile b/crypto_aead/lilliputaei128v1/ref/Makefile index 891d0e3..3ffcf57 100644 --- a/crypto_aead/lilliputaei128v1/ref/Makefile +++ b/crypto_aead/lilliputaei128v1/ref/Makefile @@ -6,19 +6,20 @@ nist_flags = -std=c99 -Wall -Wextra -Wshadow -fsanitize=address,undefined -O2 clean: - -rm *.o - -rm test-tweakey - -rm tweakey_*.txt + -rm -r results -%.o: %.c +results: + mkdir $@ + +results/%.o: %.c | results gcc -c $< $(nist_flags) -o $@ -test-tweakey: test-tweakey.o tweakey.o +results/test-tweakey: results/test-tweakey.o results/tweakey.o | results gcc $^ $(nist_flags) -o $@ -run-test-tweakey: test-tweakey - ./test-tweakey +run-test-tweakey: results/test-tweakey + ./results/test-tweakey -test-tweakey.o: tweakey.h -tweakey.o: tweakey.h +results/test-tweakey.o: tweakey.h +results/tweakey.o: tweakey.h diff --git a/crypto_aead/lilliputaei128v1/ref/test-tweakey.c b/crypto_aead/lilliputaei128v1/ref/test-tweakey.c index 946f7c9..998d699 100644 --- a/crypto_aead/lilliputaei128v1/ref/test-tweakey.c +++ b/crypto_aead/lilliputaei128v1/ref/test-tweakey.c @@ -11,8 +11,8 @@ struct vector_input { char * name; - uint8_t key[KEY_LENGTH_BITS/8]; - uint8_t tweak[TWEAK_LENGTH_BITS/8]; + uint8_t key[KEY_BYTES]; + uint8_t tweak[TWEAK_BYTES]; }; typedef struct vector_input vector_input; @@ -76,7 +76,7 @@ vector_input VECTORS[] = { FILE* open_dump_file(const char * name) { char filename[128]; - snprintf(filename, sizeof(filename), "tweakey_%s.txt", name); + snprintf(filename, sizeof(filename), "results/tweakey_%s.txt", name); return fopen(filename, "w"); } @@ -95,7 +95,7 @@ int main() fprintf(dump, "Tweakey Schedule\n"); - uint8_t rtk[ROUND_TWEAKEY_BITS/8]; + uint8_t rtk[ROUND_TWEAKEY_BYTES]; for (uint8_t i=0; i<32; i++) { tweakey_state_extract(&tk, rtk, i); diff --git a/crypto_aead/lilliputaei128v1/ref/tweakey.c b/crypto_aead/lilliputaei128v1/ref/tweakey.c index 340a85b..7cc92c3 100644 --- a/crypto_aead/lilliputaei128v1/ref/tweakey.c +++ b/crypto_aead/lilliputaei128v1/ref/tweakey.c @@ -1,21 +1,49 @@ +#include <string.h> + #include "tweakey.h" +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++) + { + 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_LENGTH_BITS/8], - const uint8_t tweak[TWEAK_LENGTH_BITS/8], + const uint8_t key[KEY_BYTES], + const uint8_t tweak[TWEAK_BYTES], FILE* debug ) { - + memcpy(TK->TK, tweak, TWEAK_BYTES); + memcpy(TK->TK+TWEAK_BYTES, key, KEY_BYTES); + + 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); } void tweakey_state_extract( const tweakey_state *TK, - uint8_t round_tweakey[ROUND_TWEAKEY_BITS/8], /* output */ - uint8_t i /* round constant */ + uint8_t round_tweakey[ROUND_TWEAKEY_BYTES], /* output */ + uint8_t i /* round constant */ ) { diff --git a/crypto_aead/lilliputaei128v1/ref/tweakey.h b/crypto_aead/lilliputaei128v1/ref/tweakey.h index 8018f9c..d5d2be3 100644 --- a/crypto_aead/lilliputaei128v1/ref/tweakey.h +++ b/crypto_aead/lilliputaei128v1/ref/tweakey.h @@ -5,14 +5,19 @@ #include <stdint.h> -#define TWEAK_LENGTH_BITS 192 -#define KEY_LENGTH_BITS 128 -#define ROUND_TWEAKEY_BITS 64 +#define TWEAK_LENGTH_BITS 192 +#define KEY_LENGTH_BITS 128 +#define ROUND_TWEAKEY_LENGTH_BITS 64 + +#define TWEAK_BYTES (TWEAK_LENGTH_BITS/8) +#define KEY_BYTES (KEY_LENGTH_BITS/8) +#define ROUND_TWEAKEY_BYTES (ROUND_TWEAKEY_LENGTH_BITS/8) struct tweakey_state { FILE* debug; + uint8_t TK[TWEAK_BYTES+KEY_BYTES]; }; typedef struct tweakey_state tweakey_state; @@ -20,15 +25,15 @@ typedef struct tweakey_state tweakey_state; void tweakey_state_init( tweakey_state *TK, - const uint8_t key[KEY_LENGTH_BITS/8], - const uint8_t tweak[TWEAK_LENGTH_BITS/8], + const uint8_t key[KEY_BYTES], + const uint8_t tweak[TWEAK_BYTES], FILE* debug ); void tweakey_state_extract( const tweakey_state *TK, - uint8_t round_tweakey[ROUND_TWEAKEY_BITS/8], /* output */ - uint8_t i /* round constant */ + uint8_t round_tweakey[ROUND_TWEAKEY_BYTES], /* output */ + uint8_t i /* round constant */ ); void tweakey_state_update(tweakey_state *TK); |
