-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a51c1c6
commit 5ff8d90
Showing
6 changed files
with
256 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
src/crypto_kem/frodo/frodo976shake/amd64/ref/indcpa.jinc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
inline | ||
fn __indcpa_keypair_derand( | ||
#spill_to_mmx reg ptr u8[BYTES_SEED_A + BYTES_SEED_SE] coins | ||
) -> stack u8[BYTES_PK], stack u8[2*NNBAR] { | ||
stack u8[BYTES_PK] pk; // seedA || b | ||
stack u8[2*NNBAR] sk; // S_T | ||
stack u16[2 * NNBAR] SE; | ||
stack u16[NNBAR] B; | ||
|
||
reg u64 i t; | ||
|
||
i = 0; | ||
while (i < BYTES_SEED_A/8) { | ||
t = coins[u64 i]; | ||
pk[u64 i] = t; | ||
i += 1; | ||
} | ||
|
||
() = #spill(coins); | ||
// gen S || E | ||
SE = __shake256_r_opt(SE, coins[BYTES_SEED_A:BYTES_SEED_SE]); | ||
|
||
SE = __sample_2NNBAR(SE); | ||
|
||
// B = A*S+E | ||
B = __AS_plus_E_opt(B, pk[0:BYTES_SEED_A], SE[0:NNBAR], SE[NNBAR:NNBAR]); | ||
|
||
// pack | ||
pk[BYTES_SEED_A:D * N] = __pack_B(pk[BYTES_SEED_A:D * N], B); | ||
|
||
i = 0; | ||
while (i < 2 * NNBAR / 8) { | ||
t = SE[u64 i]; | ||
sk[u64 i] = t; | ||
i += 1; | ||
} | ||
|
||
return pk, sk; | ||
} | ||
|
||
inline | ||
fn __indcpa_enc_derand( | ||
#spill_to_mmx reg ptr u8[BYTES_CT - BYTES_SALT] ct, | ||
#spill_to_mmx reg ptr u8[BYTES_SEC] u, | ||
#spill_to_mmx reg ptr u8[BYTES_PK] pk, | ||
#spill_to_mmx reg ptr u8[BYTES_SEED_SE] coins | ||
) -> reg ptr u8[BYTES_CT - BYTES_SALT] { | ||
reg u64 i t; | ||
|
||
// 0x96 || seed_SE | ||
stack u8[1 + BYTES_SEED_SE] seedSE; | ||
seedSE[0] = 0x96; | ||
|
||
// S' || E' || E'' | ||
stack u16[2 * NNBAR + NBAR * NBAR] SEE; | ||
stack u16[NNBAR] B; | ||
reg ptr u16[NNBAR] Bp; | ||
stack u16[NBAR * NBAR] C; | ||
reg ptr u16[NBAR * NBAR] V; | ||
|
||
// stack u8[BYTES_CT - BYTES_SALT] ct; | ||
|
||
i = 0; | ||
while (i < BYTES_SEED_SE/8) { | ||
t = coins[u64 i]; | ||
seedSE.[u64 1 + 8*i] = t; | ||
i += 1; | ||
} | ||
|
||
// B <- Unpack(b) | ||
B = __unpack_B(B, pk[BYTES_SEED_A:D * N]); | ||
C = __encode(C, u); | ||
|
||
() = #spill(ct, u, pk, coins); | ||
|
||
// gen input bit string for sampling S and E | ||
SEE = __shake256_encap_r_opt(SEE, seedSE); | ||
|
||
// S' || E' | ||
SEE[0:2 * NNBAR] = __sample_2NNBAR(SEE[0:2 * NNBAR]); | ||
// E'' | ||
SEE[NNBAR * 2:NBAR * NBAR] = __sample_NBAR2(SEE[NNBAR * 2:NBAR * NBAR]); | ||
|
||
// B' = S'A + E'' | ||
Bp = SEE[NNBAR:NNBAR]; | ||
|
||
() = #unspill(pk); | ||
Bp = __SA_plus_E_opt(Bp, pk[0:BYTES_SEED_A], SEE[0:NNBAR]); | ||
|
||
// V = S'B + E'' | ||
V = SEE[NNBAR*2:NBAR*NBAR]; | ||
V = __SB_plus_E_opt(V, SEE[0:NNBAR], B); | ||
|
||
// C = V + Encode(u) | ||
C = __matrix_add(C, V); | ||
|
||
// c1 <- Pack(B') | ||
() = #unspill(ct); | ||
ct[0:D * N] = __pack_B(ct[0:D * N], Bp); | ||
// c2 <- Pack(C) | ||
ct[D * N: D * NBAR] = __pack_C(ct[D * N: D * NBAR], C); | ||
|
||
return ct; | ||
} | ||
|
||
inline | ||
fn __indcpa_dec( | ||
#spill_to_mmx reg ptr u8[BYTES_SEC] pt, | ||
#spill_to_mmx reg ptr u8[BYTES_CT - BYTES_SALT] ct, | ||
#spill_to_mmx reg ptr u8[2*NNBAR] sk | ||
) -> reg ptr u8[BYTES_SEC] { | ||
stack u16[NNBAR] Bp; | ||
stack u16[NBAR * NBAR] M C; | ||
|
||
// B' <- Unpack(c1) | ||
Bp = __unpack_B(Bp, ct[0:D * N]); | ||
// C <- Unpack(c2) | ||
C = __unpack_C(C, ct[D * N:D * NBAR]); | ||
|
||
// M = C - B'S | ||
M = __mul_BS_opt(M, Bp, sk); | ||
M = __matrix_sub(M, C); | ||
pt = __decode(pt, M); | ||
|
||
return pt; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.