2020-01-15 20:13:43 +00:00
|
|
|
#ifndef ECIES_X25519_AEAD_RATCHET_SESSION_H__
|
|
|
|
#define ECIES_X25519_AEAD_RATCHET_SESSION_H__
|
|
|
|
|
2020-01-17 00:33:00 +00:00
|
|
|
#include <string.h>
|
2020-01-15 20:13:43 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <functional>
|
2020-01-17 16:21:41 +00:00
|
|
|
#include <vector>
|
2020-01-15 20:13:43 +00:00
|
|
|
#include "Identity.h"
|
2020-01-16 21:34:13 +00:00
|
|
|
#include "Crypto.h"
|
2020-01-16 19:59:19 +00:00
|
|
|
#include "Garlic.h"
|
2020-01-15 20:13:43 +00:00
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace garlic
|
|
|
|
{
|
|
|
|
enum ECIESx25519BlockType
|
|
|
|
{
|
|
|
|
eECIESx25519BlkDateTime = 0,
|
|
|
|
eECIESx25519BlkSessionID = 1,
|
|
|
|
eECIESx25519BlkTermination = 4,
|
|
|
|
eECIESx25519BlkOptions = 5,
|
|
|
|
eECIESx25519BlkNextSessionKey = 7,
|
|
|
|
eECIESx25519BlkGalicClove = 11,
|
|
|
|
eECIESx25519BlkPadding = 254
|
|
|
|
};
|
|
|
|
|
2020-01-16 19:59:19 +00:00
|
|
|
class ECIESX25519AEADRatchetSession: public GarlicRoutingSession
|
2020-01-15 20:13:43 +00:00
|
|
|
{
|
2020-01-17 16:21:41 +00:00
|
|
|
enum SessionState
|
|
|
|
{
|
|
|
|
eSessionStateNew =0,
|
|
|
|
eSessionStateNewSessionReceived
|
|
|
|
};
|
|
|
|
|
2020-01-15 20:13:43 +00:00
|
|
|
public:
|
|
|
|
|
2020-01-16 17:47:08 +00:00
|
|
|
typedef std::function<void (const uint8_t * buf, size_t len)> CloveHandler;
|
2020-01-15 20:13:43 +00:00
|
|
|
|
2020-01-16 19:59:19 +00:00
|
|
|
ECIESX25519AEADRatchetSession (GarlicDestination * owner);
|
2020-01-15 20:13:43 +00:00
|
|
|
~ECIESX25519AEADRatchetSession ();
|
|
|
|
|
2020-01-16 19:59:19 +00:00
|
|
|
std::shared_ptr<I2NPMessage> WrapSingleMessage (std::shared_ptr<const I2NPMessage> msg);
|
|
|
|
|
|
|
|
bool NewIncomingSession (const uint8_t * buf, size_t len, CloveHandler handleClove);
|
2020-01-17 00:33:00 +00:00
|
|
|
const uint8_t * GetRemoteStaticKey () const { return m_RemoteStaticKey; }
|
|
|
|
void SetRemoteStaticKey (const uint8_t * key) { memcpy (m_RemoteStaticKey, key, 32); }
|
2020-01-15 20:13:43 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void MixHash (const uint8_t * buf, size_t len);
|
2020-01-17 19:11:15 +00:00
|
|
|
void DHInitialize (const uint8_t * rootKey, const uint8_t * k, uint8_t * nextRootKey, uint8_t * ck); // ck is 64 buytes
|
2020-01-15 20:13:43 +00:00
|
|
|
|
2020-01-16 17:47:08 +00:00
|
|
|
void HandlePayload (const uint8_t * buf, size_t len, CloveHandler& handleClove);
|
2020-01-15 20:13:43 +00:00
|
|
|
|
2020-01-16 21:34:13 +00:00
|
|
|
bool NewOutgoingSessionMessage (const uint8_t * payload, size_t len, uint8_t * out, size_t outLen);
|
2020-01-17 19:11:15 +00:00
|
|
|
bool NewSessionReplyMessage (const uint8_t * payload, size_t len, uint8_t * out, size_t outLen);
|
2020-01-17 16:21:41 +00:00
|
|
|
std::vector<uint8_t> CreatePayload (std::shared_ptr<const I2NPMessage> msg);
|
2020-01-16 21:34:13 +00:00
|
|
|
|
2020-01-15 20:13:43 +00:00
|
|
|
private:
|
|
|
|
|
2020-01-17 00:33:00 +00:00
|
|
|
uint8_t m_H[32], m_CK[64] /* [chainkey, key] */, m_RemoteStaticKey[32];
|
2020-01-16 21:34:13 +00:00
|
|
|
i2p::crypto::X25519Keys m_EphemeralKeys;
|
2020-01-17 16:21:41 +00:00
|
|
|
SessionState m_State = eSessionStateNew;
|
2020-01-15 20:13:43 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|