Skip to content

Commit 73ea96d

Browse files
Rename Payment{Hash,Id} hmac creation/verification methods for offers.
We want to specify that these methods are only to be used in an outbound offers payment context, because we'll be adding similar methods for the outbound async payments context in upcoming commits.
1 parent b20e374 commit 73ea96d

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ pub trait Verification {
420420
) -> Hmac<Sha256>;
421421

422422
/// Authenticates the data using an HMAC and a [`Nonce`] taken from an [`OffersContext`].
423-
fn verify(
423+
fn verify_for_offer_payment(
424424
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
425425
) -> Result<(), ()>;
426426
}
@@ -436,7 +436,7 @@ impl Verification for PaymentHash {
436436

437437
/// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
438438
/// [`OffersContext::InboundPayment`].
439-
fn verify(
439+
fn verify_for_offer_payment(
440440
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
441441
) -> Result<(), ()> {
442442
signer::verify_payment_hash(*self, hmac, nonce, expanded_key)
@@ -461,15 +461,15 @@ impl Verification for PaymentId {
461461
fn hmac_for_offer_payment(
462462
&self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
463463
) -> Hmac<Sha256> {
464-
signer::hmac_for_payment_id(*self, nonce, expanded_key)
464+
signer::hmac_for_offer_payment_id(*self, nonce, expanded_key)
465465
}
466466

467467
/// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
468468
/// [`OffersContext::OutboundPayment`].
469-
fn verify(
469+
fn verify_for_offer_payment(
470470
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
471471
) -> Result<(), ()> {
472-
signer::verify_payment_id(*self, hmac, nonce, expanded_key)
472+
signer::verify_offer_payment_id(*self, hmac, nonce, expanded_key)
473473
}
474474
}
475475

@@ -11144,7 +11144,7 @@ where
1114411144
OffersMessage::StaticInvoice(invoice) => {
1114511145
let payment_id = match context {
1114611146
Some(OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }) => {
11147-
if payment_id.verify(hmac, nonce, expanded_key).is_err() {
11147+
if payment_id.verify_for_offer_payment(hmac, nonce, expanded_key).is_err() {
1114811148
return None
1114911149
}
1115011150
payment_id
@@ -11157,7 +11157,7 @@ where
1115711157
OffersMessage::InvoiceError(invoice_error) => {
1115811158
let payment_hash = match context {
1115911159
Some(OffersContext::InboundPayment { payment_hash, nonce, hmac }) => {
11160-
match payment_hash.verify(hmac, nonce, expanded_key) {
11160+
match payment_hash.verify_for_offer_payment(hmac, nonce, expanded_key) {
1116111161
Ok(_) => Some(payment_hash),
1116211162
Err(_) => None,
1116311163
}
@@ -11170,7 +11170,7 @@ where
1117011170

1117111171
match context {
1117211172
Some(OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }) => {
11173-
if let Ok(()) = payment_id.verify(hmac, nonce, expanded_key) {
11173+
if let Ok(()) = payment_id.verify_for_offer_payment(hmac, nonce, expanded_key) {
1117411174
self.abandon_payment_with_reason(
1117511175
payment_id, PaymentFailureReason::InvoiceRequestRejected,
1117611176
);

lightning/src/offers/signer.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const WITHOUT_ENCRYPTED_PAYMENT_ID_HMAC_INPUT: &[u8; 16] = &[3; 16];
3838
const WITH_ENCRYPTED_PAYMENT_ID_HMAC_INPUT: &[u8; 16] = &[4; 16];
3939

4040
// HMAC input for a `PaymentId`. The HMAC is used in `OffersContext::OutboundPayment`.
41-
const PAYMENT_ID_HMAC_INPUT: &[u8; 16] = &[5; 16];
41+
const OFFER_PAYMENT_ID_HMAC_INPUT: &[u8; 16] = &[5; 16];
4242

4343
// HMAC input for a `PaymentHash`. The HMAC is used in `OffersContext::InboundPayment`.
4444
const PAYMENT_HASH_HMAC_INPUT: &[u8; 16] = &[6; 16];
@@ -399,23 +399,23 @@ fn hmac_for_message<'a>(
399399
Ok(hmac)
400400
}
401401

402-
pub(crate) fn hmac_for_payment_id(
402+
pub(crate) fn hmac_for_offer_payment_id(
403403
payment_id: PaymentId, nonce: Nonce, expanded_key: &ExpandedKey,
404404
) -> Hmac<Sha256> {
405405
const IV_BYTES: &[u8; IV_LEN] = b"LDK Payment ID ~";
406406
let mut hmac = expanded_key.hmac_for_offer();
407407
hmac.input(IV_BYTES);
408408
hmac.input(&nonce.0);
409-
hmac.input(PAYMENT_ID_HMAC_INPUT);
409+
hmac.input(OFFER_PAYMENT_ID_HMAC_INPUT);
410410
hmac.input(&payment_id.0);
411411

412412
Hmac::from_engine(hmac)
413413
}
414414

415-
pub(crate) fn verify_payment_id(
415+
pub(crate) fn verify_offer_payment_id(
416416
payment_id: PaymentId, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &ExpandedKey,
417417
) -> Result<(), ()> {
418-
if hmac_for_payment_id(payment_id, nonce, expanded_key) == hmac { Ok(()) } else { Err(()) }
418+
if hmac_for_offer_payment_id(payment_id, nonce, expanded_key) == hmac { Ok(()) } else { Err(()) }
419419
}
420420

421421
pub(crate) fn hmac_for_payment_hash(

0 commit comments

Comments
 (0)