@@ -156,7 +156,7 @@ pub trait HashAlgorithm: Clone + Default {
156156}
157157
158158/// SHA-256 hash algorithm
159- #[ derive( Clone , Copy , Debug , Default ) ]
159+ #[ derive( Clone , Copy , Debug , Default , Eq , PartialEq ) ]
160160pub struct Sha256 ;
161161
162162impl HashAlgorithm for Sha256 {
@@ -180,7 +180,7 @@ impl HashAlgorithm for Sha256 {
180180}
181181
182182/// SHA-384 hash algorithm
183- #[ derive( Clone , Copy , Debug , Default ) ]
183+ #[ derive( Clone , Copy , Debug , Default , Eq , PartialEq ) ]
184184pub struct Sha384 ;
185185
186186impl HashAlgorithm for Sha384 {
@@ -204,7 +204,7 @@ impl HashAlgorithm for Sha384 {
204204}
205205
206206/// SHA-512 hash algorithm
207- #[ derive( Clone , Copy , Debug , Default ) ]
207+ #[ derive( Clone , Copy , Debug , Default , Eq , PartialEq ) ]
208208pub struct Sha512 ;
209209
210210impl HashAlgorithm for Sha512 {
@@ -244,7 +244,7 @@ pub trait SaltMode: Clone + Default + private::Sealed {
244244}
245245
246246/// PSS mode with salt (salt length = hash output length)
247- #[ derive( Clone , Copy , Debug , Default ) ]
247+ #[ derive( Clone , Copy , Debug , Default , Eq , PartialEq ) ]
248248pub struct PSS ;
249249
250250impl private:: Sealed for PSS { }
@@ -254,7 +254,7 @@ impl SaltMode for PSS {
254254}
255255
256256/// PSS mode without salt (salt length = 0)
257- #[ derive( Clone , Copy , Debug , Default ) ]
257+ #[ derive( Clone , Copy , Debug , Default , Eq , PartialEq ) ]
258258pub struct PSSZero ;
259259
260260impl private:: Sealed for PSSZero { }
@@ -271,7 +271,7 @@ pub trait MessagePrepare: Clone + Default + private::Sealed {
271271}
272272
273273/// Randomized message preparation
274- #[ derive( Clone , Copy , Debug , Default ) ]
274+ #[ derive( Clone , Copy , Debug , Default , Eq , PartialEq ) ]
275275pub struct Randomized ;
276276
277277impl private:: Sealed for Randomized { }
@@ -281,7 +281,7 @@ impl MessagePrepare for Randomized {
281281}
282282
283283/// Deterministic message preparation
284- #[ derive( Clone , Copy , Debug , Default ) ]
284+ #[ derive( Clone , Copy , Debug , Default , Eq , PartialEq ) ]
285285pub struct Deterministic ;
286286
287287impl private:: Sealed for Deterministic { }
@@ -317,24 +317,32 @@ impl TryCryptoRng for DefaultRng {}
317317#[ derive( Clone , Debug , AsRef , Deref , From , Into , new) ]
318318pub struct Secret ( pub Vec < u8 > ) ;
319319
320+ impl Eq for Secret { }
321+
322+ impl PartialEq for Secret {
323+ fn eq ( & self , other : & Self ) -> bool {
324+ ct_codecs:: verify ( & self . 0 , & other. 0 )
325+ }
326+ }
327+
320328/// A blind message
321329#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
322- #[ derive( Clone , Debug , AsRef , Deref , From , Into , new) ]
330+ #[ derive( Clone , Debug , Eq , PartialEq , AsRef , Deref , From , Into , new) ]
323331pub struct BlindMessage ( pub Vec < u8 > ) ;
324332
325333/// A blind signature
326334#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
327- #[ derive( Clone , Debug , AsRef , Deref , From , Into , new) ]
335+ #[ derive( Clone , Debug , Eq , PartialEq , AsRef , Deref , From , Into , new) ]
328336pub struct BlindSignature ( pub Vec < u8 > ) ;
329337
330338/// A (non-blind) signature
331339#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
332- #[ derive( Clone , Debug , AsRef , Deref , From , Into , new) ]
340+ #[ derive( Clone , Debug , Eq , PartialEq , AsRef , Deref , From , Into , new) ]
333341pub struct Signature ( pub Vec < u8 > ) ;
334342
335343/// A message randomizer (noise added as a prefix to the message)
336344#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
337- #[ derive( Clone , Copy , Debug , AsRef , Deref , From , Into , new) ]
345+ #[ derive( Clone , Copy , Debug , Eq , PartialEq , AsRef , Deref , From , Into , new) ]
338346pub struct MessageRandomizer ( pub [ u8 ; 32 ] ) ;
339347
340348/// Result of a blinding operation
@@ -345,6 +353,16 @@ pub struct BlindingResult {
345353 pub msg_randomizer : Option < MessageRandomizer > ,
346354}
347355
356+ impl Eq for BlindingResult { }
357+
358+ impl PartialEq for BlindingResult {
359+ fn eq ( & self , other : & Self ) -> bool {
360+ self . blind_message == other. blind_message
361+ && self . secret == other. secret
362+ && self . msg_randomizer == other. msg_randomizer
363+ }
364+ }
365+
348366impl AsRef < [ u8 ] > for Secret {
349367 fn as_ref ( & self ) -> & [ u8 ] {
350368 self . 0 . as_slice ( )
@@ -529,7 +547,7 @@ fn emsa_pss_encode(
529547///
530548/// type BRsa = BlindRsa<Sha384, PSS, Randomized>;
531549/// ```
532- #[ derive( Clone , Copy , Debug , Default ) ]
550+ #[ derive( Clone , Copy , Debug , Default , Eq , PartialEq ) ]
533551pub struct BlindRsa < H : HashAlgorithm , S : SaltMode , M : MessagePrepare > {
534552 _phantom : PhantomData < ( H , S , M ) > ,
535553}
@@ -854,8 +872,18 @@ impl<H: HashAlgorithm, S: SaltMode, M: MessagePrepare> AsRef<RsaPrivateKey> for
854872 }
855873}
856874
875+ impl < H : HashAlgorithm , S : SaltMode , M : MessagePrepare > Eq for SecretKey < H , S , M > { }
876+
877+ impl < H : HashAlgorithm , S : SaltMode , M : MessagePrepare > PartialEq for SecretKey < H , S , M > {
878+ fn eq ( & self , other : & Self ) -> bool {
879+ // RsaPrivateKey currently uses BoxedUint internally, which implements
880+ // constant-time comparison when the moduli are the same.
881+ self . inner == other. inner
882+ }
883+ }
884+
857885/// An RSA key pair
858- #[ derive( Clone , Debug ) ]
886+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
859887pub struct KeyPair < H : HashAlgorithm , S : SaltMode , M : MessagePrepare > {
860888 pub pk : PublicKey < H , S , M > ,
861889 pub sk : SecretKey < H , S , M > ,
0 commit comments