15#ifndef BOTAN_KYBER_ALGOS_H_
16#define BOTAN_KYBER_ALGOS_H_
19#include <botan/internal/fmt.h>
20#include <botan/internal/kyber_symmetric_primitives.h>
21#include <botan/internal/kyber_types.h>
22#include <botan/internal/loadstor.h>
39 const KyberConstants& m_mode);
41std::pair<KyberPolyVec, KyberPoly>
decompress_ciphertext(StrongSpan<const KyberCompressedCiphertext> ct,
42 const KyberConstants& mode);
50template <concepts::resizable_
byte_buffer T = secure_vector<u
int8_t>>
63template <
typename SeedT>
64 requires std::same_as<KyberSeedSigma, SeedT> || std::same_as<KyberEncryptionRandomness, SeedT>
68 m_seed(seed), m_mode(mode), m_nonce(0) {}
72 for(
auto& poly : vec) {
73 sample_poly_cbd(poly, m_mode.
eta1());
82 sample_poly_cbd(poly, m_mode.
eta2());
90 for(
auto& poly : vec) {
91 sample_poly_cbd(poly, m_mode.
eta2());
100 const auto randomness = [&] {
103 return prf(2 * poly.
size() / 4);
105 return prf(3 * poly.
size() / 4);
115 StrongSpan<const SeedT> m_seed;
116 const KyberConstants& m_mode;
#define BOTAN_ASSERT_UNREACHABLE()
constexpr size_t size() const
constexpr KyberEta eta2() const
size_t polynomial_vector_bytes() const
byte length of an encoded polynomial vector
Kyber_Symmetric_Primitives & symmetric_primitives() const
KyberPoly sample_polynomial_cbd_eta2()
PolynomialSampler(StrongSpan< const SeedT > seed, const KyberConstants &mode)
KyberPolyVec sample_polynomial_vector_cbd_eta1()
KyberPolyVec sample_polynomial_vector_cbd_eta2()
KyberSamplingRandomness PRF(KyberSigmaOrEncryptionRandomness seed, const uint8_t nonce, const size_t outlen) const
PolynomialSampler(T, const KyberConstants &) -> PolynomialSampler< T >
void encode_polynomial_vector(std::span< uint8_t > out, const KyberPolyVecNTT &vec)
KyberMessage polynomial_to_message(const KyberPoly &p)
KyberPolyMat sample_matrix(StrongSpan< const KyberSeedRho > seed, bool transposed, const KyberConstants &mode)
void compress_ciphertext(StrongSpan< KyberCompressedCiphertext > out, const KyberPolyVec &u, const KyberPoly &v, const KyberConstants &m_mode)
KyberInternalKeypair expand_keypair(KyberPrivateKeySeed seed, KyberConstants mode)
KyberPoly polynomial_from_message(StrongSpan< const KyberMessage > msg)
void sample_polynomial_from_cbd(KyberPoly &poly, KyberConstants::KyberEta eta, const KyberSamplingRandomness &randomness)
std::pair< KyberPolyVec, KyberPoly > decompress_ciphertext(StrongSpan< const KyberCompressedCiphertext > ct, const KyberConstants &mode)
KyberPolyVecNTT decode_polynomial_vector(std::span< const uint8_t > a, const KyberConstants &mode)
Strong< secure_vector< uint8_t >, struct KyberMessage_ > KyberMessage
Random message value to be encrypted by the CPA-secure Kyber encryption scheme.
Botan::CRYSTALS::Polynomial< KyberPolyTraits, Botan::CRYSTALS::Domain::Normal > KyberPoly
Botan::CRYSTALS::PolynomialVector< KyberPolyTraits, Botan::CRYSTALS::Domain::NTT > KyberPolyVecNTT
Strong< secure_vector< uint8_t >, struct KyberSamplingRandomness_ > KyberSamplingRandomness
PRF value used for sampling of error polynomials.
std::pair< std::shared_ptr< Kyber_PublicKeyInternal >, std::shared_ptr< Kyber_PrivateKeyInternal > > KyberInternalKeypair
Botan::CRYSTALS::PolynomialMatrix< KyberPolyTraits > KyberPolyMat
Botan::CRYSTALS::PolynomialVector< KyberPolyTraits, Botan::CRYSTALS::Domain::Normal > KyberPolyVec