Skip to content

Commit 8121ec2

Browse files
committed
Use [u8; 32] rather than Hmac<Sha256> for simplicity
Mapping an `Hmac<Sha256>` would require somewhat custom logic as we'd have to behave differently based on generic parameters, so its simplest to just swap it to a `[u8; 32]` instead.
1 parent 1cffc9c commit 8121ec2

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

lightning/src/blinded_path/message.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ pub enum OffersContext {
344344
/// used with an [`InvoiceError`].
345345
///
346346
/// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
347-
hmac: Option<Hmac<Sha256>>,
347+
hmac: Option<[u8; 32]>,
348348
},
349349
/// Context used by a [`BlindedMessagePath`] as a reply path for a [`Bolt12Invoice`].
350350
///
@@ -369,7 +369,7 @@ pub enum OffersContext {
369369
/// used to log the received [`InvoiceError`].
370370
///
371371
/// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
372-
hmac: Hmac<Sha256>,
372+
hmac: [u8; 32],
373373
},
374374
}
375375

@@ -400,7 +400,7 @@ pub enum AsyncPaymentsContext {
400400
///
401401
/// Prevents the recipient from being able to deanonymize us by creating a blinded path to us
402402
/// containing the expected [`PaymentId`].
403-
hmac: Hmac<Sha256>,
403+
hmac: [u8; 32],
404404
},
405405
}
406406

lightning/src/blinded_path/payment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ pub struct ReceiveTlvs {
264264
/// The TLVs for which the HMAC in `authentication` is derived.
265265
pub(crate) tlvs: UnauthenticatedReceiveTlvs,
266266
/// An HMAC of `tlvs` along with a nonce used to construct it.
267-
pub(crate) authentication: (Hmac<Sha256>, Nonce),
267+
pub(crate) authentication: ([u8; 32], Nonce),
268268
}
269269

270270
impl ReceiveTlvs {

lightning/src/ln/channelmanager.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -456,11 +456,11 @@ pub trait Verification {
456456
/// [`Nonce`].
457457
fn hmac_for_offer_payment(
458458
&self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
459-
) -> Hmac<Sha256>;
459+
) -> [u8; 32];
460460

461461
/// Authenticates the data using an HMAC and a [`Nonce`] taken from an [`OffersContext`].
462462
fn verify_for_offer_payment(
463-
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
463+
&self, hmac: [u8; 32], nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
464464
) -> Result<(), ()>;
465465
}
466466

@@ -469,29 +469,31 @@ impl Verification for PaymentHash {
469469
/// along with the given [`Nonce`].
470470
fn hmac_for_offer_payment(
471471
&self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
472-
) -> Hmac<Sha256> {
473-
signer::hmac_for_payment_hash(*self, nonce, expanded_key)
472+
) -> [u8; 32] {
473+
signer::hmac_for_payment_hash(*self, nonce, expanded_key).to_byte_array()
474474
}
475475

476476
/// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
477477
/// [`OffersContext::InboundPayment`].
478478
fn verify_for_offer_payment(
479-
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
479+
&self, hmac: [u8; 32], nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
480480
) -> Result<(), ()> {
481+
let hmac = bitcoin::hashes::hmac::Hmac::from_byte_array(hmac);
481482
signer::verify_payment_hash(*self, hmac, nonce, expanded_key)
482483
}
483484
}
484485

485486
impl Verification for UnauthenticatedReceiveTlvs {
486487
fn hmac_for_offer_payment(
487488
&self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
488-
) -> Hmac<Sha256> {
489-
signer::hmac_for_payment_tlvs(self, nonce, expanded_key)
489+
) -> [u8; 32] {
490+
signer::hmac_for_payment_tlvs(self, nonce, expanded_key).to_byte_array()
490491
}
491492

492493
fn verify_for_offer_payment(
493-
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
494+
&self, hmac: [u8; 32], nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
494495
) -> Result<(), ()> {
496+
let hmac = bitcoin::hashes::hmac::Hmac::from_byte_array(hmac);
495497
signer::verify_payment_tlvs(self, hmac, nonce, expanded_key)
496498
}
497499
}
@@ -512,16 +514,17 @@ impl PaymentId {
512514
#[cfg(async_payments)]
513515
pub fn hmac_for_async_payment(
514516
&self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
515-
) -> Hmac<Sha256> {
516-
signer::hmac_for_async_payment_id(*self, nonce, expanded_key)
517+
) -> [u8; 32] {
518+
signer::hmac_for_async_payment_id(*self, nonce, expanded_key).to_byte_array()
517519
}
518520

519521
/// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
520522
/// [`AsyncPaymentsContext::OutboundPayment`].
521523
#[cfg(async_payments)]
522524
pub fn verify_for_async_payment(
523-
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
525+
&self, hmac: [u8; 32], nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
524526
) -> Result<(), ()> {
527+
let hmac = bitcoin::hashes::hmac::Hmac::from_byte_array(hmac);
525528
signer::verify_async_payment_id(*self, hmac, nonce, expanded_key)
526529
}
527530
}
@@ -531,15 +534,16 @@ impl Verification for PaymentId {
531534
/// along with the given [`Nonce`].
532535
fn hmac_for_offer_payment(
533536
&self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
534-
) -> Hmac<Sha256> {
535-
signer::hmac_for_offer_payment_id(*self, nonce, expanded_key)
537+
) -> [u8; 32] {
538+
signer::hmac_for_offer_payment_id(*self, nonce, expanded_key).to_byte_array()
536539
}
537540

538541
/// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
539542
/// [`OffersContext::OutboundPayment`].
540543
fn verify_for_offer_payment(
541-
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
544+
&self, hmac: [u8; 32], nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
542545
) -> Result<(), ()> {
546+
let hmac = bitcoin::hashes::hmac::Hmac::from_byte_array(hmac);
543547
signer::verify_offer_payment_id(*self, hmac, nonce, expanded_key)
544548
}
545549
}

0 commit comments

Comments
 (0)