10#ifndef BOTAN_ML_KEM_IMPL_H_
11#define BOTAN_ML_KEM_IMPL_H_
13#include <botan/hash.h>
17#include <botan/internal/kyber_encaps_base.h>
18#include <botan/internal/kyber_keys.h>
19#include <botan/internal/kyber_symmetric_primitives.h>
20#include <botan/internal/kyber_types.h>
26 ML_KEM_Encryptor(std::shared_ptr<const Kyber_PublicKeyInternal> key, std::string_view kdf) :
37 std::shared_ptr<const Kyber_PublicKeyInternal> m_public_key;
43 std::shared_ptr<const Kyber_PublicKeyInternal> public_key,
44 std::string_view kdf) :
46 m_public_key(std::move(public_key)),
47 m_private_key(std::move(private_key)) {}
56 std::shared_ptr<const Kyber_PublicKeyInternal> m_public_key;
57 std::shared_ptr<const Kyber_PrivateKeyInternal> m_private_key;
65 m_shake256_256(
HashFunction::create_or_throw(
"SHAKE-256(256)")),
66 m_shake128(
Botan::
XOF::create_or_throw(
"SHAKE-128")),
67 m_shake256(
Botan::
XOF::create_or_throw(
"SHAKE-256")) {}
75 return std::array{mode.
k()};
88 m_shake256->update(seed);
93 Botan::XOF&
get_XOF(std::span<const uint8_t> seed, std::tuple<uint8_t, uint8_t> matrix_position)
const override {
95 m_shake128->update(seed);
96 m_shake128->update(
store_be(
make_uint16(std::get<0>(matrix_position), std::get<1>(matrix_position))));
101 std::unique_ptr<HashFunction> m_sha3_512;
102 std::unique_ptr<HashFunction> m_sha3_256;
103 std::unique_ptr<HashFunction> m_shake256_256;
104 std::unique_ptr<Botan::XOF> m_shake128;
105 std::unique_ptr<Botan::XOF> m_shake256;
void decapsulate(StrongSpan< KyberSharedSecret > out_shared_key, StrongSpan< const KyberCompressedCiphertext > encapsulated_key) override
ML_KEM_Decryptor(std::shared_ptr< const Kyber_PrivateKeyInternal > private_key, std::shared_ptr< const Kyber_PublicKeyInternal > public_key, std::string_view kdf)
const KyberConstants & mode() const override
void encapsulate(StrongSpan< KyberCompressedCiphertext > out_encapsulated_key, StrongSpan< KyberSharedSecret > out_shared_key, RandomNumberGenerator &rng) override
ML_KEM_Encryptor(std::shared_ptr< const Kyber_PublicKeyInternal > key, std::string_view kdf)
const KyberConstants & mode() const override
KyberInternalKeypair decode_keypair(std::span< const uint8_t > buffer, KyberConstants mode) const override
secure_vector< uint8_t > encode_keypair(KyberInternalKeypair keypair) const override
std::optional< std::array< uint8_t, 1 > > seed_expansion_domain_separator(const KyberConstants &mode) const override
Botan::XOF & get_PRF(std::span< const uint8_t > seed, const uint8_t nonce) const override
ML_KEM_Symmetric_Primitives()
HashFunction & get_J() const override
HashFunction & get_H() const override
HashFunction & get_KDF() const override
Botan::XOF & get_XOF(std::span< const uint8_t > seed, std::tuple< uint8_t, uint8_t > matrix_position) const override
HashFunction & get_G() const override
int(* final)(unsigned char *, CTX *)
std::pair< std::shared_ptr< Kyber_PublicKeyInternal >, std::shared_ptr< Kyber_PrivateKeyInternal > > KyberInternalKeypair
std::vector< T, secure_allocator< T > > secure_vector
constexpr auto store_be(ParamTs &&... params)
constexpr uint16_t make_uint16(uint8_t i0, uint8_t i1)