From c5206d43db1c2aee725f338cd0a7a26278263495 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Wed, 17 Jan 2024 23:14:01 +0000 Subject: [PATCH] ecdsa: use `EcdsaCurve` in bounds (#792) Replaces previous `PrimeCurve` bounds with the new `EcdsaCurve` trait (which has a supertrait bound on `PrimeCurve`). --- ecdsa/src/der.rs | 38 ++++++++++----------- ecdsa/src/dev.rs | 7 ++++ ecdsa/src/hazmat.rs | 18 +++++----- ecdsa/src/lib.rs | 49 +++++++++++++------------- ecdsa/src/normalized.rs | 11 ------ ecdsa/src/recovery.rs | 20 +++++------ ecdsa/src/signing.rs | 76 ++++++++++++++++++++--------------------- ecdsa/src/verifying.rs | 66 +++++++++++++++++------------------ ed25519/tests/serde.rs | 1 - 9 files changed, 140 insertions(+), 146 deletions(-) delete mode 100644 ecdsa/src/normalized.rs diff --git a/ecdsa/src/der.rs b/ecdsa/src/der.rs index 963da4ea..085accc4 100644 --- a/ecdsa/src/der.rs +++ b/ecdsa/src/der.rs @@ -3,7 +3,7 @@ //! //! [RFC5912 Section 6]: https://www.rfc-editor.org/rfc/rfc5912#section-6 -use crate::{Error, Result}; +use crate::{EcdsaCurve, Error, Result}; use core::{ fmt::{self, Debug}, ops::{Add, Range}, @@ -12,7 +12,7 @@ use der::{asn1::UintRef, Decode, Encode, FixedTag, Length, Reader, Tag, Writer}; use elliptic_curve::{ array::{typenum::Unsigned, Array, ArraySize}, consts::U9, - FieldBytesSize, PrimeCurve, + FieldBytesSize, }; #[cfg(feature = "alloc")] @@ -59,7 +59,7 @@ type SignatureBytes = Array>; /// [RFC5912 Section 6]: https://www.rfc-editor.org/rfc/rfc5912#section-6 pub struct Signature where - C: PrimeCurve, + C: EcdsaCurve, MaxSize: ArraySize, as Add>::Output: Add + ArraySize, { @@ -76,7 +76,7 @@ where #[allow(clippy::len_without_is_empty)] impl Signature where - C: PrimeCurve, + C: EcdsaCurve, MaxSize: ArraySize, as Add>::Output: Add + ArraySize, { @@ -156,7 +156,7 @@ where impl AsRef<[u8]> for Signature where - C: PrimeCurve, + C: EcdsaCurve, MaxSize: ArraySize, as Add>::Output: Add + ArraySize, { @@ -167,7 +167,7 @@ where impl Clone for Signature where - C: PrimeCurve, + C: EcdsaCurve, MaxSize: ArraySize, as Add>::Output: Add + ArraySize, { @@ -182,7 +182,7 @@ where impl Debug for Signature where - C: PrimeCurve, + C: EcdsaCurve, MaxSize: ArraySize, as Add>::Output: Add + ArraySize, { @@ -199,7 +199,7 @@ where impl<'a, C> Decode<'a> for Signature where - C: PrimeCurve, + C: EcdsaCurve, MaxSize: ArraySize, as Add>::Output: Add + ArraySize, { @@ -220,7 +220,7 @@ where impl Encode for Signature where - C: PrimeCurve, + C: EcdsaCurve, MaxSize: ArraySize, as Add>::Output: Add + ArraySize, { @@ -235,7 +235,7 @@ where impl FixedTag for Signature where - C: PrimeCurve, + C: EcdsaCurve, MaxSize: ArraySize, as Add>::Output: Add + ArraySize, { @@ -244,7 +244,7 @@ where impl From> for Signature where - C: PrimeCurve, + C: EcdsaCurve, MaxSize: ArraySize, as Add>::Output: Add + ArraySize, { @@ -255,7 +255,7 @@ where impl TryFrom<&[u8]> for Signature where - C: PrimeCurve, + C: EcdsaCurve, MaxSize: ArraySize, as Add>::Output: Add + ArraySize, { @@ -268,7 +268,7 @@ where impl TryFrom> for crate::Signature where - C: PrimeCurve, + C: EcdsaCurve, MaxSize: ArraySize, as Add>::Output: Add + ArraySize, { @@ -287,7 +287,7 @@ where #[cfg(feature = "alloc")] impl From> for Box<[u8]> where - C: PrimeCurve, + C: EcdsaCurve, MaxSize: ArraySize, as Add>::Output: Add + ArraySize, { @@ -299,7 +299,7 @@ where #[cfg(feature = "alloc")] impl SignatureEncoding for Signature where - C: PrimeCurve, + C: EcdsaCurve, MaxSize: ArraySize, as Add>::Output: Add + ArraySize, { @@ -313,7 +313,7 @@ where #[cfg(feature = "alloc")] impl SignatureBitStringEncoding for Signature where - C: PrimeCurve, + C: EcdsaCurve, MaxSize: ArraySize, as Add>::Output: Add + ArraySize, { @@ -325,7 +325,7 @@ where #[cfg(feature = "serde")] impl Serialize for Signature where - C: PrimeCurve, + C: EcdsaCurve, MaxSize: ArraySize, as Add>::Output: Add + ArraySize, { @@ -340,7 +340,7 @@ where #[cfg(feature = "serde")] impl<'de, C> Deserialize<'de> for Signature where - C: PrimeCurve, + C: EcdsaCurve, MaxSize: ArraySize, as Add>::Output: Add + ArraySize, { @@ -383,7 +383,7 @@ fn find_scalar_range(outer: &[u8], inner: &[u8]) -> Result> { #[cfg(all(feature = "digest", feature = "hazmat"))] impl signature::PrehashSignature for Signature where - C: PrimeCurve + crate::hazmat::DigestPrimitive, + C: EcdsaCurve + crate::hazmat::DigestPrimitive, MaxSize: ArraySize, as Add>::Output: Add + ArraySize, { diff --git a/ecdsa/src/dev.rs b/ecdsa/src/dev.rs index 948c5ea4..00feec26 100644 --- a/ecdsa/src/dev.rs +++ b/ecdsa/src/dev.rs @@ -3,6 +3,13 @@ // TODO(tarcieri): implement full set of tests from ECDSA2VS // +use crate::EcdsaCurve; +use elliptic_curve::dev::MockCurve; + +impl EcdsaCurve for MockCurve { + const NORMALIZE_S: bool = false; +} + /// ECDSA test vector pub struct TestVector { /// Private scalar diff --git a/ecdsa/src/hazmat.rs b/ecdsa/src/hazmat.rs index 013dde9a..d6e6a0c2 100644 --- a/ecdsa/src/hazmat.rs +++ b/ecdsa/src/hazmat.rs @@ -10,9 +10,9 @@ //! Failure to use them correctly can lead to catastrophic failures including //! FULL PRIVATE KEY RECOVERY! -use crate::{Error, Result}; +use crate::{EcdsaCurve, Error, Result}; use core::cmp; -use elliptic_curve::{array::typenum::Unsigned, FieldBytes, PrimeCurve}; +use elliptic_curve::{array::typenum::Unsigned, FieldBytes}; #[cfg(feature = "arithmetic")] use { @@ -56,7 +56,7 @@ pub trait SignPrimitive: + Reduce> + Sized where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, SignatureSize: ArraySize, { /// Try to sign the prehashed message. @@ -128,7 +128,7 @@ where #[cfg(feature = "arithmetic")] pub trait VerifyPrimitive: AffineCoordinates> + Copy + Sized where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, SignatureSize: ArraySize, { /// Verify the prehashed message against the provided ECDSA signature. @@ -163,7 +163,7 @@ where /// /// [1]: https://github.com/RustCrypto/traits/tree/master/signature/derive #[cfg(feature = "digest")] -pub trait DigestPrimitive: PrimeCurve { +pub trait DigestPrimitive: EcdsaCurve { /// Preferred digest to use when computing ECDSA signatures for this /// elliptic curve. This is typically a member of the SHA-2 family. type Digest: BlockSizeUser + Digest + FixedOutput + FixedOutputReset; @@ -187,7 +187,7 @@ where /// /// [RFC6979 § 2.3.2]: https://datatracker.ietf.org/doc/html/rfc6979#section-2.3.2 /// [SEC1]: https://www.secg.org/sec1-v2.pdf -pub fn bits2field(bits: &[u8]) -> Result> { +pub fn bits2field(bits: &[u8]) -> Result> { // Minimum allowed bits size is half the field size if bits.len() < C::FieldBytesSize::USIZE / 2 { return Err(Error::new()); @@ -232,7 +232,7 @@ pub fn sign_prehashed( z: &FieldBytes, ) -> Result<(Signature, RecoveryId)> where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, K: AsRef> + Invert>>, SignatureSize: ArraySize, { @@ -278,7 +278,7 @@ pub fn verify_prehashed( sig: &Signature, ) -> Result<()> where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, SignatureSize: ArraySize, { let z = Scalar::::reduce_bytes(z); @@ -297,7 +297,7 @@ where } } -#[cfg(test)] +#[cfg(all(test, feature = "dev"))] mod tests { use super::bits2field; use elliptic_curve::dev::MockCurve; diff --git a/ecdsa/src/lib.rs b/ecdsa/src/lib.rs index 5c216d96..ef97e618 100644 --- a/ecdsa/src/lib.rs +++ b/ecdsa/src/lib.rs @@ -57,7 +57,6 @@ #[cfg(feature = "alloc")] extern crate alloc; -mod normalized; mod recovery; #[cfg(feature = "der")] @@ -71,7 +70,7 @@ mod signing; #[cfg(feature = "verifying")] mod verifying; -pub use crate::{normalized::NormalizedSignature, recovery::RecoveryId}; +pub use crate::recovery::RecoveryId; // Re-export the `elliptic-curve` crate (and select types) pub use elliptic_curve::{self, sec1::EncodedPoint, PrimeCurve}; @@ -205,14 +204,14 @@ pub type SignatureBytes = Array>; /// The serialization uses a hexadecimal encoding when used with /// "human readable" text formats, and a binary encoding otherwise. #[derive(Clone, Eq, PartialEq)] -pub struct Signature { +pub struct Signature { r: ScalarPrimitive, s: ScalarPrimitive, } impl Signature where - C: PrimeCurve, + C: EcdsaCurve, SignatureSize: ArraySize, { /// Parse a signature from fixed-width bytes, i.e. 2 * the size of @@ -301,7 +300,7 @@ where #[cfg(feature = "arithmetic")] impl Signature where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, SignatureSize: ArraySize, { /// Get the `r` component of this signature @@ -333,7 +332,7 @@ where impl Copy for Signature where - C: PrimeCurve, + C: EcdsaCurve, SignatureSize: ArraySize, as ArraySize>::ArrayType: Copy, { @@ -341,7 +340,7 @@ where impl From> for SignatureBytes where - C: PrimeCurve, + C: EcdsaCurve, SignatureSize: ArraySize, { fn from(signature: Signature) -> SignatureBytes { @@ -351,7 +350,7 @@ where impl SignatureEncoding for Signature where - C: PrimeCurve, + C: EcdsaCurve, SignatureSize: ArraySize, { type Repr = SignatureBytes; @@ -359,7 +358,7 @@ where impl TryFrom<&[u8]> for Signature where - C: PrimeCurve, + C: EcdsaCurve, SignatureSize: ArraySize, { type Error = Error; @@ -371,7 +370,7 @@ where impl fmt::Debug for Signature where - C: PrimeCurve, + C: EcdsaCurve, SignatureSize: ArraySize, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -387,7 +386,7 @@ where impl fmt::Display for Signature where - C: PrimeCurve, + C: EcdsaCurve, SignatureSize: ArraySize, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -397,7 +396,7 @@ where impl fmt::LowerHex for Signature where - C: PrimeCurve, + C: EcdsaCurve, SignatureSize: ArraySize, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -410,7 +409,7 @@ where impl fmt::UpperHex for Signature where - C: PrimeCurve, + C: EcdsaCurve, SignatureSize: ArraySize, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -424,7 +423,7 @@ where #[cfg(feature = "arithmetic")] impl str::FromStr for Signature where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, SignatureSize: ArraySize, { type Err = Error; @@ -479,7 +478,7 @@ where #[cfg(feature = "pkcs8")] impl AssociatedAlgorithmIdentifier for Signature where - C: PrimeCurve, + C: EcdsaCurve, Self: AssociatedOid, { type Params = AnyRef<'static>; @@ -493,7 +492,7 @@ where #[cfg(feature = "serde")] impl Serialize for Signature where - C: PrimeCurve, + C: EcdsaCurve, SignatureSize: ArraySize, { fn serialize(&self, serializer: S) -> core::result::Result @@ -507,7 +506,7 @@ where #[cfg(feature = "serde")] impl<'de, C> Deserialize<'de> for Signature where - C: PrimeCurve, + C: EcdsaCurve, SignatureSize: ArraySize, { fn deserialize(deserializer: D) -> core::result::Result @@ -534,7 +533,7 @@ where /// [RFC5758 § 3.2]: https://www.rfc-editor.org/rfc/rfc5758#section-3.2 #[cfg(feature = "digest")] #[derive(Clone, Eq, PartialEq)] -pub struct SignatureWithOid { +pub struct SignatureWithOid { /// Inner signature type. signature: Signature, @@ -549,7 +548,7 @@ pub struct SignatureWithOid { #[cfg(feature = "digest")] impl SignatureWithOid where - C: PrimeCurve, + C: EcdsaCurve, { /// Create a new signature with an explicitly provided OID. /// @@ -660,7 +659,7 @@ where #[cfg(feature = "digest")] impl Copy for SignatureWithOid where - C: PrimeCurve, + C: EcdsaCurve, SignatureSize: ArraySize, as ArraySize>::ArrayType: Copy, { @@ -669,7 +668,7 @@ where #[cfg(feature = "digest")] impl From> for Signature where - C: PrimeCurve, + C: EcdsaCurve, { fn from(sig: SignatureWithOid) -> Signature { sig.signature @@ -679,7 +678,7 @@ where #[cfg(feature = "digest")] impl From> for SignatureBytes where - C: PrimeCurve, + C: EcdsaCurve, SignatureSize: ArraySize, { fn from(signature: SignatureWithOid) -> SignatureBytes { @@ -690,7 +689,7 @@ where #[cfg(all(feature = "der", feature = "digest"))] impl From> for der::Signature where - C: PrimeCurve, + C: EcdsaCurve, der::MaxSize: ArraySize, as Add>::Output: Add + ArraySize, { @@ -702,7 +701,7 @@ where #[cfg(all(feature = "der", feature = "digest"))] impl From<&SignatureWithOid> for der::Signature where - C: PrimeCurve, + C: EcdsaCurve, der::MaxSize: ArraySize, as Add>::Output: Add + ArraySize, { @@ -748,7 +747,7 @@ where #[cfg(all(feature = "alloc", feature = "pkcs8"))] impl DynAssociatedAlgorithmIdentifier for SignatureWithOid where - C: PrimeCurve, + C: EcdsaCurve, { fn algorithm_identifier(&self) -> spki::Result { Ok(AlgorithmIdentifierOwned { diff --git a/ecdsa/src/normalized.rs b/ecdsa/src/normalized.rs deleted file mode 100644 index 6a66a4b7..00000000 --- a/ecdsa/src/normalized.rs +++ /dev/null @@ -1,11 +0,0 @@ -//! Support for ECDSA signatures with low-S normalization. - -use crate::Signature; -use elliptic_curve::PrimeCurve; - -/// ECDSA signature with low-S normalization applied. -#[derive(Clone, Eq, PartialEq)] -#[repr(transparent)] -pub struct NormalizedSignature { - inner: Signature, -} diff --git a/ecdsa/src/recovery.rs b/ecdsa/src/recovery.rs index 60175d1b..77f86ab7 100644 --- a/ecdsa/src/recovery.rs +++ b/ecdsa/src/recovery.rs @@ -26,9 +26,9 @@ use { use { crate::{ hazmat::{bits2field, DigestPrimitive}, - Signature, SignatureSize, + EcdsaCurve, Signature, SignatureSize, }, - elliptic_curve::{array::ArraySize, ops::Invert, CurveArithmetic, PrimeCurve, Scalar}, + elliptic_curve::{array::ArraySize, ops::Invert, CurveArithmetic, Scalar}, signature::digest::Digest, }; @@ -96,7 +96,7 @@ impl RecoveryId { signature: &Signature, ) -> Result where - C: DigestPrimitive + PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic + DigestPrimitive, AffinePoint: DecompressPoint + FromEncodedPoint + ToEncodedPoint + VerifyPrimitive, FieldBytesSize: sec1::ModulusSize, @@ -114,7 +114,7 @@ impl RecoveryId { signature: &Signature, ) -> Result where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, D: Digest, AffinePoint: DecompressPoint + FromEncodedPoint + ToEncodedPoint + VerifyPrimitive, @@ -133,7 +133,7 @@ impl RecoveryId { signature: &Signature, ) -> Result where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, AffinePoint: DecompressPoint + FromEncodedPoint + ToEncodedPoint + VerifyPrimitive, FieldBytesSize: sec1::ModulusSize, @@ -170,7 +170,7 @@ impl From for u8 { #[cfg(feature = "signing")] impl SigningKey where - C: PrimeCurve + CurveArithmetic + DigestPrimitive, + C: EcdsaCurve + CurveArithmetic + DigestPrimitive, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -202,7 +202,7 @@ where #[cfg(feature = "signing")] impl DigestSigner, RecoveryId)> for SigningKey where - C: PrimeCurve + CurveArithmetic + DigestPrimitive, + C: EcdsaCurve + CurveArithmetic + DigestPrimitive, D: Digest, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, @@ -215,7 +215,7 @@ where #[cfg(feature = "signing")] impl PrehashSigner<(Signature, RecoveryId)> for SigningKey where - C: PrimeCurve + CurveArithmetic + DigestPrimitive, + C: EcdsaCurve + CurveArithmetic + DigestPrimitive, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -227,7 +227,7 @@ where #[cfg(feature = "signing")] impl Signer<(Signature, RecoveryId)> for SigningKey where - C: PrimeCurve + CurveArithmetic + DigestPrimitive, + C: EcdsaCurve + CurveArithmetic + DigestPrimitive, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -239,7 +239,7 @@ where #[cfg(feature = "verifying")] impl VerifyingKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, AffinePoint: DecompressPoint + FromEncodedPoint + ToEncodedPoint + VerifyPrimitive, FieldBytesSize: sec1::ModulusSize, diff --git a/ecdsa/src/signing.rs b/ecdsa/src/signing.rs index 6d5d7f61..373dee36 100644 --- a/ecdsa/src/signing.rs +++ b/ecdsa/src/signing.rs @@ -3,7 +3,7 @@ use crate::{ ecdsa_oid_for_digest, hazmat::{bits2field, DigestPrimitive, SignPrimitive}, - Error, Result, Signature, SignatureSize, SignatureWithOid, + EcdsaCurve, Error, Result, Signature, SignatureSize, SignatureWithOid, }; use core::fmt::{self, Debug}; use digest::{const_oid::AssociatedOid, Digest, FixedOutput}; @@ -13,7 +13,7 @@ use elliptic_curve::{ ops::Invert, subtle::{Choice, ConstantTimeEq, CtOption}, zeroize::{Zeroize, ZeroizeOnDrop}, - CurveArithmetic, FieldBytes, NonZeroScalar, PrimeCurve, Scalar, SecretKey, + CurveArithmetic, FieldBytes, NonZeroScalar, Scalar, SecretKey, }; use signature::{ hazmat::{PrehashSigner, RandomizedPrehashSigner}, @@ -65,7 +65,7 @@ use elliptic_curve::pkcs8::{EncodePrivateKey, SecretDocument}; #[derive(Clone)] pub struct SigningKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -79,7 +79,7 @@ where impl SigningKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -135,7 +135,7 @@ where /// [RFC6979 § 3.2]: https://tools.ietf.org/html/rfc6979#section-3 impl DigestSigner> for SigningKey where - C: PrimeCurve + CurveArithmetic + DigestPrimitive, + C: EcdsaCurve + CurveArithmetic + DigestPrimitive, D: Digest + FixedOutput, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, @@ -151,7 +151,7 @@ where /// [RFC6979 § 3.2]: https://tools.ietf.org/html/rfc6979#section-3 impl PrehashSigner> for SigningKey where - C: PrimeCurve + CurveArithmetic + DigestPrimitive, + C: EcdsaCurve + CurveArithmetic + DigestPrimitive, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -170,7 +170,7 @@ where /// [RFC6979 § 3.2]: https://tools.ietf.org/html/rfc6979#section-3 impl Signer> for SigningKey where - C: PrimeCurve + CurveArithmetic + DigestPrimitive, + C: EcdsaCurve + CurveArithmetic + DigestPrimitive, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -181,7 +181,7 @@ where impl RandomizedDigestSigner> for SigningKey where - C: PrimeCurve + CurveArithmetic + DigestPrimitive, + C: EcdsaCurve + CurveArithmetic + DigestPrimitive, D: Digest + FixedOutput, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, @@ -197,7 +197,7 @@ where impl RandomizedPrehashSigner> for SigningKey where - C: PrimeCurve + CurveArithmetic + DigestPrimitive, + C: EcdsaCurve + CurveArithmetic + DigestPrimitive, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -219,7 +219,7 @@ where impl RandomizedSigner> for SigningKey where Self: RandomizedDigestSigner>, - C: PrimeCurve + CurveArithmetic + DigestPrimitive, + C: EcdsaCurve + CurveArithmetic + DigestPrimitive, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -230,7 +230,7 @@ where impl DigestSigner> for SigningKey where - C: PrimeCurve + CurveArithmetic + DigestPrimitive, + C: EcdsaCurve + CurveArithmetic + DigestPrimitive, D: AssociatedOid + Digest + FixedOutput, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, @@ -244,7 +244,7 @@ where impl Signer> for SigningKey where - C: PrimeCurve + CurveArithmetic + DigestPrimitive, + C: EcdsaCurve + CurveArithmetic + DigestPrimitive, C::Digest: AssociatedOid, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, @@ -257,7 +257,7 @@ where #[cfg(feature = "der")] impl PrehashSigner> for SigningKey where - C: PrimeCurve + CurveArithmetic + DigestPrimitive, + C: EcdsaCurve + CurveArithmetic + DigestPrimitive, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, der::MaxSize: ArraySize, @@ -271,7 +271,7 @@ where #[cfg(feature = "der")] impl Signer> for SigningKey where - C: PrimeCurve + CurveArithmetic + DigestPrimitive, + C: EcdsaCurve + CurveArithmetic + DigestPrimitive, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, der::MaxSize: ArraySize, @@ -285,7 +285,7 @@ where #[cfg(feature = "der")] impl RandomizedDigestSigner> for SigningKey where - C: PrimeCurve + CurveArithmetic + DigestPrimitive, + C: EcdsaCurve + CurveArithmetic + DigestPrimitive, D: Digest + FixedOutput, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, @@ -305,7 +305,7 @@ where #[cfg(feature = "der")] impl RandomizedPrehashSigner> for SigningKey where - C: PrimeCurve + CurveArithmetic + DigestPrimitive, + C: EcdsaCurve + CurveArithmetic + DigestPrimitive, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, der::MaxSize: ArraySize, @@ -324,7 +324,7 @@ where #[cfg(feature = "der")] impl RandomizedSigner> for SigningKey where - C: PrimeCurve + CurveArithmetic + DigestPrimitive, + C: EcdsaCurve + CurveArithmetic + DigestPrimitive, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, der::MaxSize: ArraySize, @@ -346,7 +346,7 @@ where #[cfg(feature = "verifying")] impl AsRef> for SigningKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -357,7 +357,7 @@ where impl ConstantTimeEq for SigningKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -368,7 +368,7 @@ where impl Debug for SigningKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -379,7 +379,7 @@ where impl Drop for SigningKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -391,14 +391,14 @@ where /// Constant-time comparison impl Eq for SigningKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { } impl PartialEq for SigningKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -409,7 +409,7 @@ where impl From> for SigningKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -427,7 +427,7 @@ where impl From> for SigningKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -438,7 +438,7 @@ where impl From<&SecretKey> for SigningKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -449,7 +449,7 @@ where impl From> for SecretKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -460,7 +460,7 @@ where impl From<&SigningKey> for SecretKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -471,7 +471,7 @@ where impl TryFrom<&[u8]> for SigningKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -484,7 +484,7 @@ where impl ZeroizeOnDrop for SigningKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -493,7 +493,7 @@ where #[cfg(feature = "verifying")] impl From> for VerifyingKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -505,7 +505,7 @@ where #[cfg(feature = "verifying")] impl From<&SigningKey> for VerifyingKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -517,7 +517,7 @@ where #[cfg(feature = "verifying")] impl KeypairRef for SigningKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -527,7 +527,7 @@ where #[cfg(feature = "pkcs8")] impl AssociatedAlgorithmIdentifier for SigningKey where - C: AssociatedOid + CurveArithmetic + PrimeCurve, + C: EcdsaCurve + AssociatedOid + CurveArithmetic, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, { @@ -540,7 +540,7 @@ where #[cfg(feature = "pkcs8")] impl SignatureAlgorithmIdentifier for SigningKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, Scalar: Invert>> + SignPrimitive, SignatureSize: ArraySize, Signature: AssociatedAlgorithmIdentifier>, @@ -554,7 +554,7 @@ where #[cfg(feature = "pkcs8")] impl TryFrom> for SigningKey where - C: PrimeCurve + AssociatedOid + CurveArithmetic, + C: EcdsaCurve + AssociatedOid + CurveArithmetic, AffinePoint: FromEncodedPoint + ToEncodedPoint, FieldBytesSize: sec1::ModulusSize, Scalar: Invert>> + SignPrimitive, @@ -570,7 +570,7 @@ where #[cfg(all(feature = "alloc", feature = "pkcs8"))] impl EncodePrivateKey for SigningKey where - C: AssociatedOid + PrimeCurve + CurveArithmetic, + C: EcdsaCurve + AssociatedOid + CurveArithmetic, AffinePoint: FromEncodedPoint + ToEncodedPoint, FieldBytesSize: sec1::ModulusSize, Scalar: Invert>> + SignPrimitive, @@ -584,7 +584,7 @@ where #[cfg(feature = "pem")] impl FromStr for SigningKey where - C: PrimeCurve + AssociatedOid + CurveArithmetic, + C: EcdsaCurve + AssociatedOid + CurveArithmetic, AffinePoint: FromEncodedPoint + ToEncodedPoint, FieldBytesSize: sec1::ModulusSize, Scalar: Invert>> + SignPrimitive, diff --git a/ecdsa/src/verifying.rs b/ecdsa/src/verifying.rs index 8c9520c9..d919f090 100644 --- a/ecdsa/src/verifying.rs +++ b/ecdsa/src/verifying.rs @@ -2,14 +2,14 @@ use crate::{ hazmat::{bits2field, DigestPrimitive, VerifyPrimitive}, - Error, Result, Signature, SignatureSize, + EcdsaCurve, Error, Result, Signature, SignatureSize, }; use core::{cmp::Ordering, fmt::Debug}; use elliptic_curve::{ array::ArraySize, point::PointCompression, sec1::{self, CompressedPoint, EncodedPoint, FromEncodedPoint, ToEncodedPoint}, - AffinePoint, CurveArithmetic, FieldBytesSize, PrimeCurve, PublicKey, + AffinePoint, CurveArithmetic, FieldBytesSize, PublicKey, }; use signature::{ digest::{Digest, FixedOutput}, @@ -77,14 +77,14 @@ use serdect::serde::{de, ser, Deserialize, Serialize}; #[derive(Clone, Debug)] pub struct VerifyingKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, { pub(crate) inner: PublicKey, } impl VerifyingKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, AffinePoint: FromEncodedPoint + ToEncodedPoint, FieldBytesSize: sec1::ModulusSize, { @@ -144,7 +144,7 @@ where impl DigestVerifier> for VerifyingKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, D: Digest + FixedOutput, AffinePoint: VerifyPrimitive, SignatureSize: ArraySize, @@ -156,7 +156,7 @@ where impl PrehashVerifier> for VerifyingKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, AffinePoint: VerifyPrimitive, SignatureSize: ArraySize, { @@ -168,7 +168,7 @@ where impl Verifier> for VerifyingKey where - C: PrimeCurve + CurveArithmetic + DigestPrimitive, + C: EcdsaCurve + CurveArithmetic + DigestPrimitive, AffinePoint: VerifyPrimitive, SignatureSize: ArraySize, { @@ -180,7 +180,7 @@ where #[cfg(feature = "sha2")] impl Verifier> for VerifyingKey where - C: PrimeCurve + CurveArithmetic + DigestPrimitive, + C: EcdsaCurve + CurveArithmetic + DigestPrimitive, AffinePoint: VerifyPrimitive, SignatureSize: ArraySize, { @@ -198,7 +198,7 @@ where #[cfg(feature = "der")] impl DigestVerifier> for VerifyingKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, D: Digest + FixedOutput, AffinePoint: VerifyPrimitive, SignatureSize: ArraySize, @@ -214,7 +214,7 @@ where #[cfg(feature = "der")] impl PrehashVerifier> for VerifyingKey where - C: PrimeCurve + CurveArithmetic + DigestPrimitive, + C: EcdsaCurve + CurveArithmetic + DigestPrimitive, AffinePoint: VerifyPrimitive, SignatureSize: ArraySize, der::MaxSize: ArraySize, @@ -229,7 +229,7 @@ where #[cfg(feature = "der")] impl Verifier> for VerifyingKey where - C: PrimeCurve + CurveArithmetic + DigestPrimitive, + C: EcdsaCurve + CurveArithmetic + DigestPrimitive, AffinePoint: VerifyPrimitive, SignatureSize: ArraySize, der::MaxSize: ArraySize, @@ -247,7 +247,7 @@ where impl AsRef> for VerifyingKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, AffinePoint: FromEncodedPoint + ToEncodedPoint, FieldBytesSize: sec1::ModulusSize, { @@ -256,11 +256,11 @@ where } } -impl Copy for VerifyingKey where C: PrimeCurve + CurveArithmetic {} +impl Copy for VerifyingKey where C: EcdsaCurve + CurveArithmetic {} impl From> for CompressedPoint where - C: PrimeCurve + CurveArithmetic + PointCompression, + C: EcdsaCurve + CurveArithmetic + PointCompression, AffinePoint: FromEncodedPoint + ToEncodedPoint, FieldBytesSize: sec1::ModulusSize, { @@ -271,7 +271,7 @@ where impl From<&VerifyingKey> for CompressedPoint where - C: PrimeCurve + CurveArithmetic + PointCompression, + C: EcdsaCurve + CurveArithmetic + PointCompression, AffinePoint: FromEncodedPoint + ToEncodedPoint, FieldBytesSize: sec1::ModulusSize, { @@ -282,7 +282,7 @@ where impl From> for EncodedPoint where - C: PrimeCurve + CurveArithmetic + PointCompression, + C: EcdsaCurve + CurveArithmetic + PointCompression, AffinePoint: FromEncodedPoint + ToEncodedPoint, FieldBytesSize: sec1::ModulusSize, { @@ -293,7 +293,7 @@ where impl From<&VerifyingKey> for EncodedPoint where - C: PrimeCurve + CurveArithmetic + PointCompression, + C: EcdsaCurve + CurveArithmetic + PointCompression, AffinePoint: FromEncodedPoint + ToEncodedPoint, FieldBytesSize: sec1::ModulusSize, { @@ -302,11 +302,11 @@ where } } -impl Eq for VerifyingKey where C: PrimeCurve + CurveArithmetic {} +impl Eq for VerifyingKey where C: EcdsaCurve + CurveArithmetic {} impl PartialEq for VerifyingKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, { fn eq(&self, other: &Self) -> bool { self.inner.eq(&other.inner) @@ -315,7 +315,7 @@ where impl From> for VerifyingKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, { fn from(public_key: PublicKey) -> VerifyingKey { VerifyingKey { inner: public_key } @@ -324,7 +324,7 @@ where impl From<&PublicKey> for VerifyingKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, { fn from(public_key: &PublicKey) -> VerifyingKey { (*public_key).into() @@ -333,7 +333,7 @@ where impl From> for PublicKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, { fn from(verifying_key: VerifyingKey) -> PublicKey { verifying_key.inner @@ -342,7 +342,7 @@ where impl From<&VerifyingKey> for PublicKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, { fn from(verifying_key: &VerifyingKey) -> PublicKey { (*verifying_key).into() @@ -351,7 +351,7 @@ where impl PartialOrd for VerifyingKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, AffinePoint: FromEncodedPoint + ToEncodedPoint, FieldBytesSize: sec1::ModulusSize, { @@ -362,7 +362,7 @@ where impl Ord for VerifyingKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, AffinePoint: FromEncodedPoint + ToEncodedPoint, FieldBytesSize: sec1::ModulusSize, { @@ -373,7 +373,7 @@ where impl TryFrom<&[u8]> for VerifyingKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, AffinePoint: FromEncodedPoint + ToEncodedPoint, FieldBytesSize: sec1::ModulusSize, { @@ -387,7 +387,7 @@ where #[cfg(feature = "pkcs8")] impl AssociatedAlgorithmIdentifier for VerifyingKey where - C: AssociatedOid + CurveArithmetic + PrimeCurve, + C: EcdsaCurve + AssociatedOid + CurveArithmetic, AffinePoint: FromEncodedPoint + ToEncodedPoint, FieldBytesSize: sec1::ModulusSize, { @@ -400,7 +400,7 @@ where #[cfg(feature = "pkcs8")] impl SignatureAlgorithmIdentifier for VerifyingKey where - C: PrimeCurve + CurveArithmetic, + C: EcdsaCurve + CurveArithmetic, AffinePoint: FromEncodedPoint + ToEncodedPoint, FieldBytesSize: sec1::ModulusSize, Signature: AssociatedAlgorithmIdentifier>, @@ -414,7 +414,7 @@ where #[cfg(feature = "pkcs8")] impl TryFrom> for VerifyingKey where - C: PrimeCurve + AssociatedOid + CurveArithmetic + PointCompression, + C: EcdsaCurve + AssociatedOid + CurveArithmetic + PointCompression, AffinePoint: FromEncodedPoint + ToEncodedPoint, FieldBytesSize: sec1::ModulusSize, { @@ -428,7 +428,7 @@ where #[cfg(all(feature = "alloc", feature = "pkcs8"))] impl EncodePublicKey for VerifyingKey where - C: PrimeCurve + AssociatedOid + CurveArithmetic + PointCompression, + C: EcdsaCurve + AssociatedOid + CurveArithmetic + PointCompression, AffinePoint: FromEncodedPoint + ToEncodedPoint, FieldBytesSize: sec1::ModulusSize, { @@ -440,7 +440,7 @@ where #[cfg(feature = "pem")] impl FromStr for VerifyingKey where - C: PrimeCurve + AssociatedOid + CurveArithmetic + PointCompression, + C: EcdsaCurve + AssociatedOid + CurveArithmetic + PointCompression, AffinePoint: FromEncodedPoint + ToEncodedPoint, FieldBytesSize: sec1::ModulusSize, { @@ -454,7 +454,7 @@ where #[cfg(all(feature = "pem", feature = "serde"))] impl Serialize for VerifyingKey where - C: PrimeCurve + AssociatedOid + CurveArithmetic + PointCompression, + C: EcdsaCurve + AssociatedOid + CurveArithmetic + PointCompression, AffinePoint: FromEncodedPoint + ToEncodedPoint, FieldBytesSize: sec1::ModulusSize, { @@ -469,7 +469,7 @@ where #[cfg(all(feature = "pem", feature = "serde"))] impl<'de, C> Deserialize<'de> for VerifyingKey where - C: PrimeCurve + AssociatedOid + CurveArithmetic + PointCompression, + C: EcdsaCurve + AssociatedOid + CurveArithmetic + PointCompression, AffinePoint: FromEncodedPoint + ToEncodedPoint, FieldBytesSize: sec1::ModulusSize, { diff --git a/ed25519/tests/serde.rs b/ed25519/tests/serde.rs index cc836a78..5e8ff6f4 100644 --- a/ed25519/tests/serde.rs +++ b/ed25519/tests/serde.rs @@ -13,7 +13,6 @@ const EXAMPLE_SIGNATURE: SignatureBytes = hex!( #[test] fn test_serialize() { let signature = Signature::try_from(&EXAMPLE_SIGNATURE[..]).unwrap(); - dbg!(&signature); let encoded_signature: Vec = bincode::serialize(&signature).unwrap(); assert_eq!(&EXAMPLE_SIGNATURE[..], &encoded_signature[..]); }