Skip to content

Commit 26b0a87

Browse files
committed
ecdh: remove use of hashes in example code and tests
We have a curious test where we confirm that we can match upstream's code with direct calls to sha256. This is nice, but completely unnecessary as a unit test. Secondly, we have example code where we demonstrate how to use bitcoin_hashes to write a custom ECDH nonce function. This is valuable, but not reason by itself to have an extra dependency, so we stick `ignore` on it to prevent the Rust compiler from attempting to compile it.
1 parent 748327a commit 26b0a87

File tree

1 file changed

+3
-31
lines changed

1 file changed

+3
-31
lines changed

src/ecdh.rs

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,9 @@ impl AsRef<[u8]> for SharedSecret {
110110
/// 64 bytes representing the (x,y) co-ordinates of a point on the curve (32 bytes each).
111111
///
112112
/// # Examples
113-
/// ```
114-
/// # #[cfg(all(feature = "hashes", feature = "rand", feature = "std"))] {
115-
/// # use secp256k1::{ecdh, rand, Secp256k1, PublicKey, SecretKey};
116-
/// # use secp256k1::hashes::{Hash, sha512};
113+
/// ```ignore
114+
/// use bitcoin_hashes::{Hash, sha512};
115+
/// use secp256k1::{ecdh, rand, Secp256k1, PublicKey, SecretKey};
117116
///
118117
/// let s = Secp256k1::new();
119118
/// let (sk1, pk1) = s.generate_keypair(&mut rand::rng());
@@ -124,7 +123,6 @@ impl AsRef<[u8]> for SharedSecret {
124123
/// let point2 = ecdh::shared_secret_point(&pk1, &sk2);
125124
/// let secret2 = sha512::Hash::hash(&point2);
126125
/// assert_eq!(secret1, secret2)
127-
/// # }
128126
/// ```
129127
pub fn shared_secret_point(point: &PublicKey, scalar: &SecretKey) -> [u8; 64] {
130128
let mut xy = [0u8; 64];
@@ -224,32 +222,6 @@ mod tests {
224222
assert_eq!(y, new_y);
225223
}
226224

227-
#[test]
228-
#[cfg(not(secp256k1_fuzz))]
229-
#[cfg(all(feature = "hashes", feature = "rand", feature = "std"))]
230-
fn hashes_and_sys_generate_same_secret() {
231-
use hashes::{sha256, Hash, HashEngine};
232-
233-
use crate::ecdh::shared_secret_point;
234-
235-
let s = Secp256k1::signing_only();
236-
let (sk1, _) = s.generate_keypair(&mut rand::rng());
237-
let (_, pk2) = s.generate_keypair(&mut rand::rng());
238-
239-
let secret_sys = SharedSecret::new(&pk2, &sk1);
240-
241-
let xy = shared_secret_point(&pk2, &sk1);
242-
243-
// Mimics logic in `bitcoin-core/secp256k1/src/module/main_impl.h`
244-
let version = (xy[63] & 0x01) | 0x02;
245-
let mut engine = sha256::HashEngine::default();
246-
engine.input(&[version]);
247-
engine.input(&xy.as_ref()[..32]);
248-
let secret_bh = sha256::Hash::from_engine(engine);
249-
250-
assert_eq!(secret_bh.as_byte_array(), secret_sys.as_ref());
251-
}
252-
253225
#[test]
254226
#[cfg(all(feature = "serde", feature = "alloc"))]
255227
fn serde() {

0 commit comments

Comments
 (0)