mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
store intermediate symmetric keys
This commit is contained in:
parent
f4798d05e7
commit
f9175db28e
|
@ -44,26 +44,35 @@ namespace garlic
|
||||||
|
|
||||||
void RatchetTagSet::GetSymmKey (int index, uint8_t * key)
|
void RatchetTagSet::GetSymmKey (int index, uint8_t * key)
|
||||||
{
|
{
|
||||||
if (m_NextSymmKeyIndex > 0 && index >= m_NextSymmKeyIndex)
|
if (index >= m_NextSymmKeyIndex)
|
||||||
{
|
{
|
||||||
auto num = index + 1 - m_NextSymmKeyIndex;
|
auto num = index + 1 - m_NextSymmKeyIndex;
|
||||||
|
if (!m_NextSymmKeyIndex)
|
||||||
|
{
|
||||||
|
i2p::crypto::HKDF (m_SymmKeyCK, nullptr, 0, "SymmetricRatchet", m_CurrentSymmKeyCK); // keydata_0 = HKDF(symmKey_ck, SYMMKEY_CONSTANT, "SymmetricRatchet", 64)
|
||||||
|
m_NextSymmKeyIndex = 1;
|
||||||
|
num--;
|
||||||
|
}
|
||||||
for (int i = 0; i < num; i++)
|
for (int i = 0; i < num; i++)
|
||||||
|
{
|
||||||
i2p::crypto::HKDF (m_CurrentSymmKeyCK, nullptr, 0, "SymmetricRatchet", m_CurrentSymmKeyCK);
|
i2p::crypto::HKDF (m_CurrentSymmKeyCK, nullptr, 0, "SymmetricRatchet", m_CurrentSymmKeyCK);
|
||||||
|
if (i < num - 1)
|
||||||
|
m_ItermediateSymmKeys.emplace (m_NextSymmKeyIndex + i, m_CurrentSymmKeyCK + 32);
|
||||||
|
}
|
||||||
m_NextSymmKeyIndex += num;
|
m_NextSymmKeyIndex += num;
|
||||||
memcpy (key, m_CurrentSymmKeyCK + 32, 32);
|
memcpy (key, m_CurrentSymmKeyCK + 32, 32);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
CalculateSymmKeyCK (index, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RatchetTagSet::CalculateSymmKeyCK (int index, uint8_t * key)
|
|
||||||
{
|
{
|
||||||
// TODO: store intermediate keys
|
auto it = m_ItermediateSymmKeys.find (index);
|
||||||
uint8_t currentSymmKeyCK[64];
|
if (it != m_ItermediateSymmKeys.end ())
|
||||||
i2p::crypto::HKDF (m_SymmKeyCK, nullptr, 0, "SymmetricRatchet", currentSymmKeyCK); // keydata_0 = HKDF(symmKey_ck, SYMMKEY_CONSTANT, "SymmetricRatchet", 64)
|
{
|
||||||
for (int i = 0; i < index; i++)
|
memcpy (key, it->second, 32);
|
||||||
i2p::crypto::HKDF (currentSymmKeyCK, nullptr, 0, "SymmetricRatchet", currentSymmKeyCK); // keydata_n = HKDF(symmKey_chainKey_(n-1), SYMMKEY_CONSTANT, "SymmetricRatchet", 64)
|
m_ItermediateSymmKeys.erase (it);
|
||||||
memcpy (key, currentSymmKeyCK + 32, 32);
|
}
|
||||||
|
else
|
||||||
|
LogPrint (eLogError, "Garlic: Missing symmetric key for index ", index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ECIESX25519AEADRatchetSession::ECIESX25519AEADRatchetSession (GarlicDestination * owner):
|
ECIESX25519AEADRatchetSession::ECIESX25519AEADRatchetSession (GarlicDestination * owner):
|
||||||
|
|
|
@ -7,9 +7,11 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <unordered_map>
|
||||||
#include "Identity.h"
|
#include "Identity.h"
|
||||||
#include "Crypto.h"
|
#include "Crypto.h"
|
||||||
#include "Garlic.h"
|
#include "Garlic.h"
|
||||||
|
#include "Tag.h"
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
|
@ -25,10 +27,6 @@ namespace garlic
|
||||||
int GetNextIndex () const { return m_NextIndex; };
|
int GetNextIndex () const { return m_NextIndex; };
|
||||||
void GetSymmKey (int index, uint8_t * key);
|
void GetSymmKey (int index, uint8_t * key);
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void CalculateSymmKeyCK (int index, uint8_t * key);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
union
|
union
|
||||||
|
@ -43,6 +41,7 @@ namespace garlic
|
||||||
} m_KeyData;
|
} m_KeyData;
|
||||||
uint8_t m_SessTagConstant[32], m_SymmKeyCK[32], m_CurrentSymmKeyCK[64];
|
uint8_t m_SessTagConstant[32], m_SymmKeyCK[32], m_CurrentSymmKeyCK[64];
|
||||||
int m_NextIndex, m_NextSymmKeyIndex;
|
int m_NextIndex, m_NextSymmKeyIndex;
|
||||||
|
std::unordered_map<int, i2p::data::Tag<32> > m_ItermediateSymmKeys;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ECIESx25519BlockType
|
enum ECIESx25519BlockType
|
||||||
|
|
Loading…
Reference in a new issue