mirror of
https://github.com/RustCrypto/signatures
synced 2026-06-21 13:45:42 +00:00
ecdsa: use the crypto_common::Generate trait (#1140)
Updates that go along with RustCrypto/traits#2173, which switched the `elliptic-curve` to use the `Generate` trait introduced in RustCrypto/traits#2096
This commit is contained in:
Generated
+16
-6
@@ -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",
|
||||
|
||||
@@ -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" }
|
||||
|
||||
+20
-43
@@ -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<C>
|
||||
where
|
||||
C: EcdsaCurve + CurveArithmetic,
|
||||
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
|
||||
SignatureSize<C>: ArraySize,
|
||||
{
|
||||
/// ECDSA signing keys are non-zero elements of a given curve's scalar field.
|
||||
secret_scalar: NonZeroScalar<C>,
|
||||
@@ -81,26 +80,7 @@ where
|
||||
impl<C> SigningKey<C>
|
||||
where
|
||||
C: EcdsaCurve + CurveArithmetic,
|
||||
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
|
||||
SignatureSize<C>: 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::<C>::generate().into()
|
||||
}
|
||||
|
||||
/// Generate a cryptographically random [`SigningKey`], returning underlying RNG errors.
|
||||
pub fn try_from_rng<R: TryCryptoRng + ?Sized>(
|
||||
rng: &mut R,
|
||||
) -> core::result::Result<Self, R::Error> {
|
||||
Ok(NonZeroScalar::<C>::try_from_rng(rng)?.into())
|
||||
}
|
||||
|
||||
/// Initialize signing key from a raw scalar serialized as a byte array.
|
||||
pub fn from_bytes(bytes: &FieldBytes<C>) -> Result<Self> {
|
||||
SecretKey::<C>::from_bytes(bytes)
|
||||
@@ -136,6 +116,23 @@ where
|
||||
pub fn verifying_key(&self) -> &VerifyingKey<C> {
|
||||
&self.verifying_key
|
||||
}
|
||||
|
||||
/// DEPRECATED: Generate a cryptographically random [`SigningKey`].
|
||||
#[deprecated(since = "0.17.0", note = "use the `Generate` trait instead")]
|
||||
pub fn random<R: CryptoRng + ?Sized>(rng: &mut R) -> Self {
|
||||
Self::generate_from_rng(rng)
|
||||
}
|
||||
}
|
||||
|
||||
impl<C> Generate for SigningKey<C>
|
||||
where
|
||||
C: EcdsaCurve + CurveArithmetic,
|
||||
{
|
||||
fn try_generate_from_rng<R: TryCryptoRng + ?Sized>(
|
||||
rng: &mut R,
|
||||
) -> core::result::Result<Self, R::Error> {
|
||||
Ok(NonZeroScalar::<C>::try_generate_from_rng(rng)?.into())
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -474,8 +471,6 @@ where
|
||||
impl<C> Debug for SigningKey<C>
|
||||
where
|
||||
C: EcdsaCurve + CurveArithmetic,
|
||||
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
|
||||
SignatureSize<C>: ArraySize,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("SigningKey").finish_non_exhaustive()
|
||||
@@ -485,8 +480,6 @@ where
|
||||
impl<C> Drop for SigningKey<C>
|
||||
where
|
||||
C: EcdsaCurve + CurveArithmetic,
|
||||
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
|
||||
SignatureSize<C>: ArraySize,
|
||||
{
|
||||
fn drop(&mut self) {
|
||||
self.secret_scalar.zeroize();
|
||||
@@ -515,8 +508,6 @@ where
|
||||
impl<C> From<NonZeroScalar<C>> for SigningKey<C>
|
||||
where
|
||||
C: EcdsaCurve + CurveArithmetic,
|
||||
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
|
||||
SignatureSize<C>: ArraySize,
|
||||
{
|
||||
fn from(secret_scalar: NonZeroScalar<C>) -> Self {
|
||||
#[cfg(feature = "algorithm")]
|
||||
@@ -533,8 +524,6 @@ where
|
||||
impl<C> From<SecretKey<C>> for SigningKey<C>
|
||||
where
|
||||
C: EcdsaCurve + CurveArithmetic,
|
||||
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
|
||||
SignatureSize<C>: ArraySize,
|
||||
{
|
||||
fn from(secret_key: SecretKey<C>) -> Self {
|
||||
Self::from(&secret_key)
|
||||
@@ -544,8 +533,6 @@ where
|
||||
impl<C> From<&SecretKey<C>> for SigningKey<C>
|
||||
where
|
||||
C: EcdsaCurve + CurveArithmetic,
|
||||
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
|
||||
SignatureSize<C>: ArraySize,
|
||||
{
|
||||
fn from(secret_key: &SecretKey<C>) -> Self {
|
||||
secret_key.to_nonzero_scalar().into()
|
||||
@@ -566,8 +553,6 @@ where
|
||||
impl<C> From<&SigningKey<C>> for SecretKey<C>
|
||||
where
|
||||
C: EcdsaCurve + CurveArithmetic,
|
||||
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
|
||||
SignatureSize<C>: ArraySize,
|
||||
{
|
||||
fn from(secret_key: &SigningKey<C>) -> Self {
|
||||
secret_key.secret_scalar.into()
|
||||
@@ -577,8 +562,6 @@ where
|
||||
impl<C> TryFrom<&[u8]> for SigningKey<C>
|
||||
where
|
||||
C: EcdsaCurve + CurveArithmetic,
|
||||
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
|
||||
SignatureSize<C>: ArraySize,
|
||||
{
|
||||
type Error = Error;
|
||||
|
||||
@@ -587,13 +570,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<C> ZeroizeOnDrop for SigningKey<C>
|
||||
where
|
||||
C: EcdsaCurve + CurveArithmetic,
|
||||
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
|
||||
SignatureSize<C>: ArraySize,
|
||||
{
|
||||
}
|
||||
impl<C> ZeroizeOnDrop for SigningKey<C> where C: EcdsaCurve + CurveArithmetic {}
|
||||
|
||||
#[cfg(feature = "algorithm")]
|
||||
impl<C> From<SigningKey<C>> for VerifyingKey<C>
|
||||
|
||||
Reference in New Issue
Block a user