summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@airbus.com>2019-07-01 17:40:36 +0200
committerKévin Le Gouguec <kevin.legouguec@airbus.com>2019-07-01 17:40:36 +0200
commit6b148934c4cc1992dda774bff87acc28c9961aa1 (patch)
tree3b8bd44d277d05f8c36e9f1d976ace7a80ed65f2
parent710d5908e1be6dd6e66663491b9fd8e0ac86b7e1 (diff)
downloadlilliput-ae-implem-6b148934c4cc1992dda774bff87acc28c9961aa1.tar.xz
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).
-rw-r--r--src/add_threshold/tweakey.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/add_threshold/tweakey.c b/src/add_threshold/tweakey.c
index 888e893..8f531d9 100644
--- 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);
}
}