diff --git a/elliptic-curve/src/arithmetic.rs b/elliptic-curve/src/arithmetic.rs index b69c1a408..fa445f1bc 100644 --- a/elliptic-curve/src/arithmetic.rs +++ b/elliptic-curve/src/arithmetic.rs @@ -1,6 +1,8 @@ //! Elliptic curve arithmetic traits. -use crate::{AffineXCoordinate, Curve, FieldBytes, IsHigh, PrimeCurve, ScalarCore}; +use crate::{ + ops::LinearCombination, AffineXCoordinate, Curve, FieldBytes, IsHigh, PrimeCurve, ScalarCore, +}; use core::fmt::Debug; use subtle::{ConditionallySelectable, ConstantTimeEq}; use zeroize::DefaultIsZeroes; @@ -54,6 +56,7 @@ pub trait ProjectiveArithmetic: Curve + AffineArithmetic { + DefaultIsZeroes + From + Into + + LinearCombination + group::Curve + group::Group; } diff --git a/elliptic-curve/src/dev.rs b/elliptic-curve/src/dev.rs index 1da6c6316..5b9ca3781 100644 --- a/elliptic-curve/src/dev.rs +++ b/elliptic-curve/src/dev.rs @@ -6,7 +6,7 @@ use crate::{ bigint::{Limb, U256}, error::{Error, Result}, - ops::Reduce, + ops::{LinearCombination, Reduce}, pkcs8, rand_core::RngCore, sec1::{FromEncodedPoint, ToEncodedPoint}, @@ -541,6 +541,8 @@ impl group::Curve for ProjectivePoint { } } +impl LinearCombination for ProjectivePoint {} + impl Add for ProjectivePoint { type Output = ProjectivePoint; diff --git a/elliptic-curve/src/ops.rs b/elliptic-curve/src/ops.rs index b49e1b335..b5ab2dd8f 100644 --- a/elliptic-curve/src/ops.rs +++ b/elliptic-curve/src/ops.rs @@ -6,7 +6,7 @@ use crypto_bigint::{ArrayEncoding, ByteArray, Integer}; use subtle::CtOption; #[cfg(feature = "arithmetic")] -use crate::ProjectiveArithmetic; +use group::Group; /// Perform an inversion on a field element (i.e. base field element or scalar) pub trait Invert { @@ -34,14 +34,9 @@ impl Invert for F { // TODO(tarcieri): replace this with a trait from the `group` crate? (see zkcrypto/group#25) #[cfg(feature = "arithmetic")] #[cfg_attr(docsrs, doc(cfg(feature = "arithmetic")))] -pub trait LinearCombination: ProjectiveArithmetic { +pub trait LinearCombination: Group { /// Calculates `x * k + y * l`. - fn lincomb( - x: &Self::ProjectivePoint, - k: &Self::Scalar, - y: &Self::ProjectivePoint, - l: &Self::Scalar, - ) -> Self::ProjectivePoint { + fn lincomb(x: &Self, k: &Self::Scalar, y: &Self, l: &Self::Scalar) -> Self { (*x * k) + (*y * l) } }