X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fonion_utils.rs;h=b223a344dbe204aafcd511c5efc2d4e035cf1ba9;hb=29e34c8a10cf813116c9251188a86978cc97e259;hp=02676b73bd81f8cfb5edb48281726997ac0b2f55;hpb=3b3a4ba0a6e60e90792bf78d2c5d9cd5c59a5ddb;p=rust-lightning diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index 02676b73..b223a344 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -11,7 +11,7 @@ use ln::{PaymentHash, PaymentPreimage, PaymentSecret}; use ln::channelmanager::HTLCSource; use ln::msgs; use ln::wire::Encode; -use routing::network_graph::NetworkUpdate; +use routing::gossip::NetworkUpdate; use routing::router::RouteHop; use util::chacha20::{ChaCha20, ChaChaReader}; use util::errors::{self, APIError}; @@ -74,6 +74,17 @@ pub(super) fn gen_ammag_from_shared_secret(shared_secret: &[u8]) -> [u8; 32] { Hmac::from_engine(hmac).into_inner() } +pub(super) fn next_hop_packet_pubkey(secp_ctx: &Secp256k1, mut packet_pubkey: PublicKey, packet_shared_secret: &[u8; 32]) -> Result { + let blinding_factor = { + let mut sha = Sha256::engine(); + sha.input(&packet_pubkey.serialize()[..]); + sha.input(packet_shared_secret); + Sha256::from_engine(sha).into_inner() + }; + + packet_pubkey.mul_assign(secp_ctx, &blinding_factor[..]).map(|_| packet_pubkey) +} + // can only fail if an intermediary hop has an invalid public key or session_priv is invalid #[inline] pub(super) fn construct_onion_keys_callback (secp_ctx: &Secp256k1, path: &Vec, session_priv: &SecretKey, mut callback: FType) -> Result<(), secp256k1::Error> {