Merge branch 'openssl' into MLKEM_libressl

This commit is contained in:
Luminok
2026-06-08 04:39:20 +00:00
committed by GitHub
7 changed files with 99 additions and 273 deletions
+2 -2
View File
@@ -332,9 +332,9 @@ namespace config {
("ntcp2.addressv6", value<std::string>()->default_value("::"), "Address to publish NTCP2 with")
("ntcp2.proxy", value<std::string>()->default_value(""), "Proxy URL for NTCP2 transport")
#if OPENSSL_PQ
("ntcp2.version", value<int>()->default_value(4), "Protocol version. 2 - standard, 3,4,5 - post quantum (default: 4")
("ntcp2.version", value<int>()->default_value(4), "Protocol version. 2 - standard, 3,4,5 - post quantum (default: 4)")
#else
("ntcp2.version", value<int>()->default_value(2), "Protocol version. 2 - standard, 3,4,5 - post quantum (default: 2")
("ntcp2.version", value<int>()->default_value(2), "Protocol version. 2 - standard, 3,4,5 - post quantum (default: 2)")
#endif
;
+3 -5
View File
@@ -979,8 +979,7 @@ namespace client
m_StreamingMaxWindowSize (i2p::stream::MAX_WINDOW_SIZE),
m_StreamingMaxResends (i2p::stream::MAX_NUM_RESEND_ATTEMPTS),
m_IsStreamingAnswerPings (DEFAULT_ANSWER_PINGS), m_IsStreamingDontSign (DEFAULT_DONT_SIGN),
m_LastPort (0), m_DatagramDestination (nullptr), m_RefCounter (0),
m_LastPublishedTimestamp (0), m_ReadyChecker(service)
m_LastPort (0), m_RefCounter (0), m_LastPublishedTimestamp (0), m_ReadyChecker(service)
{
if (keys.IsOfflineSignature () && GetLeaseSetType () == i2p::data::NETDB_STORE_TYPE_LEASESET)
SetLeaseSetType (i2p::data::NETDB_STORE_TYPE_STANDARD_LEASESET2); // offline keys can be published with LS2 only
@@ -1129,7 +1128,6 @@ namespace client
if (m_DatagramDestination)
{
LogPrint(eLogDebug, "Destination: -> Stopping Datagram Destination");
delete m_DatagramDestination;
m_DatagramDestination = nullptr;
}
LeaseSetDestination::Stop ();
@@ -1382,14 +1380,14 @@ namespace client
return nullptr;
}
i2p::datagram::DatagramDestination * ClientDestination::CreateDatagramDestination (bool gzip,
std::shared_ptr<i2p::datagram::DatagramDestination> ClientDestination::CreateDatagramDestination (bool gzip,
i2p::datagram::DatagramVersion version)
{
if (!m_DatagramDestination)
{
if (!GetNumRatchetInboundTags ())
SetNumRatchetInboundTags (i2p::garlic::ECIESX25519_MAX_NUM_GENERATED_TAGS); // set max tags if not specified
m_DatagramDestination = new i2p::datagram::DatagramDestination (GetSharedFromThis (), gzip, version);
m_DatagramDestination = std::make_shared<i2p::datagram::DatagramDestination> (GetSharedFromThis (), gzip, version);
}
return m_DatagramDestination;
}
+3 -3
View File
@@ -285,8 +285,8 @@ namespace client
int GetStreamingMaxResends () const { return m_StreamingMaxResends; }
// datagram
i2p::datagram::DatagramDestination * GetDatagramDestination () const { return m_DatagramDestination; };
i2p::datagram::DatagramDestination * CreateDatagramDestination (bool gzip = true,
std::shared_ptr<i2p::datagram::DatagramDestination> GetDatagramDestination () const { return m_DatagramDestination; };
std::shared_ptr<i2p::datagram::DatagramDestination> CreateDatagramDestination (bool gzip = true,
i2p::datagram::DatagramVersion version = i2p::datagram::eDatagramV1);
// implements LocalDestination
@@ -330,7 +330,7 @@ namespace client
std::shared_ptr<i2p::stream::StreamingDestination> m_StreamingDestination; // default
std::map<uint16_t, std::shared_ptr<i2p::stream::StreamingDestination> > m_StreamingDestinationsByPorts;
std::shared_ptr<i2p::stream::StreamingDestination> m_LastStreamingDestination; uint16_t m_LastPort; // for server tunnels
i2p::datagram::DatagramDestination * m_DatagramDestination;
std::shared_ptr<i2p::datagram::DatagramDestination> m_DatagramDestination;
int m_RefCounter; // how many clients(tunnels) use this destination
uint64_t m_LastPublishedTimestamp;
+48 -169
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2025, The PurpleI2P Project
* Copyright (c) 2013-2026, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
@@ -40,7 +40,7 @@ namespace crypto
m_PublicKey = CreateDSA (pub);
BN_free (pub);
}
bool DSAVerifier::Verify (const uint8_t * buf, size_t len, const uint8_t * signature) const
{
// signature
@@ -89,7 +89,7 @@ namespace crypto
bn2buf (s, signature + DSA_SIGNATURE_LENGTH/2, DSA_SIGNATURE_LENGTH/2);
DSA_SIG_free(sig);
}
void CreateDSARandomKeys (uint8_t * signingPrivateKey, uint8_t * signingPublicKey)
{
EVP_PKEY * paramskey = CreateDSA();
@@ -106,9 +106,9 @@ namespace crypto
EVP_PKEY_free (pkey);
EVP_PKEY_free (paramskey);
EVP_PKEY_CTX_free (ctx);
}
#else
}
#else
DSAVerifier::DSAVerifier ()
{
m_PublicKey = CreateDSA ();
@@ -123,7 +123,7 @@ namespace crypto
{
DSA_set0_key (m_PublicKey, BN_bin2bn (signingKey, DSA_PUBLIC_KEY_LENGTH, NULL), NULL);
}
bool DSAVerifier::Verify (const uint8_t * buf, size_t len, const uint8_t * signature) const
{
// calculate SHA1 digest
@@ -171,7 +171,7 @@ namespace crypto
bn2buf (pub_key, signingPublicKey, DSA_PUBLIC_KEY_LENGTH);
DSA_free (dsa);
}
#endif
#endif
#if (OPENSSL_VERSION_NUMBER >= 0x030000000) // since 3.0.0
ECDSAVerifier::ECDSAVerifier (int curve, size_t keyLen, const EVP_MD * hash):
@@ -183,20 +183,20 @@ namespace crypto
{
if (m_PublicKey)
EVP_PKEY_free (m_PublicKey);
}
}
void ECDSAVerifier::SetPublicKey (const uint8_t * signingKey)
{
if (m_PublicKey)
{
{
EVP_PKEY_free (m_PublicKey);
m_PublicKey = nullptr;
}
}
auto plen = GetPublicKeyLen ();
std::vector<uint8_t> pub(plen + 1);
pub[0] = POINT_CONVERSION_UNCOMPRESSED;
memcpy (pub.data() + 1, signingKey, plen); // 0x04|x|y
OSSL_PARAM_BLD * paramBld = OSSL_PARAM_BLD_new ();
OSSL_PARAM_BLD * paramBld = OSSL_PARAM_BLD_new ();
OSSL_PARAM_BLD_push_utf8_string (paramBld, OSSL_PKEY_PARAM_GROUP_NAME, OBJ_nid2ln(m_Curve), 0);
OSSL_PARAM_BLD_push_octet_string (paramBld, OSSL_PKEY_PARAM_PUB_KEY, pub.data (), pub.size ());
OSSL_PARAM * params = OSSL_PARAM_BLD_to_param(paramBld);
@@ -211,16 +211,16 @@ namespace crypto
}
else
LogPrint (eLogError, "ECDSA can't create PKEY context");
OSSL_PARAM_free (params);
OSSL_PARAM_free (params);
OSSL_PARAM_BLD_free (paramBld);
}
}
bool ECDSAVerifier::Verify (const uint8_t * buf, size_t len, const uint8_t * signature) const
{
// signature
ECDSA_SIG * sig = ECDSA_SIG_new();
ECDSA_SIG_set0 (sig, BN_bin2bn (signature, GetSignatureLen ()/2, NULL),
ECDSA_SIG_set0 (sig, BN_bin2bn (signature, GetSignatureLen ()/2, NULL),
BN_bin2bn (signature + GetSignatureLen ()/2, GetSignatureLen ()/2, NULL));
// to DER format
std::vector<uint8_t> sign(GetSignatureLen () + 8);
@@ -233,17 +233,17 @@ namespace crypto
auto ret = EVP_DigestVerify (ctx, sign.data (), l, buf, len) == 1;
EVP_MD_CTX_destroy (ctx);
return ret;
}
}
ECDSASigner::ECDSASigner (int curve, size_t keyLen, const EVP_MD * hash, const uint8_t * signingPrivateKey):
m_KeyLen (keyLen), m_Hash(hash), m_PrivateKey (nullptr)
{
BIGNUM * priv = BN_bin2bn (signingPrivateKey, keyLen/2, NULL);
OSSL_PARAM_BLD * paramBld = OSSL_PARAM_BLD_new ();
OSSL_PARAM_BLD * paramBld = OSSL_PARAM_BLD_new ();
OSSL_PARAM_BLD_push_utf8_string (paramBld, OSSL_PKEY_PARAM_GROUP_NAME, OBJ_nid2ln(curve), 0);
OSSL_PARAM_BLD_push_BN (paramBld, OSSL_PKEY_PARAM_PRIV_KEY, priv);
OSSL_PARAM * params = OSSL_PARAM_BLD_to_param(paramBld);
OSSL_PARAM_BLD_push_BN (paramBld, OSSL_PKEY_PARAM_PRIV_KEY, priv);
OSSL_PARAM * params = OSSL_PARAM_BLD_to_param(paramBld);
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_from_name (NULL, "EC", NULL);
if (ctx)
{
@@ -255,11 +255,11 @@ namespace crypto
else
LogPrint (eLogError, "ECDSA can't create PKEY context");
OSSL_PARAM_free (params);
OSSL_PARAM_BLD_free (paramBld);
BN_free (priv);
OSSL_PARAM_free (params);
OSSL_PARAM_BLD_free (paramBld);
BN_free (priv);
}
ECDSASigner::~ECDSASigner ()
{
if (m_PrivateKey)
@@ -274,7 +274,7 @@ namespace crypto
EVP_DigestSignInit (ctx, NULL, m_Hash, NULL, m_PrivateKey);
EVP_DigestSign (ctx, sign.data(), &l, buf, len);
EVP_MD_CTX_destroy (ctx);
// decode r and s
// decode r and s
const uint8_t * s1 = sign.data ();
ECDSA_SIG * sig = d2i_ECDSA_SIG (NULL, &s1, l);
const BIGNUM * r, * s;
@@ -282,8 +282,8 @@ namespace crypto
bn2buf (r, signature, m_KeyLen/2);
bn2buf (s, signature + m_KeyLen/2, m_KeyLen/2);
ECDSA_SIG_free(sig);
}
}
void CreateECDSARandomKeys (int curve, size_t keyLen, uint8_t * signingPrivateKey, uint8_t * signingPublicKey)
{
EVP_PKEY * pkey = EVP_EC_gen (OBJ_nid2ln(curve));
@@ -300,10 +300,10 @@ namespace crypto
bn2buf (y, signingPublicKey + keyLen/2, keyLen/2);
BN_free (x); BN_free (y);
EVP_PKEY_free (pkey);
}
#endif
}
#endif
EDDSA25519Verifier::EDDSA25519Verifier ():
m_Pkey (nullptr)
{
@@ -323,13 +323,13 @@ namespace crypto
bool EDDSA25519Verifier::Verify (const uint8_t * buf, size_t len, const uint8_t * signature) const
{
if (m_Pkey)
{
{
EVP_MD_CTX * ctx = EVP_MD_CTX_create ();
EVP_DigestVerifyInit (ctx, NULL, NULL, NULL, m_Pkey);
auto ret = EVP_DigestVerify (ctx, signature, 64, buf, len) == 1;
EVP_MD_CTX_destroy (ctx);
return ret;
}
EVP_MD_CTX_destroy (ctx);
return ret;
}
else
LogPrint (eLogError, "EdDSA verification key is not set");
return false;
@@ -388,11 +388,11 @@ namespace crypto
void EDDSA25519Signer::Sign (const uint8_t * buf, int len, uint8_t * signature) const
{
if (m_Fallback)
if (m_Fallback)
return m_Fallback->Sign (buf, len, signature);
else if (m_Pkey)
{
EVP_MD_CTX * ctx = EVP_MD_CTX_create ();
size_t l = 64;
uint8_t sig[64]; // temporary buffer for signature. openssl issue #7232
@@ -412,35 +412,35 @@ namespace crypto
OSSL_PARAM_utf8_string ("instance", (char *)"Ed25519ph", 9),
OSSL_PARAM_END
};
bool EDDSA25519phVerifier::Verify (const uint8_t * buf, size_t len, const uint8_t * signature) const
{
auto pkey = GetPkey ();
if (pkey)
{
{
uint8_t digest[64];
SHA512 (buf, len, digest);
EVP_MD_CTX * ctx = EVP_MD_CTX_create ();
EVP_DigestVerifyInit_ex (ctx, NULL, NULL, NULL, NULL, pkey, EDDSA25519phParams);
auto ret = EVP_DigestVerify (ctx, signature, 64, digest, 64);
EVP_MD_CTX_destroy (ctx);
return ret;
}
EVP_MD_CTX_destroy (ctx);
return ret;
}
else
LogPrint (eLogError, "EdDSA verification key is not set");
return false;
}
EDDSA25519phSigner::EDDSA25519phSigner (const uint8_t * signingPrivateKey):
EDDSA25519phSigner::EDDSA25519phSigner (const uint8_t * signingPrivateKey):
EDDSA25519Signer (signingPrivateKey)
{
{
}
void EDDSA25519phSigner::Sign (const uint8_t * buf, int len, uint8_t * signature) const
{
auto pkey = GetPkey ();
if (pkey)
{
{
uint8_t digest[64];
SHA512 (buf, len, digest);
EVP_MD_CTX * ctx = EVP_MD_CTX_create ();
@@ -454,128 +454,7 @@ namespace crypto
}
else
LogPrint (eLogError, "EdDSA signing key is not set");
}
#endif
#if OPENSSL_PQ && !LIBRESSL_PQ
#warning use MLSDA
MLDSA44Verifier::MLDSA44Verifier ():
m_Pkey (nullptr)
{
}
MLDSA44Verifier::~MLDSA44Verifier ()
{
EVP_PKEY_free (m_Pkey);
}
void MLDSA44Verifier::SetPublicKey (const uint8_t * signingKey)
{
if (m_Pkey)
{
EVP_PKEY_free (m_Pkey);
m_Pkey = nullptr;
}
OSSL_PARAM params[] =
{
OSSL_PARAM_octet_string (OSSL_PKEY_PARAM_PUB_KEY, (uint8_t *)signingKey, GetPublicKeyLen ()),
OSSL_PARAM_END
};
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_from_name (NULL, "ML-DSA-44", NULL);
if (ctx)
{
EVP_PKEY_fromdata_init (ctx);
EVP_PKEY_fromdata (ctx, &m_Pkey, OSSL_KEYMGMT_SELECT_PUBLIC_KEY, params);
EVP_PKEY_CTX_free (ctx);
}
else
LogPrint (eLogError, "MLDSA44 can't create PKEY context");
}
bool MLDSA44Verifier::Verify (const uint8_t * buf, size_t len, const uint8_t * signature) const
{
bool ret = false;
if (m_Pkey)
{
EVP_PKEY_CTX * vctx = EVP_PKEY_CTX_new_from_pkey (NULL, m_Pkey, NULL);
if (vctx)
{
EVP_SIGNATURE * sig = EVP_SIGNATURE_fetch (NULL, "ML-DSA-44", NULL);
if (sig)
{
int encode = 1;
OSSL_PARAM params[] =
{
OSSL_PARAM_int(OSSL_SIGNATURE_PARAM_MESSAGE_ENCODING, &encode),
OSSL_PARAM_END
};
EVP_PKEY_verify_message_init (vctx, sig, params);
ret = EVP_PKEY_verify (vctx, signature, GetSignatureLen (), buf, len) == 1;
EVP_SIGNATURE_free (sig);
}
EVP_PKEY_CTX_free (vctx);
}
else
LogPrint (eLogError, "MLDSA44 can't obtain context from PKEY");
}
else
LogPrint (eLogError, "MLDSA44 verification key is not set");
return ret;
}
MLDSA44Signer::MLDSA44Signer (const uint8_t * signingPrivateKey):
m_Pkey (nullptr)
{
OSSL_PARAM params[] =
{
OSSL_PARAM_octet_string (OSSL_PKEY_PARAM_PRIV_KEY, (uint8_t *)signingPrivateKey, MLDSA44_PRIVATE_KEY_LENGTH),
OSSL_PARAM_END
};
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_from_name (NULL, "ML-DSA-44", NULL);
if (ctx)
{
EVP_PKEY_fromdata_init (ctx);
EVP_PKEY_fromdata (ctx, &m_Pkey, OSSL_KEYMGMT_SELECT_PRIVATE_KEY, params);
EVP_PKEY_CTX_free (ctx);
}
else
LogPrint (eLogError, "MLDSA44 can't create PKEY context");
}
MLDSA44Signer::~MLDSA44Signer ()
{
if (m_Pkey) EVP_PKEY_free (m_Pkey);
}
void MLDSA44Signer::Sign (const uint8_t * buf, int len, uint8_t * signature) const
{
if (m_Pkey)
{
EVP_PKEY_CTX * sctx = EVP_PKEY_CTX_new_from_pkey (NULL, m_Pkey, NULL);
if (sctx)
{
EVP_SIGNATURE * sig = EVP_SIGNATURE_fetch (NULL, "ML-DSA-44", NULL);
if (sig)
{
int encode = 1;
OSSL_PARAM params[] =
{
OSSL_PARAM_int(OSSL_SIGNATURE_PARAM_MESSAGE_ENCODING, &encode),
OSSL_PARAM_END
};
EVP_PKEY_sign_message_init (sctx, sig, params);
size_t siglen = MLDSA44_SIGNATURE_LENGTH;
EVP_PKEY_sign (sctx, signature, &siglen, buf, len);
EVP_SIGNATURE_free (sig);
}
EVP_PKEY_CTX_free (sctx);
}
else
LogPrint (eLogError, "MLDSA44 can't obtain context from PKEY");
}
else
LogPrint (eLogError, "MLDSA44 signing key is not set");
}
#endif
#endif
}
}
+38 -91
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2025, The PurpleI2P Project
* Copyright (c) 2013-2026, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
@@ -50,7 +50,7 @@ namespace crypto
class DSAVerifier: public Verifier
{
public:
DSAVerifier ();
~DSAVerifier ();
@@ -59,14 +59,14 @@ namespace crypto
bool Verify (const uint8_t * buf, size_t len, const uint8_t * signature) const override;
size_t GetPublicKeyLen () const override { return DSA_PUBLIC_KEY_LENGTH; };
size_t GetSignatureLen () const override { return DSA_SIGNATURE_LENGTH; };
private:
#if (OPENSSL_VERSION_NUMBER >= 0x030000000) // since 3.0.0
EVP_PKEY * m_PublicKey;
#else
#else
DSA * m_PublicKey;
#endif
#endif
};
class DSASigner: public Signer
@@ -86,7 +86,7 @@ namespace crypto
EVP_PKEY * m_PrivateKey;
#else
DSA * m_PrivateKey;
#endif
#endif
};
void CreateDSARandomKeys (uint8_t * signingPrivateKey, uint8_t * signingPublicKey);
@@ -95,7 +95,7 @@ namespace crypto
constexpr size_t ECDSAP256_KEY_LENGTH = 64;
constexpr size_t ECDSAP384_KEY_LENGTH = 96;
constexpr size_t ECDSAP521_KEY_LENGTH = 132;
#if (OPENSSL_VERSION_NUMBER >= 0x030000000) // since 3.0.0
class ECDSAVerifier: public Verifier
{
@@ -103,10 +103,10 @@ namespace crypto
ECDSAVerifier (int curve, size_t keyLen, const EVP_MD * hash);
~ECDSAVerifier ();
void SetPublicKey (const uint8_t * signingKey);
bool Verify (const uint8_t * buf, size_t len, const uint8_t * signature) const;
size_t GetPublicKeyLen () const { return m_KeyLen; };
size_t GetSignatureLen () const { return m_KeyLen; }; // signature length = key length
@@ -116,7 +116,7 @@ namespace crypto
size_t m_KeyLen;
const EVP_MD * m_Hash;
EVP_PKEY * m_PublicKey;
};
};
class ECDSASigner: public Signer
{
@@ -126,23 +126,23 @@ namespace crypto
~ECDSASigner ();
void Sign (const uint8_t * buf, int len, uint8_t * signature) const;
private:
size_t m_KeyLen;
const EVP_MD * m_Hash;
EVP_PKEY * m_PrivateKey;
};
};
void CreateECDSARandomKeys (int curve, size_t keyLen, uint8_t * signingPrivateKey, uint8_t * signingPublicKey);
// ECDSA_SHA256_P256
// ECDSA_SHA256_P256
class ECDSAP256Verifier: public ECDSAVerifier
{
public:
ECDSAP256Verifier (): ECDSAVerifier (NID_X9_62_prime256v1, ECDSAP256_KEY_LENGTH, EVP_sha256()) {};
};
};
class ECDSAP256Signer: public ECDSASigner
{
@@ -150,8 +150,8 @@ namespace crypto
ECDSAP256Signer (const uint8_t * signingPrivateKey):
ECDSASigner (NID_X9_62_prime256v1, ECDSAP256_KEY_LENGTH, EVP_sha256(), signingPrivateKey) {};
};
};
inline void CreateECDSAP256RandomKeys (uint8_t * signingPrivateKey, uint8_t * signingPublicKey)
{
CreateECDSARandomKeys (NID_X9_62_prime256v1, ECDSAP256_KEY_LENGTH, signingPrivateKey, signingPublicKey);
@@ -161,9 +161,9 @@ namespace crypto
class ECDSAP384Verifier: public ECDSAVerifier
{
public:
ECDSAP384Verifier (): ECDSAVerifier (NID_secp384r1, ECDSAP384_KEY_LENGTH, EVP_sha384()) {};
};
};
class ECDSAP384Signer: public ECDSASigner
{
@@ -171,8 +171,8 @@ namespace crypto
ECDSAP384Signer (const uint8_t * signingPrivateKey):
ECDSASigner (NID_secp384r1, ECDSAP384_KEY_LENGTH, EVP_sha384(), signingPrivateKey) {};
};
};
inline void CreateECDSAP384RandomKeys (uint8_t * signingPrivateKey, uint8_t * signingPublicKey)
{
CreateECDSARandomKeys (NID_secp384r1, ECDSAP384_KEY_LENGTH, signingPrivateKey, signingPublicKey);
@@ -182,9 +182,9 @@ namespace crypto
class ECDSAP521Verifier: public ECDSAVerifier
{
public:
ECDSAP521Verifier (): ECDSAVerifier (NID_secp521r1, ECDSAP521_KEY_LENGTH, EVP_sha512()) {};
};
};
class ECDSAP521Signer: public ECDSASigner
{
@@ -192,15 +192,15 @@ namespace crypto
ECDSAP521Signer (const uint8_t * signingPrivateKey):
ECDSASigner (NID_secp521r1, ECDSAP521_KEY_LENGTH, EVP_sha512(), signingPrivateKey) {};
};
};
inline void CreateECDSAP521RandomKeys (uint8_t * signingPrivateKey, uint8_t * signingPublicKey)
{
CreateECDSARandomKeys (NID_secp521r1, ECDSAP521_KEY_LENGTH, signingPrivateKey, signingPublicKey);
}
#else
struct SHA256Hash
{
static void CalculateHash (const uint8_t * buf, size_t len, uint8_t * digest)
@@ -351,7 +351,7 @@ namespace crypto
{
CreateECDSARandomKeys (NID_secp521r1, ECDSAP521_KEY_LENGTH, signingPrivateKey, signingPublicKey);
}
#endif
// EdDSA
@@ -369,9 +369,9 @@ namespace crypto
size_t GetSignatureLen () const { return EDDSA25519_SIGNATURE_LENGTH; };
private:
EVP_PKEY * m_Pkey;
protected:
EVP_PKEY * GetPkey () const { return m_Pkey; };
@@ -384,8 +384,8 @@ namespace crypto
bool Verify (const uint8_t * buf, size_t len, const uint8_t * signature) const;
};
#endif
#endif
class EDDSA25519SignerCompat: public Signer
{
public:
@@ -416,7 +416,7 @@ namespace crypto
protected:
EVP_PKEY * GetPkey () const { return m_Pkey; };
private:
EVP_PKEY * m_Pkey;
@@ -429,12 +429,12 @@ namespace crypto
public:
EDDSA25519phSigner (const uint8_t * signingPrivateKey);
void Sign (const uint8_t * buf, int len, uint8_t * signature) const;
};
#endif
#endif
inline void CreateEDDSA25519RandomKeys (uint8_t * signingPrivateKey, uint8_t * signingPublicKey)
{
EVP_PKEY *pkey = NULL;
@@ -609,59 +609,6 @@ namespace crypto
RedDSA25519Signer signer (signingPrivateKey);
memcpy (signingPublicKey, signer.GetPublicKey (), EDDSA25519_PUBLIC_KEY_LENGTH);
}
#if OPENSSL_PQ && !LIBRESSL_PQ
#ifndef LIBRESSL_VERSION_NUMBER
#include <openssl/core_names.h>
#endif
// Post-Quantum
const size_t MLDSA44_PUBLIC_KEY_LENGTH = 1312;
const size_t MLDSA44_SIGNATURE_LENGTH = 2420;
const size_t MLDSA44_PRIVATE_KEY_LENGTH = 2560;
class MLDSA44Verifier: public Verifier
{
public:
MLDSA44Verifier ();
void SetPublicKey (const uint8_t * signingKey);
~MLDSA44Verifier ();
bool Verify (const uint8_t * buf, size_t len, const uint8_t * signature) const;
size_t GetPublicKeyLen () const { return MLDSA44_PUBLIC_KEY_LENGTH; };
size_t GetSignatureLen () const { return MLDSA44_SIGNATURE_LENGTH; };
size_t GetPrivateKeyLen () const { return MLDSA44_PRIVATE_KEY_LENGTH; };
private:
EVP_PKEY * m_Pkey;
};
class MLDSA44Signer: public Signer
{
public:
MLDSA44Signer (const uint8_t * signingPrivateKey);
~MLDSA44Signer ();
void Sign (const uint8_t * buf, int len, uint8_t * signature) const;
private:
EVP_PKEY * m_Pkey;
};
inline void CreateMLDSA44RandomKeys (uint8_t * signingPrivateKey, uint8_t * signingPublicKey)
{
EVP_PKEY * pkey = EVP_PKEY_Q_keygen (NULL, NULL, "ML-DSA-44");
size_t len = MLDSA44_PUBLIC_KEY_LENGTH;
EVP_PKEY_get_octet_string_param (pkey, OSSL_PKEY_PARAM_PUB_KEY, signingPublicKey, MLDSA44_PUBLIC_KEY_LENGTH, &len);
len = MLDSA44_PRIVATE_KEY_LENGTH;
EVP_PKEY_get_octet_string_param (pkey, OSSL_PKEY_PARAM_PRIV_KEY, signingPrivateKey, MLDSA44_PRIVATE_KEY_LENGTH, &len);
EVP_PKEY_free (pkey);
}
#endif
}
}
+3 -1
View File
@@ -1103,6 +1103,7 @@ namespace transport
{
auto ts = i2p::util::GetSecondsSinceEpoch ();
std::list<std::shared_ptr<TransportSession> > sessionsToRemove;
std::list<std::shared_ptr<Peer> > peersToRemove;
{
std::lock_guard<std::mutex> l(m_PeersMutex);
@@ -1134,6 +1135,7 @@ namespace transport
auto profile = i2p::data::GetRouterProfile (it->first);
if (profile) profile->Unreachable ();
} */
peersToRemove.emplace_back (peer); // defer peer destructor call after the loop
it = m_Peers.erase (it);
}
else
@@ -1162,7 +1164,7 @@ namespace transport
PeerTest (ipv4Testing, ipv6Testing);
m_PeerCleanupTimer->expires_after (std::chrono::seconds(2 * SESSION_CREATION_TIMEOUT + m_Rng() % SESSION_CREATION_TIMEOUT));
m_PeerCleanupTimer->async_wait (std::bind (&Transports::HandlePeerCleanupTimer, this, std::placeholders::_1));
// cleanup and delete sessionsToRemove here
// cleanup and delete sessionsToRemove and peersToRemove here
}
}
+2 -2
View File
@@ -38,7 +38,7 @@ namespace client
struct UDPConnection
{
i2p::datagram::DatagramDestination * m_Destination;
std::shared_ptr<i2p::datagram::DatagramDestination> m_Destination;
std::weak_ptr<i2p::datagram::DatagramSession> m_LastDatagramSession;
uint64_t m_LastRepliableDatagramTime; // milliseconds
i2p::data::IdentHash Identity;
@@ -52,7 +52,7 @@ namespace client
bool m_IsSendingAllowed = true;
bool m_IsFirstPacket = true;
UDPConnection (boost::asio::io_context& service, i2p::datagram::DatagramDestination * destination):
UDPConnection (boost::asio::io_context& service, std::shared_ptr<i2p::datagram::DatagramDestination> destination):
m_Destination (destination), m_LastRepliableDatagramTime (0), m_AckTimer (service) {};
void SetIdentity (const i2p::data::IdentHash& ident) { Identity = ident; isIdentity = true; };