lilliput-ae-reference-implementation

Implementations of Lilliput-AE submitted to the NIST LWC standardization process
git clone https://git.kevinlegouguec.net/lilliput-ae-reference-implementation
Log | Files | Refs | README

multiplications.h (3110B)


      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 each matrix M and M_R to the power n are
     19 implemented in distinct functions with shifts and XORs.
     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 a5 = x[5]<<3 ^ x[4];
     45     uint8_t a4 = x[4]>>3 ^ x[3];
     46 
     47     y[7] = x[5];
     48     y[6] = a5;
     49     y[5] = a5<<3   ^ a4;
     50     y[4] = a4>>3   ^ x[2];
     51     y[3] = x[6]<<2 ^ x[1];
     52     y[2] = x[5]<<2 ^ x[0];
     53     y[1] = x[7];
     54     y[0] = x[6];
     55 }
     56 
     57 static void _multiply_M3(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES])
     58 {
     59     uint8_t a5 = x[5]<<3 ^ x[4];
     60     uint8_t a4 = x[4]>>3 ^ x[3];
     61     uint8_t b5 = a5<<3   ^ a4;
     62     uint8_t b4 = a4>>3   ^ x[2];
     63 
     64     y[7] = a5;
     65     y[6] = b5;
     66     y[5] = b5<<3   ^ b4;
     67     y[4] = b4>>3   ^ x[6]<<2 ^ x[1];
     68     y[3] = x[5]<<2 ^ x[0];
     69     y[2] = a5<<2   ^ x[7];
     70     y[1] = x[6];
     71     y[0] = x[5];
     72 }
     73 
     74 static void _multiply_M4(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES])
     75 {
     76     uint8_t a5 = x[5]<<3 ^ x[4];
     77     uint8_t a4 = x[4]>>3 ^ x[3];
     78     uint8_t b5 = a5<<3   ^ a4;
     79     uint8_t b4 = a4>>3   ^ x[2];
     80     uint8_t c4 = b4>>3   ^ x[6]<<2 ^ x[1];
     81     uint8_t c5 = b5<<3   ^ b4;
     82 
     83     y[7] = b5;
     84     y[6] = c5;
     85     y[5] = c5<<3 ^ c4;
     86     y[4] = c4>>3 ^ x[5]<<2 ^ x[0];
     87     y[3] = a5<<2 ^ x[7];
     88     y[2] = b5<<2 ^ x[6];
     89     y[1] = x[5];
     90     y[0] = a5;
     91 }
     92 
     93 static void _multiply_MR(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES])
     94 {
     95     y[0] = x[1];
     96     y[1] = x[2];
     97     y[2] = x[3]    ^ x[4]>>3;
     98     y[3] = x[4];
     99     y[4] = x[5]    ^ x[6]<<3;
    100     y[5] = x[3]<<2 ^ x[6];
    101     y[6] = x[7];
    102     y[7] = x[0];
    103 }
    104 
    105 static void _multiply_MR2(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES])
    106 {
    107     uint8_t a4 = x[5] ^ x[6]<<3;
    108 
    109     y[0] = x[2];
    110     y[1] = x[3]    ^ x[4]>>3;
    111     y[2] = x[4]    ^ a4>>3;
    112     y[3] = a4;
    113     y[4] = x[3]<<2 ^ x[6]    ^ x[7]<<3;
    114     y[5] = x[4]<<2 ^ x[7];
    115     y[6] = x[0];
    116     y[7] = x[1];
    117 }
    118 
    119 static void _multiply_MR3(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES])
    120 {
    121     uint8_t a4 = x[5]    ^ x[6]<<3;
    122     uint8_t b4 = x[3]<<2 ^ x[6]    ^ x[7]<<3;
    123 
    124     y[0] = x[3]    ^ x[4]>>3;
    125     y[1] = x[4]    ^ a4>>3;
    126     y[2] = a4      ^ b4>>3;
    127     y[3] = b4;
    128     y[4] = x[0]<<3 ^ x[4]<<2 ^ x[7];
    129     y[5] = a4<<2   ^ x[0];
    130     y[6] = x[1];
    131     y[7] = x[2];
    132 }
    133 
    134 
    135 #endif /* MULTIPLICATIONS_H */