Botan 3.14.1
Crypto and TLS for C&
Botan::Kyber_PublicKeyInternal Class Referencefinal

#include <kyber_keys.h>

Public Member Functions

const KyberHashedPublicKey & H_public_key_bits_raw () const
KyberCompressedCiphertext indcpa_encrypt (const KyberMessage &m, const KyberEncryptionRandomness &r, const KyberPolyMat &At, const KyberConstants &mode) const
void indcpa_encrypt (StrongSpan< KyberCompressedCiphertext > out_ct, StrongSpan< const KyberMessage > m, StrongSpan< const KyberEncryptionRandomness > r, const KyberPolyMat &At, const KyberConstants &mode) const
 Kyber_PublicKeyInternal ()=delete
 Kyber_PublicKeyInternal (KyberConstants mode, KyberPolyVecNTT polynomials, KyberSeedRho seed)
 Kyber_PublicKeyInternal (KyberConstants mode, KyberSerializedPublicKey public_key)
const KyberConstants & mode () const
const KyberSerializedPublicKey & public_key_bits_raw () const
const KyberSeedRho & rho () const
const KyberPolyVecNTT & t () const

Detailed Description

Definition at line 65 of file kyber_keys.h.

Constructor & Destructor Documentation

◆ Kyber_PublicKeyInternal() [1/3]

Botan::Kyber_PublicKeyInternal::Kyber_PublicKeyInternal ( KyberConstants mode,
KyberSerializedPublicKey public_key )

Definition at line 271 of file kyber_keys.cpp.

271 :
272 m_mode(std::move(mode)),
273 m_public_key_bits_raw(validate_public_key_length(std::move(public_key), m_mode.public_key_bytes())),
274 m_H_public_key_bits_raw(m_mode.symmetric_primitives().H(m_public_key_bits_raw)),
276 std::span{m_public_key_bits_raw}.first(m_mode.polynomial_vector_bytes()), m_mode)),
277 m_rho(std::span{m_public_key_bits_raw}.last(Botan::KyberConstants::SEED_BYTES)) {}
static constexpr size_t SEED_BYTES
const KyberConstants & mode() const
Definition kyber_keys.h:89
KyberPolyVecNTT decode_polynomial_vector(std::span< const uint8_t > a, const KyberConstants &mode)

References mode().

◆ Kyber_PublicKeyInternal() [2/3]

Botan::Kyber_PublicKeyInternal::Kyber_PublicKeyInternal ( KyberConstants mode,
KyberPolyVecNTT polynomials,
KyberSeedRho seed )

Definition at line 279 of file kyber_keys.cpp.

279 :
280 m_mode(std::move(mode)),
281 m_public_key_bits_raw(concat(Kyber_Algos::encode_polynomial_vector<std::vector<uint8_t>>(t, m_mode), rho)),
282 m_H_public_key_bits_raw(m_mode.symmetric_primitives().H(m_public_key_bits_raw)),
283 m_t(std::move(t)),
284 m_rho(std::move(rho)) {}
const KyberPolyVecNTT & t() const
Definition kyber_keys.h:85
const KyberSeedRho & rho() const
Definition kyber_keys.h:87
void encode_polynomial_vector(std::span< uint8_t > out, const KyberPolyVecNTT &vec)
constexpr auto concat(Rs &&... ranges)
Definition concat_util.h:95

References Botan::concat(), mode(), rho(), and t().

◆ Kyber_PublicKeyInternal() [3/3]

Botan::Kyber_PublicKeyInternal::Kyber_PublicKeyInternal ( )
delete

Member Function Documentation

◆ H_public_key_bits_raw()

const KyberHashedPublicKey & Botan::Kyber_PublicKeyInternal::H_public_key_bits_raw ( ) const
inline

Definition at line 93 of file kyber_keys.h.

93{ return m_H_public_key_bits_raw; }

◆ indcpa_encrypt() [1/2]

KyberCompressedCiphertext Botan::Kyber_PublicKeyInternal::indcpa_encrypt ( const KyberMessage & m,
const KyberEncryptionRandomness & r,
const KyberPolyMat & At,
const KyberConstants & mode ) const
inline

Definition at line 76 of file kyber_keys.h.

