From: Valentine Wallace Date: Thu, 5 Sep 2024 20:40:51 +0000 (-0400) Subject: Rename Payment{Hash,Id} hmac creation/verification methods for offers. X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=5a7f52313b9b530206cd4a8a9c812c0ca9d86ed7;p=rust-lightning 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. --- diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 90d896edd..7e891f93d 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -420,7 +420,7 @@ pub trait Verification { ) -> Hmac; /// Authenticates the data using an HMAC and a [`Nonce`] taken from an [`OffersContext`]. - fn verify( + fn verify_for_offer_payment( &self, hmac: Hmac, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey, ) -> Result<(), ()>; } @@ -436,7 +436,7 @@ impl Verification for PaymentHash { /// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an /// [`OffersContext::InboundPayment`]. - fn verify( + fn verify_for_offer_payment( &self, hmac: Hmac, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey, ) -> Result<(), ()> { signer::verify_payment_hash(*self, hmac, nonce, expanded_key) @@ -461,15 +461,15 @@ impl Verification for PaymentId { fn hmac_for_offer_payment( &self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey, ) -> Hmac { - signer::hmac_for_payment_id(*self, nonce, expanded_key) + signer::hmac_for_offer_payment_id(*self, nonce, expanded_key) } /// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an /// [`OffersContext::OutboundPayment`]. - fn verify( + fn verify_for_offer_payment( &self, hmac: Hmac, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey, ) -> Result<(), ()> { - signer::verify_payment_id(*self, hmac, nonce, expanded_key) + signer::verify_offer_payment_id(*self, hmac, nonce, expanded_key) } } @@ -11144,7 +11144,7 @@ where OffersMessage::StaticInvoice(invoice) => { let payment_id = match context { Some(OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }) => { - if payment_id.verify(hmac, nonce, expanded_key).is_err() { + if payment_id.verify_for_offer_payment(hmac, nonce, expanded_key).is_err() { return None } payment_id @@ -11157,7 +11157,7 @@ where OffersMessage::InvoiceError(invoice_error) => { let payment_hash = match context { Some(OffersContext::InboundPayment { payment_hash, nonce, hmac }) => { - match payment_hash.verify(hmac, nonce, expanded_key) { + match payment_hash.verify_for_offer_payment(hmac, nonce, expanded_key) { Ok(_) => Some(payment_hash), Err(_) => None, } @@ -11170,7 +11170,7 @@ where match context { Some(OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }) => { - if let Ok(()) = payment_id.verify(hmac, nonce, expanded_key) { + if let Ok(()) = payment_id.verify_for_offer_payment(hmac, nonce, expanded_key) { self.abandon_payment_with_reason( payment_id, PaymentFailureReason::InvoiceRequestRejected, ); diff --git a/lightning/src/offers/signer.rs b/lightning/src/offers/signer.rs index 907e47822..152c7af57 100644 --- a/lightning/src/offers/signer.rs +++ b/lightning/src/offers/signer.rs @@ -38,7 +38,7 @@ const WITHOUT_ENCRYPTED_PAYMENT_ID_HMAC_INPUT: &[u8; 16] = &[3; 16]; const WITH_ENCRYPTED_PAYMENT_ID_HMAC_INPUT: &[u8; 16] = &[4; 16]; // HMAC input for a `PaymentId`. The HMAC is used in `OffersContext::OutboundPayment`. -const PAYMENT_ID_HMAC_INPUT: &[u8; 16] = &[5; 16]; +const OFFER_PAYMENT_ID_HMAC_INPUT: &[u8; 16] = &[5; 16]; // HMAC input for a `PaymentHash`. The HMAC is used in `OffersContext::InboundPayment`. const PAYMENT_HASH_HMAC_INPUT: &[u8; 16] = &[6; 16]; @@ -399,23 +399,23 @@ fn hmac_for_message<'a>( Ok(hmac) } -pub(crate) fn hmac_for_payment_id( +pub(crate) fn hmac_for_offer_payment_id( payment_id: PaymentId, nonce: Nonce, expanded_key: &ExpandedKey, ) -> Hmac { const IV_BYTES: &[u8; IV_LEN] = b"LDK Payment ID ~"; let mut hmac = expanded_key.hmac_for_offer(); hmac.input(IV_BYTES); hmac.input(&nonce.0); - hmac.input(PAYMENT_ID_HMAC_INPUT); + hmac.input(OFFER_PAYMENT_ID_HMAC_INPUT); hmac.input(&payment_id.0); Hmac::from_engine(hmac) } -pub(crate) fn verify_payment_id( +pub(crate) fn verify_offer_payment_id( payment_id: PaymentId, hmac: Hmac, nonce: Nonce, expanded_key: &ExpandedKey, ) -> Result<(), ()> { - if hmac_for_payment_id(payment_id, nonce, expanded_key) == hmac { Ok(()) } else { Err(()) } + if hmac_for_offer_payment_id(payment_id, nonce, expanded_key) == hmac { Ok(()) } else { Err(()) } } pub(crate) fn hmac_for_payment_hash(