mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
check if x25519 key is valid
This commit is contained in:
parent
ce9640773c
commit
726bd0d63b
6 changed files with 52 additions and 13 deletions
|
@ -351,11 +351,13 @@ namespace crypto
|
|||
#endif
|
||||
}
|
||||
|
||||
void X25519Keys::Agree (const uint8_t * pub, uint8_t * shared)
|
||||
bool X25519Keys::Agree (const uint8_t * pub, uint8_t * shared)
|
||||
{
|
||||
if (pub[31] & 0x80) return false; // not x25519 key
|
||||
#if OPENSSL_X25519
|
||||
EVP_PKEY_derive_init (m_Ctx);
|
||||
auto pkey = EVP_PKEY_new_raw_public_key (EVP_PKEY_X25519, NULL, pub, 32);
|
||||
if (!pkey) return false;
|
||||
EVP_PKEY_derive_set_peer (m_Ctx, pkey);
|
||||
size_t len = 32;
|
||||
EVP_PKEY_derive (m_Ctx, shared, &len);
|
||||
|
@ -363,6 +365,7 @@ namespace crypto
|
|||
#else
|
||||
GetEd25519 ()->ScalarMul (pub, m_PrivateKey, shared, m_Ctx);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
void X25519Keys::GetPrivateKey (uint8_t * priv) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue