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 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'src/ae-common.h') 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