mirror of https://github.com/PurpleI2P/i2pd.git
orignal
7 years ago
6 changed files with 89 additions and 6 deletions
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
#include <openssl/rand.h> |
||||
#include "Crypto.h" |
||||
#include "Ed25519.h" |
||||
#include "ChaCha20.h" |
||||
#include "Poly1305.h" |
||||
#include "NTCP2.h" |
||||
|
||||
namespace i2p |
||||
{ |
||||
namespace transport |
||||
{ |
||||
NTCP2Session::NTCP2Session (std::shared_ptr<const i2p::data::RouterInfo> in_RemoteRouter): |
||||
TransportSession (in_RemoteRouter, 30) |
||||
{ |
||||
} |
||||
|
||||
NTCP2Session::~NTCP2Session () |
||||
{ |
||||
} |
||||
|
||||
void NTCP2Session::CreateEphemeralKey (uint8_t * pub) |
||||
{ |
||||
uint8_t key[32]; |
||||
RAND_bytes (key, 32); |
||||
i2p::crypto::Ed25519::ExpandPrivateKey (key, m_ExpandedPrivateKey); |
||||
BN_CTX * ctx = BN_CTX_new (); |
||||
auto publicKey = i2p::crypto::GetEd25519 ()->GeneratePublicKey (m_ExpandedPrivateKey, ctx); |
||||
i2p::crypto::GetEd25519 ()->EncodePublicKey (publicKey, pub, ctx); |
||||
BN_CTX_free (ctx); |
||||
} |
||||
|
||||
void NTCP2Session::SendSessionRequest (const uint8_t * iv) |
||||
{ |
||||
i2p::crypto::AESAlignedBuffer<32> x; |
||||
CreateEphemeralKey (x); |
||||
// encrypt X
|
||||
i2p::crypto::CBCEncryption encryption; |
||||
encryption.SetKey (GetRemoteIdentity ()->GetIdentHash ()); |
||||
encryption.SetIV (iv); |
||||
encryption.Encrypt (2, x.GetChipherBlock (), x.GetChipherBlock ()); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
#ifndef NTCP2_H__ |
||||
#define NTCP2_H__ |
||||
|
||||
#include <inttypes.h> |
||||
#include <memory> |
||||
#include "RouterInfo.h" |
||||
#include "TransportSession.h" |
||||
|
||||
namespace i2p |
||||
{ |
||||
namespace transport |
||||
{ |
||||
class NTCP2Session: public TransportSession, public std::enable_shared_from_this<NTCP2Session> |
||||
{ |
||||
public: |
||||
|
||||
NTCP2Session (std::shared_ptr<const i2p::data::RouterInfo> in_RemoteRouter = nullptr); // TODO
|
||||
~NTCP2Session (); |
||||
|
||||
private: |
||||
|
||||
void CreateEphemeralKey (uint8_t * pub); |
||||
void SendSessionRequest (const uint8_t * iv); |
||||
|
||||
private: |
||||
|
||||
uint8_t m_ExpandedPrivateKey[64]; // x25519 ephemeral key
|
||||
}; |
||||
} |
||||
} |
||||
|
||||
#endif |
Loading…
Reference in new issue