Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt Kyber to use Init-Absorb-Squeeze* API #211

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d80f9ea
enabling the incremental (nblocks) API for Shake128 (scalar) in Kyber
karthikbhargavan Feb 20, 2024
2e73fbb
trying to extract c
karthikbhargavan Feb 21, 2024
b6f21bc
sort imports to work with kyber-crate.sh
franziskuskiefer Feb 21, 2024
635439b
eurydice initialization experiments
karthikbhargavan Feb 21, 2024
26aaa66
added SIMD - wip - and passing hax
karthikbhargavan Feb 22, 2024
2a2bf36
made sha3 internal state abstract
karthikbhargavan Feb 22, 2024
eee97d8
Updated ml-kem C extraction (#208)
franziskuskiefer Feb 23, 2024
9c6985b
enabling the incremental (nblocks) API for Shake128 (scalar) in Kyber
karthikbhargavan Feb 20, 2024
652f579
sort imports to work with kyber-crate.sh
franziskuskiefer Feb 21, 2024
5cf2b9d
added SIMD - wip - and passing hax
karthikbhargavan Feb 22, 2024
511c50c
hand edits to work around hax bug
karthikbhargavan Feb 23, 2024
b56defa
linux testing
karthikbhargavan Feb 24, 2024
4acdf81
aligned malloc and initialization
karthikbhargavan Feb 24, 2024
7dd3040
tested on mac
karthikbhargavan Feb 28, 2024
8b45a5f
fix matching on K for hax
karthikbhargavan Feb 28, 2024
f96d03d
eurydice
karthikbhargavan Feb 28, 2024
7b77f63
fixup kyber-crate.sh
franziskuskiefer Feb 28, 2024
0dc5d74
fixes for avx2/linux
karthikbhargavan Feb 28, 2024
7d4613d
Merge branch 'karthik/kyber_shake128_squeeze_nblocks' of github.com:c…
karthikbhargavan Feb 28, 2024
e3361fa
merged
karthikbhargavan Feb 28, 2024
9983cc2
rust format
karthikbhargavan Feb 29, 2024
d825ca1
merged main
karthikbhargavan Feb 29, 2024
c1f2058
new patches
karthikbhargavan Feb 29, 2024
fa602a6
improved C code generation by simplifying match in hash-functions
karthikbhargavan Mar 1, 2024
1c53421
recreated patches
karthikbhargavan Mar 1, 2024
1aea834
rust format
karthikbhargavan Mar 1, 2024
d73de68
undo accidental commit gcp -> cp
karthikbhargavan Mar 1, 2024
fa83765
updated extraction
karthikbhargavan Mar 1, 2024
7fc6a4c
updated code to free SHAKE state, avoiding memory leaks in C
karthikbhargavan Mar 2, 2024
19bf8ae
rust format
karthikbhargavan Mar 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ wasm-bindgen = { version = "0.2.87", optional = true }
# When using the hax toolchain, we have more dependencies.
# This is only required when doing proofs.
[target.'cfg(hax)'.dependencies]
hax-lib-macros = { version = "0.1.0-pre.1", git = "https://github.com/hacspec/hax" }
hax-lib-macros = { version = "0.1.0-pre.1", git = "https://github.com/hacspec/hax", branch = "main" }
hax-lib = { version = "0.1.0-pre.1", git = "https://github.com/hacspec/hax/", branch = "main" }

[target.'cfg(all(not(target_os = "windows"), target_arch = "x86_64", libjade))'.dependencies]
Expand Down
3 changes: 2 additions & 1 deletion hax-driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def shell(command, expect=0, cwd=None, env={}):
f"-** +libcrux::kem::kyber::** +!libcrux_platform::platform::* {exclude_sha3_implementations} -libcrux::**::types::index_impls::**",
"fstar",
"--interfaces",
"+* -libcrux::kem::kyber::types +!libcrux_platform::**",
"+* -libcrux::kem::kyber::types +!libcrux_platform::** +!libcrux::digest::**",
],
cwd=".",
env=hax_env,
Expand All @@ -136,6 +136,7 @@ def shell(command, expect=0, cwd=None, env={}):
# remove this when https://github.com/hacspec/hax/issues/465 is
# closed)
shell(["rm", "-f", "./sys/platform/proofs/fstar/extraction/*.fst"])

