Browse Source

correct usage of sipkeys

pull/1200/head
orignal 7 years ago
parent
commit
5884852612
  1. 7
      libi2pd/NTCP2.cpp
  2. 12
      libi2pd/Siphash.h

7
libi2pd/NTCP2.cpp

@ -132,7 +132,6 @@ namespace transport @@ -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 @@ -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 @@ -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];

12
libi2pd/Siphash.h

@ -19,14 +19,14 @@ namespace crypto @@ -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 @@ -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 @@ -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 @@ -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 @@ -79,7 +79,7 @@ namespace crypto
/** hashsz must be 8 or 16 */
template<std::size_t hashsz>
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;

Loading…
Cancel
Save