Botan 3.11.0
Crypto and TLS for C&
Botan::ML_KEM_Symmetric_Primitives Class Referencefinal

#include <ml_kem_impl.h>

Inheritance diagram for Botan::ML_KEM_Symmetric_Primitives:
Botan::Kyber_Symmetric_Primitives

Public Member Functions

std::pair< KyberSharedSecret, KyberEncryptionRandomnessG (StrongSpan< const KyberMessage > msg, StrongSpan< const KyberHashedPublicKey > pubkey_hash) const
std::pair< KyberSeedRho, KyberSeedSigmaG (StrongSpan< const KyberSeedRandomness > seed, const KyberConstants &mode) const
KyberHashedCiphertext H (StrongSpan< const KyberCompressedCiphertext > r) const
KyberMessage H (StrongSpan< const KyberMessage > m) const
KyberHashedPublicKey H (StrongSpan< const KyberSerializedPublicKey > pk) const
KyberSharedSecret J (StrongSpan< const KyberImplicitRejectionValue > rejection_value, StrongSpan< const KyberCompressedCiphertext > ciphertext) const
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
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.
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.

Protected Member Functions

std::unique_ptr< HashFunctioncreate_G () const override
std::unique_ptr< HashFunctioncreate_H () const override
std::unique_ptr< HashFunctioncreate_J () const override
std::unique_ptr< HashFunctioncreate_KDF () const override
std::unique_ptr< Botan::XOFcreate_PRF (std::span< const uint8_t > seed, const uint8_t nonce) const override
std::unique_ptr< Botan::XOFcreate_XOF (std::span< const uint8_t > seed, std::tuple< uint8_t, uint8_t > matrix_position) const override
void init_PRF (Botan::XOF &xof, std::span< const uint8_t > seed, const uint8_t nonce) const override
void init_XOF (Botan::XOF &xof, std::span< const uint8_t > seed, std::tuple< uint8_t, uint8_t > matrix_position) const override
std::optional< std::array< uint8_t, 1 > > seed_expansion_domain_separator (const KyberConstants &mode) const override

Detailed Description

Definition at line 57 of file ml_kem_impl.h.

Member Function Documentation

◆ create_G()

std::unique_ptr< HashFunction > Botan::ML_KEM_Symmetric_Primitives::create_G ( ) const
inlineoverrideprotectedvirtual

Implements Botan::Kyber_Symmetric_Primitives.

Definition at line 67 of file ml_kem_impl.h.

67{ return HashFunction::create_or_throw("SHA-3(512)"); }
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:308

References Botan::HashFunction::create_or_throw().

◆ create_H()

std::unique_ptr< HashFunction > Botan::ML_KEM_Symmetric_Primitives::create_H ( ) const
inlineoverrideprotectedvirtual

Implements Botan::Kyber_Symmetric_Primitives.

Definition at line 69 of file ml_kem_impl.h.

69{ return HashFunction::create_or_throw("SHA-3(256)"); }

References Botan::HashFunction::create_or_throw().

◆ create_J()

std::unique_ptr< HashFunction > Botan::ML_KEM_Symmetric_Primitives::create_J ( ) const
inlineoverrideprotectedvirtual

Implements Botan::Kyber_Symmetric_Primitives.

Definition at line 71 of file ml_kem_impl.h.

71 {
72 return HashFunction::create_or_throw("SHAKE-256(256)");
73 }

References Botan::HashFunction::create_or_throw().

◆ create_KDF()

std::unique_ptr< HashFunction > Botan::ML_KEM_Symmetric_Primitives::create_KDF ( ) const
inlineoverrideprotectedvirtual

Implements Botan::Kyber_Symmetric_Primitives.

Definition at line 75 of file ml_kem_impl.h.

75 {
76 throw Invalid_State("ML-KEM does not support KDF()");
77 }

◆ create_PRF()

std::unique_ptr< Botan::XOF > Botan::ML_KEM_Symmetric_Primitives::create_PRF ( std::span< const uint8_t > seed,
const uint8_t nonce ) const
inlineoverrideprotectedvirtual

Implements Botan::Kyber_Symmetric_Primitives.

Definition at line 79 of file ml_kem_impl.h.

79 {
80 auto xof = Botan::XOF::create_or_throw("SHAKE-256");
81 init_PRF(*xof, seed, nonce);
82 return xof;
83 }
void init_PRF(Botan::XOF &xof, std::span< const uint8_t > seed, const uint8_t nonce) const override
Definition ml_kem_impl.h:85
static std::unique_ptr< XOF > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition xof.cpp:54

References Botan::XOF::create_or_throw(), and init_PRF().

◆ create_XOF()

std::unique_ptr< Botan::XOF > Botan::ML_KEM_Symmetric_Primitives::create_XOF ( std::span< const uint8_t > seed,
std::tuple< uint8_t, uint8_t > matrix_position ) const
inlineoverrideprotectedvirtual