elif options.kyber_specification:
shell(
cargo_hax_into
Expand Down
5 changes: 3 additions & 2 deletions kyber-crate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ rm src/kyber512.rs
rm src/kyber1024.rs

# Build & test
cargo test
cargo build

# Extract
if [[ -z "$CHARON_HOME" ]]; then
Expand All @@ -90,5 +90,6 @@ if [[ -n "$HACL_PACKAGES_HOME" ]]; then
cp internal/*.h $HACL_PACKAGES_HOME/libcrux/include/internal/
cp *.h $HACL_PACKAGES_HOME/libcrux/include
cp *.c $HACL_PACKAGES_HOME/libcrux/src
else
echo "Please set HACL_PACKAGES_HOME to the hacl-packages directory to copy the code over" 1>&2
fi
echo "Please set HACL_PACKAGES_HOME to the hacl-packages directory to copy the code over" 1>&2
1,084 changes: 825 additions & 259 deletions proofs/fstar/extraction-edited.patch

Large diffs are not rendered by default.

128 changes: 64 additions & 64 deletions proofs/fstar/extraction-secret-independent.patch

Large diffs are not rendered by default.

48 changes: 0 additions & 48 deletions proofs/fstar/extraction/Libcrux.Digest.fst

This file was deleted.

48 changes: 39 additions & 9 deletions proofs/fstar/extraction/Libcrux.Digest.fsti
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,53 @@ val sha3_256_ (payload: t_Slice u8)
val sha3_512_ (payload: t_Slice u8)
: Prims.Pure (t_Array u8 (sz 64)) Prims.l_True (fun _ -> Prims.l_True)

val shake128 (v_LEN: usize) (data: t_Slice u8)
: Prims.Pure (t_Array u8 v_LEN) Prims.l_True (fun _ -> Prims.l_True)

val shake256 (v_LEN: usize) (data: t_Slice u8)
: Prims.Pure (t_Array u8 v_LEN) Prims.l_True (fun _ -> Prims.l_True)

val shake128x4_portable (v_LEN: usize) (data0 data1 data2 data3: t_Slice u8)
: Prims.Pure (t_Array u8 v_LEN & t_Array u8 v_LEN & t_Array u8 v_LEN & t_Array u8 v_LEN)
val t_Shake128StateX2:Type

val t_Shake128StateX3:Type

val t_Shake128StateX4:Type

val shake128_absorb_final_x2 (st: t_Shake128StateX2) (data0 data1: t_Slice u8)
: Prims.Pure t_Shake128StateX2 Prims.l_True (fun _ -> Prims.l_True)

val shake128_absorb_final_x3 (st: t_Shake128StateX3) (data0 data1 data2: t_Slice u8)
: Prims.Pure t_Shake128StateX3 Prims.l_True (fun _ -> Prims.l_True)

val shake128_absorb_final_x4 (st: t_Shake128StateX4) (data0 data1 data2 data3: t_Slice u8)
: Prims.Pure t_Shake128StateX4 Prims.l_True (fun _ -> Prims.l_True)

val shake128_free_x2 (st: t_Shake128StateX2)
: Prims.Pure Prims.unit Prims.l_True (fun _ -> Prims.l_True)

val shake128_free_x3 (st: t_Shake128StateX3)
: Prims.Pure Prims.unit Prims.l_True (fun _ -> Prims.l_True)

val shake128_free_x4 (st: t_Shake128StateX4)
: Prims.Pure Prims.unit Prims.l_True (fun _ -> Prims.l_True)

val shake128_init_x2: Prims.unit
-> Prims.Pure t_Shake128StateX2 Prims.l_True (fun _ -> Prims.l_True)

val shake128_init_x3: Prims.unit
-> Prims.Pure t_Shake128StateX3 Prims.l_True (fun _ -> Prims.l_True)

val shake128_init_x4: Prims.unit
-> Prims.Pure t_Shake128StateX4 Prims.l_True (fun _ -> Prims.l_True)

val shake128_squeeze_nblocks_x2 (v_OUTPUT_BYTES: usize) (st: t_Shake128StateX2)
: Prims.Pure (t_Shake128StateX2 & t_Array (t_Array u8 v_OUTPUT_BYTES) (sz 2))
Prims.l_True
(fun _ -> Prims.l_True)

val shake128x4_256_ (v_LEN: usize) (data0 data1 data2 data3: t_Slice u8)
: Prims.Pure (t_Array u8 v_LEN & t_Array u8 v_LEN & t_Array u8 v_LEN & t_Array u8 v_LEN)
val shake128_squeeze_nblocks_x3 (v_OUTPUT_BYTES: usize) (st: t_Shake128StateX3)
: Prims.Pure (t_Shake128StateX3 & t_Array (t_Array u8 v_OUTPUT_BYTES) (sz 3))
Prims.l_True
(fun _ -> Prims.l_True)

val shake128x4 (v_LEN: usize) (data0 data1 data2 data3: t_Slice u8)
: Prims.Pure (t_Array u8 v_LEN & t_Array u8 v_LEN & t_Array u8 v_LEN & t_Array u8 v_LEN)
val shake128_squeeze_nblocks_x4 (v_OUTPUT_BYTES: usize) (st: t_Shake128StateX4)
: Prims.Pure (t_Shake128StateX4 & t_Array (t_Array u8 v_OUTPUT_BYTES) (sz 4))
Prims.l_True
(fun _ -> Prims.l_True)
2 changes: 0 additions & 2 deletions proofs/fstar/extraction/Libcrux.Kem.Kyber.Constants.fsti
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@ let v_FIELD_MODULUS: i32 = 3329l

let v_H_DIGEST_SIZE: usize = sz 32

let v_REJECTION_SAMPLING_SEED_SIZE: usize = sz 168 *! sz 5

let v_SHARED_SECRET_SIZE: usize = sz 32
Loading
Loading