mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-29 12:17:49 +02:00
common ML-KEM names and key lengths
Some checks are pending
Build Debian packages / bookworm (push) Waiting to run
Build Debian packages / bullseye (push) Waiting to run
Build Debian packages / buster (push) Waiting to run
Build on FreeBSD / with UPnP (push) Waiting to run
Build on OSX / With USE_UPNP=no (push) Waiting to run
Build on OSX / With USE_UPNP=yes (push) Waiting to run
Build on Windows / i686 (push) Waiting to run
Build on Windows / clang-x86_64 (push) Waiting to run
Build on Windows / ucrt-x86_64 (push) Waiting to run
Build on Windows / x86_64 (push) Waiting to run
Build on Windows / CMake clang-x86_64 (push) Waiting to run
Build on Windows / CMake i686 (push) Waiting to run
Build on Windows / CMake ucrt-x86_64 (push) Waiting to run
Build on Windows / CMake x86_64 (push) Waiting to run
Build on Windows / XP (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=no (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=yes (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=OFF (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=ON (push) Waiting to run
Build containers / Building container for linux/amd64 (push) Waiting to run
Build containers / Building container for linux/arm64 (push) Waiting to run
Build containers / Building container for linux/arm/v7 (push) Waiting to run
Build containers / Building container for linux/386 (push) Waiting to run
Build containers / Pushing merged manifest (push) Blocked by required conditions
Some checks are pending
Build Debian packages / bookworm (push) Waiting to run
Build Debian packages / bullseye (push) Waiting to run
Build Debian packages / buster (push) Waiting to run
Build on FreeBSD / with UPnP (push) Waiting to run
Build on OSX / With USE_UPNP=no (push) Waiting to run
Build on OSX / With USE_UPNP=yes (push) Waiting to run
Build on Windows / i686 (push) Waiting to run
Build on Windows / clang-x86_64 (push) Waiting to run
Build on Windows / ucrt-x86_64 (push) Waiting to run
Build on Windows / x86_64 (push) Waiting to run
Build on Windows / CMake clang-x86_64 (push) Waiting to run
Build on Windows / CMake i686 (push) Waiting to run
Build on Windows / CMake ucrt-x86_64 (push) Waiting to run
Build on Windows / CMake x86_64 (push) Waiting to run
Build on Windows / XP (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=no (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=yes (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=OFF (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=ON (push) Waiting to run
Build containers / Building container for linux/amd64 (push) Waiting to run
Build containers / Building container for linux/arm64 (push) Waiting to run
Build containers / Building container for linux/arm/v7 (push) Waiting to run
Build containers / Building container for linux/386 (push) Waiting to run
Build containers / Pushing merged manifest (push) Blocked by required conditions
This commit is contained in:
parent
f6abbe5908
commit
9ab1a67f0b
5 changed files with 88 additions and 46 deletions
|
@ -1011,32 +1011,32 @@ namespace crypto
|
|||
|
||||
#if OPENSSL_PQ
|
||||
|
||||
MLKEM512Keys::MLKEM512Keys ():
|
||||
m_Pkey (nullptr)
|
||||
MLKEMKeys::MLKEMKeys (std::string_view name, size_t keyLen, size_t ctLen):
|
||||
m_Name (name), m_KeyLen (keyLen), m_CTLen (ctLen),m_Pkey (nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
MLKEM512Keys::~MLKEM512Keys ()
|
||||
MLKEMKeys::~MLKEMKeys ()
|
||||
{
|
||||
if (m_Pkey) EVP_PKEY_free (m_Pkey);
|
||||
}
|
||||
|
||||
void MLKEM512Keys::GenerateKeys ()
|
||||
void MLKEMKeys::GenerateKeys ()
|
||||
{
|
||||
if (m_Pkey) EVP_PKEY_free (m_Pkey);
|
||||
m_Pkey = EVP_PKEY_Q_keygen(NULL, NULL, "ML-KEM-512");
|
||||
m_Pkey = EVP_PKEY_Q_keygen(NULL, NULL, m_Name.c_str ());
|
||||
}
|
||||
|
||||
void MLKEM512Keys::GetPublicKey (uint8_t * pub) const
|
||||
void MLKEMKeys::GetPublicKey (uint8_t * pub) const
|
||||
{
|
||||
if (m_Pkey)
|
||||
{
|
||||
size_t len = MLKEM512_KEY_LENGTH;
|
||||
EVP_PKEY_get_octet_string_param (m_Pkey, OSSL_PKEY_PARAM_PUB_KEY, pub, MLKEM512_KEY_LENGTH, &len);
|
||||
size_t len = m_KeyLen;
|
||||
EVP_PKEY_get_octet_string_param (m_Pkey, OSSL_PKEY_PARAM_PUB_KEY, pub, m_KeyLen, &len);
|
||||
}
|
||||
}
|
||||
|
||||
void MLKEM512Keys::SetPublicKey (const uint8_t * pub)
|
||||
void MLKEMKeys::SetPublicKey (const uint8_t * pub)
|
||||
{
|
||||
if (m_Pkey)
|
||||
{
|
||||
|
@ -1045,10 +1045,10 @@ namespace crypto
|
|||
}
|
||||
OSSL_PARAM params[] =
|
||||
{
|
||||
OSSL_PARAM_octet_string (OSSL_PKEY_PARAM_PUB_KEY, (uint8_t *)pub, MLKEM512_KEY_LENGTH),
|
||||
OSSL_PARAM_octet_string (OSSL_PKEY_PARAM_PUB_KEY, (uint8_t *)pub, m_KeyLen),
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_from_name (NULL, "ML-KEM-512", NULL);
|
||||
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_from_name (NULL, m_Name.c_str (), NULL);
|
||||
if (ctx)
|
||||
{
|
||||
EVP_PKEY_fromdata_init (ctx);
|
||||
|
@ -1059,14 +1059,14 @@ namespace crypto
|
|||
LogPrint (eLogError, "MLKEM512 can't create PKEY context");
|
||||
}
|
||||
|
||||
void MLKEM512Keys::Encaps (uint8_t * ciphertext, uint8_t * shared)
|
||||
void MLKEMKeys::Encaps (uint8_t * ciphertext, uint8_t * shared)
|
||||
{
|
||||
if (!m_Pkey) return;
|
||||
auto ctx = EVP_PKEY_CTX_new_from_pkey (NULL, m_Pkey, NULL);
|
||||
if (ctx)
|
||||
{
|
||||
EVP_PKEY_encapsulate_init (ctx, NULL);
|
||||
size_t len = MLKEM512_CIPHER_TEXT_LENGTH, sharedLen = 32;
|
||||
size_t len = m_CTLen, sharedLen = 32;
|
||||
EVP_PKEY_encapsulate (ctx, ciphertext, &len, shared, &sharedLen);
|
||||
EVP_PKEY_CTX_free (ctx);
|
||||
}
|
||||
|
@ -1074,7 +1074,7 @@ namespace crypto
|
|||
LogPrint (eLogError, "MLKEM512 can't create PKEY context");
|
||||
}
|
||||
|
||||
void MLKEM512Keys::Decaps (const uint8_t * ciphertext, uint8_t * shared)
|
||||
void MLKEMKeys::Decaps (const uint8_t * ciphertext, uint8_t * shared)
|
||||
{
|
||||
if (!m_Pkey) return;
|
||||
auto ctx = EVP_PKEY_CTX_new_from_pkey (NULL, m_Pkey, NULL);
|
||||
|
@ -1082,7 +1082,7 @@ namespace crypto
|
|||
{
|
||||
EVP_PKEY_decapsulate_init (ctx, NULL);
|
||||
size_t sharedLen = 32;
|
||||
EVP_PKEY_decapsulate (ctx, shared, &sharedLen, ciphertext, MLKEM512_CIPHER_TEXT_LENGTH);
|
||||
EVP_PKEY_decapsulate (ctx, shared, &sharedLen, ciphertext, m_CTLen);
|
||||
EVP_PKEY_CTX_free (ctx);
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue