Skip to content

Commit dc318d0

Browse files
committed
Use NodeSigner::ecdh to compute SharedSecrets
1 parent e2f66fb commit dc318d0

File tree

4 files changed

+81
-51
lines changed

4 files changed

+81
-51
lines changed

fuzz/src/peer_crypt.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// licenses.
99

1010
use lightning::ln::peer_channel_encryptor::PeerChannelEncryptor;
11+
use lightning::util::test_utils::TestNodeSigner;
1112

1213
use bitcoin::secp256k1::{Secp256k1, PublicKey, SecretKey};
1314

@@ -41,6 +42,7 @@ pub fn do_test(data: &[u8]) {
4142
Ok(key) => key,
4243
Err(_) => return,
4344
};
45+
let node_signer = TestNodeSigner::new(our_network_key);
4446
let ephemeral_key = match SecretKey::from_slice(get_slice!(32)) {
4547
Ok(key) => key,
4648
Err(_) => return,
@@ -53,15 +55,15 @@ pub fn do_test(data: &[u8]) {
5355
};
5456
let mut crypter = PeerChannelEncryptor::new_outbound(their_pubkey, ephemeral_key);
5557
crypter.get_act_one(&secp_ctx);
56-
match crypter.process_act_two(get_slice!(50), &our_network_key, &secp_ctx) {
58+
match crypter.process_act_two(get_slice!(50), &&node_signer) {
5759
Ok(_) => {},
5860
Err(_) => return,
5961
}
6062
assert!(crypter.is_ready_for_encryption());
6163
crypter
6264
} else {
63-
let mut crypter = PeerChannelEncryptor::new_inbound(&our_network_key, &secp_ctx);
64-
match crypter.process_act_one_with_keys(get_slice!(50), &our_network_key, ephemeral_key, &secp_ctx) {
65+
let mut crypter = PeerChannelEncryptor::new_inbound(&&node_signer);
66+
match crypter.process_act_one_with_keys(get_slice!(50), &&node_signer, ephemeral_key, &secp_ctx) {
6567
Ok(_) => {},
6668
Err(_) => return,
6769
}

lightning/src/ln/channelmanager.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use bitcoin::hash_types::{BlockHash, Txid};
3030

3131
use bitcoin::secp256k1::{SecretKey,PublicKey};
3232
use bitcoin::secp256k1::Secp256k1;
33-
use bitcoin::secp256k1::ecdh::SharedSecret;
3433
use bitcoin::{LockTime, secp256k1, Sequence};
3534

3635
use crate::chain;
@@ -2016,7 +2015,9 @@ where
20162015
return_malformed_err!("invalid ephemeral pubkey", 0x8000 | 0x4000 | 6);
20172016
}
20182017

2019-
let shared_secret = SharedSecret::new(&msg.onion_routing_packet.public_key.unwrap(), &self.our_network_key).secret_bytes();
2018+
let shared_secret = self.node_signer.ecdh(
2019+
Recipient::Node, &msg.onion_routing_packet.public_key.unwrap(), None
2020+
).unwrap().secret_bytes();
20202021

20212022
if msg.onion_routing_packet.version != 0 {
20222023
//TODO: Spec doesn't indicate if we should only hash hop_data here (and in other
@@ -2924,9 +2925,9 @@ where
29242925
}
29252926
}
29262927
if let PendingHTLCRouting::Forward { onion_packet, .. } = routing {
2927-
let phantom_secret_res = self.node_signer.get_node_secret(Recipient::PhantomNode);
2928-
if phantom_secret_res.is_ok() && fake_scid::is_valid_phantom(&self.fake_scid_rand_bytes, short_chan_id, &self.genesis_hash) {
2929-
let phantom_shared_secret = SharedSecret::new(&onion_packet.public_key.unwrap(), &phantom_secret_res.unwrap()).secret_bytes();
2928+
let phantom_pubkey_res = self.node_signer.get_node_id(Recipient::PhantomNode);
2929+
if phantom_pubkey_res.is_ok() && fake_scid::is_valid_phantom(&self.fake_scid_rand_bytes, short_chan_id, &self.genesis_hash) {
2930+
let phantom_shared_secret = self.node_signer.ecdh(Recipient::PhantomNode, &onion_packet.public_key.unwrap(), None).unwrap().secret_bytes();
29302931
let next_hop = match onion_utils::decode_next_payment_hop(phantom_shared_secret, &onion_packet.hop_data, onion_packet.hmac, payment_hash) {
29312932
Ok(res) => res,
29322933
Err(onion_utils::OnionDecodeErr::Malformed { err_msg, err_code }) => {

0 commit comments

Comments
 (0)