Skip to content

Commit

Permalink
fips/keccakf: replace keccakf1600 implementation for a more efficient…
Browse files Browse the repository at this point in the history
… one in ref and avx2 (some extra spills were needed)

Co-authored-by: Vincent Laporte <[email protected]>
  • Loading branch information
tfaoliveira and vbgl committed Feb 17, 2024
1 parent 44c44f8 commit e6a20d7
Show file tree
Hide file tree
Showing 9 changed files with 819 additions and 596 deletions.
268 changes: 142 additions & 126 deletions code/jasmin/mlkem_avx2/extraction/jkem_avx2.ec

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions code/jasmin/mlkem_avx2/fips202.jinc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ fn __keccak1600_scalar(
s_inlen = inlen;
s_rate = rate;

state = _keccakf1600_scalar(state);
state = _keccakf1600_(state);

inlen = s_inlen;
in = s_in;
Expand All @@ -180,7 +180,7 @@ fn __keccak1600_scalar(
s_outlen = outlen;
s_rate = rate;

state = _keccakf1600_scalar(state);
state = _keccakf1600_(state);

out = s_out;
outlen = s_outlen;
Expand All @@ -191,7 +191,7 @@ fn __keccak1600_scalar(
s_out = out;
}

state = _keccakf1600_scalar(state);
state = _keccakf1600_(state);
out = s_out;
outlen = s_outlen;

Expand Down Expand Up @@ -267,7 +267,7 @@ fn _isha3_256(reg ptr u8[32] out, reg u64 in inlen) -> reg ptr u8[32]
s_ilen = ilen;
s_r8 = r8;

state = _keccakf1600_scalar(state);
state = _keccakf1600_(state);

in = s_in;
ilen = s_ilen;
Expand All @@ -277,7 +277,7 @@ fn _isha3_256(reg ptr u8[32] out, reg u64 in inlen) -> reg ptr u8[32]
t8 = 0x06;
state = __add_final_block(state, in, ilen, t8, r8);

state = _keccakf1600_scalar(state);
state = _keccakf1600_(state);

out = s_out;

Expand Down Expand Up @@ -315,7 +315,7 @@ fn __isha3_512(reg ptr u8[64] out, reg u64 in, inline int inlen) -> stack u8[64]
s_ilen = ilen;
s_r8 = r8;

state = _keccakf1600_scalar(state);
state = _keccakf1600_(state);

in = s_in;
ilen = s_ilen;
Expand All @@ -325,7 +325,7 @@ fn __isha3_512(reg ptr u8[64] out, reg u64 in, inline int inlen) -> stack u8[64]
t8 = 0x06;
state = __add_final_block(state, in, ilen, t8, r8);

state = _keccakf1600_scalar(state);
state = _keccakf1600_(state);

out = s_out;

Expand Down Expand Up @@ -361,7 +361,7 @@ fn _shake256_1120_32(reg u64 out, reg u64 in0 in1) {

s_in = in1;

state = _keccakf1600_scalar(state);
state = _keccakf1600_(state);

r8 = SHAKE256_RATE;
ilen = MLKEM_INDCPA_CIPHERTEXTBYTES - (SHAKE256_RATE - MLKEM_SYMBYTES);
Expand All @@ -376,7 +376,7 @@ fn _shake256_1120_32(reg u64 out, reg u64 in0 in1) {
s_ilen = ilen;
s_r8 = r8;

state = _keccakf1600_scalar(state);
state = _keccakf1600_(state);

in = s_in;
ilen = s_ilen;
Expand All @@ -386,7 +386,7 @@ fn _shake256_1120_32(reg u64 out, reg u64 in0 in1) {
t8 = 0x1f;
state = __add_final_block(state, in, ilen, t8, r8);

state = _keccakf1600_scalar(state);
state = _keccakf1600_(state);

out = s_out;

Expand Down Expand Up @@ -422,7 +422,7 @@ fn _shake256_128_33(reg ptr u8[128] out, reg const ptr u8[33] in) -> stack u8[12
state[u8 33] ^= 0x1f;
state[u8 SHAKE256_RATE-1] ^= 0x80;

state = _keccakf1600_scalar(state);
state = _keccakf1600_(state);

out = sout;

Expand Down Expand Up @@ -455,7 +455,7 @@ fn _isha3_256_32(reg ptr u8[32] out, reg ptr u8[MLKEM_SYMBYTES] in) -> reg ptr u
state[u8 MLKEM_SYMBYTES] ^= 0x06;
state[u8 SHA3_256_RATE - 1] = 0x80;

state = _keccakf1600_scalar(state);
state = _keccakf1600_(state);

out = s_out;

Expand Down Expand Up @@ -489,7 +489,7 @@ fn _sha3_512_64(reg ptr u8[64] out, reg const ptr u8[64] in) -> stack u8[64]

out_s = out;

state = _keccakf1600_scalar(state);
state = _keccakf1600_(state);

out = out_s;

Expand Down Expand Up @@ -523,7 +523,7 @@ fn _sha3_512_32(reg ptr u8[64] out, reg const ptr u8[32] in) -> stack u8[64]

out_s = out;

state = _keccakf1600_scalar(state);
state = _keccakf1600_(state);

out = out_s;

Expand Down Expand Up @@ -567,7 +567,7 @@ fn _shake128_squeezeblock(reg ptr u64[25] state, reg ptr u8[SHAKE128_RATE] out)
inline int i;

out_s = out;
state = _keccakf1600_scalar(state);
state = _keccakf1600_(state);
out = out_s;

for i = 0 to SHAKE128_RATE/8
Expand Down
Loading

0 comments on commit e6a20d7

Please sign in to comment.