Botan 3.6.1
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
 
 ML_KEM_Symmetric_Primitives ()
 
KyberSamplingRandomness PRF (KyberSigmaOrEncryptionRandomness seed, const uint8_t nonce, const size_t outlen) const
 
Botan::XOFXOF (StrongSpan< const KyberSeedRho > seed, std::tuple< uint8_t, uint8_t > matrix_position) const
 

Protected Member Functions

HashFunctionget_G () const override
 
HashFunctionget_H () const override
 
HashFunctionget_J () const override
 
HashFunctionget_KDF () const override
 
Botan::XOFget_PRF (std::span< const uint8_t > seed, const uint8_t nonce) const override
 
Botan::XOFget_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 60 of file ml_kem_impl.h.

Constructor & Destructor Documentation

◆ ML_KEM_Symmetric_Primitives()

Botan::ML_KEM_Symmetric_Primitives::ML_KEM_Symmetric_Primitives ( )
inline

Definition at line 62 of file ml_kem_impl.h.

62 :
63 m_sha3_512(HashFunction::create_or_throw("SHA-3(512)")),
64 m_sha3_256(HashFunction::create_or_throw("SHA-3(256)")),
65 m_shake256_256(HashFunction::create_or_throw("SHAKE-256(256)")),
66 m_shake128(Botan::XOF::create_or_throw("SHAKE-128")),
67 m_shake256(Botan::XOF::create_or_throw("SHAKE-256")) {}
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:298
static std::unique_ptr< XOF > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition xof.cpp:42

Member Function Documentation

◆ 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 55 of file kyber_symmetric_primitives.h.

56 {
57 return G_split<KyberSharedSecret, KyberEncryptionRandomness>(msg, pubkey_hash);
58 }

◆ G() [2/2]

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

Definition at line 46 of file kyber_symmetric_primitives.h.

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

References Botan::Kyber_Symmetric_Primitives::seed_expansion_domain_separator().

Referenced by Botan::Kyber_Algos::expand_keypair().

◆ get_G()

HashFunction & Botan::ML_KEM_Symmetric_Primitives::get_G ( ) const
inlineoverrideprotectedvirtual

Implements Botan::Kyber_Symmetric_Primitives.

Definition at line 78 of file ml_kem_impl.h.

78{ return *m_sha3_512; }

◆ get_H()

HashFunction & Botan::ML_KEM_Symmetric_Primitives::get_H ( ) const
inlineoverrideprotectedvirtual

Implements Botan::Kyber_Symmetric_Primitives.

Definition at line 80 of file ml_kem_impl.h.

80{ return *m_sha3_256; }

◆ get_J()

HashFunction & Botan::ML_KEM_Symmetric_Primitives::get_J ( ) const
inlineoverrideprotectedvirtual

Implements Botan::Kyber_Symmetric_Primitives.

Definition at line 82 of file ml_kem_impl.h.

82{ return *m_shake256_256; }

◆ get_KDF()

HashFunction & Botan::ML_KEM_Symmetric_Primitives::get_KDF ( ) const
inlineoverrideprotectedvirtual

Implements Botan::Kyber_Symmetric_Primitives.

Definition at line 84 of file ml_kem_impl.h.

84{ throw Invalid_State("ML-KEM does not support KDF()"); }

◆ get_PRF()

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

Implements Botan::Kyber_Symmetric_Primitives.

Definition at line 86 of file ml_kem_impl.h.

86 {
87 m_shake256->clear();
88 m_shake256->update(seed);
89 m_shake256->update(store_be(nonce));
90 return *m_shake256;
91 }
constexpr auto store_be(ParamTs &&... params)
Definition loadstor.h:773

References Botan::store_be().

◆ get_XOF()

Botan::XOF & Botan::ML_KEM_Symmetric_Primitives::get_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 93 of file ml_kem_impl.h.

93 {
94 m_shake128->clear();
95 m_shake128->update(seed);
96 m_shake128->update(store_be(make_uint16(std::get<0>(matrix_position), std::get<1>(matrix_position))));
97 return *m_shake128;
98 }
constexpr uint16_t make_uint16(uint8_t i0, uint8_t i1)
Definition loadstor.h:88

References Botan::make_uint16(), and Botan::store_be().

◆ H() [1/3]

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

Definition at line 38 of file kyber_symmetric_primitives.h.

38 {
40 }
T process(const uint8_t in[], size_t length)
Definition buf_comp.h:105
virtual HashFunction & get_H() const =0
Strong< std::vector< uint8_t >, struct KyberHashedCiphertext_ > KyberHashedCiphertext
Definition kyber_types.h:67

References Botan::Kyber_Symmetric_Primitives::get_H(), and Botan::Buffered_Computation::process().

◆ H() [2/3]

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

Definition at line 35 of file kyber_symmetric_primitives.h.

35{ return get_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 Botan::Kyber_Symmetric_Primitives::get_H(), and Botan::Buffered_Computation::process().

◆ H() [3/3]

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

Definition at line 42 of file kyber_symmetric_primitives.h.

42 {
44 }
Strong< std::vector< uint8_t >, struct KyberHashedPublicKey_ > KyberHashedPublicKey
Hash value of the serialized public key.
Definition kyber_types.h:60

References Botan::Kyber_Symmetric_Primitives::get_H(), and Botan::Buffered_Computation::process().

◆ J()

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

Definition at line 60 of file kyber_symmetric_primitives.h.

61 {
62 auto& j = get_J();
63 j.update(rejection_value);
64 j.update(ciphertext);
65 return j.final<KyberSharedSecret>();
66 }
virtual HashFunction & get_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 Botan::Kyber_Symmetric_Primitives::get_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 69 of file kyber_symmetric_primitives.h.

71 {
72 auto& kdf = get_KDF();
73 kdf.update(shared_secret);
74 kdf.update(hashed_ciphertext);
75 kdf.final(out);
76 }
virtual HashFunction & get_KDF() const =0

References Botan::Kyber_Symmetric_Primitives::get_KDF().

◆ PRF()

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

Definition at line 78 of file kyber_symmetric_primitives.h.

80 {
81 auto bare_seed_span = std::visit([&](const auto s) { return s.get(); }, seed);
82 return get_PRF(bare_seed_span, nonce).output<KyberSamplingRandomness>(outlen);
83 }
virtual Botan::XOF & get_PRF(std::span< const uint8_t > seed, uint8_t nonce) const =0
T output(size_t bytes)
Definition xof.h:155
Strong< secure_vector< uint8_t >, struct KyberSamplingRandomness_ > KyberSamplingRandomness
PRF value used for sampling of error polynomials.
Definition kyber_types.h:51

References Botan::Kyber_Symmetric_Primitives::get_PRF(), and Botan::XOF::output().

◆ 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 70 of file ml_kem_impl.h.

70 {
71 // NIST FIPS 203, Algorithm 13 (K-PKE.KeyGen)
72 // Byte 33 of the input to G is the module dimension k from {2,3,4}.
73 // This is included to establish domain separation between the three
74 // parameter sets
75 return std::array{mode.k()};
76 }

References Botan::KyberConstants::k().

◆ XOF()

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

Definition at line 85 of file kyber_symmetric_primitives.h.

85 {
86 return get_XOF(seed, matrix_position);
87 }
virtual Botan::XOF & get_XOF(std::span< const uint8_t > seed, std::tuple< uint8_t, uint8_t > matrix_position) const =0

References Botan::Kyber_Symmetric_Primitives::get_XOF().

Referenced by Botan::Kyber_Algos::sample_matrix().


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