Skip to content

Commit

Permalink
ga update
Browse files Browse the repository at this point in the history
  • Loading branch information
eschorn1 committed Oct 28, 2024
1 parent 346b6f8 commit 14d5b6d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ jobs:


# TODO: Temp 'fix' for Rust 1.80/1.81 problem involving 'time'; to be unwound...
# cargo_outdated:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: dtolnay/rust-toolchain@stable
# - name: Install cargo outdated
# run: cargo install --locked cargo-outdated
# - name: Run cargo outdated
# run: cargo outdated -R
cargo_outdated:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Install cargo outdated
run: cargo install --locked cargo-outdated
- name: Run cargo outdated
run: cargo outdated -R


clippy:
Expand Down
19 changes: 15 additions & 4 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,17 @@ pub(crate) fn mat_vec_mul<const K: usize, const L: usize>(
w_hat
}

// Algorithm 44: `AddNTT()` and Algorithm 46 `AddVectorNTT()`
/// Vector addition; e.g., fips 203 bottom of page 9, second row: `z_hat` = `u_hat` + `v_hat`

// Note Algorithm 44 has been dissolved into its place of use(s)

/// Algorithm 46: `AddVectorNTT(v_hat, w_hat)` on page 45.
/// Computes the sum `v_hat + w_hat` of two vectors `v_hat`, `w_hat` over `𝑇_𝑞`.
///
/// **Input**: `ℓ ∈ ℕ, v_hat ∈ 𝑇_𝑞^ℓ , w_hat ∈ 𝑇_𝑞^ℓ`. <br>
/// **Output**: `u_hat ∈ 𝑇_𝑞^ℓ`.
#[must_use]
pub(crate) fn add_vector_ntt<const K: usize>(vec_a: &[R; K], vec_b: &[R; K]) -> [R; K] {
core::array::from_fn(|k| R(core::array::from_fn(|n| vec_a[k].0[n] + vec_b[k].0[n])))
pub(crate) fn add_vector_ntt<const K: usize>(v_hat: &[R; K], w_hat: &[R; K]) -> [R; K] {
core::array::from_fn(|k| R(core::array::from_fn(|n| v_hat[k].0[n] + w_hat[k].0[n])))
}


Expand All @@ -145,6 +151,11 @@ pub(crate) fn infinity_norm<const ROW: usize>(w: &[R; ROW]) -> i32 {
}


/// Algorithm 49: MontgomeryReduce(𝑎) on page 50.
/// Computes 𝑎 ⋅ 2−32 mod 𝑞.
///
/// **Input**: Integer 𝑎 with −231 𝑞 ≤ 𝑎 ≤ 231 𝑞.
/// **Output**: 𝑟 ≡ 𝑎 ⋅ 2−32 mod 𝑞.
#[allow(clippy::cast_possible_truncation)] // a as i32, res as i32
pub(crate) const fn mont_reduce(a: i64) -> i32 {
const QINV: i32 = 58_728_449; // (Q * QINV) % 2**32 = 1
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
// Algorithm 40 UseHint(h,r) on page 41 --> high_low.rs
// Algorithm 41 NTT(w) on page 43 --> ntt.rs
// Algorithm 42 NTT−1(wˆ) on page 44 --> ntt.rs
// Algorithm 43 BitRev8(m) on page 44 --> helpers.rs
// Algorithm 43 BitRev8(m) on page 44 --> not needed to to zeta table
// Algorithm 44 AddNTT(a,b)̂ on page 45 --> helpers.rs
// Algorithm 45 MultiplyNTT(a,b)̂ on page 45 --> helpers.rs
// Algorithm 46 AddVectorNTT(v,w) on page 45 --> helpers.rs
Expand Down

0 comments on commit 14d5b6d

Please sign in to comment.