diff options
| author | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2019-05-21 13:53:07 +0200 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2019-05-21 14:02:18 +0200 |
| commit | 9bc87082cec1dc078a6c9c1d62098aced5ea8331 (patch) | |
| tree | 1ff318c447bc43fb8a0f4cbf15c824bc18757ce2 /src | |
| parent | 79ef56dfc57d18eb86df36bf5bb39c039f541e08 (diff) | |
| download | lilliput-ae-implem-9bc87082cec1dc078a6c9c1d62098aced5ea8331.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')
| -rw-r--r--[l---------] | src/add_felicsref/implem.mk | 41 | ||||
| l--------- | src/add_felicsref/multiplications.h | 1 | ||||
| -rw-r--r-- | src/add_felicsref/tweakey.c | 111 | ||||
| -rw-r--r-- | src/add_threshold/implem.mk | 3 |
4 files changed, 50 insertions, 106 deletions
diff --git a/src/add_felicsref/implem.mk b/src/add_felicsref/implem.mk index eb789fb..86b4048 120000..100644 --- a/src/add_felicsref/implem.mk +++ b/src/add_felicsref/implem.mk @@ -1 +1,40 @@ -../ref/implem.mk
\ No newline at end of file +# This file sets some implementation-specific variables and defines +# build dependencies. + +tests = $(basename $(wildcard test-*.c)) +traces = $(basename $(wildcard traces-*.c)) + + +# Don't trigger warnings for unused tweakey multiplications. +$(results_dir)/src/tweakey.o: CFLAGS += -Wno-unused-function + + +# Program => additional objects dependencies + +$(results_dir)/test-tbc-decrypt $(results_dir)/test-tbc-encrypt $(results_dir)/traces-tbc: \ +$(results_dir)/src/cipher.o $(results_dir)/src/tweakey.o + +$(results_dir)/test-ae-decrypt $(results_dir)/test-ae-encrypt $(results_dir)/test-ae-roundtrip $(results_dir)/traces-ae: \ +$(results_dir)/src/lilliput-$(mode).o $(results_dir)/src/cipher.o \ +$(results_dir)/src/tweakey.o + +$(results_dir)/test-tweakey: $(results_dir)/src/tweakey.o + +# Object => headers dependencies + +$(results_dir)/src/cipher.o: $(src_dir)/cipher.h \ +$(src_dir)/tweakey.h $(variant_dir)/parameters.h + +$(results_dir)/src/lilliput-i.o $(results_dir)/src/lilliput-ii.o: \ +$(src_dir)/lilliput-ae.h $(src_dir)/cipher.h $(src_dir)/constants.h \ +$(variant_dir)/parameters.h + +$(results_dir)/src/tweakey.o: $(src_dir)/tweakey.h \ +$(src_dir)/constants.h $(src_dir)/multiplications.h \ +$(variant_dir)/parameters.h + +$(results_dir)/test/test-tbc-encrypt.o $(results_dir)/test/test-tbc-decrypt.o $(results_dir)/test/traces-tbc.o: \ +$(src_dir)/cipher.h + +$(results_dir)/test/test-ae-encrypt.o $(results_dir)/test/test-ae-decrypt.o $(results_dir)/test/test-ae-roundtrip.o $(results_dir)/test/traces-ae.o: \ +$(src_dir)/lilliput-ae.h diff --git a/src/add_felicsref/multiplications.h b/src/add_felicsref/multiplications.h new file mode 120000 index 0000000..df7f6a6 --- /dev/null +++ b/src/add_felicsref/multiplications.h @@ -0,0 +1 @@ +../ref/multiplications.h
\ No newline at end of file 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. */ diff --git a/src/add_threshold/implem.mk b/src/add_threshold/implem.mk index 7e3ac8e..8d4d4a1 100644 --- a/src/add_threshold/implem.mk +++ b/src/add_threshold/implem.mk @@ -8,8 +8,9 @@ tests = $(filter-out test-tweakey,$(basename $(wildcard test-*.c))) # differ significantly. traces = $(basename $(wildcard traces-*.c)) + # Don't trigger warnings for "a&b ^ c". -CFLAGS += -Wno-parentheses +$(results_dir)/src/cipher.o: CFLAGS += -Wno-parentheses # Build dependencies: add random module; remove unused tests/traces. |
