@@ -152,9 +152,10 @@ impl ElligatorSwift {
152152 /// the x-only Elliptic Curve Diffie-Hellman (ECDH) shared secret between Alice and Bob.
153153 /// # Example
154154 /// ```
155- /// # #[cfg(feature = "alloc")] {
155+ /// # use secp256k1::ellswift::Party;
156+ /// #[cfg(feature = "alloc")] {
156157 /// use secp256k1::{
157- /// ellswift::{ElligatorSwift, ElligatorSwiftParty },
158+ /// ellswift::{ElligatorSwift},
158159 /// PublicKey, SecretKey, XOnlyPublicKey, Secp256k1,
159160 /// };
160161 /// use core::str::FromStr;
@@ -167,8 +168,8 @@ impl ElligatorSwift {
167168 /// let alice_es = ElligatorSwift::from_seckey(&secp, alice_sk, None);
168169 /// let bob_es = ElligatorSwift::from_seckey(&secp, bob_sk, None);
169170 ///
170- /// let alice_shared_secret = ElligatorSwift::shared_secret(alice_es, bob_es, alice_sk, ElligatorSwiftParty::A , None);
171- /// let bob_shared_secret = ElligatorSwift::shared_secret(alice_es, bob_es, bob_sk, ElligatorSwiftParty::B , None);
171+ /// let alice_shared_secret = ElligatorSwift::shared_secret(alice_es, bob_es, alice_sk, Party::Initiator , None);
172+ /// let bob_shared_secret = ElligatorSwift::shared_secret(alice_es, bob_es, bob_sk, Party::Responder , None);
172173 ///
173174 /// assert_eq!(alice_shared_secret, bob_shared_secret);
174175 /// # }
@@ -177,18 +178,19 @@ impl ElligatorSwift {
177178 ellswift_a : ElligatorSwift ,
178179 ellswift_b : ElligatorSwift ,
179180 secret_key : SecretKey ,
180- party : ElligatorSwiftParty ,
181+ party : impl Into < Party > ,
181182 data : Option < & [ u8 ] > ,
182183 ) -> ElligatorSwiftSharedSecret {
183184 let mut shared_secret = [ 0u8 ; 32 ] ;
185+ let p: Party = party. into ( ) ;
184186 unsafe {
185187 let ret = ffi:: secp256k1_ellswift_xdh (
186188 ffi:: secp256k1_context_no_precomp,
187189 shared_secret. as_mut_c_ptr ( ) ,
188190 ellswift_a. as_c_ptr ( ) ,
189191 ellswift_b. as_c_ptr ( ) ,
190192 secret_key. as_c_ptr ( ) ,
191- party . to_ffi_int ( ) ,
193+ p . to_ffi_int ( ) ,
192194 ffi:: secp256k1_ellswift_xdh_hash_function_bip324,
193195 data. as_c_ptr ( ) as * mut c_void ,
194196 ) ;
@@ -206,22 +208,23 @@ impl ElligatorSwift {
206208 ellswift_a : ElligatorSwift ,
207209 ellswift_b : ElligatorSwift ,
208210 secret_key : SecretKey ,
209- party : ElligatorSwiftParty ,
211+ party : impl Into < Party > ,
210212 mut hash_function : F ,
211213 ) -> ElligatorSwiftSharedSecret
212214 where
213215 F : FnMut ( [ u8 ; 32 ] , [ u8 ; 64 ] , [ u8 ; 64 ] ) -> ElligatorSwiftSharedSecret ,
214216 {
215217 let mut shared_secret = [ 0u8 ; 32 ] ;
216218 let hashfp = hash_callback :: < F > ;
219+ let p: Party = party. into ( ) ;
217220 unsafe {
218221 let ret = ffi:: secp256k1_ellswift_xdh (
219222 ffi:: secp256k1_context_no_precomp,
220223 shared_secret. as_mut_c_ptr ( ) ,
221224 ellswift_a. 0 . as_c_ptr ( ) ,
222225 ellswift_b. 0 . as_c_ptr ( ) ,
223226 secret_key. as_c_ptr ( ) ,
224- party . to_ffi_int ( ) ,
227+ p . to_ffi_int ( ) ,
225228 Some ( hashfp) ,
226229 & mut hash_function as * mut F as * mut c_void ,
227230 ) ;
@@ -291,23 +294,14 @@ impl ElligatorSwiftSharedSecret {
291294/// This distinction is important because the different parties compute different
292295/// hashes of the shared secret.
293296#[ derive( Copy , Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
297+ #[ deprecated( since = "0.30.0" , note = "Use `Party` instead." ) ]
294298pub enum ElligatorSwiftParty {
295299 /// We are the initiator of the ECDH
296300 A ,
297301 /// We are the responder of the ECDH
298302 B ,
299303}
300304
301-
302- impl ElligatorSwiftParty {
303- fn to_ffi_int ( self ) -> c_int {
304- match self {
305- ElligatorSwiftParty :: A => 0 ,
306- ElligatorSwiftParty :: B => 1 ,
307- }
308- }
309- }
310-
311305/// Represents the two parties in ECDH
312306#[ derive( Copy , Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
313307pub enum Party {
@@ -317,6 +311,7 @@ pub enum Party {
317311 Responder ,
318312}
319313
314+ #[ allow( deprecated) ]
320315impl From < ElligatorSwiftParty > for Party {
321316 fn from ( value : ElligatorSwiftParty ) -> Self {
322317 match value {
@@ -373,7 +368,7 @@ mod tests {
373368
374369 use crate :: ellswift:: ElligatorSwift ;
375370 #[ cfg( all( not( secp256k1_fuzz) , feature = "alloc" ) ) ]
376- use crate :: ellswift:: { ElligatorSwiftParty , ElligatorSwiftSharedSecret } ;
371+ use crate :: ellswift:: { ElligatorSwiftSharedSecret , Party } ;
377372 #[ cfg( all( not( secp256k1_fuzz) , feature = "alloc" ) ) ]
378373 use crate :: SecretKey ;
379374 use crate :: { from_hex, PublicKey , XOnlyPublicKey } ;
@@ -419,7 +414,7 @@ mod tests {
419414 ell,
420415 ell,
421416 SecretKey :: from_slice ( & priv32) . unwrap ( ) ,
422- ElligatorSwiftParty :: A ,
417+ Party :: Initiator ,
423418 |_, _, _| ElligatorSwiftSharedSecret ( [ 0xff ; 32 ] ) ,
424419 ) ;
425420 assert_eq ! ( pk, ElligatorSwiftSharedSecret ( [ 0xff ; 32 ] ) ) ;
@@ -634,7 +629,7 @@ mod tests {
634629 } ;
635630 let sec_key = SecretKey :: from_slice ( & my_secret) . unwrap ( ) ;
636631 let initiator =
637- if initiator == 0 { ElligatorSwiftParty :: B } else { ElligatorSwiftParty :: A } ;
632+ if initiator == 0 { Party :: Responder } else { Party :: Initiator } ;
638633
639634 let shared = ElligatorSwift :: shared_secret ( el_a, el_b, sec_key, initiator, None ) ;
640635
0 commit comments