Botan 3.5.0
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
17#include <botan/internal/kyber_types.h>
18
19namespace Botan {
20
21class Kyber_Symmetric_Primitives;
22
24 public:
25 static constexpr size_t N = 256;
26 static constexpr size_t Q = 3329;
27 static constexpr size_t Q_Inv = 62209;
28
29 static constexpr int16_t zetas[128] = {
30 2285, 2571, 2970, 1812, 1493, 1422, 287, 202, 3158, 622, 1577, 182, 962, 2127, 1855, 1468,
31 573, 2004, 264, 383, 2500, 1458, 1727, 3199, 2648, 1017, 732, 608, 1787, 411, 3124, 1758,
32 1223, 652, 2777, 1015, 2036, 1491, 3047, 1785, 516, 3321, 3009, 2663, 1711, 2167, 126, 1469,
33 2476, 3239, 3058, 830, 107, 1908, 3082, 2378, 2931, 961, 1821, 2604, 448, 2264, 677, 2054,
34 2226, 430, 555, 843, 2078, 871, 1550, 105, 422, 587, 177, 3094, 3038, 2869, 1574, 1653,
35 3083, 778, 1159, 3182, 2552, 1483, 2727, 1119, 1739, 644, 2457, 349, 418, 329, 3173, 3254,
36 817, 1097, 603, 610, 1322, 2044, 1864, 384, 2114, 3193, 1218, 1994, 2455, 220, 2142, 1670,
37 2144, 1799, 2051, 794, 1819, 2475, 2459, 478, 3221, 3021, 996, 991, 958, 1869, 1522, 1628};
38
39 static constexpr int16_t zetas_inv[128] = {
40 1701, 1807, 1460, 2371, 2338, 2333, 308, 108, 2851, 870, 854, 1510, 2535, 1278, 1530, 1185,
41 1659, 1187, 3109, 874, 1335, 2111, 136, 1215, 2945, 1465, 1285, 2007, 2719, 2726, 2232, 2512,
42 75, 156, 3000, 2911, 2980, 872, 2685, 1590, 2210, 602, 1846, 777, 147, 2170, 2551, 246,
43 1676, 1755, 460, 291, 235, 3152, 2742, 2907, 3224, 1779, 2458, 1251, 2486, 2774, 2899, 1103,
44 1275, 2652, 1065, 2881, 725, 1508, 2368, 398, 951, 247, 1421, 3222, 2499, 271, 90, 853,
45 1860, 3203, 1162, 1618, 666, 320, 8, 2813, 1544, 282, 1838, 1293, 2314, 552, 2677, 2106,
46 1571, 205, 2918, 1542, 2721, 2597, 2312, 681, 130, 1602, 1871, 829, 2946, 3065, 1325, 2756,
47 1861, 1474, 1202, 2367, 3147, 1752, 2707, 171, 3127, 3042, 1907, 1836, 1517, 359, 758, 1441};
48
49 static constexpr size_t kSymBytes = 32;
50 static constexpr size_t kSeedLength = kSymBytes;
51 static constexpr size_t kSerializedPolynomialByteLength = N / 2 * 3;
52 static constexpr size_t kPublicKeyHashLength = 32;
53 static constexpr size_t kZLength = kSymBytes;
54
55 public:
57
59
60 KyberConstants(const KyberConstants& other) : KyberConstants(other.m_mode) {}
61
62 KyberConstants(KyberConstants&& other) = default;
63 KyberConstants& operator=(const KyberConstants& other) = delete;
65
66 KyberMode mode() const { return m_mode; }
67
68 size_t estimated_strength() const { return m_nist_strength; }
69
70 uint8_t k() const { return m_k; }
71
72 uint8_t eta1() const { return m_eta1; }
73
74 uint8_t eta2() const { return 2; }
75
77
78 size_t polynomial_vector_compressed_bytes() const { return (m_k == 2 || m_k == 3) ? m_k * 320 : m_k * 352; }
79
80 size_t polynomial_compressed_bytes() const { return (m_k == 2 || m_k == 3) ? 128 : 160; }
81
83
87
88 size_t shared_key_length() const { return 32; }
89
93
94 Kyber_Symmetric_Primitives& symmetric_primitives() const { return *m_symmetric_primitives; }
95
96 private:
97 KyberMode m_mode;
98 std::unique_ptr<Kyber_Symmetric_Primitives> m_symmetric_primitives;
99 size_t m_nist_strength;
100 uint8_t m_k;
101 uint8_t m_eta1;
102};
103
104} // namespace Botan
105
106#endif
size_t polynomial_vector_compressed_bytes() const
size_t polynomial_compressed_bytes() const
size_t private_key_byte_length() const
static constexpr int16_t zetas_inv[128]
static constexpr size_t Q_Inv
static constexpr size_t kPublicKeyHashLength
KyberConstants & operator=(const KyberConstants &other)=delete
static constexpr size_t kSerializedPolynomialByteLength
size_t shared_key_length() const
KyberConstants & operator=(KyberConstants &&other)=default
static constexpr size_t kZLength
size_t public_key_byte_length() const
KyberConstants(KyberMode mode)
static constexpr size_t kSeedLength
static constexpr int16_t zetas[128]
KyberConstants(KyberConstants &&other)=default
size_t encapsulated_key_length() const
static constexpr size_t N
KyberConstants(const KyberConstants &other)
size_t polynomial_vector_byte_length() const
size_t estimated_strength() const
static constexpr size_t kSymBytes
KyberMode mode() const
Kyber_Symmetric_Primitives & symmetric_primitives() const
static constexpr size_t Q
int(* final)(unsigned char *, CTX *)