From 6745bd08c9048243f83384bad91574c508ab75c4 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Sat, 5 Nov 2022 17:14:39 -0600 Subject: [PATCH] Bump `ecdsa` crate to v0.15.0-pre This (unpublished) prerelease of the `ecdsa` crate impl's the prospective `signature` v2 API from: RustCrypto/traits#1141 --- Cargo.lock | 16 +++---- Cargo.toml | 3 ++ bp256/Cargo.toml | 2 +- bp384/Cargo.toml | 2 +- k256/Cargo.toml | 6 +-- k256/src/arithmetic/scalar.rs | 10 ++-- k256/src/ecdsa/normalize.rs | 13 +++--- k256/src/ecdsa/recoverable.rs | 20 +++++--- k256/src/ecdsa/sign.rs | 20 +++----- k256/src/schnorr.rs | 67 +++++++++++++-------------- k256/src/schnorr/sign.rs | 18 +++---- k256/src/schnorr/verify.rs | 2 +- p256/Cargo.toml | 4 +- p256/src/arithmetic/scalar/blinded.rs | 10 ++-- p256/src/ecdsa.rs | 26 +++++------ p384/Cargo.toml | 4 +- p384/src/ecdsa.rs | 21 +++++---- 17 files changed, 118 insertions(+), 126 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index adbc5396..ea419ebe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -317,9 +317,8 @@ dependencies = [ [[package]] name = "ecdsa" -version = "0.14.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413301934810f597c1d19ca71c8710e99a3f1ba28a0d2ebc01551a2daeea3c5c" +version = "0.15.0-pre" +source = "git+https://github.com/RustCrypto/signatures.git#1578fe31b96cad80afdc1be47e5f0d088bd5bc2b" dependencies = [ "der", "elliptic-curve", @@ -514,7 +513,7 @@ dependencies = [ [[package]] name = "k256" -version = "0.11.6" +version = "0.12.0-pre" dependencies = [ "blobby", "cfg-if", @@ -871,9 +870,8 @@ dependencies = [ [[package]] name = "rfc6979" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88c86280f057430a52f4861551b092a01b419b8eacefc7c995eacb9dc132fe32" +version = "0.3.1" +source = "git+https://github.com/RustCrypto/signatures.git#1578fe31b96cad80afdc1be47e5f0d088bd5bc2b" dependencies = [ "crypto-bigint", "hmac", @@ -992,9 +990,9 @@ dependencies = [ [[package]] name = "signature" -version = "1.6.2" +version = "2.0.0-pre.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a622c5fc69cf2a070d3217981bded5071cdd1b1ac17ae906646debae83579b54" +checksum = "3b7d7471fcfa786b75b657061bd5bf1d51179b3aac54db33bba7e44f5a4b5b75" dependencies = [ "digest", "rand_core", diff --git a/Cargo.toml b/Cargo.toml index 88e5ae12..9f29e615 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,6 @@ members = [ [profile.dev] opt-level = 2 + +[patch.crates-io] +ecdsa = { git = "https://github.com/RustCrypto/signatures.git" } diff --git a/bp256/Cargo.toml b/bp256/Cargo.toml index aaff4e5e..90f491e5 100644 --- a/bp256/Cargo.toml +++ b/bp256/Cargo.toml @@ -16,7 +16,7 @@ rust-version = "1.57" elliptic-curve = { version = "0.12", default-features = false, features = ["hazmat", "sec1"] } # optional dependencies -ecdsa = { version = "0.14", optional = true, default-features = false, features = ["der"] } +ecdsa = { version = "=0.15.0-pre", optional = true, default-features = false, features = ["der"] } sha2 = { version = "0.10", optional = true, default-features = false } [features] diff --git a/bp384/Cargo.toml b/bp384/Cargo.toml index d3f14a58..536a4e9e 100644 --- a/bp384/Cargo.toml +++ b/bp384/Cargo.toml @@ -16,7 +16,7 @@ rust-version = "1.57" elliptic-curve = { version = "0.12", default-features = false, features = ["hazmat", "sec1"] } # optional dependencies -ecdsa = { version = "0.14", optional = true, default-features = false, features = ["der"] } +ecdsa = { version = "=0.15.0-pre", optional = true, default-features = false, features = ["der"] } sha2 = { version = "0.10", optional = true, default-features = false } [features] diff --git a/k256/Cargo.toml b/k256/Cargo.toml index 3ae0f669..dcca9bd7 100644 --- a/k256/Cargo.toml +++ b/k256/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "k256" -version = "0.11.6" +version = "0.12.0-pre" description = """ secp256k1 elliptic curve library written in pure Rust with support for ECDSA signing/verification (including Ethereum-style signatures with public-key @@ -22,7 +22,7 @@ cfg-if = "1.0" elliptic-curve = { version = "0.12.3", default-features = false, features = ["hazmat", "sec1"] } # optional dependencies -ecdsa-core = { version = "0.14.6", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { version = "=0.15.0-pre", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.3", optional = true } serdect = { version = "0.1", optional = true, default-features = false } sha2 = { version = "0.10", optional = true, default-features = false } @@ -31,7 +31,7 @@ sha3 = { version = "0.10", optional = true, default-features = false } [dev-dependencies] blobby = "0.3" criterion = "0.4" -ecdsa-core = { version = "0.14", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { version = "=0.15.0-pre", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.3" num-bigint = "0.4" num-traits = "0.2" diff --git a/k256/src/arithmetic/scalar.rs b/k256/src/arithmetic/scalar.rs index 9e671806..552c4610 100644 --- a/k256/src/arithmetic/scalar.rs +++ b/k256/src/arithmetic/scalar.rs @@ -13,7 +13,7 @@ use elliptic_curve::{ generic_array::arr, group::ff::{Field, PrimeField}, ops::{Reduce, ReduceNonZero}, - rand_core::{CryptoRng, RngCore}, + rand_core::{CryptoRngCore, RngCore}, subtle::{ Choice, ConditionallySelectable, ConstantTimeEq, ConstantTimeGreater, ConstantTimeLess, CtOption, @@ -184,7 +184,7 @@ impl Scalar { } /// Returns a (nearly) uniformly-random scalar, generated in constant time. - pub fn generate_biased(mut rng: impl CryptoRng + RngCore) -> Self { + pub fn generate_biased(rng: &mut impl CryptoRngCore) -> Self { // We reduce a random 512-bit value into a 256-bit field, which results in a // negligible bias from the uniform distribution, but the process is constant-time. let mut buf = [0u8; 64]; @@ -194,7 +194,7 @@ impl Scalar { /// Returns a uniformly-random scalar, generated using rejection sampling. // TODO(tarcieri): make this a `CryptoRng` when `ff` allows it - pub fn generate_vartime(mut rng: impl RngCore) -> Self { + pub fn generate_vartime(rng: &mut impl RngCore) -> Self { let mut bytes = FieldBytes::default(); // TODO: pre-generate several scalars to bring the probability of non-constant-timeness down? @@ -223,7 +223,7 @@ impl Scalar { } impl Field for Scalar { - fn random(rng: impl RngCore) -> Self { + fn random(mut rng: impl RngCore) -> Self { // Uses rejection sampling as the default random generation method, // which produces a uniformly random distribution of scalars. // @@ -233,7 +233,7 @@ impl Field for Scalar { // // With an unbiased RNG, the probability of failing to complete after 4 // iterations is vanishingly small. - Self::generate_vartime(rng) + Self::generate_vartime(&mut rng) } fn zero() -> Self { diff --git a/k256/src/ecdsa/normalize.rs b/k256/src/ecdsa/normalize.rs index 294b321e..af1a4963 100644 --- a/k256/src/ecdsa/normalize.rs +++ b/k256/src/ecdsa/normalize.rs @@ -5,13 +5,12 @@ #[cfg(all(test, feature = "ecdsa"))] mod tests { use crate::ecdsa::Signature; - use ecdsa_core::signature::Signature as _; // Test vectors generated using rust-secp256k1 #[test] #[rustfmt::skip] fn normalize_s_high() { - let sig_hi = Signature::from_bytes(&[ + let sig_hi = Signature::try_from([ 0x20, 0xc0, 0x1a, 0x91, 0x0e, 0xbb, 0x26, 0x10, 0xaf, 0x2d, 0x76, 0x3f, 0xa0, 0x9b, 0x3b, 0x30, 0x92, 0x3c, 0x8e, 0x40, 0x8b, 0x11, 0xdf, 0x2c, @@ -20,9 +19,9 @@ mod tests { 0x61, 0x7d, 0x13, 0x57, 0xf4, 0xd5, 0x56, 0x41, 0x09, 0x0a, 0x48, 0xf2, 0x01, 0xe9, 0xb9, 0x59, 0xc4, 0x8f, 0x6f, 0x6b, 0xec, 0x6f, 0x93, 0x8f, - ]).unwrap(); + ].as_slice()).unwrap(); - let sig_lo = Signature::from_bytes(&[ + let sig_lo = Signature::try_from([ 0x20, 0xc0, 0x1a, 0x91, 0x0e, 0xbb, 0x26, 0x10, 0xaf, 0x2d, 0x76, 0x3f, 0xa0, 0x9b, 0x3b, 0x30, 0x92, 0x3c, 0x8e, 0x40, 0x8b, 0x11, 0xdf, 0x2c, @@ -31,7 +30,7 @@ mod tests { 0x9e, 0x82, 0xec, 0xa8, 0x0b, 0x2a, 0xa9, 0xbd, 0xb1, 0xa4, 0x93, 0xf4, 0xad, 0x5e, 0xe6, 0xe1, 0xfb, 0x42, 0xef, 0x20, 0xe3, 0xc6, 0xad, 0xb2, - ]).unwrap(); + ].as_slice()).unwrap(); let sig_normalized = sig_hi.normalize_s().unwrap(); assert_eq!(sig_lo, sig_normalized); @@ -40,12 +39,12 @@ mod tests { #[test] fn normalize_s_low() { #[rustfmt::skip] - let sig = Signature::from_bytes(&[ + let sig = Signature::try_from([ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]).unwrap(); + ].as_slice()).unwrap(); assert_eq!(sig.normalize_s(), None); } diff --git a/k256/src/ecdsa/recoverable.rs b/k256/src/ecdsa/recoverable.rs index 8918c57a..f7b6a108 100644 --- a/k256/src/ecdsa/recoverable.rs +++ b/k256/src/ecdsa/recoverable.rs @@ -36,7 +36,7 @@ //! ``` use core::fmt::{self, Debug}; -use ecdsa_core::{signature::Signature as _, Error, Result}; +use ecdsa_core::{Error, Result}; use elliptic_curve::subtle::Choice; #[cfg(feature = "ecdsa")] @@ -85,7 +85,7 @@ impl Signature { /// is valid for this signature. pub fn new(signature: &super::Signature, recovery_id: Id) -> Result { let mut bytes = [0u8; SIZE]; - bytes[..64].copy_from_slice(signature.as_ref()); + bytes[..64].copy_from_slice(&signature.to_bytes()); bytes[64] = recovery_id.0; Ok(Self { bytes }) } @@ -223,9 +223,11 @@ impl Signature { } } -impl ecdsa_core::signature::Signature for Signature { - fn from_bytes(bytes: &[u8]) -> Result { - bytes.try_into() +impl ecdsa_core::signature::SignatureEncoding for Signature { + type Repr = [u8; SIZE]; + + fn to_bytes(&self) -> Self::Repr { + self.bytes } } @@ -241,6 +243,12 @@ impl Debug for Signature { } } +impl From for [u8; SIZE] { + fn from(signature: Signature) -> [u8; SIZE] { + signature.bytes + } +} + impl TryFrom<&[u8]> for Signature { type Error = Error; @@ -257,7 +265,7 @@ impl TryFrom<&[u8]> for Signature { impl From for super::Signature { fn from(sig: Signature) -> Self { - Self::from_bytes(&sig.bytes[..64]).unwrap() + Self::try_from(&sig.bytes[..64]).unwrap() } } diff --git a/k256/src/ecdsa/sign.rs b/k256/src/ecdsa/sign.rs index 6c626187..4bea8cb4 100644 --- a/k256/src/ecdsa/sign.rs +++ b/k256/src/ecdsa/sign.rs @@ -11,14 +11,14 @@ use ecdsa_core::{ signature::{ digest::{Digest, FixedOutput}, hazmat::PrehashSigner, - DigestSigner, Keypair, RandomizedDigestSigner, + DigestSigner, KeypairRef, RandomizedDigestSigner, }, }; use elliptic_curve::{ bigint::U256, consts::U32, ops::{Invert, Reduce}, - rand_core::{CryptoRng, RngCore}, + rand_core::CryptoRngCore, subtle::{Choice, ConstantTimeEq, CtOption}, zeroize::{Zeroize, ZeroizeOnDrop}, IsHigh, @@ -47,7 +47,7 @@ pub struct SigningKey { impl SigningKey { /// Generate a cryptographically random [`SigningKey`]. - pub fn random(rng: impl CryptoRng + RngCore) -> Self { + pub fn random(rng: &mut impl CryptoRngCore) -> Self { NonZeroScalar::random(rng).into() } @@ -92,7 +92,7 @@ where S: PrehashSignature, Self: RandomizedDigestSigner, { - fn try_sign_with_rng(&self, rng: impl CryptoRng + RngCore, msg: &[u8]) -> signature::Result { + fn try_sign_with_rng(&self, rng: &mut impl CryptoRngCore, msg: &[u8]) -> signature::Result { self.try_sign_digest_with_rng(rng, S::Digest::new_with_prefix(msg)) } } @@ -117,13 +117,7 @@ where #[cfg(feature = "sha256")] #[cfg_attr(docsrs, doc(cfg(feature = "sha256")))] -impl Keypair for SigningKey { - type VerifyingKey = VerifyingKey; -} - -#[cfg(feature = "keccak256")] -#[cfg_attr(docsrs, doc(cfg(feature = "keccak256")))] -impl Keypair for SigningKey { +impl KeypairRef for SigningKey { type VerifyingKey = VerifyingKey; } @@ -159,7 +153,7 @@ where { fn try_sign_digest_with_rng( &self, - rng: impl CryptoRng + RngCore, + rng: &mut impl CryptoRngCore, digest: D, ) -> Result { RandomizedDigestSigner::::try_sign_digest_with_rng( @@ -175,7 +169,7 @@ where { fn try_sign_digest_with_rng( &self, - mut rng: impl CryptoRng + RngCore, + rng: &mut impl CryptoRngCore, msg_digest: D, ) -> Result { let mut ad = FieldBytes::default(); diff --git a/k256/src/schnorr.rs b/k256/src/schnorr.rs index cf319cac..a3b5485d 100644 --- a/k256/src/schnorr.rs +++ b/k256/src/schnorr.rs @@ -66,25 +66,26 @@ mod sign; mod verify; pub use self::{sign::SigningKey, verify::VerifyingKey}; -pub use ecdsa_core::signature::{self, Error}; +pub use ecdsa_core::signature::{self, rand_core::CryptoRngCore, Error}; use crate::{arithmetic::FieldElement, NonZeroScalar}; -use core::{cmp, fmt}; +use core::fmt; use ecdsa_core::signature::Result; +use elliptic_curve::subtle::ConstantTimeEq; use sha2::{Digest, Sha256}; const AUX_TAG: &[u8] = b"BIP0340/aux"; const NONCE_TAG: &[u8] = b"BIP0340/nonce"; const CHALLENGE_TAG: &[u8] = b"BIP0340/challenge"; +/// Taproot Schnorr signature serialized as bytes. +pub type SignatureBytes = [u8; Signature::BYTE_SIZE]; + /// Taproot Schnorr signature as defined in [BIP340]. /// /// [BIP340]: https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki #[derive(Copy, Clone)] pub struct Signature { - bytes: [u8; Self::BYTE_SIZE], - - // for efficiency r: FieldElement, s: NonZeroScalar, } @@ -93,9 +94,13 @@ impl Signature { /// Size of a Taproot Schnorr signature in bytes. pub const BYTE_SIZE: usize = 64; - /// Borrow the serialized signature as bytes. - pub fn as_bytes(&self) -> &[u8; Self::BYTE_SIZE] { - &self.bytes + /// Serialize this signature as bytes. + pub fn to_bytes(&self) -> SignatureBytes { + let mut ret = [0; Self::BYTE_SIZE]; + let (r_bytes, s_bytes) = ret.split_at_mut(Self::BYTE_SIZE / 2); + r_bytes.copy_from_slice(&self.r.to_bytes()); + s_bytes.copy_from_slice(&self.s.to_bytes()); + ret } /// Get the `r` component of this signature. @@ -114,30 +119,23 @@ impl Signature { } } -impl AsRef<[u8]> for Signature { - fn as_ref(&self) -> &[u8] { - self.as_bytes() - } -} - impl Eq for Signature {} -impl PartialEq for Signature { - fn eq(&self, other: &Self) -> bool { - self.bytes == other.bytes +impl From for SignatureBytes { + fn from(signature: Signature) -> SignatureBytes { + signature.to_bytes() } } -impl PartialOrd for Signature { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) +impl From<&Signature> for SignatureBytes { + fn from(signature: &Signature) -> SignatureBytes { + signature.to_bytes() } } -// useful e.g. for BTreeMaps -impl Ord for Signature { - fn cmp(&self, other: &Self) -> cmp::Ordering { - self.bytes.cmp(&other.bytes) +impl PartialEq for Signature { + fn eq(&self, other: &Self) -> bool { + (self.r == other.r) && (self.s.ct_eq(&other.s).into()) } } @@ -145,7 +143,6 @@ impl TryFrom<&[u8]> for Signature { type Error = Error; fn try_from(bytes: &[u8]) -> Result { - let bytes: [u8; Self::BYTE_SIZE] = bytes.try_into().map_err(|_| Error::new())?; let (r_bytes, s_bytes) = bytes.split_at(Self::BYTE_SIZE / 2); let r: FieldElement = @@ -158,19 +155,21 @@ impl TryFrom<&[u8]> for Signature { let s = NonZeroScalar::try_from(s_bytes).map_err(|_| Error::new())?; - Ok(Self { bytes, r, s }) + Ok(Self { r, s }) } } impl fmt::Debug for Signature { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.bytes.fmt(f) + write!(f, "{:?}", self.to_bytes()) } } -impl signature::Signature for Signature { - fn from_bytes(bytes: &[u8]) -> Result { - bytes.try_into() +impl signature::SignatureEncoding for Signature { + type Repr = SignatureBytes; + + fn to_bytes(&self) -> Self::Repr { + self.into() } } @@ -190,7 +189,7 @@ fn tagged_hash(tag: &[u8]) -> Sha256 { // https://github.com/bitcoin/bips/blob/master/bip-0340/test-vectors.csv #[cfg(test)] mod tests { - use super::{signature::Signature as _, Signature, SigningKey, VerifyingKey}; + use super::{Signature, SigningKey, VerifyingKey}; use hex_literal::hex; /// Signing test vector @@ -279,8 +278,8 @@ mod tests { }); assert_eq!( - &vector.signature, - sig.as_ref(), + vector.signature, + sig.to_bytes(), "wrong signature for index {}", vector.index ); @@ -434,7 +433,7 @@ mod tests { for vector in BIP340_VERIFY_VECTORS { let valid = match ( VerifyingKey::from_bytes(&vector.public_key), - Signature::from_bytes(&vector.signature), + Signature::try_from(vector.signature.as_slice()), ) { (Ok(pk), Ok(sig)) => pk.verify_prehashed(&vector.message, &sig).is_ok(), _ => false, diff --git a/k256/src/schnorr/sign.rs b/k256/src/schnorr/sign.rs index f3be5d87..b0175156 100644 --- a/k256/src/schnorr/sign.rs +++ b/k256/src/schnorr/sign.rs @@ -9,7 +9,7 @@ use ecdsa_core::signature::{ use elliptic_curve::{ bigint::U256, ops::Reduce, - rand_core::{CryptoRng, RngCore}, + rand_core::CryptoRngCore, subtle::ConditionallySelectable, zeroize::{Zeroize, ZeroizeOnDrop}, }; @@ -27,7 +27,7 @@ pub struct SigningKey { impl SigningKey { /// Generate a cryptographically random [`SigningKey`]. - pub fn random(rng: impl CryptoRng + RngCore) -> Self { + pub fn random(rng: &mut impl CryptoRngCore) -> Self { let bytes = NonZeroScalar::random(rng).to_bytes(); Self::from_bytes(&bytes).unwrap() } @@ -110,14 +110,8 @@ impl SigningKey { ); let s = *secret_key + e * *self.secret_key; - let s: NonZeroScalar = Option::from(NonZeroScalar::new(s)).ok_or_else(Error::new)?; - - let mut bytes = [0u8; Signature::BYTE_SIZE]; - let (r_bytes, s_bytes) = bytes.split_at_mut(Signature::BYTE_SIZE / 2); - r_bytes.copy_from_slice(&r.to_bytes()); - s_bytes.copy_from_slice(&s.to_bytes()); - - let sig = Signature { bytes, r, s }; + let s = Option::from(NonZeroScalar::new(s)).ok_or_else(Error::new)?; + let sig = Signature { r, s }; #[cfg(debug_assertions)] self.verifying_key.verify_prehashed(msg_digest, &sig)?; @@ -141,7 +135,7 @@ where { fn try_sign_digest_with_rng( &self, - mut rng: impl CryptoRng + RngCore, + rng: &mut impl CryptoRngCore, digest: D, ) -> Result { let mut aux_rand = [0u8; 32]; @@ -151,7 +145,7 @@ where } impl RandomizedSigner for SigningKey { - fn try_sign_with_rng(&self, rng: impl CryptoRng + RngCore, msg: &[u8]) -> Result { + fn try_sign_with_rng(&self, rng: &mut impl CryptoRngCore, msg: &[u8]) -> Result { self.try_sign_digest_with_rng(rng, Sha256::new_with_prefix(msg)) } } diff --git a/k256/src/schnorr/verify.rs b/k256/src/schnorr/verify.rs index 73bfa687..083a744a 100644 --- a/k256/src/schnorr/verify.rs +++ b/k256/src/schnorr/verify.rs @@ -34,7 +34,7 @@ impl VerifyingKey { let e = >::from_be_bytes_reduced( tagged_hash(CHALLENGE_TAG) - .chain_update(&sig.bytes[..32]) + .chain_update(sig.r.to_bytes()) .chain_update(self.to_bytes()) .chain_update(msg_digest) .finalize(), diff --git a/p256/Cargo.toml b/p256/Cargo.toml index 9f917b2e..613010ab 100644 --- a/p256/Cargo.toml +++ b/p256/Cargo.toml @@ -21,7 +21,7 @@ elliptic-curve = { version = "0.12", default-features = false, features = ["hazm weierstrass = { version = "0", path = "../weierstrass" } # optional dependencies -ecdsa-core = { version = "0.14", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { version = "=0.15.0-pre", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.3", optional = true } serdect = { version = "0.1", optional = true, default-features = false } sha2 = { version = "0.10", optional = true, default-features = false } @@ -29,7 +29,7 @@ sha2 = { version = "0.10", optional = true, default-features = false } [dev-dependencies] blobby = "0.3" criterion = "0.4" -ecdsa-core = { version = "0.14", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { version = "=0.15.0-pre", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.3" proptest = "1.0" rand_core = { version = "0.6", features = ["getrandom"] } diff --git a/p256/src/arithmetic/scalar/blinded.rs b/p256/src/arithmetic/scalar/blinded.rs index 4aac591d..265efef9 100644 --- a/p256/src/arithmetic/scalar/blinded.rs +++ b/p256/src/arithmetic/scalar/blinded.rs @@ -6,11 +6,7 @@ use super::Scalar; use core::borrow::Borrow; use elliptic_curve::{ - group::ff::Field, - ops::Invert, - rand_core::{CryptoRng, RngCore}, - subtle::CtOption, - zeroize::Zeroize, + group::ff::Field, ops::Invert, rand_core::CryptoRngCore, subtle::CtOption, zeroize::Zeroize, }; /// Scalar blinded with a randomly generated masking value. @@ -28,8 +24,8 @@ pub struct BlindedScalar { } impl BlindedScalar { - /// Create a new [`BlindedScalar`] from a scalar and a [`CryptoRng`] - pub fn new(scalar: Scalar, rng: impl CryptoRng + RngCore) -> Self { + /// Create a new [`BlindedScalar`] from a scalar and a [`CryptoRngCore`] + pub fn new(scalar: Scalar, rng: &mut impl CryptoRngCore) -> Self { Self { scalar, mask: Scalar::random(rng), diff --git a/p256/src/ecdsa.rs b/p256/src/ecdsa.rs index e06856cd..1c70a127 100644 --- a/p256/src/ecdsa.rs +++ b/p256/src/ecdsa.rs @@ -29,7 +29,7 @@ //! // Signing //! let signing_key = SigningKey::random(&mut OsRng); // Serialize with `::to_bytes()` //! let message = b"ECDSA proves knowledge of a secret number in the context of a single message"; -//! let signature = signing_key.sign(message); +//! let signature: Signature = signing_key.sign(message); //! //! // Verification //! use p256::ecdsa::{VerifyingKey, signature::Verifier}; @@ -102,21 +102,21 @@ mod tests { fn rfc6979() { let x = &hex!("c9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721"); let signer = SigningKey::from_bytes(x).unwrap(); - let signature = signer.sign(b"sample"); + let signature: Signature = signer.sign(b"sample"); assert_eq!( - signature.as_ref(), + signature.to_bytes().as_slice(), &hex!( "efd48b2aacb6a8fd1140dd9cd45e81d69d2c877b56aaf991c34d0ea84eaf3716 - f7cb1c942d657c41d436c7a1b6e29f65f3e900dbb9aff4064dc4ab2f843acda8" - )[..] + f7cb1c942d657c41d436c7a1b6e29f65f3e900dbb9aff4064dc4ab2f843acda8" + ) ); - let signature = signer.sign(b"test"); + let signature: Signature = signer.sign(b"test"); assert_eq!( - signature.as_ref(), + signature.to_bytes().as_slice(), &hex!( "f1abb023518351cd71d881567b1ea663ed3efcf6c5132b354f28d3b0b7d38367 - 019f4113742a2b14bd25926b49c649155f267e60d3814b4c0cc84250e46f0083" - )[..] + 019f4113742a2b14bd25926b49c649155f267e60d3814b4c0cc84250e46f0083" + ) ); } @@ -126,13 +126,13 @@ mod tests { let x = &hex!("c9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721"); let signer = SigningKey::from_bytes(x).unwrap(); let digest = sha2::Sha384::digest(b"test"); - let signature = signer.sign_prehash(&digest).unwrap(); + let signature: Signature = signer.sign_prehash(&digest).unwrap(); assert_eq!( - signature.as_ref(), + signature.to_bytes().as_slice(), &hex!( "ebde85f1539af67e70dd7a8a6afeeb332aa7f08f01ebb6ab6e04e2a62d2fef75 - 871af45800daddf55619b005a601a7a84f544260f1d2625b2ef5aa7a4f4dd76f" - )[..] + 871af45800daddf55619b005a601a7a84f544260f1d2625b2ef5aa7a4f4dd76f" + ) ); } diff --git a/p384/Cargo.toml b/p384/Cargo.toml index a2fc62d1..04aac267 100644 --- a/p384/Cargo.toml +++ b/p384/Cargo.toml @@ -21,7 +21,7 @@ elliptic-curve = { version = "0.12", default-features = false, features = ["hazm weierstrass = { version = "0", path = "../weierstrass" } # optional dependencies -ecdsa-core = { version = "0.14", package = "ecdsa", optional = true, default-features = false, features = ["der"] } +ecdsa-core = { version = "=0.15.0-pre", package = "ecdsa", optional = true, default-features = false, features = ["der"] } hex-literal = { version = "0.3", optional = true } serdect = { version = "0.1", optional = true, default-features = false } sha2 = { version = "0.10", optional = true, default-features = false } @@ -29,7 +29,7 @@ sha2 = { version = "0.10", optional = true, default-features = false } [dev-dependencies] blobby = "0.3" criterion = "0.4" -ecdsa-core = { version = "0.14", package = "ecdsa", default-features = false, features = ["dev"] } +ecdsa-core = { version = "=0.15.0-pre", package = "ecdsa", default-features = false, features = ["dev"] } hex-literal = "0.3" proptest = "1.0" rand_core = { version = "0.6", features = ["getrandom"] } diff --git a/p384/src/ecdsa.rs b/p384/src/ecdsa.rs index 53f718ab..ea1c1e5b 100644 --- a/p384/src/ecdsa.rs +++ b/p384/src/ecdsa.rs @@ -27,7 +27,7 @@ //! // Signing //! let signing_key = SigningKey::random(&mut OsRng); // Serialize with `::to_bytes()` //! let message = b"ECDSA proves knowledge of a secret number in the context of a single message"; -//! let signature = signing_key.sign(message); +//! let signature: Signature = signing_key.sign(message); //! //! // Verification //! use p384::ecdsa::{signature::Verifier, VerifyingKey}; @@ -95,21 +95,22 @@ mod tests { fn rfc6979() { let x = &hex!("6b9d3dad2e1b8c1c05b19875b6659f4de23c3b667bf297ba9aa47740787137d896d5724e4c70a825f872c9ea60d2edf5"); let signer = SigningKey::from_bytes(x).unwrap(); - let signature = signer.sign(b"sample"); + let signature: Signature = signer.sign(b"sample"); assert_eq!( - signature.as_ref(), + signature.to_bytes().as_slice(), &hex!( "94edbb92a5ecb8aad4736e56c691916b3f88140666ce9fa73d64c4ea95ad133c81a648152e44acf96e36dd1e80fabe46 99ef4aeb15f178cea1fe40db2603138f130e740a19624526203b6351d0a3a94fa329c145786e679e7b82c71a38628ac8" - )[..] + ) ); - let signature = signer.sign(b"test"); + + let signature: Signature = signer.sign(b"test"); assert_eq!( - signature.as_ref(), + signature.to_bytes().as_slice(), &hex!( "8203b63d3c853e8d77227fb377bcf7b7b772e97892a80f36ab775d509d7a5feb0542a7f0812998da8f1dd3ca3cf023db ddd0760448d42d8a43af45af836fce4de8be06b485e9b61b827c2f13173923e06a739f040649a667bf3b828246baa5a5" - )[..] + ) ); } @@ -119,13 +120,13 @@ mod tests { let x = &hex!("6b9d3dad2e1b8c1c05b19875b6659f4de23c3b667bf297ba9aa47740787137d896d5724e4c70a825f872c9ea60d2edf5"); let signer = SigningKey::from_bytes(x).unwrap(); let digest = sha2::Sha256::digest(b"test"); - let signature = signer.sign_prehash(&digest).unwrap(); + let signature: Signature = signer.sign_prehash(&digest).unwrap(); assert_eq!( - signature.as_ref(), + signature.to_bytes().as_slice(), &hex!( "010c3ab1a300f8c9d63eafa9a41813f0c5416c08814bdfc0236458d6c2603d71c4941f4696e60aff5717476170bb6ab4 03c4ad6274c61691346b2178def879424726909af308596ffb6355a042f48a114e2eb28eaa6918592b4727961057c0c1" - )[..] + ) ); }