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

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ hash2curve = { path = "hash2curve" }
primefield = { path = "primefield" }
primeorder = { path = "primeorder" }

elliptic-curve = { git = "http://github.com/RustCrypto/traits.git" }
rustcrypto-group = { git = "https://github.com/RustCrypto/group" }
9 changes: 9 additions & 0 deletions p256/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,13 @@ impl PrimeCurveParams for NistP256 {
fn mul_by_generator_vartime(k: &Scalar) -> ProjectivePoint {
tables::BASEPOINT_TABLE_VARTIME.mul(k)
}

#[cfg(all(feature = "alloc", feature = "precomputed-tables"))]
fn mul_by_generator_and_mul_add_vartime(
a: &Scalar,
b_scalar: &Scalar,
b_point: &ProjectivePoint,
) -> ProjectivePoint {
tables::BASEPOINT_TABLE_VARTIME.lincomb(a, &[(*b_point, *b_scalar)])
}
}
9 changes: 9 additions & 0 deletions p384/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,13 @@ impl PrimeCurveParams for NistP384 {
fn mul_by_generator_vartime(k: &Scalar) -> ProjectivePoint {
tables::BASEPOINT_TABLE_VARTIME.mul(k)
}

#[cfg(all(feature = "alloc", feature = "precomputed-tables"))]
fn mul_by_generator_and_mul_add_vartime(
a: &Scalar,
b_scalar: &Scalar,
b_point: &ProjectivePoint,
) -> ProjectivePoint {
tables::BASEPOINT_TABLE_VARTIME.lincomb(a, &[(*b_point, *b_scalar)])
}
}
9 changes: 9 additions & 0 deletions p521/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,13 @@ impl PrimeCurveParams for NistP521 {
fn mul_by_generator_vartime(k: &Scalar) -> ProjectivePoint {
tables::BASEPOINT_TABLE_VARTIME.mul(k)
}

#[cfg(all(feature = "alloc", feature = "precomputed-tables"))]
fn mul_by_generator_and_mul_add_vartime(
a: &Scalar,
b_scalar: &Scalar,
b_point: &ProjectivePoint,
) -> ProjectivePoint {
tables::BASEPOINT_TABLE_VARTIME.lincomb(a, &[(*b_point, *b_scalar)])
}
}
15 changes: 14 additions & 1 deletion primeorder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub use elliptic_curve::{

use elliptic_curve::{
CurveArithmetic, Generate,
ops::{Invert, MulVartime},
ops::{Invert, LinearCombination, MulVartime},
subtle::CtOption,
};

Expand Down Expand Up @@ -73,6 +73,19 @@ pub trait PrimeCurveParams:
fn mul_by_generator_vartime(k: &Scalar<Self>) -> ProjectivePoint<Self> {
ProjectivePoint::GENERATOR.mul_vartime(k)
}

/// Multiply `a` by the generator of the prime-order subgroup, adding the result to the point
/// `P` multiplied by the scalar `b`, i.e. compute `aG + bP`.
fn mul_by_generator_and_mul_add_vartime(
a: &Scalar<Self>,
b_scalar: &Scalar<Self>,
b_point: &ProjectivePoint<Self>,
) -> ProjectivePoint<Self> {
ProjectivePoint::<Self>::lincomb_vartime(&[
(ProjectivePoint::GENERATOR, *a),
(*b_point, *b_scalar),
])
}
}

/// Trait which allows curves to specify a variable-time basepoint table.
Expand Down
7 changes: 2 additions & 5 deletions primeorder/src/projective.rs
Original file line number Diff line number Diff line change
Expand Up @@ -970,16 +970,13 @@ where
C::mul_by_generator_vartime(scalar)
}

// When we're guaranteed *not* to have basepoint tables available (because they need `alloc`)
// use linear combinations for this computation, but they're slower when they are available
// TODO(tarcieri): `WnafBase::multiscalar_mul` w\ basepoint table when `alloc` *is* available
#[cfg(not(feature = "alloc"))]
#[inline]
fn mul_by_generator_and_mul_add_vartime(
a: &Self::Scalar,
b_scalar: &Self::Scalar,
b_point: &Self,
) -> Self {
Self::lincomb(&[(Self::GENERATOR, *a), (*b_point, *b_scalar)])
C::mul_by_generator_and_mul_add_vartime(a, b_scalar, b_point)
}
}

Expand Down
9 changes: 9 additions & 0 deletions sm2/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,13 @@ impl PrimeCurveParams for Sm2 {
fn mul_by_generator_vartime(k: &Scalar) -> ProjectivePoint {
tables::BASEPOINT_TABLE_VARTIME.mul(k)
}

#[cfg(all(feature = "alloc", feature = "precomputed-tables"))]
fn mul_by_generator_and_mul_add_vartime(
a: &Scalar,
b_scalar: &Scalar,
b_point: &ProjectivePoint,
) -> ProjectivePoint {
tables::BASEPOINT_TABLE_VARTIME.lincomb(a, &[(*b_point, *b_scalar)])
}
}
Loading