Implements Botan::Kyber_Symmetric_Primitives.

Definition at line 91 of file ml_kem_impl.h.

92 {
93 auto xof = Botan::XOF::create_or_throw("SHAKE-128");
94 init_XOF(*xof, seed, matrix_position);
95 return xof;
96 }
void init_XOF(Botan::XOF &xof, std::span< const uint8_t > seed, std::tuple< uint8_t, uint8_t > matrix_position) const override
Definition ml_kem_impl.h:98

References Botan::XOF::create_or_throw(), and init_XOF().

◆ G() [1/2]

std::pair< KyberSharedSecret, KyberEncryptionRandomness > Botan::Kyber_Symmetric_Primitives::G ( StrongSpan< const KyberMessage > msg,
StrongSpan< const KyberHashedPublicKey > pubkey_hash ) const
inlineinherited

Definition at line 53 of file kyber_symmetric_primitives.h.

54 {
55 return G_split<KyberSharedSecret, KyberEncryptionRandomness>(msg, pubkey_hash);
56 }

◆ G() [2/2]

std::pair< KyberSeedRho, KyberSeedSigma > Botan::Kyber_Symmetric_Primitives::G ( StrongSpan< const KyberSeedRandomness > seed,
const KyberConstants & mode ) const
inlineinherited

Definition at line 44 of file kyber_symmetric_primitives.h.

45 {
46 if(auto domsep = seed_expansion_domain_separator(mode)) {
47 return G_split<KyberSeedRho, KyberSeedSigma>(seed, *domsep);
48 } else {
49 return G_split<KyberSeedRho, KyberSeedSigma>(seed);
50 }
51 }
virtual std::optional< std::array< uint8_t, 1 > > seed_expansion_domain_separator(const KyberConstants &mode) const =0

References seed_expansion_domain_separator().

Referenced by Botan::Kyber_KEM_Decryptor::decapsulate(), Botan::ML_KEM_Decryptor::decapsulate(), and Botan::Kyber_Algos::expand_keypair().

◆ H() [1/3]

KyberHashedCiphertext Botan::Kyber_Symmetric_Primitives::H ( StrongSpan< const KyberCompressedCiphertext > r) const
inlineinherited

Definition at line 36 of file kyber_symmetric_primitives.h.

36 {
37 return create_H()->process<KyberHashedCiphertext>(r);
38 }
virtual std::unique_ptr< HashFunction > create_H() const =0
Strong< std::vector< uint8_t >, struct KyberHashedCiphertext_ > KyberHashedCiphertext
Definition kyber_types.h:67

References create_H().

◆ H() [2/3]

KyberMessage Botan::Kyber_Symmetric_Primitives::H ( StrongSpan< const KyberMessage > m) const
inlineinherited

Definition at line 33 of file kyber_symmetric_primitives.h.

33{ return create_H()->process<KyberMessage>(m); }
Strong< secure_vector< uint8_t >, struct KyberMessage_ > KyberMessage
Random message value to be encrypted by the CPA-secure Kyber encryption scheme.
Definition kyber_types.h:45

References create_H().

◆ H() [3/3]

KyberHashedPublicKey Botan::Kyber_Symmetric_Primitives::H ( StrongSpan< const KyberSerializedPublicKey > pk) const
inlineinherited

Definition at line 40 of file kyber_symmetric_primitives.h.

40 {
41 return create_H()->process<KyberHashedPublicKey>(pk);
42 }
Strong< std::vector< uint8_t >, struct KyberHashedPublicKey_ > KyberHashedPublicKey
Hash value of the serialized public key.
Definition kyber_types.h:60

References create_H().

◆ init_PRF()

void Botan::ML_KEM_Symmetric_Primitives::init_PRF ( Botan::XOF & xof,
std::span< const uint8_t > seed,
const uint8_t nonce ) const
inlineoverrideprotectedvirtual

Implements Botan::Kyber_Symmetric_Primitives.

Definition at line 85 of file ml_kem_impl.h.

85 {
86 xof.clear();
87 xof.update(seed);
88 xof.update(store_be(nonce));
89 }
void clear()
Definition xof.h:64
void update(std::span< const uint8_t > input)
Definition xof.h:140
constexpr auto store_be(ParamTs &&... params)
Definition loadstor.h:745

References Botan::XOF::clear(), Botan::store_be(), and Botan::XOF::update().

Referenced by create_PRF().

◆ init_XOF()

void Botan::ML_KEM_Symmetric_Primitives::init_XOF ( Botan::XOF & xof,
std::span< const uint8_t > seed,
std::tuple< uint8_t, uint8_t > matrix_position ) const
inlineoverrideprotectedvirtual

Implements Botan::Kyber_Symmetric_Primitives.

Definition at line 98 of file ml_kem_impl.h.

