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
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ unused_qualifications = "warn"
crypto-common = { path = "crypto-common" }
digest = { path = "digest" }
signature = { path = "signature" }

rustcrypto-group = { git = "https://github.com/RustCrypto/group" }
31 changes: 31 additions & 0 deletions elliptic-curve/src/point/basepoint_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl<Point, const WINDOW_SIZE: usize> Deref for BasepointTable<Point, WINDOW_SIZ
#[cfg(feature = "alloc")]
pub(super) mod vartime {
use super::LazyLock;
use alloc::vec::Vec;
use core::ops::Mul;
use group::{Group, WnafBase, WnafScalar};

Expand Down Expand Up @@ -151,6 +152,36 @@ pub(super) mod vartime {
pub fn mul(&self, scalar: &Point::Scalar) -> Point {
self.table.mul(&WnafScalar::new(scalar))
}

/// Multiply `Point::generator` by the given scalar in variable-time, then compute a linear
/// combination of the remaining points and scalars, i.e.
///
/// ```text
/// scalar * G + scalars[0] * Points[0] + ...
/// ```
pub fn lincomb(
&self,
scalar: &Point::Scalar,
points_and_scalars: &[(Point, Point::Scalar)],
) -> Point {
let mut bases = Vec::with_capacity(points_and_scalars.len() + 1);
bases.push(self.table.clone());
bases.extend(
points_and_scalars
.iter()
.map(|(point, _)| WnafBase::new(*point)),
);

let mut scalars = Vec::with_capacity(points_and_scalars.len() + 1);
scalars.push(WnafScalar::new(scalar));
scalars.extend(
points_and_scalars
.iter()
.map(|(_, scalar)| WnafScalar::new(scalar)),
);

WnafBase::multiscalar_mul(scalars.iter(), bases.iter())
}
}

impl<Point: Group, const WINDOW_SIZE: usize> Default for BasepointTableVartime<Point, WINDOW_SIZE> {
Expand Down
Loading