From 1989002054111cc5301f9aa229957cbd59a9e2f5 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Wed, 20 Feb 2019 17:30:10 +0100 Subject: Changement de l'implémentation de référence MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Et suppression de l'implémentation add_tweakeysequences, qui n'a plus aucun intérêt (plus lente et plus grosse que les deux autres). --- src/ref/tweakey.c | 63 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 17 deletions(-) (limited to 'src/ref/tweakey.c') diff --git a/src/ref/tweakey.c b/src/ref/tweakey.c index b1f349e..b2822b0 100644 --- a/src/ref/tweakey.c +++ b/src/ref/tweakey.c @@ -14,7 +14,7 @@ http://creativecommons.org/publicdomain/zero/1.0/ This file provides an implementation of Lilliput-TBC's tweakey schedule, where multiplications by matrices M and M_R to the power n are performed -by applying functions for M and M_R n times. +by functions expressing the exponentiated matrices with shifts and XORs. */ #include @@ -76,18 +76,34 @@ static void _multiply_M(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES]) static void _multiply_M2(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES]) { - uint8_t M_x[LANE_BYTES]; - _multiply_M(x, M_x); - _multiply_M(M_x, y); + uint8_t x_M_5 = x[5]<<3 ^ x[4]; + uint8_t x_M_4 = x[4]>>3 ^ x[3]; + + y[7] = x[5]; + y[6] = x_M_5; + y[5] = x_M_5<<3 ^ x_M_4; + y[4] = x_M_4>>3 ^ x[2]; + y[3] = x[6]<<2 ^ x[1]; + y[2] = x[5]<<2 ^ x[0]; + y[1] = x[7]; + y[0] = x[6]; } static void _multiply_M3(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES]) { - uint8_t M_x[LANE_BYTES]; - uint8_t M2_x[LANE_BYTES]; - _multiply_M(x, M_x); - _multiply_M(M_x, M2_x); - _multiply_M(M2_x, y); + uint8_t x_M_5 = x[5]<<3 ^ x[4]; + uint8_t x_M_4 = x[4]>>3 ^ x[3]; + uint8_t x_M2_5 = x_M_5<<3 ^ x_M_4; + uint8_t x_M2_4 = x_M_4>>3 ^ x[2]; + + y[7] = x_M_5; + y[6] = x_M2_5; + y[5] = x_M2_5<<3 ^ x_M2_4; + y[4] = x_M2_4>>3 ^ x[6]<<2 ^ x[1]; + y[3] = x[5]<<2 ^ x[0]; + y[2] = x_M_5<<2 ^ x[7]; + y[1] = x[6]; + y[0] = x[5]; } static void _multiply_MR(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES]) @@ -104,18 +120,31 @@ static void _multiply_MR(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES]) static void _multiply_MR2(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES]) { - uint8_t MR_x[LANE_BYTES]; - _multiply_MR(x, MR_x); - _multiply_MR(MR_x, y); + uint8_t x_MR_4 = x[5] ^ x[6]<<3; + + y[0] = x[2]; + y[1] = x[3] ^ x[4]>>3; + y[2] = x[4] ^ x_MR_4>>3; + y[3] = x_MR_4; + y[4] = x[3]<<2 ^ x[6] ^ x[7]<<3; + y[5] = x[4]<<2 ^ x[7]; + y[6] = x[0]; + y[7] = x[1]; } static void _multiply_MR3(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES]) { - uint8_t MR_x[LANE_BYTES]; - uint8_t MR2_x[LANE_BYTES]; - _multiply_MR(x, MR_x); - _multiply_MR(MR_x, MR2_x); - _multiply_MR(MR2_x, y); + uint8_t x_MR_4 = x[5] ^ x[6]<<3; + uint8_t x_MR2_4 = x[3]<<2 ^ x[6] ^ x[7]<<3; + + y[0] = x[3] ^ x[4]>>3; + y[1] = x[4] ^ x_MR_4>>3; + y[2] = x_MR_4 ^ x_MR2_4>>3; + y[3] = x_MR2_4; + y[4] = x[0]<<3 ^ x[4]<<2 ^ x[7]; + y[5] = x_MR_4<<2 ^ x[0]; + y[6] = x[1]; + y[7] = x[2]; } typedef void (*matrix_multiplication)(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES]); -- cgit v1.2.3