@@ -42,7 +42,7 @@ use core::str::FromStr;
4242use ffi:: CPtr ;
4343use secp256k1_sys:: types:: { c_int, c_uchar, c_void} ;
4444
45- use crate :: { constants, ffi, from_hex, Error , PublicKey , Secp256k1 , SecretKey , Verification } ;
45+ use crate :: { constants, ffi, from_hex, Error , PublicKey , Secp256k1 , SecretKey } ;
4646
4747unsafe extern "C" fn hash_callback < F > (
4848 output : * mut c_uchar ,
@@ -109,25 +109,26 @@ impl ElligatorSwift {
109109 /// # Example
110110 /// ```
111111 /// # #[cfg(feature = "alloc")] {
112- /// use secp256k1::{ellswift::ElligatorSwift, PublicKey, Secp256k1, SecretKey};
113- /// let secp = Secp256k1::new();
112+ /// use secp256k1::{ellswift::ElligatorSwift, PublicKey, SecretKey};
114113 /// let sk = SecretKey::from_secret_bytes([1; 32]).unwrap();
115- /// let es = ElligatorSwift::from_seckey(&secp, sk, None);
114+ /// let es = ElligatorSwift::from_seckey(sk, None);
116115 /// # }
117116 /// ```
118- pub fn from_seckey < C : Verification > (
119- secp : & Secp256k1 < C > ,
117+ pub fn from_seckey (
120118 sk : SecretKey ,
121119 aux_rand : Option < [ u8 ; 32 ] > ,
122120 ) -> ElligatorSwift {
123121 let mut es_out = [ 0u8 ; constants:: ELLSWIFT_ENCODING_SIZE ] ;
124122 let aux_rand_ptr = aux_rand. as_c_ptr ( ) ;
125123 unsafe {
126- let ret = ffi:: secp256k1_ellswift_create (
127- secp. ctx ( ) . as_ptr ( ) ,
128- es_out. as_mut_c_ptr ( ) ,
129- sk. as_c_ptr ( ) ,
130- aux_rand_ptr,
124+ let ret = crate :: with_global_context (
125+ |secp : & Secp256k1 < crate :: AllPreallocated > | ffi:: secp256k1_ellswift_create (
126+ secp. ctx ( ) . as_ptr ( ) ,
127+ es_out. as_mut_c_ptr ( ) ,
128+ sk. as_c_ptr ( ) ,
129+ aux_rand_ptr,
130+ ) ,
131+ Some ( & sk. to_secret_bytes ( ) ) ,
131132 ) ;
132133 debug_assert_eq ! ( ret, 1 ) ;
133134 }
@@ -154,17 +155,15 @@ impl ElligatorSwift {
154155 /// # #[cfg(feature = "alloc")] {
155156 /// use secp256k1::{
156157 /// ellswift::{ElligatorSwift, Party},
157- /// PublicKey, SecretKey, XOnlyPublicKey, Secp256k1,
158+ /// PublicKey, SecretKey, XOnlyPublicKey,
158159 /// };
159160 /// use core::str::FromStr;
160161 ///
161- /// let secp = Secp256k1::new();
162- ///
163162 /// let alice_sk = SecretKey::from_str("e714e76bdd67ad9f495683c37934148f4efc25ce3f01652c8a906498339e1f3a").unwrap();
164163 /// let bob_sk = SecretKey::from_str("b6c4b0e2f8c4359caf356a618cd1649d18790a1d67f7c2d1e4760e04c785db4f").unwrap();
165164 ///
166- /// let alice_es = ElligatorSwift::from_seckey(&secp, alice_sk, None);
167- /// let bob_es = ElligatorSwift::from_seckey(&secp, bob_sk, None);
165+ /// let alice_es = ElligatorSwift::from_seckey(alice_sk, None);
166+ /// let bob_es = ElligatorSwift::from_seckey(bob_sk, None);
168167 ///
169168 /// let alice_shared_secret = ElligatorSwift::shared_secret(alice_es, bob_es, alice_sk, Party::Initiator);
170169 /// let bob_shared_secret = ElligatorSwift::shared_secret(alice_es, bob_es, bob_sk, Party::Responder);
@@ -385,11 +384,10 @@ mod tests {
385384 #[ cfg( all( not( secp256k1_fuzz) , feature = "alloc" ) ) ]
386385 fn test_create_elligator_swift_create_rtt ( ) {
387386 // Test that we can round trip an ElligatorSwift created from a secret key
388- let secp = crate :: Secp256k1 :: new ( ) ;
389387 let rand32 = [ 1u8 ; 32 ] ;
390388 let priv32 = [ 1u8 ; 32 ] ;
391389 let ell =
392- ElligatorSwift :: from_seckey ( & secp , SecretKey :: from_secret_bytes ( rand32) . unwrap ( ) , None ) ;
390+ ElligatorSwift :: from_seckey ( SecretKey :: from_secret_bytes ( rand32) . unwrap ( ) , None ) ;
393391 let pk = PublicKey :: from_ellswift ( ell) ;
394392 let expected =
395393 PublicKey :: from_secret_key ( & SecretKey :: from_secret_bytes ( priv32) . unwrap ( ) ) ;
@@ -400,11 +398,9 @@ mod tests {
400398 #[ cfg( all( not( secp256k1_fuzz) , feature = "alloc" ) ) ]
401399 fn test_xdh_with_custom_hasher ( ) {
402400 // Test the ECDH with a custom hash function
403- let secp = crate :: Secp256k1 :: new ( ) ;
404401 let rand32 = [ 1u8 ; 32 ] ;
405402 let priv32 = [ 2u8 ; 32 ] ;
406403 let ell = ElligatorSwift :: from_seckey (
407- & secp,
408404 SecretKey :: from_secret_bytes ( rand32) . unwrap ( ) ,
409405 Some ( rand32) ,
410406 ) ;
0 commit comments