Commit 3ba6f927 authored by Gaëtan Cassiers's avatar Gaëtan Cassiers

Add other constant addition modes

define SHCST to
* 1: old constant addition
* 8: add 1 byte per bundle, on 1 word (always the same), value of the byte differs per
bundle
* 32: add 4 bytes per bundle, on 1 word (always the same), the word is
rotated by 8 bits for each bundle.
parent 53a09d84
......@@ -30,18 +30,26 @@
#define SHADOW_NS 6 // Number of steps
#define SHADOW_NR 2 * SHADOW_NS // Number of rounds
#define ROTL(x, n) ((x << n) | (x >> ((32-n) & 32)))
#define XORLSS(DEST, OP, SHIFT) do { \
(DEST)[0] ^= ((OP)[0] << (SHIFT)); \
(DEST)[1] ^= ((OP)[1] << (SHIFT)); \
(DEST)[2] ^= ((OP)[2] << (SHIFT)); \
(DEST)[3] ^= ((OP)[3] << (SHIFT)); } while (0)
#if (SHCST==1)
#define XORCST(DEST, LFSR, SHIFT) do { \
(DEST)[0] ^= ((LFSR)>>3 & 0x1)<< (SHIFT); \
(DEST)[1] ^= ((LFSR)>>2 & 0x1)<< (SHIFT); \
(DEST)[2] ^= ((LFSR)>>1 & 0x1)<< (SHIFT); \
(DEST)[3] ^= ((LFSR) & 0x1)<< (SHIFT); } while (0)
#elif (SHCST==8)
#define XORCST(DEST, LFSR, SHIFT) do { \
(DEST)[0] ^= (LFSR) & (0xff << (8*(SHIFT))); } while (0)
#elif (SHCST==32)
#define XORCST(DEST, LFSR, SHIFT) do { \
(DEST)[0] ^= ROTL((LFSR), (8*(SHIFT))); } while (0)
#endif
static uint32_t update_lfsr(uint32_t lfsr) {
uint32_t b = lfsr & 0x1;
return (lfsr^(b<<3) | b<<4)>>1;
}
// Shadow permutation. Updates state.
void shadow(shadow_state state) {
......@@ -55,14 +63,13 @@ void shadow(shadow_state state) {
sbox_layer(state[b]);
}
uint32_t b = lfsr & 0x1;
lfsr = (lfsr^(b<<3) | b<<4)>>1; // update LFSR
lfsr = update_lfsr(lfsr);
dbox_mls_layer(state);
for (unsigned int b = 0; b < MLS_BUNDLES; b++) {
XORCST(state[b], lfsr, b);
}
b = lfsr & 0x1;
lfsr = (lfsr^(b<<3) | b<<4)>>1; // update LFSR
lfsr = update_lfsr(lfsr);
}
}
......@@ -17,6 +17,10 @@ SHADOW_TYPE?=shadow_32bit
#CFLAGS+=-DDBOX=8 # dbox over 8 bit
CFLAGS+=-DDBOX=1 # dbox over 1 bit
CFLAGS+=-DSHCST=1 # old cst addition
#CFLAGS+=-DSHCST=8 # 8 bit per bundle (on 1 word)
#CFLAGS+=-DSHCST=32 # 32 bits per bundle (on 1 word)
ifeq "$(CLYDE_TYPE)" "clyde_64bit"
CFLAGS+=-mbmi2
endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment