Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 26 additions & 0 deletions curve25519-dalek/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,32 @@ impl VartimePrecomputedStraus {
}
}

/// Return the number of static points in the precomputation.
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 = "unstable_avx512", nightly))]
VartimePrecomputedStraus::Avx512ifma(inner) => inner.len(),
VartimePrecomputedStraus::Scalar(inner) => inner.len(),
}
}

/// Determine if the precomputation is empty.
pub fn is_empty(&self) -> bool {
use crate::traits::VartimePrecomputedMultiscalarMul;

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

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,14 @@ impl VartimePrecomputedMultiscalarMul for VartimePrecomputedStraus {
}
}

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

fn is_empty(&self) -> bool {
self.static_lookup_tables.is_empty()
}

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 @@ -57,6 +57,14 @@ pub mod spec {
}
}

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

fn is_empty(&self) -> bool {
self.static_lookup_tables.is_empty()
}

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

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

fn is_empty(&self) -> bool {
self.0.is_empty()
}

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

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

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

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

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

fn is_empty(&self) -> bool {
self.0.is_empty()
}

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

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

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

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

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

/// Determine if the precomputation is empty.
fn is_empty(&self) -> bool;

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