From 2c90f8474502559c4314c2e02a4ea76b21ff9509 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Wed, 21 Nov 2018 14:46:17 +0100 Subject: Ébauche de déchiffrement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit La gestion de la permutation est probablement pas élégante… 🤷 --- crypto_aead/lilliputaei128v1/ref/cipher.c | 62 ++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 14 deletions(-) (limited to 'crypto_aead/lilliputaei128v1/ref/cipher.c') diff --git a/crypto_aead/lilliputaei128v1/ref/cipher.c b/crypto_aead/lilliputaei128v1/ref/cipher.c index 60e0d16..dba7e90 100644 --- a/crypto_aead/lilliputaei128v1/ref/cipher.c +++ b/crypto_aead/lilliputaei128v1/ref/cipher.c @@ -8,6 +8,25 @@ #include "tweakey.h" +enum permutation +{ + PERMUTATION_ENCRYPTION = 0, + PERMUTATION_DECRYPTION = 1, + PERMUTATION_NONE +}; + +typedef enum permutation permutation; + +const uint8_t PERMUTATIONS[2][BLOCK_BYTES] = { + /* PI(i) */ + [0] = { 13, 9, 14, 8, 10, 11, 12, 15, + 4, 5, 3, 1, 2, 6, 0, 7 }, + /* PI^-1(i) */ + [1] = { 14, 11, 12, 10, 8, 9, 13, 15, + 3, 1, 4, 5, 6, 0, 2, 7 } +}; + + struct cipher_state { uint8_t X[BLOCK_BYTES]; @@ -53,19 +72,19 @@ static void _linear_layer(__attribute__((unused)) cipher_state *X) } -static void _permutation_layer(__attribute__((unused)) cipher_state *X) +static void _permutation_layer(__attribute__((unused)) cipher_state *X, permutation p) { - + if (p == PERMUTATION_NONE) + { + return; + } } -static void _one_round_egfn(cipher_state *X, const uint8_t RTK[ROUND_TWEAKEY_BYTES], bool permute) +static void _one_round_egfn(cipher_state *X, const uint8_t RTK[ROUND_TWEAKEY_BYTES], permutation p) { _nonlinear_layer(X, RTK); _linear_layer(X); - if (permute) - { - _permutation_layer(X); - } + _permutation_layer(X, p); } @@ -83,21 +102,36 @@ void lilliput_tbc_encrypt( uint8_t RTK[ROUNDS][ROUND_TWEAKEY_BYTES]; _compute_round_tweakeys(key, tweak, RTK); - for (uint8_t i=0; i