From 30b6de9dd377259685cfd0aedabd1f891fcf0d44 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Tue, 27 Nov 2018 14:08:56 +0100 Subject: Implémentation du mode SCT-2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crypto_aead/lilliputaeii128v1/ref/Makefile | 2 - src/ae-common.h | 19 +++---- src/lilliput-ae-ii.c | 89 +++++++++++++++++++++++++----- 3 files changed, 82 insertions(+), 28 deletions(-) diff --git a/crypto_aead/lilliputaeii128v1/ref/Makefile b/crypto_aead/lilliputaeii128v1/ref/Makefile index 90f2a75..ab18c62 100644 --- a/crypto_aead/lilliputaeii128v1/ref/Makefile +++ b/crypto_aead/lilliputaeii128v1/ref/Makefile @@ -39,5 +39,3 @@ results/src/tweakey.o: src/tweakey.h src/constants.h parameters.h # TODO: should add order-only prerequisites to remove mkdirs inside recipes # TODO: add valgrind, although it does not seem to play well with ASAN # TODO: should use gcc -M... to generate .o -> .h dependencies - -results/src/lilliput-ae-ii.o: CFLAGS += -Wno-unused # FIXME: remove once implemented diff --git a/src/ae-common.h b/src/ae-common.h index da5d04d..561854e 100644 --- a/src/ae-common.h +++ b/src/ae-common.h @@ -65,26 +65,23 @@ static inline void pad10(size_t X_len, const uint8_t X[X_len], uint8_t padded[BL } } -static inline void _fill_ad_tweak( +static inline void fill_index_tweak( uint8_t prefix, - uint64_t block_nb, + uint64_t block_index, uint8_t tweak[TWEAK_BYTES] ) { /* The t-bit tweak is filled as follows: * - * - bits [ 1, t-4]: block number - * [ 1, 64]: actual 64-bit block number + * - bits [ 1, t-4]: block index + * [ 1, 64]: actual 64-bit block index * [ 65, t-4]: 0-padding * - bits [t-3, t]: constant 4-bit prefix */ - for (size_t i=0; i> 8*i; - - tweak[i] = b; + tweak[i] = block_index >> 8*i & 0xff; } /* Assume padding bytes have already been memset to 0. */ @@ -110,7 +107,7 @@ static void process_associated_data( for (size_t i=0; i> i*8 & 0xff; + tweak[i] = tag[i] ^ index_i; + } +} static void _generate_tag( const uint8_t key[KEY_BYTES], size_t M_len, const uint8_t M[M_len], - const uint8_t N[NONCE_BYTES], const uint8_t Auth[BLOCK_BYTES], uint8_t tag[TAG_BYTES] ) { + uint8_t Ek_Mj[BLOCK_BYTES]; + uint8_t tweak[TWEAK_BYTES]; + memset(tweak, 0, TWEAK_BYTES); + + memcpy(tag, Auth, TAG_BYTES); + + size_t l = M_len / BLOCK_BYTES; + size_t rest = M_len % BLOCK_BYTES; + + for (size_t j=0; j