summaryrefslogtreecommitdiff
path: root/src/ref/tweakey.c
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@airbus.com>2019-02-13 17:54:06 +0100
committerKévin Le Gouguec <kevin.legouguec@airbus.com>2019-02-13 17:54:06 +0100
commit35f637aa76a6370aff4f6812d9bfeb9c0c371ec7 (patch)
tree438810c49d3140a074abc164c9e29023742c64e2 /src/ref/tweakey.c
parentec5c219519c4ebeb83e43725f9de3162bf7d5552 (diff)
parent3e4096b266e623ec8c3a82bf688a980453db44a3 (diff)
downloadlilliput-ae-implem-35f637aa76a6370aff4f6812d9bfeb9c0c371ec7.tar.xz
Merge branch 'alpha-reformulation' into 'master'
Reformulations des considérations d'implémentation sur le tweakey schedule See merge request paclido/sp3!11
Diffstat (limited to 'src/ref/tweakey.c')
-rw-r--r--src/ref/tweakey.c70
1 files changed, 17 insertions, 53 deletions
diff --git a/src/ref/tweakey.c b/src/ref/tweakey.c
index 319ca49..7019037 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 functions expressing the exponentiated matrices with shifts and XORs.
+by applying functions for M and M_R n times.
*/
#include <stdint.h>
@@ -62,26 +62,6 @@ void tweakey_state_extract(
}
-static uint8_t _M1(uint8_t x)
-{
- return x<<3 ^ x>>3;
-}
-
-static uint8_t _M2(uint8_t x)
-{
- return x<<6 ^ (x & 0xf8) ^ x>>6;
-}
-
-static uint8_t _M3(uint8_t x)
-{
- return (uint8_t)(x<<3) >> 3;
-}
-
-static uint8_t _M4(uint8_t x)
-{
- return (uint8_t)(x<<2) >> 3;
-}
-
static void _multiply_M(const uint8_t X[LANE_BYTES], uint8_t Y[LANE_BYTES])
{
Y[7] = X[6];
@@ -96,26 +76,18 @@ 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])
{
- Y[7] = X[5];
- Y[6] = X[5]<<3 ^ X[4];
- Y[5] = X[5]<<6 ^ _M1(X[4]) ^ X[3];
- Y[4] = X[4]>>6 ^ X[3]>>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];
+ uint8_t M_X[LANE_BYTES];
+ _multiply_M(X, M_X);
+ _multiply_M(M_X, Y);
}
static void _multiply_M3(const uint8_t X[LANE_BYTES], uint8_t Y[LANE_BYTES])
{
- Y[7] = X[5]<<3 ^ X[4];
- Y[6] = X[5]<<6 ^ _M1(X[4]) ^ X[3];
- Y[5] = _M2(X[4]) ^ _M1(X[3]) ^ X[2];
- Y[4] = X[6]<<2 ^ X[3]>>6 ^ X[2]>>3 ^ X[1];
- Y[3] = X[5]<<2 ^ X[0];
- Y[2] = X[7] ^ X[5]<<5 ^ X[4]<<2;
- Y[1] = X[6];
- Y[0] = X[5];
+ 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);
}
static void _multiply_MR(const uint8_t X[LANE_BYTES], uint8_t Y[LANE_BYTES])
@@ -132,26 +104,18 @@ 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])
{
- Y[0] = X[2];
- Y[1] = X[3] ^ X[4]>>3;
- Y[2] = X[4] ^ X[5]>>3 ^ _M3(X[6]);
- Y[3] = X[5] ^ X[6]<<3;
- 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];
+ uint8_t MR_X[LANE_BYTES];
+ _multiply_MR(X, MR_X);
+ _multiply_MR(MR_X, Y);
}
static void _multiply_MR3(const uint8_t X[LANE_BYTES], uint8_t Y[LANE_BYTES])
{
- 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];
+ 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);
}
typedef void (*matrix_multiplication)(const uint8_t X[LANE_BYTES], uint8_t Y[LANE_BYTES]);