100 {
101 xof.clear();
102 xof.update(seed);
103 xof.update(store_be(make_uint16(std::get<0>(matrix_position), std::get<1>(matrix_position))));
104 }
constexpr uint16_t make_uint16(uint8_t i0, uint8_t i1)
Definition loadstor.h:92

References Botan::XOF::clear(), Botan::make_uint16(), Botan::store_be(), and Botan::XOF::update().

Referenced by create_XOF().

◆ J()

KyberSharedSecret Botan::Kyber_Symmetric_Primitives::J ( StrongSpan< const KyberImplicitRejectionValue > rejection_value,
StrongSpan< const KyberCompressedCiphertext > ciphertext ) const
inlineinherited

Definition at line 58 of file kyber_symmetric_primitives.h.

59 {
60 auto j = create_J();
61 j->update(rejection_value);
62 j->update(ciphertext);
63 return j->final<KyberSharedSecret>();
64 }
virtual std::unique_ptr< HashFunction > create_J() const =0
Strong< secure_vector< uint8_t >, struct KyberSharedSecret_ > KyberSharedSecret
Shared secret value generated during encapsulation and recovered during decapsulation.
Definition kyber_types.h:54

References create_J().

◆ KDF()

void Botan::Kyber_Symmetric_Primitives::KDF ( StrongSpan< KyberSharedSecret > out,
StrongSpan< const KyberSharedSecret > shared_secret,
StrongSpan< const KyberHashedCiphertext > hashed_ciphertext ) const
inlineinherited

Definition at line 67 of file kyber_symmetric_primitives.h.

69 {
70 auto kdf = create_KDF();
71 kdf->update(shared_secret);
72 kdf->update(hashed_ciphertext);
73 kdf->final(out);
74 }
virtual std::unique_ptr< HashFunction > create_KDF() const =0

References create_KDF().

◆ PRF()

KyberSamplingRandomness Botan::Kyber_Symmetric_Primitives::PRF ( KyberSigmaOrEncryptionRandomness seed,
const uint8_t nonce,
const size_t outlen ) const
inlineinherited

Definition at line 76 of file kyber_symmetric_primitives.h.

78 {
79 auto bare_seed_span = std::visit([&](const auto s) { return s.get(); }, seed);
80 return create_PRF(bare_seed_span, nonce)->output<KyberSamplingRandomness>(outlen);
81 }
virtual std::unique_ptr< Botan::XOF > create_PRF(std::span< const uint8_t > seed, uint8_t nonce) const =0
Strong< secure_vector< uint8_t >, struct KyberSamplingRandomness_ > KyberSamplingRandomness
PRF value used for sampling of error polynomials.
Definition kyber_types.h:51

References create_PRF().

◆ seed_expansion_domain_separator()

std::optional< std::array< uint8_t, 1 > > Botan::ML_KEM_Symmetric_Primitives::seed_expansion_domain_separator ( const KyberConstants & mode) const
inlineoverrideprotectedvirtual

Implements Botan::Kyber_Symmetric_Primitives.

Definition at line 59 of file ml_kem_impl.h.

59 {
60 // NIST FIPS 203, Algorithm 13 (K-PKE.KeyGen)
61 // Byte 33 of the input to G is the module dimension k from {2,3,4}.
62 // This is included to establish domain separation between the three
63 // parameter sets
64 return std::array{mode.k()};
65 }

References Botan::KyberConstants::k().

◆ setup_PRF()

void Botan::Kyber_Symmetric_Primitives::setup_PRF ( std::unique_ptr< Botan::XOF > & xof,
std::span< const uint8_t > seed,
uint8_t nonce ) const
inlineinherited

Setup a seeded PRF XOF for polynomial sampling.

Definition at line 95 of file kyber_symmetric_primitives.h.

95 {
96 if(!xof) {
97 xof = create_PRF(seed, nonce);
98 } else {
99 init_PRF(*xof, seed, nonce);
100 }
101 }
virtual void init_PRF(Botan::XOF &xof, std::span< const uint8_t > seed, uint8_t nonce) const =0

References create_PRF(), and init_PRF().

◆ setup_XOF()

void Botan::Kyber_Symmetric_Primitives::setup_XOF ( std::unique_ptr< Botan::XOF > & xof,
StrongSpan< const KyberSeedRho > seed,
std::tuple< uint8_t, uint8_t > matrix_position ) const
inlineinherited

Setup an XOF object for matrix sampling.

Definition at line 84 of file kyber_symmetric_primitives.h.

86 {
87 if(!xof) {
88 xof = create_XOF(seed, matrix_position);
89 } else {
90 init_XOF(*xof, seed, matrix_position);
91 }
92 }
virtual void init_XOF(Botan::XOF &xof, std::span< const uint8_t > seed, std::tuple< uint8_t, uint8_t > matrix_position) const =0
virtual std::unique_ptr< Botan::XOF > create_XOF(std::span< const uint8_t > seed, std::tuple< uint8_t, uint8_t > matrix_position) const =0

References create_XOF(), and init_XOF().


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