Botan 3.6.1
Crypto and TLS for C&
kyber_keys.h
Go to the documentation of this file.
1/*
2 * Crystals Kyber Internal Key Types
3 *
4 * (C) 2021-2024 Jack Lloyd
5 * (C) 2021-2022 Manuel Glaser and Michael Boric, Rohde & Schwarz Cybersecurity
6 * (C) 2021-2022 René Meusel and Hannes Rantzsch, neXenio GmbH
7 * (C) 2024 René Meusel, Rohde & Schwarz Cybersecurity
8 *
9 * Botan is released under the Simplified BSD License (see license.txt)
10 */
11
12#ifndef BOTAN_KYBER_INTERNAL_KEYS_H_
13#define BOTAN_KYBER_INTERNAL_KEYS_H_
14
15#include <botan/internal/ct_utils.h>
16#include <botan/internal/kyber_algos.h>
17#include <botan/internal/kyber_constants.h>
18#include <botan/internal/kyber_types.h>
19
20namespace Botan {
21
23 public:
24 virtual ~Kyber_Keypair_Codec() = default;
26 virtual KyberInternalKeypair decode_keypair(std::span<const uint8_t> private_key, KyberConstants mode) const = 0;
27};
28
30 public:
33
37 const KyberPolyMat& At) const;
38
41 const KyberPolyMat& At) const {
43 indcpa_encrypt(ct, m, r, At);
44 return ct;
45 }
46
47 const KyberPolyVecNTT& t() const { return m_t; }
48
49 const KyberSeedRho& rho() const { return m_rho; }
50
51 const KyberConstants& mode() const { return m_mode; }
52
53 const KyberSerializedPublicKey& public_key_bits_raw() const { return m_public_key_bits_raw; }
54
55 const KyberHashedPublicKey& H_public_key_bits_raw() const { return m_H_public_key_bits_raw; }
56
58
59 private:
60 const KyberConstants m_mode;
61 const KyberSerializedPublicKey m_public_key_bits_raw;
62 const KyberHashedPublicKey m_H_public_key_bits_raw;
64 const KyberSeedRho m_rho;
65};
66
68 public:
70 m_mode(std::move(mode)), m_s(std::move(s)), m_seed(std::move(seed)) {}
71
73
74 KyberPolyVecNTT& s() { return m_s; }
75
76 const KyberPolyVecNTT& s() const { return m_s; }
77
78 const KyberPrivateKeySeed& seed() const { return m_seed; }
79
80 const KyberImplicitRejectionValue& z() const { return m_seed.z; }
81
82 const KyberConstants& mode() const { return m_mode; }
83
85
86 void _const_time_poison() const { CT::poison_all(m_s, m_seed.d, m_seed.z); }
87
88 void _const_time_unpoison() const { CT::unpoison_all(m_s, m_seed.d, m_seed.z); }
89
90 private:
91 KyberConstants m_mode;
94};
95
96} // namespace Botan
97
98#endif
size_t ciphertext_bytes() const
byte length of an encoded ciphertext
virtual secure_vector< uint8_t > encode_keypair(KyberInternalKeypair keypair) const =0
virtual KyberInternalKeypair decode_keypair(std::span< const uint8_t > private_key, KyberConstants mode) const =0
virtual ~Kyber_Keypair_Codec()=default
KyberMessage indcpa_decrypt(StrongSpan< const KyberCompressedCiphertext > ct) const
const KyberConstants & mode() const
Definition kyber_keys.h:82
const KyberPrivateKeySeed & seed() const
Definition kyber_keys.h:78
Kyber_PrivateKeyInternal(KyberConstants mode, KyberPolyVecNTT s, KyberPrivateKeySeed seed)
Definition kyber_keys.h:69
const KyberPolyVecNTT & s() const
Definition kyber_keys.h:76
const KyberImplicitRejectionValue & z() const
Definition kyber_keys.h:80
const KyberHashedPublicKey & H_public_key_bits_raw() const
Definition kyber_keys.h:55
const KyberPolyVecNTT & t() const
Definition kyber_keys.h:47
KyberCompressedCiphertext indcpa_encrypt(const KyberMessage &m, const KyberEncryptionRandomness &r, const KyberPolyMat &At) const
Definition kyber_keys.h:39
const KyberSeedRho & rho() const
Definition kyber_keys.h:49
void indcpa_encrypt(StrongSpan< KyberCompressedCiphertext > out_ct, StrongSpan< const KyberMessage > m, StrongSpan< const KyberEncryptionRandomness > r, const KyberPolyMat &At) const
const KyberConstants & mode() const
Definition kyber_keys.h:51
const KyberSerializedPublicKey & public_key_bits_raw() const
Definition kyber_keys.h:53
constexpr void unpoison_all(Ts &&... ts)
Definition ct_utils.h:201
constexpr void poison_all(Ts &&... ts)
Definition ct_utils.h:195
std::pair< std::shared_ptr< Kyber_PublicKeyInternal >, std::shared_ptr< Kyber_PrivateKeyInternal > > KyberInternalKeypair
Definition kyber_types.h:73
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61
KyberImplicitRejectionValue z
Definition kyber_types.h:81
std::optional< KyberSeedRandomness > d
Definition kyber_types.h:80