Skip to content

Commit ecce268

Browse files
authored
Merge pull request #3941 from TheBlueMatt/2025-07-3917-followups
Various followups to #3917
2 parents 00c4059 + 8ee02eb commit ecce268

File tree

4 files changed

+19
-21
lines changed

4 files changed

+19
-21
lines changed

lightning/src/blinded_path/message.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -543,27 +543,20 @@ impl_writeable_tlv_based_enum!(MessageContext,
543543
{3, DNSResolver} => (),
544544
);
545545

546-
// NOTE:
547-
// Several TLV fields (`nonce`, `hmac`, etc.) were removed in LDK v0.2
548-
// following the introduction of `ReceiveAuthKey`-based authentication for
549-
// inbound `BlindedMessagePath`s. These fields are now commented out and
550-
// their `type` values must not be reused unless support for LDK v0.2
551-
// and earlier is fully dropped.
552-
//
553-
// For context-specific removals, see the commented-out fields within each enum variant.
546+
// Note: Several TLV fields (`nonce`, `hmac`, etc.) were removed in LDK v0.2 following the
547+
// introduction of `ReceiveAuthKey`-based authentication for inbound `BlindedMessagePath`s. Because
548+
// we do not support receiving to those contexts anymore (they will fail the `ReceiveAuthKey`-based
549+
// authentication checks), we can reuse those fields here.
554550
impl_writeable_tlv_based_enum!(OffersContext,
555551
(0, InvoiceRequest) => {
556552
(0, nonce, required),
557553
},
558554
(1, OutboundPayment) => {
559555
(0, payment_id, required),
560556
(1, nonce, required),
561-
// Removed: (2, hmac, option)
562557
},
563558
(2, InboundPayment) => {
564559
(0, payment_hash, required),
565-
// Removed: (1, nonce, required),
566-
// Removed: (2, hmac, required)
567560
},
568561
(3, StaticInvoiceRequested) => {
569562
(0, recipient_id, required),
@@ -575,12 +568,8 @@ impl_writeable_tlv_based_enum!(OffersContext,
575568
impl_writeable_tlv_based_enum!(AsyncPaymentsContext,
576569
(0, OutboundPayment) => {
577570
(0, payment_id, required),
578-
// Removed: (2, nonce, required),
579-
// Removed: (4, hmac, required),
580571
},
581572
(1, InboundPayment) => {
582-
// Removed: (0, nonce, required),
583-
// Removed: (2, hmac, required),
584573
(4, path_absolute_expiry, required),
585574
},
586575
(2, OfferPaths) => {

lightning/src/crypto/streams.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ impl<'a, T: Writeable> Writeable for ChaChaPolyWriteAdapter<'a, T> {
5151

5252
Ok(())
5353
}
54+
55+
fn serialized_length(&self) -> usize {
56+
self.writeable.serialized_length() + 16
57+
}
5458
}
5559

5660
/// Encrypts the provided plaintext with the given key using ChaCha20Poly1305 in the modified
@@ -124,7 +128,10 @@ impl<T: Readable> LengthReadableArgs<([u8; 32], [u8; 32])> for ChaChaDualPolyRea
124128
ChaChaDualPolyReader { chacha: &mut chacha, poly: &mut mac, read_len: 0, read: s };
125129

126130
let readable: T = Readable::read(&mut chacha_stream)?;
127-
chacha_stream.read.eat_remaining()?;
131+
while chacha_stream.read.bytes_remain() {
132+
let mut buf = [0; 256];
133+
chacha_stream.read(&mut buf)?;
134+
}
128135

129136
let read_len = chacha_stream.read_len;
130137

@@ -199,7 +206,10 @@ impl<T: Readable> LengthReadableArgs<[u8; 32]> for ChaChaPolyReadAdapter<T> {
199206
let s = FixedLengthReader::new(r, decrypted_len);
200207
let mut chacha_stream = ChaChaPolyReader { chacha: &mut chacha, read: s };
201208
let readable: T = Readable::read(&mut chacha_stream)?;
202-
chacha_stream.read.eat_remaining()?;
209+
while chacha_stream.read.bytes_remain() {
210+
let mut buf = [0; 256];
211+
chacha_stream.read(&mut buf)?;
212+
}
203213

204214
let mut tag = [0 as u8; 16];
205215
r.read_exact(&mut tag)?;

lightning/src/offers/flow.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,13 +501,12 @@ where
501501

502502
/// Verifies the provided [`AsyncPaymentsContext`] for an inbound [`HeldHtlcAvailable`] message.
503503
///
504-
/// The context is verified using the `nonce` and `hmac` values, and ensures that the context
505-
/// has not expired based on `path_absolute_expiry`.
504+
/// Because blinded path contexts are verified as a part of onion message processing, this only
505+
/// validates that the context is not yet expired based on `path_absolute_expiry`.
506506
///
507507
/// # Errors
508508
///
509509
/// Returns `Err(())` if:
510-
/// - The HMAC verification fails for inbound context.
511510
/// - The inbound payment context has expired.
512511
#[cfg(async_payments)]
513512
pub fn verify_inbound_async_payment_context(

lightning/src/offers/signer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const WITH_ENCRYPTED_PAYMENT_ID_HMAC_INPUT: &[u8; 16] = &[4; 16];
4242
// `OffersContext`, but were removed in LDK v0.2 with the introduction of `ReceiveAuthKey`-based
4343
// authentication.
4444
// Their corresponding values (`[5; 16]` and `[7; 16]`) are now reserved and must not
45-
// be reused to preserve backward compatibility.
45+
// be reused to ensure type confusion attacks are impossible.
4646
//
4747
// Reserved HMAC_INPUT values — do not reuse:
4848
//

0 commit comments

Comments
 (0)