Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elliptic-curve: revised LinearCombination trait #835

Merged
merged 1 commit into from Dec 4, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion 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;
Expand Down Expand Up @@ -54,6 +56,7 @@ pub trait ProjectiveArithmetic: Curve + AffineArithmetic {
+ DefaultIsZeroes
+ From<Self::AffinePoint>
+ Into<Self::AffinePoint>
+ LinearCombination
+ group::Curve<AffineRepr = Self::AffinePoint>
+ group::Group<Scalar = Self::Scalar>;
}
Expand Down
4 changes: 3 additions & 1 deletion elliptic-curve/src/dev.rs
Expand Up @@ -6,7 +6,7 @@
use crate::{
bigint::{Limb, U256},
error::{Error, Result},
ops::Reduce,
ops::{LinearCombination, Reduce},
pkcs8,
rand_core::RngCore,
sec1::{FromEncodedPoint, ToEncodedPoint},
Expand Down Expand Up @@ -541,6 +541,8 @@ impl group::Curve for ProjectivePoint {
}
}

impl LinearCombination for ProjectivePoint {}

impl Add<ProjectivePoint> for ProjectivePoint {
type Output = ProjectivePoint;

Expand Down
11 changes: 3 additions & 8 deletions elliptic-curve/src/ops.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -34,14 +34,9 @@ impl<F: ff::Field> 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)
}
}
Expand Down