From: Jeffrey Czyz Date: Thu, 18 Jul 2024 16:42:57 +0000 (-0500) Subject: Add Sha256 HMAC (de)serialization X-Git-Tag: v0.0.124-beta~12^2~17 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=8119fbfaf9fb72a083c7e20250766a1eb4e0183b;p=rust-lightning Add Sha256 HMAC (de)serialization An HMAC needs to be included in OffersContext::OutboundPayment to authenticate the included PaymentId. Implement Readable and Writeable to allow for this. --- diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs index 29c52f6a0..5f203b74d 100644 --- a/lightning/src/util/ser.rs +++ b/lightning/src/util/ser.rs @@ -33,7 +33,9 @@ use bitcoin::script::{self, ScriptBuf}; use bitcoin::transaction::{OutPoint, Transaction, TxOut}; use bitcoin::{consensus, Witness}; use bitcoin::consensus::Encodable; +use bitcoin::hashes::hmac::Hmac; use bitcoin::hashes::sha256d::Hash as Sha256dHash; +use bitcoin::hashes::sha256::Hash as Sha256; use bitcoin::hash_types::{Txid, BlockHash}; use core::time::Duration; use crate::chain::ClaimId; @@ -1033,6 +1035,21 @@ impl Readable for PartialSignatureWithNonce { } } +impl Writeable for Hmac { + fn write(&self, w: &mut W) -> Result<(), io::Error> { + w.write_all(&self[..]) + } +} + +impl Readable for Hmac { + fn read(r: &mut R) -> Result { + use bitcoin::hashes::Hash; + + let buf: [u8; 32] = Readable::read(r)?; + Ok(Hmac::::from_byte_array(buf)) + } +} + impl Writeable for Sha256dHash { fn write(&self, w: &mut W) -> Result<(), io::Error> { w.write_all(&self[..])