diff options
| author | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2019-07-04 17:13:57 +0200 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2019-07-04 17:13:57 +0200 |
| commit | 5fc1268d9c866ac78d3360af51eb0c0201a31167 (patch) | |
| tree | ce7a28187e7c407f6fa56bf4ff4ed29245f8b484 /src/ref | |
| parent | 7e4b76b05d9a3945b916af09de0f9672abd2b22c (diff) | |
| parent | 649073fb97cb11e4c1057ad25d8b816575fb85c2 (diff) | |
| download | lilliput-ae-implem-5fc1268d9c866ac78d3360af51eb0c0201a31167.tar.xz | |
Merge branch 'fix-tweakey-m4'
Diffstat (limited to 'src/ref')
| -rw-r--r-- | src/ref/multiplications.h | 20 | ||||
| -rw-r--r-- | src/ref/tweakey.c | 9 |
2 files changed, 24 insertions, 5 deletions
diff --git a/src/ref/multiplications.h b/src/ref/multiplications.h index 4de1848..c0645b9 100644 --- a/src/ref/multiplications.h +++ b/src/ref/multiplications.h @@ -71,6 +71,26 @@ static void _multiply_M3(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES]) y[0] = x[5]; } +static void _multiply_M4(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES]) +{ + uint8_t a_5 = x[5]<<3 ^ x[4]; + uint8_t a_4 = x[4]>>3 ^ x[3]; + uint8_t b_5 = a_5<<3 ^ a_4; + uint8_t b_4 = a_4>>3 ^ x[2]; + + uint8_t c_4 = b_4>>3 ^ x[6]<<2 ^ x[1]; + uint8_t c_5 = b_5<<3 ^ b_4; + + y[7] = b_5; + y[6] = c_5; + y[5] = c_5<<3 ^ c_4; + y[4] = c_4>>3 ^ x[5]<<2 ^ x[0]; + y[3] = a_5<<2 ^ x[7]; + y[2] = b_5<<2 ^ x[6]; + y[1] = x[5]; + y[0] = a_5; +} + static void _multiply_MR(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES]) { y[0] = x[1]; diff --git a/src/ref/tweakey.c b/src/ref/tweakey.c index 2f357ca..510f35a 100644 --- a/src/ref/tweakey.c +++ b/src/ref/tweakey.c @@ -63,10 +63,11 @@ void tweakey_state_extract( typedef void (*matrix_multiplication)(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES]); -static const matrix_multiplication ALPHAS[6] = { +static const matrix_multiplication ALPHAS[7] = { _multiply_M, _multiply_M2, _multiply_M3, + _multiply_M4, _multiply_MR, _multiply_MR2, _multiply_MR3 @@ -75,15 +76,13 @@ static const matrix_multiplication ALPHAS[6] = { void tweakey_state_update(uint8_t TK[TWEAKEY_BYTES]) { - /* Skip lane 0, as it is multiplied by the identity matrix. */ - - for (size_t j=1; j<LANES_NB; j++) + for (size_t j=0; j<LANES_NB; j++) { uint8_t *TKj = TK + j*LANE_BYTES; uint8_t TKj_old[LANE_BYTES]; memcpy(TKj_old, TKj, LANE_BYTES); - ALPHAS[j-1](TKj_old, TKj); + ALPHAS[j](TKj_old, TKj); } } |
