Skip to content

Commit

Permalink
rm copy_from_slice
Browse files Browse the repository at this point in the history
  • Loading branch information
eschorn1 committed Apr 27, 2024
1 parent 55def32 commit 8dacc69
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
rust:
- 1.72 # MSRV 1.70 GA flaky
- 1.72 # MSRV 1.70 GA flaky
- stable
target:
- thumbv7em-none-eabi
Expand Down Expand Up @@ -96,17 +96,17 @@ jobs:
include:
# ARM32
- target: armv7-unknown-linux-gnueabihf
rust: 1.72 # MSRV 1.70 GA flaky
rust: 1.72 # MSRV 1.70 GA flaky
- target: armv7-unknown-linux-gnueabihf
rust: stable
# ARM64
- target: aarch64-unknown-linux-gnu
rust: 1.72 # MSRV 1.70 GA flaky
rust: 1.72 # MSRV 1.70 GA flaky
- target: aarch64-unknown-linux-gnu
rust: stable
# PPC32
- target: powerpc-unknown-linux-gnu
rust: 1.72 # MSRV 1.70 GA flaky
rust: 1.72 # MSRV 1.70 GA flaky
- target: powerpc-unknown-linux-gnu
rust: stable
runs-on: ubuntu-latest
Expand Down Expand Up @@ -158,4 +158,3 @@ jobs:
- run: ${{ matrix.deps }}
- run: cargo check --target ${{ matrix.target }} --all-features
- run: cargo test --release --target ${{ matrix.target }}

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = ["Eric Schorn <eschorn@integritychain.com>"]
documentation = "https://docs.rs/fips203"
categories = ["cryptography", "no-std"]
repository = "https://github.com/integritychain/fips203"
keywords = ["FIPS", "FIPS203", "lattice", "kyber", "encapsulation"]
keywords = ["kem", "FIPS203", "lattice", "kyber", "encapsulation"]
# MSRV set at 1.70 for debian testing, e.g. https://packages.debian.org/search?keywords=rustc
# This requires several marginally outdated dependencies, see below
rust-version = "1.70"
Expand All @@ -25,10 +25,11 @@ ml-kem-1024 = []


[dependencies] # Some are marginally outdated to retain MSRV 1.70
zeroize = { version = "1.6.0", default-features = false, features = ["zeroize_derive"] }
rand_core = { version = "0.6.4", default-features = false }
sha3 = { version = "0.10.2", default-features = false }
subtle = { version = "2.5.0", default-features = false, features = ['const-generics'] }
zeroize = { version = "1.6.0", default-features = false, features = ["zeroize_derive"] }


[dev-dependencies] # Some are marginally outdated to retain MSRV 1.70
rand = "0.8.5"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ without any unsafe code**. All three security parameter sets are fully supported
in constant-time (outside of rho, which is part of the encapsulation key sent across the trust boundary in the clear),
does not require the standard library, e.g. `#[no_std]`, has no heap allocations, e.g. no `alloc` needed, and optionally
exposes the `RNG` so it is suitable for the full range of applications down to the bare-metal. The API is stabilized
and the code is heavily biased towards safety and correctness; further performance optimizations will be implemented
and the code is heavily biased towards safety and correctness; further performance optimizations will be implemented
as the standard matures. This crate will quickly follow any changes to FIPS 203 as they become available.

See <https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.203.ipd.pdf> for a full description of the target functionality.
Expand Down
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ attr_fn_like_width = 100
struct_lit_width = 60
struct_variant_width = 60
array_width = 60
chain_width = 60
chain_width = 100
single_line_if_else_max_width = 50
single_line_let_else_max_width = 50
wrap_comments = false
Expand Down
8 changes: 3 additions & 5 deletions src/k_pke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ pub(crate) fn k_pke_key_gen<const K: usize, const ETA1_64: usize>(

// 1: d ←− B^{32} ▷ d is 32 random bytes (see Section 3.3)
let mut d = [0u8; 32];
rng.try_fill_bytes(&mut d)
.map_err(|_| "Alg12: random number generator failed")?;
rng.try_fill_bytes(&mut d).map_err(|_| "Alg12: random number generator failed")?;

// 2: (ρ, σ) ← G(d) ▷ expand to two pseudorandom 32-byte seeds
let (rho, sigma) = g(&[&d]);
Expand Down Expand Up @@ -129,11 +128,10 @@ pub(crate) fn k_pke_encrypt<const K: usize, const ETA1_64: usize, const ETA2_64:
}

// 3: ρ ← ekPKE [384k : 384k + 32] ▷ extract 32-byte seed from ekPKE
let mut rho = [0u8; 32];
rho.copy_from_slice(&ek[384 * K..(384 * K + 32)]);
let rho = &ek[384 * K..(384 * K + 32)].try_into().unwrap();

// Steps 4-8 in gen_a_hat() above
let a_hat = gen_a_hat(&rho);
let a_hat = gen_a_hat(rho);

// 9: for (i ← 0; i < k; i ++)
// 10: r[i] ← SamplePolyCBDη 1 (PRFη 1 (r, N)) ▷ r[i] ∈ Z^{256}_q sampled from CBD
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
// See <https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.203.ipd.pdf>

// TODO Roadmap
// 0. Stay current with FIPS 203 updates (due late summer 2024)
// 1. Perf: optimize/minimize modular reductions, minimize u16 arith, consider avx2/aarch64
// (currently, code is 'optimized' for safety and change-support, with reasonable perf)
// 1. Stay current with FIPS 203 updates (due late summer 2024)
// 2. Expand test coverage, looping test w/ check, add report badge
// 3. Slightly more intelligent fuzzing (e.g., as dk contains h(ek))
// 3. Perf: optimize/minimize modular reductions, minimize u16 arith, consider avx2/aarch64
// (currently, code is 'optimized' for safety and change-support, with reasonable perf)
// 4. Slightly more intelligent fuzzing (e.g., as dk contains h(ek))

// Functionality map per FIPS 203 draft
//
Expand Down

0 comments on commit 8dacc69

Please sign in to comment.