10#include <botan/internal/kyber_round3_impl.h>
12#include <botan/internal/ct_utils.h>
13#include <botan/internal/kyber_constants.h>
14#include <botan/internal/kyber_symmetric_primitives.h>
15#include <botan/internal/kyber_types.h>
25 const auto& sym = m_public_key->mode().symmetric_primitives();
30 const auto m = sym.H(seed_m);
31 const auto [K_bar, r] = sym.G(m, m_public_key->H_public_key_bits_raw());
34 sym.KDF(out_shared_key, K_bar, sym.H(out_encapsulated_key));
45 const auto& sym = m_public_key->mode().symmetric_primitives();
47 const auto& h = m_public_key->H_public_key_bits_raw();
48 const auto& z = m_private_key->z();
50 const auto m_prime = m_private_key->indcpa_decrypt(encapsulated_key);
51 const auto [K_bar_prime, r_prime] = sym.G(m_prime, h);
58 const auto reencrypt_success =
CT::is_equal(encapsulated_key.
data(), c_prime.data(), encapsulated_key.
size());
61 sym.KDF(out_shared_key, K, sym.H(encapsulated_key));
89 std::make_shared<Kyber_PublicKeyInternal>(mode, std::move(pub_key)),
90 std::make_shared<Kyber_PrivateKeyInternal>(
99 BOTAN_ASSERT(keypair.first && keypair.second,
"reading private key encoding");
100 BOTAN_ARG_CHECK(keypair.first->H_public_key_bits_raw().size() == puk_key_hash.size() &&
101 std::equal(keypair.first->H_public_key_bits_raw().begin(),
102 keypair.first->H_public_key_bits_raw().end(),
103 puk_key_hash.begin()),
104 "public key's hash does not match the stored hash");
112 const auto& mode = keypair.first->mode();
115 keypair.first->public_key_bits_raw(),
116 keypair.first->H_public_key_bits_raw(),
117 keypair.second->z());
#define BOTAN_ASSERT_NOMSG(expr)
#define BOTAN_ASSERT_NONNULL(ptr)
#define BOTAN_ARG_CHECK(expr, msg)
#define BOTAN_ASSERT(expr, assertion_made)
auto copy(const size_t count)
std::span< const uint8_t > take(const size_t count)
static constexpr size_t SEED_BYTES
size_t public_key_bytes() const
byte length of an encoded public key
size_t polynomial_vector_bytes() const
byte length of an encoded polynomial vector
static constexpr size_t PUBLIC_KEY_HASH_BYTES
KyberInternalKeypair decode_keypair(std::span< const uint8_t > buffer, KyberConstants mode) const override
secure_vector< uint8_t > encode_keypair(KyberInternalKeypair private_key) const override
void decapsulate(StrongSpan< KyberSharedSecret > out_shared_key, StrongSpan< const KyberCompressedCiphertext > encapsulated_key) override
void encapsulate(StrongSpan< KyberCompressedCiphertext > out_encapsulated_key, StrongSpan< KyberSharedSecret > out_shared_key, RandomNumberGenerator &rng) override
const KyberPolyMat & precomputed_matrix_At() const
void random_vec(std::span< uint8_t > v)
decltype(auto) data() noexcept(noexcept(this->m_span.data()))
decltype(auto) size() const noexcept(noexcept(this->m_span.size()))
constexpr void unpoison_all(Ts &&... ts)
constexpr auto scoped_poison(const Ts &... xs)
constexpr Mask< T > conditional_copy_mem(Mask< T > mask, T *to, const T *from0, const T *from1, size_t elems)
constexpr CT::Mask< T > is_equal(const T x[], const T y[], size_t len)
constexpr void unpoison(const T *p, size_t n)
constexpr void poison(const T *p, size_t n)
void encode_polynomial_vector(std::span< uint8_t > out, const KyberPolyVecNTT &vec)
KyberPolyVecNTT decode_polynomial_vector(std::span< const uint8_t > a, const KyberConstants &mode)
constexpr auto concat(Rs &&... ranges)
std::pair< std::shared_ptr< Kyber_PublicKeyInternal >, std::shared_ptr< Kyber_PrivateKeyInternal > > KyberInternalKeypair
std::vector< T, secure_allocator< T > > secure_vector