From 715ca44396acc009ed57f904d523fcc72031b4d3 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Tue, 20 Nov 2018 15:18:37 +0100 Subject: Implémentation de l'extraction du tweakey MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crypto_aead/lilliputaei128v1/ref/test/tweakey.c | 3 +- crypto_aead/lilliputaei128v1/ref/tweakey.c | 40 +++++++++++++++++++++---- crypto_aead/lilliputaei128v1/ref/tweakey.h | 4 ++- 3 files changed, 39 insertions(+), 8 deletions(-) (limited to 'crypto_aead/lilliputaei128v1') 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 +#include #include #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 #include +#include /* 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; lineTK, 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; laneTK+TWEAKEY_BYTES; lane+=LANE_BYTES) + { + for (size_t j=0; jdebug, " 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; -- cgit v1.2.3