10#ifndef BOTAN_KYBER_SYMMETRIC_PRIMITIVES_H_
11#define BOTAN_KYBER_SYMMETRIC_PRIMITIVES_H_
13#include <botan/hash.h>
15#include <botan/internal/buffer_slicer.h>
16#include <botan/internal/kyber_constants.h>
17#include <botan/internal/kyber_types.h>
47 return G_split<KyberSeedRho, KyberSeedSigma>(seed, *domsep);
49 return G_split<KyberSeedRho, KyberSeedSigma>(seed);
53 std::pair<KyberSharedSecret, KyberEncryptionRandomness>
G(
55 return G_split<KyberSharedSecret, KyberEncryptionRandomness>(msg, pubkey_hash);
61 j->update(rejection_value);
62 j->update(ciphertext);
71 kdf->update(shared_secret);
72 kdf->update(hashed_ciphertext);
78 const size_t outlen)
const {
79 auto bare_seed_span = std::visit([&](
const auto s) {
return s.get(); }, seed);
86 std::tuple<uint8_t, uint8_t> matrix_position)
const {
90 init_XOF(*xof, seed, matrix_position);
95 void setup_PRF(std::unique_ptr<Botan::XOF>& xof, std::span<const uint8_t> seed, uint8_t nonce)
const {
107 std::pair<T1, T2> G_split(
const InputTs&... inputs)
const {
109 (g->update(inputs), ...);
110 const auto s = g->final();
113 std::pair<T1, T2> result;
124 virtual std::unique_ptr<HashFunction>
create_G()
const = 0;
125 virtual std::unique_ptr<HashFunction>
create_H()
const = 0;
126 virtual std::unique_ptr<HashFunction>
create_J()
const = 0;
127 virtual std::unique_ptr<HashFunction>
create_KDF()
const = 0;
129 virtual std::unique_ptr<Botan::XOF>
create_PRF(std::span<const uint8_t> seed, uint8_t nonce)
const = 0;
132 virtual std::unique_ptr<Botan::XOF>
create_XOF(std::span<const uint8_t> seed,
133 std::tuple<uint8_t, uint8_t> matrix_position)
const = 0;
135 std::span<const uint8_t> seed,
136 std::tuple<uint8_t, uint8_t> matrix_position)
const = 0;
#define BOTAN_ASSERT_NOMSG(expr)
static constexpr size_t SEED_BYTES
virtual ~Kyber_Symmetric_Primitives()=default
KyberMessage H(StrongSpan< const KyberMessage > m) const
void setup_XOF(std::unique_ptr< Botan::XOF > &xof, StrongSpan< const KyberSeedRho > seed, std::tuple< uint8_t, uint8_t > matrix_position) const
Setup an XOF object for matrix sampling.
virtual void init_XOF(Botan::XOF &xof, std::span< const uint8_t > seed, std::tuple< uint8_t, uint8_t > matrix_position) const =0
KyberHashedCiphertext H(StrongSpan< const KyberCompressedCiphertext > r) const
void setup_PRF(std::unique_ptr< Botan::XOF > &xof, std::span< const uint8_t > seed, uint8_t nonce) const
Setup a seeded PRF XOF for polynomial sampling.
virtual std::unique_ptr< Botan::XOF > create_XOF(std::span< const uint8_t > seed, std::tuple< uint8_t, uint8_t > matrix_position) const =0
void KDF(StrongSpan< KyberSharedSecret > out, StrongSpan< const KyberSharedSecret > shared_secret, StrongSpan< const KyberHashedCiphertext > hashed_ciphertext) const
KyberSamplingRandomness PRF(KyberSigmaOrEncryptionRandomness seed, const uint8_t nonce, const size_t outlen) const
virtual std::unique_ptr< Botan::XOF > create_PRF(std::span< const uint8_t > seed, uint8_t nonce) const =0
virtual std::unique_ptr< HashFunction > create_G() const =0
virtual std::unique_ptr< HashFunction > create_H() const =0
std::pair< KyberSharedSecret, KyberEncryptionRandomness > G(StrongSpan< const KyberMessage > msg, StrongSpan< const KyberHashedPublicKey > pubkey_hash) const
KyberSharedSecret J(StrongSpan< const KyberImplicitRejectionValue > rejection_value, StrongSpan< const KyberCompressedCiphertext > ciphertext) const
virtual std::unique_ptr< HashFunction > create_J() const =0
std::pair< KyberSeedRho, KyberSeedSigma > G(StrongSpan< const KyberSeedRandomness > seed, const KyberConstants &mode) const
virtual void init_PRF(Botan::XOF &xof, std::span< const uint8_t > seed, uint8_t nonce) const =0
KyberHashedPublicKey H(StrongSpan< const KyberSerializedPublicKey > pk) const
virtual std::unique_ptr< HashFunction > create_KDF() const =0
virtual std::optional< std::array< uint8_t, 1 > > seed_expansion_domain_separator(const KyberConstants &mode) const =0
Strong< secure_vector< uint8_t >, struct KyberMessage_ > KyberMessage
Random message value to be encrypted by the CPA-secure Kyber encryption scheme.
Strong< secure_vector< uint8_t >, struct KyberSamplingRandomness_ > KyberSamplingRandomness
PRF value used for sampling of error polynomials.
Strong< std::vector< uint8_t >, struct KyberHashedCiphertext_ > KyberHashedCiphertext
std::variant< StrongSpan< const KyberSeedSigma >, StrongSpan< const KyberEncryptionRandomness > > KyberSigmaOrEncryptionRandomness
Variant value of either a KyberSeedSigma or a KyberEncryptionRandomness.
Strong< secure_vector< uint8_t >, struct KyberSharedSecret_ > KyberSharedSecret
Shared secret value generated during encapsulation and recovered during decapsulation.
Strong< std::vector< uint8_t >, struct KyberHashedPublicKey_ > KyberHashedPublicKey
Hash value of the serialized public key.