From 4fefe35fd63842b827016acecfadae891d0da953 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Tue, 27 Nov 2018 10:37:56 +0100 Subject: Extraction du traitement des données authentifiées MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commun à ΘCB3 et SCT-2. --- src/ae-common.h | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ src/lilliput-ae-i.c | 64 ++-------------------------------------------------- src/lilliput-ae-ii.c | 13 +++-------- 3 files changed, 66 insertions(+), 72 deletions(-) (limited to 'src') diff --git a/src/ae-common.h b/src/ae-common.h index 6343f98..da5d04d 100644 --- a/src/ae-common.h +++ b/src/ae-common.h @@ -65,5 +65,66 @@ static inline void pad10(size_t X_len, const uint8_t X[X_len], uint8_t padded[BL } } +static inline void _fill_ad_tweak( + uint8_t prefix, + uint64_t block_nb, + 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 + * [ 65, t-4]: 0-padding + * - bits [t-3, t]: constant 4-bit prefix + */ + + for (size_t i=0; i> 8*i; + + tweak[i] = b; + } + + /* Assume padding bytes have already been memset to 0. */ + + tweak[TWEAK_BYTES-1] |= prefix << 4; +} + +static void process_associated_data( + const uint8_t key[KEY_BYTES], + size_t A_len, + const uint8_t A[A_len], + uint8_t Auth[BLOCK_BYTES] +) +{ + uint8_t Ek_Ai[BLOCK_BYTES]; + uint8_t tweak[TWEAK_BYTES]; + + memset(tweak, 0, TWEAK_BYTES); + memset(Auth, 0, BLOCK_BYTES); + + size_t l_a = A_len / BLOCK_BYTES; + size_t rest = A_len % BLOCK_BYTES; + + for (size_t i=0; i> 8*i; - - tweak[i] = b; - } - - /* Assume padding bytes have already been memset to 0. */ - - tweak[TWEAK_BYTES-1] |= prefix << 4; -} - static void _fill_msg_tweak( uint8_t prefix, const uint8_t N[NONCE_BYTES], @@ -74,39 +47,6 @@ static void _fill_msg_tweak( tweak[TWEAK_BYTES-1] = prefix << 4 ^ upper_nibble(N[NONCE_BYTES-1]); } -static void _process_associated_data( - const uint8_t key[KEY_BYTES], - size_t A_len, - const uint8_t A[A_len], - uint8_t Auth[BLOCK_BYTES] -) -{ - uint8_t Ek_Ai[BLOCK_BYTES]; - uint8_t tweak[TWEAK_BYTES]; - - memset(tweak, 0, TWEAK_BYTES); - memset(Auth, 0, BLOCK_BYTES); - - size_t l_a = A_len / BLOCK_BYTES; - size_t rest = A_len % BLOCK_BYTES; - - for (size_t i=0; i #include +#include "ae-common.h" #include "cipher.h" #include "lilliput-ae.h" -static void _process_associated_data( - const uint8_t key[KEY_BYTES], - size_t A_len, - const uint8_t A[A_len], - uint8_t Auth[BLOCK_BYTES] -) -{ -} static void _generate_tag( const uint8_t key[KEY_BYTES], @@ -61,7 +54,7 @@ void lilliput_ae_encrypt( ) { uint8_t auth[BLOCK_BYTES]; - _process_associated_data(key, auth_data_len, auth_data, auth); + process_associated_data(key, auth_data_len, auth_data, auth); _generate_tag(key, message_len, message, nonce, auth, tag); @@ -82,7 +75,7 @@ bool lilliput_ae_decrypt( _decrypt_message(key, ciphertext_len, ciphertext, nonce, tag, message); uint8_t auth[BLOCK_BYTES]; - _process_associated_data(key, auth_data_len, auth_data, auth); + process_associated_data(key, auth_data_len, auth_data, auth); uint8_t effective_tag[TAG_BYTES]; _generate_tag(key, ciphertext_len, message, nonce, auth, effective_tag); -- cgit v1.2.3