From 5884852612d2f091c8793912fa1641c8bc69b24b Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 22 Jun 2018 12:20:35 -0400 Subject: [PATCH] correct usage of sipkeys --- libi2pd/NTCP2.cpp | 7 +++---- libi2pd/Siphash.h | 14 +++++++------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/libi2pd/NTCP2.cpp b/libi2pd/NTCP2.cpp index db509186..f7e5e796 100644 --- a/libi2pd/NTCP2.cpp +++ b/libi2pd/NTCP2.cpp @@ -132,7 +132,6 @@ namespace transport void NTCP2Session::KeyDerivationFunctionDataPhase () { - char buf[100]; uint8_t tempKey[32]; unsigned int len; HMAC(EVP_sha256(), m_CK, 32, nullptr, 0, tempKey, &len); // temp_key = HMAC-SHA256(ck, zerolen) static uint8_t one[1] = { 1 }; @@ -411,7 +410,7 @@ namespace transport { LogPrint (eLogDebug, "NTCP2: SessionConfirmed sent"); KeyDerivationFunctionDataPhase (); - memcpy (m_IV, m_Sipkeysba + 16, 8); //Alice + memcpy (m_ReceiveIV, m_Sipkeysba + 16, 8); //Alice ReceiveLength (); } @@ -449,8 +448,8 @@ namespace transport } else { - i2p::crypto::Siphash<8> (m_ReceiveIV, m_ReceiveIV, 8, m_Kba); // assume Alice TODO: - m_NextReceivedLen = be16toh (m_NextReceivedLen ^ buf16toh(m_ReceiveIV)); + i2p::crypto::Siphash<8> (m_ReceiveIV, m_ReceiveIV, 8, m_Sipkeysba); // assume Alice TODO: + m_NextReceivedLen = be16toh (m_NextReceivedLen ^ bufbe16toh(m_ReceiveIV)); LogPrint (eLogDebug, "NTCP2: received length ", m_NextReceivedLen); delete[] m_NextReceivedBuffer; m_NextReceivedBuffer = new uint8_t[m_NextReceivedLen]; diff --git a/libi2pd/Siphash.h b/libi2pd/Siphash.h index 3e74c6e9..aa8b8631 100644 --- a/libi2pd/Siphash.h +++ b/libi2pd/Siphash.h @@ -19,14 +19,14 @@ namespace crypto constexpr int crounds = 2; constexpr int drounds = 4; - uint64_t rotl(const uint64_t & x, int b) + inline uint64_t rotl(const uint64_t & x, int b) { uint64_t ret = x << b; ret |= x >> (64 - b); return ret; } - void u32to8le(const uint32_t & v, uint8_t * p) + inline void u32to8le(const uint32_t & v, uint8_t * p) { p[0] = (uint8_t) v; p[1] = (uint8_t) (v >> 8); @@ -34,7 +34,7 @@ namespace crypto p[3] = (uint8_t) (v >> 24); } - void u64to8le(const uint64_t & v, uint8_t * p) + inline void u64to8le(const uint64_t & v, uint8_t * p) { p[0] = v & 0xff; p[1] = (v >> 8) & 0xff; @@ -46,7 +46,7 @@ namespace crypto p[7] = (v >> 56) & 0xff; } - uint64_t u8to64le(const uint8_t * p) + inline uint64_t u8to64le(const uint8_t * p) { uint64_t i = 0; int idx = 0; @@ -58,7 +58,7 @@ namespace crypto return i; } - void round(uint64_t & _v0, uint64_t & _v1, uint64_t & _v2, uint64_t & _v3) + inline void round(uint64_t & _v0, uint64_t & _v1, uint64_t & _v2, uint64_t & _v3) { _v0 += _v1; _v1 = rotl(_v1, 13); @@ -79,7 +79,7 @@ namespace crypto /** hashsz must be 8 or 16 */ template - void Siphash(uint8_t * h, const uint8_t * buf, std::size_t bufsz, const uint8_t * key) + inline void Siphash(uint8_t * h, const uint8_t * buf, std::size_t bufsz, const uint8_t * key) { uint64_t v0 = 0x736f6d6570736575ULL; uint64_t v1 = 0x646f72616e646f6dULL; @@ -149,4 +149,4 @@ namespace crypto } } -#endif \ No newline at end of file +#endif