Skip to content

Commit 11166aa

Browse files
committed
Modify ecdh to take Scalar
1 parent 7e05623 commit 11166aa

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ impl KeysInterface for KeyProvider {
168168
Ok(SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, self.node_id]).unwrap())
169169
}
170170

171-
fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&[u8; 32]>) -> Result<SharedSecret, ()> {
171+
fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&Scalar>) -> Result<SharedSecret, ()> {
172172
let mut node_secret = self.get_node_secret(recipient)?;
173173
if let Some(tweak) = tweak {
174-
node_secret = node_secret.mul_tweak(&Scalar::from_be_bytes(*tweak).unwrap()).unwrap();
174+
node_secret = node_secret.mul_tweak(tweak).unwrap();
175175
}
176176
Ok(SharedSecret::new(other_key, &node_secret))
177177
}

fuzz/src/full_stack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,10 @@ impl KeysInterface for KeyProvider {
272272
Ok(self.node_secret.clone())
273273
}
274274

275-
fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&[u8; 32]>) -> Result<SharedSecret, ()> {
275+
fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&Scalar>) -> Result<SharedSecret, ()> {
276276
let mut node_secret = self.get_node_secret(recipient)?;
277277
if let Some(tweak) = tweak {
278-
node_secret = node_secret.mul_tweak(&Scalar::from_be_bytes(*tweak).unwrap()).unwrap();
278+
node_secret = node_secret.mul_tweak(tweak).unwrap();
279279
}
280280
Ok(SharedSecret::new(other_key, &node_secret))
281281
}

lightning/src/chain/keysinterface.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ pub trait KeysInterface {
410410
/// secret, though this is less efficient.
411411
///
412412
/// [`node secret`]: Self::get_node_secret
413-
fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&[u8; 32]>) -> Result<SharedSecret, ()>;
413+
fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&Scalar>) -> Result<SharedSecret, ()>;
414414
/// Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
415415
///
416416
/// This method should return a different value each time it is called, to avoid linking
@@ -1140,10 +1140,10 @@ impl KeysInterface for KeysManager {
11401140
}
11411141
}
11421142

1143-
fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&[u8; 32]>) -> Result<SharedSecret, ()> {
1143+
fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&Scalar>) -> Result<SharedSecret, ()> {
11441144
let mut node_secret = self.get_node_secret(recipient)?;
11451145
if let Some(tweak) = tweak {
1146-
node_secret = node_secret.mul_tweak(&Scalar::from_be_bytes(*tweak).unwrap()).map_err(|_| ())?;
1146+
node_secret = node_secret.mul_tweak(tweak).map_err(|_| ())?;
11471147
}
11481148
Ok(SharedSecret::new(other_key, &node_secret))
11491149
}
@@ -1232,10 +1232,10 @@ impl KeysInterface for PhantomKeysManager {
12321232
}
12331233
}
12341234

1235-
fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&[u8; 32]>) -> Result<SharedSecret, ()> {
1235+
fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&Scalar>) -> Result<SharedSecret, ()> {
12361236
let mut node_secret = self.get_node_secret(recipient)?;
12371237
if let Some(tweak) = tweak {
1238-
node_secret = node_secret.mul_tweak(&Scalar::from_be_bytes(*tweak).unwrap()).map_err(|_| ())?;
1238+
node_secret = node_secret.mul_tweak(tweak).map_err(|_| ())?;
12391239
}
12401240
Ok(SharedSecret::new(other_key, &node_secret))
12411241
}

lightning/src/ln/channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6603,7 +6603,7 @@ mod tests {
66036603
use util::errors::APIError;
66046604
use util::test_utils;
66056605
use util::test_utils::OnGetShutdownScriptpubkey;
6606-
use bitcoin::secp256k1::{Secp256k1, ecdsa::Signature};
6606+
use bitcoin::secp256k1::{Secp256k1, ecdsa::Signature, Scalar};
66076607
use bitcoin::secp256k1::ffi::Signature as FFISignature;
66086608
use bitcoin::secp256k1::{SecretKey,PublicKey};
66096609
use bitcoin::secp256k1::ecdh::SharedSecret;
@@ -6648,7 +6648,7 @@ mod tests {
66486648
type Signer = InMemorySigner;
66496649

66506650
fn get_node_secret(&self, _recipient: Recipient) -> Result<SecretKey, ()> { panic!(); }
6651-
fn ecdh(&self, _recipient: Recipient, _other_key: &PublicKey, _tweak: Option<&[u8; 32]>) -> Result<SharedSecret, ()> { panic!(); }
6651+
fn ecdh(&self, _recipient: Recipient, _other_key: &PublicKey, _tweak: Option<&Scalar>) -> Result<SharedSecret, ()> { panic!(); }
66526652
fn get_inbound_payment_key_material(&self) -> KeyMaterial { panic!(); }
66536653
fn get_destination_script(&self) -> Script {
66546654
let secp_ctx = Secp256k1::signing_only();

lightning/src/onion_message/messenger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl<Signer: Sign, K: Deref, L: Deref> OnionMessenger<Signer, K, L>
196196
Hmac::from_engine(hmac).into_inner()
197197
};
198198
match self.keys_manager.ecdh(Recipient::Node, &msg.onion_routing_packet.public_key,
199-
Some(&blinding_factor))
199+
Some(&Scalar::from_be_bytes(blinding_factor).unwrap()))
200200
{
201201
Ok(ss) => ss.secret_bytes(),
202202
Err(()) => {

lightning/src/util/test_utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use bitcoin::blockdata::block::Block;
3434
use bitcoin::network::constants::Network;
3535
use bitcoin::hash_types::{BlockHash, Txid};
3636

37-
use bitcoin::secp256k1::{SecretKey, PublicKey, Secp256k1, ecdsa::Signature};
37+
use bitcoin::secp256k1::{SecretKey, PublicKey, Secp256k1, ecdsa::Signature, Scalar};
3838
use bitcoin::secp256k1::ecdh::SharedSecret;
3939
use bitcoin::secp256k1::ecdsa::RecoverableSignature;
4040

@@ -75,7 +75,7 @@ impl keysinterface::KeysInterface for OnlyReadsKeysInterface {
7575
type Signer = EnforcingSigner;
7676

7777
fn get_node_secret(&self, _recipient: Recipient) -> Result<SecretKey, ()> { unreachable!(); }
78-
fn ecdh(&self, _recipient: Recipient, _other_key: &PublicKey, _tweak: Option<&[u8; 32]>) -> Result<SharedSecret, ()> { unreachable!(); }
78+
fn ecdh(&self, _recipient: Recipient, _other_key: &PublicKey, _tweak: Option<&Scalar>) -> Result<SharedSecret, ()> { unreachable!(); }
7979
fn get_inbound_payment_key_material(&self) -> KeyMaterial { unreachable!(); }
8080
fn get_destination_script(&self) -> Script { unreachable!(); }
8181
fn get_shutdown_scriptpubkey(&self) -> ShutdownScript { unreachable!(); }
@@ -602,7 +602,7 @@ impl keysinterface::KeysInterface for TestKeysInterface {
602602
fn get_node_secret(&self, recipient: Recipient) -> Result<SecretKey, ()> {
603603
self.backing.get_node_secret(recipient)
604604
}
605-
fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&[u8; 32]>) -> Result<SharedSecret, ()> {
605+
fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&Scalar>) -> Result<SharedSecret, ()> {
606606
self.backing.ecdh(recipient, other_key, tweak)
607607
}
608608
fn get_inbound_payment_key_material(&self) -> keysinterface::KeyMaterial {

0 commit comments

Comments
 (0)