@@ -90,7 +90,7 @@ mod tests {
9090 use bc_rand:: make_fake_random_number_generator;
9191 #[ cfg( any( feature = "secp256k1" , feature = "pqcrypto" ) ) ]
9292 use dcbor:: prelude:: * ;
93- #[ cfg( any( feature = "secp256k1" , feature = "ed25519" ) ) ]
93+ #[ cfg( any( feature = "secp256k1" , feature = "ed25519" , feature = "sr25519" ) ) ]
9494 use hex_literal:: hex;
9595 #[ cfg( feature = "secp256k1" ) ]
9696 use indoc:: indoc;
@@ -100,6 +100,7 @@ mod tests {
100100 #[ cfg( any(
101101 feature = "secp256k1" ,
102102 feature = "ed25519" ,
103+ feature = "sr25519" ,
103104 feature = "ssh"
104105 ) ) ]
105106 use super :: SignatureScheme ;
@@ -110,17 +111,22 @@ mod tests {
110111 #[ cfg( any(
111112 feature = "secp256k1" ,
112113 feature = "ed25519" ,
114+ feature = "sr25519" ,
113115 feature = "ssh"
114116 ) ) ]
115117 use crate :: SigningOptions ;
116118 #[ cfg( all( feature = "secp256k1" , not( feature = "ed25519" ) ) ) ]
117119 use crate :: SigningPrivateKey ;
118120 #[ cfg( feature = "ed25519" ) ]
119- use crate :: { Ed25519PrivateKey , Signer , SigningPrivateKey , Verifier } ;
121+ use crate :: Ed25519PrivateKey ;
122+ #[ cfg( feature = "sr25519" ) ]
123+ use crate :: Sr25519PrivateKey ;
124+ #[ cfg( any( feature = "ed25519" , feature = "sr25519" ) ) ]
125+ use crate :: { Signer , SigningPrivateKey , Verifier } ;
120126 #[ cfg( feature = "pqcrypto" ) ]
121127 use crate :: { MLDSA , MLDSASignature } ;
122128 #[ cfg( all(
123- not( feature = "ed25519" ) ,
129+ not( any ( feature = "ed25519" , feature = "sr25519" ) ) ,
124130 any( feature = "secp256k1" , feature = "ssh" )
125131 ) ) ]
126132 use crate :: { Signer , Verifier } ;
@@ -142,9 +148,17 @@ mod tests {
142148 "322b5c1dd5a17c3481c2297990c85c232ed3c17b52ce9905c6ec5193ad132c36"
143149 ) ) ) ;
144150
151+ #[ cfg( feature = "sr25519" ) ]
152+ fn sr25519_signing_private_key ( ) -> SigningPrivateKey {
153+ SigningPrivateKey :: new_sr25519 ( Sr25519PrivateKey :: from_seed ( hex ! (
154+ "322b5c1dd5a17c3481c2297990c85c232ed3c17b52ce9905c6ec5193ad132c36"
155+ ) ) )
156+ }
157+
145158 #[ cfg( any(
146159 feature = "secp256k1" ,
147160 feature = "ed25519" ,
161+ feature = "sr25519" ,
148162 feature = "pqcrypto" ,
149163 feature = "ssh"
150164 ) ) ]
@@ -242,6 +256,22 @@ mod tests {
242256 assert ! ( public_key. verify( & another_signature, MESSAGE ) ) ;
243257 }
244258
259+ #[ test]
260+ #[ cfg( feature = "sr25519" ) ]
261+ fn test_sr25519_signing ( ) {
262+ let private_key = sr25519_signing_private_key ( ) ;
263+ let public_key = private_key. public_key ( ) . unwrap ( ) ;
264+ let signature = private_key. sign ( MESSAGE ) . unwrap ( ) ;
265+
266+ assert ! ( public_key. verify( & signature, MESSAGE ) ) ;
267+ assert ! ( !public_key. verify( & signature, b"Wolf Mcnally" ) ) ;
268+
269+ // SR25519 signatures include randomness, so they differ each time
270+ let another_signature = private_key. sign ( MESSAGE ) . unwrap ( ) ;
271+ assert_ne ! ( signature, another_signature) ;
272+ assert ! ( public_key. verify( & another_signature, MESSAGE ) ) ;
273+ }
274+
245275 #[ test]
246276 #[ cfg( feature = "pqcrypto" ) ]
247277 fn test_mldsa_signing ( ) {
@@ -268,7 +298,7 @@ mod tests {
268298 assert_eq ! ( signature, received_signature) ;
269299 }
270300
271- #[ cfg( any( feature = "secp256k1" , feature = "ed25519" , feature = "ssh" ) ) ]
301+ #[ cfg( any( feature = "secp256k1" , feature = "ed25519" , feature = "sr25519" , feature = " ssh") ) ]
272302 fn test_keypair_signing (
273303 scheme : SignatureScheme ,
274304 options : Option < SigningOptions > ,
@@ -297,10 +327,16 @@ mod tests {
297327 test_keypair_signing ( SignatureScheme :: Ed25519 , None ) ;
298328 }
299329
330+ #[ test]
331+ #[ cfg( feature = "sr25519" ) ]
332+ fn test_sr25519_keypair ( ) {
333+ test_keypair_signing ( SignatureScheme :: Sr25519 , None ) ;
334+ }
335+
300336 #[ test]
301337 #[ cfg( all(
302338 feature = "pqcrypto" ,
303- any( feature = "secp256k1" , feature = "ed25519" )
339+ any( feature = "secp256k1" , feature = "ed25519" , feature = "sr25519" )
304340 ) ) ]
305341 fn test_mldsa44_keypair ( ) {
306342 test_keypair_signing ( SignatureScheme :: MLDSA44 , None ) ;
@@ -309,7 +345,7 @@ mod tests {
309345 #[ test]
310346 #[ cfg( all(
311347 feature = "pqcrypto" ,
312- any( feature = "secp256k1" , feature = "ed25519" )
348+ any( feature = "secp256k1" , feature = "ed25519" , feature = "sr25519" )
313349 ) ) ]
314350 fn test_mldsa65_keypair ( ) {
315351 test_keypair_signing ( SignatureScheme :: MLDSA65 , None ) ;
@@ -318,7 +354,7 @@ mod tests {
318354 #[ test]
319355 #[ cfg( all(
320356 feature = "pqcrypto" ,
321- any( feature = "secp256k1" , feature = "ed25519" )
357+ any( feature = "secp256k1" , feature = "ed25519" , feature = "sr25519" )
322358 ) ) ]
323359 fn test_mldsa87_keypair ( ) {
324360 test_keypair_signing ( SignatureScheme :: MLDSA87 , None ) ;
0 commit comments