mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 08:14:15 +00:00
correct usage of sipkeys
This commit is contained in:
parent
5b29592174
commit
5884852612
@ -132,7 +132,6 @@ namespace transport
|
|||||||
|
|
||||||
void NTCP2Session::KeyDerivationFunctionDataPhase ()
|
void NTCP2Session::KeyDerivationFunctionDataPhase ()
|
||||||
{
|
{
|
||||||
char buf[100];
|
|
||||||
uint8_t tempKey[32]; unsigned int len;
|
uint8_t tempKey[32]; unsigned int len;
|
||||||
HMAC(EVP_sha256(), m_CK, 32, nullptr, 0, tempKey, &len); // temp_key = HMAC-SHA256(ck, zerolen)
|
HMAC(EVP_sha256(), m_CK, 32, nullptr, 0, tempKey, &len); // temp_key = HMAC-SHA256(ck, zerolen)
|
||||||
static uint8_t one[1] = { 1 };
|
static uint8_t one[1] = { 1 };
|
||||||
@ -411,7 +410,7 @@ namespace transport
|
|||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "NTCP2: SessionConfirmed sent");
|
LogPrint (eLogDebug, "NTCP2: SessionConfirmed sent");
|
||||||
KeyDerivationFunctionDataPhase ();
|
KeyDerivationFunctionDataPhase ();
|
||||||
memcpy (m_IV, m_Sipkeysba + 16, 8); //Alice
|
memcpy (m_ReceiveIV, m_Sipkeysba + 16, 8); //Alice
|
||||||
ReceiveLength ();
|
ReceiveLength ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -449,8 +448,8 @@ namespace transport
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i2p::crypto::Siphash<8> (m_ReceiveIV, m_ReceiveIV, 8, m_Kba); // assume Alice TODO:
|
i2p::crypto::Siphash<8> (m_ReceiveIV, m_ReceiveIV, 8, m_Sipkeysba); // assume Alice TODO:
|
||||||
m_NextReceivedLen = be16toh (m_NextReceivedLen ^ buf16toh(m_ReceiveIV));
|
m_NextReceivedLen = be16toh (m_NextReceivedLen ^ bufbe16toh(m_ReceiveIV));
|
||||||
LogPrint (eLogDebug, "NTCP2: received length ", m_NextReceivedLen);
|
LogPrint (eLogDebug, "NTCP2: received length ", m_NextReceivedLen);
|
||||||
delete[] m_NextReceivedBuffer;
|
delete[] m_NextReceivedBuffer;
|
||||||
m_NextReceivedBuffer = new uint8_t[m_NextReceivedLen];
|
m_NextReceivedBuffer = new uint8_t[m_NextReceivedLen];
|
||||||
|
@ -19,14 +19,14 @@ namespace crypto
|
|||||||
constexpr int crounds = 2;
|
constexpr int crounds = 2;
|
||||||
constexpr int drounds = 4;
|
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;
|
uint64_t ret = x << b;
|
||||||
ret |= x >> (64 - b);
|
ret |= x >> (64 - b);
|
||||||
return ret;
|
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[0] = (uint8_t) v;
|
||||||
p[1] = (uint8_t) (v >> 8);
|
p[1] = (uint8_t) (v >> 8);
|
||||||
@ -34,7 +34,7 @@ namespace crypto
|
|||||||
p[3] = (uint8_t) (v >> 24);
|
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[0] = v & 0xff;
|
||||||
p[1] = (v >> 8) & 0xff;
|
p[1] = (v >> 8) & 0xff;
|
||||||
@ -46,7 +46,7 @@ namespace crypto
|
|||||||
p[7] = (v >> 56) & 0xff;
|
p[7] = (v >> 56) & 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t u8to64le(const uint8_t * p)
|
inline uint64_t u8to64le(const uint8_t * p)
|
||||||
{
|
{
|
||||||
uint64_t i = 0;
|
uint64_t i = 0;
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
@ -58,7 +58,7 @@ namespace crypto
|
|||||||
return i;
|
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;
|
_v0 += _v1;
|
||||||
_v1 = rotl(_v1, 13);
|
_v1 = rotl(_v1, 13);
|
||||||
@ -79,7 +79,7 @@ namespace crypto
|
|||||||
|
|
||||||
/** hashsz must be 8 or 16 */
|
/** hashsz must be 8 or 16 */
|
||||||
template<std::size_t hashsz>
|
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 v0 = 0x736f6d6570736575ULL;
|
||||||
uint64_t v1 = 0x646f72616e646f6dULL;
|
uint64_t v1 = 0x646f72616e646f6dULL;
|
||||||
@ -149,4 +149,4 @@ namespace crypto
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user