diff --git a/Cargo.lock b/Cargo.lock index e2107dcd..79924dea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -86,15 +86,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "der" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce93ba4502a73722aa4b955d97f4b1bd26f4f8da74315399ca58fb88fe2bdaae" -dependencies = [ - "typenum", -] - [[package]] name = "der" version = "0.3.0" @@ -102,6 +93,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7516ff8d4f25ddd138caba1b7836ceb3ddd07660213b50e83ae3165320257ba2" dependencies = [ "const-oid", + "typenum", ] [[package]] @@ -117,7 +109,7 @@ dependencies = [ name = "ecdsa" version = "0.11.0-pre.2" dependencies = [ - "der 0.2.10", + "der", "elliptic-curve", "hex-literal", "hmac", @@ -260,7 +252,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b813f58dc6e5d1820868a3c3df3a7ae7852aa2d3d18e98f0d6b20ddd01fe25d7" dependencies = [ "base64ct", - "der 0.3.0", + "der", "spki", "zeroize", ] @@ -377,7 +369,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9dae7e047abc519c96350e9484a96c6bf1492348af912fd3446dd2dc323f6268" dependencies = [ - "der 0.3.0", + "der", ] [[package]] diff --git a/ecdsa/Cargo.toml b/ecdsa/Cargo.toml index 5bbc2e2f..d215c358 100644 --- a/ecdsa/Cargo.toml +++ b/ecdsa/Cargo.toml @@ -14,7 +14,7 @@ categories = ["cryptography", "no-std"] keywords = ["crypto", "ecc", "nist", "secp256k1", "signature"] [dependencies] -der = { version = "0.2", optional = true, features = ["big-uint"] } +der = { version = "0.3", optional = true, features = ["big-uint"] } elliptic-curve = { version = "0.9", default-features = false } hmac = { version = "0.10", optional = true, default-features = false } signature = { version = ">= 1.3.0, < 1.4.0", default-features = false, features = ["rand-preview"] } diff --git a/ecdsa/src/der.rs b/ecdsa/src/der.rs index 4e7c9647..1999c24c 100644 --- a/ecdsa/src/der.rs +++ b/ecdsa/src/der.rs @@ -1,9 +1,7 @@ //! Support for ECDSA signatures encoded as ASN.1 DER. -pub use der::BigUIntSize; - use crate::{ - generic_array::{ArrayLength, GenericArray}, + generic_array::{typenum::NonZero, ArrayLength, GenericArray}, Error, }; use core::{ @@ -52,7 +50,7 @@ const ENCODING_ERR_MSG: &str = "DER encoding error"; pub struct Signature where C: Curve, - C::FieldSize: Add + ArrayLength + BigUIntSize, + C::FieldSize: Add + ArrayLength + NonZero, MaxSize: ArrayLength, ::Output: Add + ArrayLength, { @@ -69,7 +67,7 @@ where impl signature::Signature for Signature where C: Curve, - C::FieldSize: Add + ArrayLength + BigUIntSize, + C::FieldSize: Add + ArrayLength + NonZero, MaxSize: ArrayLength, ::Output: Add + ArrayLength, { @@ -83,7 +81,7 @@ where impl Signature where C: Curve, - C::FieldSize: Add + ArrayLength + BigUIntSize, + C::FieldSize: Add + ArrayLength + NonZero, MaxSize: ArrayLength, ::Output: Add + ArrayLength, { @@ -111,7 +109,8 @@ where let mut bytes = SignatureBytes::::default(); let mut encoder = der::Encoder::new(&mut bytes); - encoder.sequence(&[&r, &s]).expect(ENCODING_ERR_MSG); + encoder.message(&[&r, &s]).expect(ENCODING_ERR_MSG); + encoder .finish() .expect(ENCODING_ERR_MSG) @@ -133,7 +132,7 @@ where impl AsRef<[u8]> for Signature where C: Curve, - C::FieldSize: Add + ArrayLength + BigUIntSize, + C::FieldSize: Add + ArrayLength + NonZero, MaxSize: ArrayLength, ::Output: Add + ArrayLength, { @@ -145,7 +144,7 @@ where impl fmt::Debug for Signature where C: Curve, - C::FieldSize: Add + ArrayLength + BigUIntSize, + C::FieldSize: Add + ArrayLength + NonZero, MaxSize: ArrayLength, ::Output: Add + ArrayLength, { @@ -160,7 +159,7 @@ where impl TryFrom<&[u8]> for Signature where C: Curve, - C::FieldSize: Add + ArrayLength + BigUIntSize, + C::FieldSize: Add + ArrayLength + NonZero, MaxSize: ArrayLength, ::Output: Add + ArrayLength, { @@ -208,7 +207,7 @@ fn find_scalar_range(outer: &[u8], inner: &[u8]) -> Result, Error> impl signature::PrehashSignature for Signature where C: Curve + crate::hazmat::DigestPrimitive, - C::FieldSize: Add + ArrayLength + BigUIntSize, + C::FieldSize: Add + ArrayLength + NonZero, MaxSize: ArrayLength, ::Output: Add + ArrayLength, { diff --git a/ecdsa/src/lib.rs b/ecdsa/src/lib.rs index 04dd9173..413e89d1 100644 --- a/ecdsa/src/lib.rs +++ b/ecdsa/src/lib.rs @@ -110,6 +110,9 @@ use generic_array::{sequence::Concat, typenum::Unsigned, ArrayLength, GenericArr #[cfg(feature = "arithmetic")] use elliptic_curve::{ff::PrimeField, NonZeroScalar, ProjectiveArithmetic, Scalar}; +#[cfg(feature = "der")] +use generic_array::typenum::NonZero; + /// Size of a fixed sized signature for the given elliptic curve. pub type SignatureSize = <::FieldSize as Add>::Output; @@ -159,7 +162,7 @@ where #[cfg_attr(docsrs, doc(cfg(feature = "der")))] pub fn from_der(bytes: &[u8]) -> Result where - C::FieldSize: Add + ArrayLength + der::BigUIntSize, + C::FieldSize: Add + ArrayLength + NonZero, der::MaxSize: ArrayLength, ::Output: Add + ArrayLength, { @@ -171,7 +174,7 @@ where #[cfg_attr(docsrs, doc(cfg(feature = "der")))] pub fn to_der(&self) -> der::Signature where - C::FieldSize: Add + ArrayLength + der::BigUIntSize, + C::FieldSize: Add + ArrayLength + NonZero, der::MaxSize: ArrayLength, ::Output: Add + ArrayLength, { @@ -293,7 +296,7 @@ where impl TryFrom> for Signature where C: Curve + CheckSignatureBytes, - C::FieldSize: Add + ArrayLength + der::BigUIntSize, + C::FieldSize: Add + ArrayLength + NonZero, der::MaxSize: ArrayLength, ::Output: Add + ArrayLength, {