Skip to content

Commit

Permalink
elliptic-curve: add MulByGenerator trait
Browse files Browse the repository at this point in the history
Adds a trait for performing scalar multiplication by the generator
point, which may use optimizations (e.g. precomputed tables) when
available
  • Loading branch information
tarcieri committed Jan 14, 2023
1 parent f69babe commit 9043691
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion elliptic-curve/src/arithmetic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! Elliptic curve arithmetic traits.
use crate::{
ops::LinearCombination, AffineXCoordinate, Curve, FieldBytes, IsHigh, PrimeCurve, ScalarCore,
ops::{LinearCombination, MulByGenerator},
AffineXCoordinate, Curve, FieldBytes, IsHigh, PrimeCurve, ScalarCore,
};
use core::fmt::Debug;
use subtle::{ConditionallySelectable, ConstantTimeEq};
Expand Down Expand Up @@ -42,6 +43,7 @@ pub trait CurveArithmetic: Curve {
+ From<Self::AffinePoint>
+ Into<Self::AffinePoint>
+ LinearCombination
+ MulByGenerator
+ group::Curve<AffineRepr = Self::AffinePoint>
+ group::Group<Scalar = Self::Scalar>;

Expand Down
12 changes: 12 additions & 0 deletions elliptic-curve/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ pub trait LinearCombination: Group {
}
}

/// Multiplication by the generator.
///
/// May use optimizations (e.g. precomputed tables) when available.
// TODO(tarcieri): replace this with `Group::mul_by_generator``? (see zkcrypto/group#44)
pub trait MulByGenerator: Group {
/// Multiply by the generator of the prime-order subgroup.
#[must_use]
fn mul_by_generator(scalar: &Self::Scalar) -> Self {
Self::generator() * scalar
}
}

/// Modular reduction.
pub trait Reduce<Uint: Integer + ArrayEncoding>: Sized {
/// Perform a modular reduction, returning a field element.
Expand Down

0 comments on commit 9043691

Please sign in to comment.