@@ -153,7 +153,7 @@ impl ElligatorSwift {
153
153
/// ```
154
154
/// # #[cfg(feature = "alloc")] {
155
155
/// use secp256k1::{
156
- /// ellswift::{ElligatorSwift, ElligatorSwiftParty },
156
+ /// ellswift::{ElligatorSwift, Party },
157
157
/// PublicKey, SecretKey, XOnlyPublicKey, Secp256k1,
158
158
/// };
159
159
/// use core::str::FromStr;
@@ -166,8 +166,8 @@ impl ElligatorSwift {
166
166
/// let alice_es = ElligatorSwift::from_seckey(&secp, alice_sk, None);
167
167
/// let bob_es = ElligatorSwift::from_seckey(&secp, bob_sk, None);
168
168
///
169
- /// let alice_shared_secret = ElligatorSwift::shared_secret(alice_es, bob_es, alice_sk, ElligatorSwiftParty::A , None);
170
- /// let bob_shared_secret = ElligatorSwift::shared_secret(alice_es, bob_es, bob_sk, ElligatorSwiftParty::B , None);
169
+ /// let alice_shared_secret = ElligatorSwift::shared_secret(alice_es, bob_es, alice_sk, Party::Initiator , None);
170
+ /// let bob_shared_secret = ElligatorSwift::shared_secret(alice_es, bob_es, bob_sk, Party::Responder , None);
171
171
///
172
172
/// assert_eq!(alice_shared_secret, bob_shared_secret);
173
173
/// # }
@@ -176,18 +176,19 @@ impl ElligatorSwift {
176
176
ellswift_a : ElligatorSwift ,
177
177
ellswift_b : ElligatorSwift ,
178
178
secret_key : SecretKey ,
179
- party : ElligatorSwiftParty ,
179
+ party : impl Into < Party > ,
180
180
data : Option < & [ u8 ] > ,
181
181
) -> ElligatorSwiftSharedSecret {
182
182
let mut shared_secret = [ 0u8 ; 32 ] ;
183
+ let p: Party = party. into ( ) ;
183
184
unsafe {
184
185
let ret = ffi:: secp256k1_ellswift_xdh (
185
186
ffi:: secp256k1_context_no_precomp,
186
187
shared_secret. as_mut_c_ptr ( ) ,
187
188
ellswift_a. as_c_ptr ( ) ,
188
189
ellswift_b. as_c_ptr ( ) ,
189
190
secret_key. as_c_ptr ( ) ,
190
- party . to_ffi_int ( ) ,
191
+ p . to_ffi_int ( ) ,
191
192
ffi:: secp256k1_ellswift_xdh_hash_function_bip324,
192
193
data. as_c_ptr ( ) as * mut c_void ,
193
194
) ;
@@ -205,22 +206,23 @@ impl ElligatorSwift {
205
206
ellswift_a : ElligatorSwift ,
206
207
ellswift_b : ElligatorSwift ,
207
208
secret_key : SecretKey ,
208
- party : ElligatorSwiftParty ,
209
+ party : impl Into < Party > ,
209
210
mut hash_function : F ,
210
211
) -> ElligatorSwiftSharedSecret
211
212
where
212
213
F : FnMut ( [ u8 ; 32 ] , [ u8 ; 64 ] , [ u8 ; 64 ] ) -> ElligatorSwiftSharedSecret ,
213
214
{
214
215
let mut shared_secret = [ 0u8 ; 32 ] ;
215
216
let hashfp = hash_callback :: < F > ;
217
+ let p: Party = party. into ( ) ;
216
218
unsafe {
217
219
let ret = ffi:: secp256k1_ellswift_xdh (
218
220
ffi:: secp256k1_context_no_precomp,
219
221
shared_secret. as_mut_c_ptr ( ) ,
220
222
ellswift_a. 0 . as_c_ptr ( ) ,
221
223
ellswift_b. 0 . as_c_ptr ( ) ,
222
224
secret_key. as_c_ptr ( ) ,
223
- party . to_ffi_int ( ) ,
225
+ p . to_ffi_int ( ) ,
224
226
Some ( hashfp) ,
225
227
& mut hash_function as * mut F as * mut c_void ,
226
228
) ;
@@ -285,18 +287,38 @@ impl ElligatorSwiftSharedSecret {
285
287
/// we are. In this context, "we" means the party that is using this library, and possesses the
286
288
/// secret key passed to `ElligatorSwift::shared_secret`.
287
289
#[ derive( Copy , Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
290
+ #[ deprecated( since = "0.29.2" , note = "Use `Party` instead." ) ]
288
291
pub enum ElligatorSwiftParty {
289
292
/// We are the initiator of the ECDH
290
293
A ,
291
294
/// We are the responder of the ECDH
292
295
B ,
293
296
}
294
297
295
- impl ElligatorSwiftParty {
298
+ /// Represents the two parties in ECDH
299
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
300
+ pub enum Party {
301
+ /// The party that starts the key exchange or communication process
302
+ Initiator ,
303
+ /// The party that responds to the initiator's communications
304
+ Responder ,
305
+ }
306
+
307
+ #[ allow( deprecated) ]
308
+ impl From < ElligatorSwiftParty > for Party {
309
+ fn from ( value : ElligatorSwiftParty ) -> Self {
310
+ match value {
311
+ ElligatorSwiftParty :: A => Party :: Initiator ,
312
+ ElligatorSwiftParty :: B => Party :: Responder ,
313
+ }
314
+ }
315
+ }
316
+
317
+ impl Party {
296
318
fn to_ffi_int ( self ) -> c_int {
297
319
match self {
298
- ElligatorSwiftParty :: A => 0 ,
299
- ElligatorSwiftParty :: B => 1 ,
320
+ Party :: Initiator => 0 ,
321
+ Party :: Responder => 1 ,
300
322
}
301
323
}
302
324
}
@@ -339,7 +361,7 @@ mod tests {
339
361
340
362
use crate :: ellswift:: ElligatorSwift ;
341
363
#[ cfg( all( not( secp256k1_fuzz) , feature = "alloc" ) ) ]
342
- use crate :: ellswift:: { ElligatorSwiftParty , ElligatorSwiftSharedSecret } ;
364
+ use crate :: ellswift:: { ElligatorSwiftSharedSecret , Party } ;
343
365
#[ cfg( all( not( secp256k1_fuzz) , feature = "alloc" ) ) ]
344
366
use crate :: SecretKey ;
345
367
use crate :: { from_hex, PublicKey , XOnlyPublicKey } ;
@@ -385,7 +407,7 @@ mod tests {
385
407
ell,
386
408
ell,
387
409
SecretKey :: from_slice ( & priv32) . unwrap ( ) ,
388
- ElligatorSwiftParty :: A ,
410
+ Party :: Initiator ,
389
411
|_, _, _| ElligatorSwiftSharedSecret ( [ 0xff ; 32 ] ) ,
390
412
) ;
391
413
assert_eq ! ( pk, ElligatorSwiftSharedSecret ( [ 0xff ; 32 ] ) ) ;
@@ -599,8 +621,7 @@ mod tests {
599
621
)
600
622
} ;
601
623
let sec_key = SecretKey :: from_slice ( & my_secret) . unwrap ( ) ;
602
- let initiator =
603
- if initiator == 0 { ElligatorSwiftParty :: B } else { ElligatorSwiftParty :: A } ;
624
+ let initiator = if initiator == 0 { Party :: Responder } else { Party :: Initiator } ;
604
625
605
626
let shared = ElligatorSwift :: shared_secret ( el_a, el_b, sec_key, initiator, None ) ;
606
627
0 commit comments