79 {
80 KyberCompressedCiphertext ct(m_mode.ciphertext_bytes());
81 indcpa_encrypt(ct, m, r, At, mode);
82 return ct;
83 }
void indcpa_encrypt(StrongSpan< KyberCompressedCiphertext > out_ct, StrongSpan< const KyberMessage > m, StrongSpan< const KyberEncryptionRandomness > r, const KyberPolyMat &At, const KyberConstants &mode) const
Strong< std::vector< uint8_t >, struct KyberCompressedCiphertext_ > KyberCompressedCiphertext
Compressed and serialized ciphertext value.
Definition kyber_types.h:63

References indcpa_encrypt(), and mode().

◆ indcpa_encrypt() [2/2]

void Botan::Kyber_PublicKeyInternal::indcpa_encrypt ( StrongSpan< KyberCompressedCiphertext > out_ct,
StrongSpan< const KyberMessage > m,
StrongSpan< const KyberEncryptionRandomness > r,
const KyberPolyMat & At,
const KyberConstants & mode ) const

NIST FIPS 203, Algorithm 14 (K-PKE.Encrypt)

In contrast to FIPS 203, the matrix At is not sampled for every invocation, instead it is precomputed and passed in as a parameter. Similarly, the t^T is already decoded and available as a member variable. This allows to reuse these structures for multiple encryptions.

The sampling loops spelled out in FIPS 203 are hidden in the sample_* functions.

Definition at line 296 of file kyber_keys.cpp.

300 {
301 // The nonce N is handled internally by the PolynomialSampler
303 const auto y = ntt(ps.sample_polynomial_vector_cbd_eta1());
304 const auto [e1, e2] = ps.sample_polynomial_vector_and_poly_cbd_eta2();
305
306 auto u = inverse_ntt(At * y);
307 u += e1;
308 u.reduce();
309
310 const auto mu = Kyber_Algos::polynomial_from_message(m);
311 auto v = inverse_ntt(m_t * y);
312 v += e2;
313 v += mu;
314 v.reduce();
315
316 Kyber_Algos::compress_ciphertext(out_ct, u, v, m_mode);
317}
BOTAN_FN_ISA_AVX2 void inverse_ntt(std::span< int16_t, 256 > p)
BOTAN_FN_ISA_AVX2 void ntt(std::span< int16_t, 256 > p)
PolynomialSampler(T, const KyberConstants &) -> PolynomialSampler< T >
void compress_ciphertext(StrongSpan< KyberCompressedCiphertext > out, const KyberPolyVec &u, const KyberPoly &v, const KyberConstants &m_mode)
KyberPoly polynomial_from_message(StrongSpan< const KyberMessage > msg)

References Botan::Kyber_Algos::compress_ciphertext(), mode(), Botan::Kyber_Algos::polynomial_from_message(), Botan::Kyber_Algos::PolynomialSampler< SeedT >::sample_polynomial_vector_and_poly_cbd_eta2(), and Botan::Kyber_Algos::PolynomialSampler< SeedT >::sample_polynomial_vector_cbd_eta1().

Referenced by indcpa_encrypt().

◆ mode()

const KyberConstants & Botan::Kyber_PublicKeyInternal::mode ( ) const
inline

Definition at line 89 of file kyber_keys.h.

89{ return m_mode; }

Referenced by indcpa_encrypt(), indcpa_encrypt(), Kyber_PublicKeyInternal(), and Kyber_PublicKeyInternal().

◆ public_key_bits_raw()

const KyberSerializedPublicKey & Botan::Kyber_PublicKeyInternal::public_key_bits_raw ( ) const
inline

Definition at line 91 of file kyber_keys.h.

91{ return m_public_key_bits_raw; }

◆ rho()

const KyberSeedRho & Botan::Kyber_PublicKeyInternal::rho ( ) const
inline

Definition at line 87 of file kyber_keys.h.

87{ return m_rho; }

Referenced by Kyber_PublicKeyInternal().

◆ t()

const KyberPolyVecNTT & Botan::Kyber_PublicKeyInternal::t ( ) const
inline

Definition at line 85 of file kyber_keys.h.

85{ return m_t; }

Referenced by Kyber_PublicKeyInternal().


The documentation for this class was generated from the following files: