Skip to content

Commit

Permalink
Add precomputation length
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronFeickert committed Aug 3, 2024
1 parent 0964f80 commit b311796
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions curve25519-dalek/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ impl VartimePrecomputedStraus {
}
}

pub fn len(&self) -> usize {
use crate::traits::VartimePrecomputedMultiscalarMul;

match self {
#[cfg(curve25519_dalek_backend = "simd")]
VartimePrecomputedStraus::Avx2(inner) => inner.len(),
#[cfg(all(curve25519_dalek_backend = "simd", nightly))]
VartimePrecomputedStraus::Avx512ifma(inner) => inner.len(),
VartimePrecomputedStraus::Scalar(inner) => inner.len(),
}
}

pub fn optional_mixed_multiscalar_mul<I, J, K>(
&self,
static_scalars: I,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ impl VartimePrecomputedMultiscalarMul for VartimePrecomputedStraus {
}
}

fn len(&self) -> usize {
self.static_lookup_tables.len()
}

fn optional_mixed_multiscalar_mul<I, J, K>(
&self,
static_scalars: I,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ pub mod spec {
}
}

fn len(&self) -> usize {
self.static_lookup_tables.len()
}

fn optional_mixed_multiscalar_mul<I, J, K>(
&self,
static_scalars: I,
Expand Down
6 changes: 6 additions & 0 deletions curve25519-dalek/src/edwards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,10 @@ impl VartimePrecomputedMultiscalarMul for VartimeEdwardsPrecomputation {
Self(crate::backend::VartimePrecomputedStraus::new(static_points))
}

fn len(&self) -> usize {
self.0.len()
}

fn optional_mixed_multiscalar_mul<I, J, K>(
&self,
static_scalars: I,
Expand Down Expand Up @@ -2136,6 +2140,8 @@ mod test {

let precomputation = VartimeEdwardsPrecomputation::new(static_points.iter());

assert_eq!(precomputation.len(), 128);

let P = precomputation.vartime_mixed_multiscalar_mul(
&static_scalars,
&dynamic_scalars,
Expand Down
6 changes: 6 additions & 0 deletions curve25519-dalek/src/ristretto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,10 @@ impl VartimePrecomputedMultiscalarMul for VartimeRistrettoPrecomputation {
))
}

fn len(&self) -> usize {
self.0.len()
}

fn optional_mixed_multiscalar_mul<I, J, K>(
&self,
static_scalars: I,
Expand Down Expand Up @@ -1852,6 +1856,8 @@ mod test {

let precomputation = VartimeRistrettoPrecomputation::new(static_points.iter());

assert_eq!(precomputation.len(), 128);

let P = precomputation.vartime_mixed_multiscalar_mul(
&static_scalars,
&dynamic_scalars,
Expand Down
3 changes: 3 additions & 0 deletions curve25519-dalek/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ pub trait VartimePrecomputedMultiscalarMul: Sized {
I: IntoIterator,
I::Item: Borrow<Self::Point>;

/// Return the number of static points in the precomputation.
fn len(&self) -> usize;

/// Given `static_scalars`, an iterator of public scalars
/// \\(b_i\\), compute
/// $$
Expand Down

0 comments on commit b311796

Please sign in to comment.