Merge pull request #2693 from Evanfeenstra/next-hop-pubkey-secp-mode
[rust-lightning] / lightning / src / util / crypto.rs
index 617f71e42c6854cb5d106e7a20d7543b14332e3b..cdd00d92af9c5f3cd0a2fe3a61c3447310a0bba2 100644 (file)
@@ -24,7 +24,7 @@ macro_rules! hkdf_extract_expand {
                let (k1, k2, _) = hkdf_extract_expand!($salt, $ikm);
                (k1, k2)
        }};
-       ($salt: expr, $ikm: expr, 4) => {{
+       ($salt: expr, $ikm: expr, 5) => {{
                let (k1, k2, prk) = hkdf_extract_expand!($salt, $ikm);
 
                let mut hmac = HmacEngine::<Sha256>::new(&prk[..]);
@@ -35,7 +35,14 @@ macro_rules! hkdf_extract_expand {
                let mut hmac = HmacEngine::<Sha256>::new(&prk[..]);
                hmac.input(&k3);
                hmac.input(&[4; 1]);
-               (k1, k2, k3, Hmac::from_engine(hmac).into_inner())
+               let k4 = Hmac::from_engine(hmac).into_inner();
+
+               let mut hmac = HmacEngine::<Sha256>::new(&prk[..]);
+               hmac.input(&k4);
+               hmac.input(&[5; 1]);
+               let k5 = Hmac::from_engine(hmac).into_inner();
+
+               (k1, k2, k3, k4, k5)
        }}
 }
 
@@ -43,8 +50,8 @@ pub fn hkdf_extract_expand_twice(salt: &[u8], ikm: &[u8]) -> ([u8; 32], [u8; 32]
        hkdf_extract_expand!(salt, ikm, 2)
 }
 
-pub fn hkdf_extract_expand_4x(salt: &[u8], ikm: &[u8]) -> ([u8; 32], [u8; 32], [u8; 32], [u8; 32]) {
-       hkdf_extract_expand!(salt, ikm, 4)
+pub fn hkdf_extract_expand_5x(salt: &[u8], ikm: &[u8]) -> ([u8; 32], [u8; 32], [u8; 32], [u8; 32], [u8; 32]) {
+       hkdf_extract_expand!(salt, ikm, 5)
 }
 
 #[inline]