summaryrefslogtreecommitdiff
path: root/src/add_felicsref/tweakey.c
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@airbus.com>2019-05-21 13:53:07 +0200
committerKévin Le Gouguec <kevin.legouguec@airbus.com>2019-05-21 14:02:18 +0200
commite71424ebdd2a3f8a4d8439beb8a5cb2a64b12149 (patch)
tree1ff318c447bc43fb8a0f4cbf15c824bc18757ce2 /src/add_felicsref/tweakey.c
parentf9ceb6d2cacc40bb92e595db68131d8664505561 (diff)
downloadlilliput-ae-implem-e71424ebdd2a3f8a4d8439beb8a5cb2a64b12149.tar.xz
Réutilisation des multiplications dans l'implémentation FELICS
Plutôt que d'ajouter -Wno-unused-functin, on pourrait aussi déclarer les multiplications "static inline", ce qui par convention esquive les avertissements sur la non-utilisation.
Diffstat (limited to 'src/add_felicsref/tweakey.c')
-rw-r--r--src/add_felicsref/tweakey.c111
1 files changed, 7 insertions, 104 deletions
diff --git a/src/add_felicsref/tweakey.c b/src/add_felicsref/tweakey.c
index 635c179..c5532f8 100644
--- a/src/add_felicsref/tweakey.c
+++ b/src/add_felicsref/tweakey.c
@@ -15,30 +15,25 @@ http://creativecommons.org/publicdomain/zero/1.0/
---
This file provides an implementation of Lilliput-TBC's tweakey schedule,
-similar to the reference implementation save for a few manual optimizations:
+similar to the reference implementation save for one manual optimization:
+the loop over an array of function pointers was unrolled.
-- unused multiplication functions were removed using preprocessor
- conditionals based on the number of lanes;
-
-- the loop over an array of function pointers was unrolled.
-
-These handmade optimizations have been found to significantly decrease code
+This handmade optimization has been found to significantly decrease code
size and execution time on GCC versions used in the FELICS framework.
-This suggests that the compiler does not detect dead code nor does it
-recognize unrolling opportunities, despite the multiplication functions
-being static and thus limited in scope to the compilation unit.
+This suggests that the compiler does not recognize inlining opportunities,
+despite the multiplication functions being static and thus limited in scope
+to the compilation unit.
*/
#include <stdint.h>
#include <string.h>
#include "constants.h"
+#include "multiplications.h"
#include "tweakey.h"
-#define LANE_BITS 64
-#define LANE_BYTES (LANE_BITS/8)
#define LANES_NB (TWEAKEY_BYTES/LANE_BYTES)
@@ -75,98 +70,6 @@ void tweakey_state_extract(
}
-static void _multiply_M(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES])
-{
- y[7] = x[6];
- y[6] = x[5];
- y[5] = x[5]<<3 ^ x[4];
- y[4] = x[4]>>3 ^ x[3];
- y[3] = x[2];
- y[2] = x[6]<<2 ^ x[1];
- y[1] = x[0];
- y[0] = x[7];
-}
-
-static void _multiply_M2(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES])
-{
- uint8_t x_M_5 = x[5]<<3 ^ x[4];
- uint8_t x_M_4 = x[4]>>3 ^ x[3];
-
- y[7] = x[5];
- y[6] = x_M_5;
- y[5] = x_M_5<<3 ^ x_M_4;
- y[4] = x_M_4>>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];
-}
-
-static void _multiply_M3(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES])
-{
- uint8_t x_M_5 = x[5]<<3 ^ x[4];
- uint8_t x_M_4 = x[4]>>3 ^ x[3];
- uint8_t x_M2_5 = x_M_5<<3 ^ x_M_4;
- uint8_t x_M2_4 = x_M_4>>3 ^ x[2];
-
- y[7] = x_M_5;
- y[6] = x_M2_5;
- y[5] = x_M2_5<<3 ^ x_M2_4;
- y[4] = x_M2_4>>3 ^ x[6]<<2 ^ x[1];
- y[3] = x[5]<<2 ^ x[0];
- y[2] = x_M_5<<2 ^ x[7];
- y[1] = x[6];
- y[0] = x[5];
-}
-
-#if LANES_NB >= 5
-static void _multiply_MR(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES])
-{
- y[0] = x[1];
- y[1] = x[2];
- y[2] = x[3] ^ x[4]>>3;
- y[3] = x[4];
- y[4] = x[5] ^ x[6]<<3;
- y[5] = x[3]<<2 ^ x[6];
- y[6] = x[7];
- y[7] = x[0];
-}
-
-#if LANES_NB >= 6
-static void _multiply_MR2(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES])
-{
- uint8_t x_MR_4 = x[5] ^ x[6]<<3;
-
- y[0] = x[2];
- y[1] = x[3] ^ x[4]>>3;
- y[2] = x[4] ^ x_MR_4>>3;
- y[3] = x_MR_4;
- 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];
-}
-
-#if LANES_NB >= 7
-static void _multiply_MR3(const uint8_t x[LANE_BYTES], uint8_t y[LANE_BYTES])
-{
- uint8_t x_MR_4 = x[5] ^ x[6]<<3;
- uint8_t x_MR2_4 = x[3]<<2 ^ x[6] ^ x[7]<<3;
-
- y[0] = x[3] ^ x[4]>>3;
- y[1] = x[4] ^ x_MR_4>>3;
- y[2] = x_MR_4 ^ x_MR2_4>>3;
- y[3] = x_MR2_4;
- y[4] = x[0]<<3 ^ x[4]<<2 ^ x[7];
- y[5] = x_MR_4<<2 ^ x[0];
- y[6] = x[1];
- y[7] = x[2];
-}
-#endif
-#endif
-#endif
-
-
void tweakey_state_update(uint8_t TK[TWEAKEY_BYTES])
{
/* Skip lane 0, as it is multiplied by the identity matrix. */