i2pd/libi2pd/ECIESX25519AEADRatchetSession.h

58 lines
1.6 KiB
C
Raw Normal View History

2020-01-15 23:13:43 +03:00
#ifndef ECIES_X25519_AEAD_RATCHET_SESSION_H__
#define ECIES_X25519_AEAD_RATCHET_SESSION_H__
#include <string.h>
2020-01-15 23:13:43 +03:00
#include <inttypes.h>
#include <functional>
#include "Identity.h"
#include "Crypto.h"
#include "Garlic.h"
2020-01-15 23:13:43 +03:00
namespace i2p
{
namespace garlic
{
enum ECIESx25519BlockType
{
eECIESx25519BlkDateTime = 0,
eECIESx25519BlkSessionID = 1,
eECIESx25519BlkTermination = 4,
eECIESx25519BlkOptions = 5,
eECIESx25519BlkNextSessionKey = 7,
eECIESx25519BlkGalicClove = 11,
eECIESx25519BlkPadding = 254
};
class ECIESX25519AEADRatchetSession: public GarlicRoutingSession
2020-01-15 23:13:43 +03:00
{
public:
typedef std::function<void (const uint8_t * buf, size_t len)> CloveHandler;
2020-01-15 23:13:43 +03:00
ECIESX25519AEADRatchetSession (GarlicDestination * owner);
2020-01-15 23:13:43 +03:00
~ECIESX25519AEADRatchetSession ();
std::shared_ptr<I2NPMessage> WrapSingleMessage (std::shared_ptr<const I2NPMessage> msg);
bool NewIncomingSession (const uint8_t * buf, size_t len, CloveHandler handleClove);
const uint8_t * GetRemoteStaticKey () const { return m_RemoteStaticKey; }
void SetRemoteStaticKey (const uint8_t * key) { memcpy (m_RemoteStaticKey, key, 32); }
2020-01-15 23:13:43 +03:00
private:
void MixHash (const uint8_t * buf, size_t len);
void HandlePayload (const uint8_t * buf, size_t len, CloveHandler& handleClove);
2020-01-15 23:13:43 +03:00
bool NewOutgoingSessionMessage (const uint8_t * payload, size_t len, uint8_t * out, size_t outLen);
2020-01-15 23:13:43 +03:00
private:
uint8_t m_H[32], m_CK[64] /* [chainkey, key] */, m_RemoteStaticKey[32];
i2p::crypto::X25519Keys m_EphemeralKeys;
2020-01-15 23:13:43 +03:00
};
}
}
#endif