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

#include <kyber_modern.h>

Inheritance diagram for Botan::Kyber_Modern_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 &) const override

Detailed Description

Definition at line 22 of file kyber_modern.h.

Member Function Documentation

◆ create_G()

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

Implements Botan::Kyber_Symmetric_Primitives.

Definition at line 29 of file kyber_modern.h.

29{ 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::Kyber_Modern_Symmetric_Primitives::create_H ( ) const
inlineoverrideprotectedvirtual

Implements Botan::Kyber_Symmetric_Primitives.

Definition at line 31 of file kyber_modern.h.

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

References Botan::HashFunction::create_or_throw().

◆ create_J()

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

Implements Botan::Kyber_Symmetric_Primitives.

Definition at line 33 of file kyber_modern.h.

33{ throw Invalid_State("Kyber-R3 does not support J()"); }

◆ create_KDF()

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

Implements Botan::Kyber_Symmetric_Primitives.

Definition at line 35 of file kyber_modern.h.

35 {
36 return HashFunction::create_or_throw("SHAKE-256(256)");
37 }

References Botan::HashFunction::create_or_throw().

◆ create_PRF()

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

Implements Botan::Kyber_Symmetric_Primitives.

Definition at line 39 of file kyber_modern.h.

39 {
40 auto xof = Botan::XOF::create_or_throw("SHAKE-256");
41 init_PRF(*xof, seed, nonce);
42 return xof;
43 }
void init_PRF(Botan::XOF &xof, std::span< const uint8_t > seed, const uint8_t nonce) const override
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::Kyber_Modern_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 51 of file kyber_modern.h.

52 {
53 auto xof = Botan::XOF::create_or_throw("SHAKE-128");
54 init_XOF(*xof, seed, matrix_position);
55 return xof;
56 }
void init_XOF(Botan::XOF &xof, std::span< const uint8_t > seed, std::tuple< uint8_t, uint8_t > matrix_position) const override

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::Kyber_Modern_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 45 of file kyber_modern.h.

45 {
46 xof.clear();
47 xof.update(seed);
48 xof.update({&nonce, 1});
49 }
void clear()
Definition xof.h:64
void update(std::span< const uint8_t > input)
Definition xof.h:140

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

Referenced by create_PRF().

◆ init_XOF()

void Botan::Kyber_Modern_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 58 of file kyber_modern.h.

60 {
61 xof.clear();
62 xof.update(seed);
63
64 const std::array<uint8_t, 2> pos = {std::get<0>(matrix_position), std::get<1>(matrix_position)};
65 xof.update(pos);
66 }

References Botan::XOF::clear(), 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::Kyber_Modern_Symmetric_Primitives::seed_expansion_domain_separator ( const KyberConstants & ) const
inlineoverrideprotectedvirtual

Implements Botan::Kyber_Symmetric_Primitives.

Definition at line 24 of file kyber_modern.h.

25 {
26 return {};
27 }

◆ 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: