diff --git a/Cargo.lock b/Cargo.lock index c856eb84..4b53071a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -152,7 +152,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "155e4a260750fa4f7754649f049748aacc31db238a358d85fd721002f230f92f" dependencies = [ "block-buffer", - "crypto-common", + "crypto-common 0.2.0-rc.8", "inout", ] @@ -268,9 +268,9 @@ checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" [[package]] name = "crypto-bigint" -version = "0.7.0-rc.14" +version = "0.7.0-rc.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9c6daa2049db6a5fad90a981b8c63f023dbaf75a0fae73db4dcf234556fc957" +checksum = "1a9e36ac79ac44866b74e08a0b4925f97b984e3fff17680d2c6fbce8317ab0f6" dependencies = [ "ctutils", "getrandom 0.4.0-rc.0", @@ -291,6 +291,16 @@ dependencies = [ "hybrid-array", ] +[[package]] +name = "crypto-common" +version = "0.2.0-rc.9" +source = "git+https://github.com/RustCrypto/traits#ded0d2297fba206939bfb5f47b4fd823c4bccae8" +dependencies = [ + "getrandom 0.4.0-rc.0", + "hybrid-array", + "rand_core 0.10.0-rc-3", +] + [[package]] name = "crypto-primes" version = "0.7.0-pre.5" @@ -353,7 +363,7 @@ dependencies = [ "blobby", "block-buffer", "const-oid", - "crypto-common", + "crypto-common 0.2.0-rc.8", "subtle", ] @@ -429,11 +439,11 @@ checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" [[package]] name = "elliptic-curve" version = "0.14.0-rc.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4874d0de0bf58704a6917f26154afcdd49ebc11cae10b6d53950217aee9408" +source = "git+https://github.com/RustCrypto/traits#ded0d2297fba206939bfb5f47b4fd823c4bccae8" dependencies = [ "base16ct", "crypto-bigint", + "crypto-common 0.2.0-rc.9", "digest", "getrandom 0.4.0-rc.0", "hex-literal", diff --git a/Cargo.toml b/Cargo.toml index 79c5444c..51be60a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,3 +25,5 @@ lms-signature = { path = "./lms" } ml-dsa = { path = "./ml-dsa" } rfc6979 = { path = "./rfc6979" } slh-dsa = { path = "./slh-dsa" } + +elliptic-curve = { git = "https://github.com/RustCrypto/traits" } diff --git a/ecdsa/src/signing.rs b/ecdsa/src/signing.rs index 3b6264eb..380563bd 100644 --- a/ecdsa/src/signing.rs +++ b/ecdsa/src/signing.rs @@ -7,10 +7,11 @@ use crate::{ use core::fmt::{self, Debug}; use digest::{Update, block_api::EagerHash, const_oid::AssociatedOid}; use elliptic_curve::{ - CurveArithmetic, FieldBytes, NonZeroScalar, Scalar, SecretKey, + CurveArithmetic, FieldBytes, Generate, NonZeroScalar, Scalar, SecretKey, array::ArraySize, group::ff::PrimeField, ops::Invert, + rand_core::CryptoRng, subtle::{Choice, ConstantTimeEq, CtOption}, zeroize::{Zeroize, ZeroizeOnDrop}, }; @@ -67,8 +68,6 @@ use elliptic_curve::pkcs8::{EncodePrivateKey, SecretDocument}; pub struct SigningKey where C: EcdsaCurve + CurveArithmetic, - Scalar: Invert>>, - SignatureSize: ArraySize, { /// ECDSA signing keys are non-zero elements of a given curve's scalar field. secret_scalar: NonZeroScalar, @@ -81,26 +80,7 @@ where impl SigningKey where C: EcdsaCurve + CurveArithmetic, - Scalar: Invert>>, - SignatureSize: ArraySize, { - /// Generate a cryptographically random [`SigningKey`]. - /// - /// # Panics - /// - /// If the system's cryptographically secure RNG has an internal error. - #[cfg(feature = "getrandom")] - pub fn generate() -> Self { - NonZeroScalar::::generate().into() - } - - /// Generate a cryptographically random [`SigningKey`], returning underlying RNG errors. - pub fn try_from_rng( - rng: &mut R, - ) -> core::result::Result { - Ok(NonZeroScalar::::try_from_rng(rng)?.into()) - } - /// Initialize signing key from a raw scalar serialized as a byte array. pub fn from_bytes(bytes: &FieldBytes) -> Result { SecretKey::::from_bytes(bytes) @@ -136,6 +116,23 @@ where pub fn verifying_key(&self) -> &VerifyingKey { &self.verifying_key } + + /// DEPRECATED: Generate a cryptographically random [`SigningKey`]. + #[deprecated(since = "0.17.0", note = "use the `Generate` trait instead")] + pub fn random(rng: &mut R) -> Self { + Self::generate_from_rng(rng) + } +} + +impl Generate for SigningKey +where + C: EcdsaCurve + CurveArithmetic, +{ + fn try_generate_from_rng( + rng: &mut R, + ) -> core::result::Result { + Ok(NonZeroScalar::::try_generate_from_rng(rng)?.into()) + } } // @@ -474,8 +471,6 @@ where impl Debug for SigningKey where C: EcdsaCurve + CurveArithmetic, - Scalar: Invert>>, - SignatureSize: ArraySize, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("SigningKey").finish_non_exhaustive() @@ -485,8 +480,6 @@ where impl Drop for SigningKey where C: EcdsaCurve + CurveArithmetic, - Scalar: Invert>>, - SignatureSize: ArraySize, { fn drop(&mut self) { self.secret_scalar.zeroize(); @@ -515,8 +508,6 @@ where impl From> for SigningKey where C: EcdsaCurve + CurveArithmetic, - Scalar: Invert>>, - SignatureSize: ArraySize, { fn from(secret_scalar: NonZeroScalar) -> Self { #[cfg(feature = "algorithm")] @@ -533,8 +524,6 @@ where impl From> for SigningKey where C: EcdsaCurve + CurveArithmetic, - Scalar: Invert>>, - SignatureSize: ArraySize, { fn from(secret_key: SecretKey) -> Self { Self::from(&secret_key) @@ -544,8 +533,6 @@ where impl From<&SecretKey> for SigningKey where C: EcdsaCurve + CurveArithmetic, - Scalar: Invert>>, - SignatureSize: ArraySize, { fn from(secret_key: &SecretKey) -> Self { secret_key.to_nonzero_scalar().into() @@ -566,8 +553,6 @@ where impl From<&SigningKey> for SecretKey where C: EcdsaCurve + CurveArithmetic, - Scalar: Invert>>, - SignatureSize: ArraySize, { fn from(secret_key: &SigningKey) -> Self { secret_key.secret_scalar.into() @@ -577,8 +562,6 @@ where impl TryFrom<&[u8]> for SigningKey where C: EcdsaCurve + CurveArithmetic, - Scalar: Invert>>, - SignatureSize: ArraySize, { type Error = Error; @@ -587,13 +570,7 @@ where } } -impl ZeroizeOnDrop for SigningKey -where - C: EcdsaCurve + CurveArithmetic, - Scalar: Invert>>, - SignatureSize: ArraySize, -{ -} +impl ZeroizeOnDrop for SigningKey where C: EcdsaCurve + CurveArithmetic {} #[cfg(feature = "algorithm")] impl From> for VerifyingKey