multiplications.h (2323B)
1 /* 2 Implementation of the Lilliput-AE tweakable block cipher. 3 4 Authors, hereby denoted as "the implementer": 5 Kévin Le Gouguec, 6 2019. 7 8 For more information, feedback or questions, refer to our website: 9 https://paclido.fr/lilliput-ae 10 11 To the extent possible under law, the implementer has waived all copyright 12 and related or neighboring rights to the source code in this file. 13 http://creativecommons.org/publicdomain/zero/1.0/ 14 15 --- 16 17 This file implements the alpha-multiplications used in Lilliput-TBC's 18 tweakey schedule, where matrices M and M_R to the power n>1 are 19 implemented by applying functions for M and M_R n times. 20 */ 21 22 #ifndef MULTIPLICATIONS_H 23 #define MULTIPLICATIONS_H 24 25 #include <stdint.h> 26 27 #include "constants.h" 28 29 30 static void _multiply_M(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES]) 31 { 32 y[7] = x[6]; 33 y[6] = x[5]; 34 y[5] = x[5]<<3 ^ x[4]; 35 y[4] = x[4]>>3 ^ x[3]; 36 y[3] = x[2]; 37 y[2] = x[6]<<2 ^ x[1]; 38 y[1] = x[0]; 39 y[0] = x[7]; 40 } 41 42 static void _multiply_M2(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES]) 43 { 44 uint8_t M_x[LANE_BYTES]; 45 _multiply_M(x, M_x); 46 _multiply_M(M_x, y); 47 } 48 49 static void _multiply_M3(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES]) 50 { 51 uint8_t M_x[LANE_BYTES]; 52 uint8_t M2_x[LANE_BYTES]; 53 _multiply_M(x, M_x); 54 _multiply_M(M_x, M2_x); 55 _multiply_M(M2_x, y); 56 } 57 58 static void _multiply_M4(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES]) 59 { 60 uint8_t M_x[LANE_BYTES]; 61 uint8_t M2_x[LANE_BYTES]; 62 uint8_t M3_x[LANE_BYTES]; 63 _multiply_M(x, M_x); 64 _multiply_M(M_x, M2_x); 65 _multiply_M(M2_x, M3_x); 66 _multiply_M(M3_x, y); 67 } 68 69 static void _multiply_MR(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES]) 70 { 71 y[0] = x[1]; 72 y[1] = x[2]; 73 y[2] = x[3] ^ x[4]>>3; 74 y[3] = x[4]; 75 y[4] = x[5] ^ x[6]<<3; 76 y[5] = x[3]<<2 ^ x[6]; 77 y[6] = x[7]; 78 y[7] = x[0]; 79 } 80 81 static void _multiply_MR2(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES]) 82 { 83 uint8_t MR_x[LANE_BYTES]; 84 _multiply_MR(x, MR_x); 85 _multiply_MR(MR_x, y); 86 } 87 88 static void _multiply_MR3(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES]) 89 { 90 uint8_t MR_x[LANE_BYTES]; 91 uint8_t MR2_x[LANE_BYTES]; 92 _multiply_MR(x, MR_x); 93 _multiply_MR(MR_x, MR2_x); 94 _multiply_MR(MR2_x, y); 95 } 96 97 98 #endif /* MULTIPLICATIONS_H */