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 @@ -58,4 +58,5 @@ crypto-common = { path = "crypto-common" }
digest = { path = "digest" }
signature = { path = "signature" }

rustcrypto-ff = { git = "https://github.com/RustCrypto/ff" }
rustcrypto-group = { git = "https://github.com/RustCrypto/group" }
6 changes: 4 additions & 2 deletions 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::{
Curve, CurveGroup, Error, FieldBytes, Group, NonZeroScalar, PrimeCurve, ScalarValue,
Curve, CurveAffine, CurveGroup, Error, FieldBytes, Group, NonZeroScalar, PrimeCurve,
ScalarValue,
ctutils::{CtEq, CtSelect},
ops::{Invert, LinearCombination, Mul, MulByGeneratorVartime, MulVartime, Reduce},
point::{AffineCoordinates, NonIdentity},
Expand All @@ -23,6 +24,7 @@ pub trait CurveArithmetic: Curve {
+ ConstantTimeEq
+ CtEq
+ CtSelect
+ CurveAffine<Curve = Self::ProjectivePoint, Scalar = Self::Scalar>
+ Debug
+ Default
+ DefaultIsZeroes
Expand Down Expand Up @@ -64,7 +66,7 @@ pub trait CurveArithmetic: Curve {
+ MulVartime<Self::Scalar>
+ for<'a> MulVartime<&'a Self::Scalar>
+ TryInto<NonIdentity<Self::ProjectivePoint>, Error = Error>
+ CurveGroup<AffineRepr = Self::AffinePoint>
+ CurveGroup<Affine = Self::AffinePoint>
+ Group<Scalar = Self::Scalar>;

/// Scalar field modulo this curve's order.
Expand Down
38 changes: 34 additions & 4 deletions elliptic-curve/src/dev/mock_curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
//! generically over curves without having to pull in a complete curve implementation.

use crate::{
BatchNormalize, Curve, CurveArithmetic, CurveGroup, FieldBytesEncoding, Generate, PrimeCurve,
BatchNormalize, Curve, CurveAffine, CurveArithmetic, CurveGroup, FieldBytesEncoding, Generate,
PrimeCurve,
array::typenum::U32,
bigint::{Limb, Odd, U256, modular::Retrieve},
ctutils,
Expand Down Expand Up @@ -92,7 +93,7 @@ impl Field for Scalar {
const ZERO: Self = Self(ScalarValue::ZERO);
const ONE: Self = Self(ScalarValue::ONE);

fn try_from_rng<R: TryRng + ?Sized>(rng: &mut R) -> core::result::Result<Self, R::Error> {
fn try_random<R: TryRng + ?Sized>(rng: &mut R) -> core::result::Result<Self, R::Error> {
let mut bytes = FieldBytes::default();

loop {
Expand Down Expand Up @@ -464,6 +465,27 @@ impl AffineCoordinates for AffinePoint {
}
}

impl CurveAffine for AffinePoint {
type Curve = ProjectivePoint;
type Scalar = Scalar;

fn identity() -> Self {
Self::Identity
}

fn generator() -> Self {
Self::Generator
}

fn is_identity(&self) -> Choice {
unimplemented!();
}

fn to_curve(&self) -> ProjectivePoint {
unimplemented!();
}
}

impl ConstantTimeEq for AffinePoint {
fn ct_eq(&self, other: &Self) -> Choice {
match (self, other) {
Expand Down Expand Up @@ -580,6 +602,14 @@ impl Mul<NonZeroScalar> for AffinePoint {
}
}

impl Neg for AffinePoint {
type Output = Self;

fn neg(self) -> Self {
unimplemented!();
}
}

impl TryFrom<AffinePoint> for NonIdentity<AffinePoint> {
type Error = Error;

Expand Down Expand Up @@ -709,7 +739,7 @@ impl TryFrom<ProjectivePoint> for NonIdentity<ProjectivePoint> {
impl group::Group for ProjectivePoint {
type Scalar = Scalar;

fn try_from_rng<R: TryRng + ?Sized>(_rng: &mut R) -> core::result::Result<Self, R::Error> {
fn try_random<R: TryRng + ?Sized>(_rng: &mut R) -> core::result::Result<Self, R::Error> {
unimplemented!();
}

Expand Down Expand Up @@ -775,7 +805,7 @@ impl group::GroupEncoding for ProjectivePoint {
}

impl CurveGroup for ProjectivePoint {
type AffineRepr = AffinePoint;
type Affine = AffinePoint;

fn to_affine(&self) -> AffinePoint {
match self {
Expand Down
2 changes: 1 addition & 1 deletion elliptic-curve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub use {
scalar::{NonZeroScalar, Scalar},
},
ff::{self, Field, PrimeField},
group::{self, Curve as CurveGroup, Group},
group::{self, Curve as CurveGroup, CurveAffine, Group},
};

#[cfg(any(feature = "pkcs8", feature = "sec1"))]
Expand Down
2 changes: 1 addition & 1 deletion elliptic-curve/src/point/basepoint_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pub(super) mod vartime {
.map(|(_, scalar)| WnafScalar::new(scalar)),
);

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

Expand Down
14 changes: 7 additions & 7 deletions elliptic-curve/src/point/non_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ where
}

/// Converts this element into its affine representation.
pub fn to_affine(self) -> NonIdentity<P::AffineRepr> {
pub fn to_affine(self) -> NonIdentity<P::Affine> {
NonIdentity {
point: self.point.to_affine(),
}
Expand Down Expand Up @@ -148,11 +148,11 @@ impl<P> AsRef<P> for NonIdentity<P> {

impl<const N: usize, P> BatchNormalize<[Self; N]> for NonIdentity<P>
where
P: CurveGroup + BatchNormalize<[P; N], Output = [P::AffineRepr; N]>,
P: CurveGroup + BatchNormalize<[P; N], Output = [P::Affine; N]>,
{
type Output = [NonIdentity<P::AffineRepr>; N];
type Output = [NonIdentity<P::Affine>; N];

fn batch_normalize(points: &[Self; N]) -> [NonIdentity<P::AffineRepr>; N] {
fn batch_normalize(points: &[Self; N]) -> [NonIdentity<P::Affine>; N] {
let points = Self::array_as_inner::<N>(points);
let affine_points = <P as BatchNormalize<_>>::batch_normalize(points);
affine_points.map(|point| NonIdentity { point })
Expand All @@ -162,11 +162,11 @@ where
#[cfg(feature = "alloc")]
impl<P> BatchNormalize<[Self]> for NonIdentity<P>
where
P: CurveGroup + BatchNormalize<[P], Output = Vec<P::AffineRepr>>,
P: CurveGroup + BatchNormalize<[P], Output = Vec<P::Affine>>,
{
type Output = Vec<NonIdentity<P::AffineRepr>>;
type Output = Vec<NonIdentity<P::Affine>>;

fn batch_normalize(points: &[Self]) -> Vec<NonIdentity<P::AffineRepr>> {
fn batch_normalize(points: &[Self]) -> Vec<NonIdentity<P::Affine>> {
let points = Self::slice_as_inner(points);
let affine_points = <P as BatchNormalize<_>>::batch_normalize(points);
affine_points
Expand Down
Loading