|
|
|
@ -120,20 +120,10 @@ namespace transport
|
|
|
|
|
SHA256_Update (&ctx, epub, 32);
|
|
|
|
|
SHA256_Final (m_H, &ctx);
|
|
|
|
|
|
|
|
|
|
// x25519 between remote pub and priv
|
|
|
|
|
// x25519 between remote pub and ephemaral priv
|
|
|
|
|
uint8_t inputKeyMaterial[32];
|
|
|
|
|
#if OPENSSL_X25519
|
|
|
|
|
auto pctx = EVP_PKEY_CTX_new (m_EphemeralPkey, NULL);
|
|
|
|
|
EVP_PKEY_derive_init (pctx);
|
|
|
|
|
auto pkey = EVP_PKEY_new_raw_public_key (EVP_PKEY_X25519, NULL, GetRemotePub (), 32);
|
|
|
|
|
EVP_PKEY_derive_set_peer (pctx, pkey);
|
|
|
|
|
size_t len = 32;
|
|
|
|
|
EVP_PKEY_derive (pctx, inputKeyMaterial, &len);
|
|
|
|
|
EVP_PKEY_free (pkey);
|
|
|
|
|
EVP_PKEY_CTX_free (pctx);
|
|
|
|
|
#else
|
|
|
|
|
i2p::crypto::GetEd25519 ()->ScalarMul (GetRemotePub (), GetPriv (), inputKeyMaterial, m_Ctx);
|
|
|
|
|
#endif
|
|
|
|
|
m_EphemeralKeys.Agree (GetRemotePub (), inputKeyMaterial);
|
|
|
|
|
|
|
|
|
|
MixKey (inputKeyMaterial, m_K);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -157,27 +147,13 @@ namespace transport
|
|
|
|
|
void NTCP2Establisher::KDF3Bob ()
|
|
|
|
|
{
|
|
|
|
|
uint8_t inputKeyMaterial[32];
|
|
|
|
|
i2p::crypto::GetEd25519 ()->ScalarMul (m_RemoteStaticKey, m_EphemeralPrivateKey, inputKeyMaterial, m_Ctx);
|
|
|
|
|
i2p::crypto::GetEd25519 ()->ScalarMul (m_RemoteStaticKey, GetPriv (), inputKeyMaterial, m_Ctx);
|
|
|
|
|
MixKey (inputKeyMaterial, m_K);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NTCP2Establisher::CreateEphemeralKey ()
|
|
|
|
|
{
|
|
|
|
|
#if OPENSSL_X25519
|
|
|
|
|
m_EphemeralPkey = nullptr;
|
|
|
|
|
EVP_PKEY_CTX * pctx = EVP_PKEY_CTX_new_id (NID_X25519, NULL);
|
|
|
|
|
EVP_PKEY_keygen_init (pctx);
|
|
|
|
|
EVP_PKEY_keygen (pctx, &m_EphemeralPkey);
|
|
|
|
|
EVP_PKEY_CTX_free (pctx);
|
|
|
|
|
// TODO: remove, after switch to m_EphemeralPkey
|
|
|
|
|
size_t len = 32;
|
|
|
|
|
EVP_PKEY_get_raw_public_key (m_EphemeralPkey, m_EphemeralPublicKey, &len);
|
|
|
|
|
len = 32;
|
|
|
|
|
EVP_PKEY_get_raw_private_key (m_EphemeralPkey, m_EphemeralPrivateKey, &len);
|
|
|
|
|
#else
|
|
|
|
|
RAND_bytes (m_EphemeralPrivateKey, 32);
|
|
|
|
|
i2p::crypto::GetEd25519 ()->ScalarMulB (m_EphemeralPrivateKey, m_EphemeralPublicKey, m_Ctx);
|
|
|
|
|
#endif
|
|
|
|
|
m_EphemeralKeys.GenerateKeys ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NTCP2Establisher::CreateSessionRequestMessage ()
|
|
|
|
|