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

ecdsa: use LinearCombination trait #417

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
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ecdsa/Cargo.toml
Expand Up @@ -15,7 +15,7 @@ edition = "2021"
rust-version = "1.56"

[dependencies]
elliptic-curve = { version = "0.11.1", default-features = false, features = ["sec1"] }
elliptic-curve = { version = "0.11.4", default-features = false, features = ["sec1"] }
signature = { version = ">= 1.3.1, <1.5", default-features = false, features = ["rand-preview"] }

# optional dependencies
Expand Down
16 changes: 10 additions & 6 deletions ecdsa/src/hazmat.rs
Expand Up @@ -16,7 +16,7 @@ use {
core::borrow::Borrow,
elliptic_curve::{
group::Curve as _,
ops::{Invert, Reduce},
ops::{Invert, LinearCombination, Reduce},
AffineArithmetic, AffineXCoordinate, Field, FieldBytes, Group, ProjectiveArithmetic,
Scalar, ScalarArithmetic,
},
Expand Down Expand Up @@ -112,7 +112,7 @@ where
#[cfg_attr(docsrs, doc(cfg(feature = "arithmetic")))]
pub trait VerifyPrimitive<C>: AffineXCoordinate<C> + Copy + Sized
where
C: PrimeCurve + AffineArithmetic<AffinePoint = Self> + ProjectiveArithmetic,
C: PrimeCurve + AffineArithmetic<AffinePoint = Self> + LinearCombination + ProjectiveArithmetic,
Scalar<C>: Reduce<C::UInt>,
SignatureSize<C>: ArrayLength<u8>,
{
Expand All @@ -127,10 +127,14 @@ where
let s_inv = Option::<Scalar<C>>::from(s.invert()).ok_or_else(Error::new)?;
let u1 = z * s_inv;
let u2 = *r * s_inv;

let x = ((C::ProjectivePoint::generator() * u1) + (C::ProjectivePoint::from(*self) * u2))
.to_affine()
.x();
let x = C::lincomb(
&C::ProjectivePoint::generator(),
&u1,
&C::ProjectivePoint::from(*self),
&u2,
)
.to_affine()
.x();

if Scalar::<C>::from_be_bytes_reduced(x) == *r {
Ok(())
Expand Down
6 changes: 3 additions & 3 deletions ecdsa/src/verify.rs
Expand Up @@ -7,7 +7,7 @@ use crate::{
use core::{cmp::Ordering, fmt::Debug};
use elliptic_curve::{
generic_array::ArrayLength,
ops::Reduce,
ops::{LinearCombination, Reduce},
sec1::{self, EncodedPoint, FromEncodedPoint, ToEncodedPoint},
AffinePoint, FieldSize, PointCompression, PrimeCurve, ProjectiveArithmetic, PublicKey, Scalar,
};
Expand Down Expand Up @@ -79,7 +79,7 @@ impl<C> Copy for VerifyingKey<C> where C: PrimeCurve + ProjectiveArithmetic {}

impl<C, D> DigestVerifier<D, Signature<C>> for VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
C: PrimeCurve + ProjectiveArithmetic + LinearCombination,
D: Digest<OutputSize = FieldSize<C>>,
AffinePoint<C>: VerifyPrimitive<C>,
Scalar<C>: Reduce<C::UInt>,
Expand All @@ -93,7 +93,7 @@ where

impl<C> Verifier<Signature<C>> for VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive + LinearCombination,
C::Digest: Digest<OutputSize = FieldSize<C>>,
AffinePoint<C>: VerifyPrimitive<C>,
Scalar<C>: Reduce<C::UInt>,
Expand Down