}
let mut chacha = ChaCha20::new(&rho, &[0u8; 8]);
- let next_hop_data = {
+ let (next_hop_data, next_hop_hmac) = {
let mut decoded = [0; 65];
chacha.process(&msg.onion_routing_packet.hop_data[0..65], &mut decoded);
- match msgs::OnionHopData::read(&mut Cursor::new(&decoded[..])) {
+ let mut hmac = [0; 32];
+ hmac.copy_from_slice(&decoded[33..]);
+ match msgs::OnionHopData::read(&mut Cursor::new(&decoded[..33])) {
Err(err) => {
let error_code = match err {
msgs::DecodeError::UnknownVersion => 0x4000 | 1, // unknown realm byte
};
return_err!("Unable to decode our hop data", error_code, &[0;0]);
},
- Ok(msg) => msg
+ Ok(msg) => (msg, hmac)
}
};
- let pending_forward_info = if next_hop_data.hmac == [0; 32] {
+ let pending_forward_info = if next_hop_hmac == [0; 32] {
#[cfg(test)]
{
// In tests, make sure that the initial onion pcket data is, at least, non-0.
version: 0,
public_key,
hop_data: new_packet_data,
- hmac: next_hop_data.hmac.clone(),
+ hmac: next_hop_hmac.clone(),
};
PendingHTLCStatus::Forward(PendingForwardHTLCInfo {
pub(crate) amt_to_forward: u64,
pub(crate) outgoing_cltv_value: u32,
// 12 bytes of 0-padding
- pub(crate) hmac: [u8; 32],
}
pub struct DecodedOnionErrorPacket {
impl Writeable for OnionHopData {
fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
- w.size_hint(65);
+ w.size_hint(33);
match self.format {
OnionHopDataFormat::Legacy => 0u8.write(w)?,
#[cfg(test)]
self.amt_to_forward.write(w)?;
self.outgoing_cltv_value.write(w)?;
w.write_all(&[0;12])?;
- self.hmac.write(w)?;
Ok(())
}
}
r.read_exact(&mut [0; 12])?;
v
},
- hmac: Readable::read(r)?,
})
}
}
short_channel_id: last_short_channel_id,
amt_to_forward: value_msat,
outgoing_cltv_value: cltv,
- hmac: [0; 32],
});
cur_value_msat += hop.fee_msat;
if cur_value_msat >= 21000000 * 100000000 * 1000 {
for (i, (payload, keys)) in payloads.iter_mut().zip(onion_keys.iter()).rev().enumerate() {
shift_arr_right(&mut packet_data);
- payload.hmac = hmac_res;
- packet_data[0..65].copy_from_slice(&payload.encode()[..]);
+ packet_data[0..33].copy_from_slice(&payload.encode()[..]);
+ packet_data[33..65].copy_from_slice(&hmac_res);
let mut chacha = ChaCha20::new(&keys.rho, &[0u8; 8]);
chacha.process(&packet_data, &mut buf[0..20*65]);
short_channel_id: 0,
amt_to_forward: 0,
outgoing_cltv_value: 0,
- hmac: [0; 32],
},
msgs::OnionHopData {
format: msgs::OnionHopDataFormat::Legacy,
short_channel_id: 0x0101010101010101,
amt_to_forward: 0x0100000001,
outgoing_cltv_value: 0,
- hmac: [0; 32],
},
msgs::OnionHopData {
format: msgs::OnionHopDataFormat::Legacy,
short_channel_id: 0x0202020202020202,
amt_to_forward: 0x0200000002,
outgoing_cltv_value: 0,
- hmac: [0; 32],
},
msgs::OnionHopData {
format: msgs::OnionHopDataFormat::Legacy,
short_channel_id: 0x0303030303030303,
amt_to_forward: 0x0300000003,
outgoing_cltv_value: 0,
- hmac: [0; 32],
},
msgs::OnionHopData {
format: msgs::OnionHopDataFormat::Legacy,
short_channel_id: 0x0404040404040404,
amt_to_forward: 0x0400000004,
outgoing_cltv_value: 0,
- hmac: [0; 32],
},
);