mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-22 17:06:37 +02:00
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 / CMake i686 (push) Waiting to run
Build on Windows / clang-x86_64 (push) Waiting to run
Build on Windows / i686 (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 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
88 lines
2.4 KiB
C++
88 lines
2.4 KiB
C++
/*
|
|
* Copyright (c) 2025, The PurpleI2P Project
|
|
*
|
|
* This file is part of Purple i2pd project and licensed under BSD3
|
|
*
|
|
* See full license text in LICENSE file at top of project tree
|
|
*/
|
|
|
|
#ifndef POST_QUANTUM_H__
|
|
#define POST_QUANTUM_H__
|
|
|
|
#include <memory>
|
|
#include <string_view>
|
|
#include <array>
|
|
#include <tuple>
|
|
#include "Crypto.h"
|
|
#include "Identity.h"
|
|
|
|
#if OPENSSL_PQ
|
|
|
|
namespace i2p
|
|
{
|
|
namespace crypto
|
|
{
|
|
enum MLKEMTypes
|
|
{
|
|
eMLKEM512 = 0,
|
|
eMLKEM768,
|
|
eMLKEM1024
|
|
};
|
|
|
|
constexpr size_t MLKEM512_KEY_LENGTH = 800;
|
|
constexpr size_t MLKEM512_CIPHER_TEXT_LENGTH = 768;
|
|
constexpr size_t MLKEM768_KEY_LENGTH = 1184;
|
|
constexpr size_t MLKEM768_CIPHER_TEXT_LENGTH = 1088;
|
|
constexpr size_t MLKEM1024_KEY_LENGTH = 1568;
|
|
constexpr size_t MLKEM1024_CIPHER_TEXT_LENGTH = 1568;
|
|
|
|
constexpr std::array<std::tuple<std::string_view, size_t, size_t>, 3> MLKEMS =
|
|
{
|
|
std::make_tuple ("ML-KEM-512", MLKEM512_KEY_LENGTH, MLKEM512_CIPHER_TEXT_LENGTH),
|
|
std::make_tuple ("ML-KEM-768", MLKEM768_KEY_LENGTH, MLKEM768_CIPHER_TEXT_LENGTH),
|
|
std::make_tuple ("ML-KEM-1024", MLKEM1024_KEY_LENGTH, MLKEM1024_CIPHER_TEXT_LENGTH)
|
|
};
|
|
|
|
constexpr size_t GetMLKEMPublicKeyLen (i2p::data::CryptoKeyType type)
|
|
{
|
|
if (type <= i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD ||
|
|
type - i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD > (int)MLKEMS.size ()) return 0;
|
|
return std::get<1>(MLKEMS[type - i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD - 1]);
|
|
}
|
|
|
|
constexpr size_t GetMLKEMCipherTextLen (i2p::data::CryptoKeyType type)
|
|
{
|
|
if (type <= i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD ||
|
|
type - i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD > (int)MLKEMS.size ()) return 0;
|
|
return std::get<2>(MLKEMS[type - i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD - 1]);
|
|
}
|
|
|
|
class MLKEMKeys
|
|
{
|
|
public:
|
|
|
|
MLKEMKeys (MLKEMTypes type);
|
|
~MLKEMKeys ();
|
|
|
|
void GenerateKeys ();
|
|
void GetPublicKey (uint8_t * pub) const;
|
|
void SetPublicKey (const uint8_t * pub);
|
|
void Encaps (uint8_t * ciphertext, uint8_t * shared);
|
|
void Decaps (const uint8_t * ciphertext, uint8_t * shared);
|
|
|
|
private:
|
|
|
|
const std::string m_Name;
|
|
const size_t m_KeyLen, m_CTLen;
|
|
EVP_PKEY * m_Pkey;
|
|
};
|
|
|
|
std::unique_ptr<MLKEMKeys> CreateMLKEMKeys (i2p::data::CryptoKeyType type);
|
|
|
|
void InitNoiseIKStateMLKEM (NoiseSymmetricState& state, i2p::data::CryptoKeyType type, const uint8_t * pub); // Noise_IK (ratchets) PQ ML-KEM5
|
|
}
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|