Skip to content

Commit 14a4740

Browse files
committed
Add an ExpandedKey key for phantom blinded path authentication
In the coming commits we'll add support for building a blinded path which can be received to any one of several nodes in a "phantom" configuration (terminology we retain from BOLT 11 though there are no longer any phantom nodes in the paths). Here we adda new key in `ExpandedKey` which we can use to authenticate blinded paths as coming from a phantom node participant.
1 parent e245c0a commit 14a4740

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

lightning/src/crypto/utils.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ macro_rules! hkdf_extract_expand {
2222
let (k1, k2, _) = hkdf_extract_expand!($salt, $ikm);
2323
(k1, k2)
2424
}};
25-
($salt: expr, $ikm: expr, 6) => {{
25+
($salt: expr, $ikm: expr, 7) => {{
2626
let (k1, k2, prk) = hkdf_extract_expand!($salt, $ikm);
2727

2828
let mut hmac = HmacEngine::<Sha256>::new(&prk[..]);
@@ -45,18 +45,23 @@ macro_rules! hkdf_extract_expand {
4545
hmac.input(&[6; 1]);
4646
let k6 = Hmac::from_engine(hmac).to_byte_array();
4747

48-
(k1, k2, k3, k4, k5, k6)
48+
let mut hmac = HmacEngine::<Sha256>::new(&prk[..]);
49+
hmac.input(&k6);
50+
hmac.input(&[7; 1]);
51+
let k7 = Hmac::from_engine(hmac).to_byte_array();
52+
53+
(k1, k2, k3, k4, k5, k6, k7)
4954
}};
5055
}
5156

5257
pub fn hkdf_extract_expand_twice(salt: &[u8], ikm: &[u8]) -> ([u8; 32], [u8; 32]) {
5358
hkdf_extract_expand!(salt, ikm, 2)
5459
}
5560

56-
pub fn hkdf_extract_expand_6x(
61+
pub fn hkdf_extract_expand_7x(
5762
salt: &[u8], ikm: &[u8],
58-
) -> ([u8; 32], [u8; 32], [u8; 32], [u8; 32], [u8; 32], [u8; 32]) {
59-
hkdf_extract_expand!(salt, ikm, 6)
63+
) -> ([u8; 32], [u8; 32], [u8; 32], [u8; 32], [u8; 32], [u8; 32], [u8; 32]) {
64+
hkdf_extract_expand!(salt, ikm, 7)
6065
}
6166

6267
#[inline]

lightning/src/ln/inbound_payment.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
1515
use bitcoin::hashes::{Hash, HashEngine};
1616

1717
use crate::crypto::chacha20::ChaCha20;
18-
use crate::crypto::utils::hkdf_extract_expand_6x;
18+
use crate::crypto::utils::hkdf_extract_expand_7x;
1919
use crate::ln::msgs;
2020
use crate::ln::msgs::MAX_VALUE_MSAT;
2121
use crate::offers::nonce::Nonce;
@@ -56,6 +56,10 @@ pub struct ExpandedKey {
5656
/// The key used to authenticate spontaneous payments' metadata as previously registered with LDK
5757
/// for inclusion in a blinded path.
5858
spontaneous_pmt_key: [u8; 32],
59+
/// The key used to authenticate phantom-node-shared blinded paths as generated by us. Note
60+
/// that this is not used for blinded paths that are not expected to be shared across nodes
61+
/// participating in a "phantom node".
62+
pub(crate) phantom_node_blinded_path_key: [u8; 32],
5963
}
6064

6165
impl ExpandedKey {
@@ -70,14 +74,16 @@ impl ExpandedKey {
7074
offers_base_key,
7175
offers_encryption_key,
7276
spontaneous_pmt_key,
73-
) = hkdf_extract_expand_6x(b"LDK Inbound Payment Key Expansion", &key_material);
77+
phantom_node_blinded_path_key,
78+
) = hkdf_extract_expand_7x(b"LDK Inbound Payment Key Expansion", &key_material);
7479
Self {
7580
metadata_key,
7681
ldk_pmt_hash_key,
7782
user_pmt_hash_key,
7883
offers_base_key,
7984
offers_encryption_key,
8085
spontaneous_pmt_key,
86+
phantom_node_blinded_path_key,
8187
}
8288
}
8389

0 commit comments

Comments
 (0)