Skip to content

Commit 44bcb89

Browse files
committed
ellswift: remove unused data argument from shared_secret
We take an optional `data` argument to `shared_secret`, but the upstream function we call never uses it. However, this argument *does* use the CPtr impl on &[T] in order to obtain a pointer to pass across the FFI boundary. This impl is very dangerous, and its use here is sound only because the resulting pointer is never used. See rust-bitcoin#627 (comment)
1 parent 2139aff commit 44bcb89

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/ellswift.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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, Party::Initiator, None);
171-
/// let bob_shared_secret = ElligatorSwift::shared_secret(alice_es, bob_es, bob_sk, Party::Responder, None);
170+
/// let alice_shared_secret = ElligatorSwift::shared_secret(alice_es, bob_es, alice_sk, Party::Initiator);
171+
/// let bob_shared_secret = ElligatorSwift::shared_secret(alice_es, bob_es, bob_sk, Party::Responder);
172172
///
173173
/// assert_eq!(alice_shared_secret, bob_shared_secret);
174174
/// # }
@@ -178,7 +178,6 @@ impl ElligatorSwift {
178178
ellswift_b: ElligatorSwift,
179179
secret_key: SecretKey,
180180
party: impl Into<Party>,
181-
data: Option<&[u8]>,
182181
) -> ElligatorSwiftSharedSecret {
183182
let mut shared_secret = [0u8; 32];
184183
let p: Party = party.into();
@@ -191,7 +190,7 @@ impl ElligatorSwift {
191190
secret_key.as_c_ptr(),
192191
p.to_ffi_int(),
193192
ffi::secp256k1_ellswift_xdh_hash_function_bip324,
194-
data.as_c_ptr() as *mut c_void,
193+
ptr::null_mut(),
195194
);
196195
debug_assert_eq!(ret, 1);
197196
}
@@ -631,7 +630,7 @@ mod tests {
631630
let sec_key = SecretKey::from_byte_array(my_secret).unwrap();
632631
let initiator = if initiator == 0 { Party::Responder } else { Party::Initiator };
633632

634-
let shared = ElligatorSwift::shared_secret(el_a, el_b, sec_key, initiator, None);
633+
let shared = ElligatorSwift::shared_secret(el_a, el_b, sec_key, initiator);
635634

636635
assert_eq!(shared.0, shared_secret);
637636
}

0 commit comments

Comments
 (0)