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
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
4 changes: 3 additions & 1 deletion elliptic-curve/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use crate::{
bigint::{Limb, U256},
error::{Error, Result},
ops::{LinearCombination, Reduce},
ops::{LinearCombination, MulByGenerator, Reduce},
pkcs8,
rand_core::RngCore,
sec1::{CompressedPoint, FromEncodedPoint, ToEncodedPoint},
Expand Down Expand Up @@ -766,6 +766,8 @@ impl MulAssign<&Scalar> for ProjectivePoint {
}
}

impl MulByGenerator for ProjectivePoint {}

impl Neg for ProjectivePoint {
type Output = ProjectivePoint;

Expand Down
13 changes: 13 additions & 0 deletions elliptic-curve/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ 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)
#[cfg(feature = "arithmetic")]
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