@@ -154,7 +154,7 @@ impl ElligatorSwift {
154154 /// ```
155155 /// # #[cfg(feature = "alloc")] {
156156 /// use secp256k1::{
157- /// ellswift::{ElligatorSwift, ElligatorSwiftParty },
157+ /// ellswift::{ElligatorSwift, Party },
158158 /// PublicKey, SecretKey, XOnlyPublicKey, Secp256k1,
159159 /// };
160160 /// use core::str::FromStr;
@@ -167,8 +167,8 @@ impl ElligatorSwift {
167167 /// let alice_es = ElligatorSwift::from_seckey(&secp, alice_sk, None);
168168 /// let bob_es = ElligatorSwift::from_seckey(&secp, bob_sk, None);
169169 ///
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);
170+ /// let alice_shared_secret = ElligatorSwift::shared_secret(alice_es, bob_es, alice_sk, Party::Initiator , None);
171+ /// let bob_shared_secret = ElligatorSwift::shared_secret(alice_es, bob_es, bob_sk, Party::Responder , None);
172172 ///
173173 /// assert_eq!(alice_shared_secret, bob_shared_secret);
174174 /// # }
@@ -177,18 +177,19 @@ impl ElligatorSwift {
177177 ellswift_a : ElligatorSwift ,
178178 ellswift_b : ElligatorSwift ,
179179 secret_key : SecretKey ,
180- party : ElligatorSwiftParty ,
180+ party : impl Into < Party > ,
181181 data : Option < & [ u8 ] > ,
182182 ) -> ElligatorSwiftSharedSecret {
183183 let mut shared_secret = [ 0u8 ; 32 ] ;
184+ let p: Party = party. into ( ) ;
184185 unsafe {
185186 let ret = ffi:: secp256k1_ellswift_xdh (
186187 ffi:: secp256k1_context_no_precomp,
187188 shared_secret. as_mut_c_ptr ( ) ,
188189 ellswift_a. as_c_ptr ( ) ,
189190 ellswift_b. as_c_ptr ( ) ,
190191 secret_key. as_c_ptr ( ) ,
191- party . to_ffi_int ( ) ,
192+ p . to_ffi_int ( ) ,
192193 ffi:: secp256k1_ellswift_xdh_hash_function_bip324,
193194 data. as_c_ptr ( ) as * mut c_void ,
194195 ) ;
@@ -206,22 +207,23 @@ impl ElligatorSwift {
206207 ellswift_a : ElligatorSwift ,
207208 ellswift_b : ElligatorSwift ,
208209 secret_key : SecretKey ,
209- party : ElligatorSwiftParty ,
210+ party : impl Into < Party > ,
210211 mut hash_function : F ,
211212 ) -> ElligatorSwiftSharedSecret
212213 where
213214 F : FnMut ( [ u8 ; 32 ] , [ u8 ; 64 ] , [ u8 ; 64 ] ) -> ElligatorSwiftSharedSecret ,
214215 {
215216 let mut shared_secret = [ 0u8 ; 32 ] ;
216217 let hashfp = hash_callback :: < F > ;
218+ let p: Party = party. into ( ) ;
217219 unsafe {
218220 let ret = ffi:: secp256k1_ellswift_xdh (
219221 ffi:: secp256k1_context_no_precomp,
220222 shared_secret. as_mut_c_ptr ( ) ,
221223 ellswift_a. 0 . as_c_ptr ( ) ,
222224 ellswift_b. 0 . as_c_ptr ( ) ,
223225 secret_key. as_c_ptr ( ) ,
224- party . to_ffi_int ( ) ,
226+ p . to_ffi_int ( ) ,
225227 Some ( hashfp) ,
226228 & mut hash_function as * mut F as * mut c_void ,
227229 ) ;
@@ -291,22 +293,14 @@ impl ElligatorSwiftSharedSecret {
291293/// This distinction is important because the different parties compute different
292294/// hashes of the shared secret.
293295#[ derive( Copy , Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
296+ #[ deprecated( since = "0.30.0" , note = "Use `Party` instead." ) ]
294297pub enum ElligatorSwiftParty {
295298 /// We are the initiator of the ECDH
296299 A ,
297300 /// We are the responder of the ECDH
298301 B ,
299302}
300303
301- impl ElligatorSwiftParty {
302- fn to_ffi_int ( self ) -> c_int {
303- match self {
304- ElligatorSwiftParty :: A => 0 ,
305- ElligatorSwiftParty :: B => 1 ,
306- }
307- }
308- }
309-
310304/// Represents the two parties in ECDH
311305#[ derive( Copy , Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
312306pub enum Party {
@@ -316,6 +310,7 @@ pub enum Party {
316310 Responder ,
317311}
318312
313+ #[ allow( deprecated) ]
319314impl From < ElligatorSwiftParty > for Party {
320315 fn from ( value : ElligatorSwiftParty ) -> Self {
321316 match value {
@@ -372,7 +367,7 @@ mod tests {
372367
373368 use crate :: ellswift:: ElligatorSwift ;
374369 #[ cfg( all( not( secp256k1_fuzz) , feature = "alloc" ) ) ]
375- use crate :: ellswift:: { ElligatorSwiftParty , ElligatorSwiftSharedSecret } ;
370+ use crate :: ellswift:: { ElligatorSwiftSharedSecret , Party } ;
376371 #[ cfg( all( not( secp256k1_fuzz) , feature = "alloc" ) ) ]
377372 use crate :: SecretKey ;
378373 use crate :: { from_hex, PublicKey , XOnlyPublicKey } ;
@@ -418,7 +413,7 @@ mod tests {
418413 ell,
419414 ell,
420415 SecretKey :: from_slice ( & priv32) . unwrap ( ) ,
421- ElligatorSwiftParty :: A ,
416+ Party :: Initiator ,
422417 |_, _, _| ElligatorSwiftSharedSecret ( [ 0xff ; 32 ] ) ,
423418 ) ;
424419 assert_eq ! ( pk, ElligatorSwiftSharedSecret ( [ 0xff ; 32 ] ) ) ;
@@ -632,8 +627,7 @@ mod tests {
632627 )
633628 } ;
634629 let sec_key = SecretKey :: from_slice ( & my_secret) . unwrap ( ) ;
635- let initiator =
636- if initiator == 0 { ElligatorSwiftParty :: B } else { ElligatorSwiftParty :: A } ;
630+ let initiator = if initiator == 0 { Party :: Responder } else { Party :: Initiator } ;
637631
638632 let shared = ElligatorSwift :: shared_secret ( el_a, el_b, sec_key, initiator, None ) ;
639633
0 commit comments