@@ -7,10 +7,11 @@ use crate::{
77use core:: fmt:: { self , Debug } ;
88use digest:: { Update , block_api:: EagerHash , const_oid:: AssociatedOid } ;
99use elliptic_curve:: {
10- CurveArithmetic , FieldBytes , NonZeroScalar , Scalar , SecretKey ,
10+ CurveArithmetic , FieldBytes , Generate , NonZeroScalar , Scalar , SecretKey ,
1111 array:: ArraySize ,
1212 group:: ff:: PrimeField ,
1313 ops:: Invert ,
14+ rand_core:: CryptoRng ,
1415 subtle:: { Choice , ConstantTimeEq , CtOption } ,
1516 zeroize:: { Zeroize , ZeroizeOnDrop } ,
1617} ;
@@ -67,8 +68,6 @@ use elliptic_curve::pkcs8::{EncodePrivateKey, SecretDocument};
6768pub struct SigningKey < C >
6869where
6970 C : EcdsaCurve + CurveArithmetic ,
70- Scalar < C > : Invert < Output = CtOption < Scalar < C > > > ,
71- SignatureSize < C > : ArraySize ,
7271{
7372 /// ECDSA signing keys are non-zero elements of a given curve's scalar field.
7473 secret_scalar : NonZeroScalar < C > ,
8180impl < C > SigningKey < C >
8281where
8382 C : EcdsaCurve + CurveArithmetic ,
84- Scalar < C > : Invert < Output = CtOption < Scalar < C > > > ,
85- SignatureSize < C > : ArraySize ,
8683{
87- /// Generate a cryptographically random [`SigningKey`].
88- ///
89- /// # Panics
90- ///
91- /// If the system's cryptographically secure RNG has an internal error.
92- #[ cfg( feature = "getrandom" ) ]
93- pub fn generate ( ) -> Self {
94- NonZeroScalar :: < C > :: generate ( ) . into ( )
95- }
96-
97- /// Generate a cryptographically random [`SigningKey`], returning underlying RNG errors.
98- pub fn try_from_rng < R : TryCryptoRng + ?Sized > (
99- rng : & mut R ,
100- ) -> core:: result:: Result < Self , R :: Error > {
101- Ok ( NonZeroScalar :: < C > :: try_from_rng ( rng) ?. into ( ) )
102- }
103-
10484 /// Initialize signing key from a raw scalar serialized as a byte array.
10585 pub fn from_bytes ( bytes : & FieldBytes < C > ) -> Result < Self > {
10686 SecretKey :: < C > :: from_bytes ( bytes)
@@ -136,6 +116,23 @@ where
136116 pub fn verifying_key ( & self ) -> & VerifyingKey < C > {
137117 & self . verifying_key
138118 }
119+
120+ /// DEPRECATED: Generate a cryptographically random [`SigningKey`].
121+ #[ deprecated( since = "0.17.0" , note = "use the `Generate` trait instead" ) ]
122+ pub fn random < R : CryptoRng + ?Sized > ( rng : & mut R ) -> Self {
123+ Self :: generate_from_rng ( rng)
124+ }
125+ }
126+
127+ impl < C > Generate for SigningKey < C >
128+ where
129+ C : EcdsaCurve + CurveArithmetic ,
130+ {
131+ fn try_generate_from_rng < R : TryCryptoRng + ?Sized > (
132+ rng : & mut R ,
133+ ) -> core:: result:: Result < Self , R :: Error > {
134+ Ok ( NonZeroScalar :: < C > :: try_generate_from_rng ( rng) ?. into ( ) )
135+ }
139136}
140137
141138//
@@ -474,8 +471,6 @@ where
474471impl < C > Debug for SigningKey < C >
475472where
476473 C : EcdsaCurve + CurveArithmetic ,
477- Scalar < C > : Invert < Output = CtOption < Scalar < C > > > ,
478- SignatureSize < C > : ArraySize ,
479474{
480475 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
481476 f. debug_struct ( "SigningKey" ) . finish_non_exhaustive ( )
@@ -485,8 +480,6 @@ where
485480impl < C > Drop for SigningKey < C >
486481where
487482 C : EcdsaCurve + CurveArithmetic ,
488- Scalar < C > : Invert < Output = CtOption < Scalar < C > > > ,
489- SignatureSize < C > : ArraySize ,
490483{
491484 fn drop ( & mut self ) {
492485 self . secret_scalar . zeroize ( ) ;
@@ -515,8 +508,6 @@ where
515508impl < C > From < NonZeroScalar < C > > for SigningKey < C >
516509where
517510 C : EcdsaCurve + CurveArithmetic ,
518- Scalar < C > : Invert < Output = CtOption < Scalar < C > > > ,
519- SignatureSize < C > : ArraySize ,
520511{
521512 fn from ( secret_scalar : NonZeroScalar < C > ) -> Self {
522513 #[ cfg( feature = "algorithm" ) ]
@@ -533,8 +524,6 @@ where
533524impl < C > From < SecretKey < C > > for SigningKey < C >
534525where
535526 C : EcdsaCurve + CurveArithmetic ,
536- Scalar < C > : Invert < Output = CtOption < Scalar < C > > > ,
537- SignatureSize < C > : ArraySize ,
538527{
539528 fn from ( secret_key : SecretKey < C > ) -> Self {
540529 Self :: from ( & secret_key)
@@ -544,8 +533,6 @@ where
544533impl < C > From < & SecretKey < C > > for SigningKey < C >
545534where
546535 C : EcdsaCurve + CurveArithmetic ,
547- Scalar < C > : Invert < Output = CtOption < Scalar < C > > > ,
548- SignatureSize < C > : ArraySize ,
549536{
550537 fn from ( secret_key : & SecretKey < C > ) -> Self {
551538 secret_key. to_nonzero_scalar ( ) . into ( )
@@ -566,8 +553,6 @@ where
566553impl < C > From < & SigningKey < C > > for SecretKey < C >
567554where
568555 C : EcdsaCurve + CurveArithmetic ,
569- Scalar < C > : Invert < Output = CtOption < Scalar < C > > > ,
570- SignatureSize < C > : ArraySize ,
571556{
572557 fn from ( secret_key : & SigningKey < C > ) -> Self {
573558 secret_key. secret_scalar . into ( )
@@ -577,8 +562,6 @@ where
577562impl < C > TryFrom < & [ u8 ] > for SigningKey < C >
578563where
579564 C : EcdsaCurve + CurveArithmetic ,
580- Scalar < C > : Invert < Output = CtOption < Scalar < C > > > ,
581- SignatureSize < C > : ArraySize ,
582565{
583566 type Error = Error ;
584567
@@ -587,13 +570,7 @@ where
587570 }
588571}
589572
590- impl < C > ZeroizeOnDrop for SigningKey < C >
591- where
592- C : EcdsaCurve + CurveArithmetic ,
593- Scalar < C > : Invert < Output = CtOption < Scalar < C > > > ,
594- SignatureSize < C > : ArraySize ,
595- {
596- }
573+ impl < C > ZeroizeOnDrop for SigningKey < C > where C : EcdsaCurve + CurveArithmetic { }
597574
598575#[ cfg( feature = "algorithm" ) ]
599576impl < C > From < SigningKey < C > > for VerifyingKey < C >
0 commit comments