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

commit e52d2c96531789fee70c1f1c5995c356ccbf9474
parent 962920c474261599f4bc13039b2d21d99b6b537a
Author: Kévin Le Gouguec <kevin.legouguec@airbus.com>
Date:   Mon,  1 Jul 2019 17:40:36 +0200

Factorisation de code dans l'implémentation à seuil

Plus facile à  lire, je trouve (pas besoin de  se demander "c'est quoi
cette division ?" à chaque fois).

Diffstat:
Msrc/add_threshold/tweakey.c | 17+++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/add_threshold/tweakey.c b/src/add_threshold/tweakey.c @@ -29,7 +29,9 @@ tweakey schedule, where the tweak and the key are split into two shares. #include "tweakey.h" -#define LANES_NB (TWEAKEY_BYTES/LANE_BYTES) +#define LANES_NB (TWEAKEY_BYTES/LANE_BYTES) +#define TWEAK_LANES_NB (TWEAK_BYTES/LANE_BYTES) +#define KEY_LANES_NB (KEY_BYTES/LANE_BYTES) void tweakey_state_init( @@ -72,8 +74,7 @@ void tweakey_state_extract( } } - - for (size_t j=0; j<(KEY_BYTES / LANE_BYTES); j++) + for (size_t j=0; j<KEY_LANES_NB; j++) { const uint8_t *TKj_Y = TK_Y + j*LANE_BYTES; @@ -103,7 +104,7 @@ void tweakey_state_update(uint8_t TK_X[TWEAKEY_BYTES], uint8_t TK_Y[KEY_BYTES]) { /* Skip lane 0, as it is multiplied by the identity matrix. */ - for (size_t j=1; j<(TWEAK_BYTES/LANE_BYTES); j++) + for (size_t j=1; j<TWEAK_LANES_NB; j++) { uint8_t *TKj_X = TK_X + j*LANE_BYTES; @@ -113,9 +114,9 @@ void tweakey_state_update(uint8_t TK_X[TWEAKEY_BYTES], uint8_t TK_Y[KEY_BYTES]) ALPHAS[j-1](TKj_old_X, TKj_X); } - for (size_t j=0; j<(KEY_BYTES/LANE_BYTES); j++) + for (size_t j=0; j<KEY_LANES_NB; j++) { - uint8_t *TKj_X = TK_X + (j + (TWEAK_BYTES/LANE_BYTES))*LANE_BYTES; + uint8_t *TKj_X = TK_X + (j + TWEAK_LANES_NB)*LANE_BYTES; uint8_t *TKj_Y = TK_Y + j*LANE_BYTES; uint8_t TKj_X_old[LANE_BYTES]; @@ -123,7 +124,7 @@ void tweakey_state_update(uint8_t TK_X[TWEAKEY_BYTES], uint8_t TK_Y[KEY_BYTES]) memcpy(TKj_X_old, TKj_X, LANE_BYTES); memcpy(TKj_Y_old, TKj_Y, LANE_BYTES); - ALPHAS[j-1 + (TWEAK_BYTES/LANE_BYTES)](TKj_X_old, TKj_X); - ALPHAS[j-1 + (TWEAK_BYTES/LANE_BYTES)](TKj_Y_old, TKj_Y); + ALPHAS[j-1 + TWEAK_LANES_NB](TKj_X_old, TKj_X); + ALPHAS[j-1 + TWEAK_LANES_NB](TKj_Y_old, TKj_Y); } }