Botan 3.6.1
Crypto and TLS for C&
kyber_constants.h
Go to the documentation of this file.
1/*
2 * Crystals Kyber Constants
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_CONSTANTS_H_
13#define BOTAN_KYBER_CONSTANTS_H_
14
15#include <botan/kyber.h>
16
17namespace Botan {
18
19class Kyber_Symmetric_Primitives;
20class Kyber_Keypair_Codec;
21
23 public:
24 /// base data type for most calculations
25 using T = int16_t;
26
27 /// number of coefficients in a polynomial
28 static constexpr T N = 256;
29
30 /// modulus
31 static constexpr T Q = 3329;
32
33 /// as specified in FIPS 203 (see Algorithm 10 (NTT^-1), f = 128^-1 mod Q)
34 static constexpr T F = 3303;
35
36 /// the primitive 256-th root of unity modulo Q (see FIPS 203 Section 4.3)
37 static constexpr T ROOT_OF_UNITY = 17;
38
39 /// degree of the NTT polynomials
40 static constexpr size_t NTT_Degree = 128;
41
42 public:
43 static constexpr size_t SEED_BYTES = 32;
44 static constexpr size_t PUBLIC_KEY_HASH_BYTES = 32;
45 static constexpr size_t SHARED_KEY_BYTES = 32;
46
47 /// sampling limit for SampleNTT (in bytes), see FIPS 204, Apx B
48 static constexpr uint16_t SAMPLE_NTT_POLY_FROM_XOF_BOUND = 280 * 3 /* XOF bytes per while iteration */;
49
50 public:
51 enum KyberEta : uint8_t { _2 = 2, _3 = 3 };
52
53 enum KyberDu : uint8_t { _10 = 10, _11 = 11 };
54
55 enum KyberDv : uint8_t { _4 = 4, _5 = 5 };
56
57 enum KyberStrength : uint32_t { _128 = 128, _192 = 192, _256 = 256 };
58
59 public:
61
63
64 KyberConstants(const KyberConstants& other) : KyberConstants(other.m_mode) {}
65
66 KyberConstants(KyberConstants&& other) = default;
67 KyberConstants& operator=(const KyberConstants& other) = delete;
69
70 KyberMode mode() const { return m_mode; }
71
72 /// @returns one of {512, 768, 1024}
73 size_t canonical_parameter_set_identifier() const { return k() * N; }
74
75 /// \name Foundational constants
76 /// @{
77
78 uint8_t k() const { return m_k; }
79
80 KyberEta eta1() const { return m_eta1; }
81
82 constexpr KyberEta eta2() const { return KyberEta::_2; }
83
84 KyberDu d_u() const { return m_du; }
85
86 KyberDv d_v() const { return m_dv; }
87
88 KyberStrength estimated_strength() const { return m_nist_strength; }
89
90 /// @}
91
92 /// \name Sizes of encoded data structures
93 /// @{
94
95 /// byte length of an encoded polynomial vector
96 size_t polynomial_vector_bytes() const { return m_polynomial_vector_bytes; }
97
98 /// byte length of an encoded compressed polynomial vector
99 size_t polynomial_vector_compressed_bytes() const { return m_polynomial_vector_compressed_bytes; }
100
101 /// byte length of an encoded compressed polynomial
102 size_t polynomial_compressed_bytes() const { return m_polynomial_compressed_bytes; }
103
104 /// byte length of an encoded ciphertext
106
107 /// byte length of the shared key
108 constexpr size_t shared_key_bytes() const { return SHARED_KEY_BYTES; }
109
110 /// byte length of an encoded public key
112
113 /// byte length of an encoded private key
114 size_t private_key_bytes() const { return m_private_key_bytes; }
115
116 /// @}
117
118 Kyber_Symmetric_Primitives& symmetric_primitives() const { return *m_symmetric_primitives; }
119
120 Kyber_Keypair_Codec& keypair_codec() const { return *m_keypair_codec; }
121
122 private:
123 KyberMode m_mode;
124
125 KyberStrength m_nist_strength;
126 KyberEta m_eta1;
127 KyberDu m_du;
128 KyberDv m_dv;
129 uint8_t m_k;
130
131 uint32_t m_polynomial_vector_bytes;
132 uint32_t m_polynomial_vector_compressed_bytes;
133 uint32_t m_polynomial_compressed_bytes;
134 uint32_t m_private_key_bytes;
135
136 std::unique_ptr<Kyber_Keypair_Codec> m_keypair_codec;
137 std::unique_ptr<Kyber_Symmetric_Primitives> m_symmetric_primitives;
138};
139
140} // namespace Botan
141
142#endif
size_t polynomial_vector_compressed_bytes() const
byte length of an encoded compressed polynomial vector
static constexpr T N
number of coefficients in a polynomial
constexpr KyberEta eta2() const
size_t polynomial_compressed_bytes() const
byte length of an encoded compressed polynomial
static constexpr T Q
modulus
KyberConstants & operator=(const KyberConstants &other)=delete
static constexpr size_t SEED_BYTES
static constexpr T ROOT_OF_UNITY
the primitive 256-th root of unity modulo Q (see FIPS 203 Section 4.3)
size_t public_key_bytes() const
byte length of an encoded public key
KyberConstants & operator=(KyberConstants &&other)=default
static constexpr T F
as specified in FIPS 203 (see Algorithm 10 (NTT^-1), f = 128^-1 mod Q)
static constexpr uint16_t SAMPLE_NTT_POLY_FROM_XOF_BOUND
sampling limit for SampleNTT (in bytes), see FIPS 204, Apx B
KyberConstants(KyberMode mode)
size_t polynomial_vector_bytes() const
byte length of an encoded polynomial vector
constexpr size_t shared_key_bytes() const
byte length of the shared key
size_t private_key_bytes() const
byte length of an encoded private key
size_t ciphertext_bytes() const
byte length of an encoded ciphertext
static constexpr size_t SHARED_KEY_BYTES
static constexpr size_t NTT_Degree
degree of the NTT polynomials
KyberStrength estimated_strength() const
Kyber_Keypair_Codec & keypair_codec() const
KyberConstants(KyberConstants &&other)=default
KyberConstants(const KyberConstants &other)
KyberMode mode() const
KyberEta eta1() const
Kyber_Symmetric_Primitives & symmetric_primitives() const
int16_t T
base data type for most calculations
size_t canonical_parameter_set_identifier() const
static constexpr size_t PUBLIC_KEY_HASH_BYTES
int(* final)(unsigned char *, CTX *)