From e5a9fe49462ad0ede700041f4ae5c8c430cefe34 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Mon, 4 Feb 2019 10:57:14 +0100 Subject: Implémentation de M₄ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/add_developedtweakey/tweakey.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/add_developedtweakey/tweakey.c b/src/add_developedtweakey/tweakey.c index a602191..605098b 100644 --- a/src/add_developedtweakey/tweakey.c +++ b/src/add_developedtweakey/tweakey.c @@ -58,6 +58,14 @@ static uint8_t _M3(uint8_t x) return x & 0x1f; } +static uint8_t _M4(uint8_t x) +{ + /* (x<<2)>>3 would keep bit x6 due to integer promotion. + * Side-step this by writing each shift on its own statement. */ + x <<= 2; + return x>>3; +} + static void _multiply_M(const uint8_t X[LANE_BYTES], uint8_t Y[LANE_BYTES]) { Y[7] = X[6]; @@ -120,11 +128,14 @@ static void _multiply_MR2(const uint8_t X[LANE_BYTES], uint8_t Y[LANE_BYTES]) 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); + Y[0] = X[3] ^ X[4]>>3; + Y[1] = X[4] ^ X[5]>>3 ^ _M3(X[6]); + Y[2] = _M4(X[3]) ^ X[5] ^ _M1(X[6]) ^ _M3(X[7]); + Y[3] = X[3]<<2 ^ X[6] ^ X[7]<<3; + Y[4] = X[0]<<3 ^ X[4]<<2 ^ X[7]; + Y[5] = X[0] ^ X[5]<<2 ^ X[6]<<5; + 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