Botan 3.7.1
Crypto and TLS for C&
cmce_parameters.cpp
Go to the documentation of this file.
1/*
2 * Classic McEliece Parameters
3 * (C) 2023 Jack Lloyd
4 * 2023,2024 Fabian Albert, Amos Treiber - Rohde & Schwarz Cybersecurity
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 **/
8
9#include <botan/internal/cmce_parameters.h>
10#include <botan/internal/cmce_poly.h>
11
12namespace Botan {
13
14namespace {
15
16CmceGfMod determine_poly_f(Classic_McEliece_Parameter_Set param_set) {
17 switch(param_set.code()) {
20 // z^12 + z^3 + 1
21 return CmceGfMod(0b0001000000001001);
36 // z^12 + z^3 + 1
37 return CmceGfMod(0b0010000000011011);
38 }
40}
41
42Classic_McEliece_Polynomial_Ring determine_poly_ring(Classic_McEliece_Parameter_Set param_set) {
43 CmceGfMod poly_f = determine_poly_f(param_set);
44
45 switch(param_set.code()) {
48 // y^64 + y^3 + y + z
49 return {{{3, Classic_McEliece_GF(CmceGfElem(1), poly_f)},
50 {1, Classic_McEliece_GF(CmceGfElem(1), poly_f)},
51 {0, Classic_McEliece_GF(CmceGfElem(2), poly_f)}},
52 poly_f,
53 64};
56 // y^96 + y^10 + y^9 + y^6 + 1
57 return {{{10, Classic_McEliece_GF(CmceGfElem(1), poly_f)},
58 {9, Classic_McEliece_GF(CmceGfElem(1), poly_f)},
59 {6, Classic_McEliece_GF(CmceGfElem(1), poly_f)},
60 {0, Classic_McEliece_GF(CmceGfElem(1), poly_f)}},
61 poly_f,
62 96};
67 // y^119 + y^8 + 1
68 // clang-format off
69 return {{{8, Classic_McEliece_GF(CmceGfElem(1), poly_f)},
70 {0, Classic_McEliece_GF(CmceGfElem(1), poly_f)}},
71 poly_f,
72 119};
73 // clang-format on
82 // y^128 + y^7 + y^2 + y + 1
83 return {{{7, Classic_McEliece_GF(CmceGfElem(1), poly_f)},
84 {2, Classic_McEliece_GF(CmceGfElem(1), poly_f)},
85 {1, Classic_McEliece_GF(CmceGfElem(1), poly_f)},
86 {0, Classic_McEliece_GF(CmceGfElem(1), poly_f)}},
87 poly_f,
88 128};
89 }
91}
92
93} //namespace
94
96 auto poly_ring = determine_poly_ring(set);
97
98 switch(set.code()) {
101 return Classic_McEliece_Parameters(set, 12, 3488, std::move(poly_ring));
102
105 return Classic_McEliece_Parameters(set, 13, 4608, std::move(poly_ring));
106
111 return Classic_McEliece_Parameters(set, 13, 6688, std::move(poly_ring));
112
117 return Classic_McEliece_Parameters(set, 13, 6960, std::move(poly_ring));
118
123 return Classic_McEliece_Parameters(set, 13, 8192, std::move(poly_ring));
124 }
126}
127
131
135
139
140Classic_McEliece_Parameters::Classic_McEliece_Parameters(Classic_McEliece_Parameter_Set param_set,
141 size_t m,
142 size_t n,
144 m_set(param_set), m_m(m), m_n(n), m_poly_ring(std::move(poly_ring)) {
145 BOTAN_ASSERT(n % 8 == 0, "We require that n is a multiple of 8");
146}
147
149 // Classic McEliece NIST Round 4 submission, Guide for security reviewers, Table 1:
150 // For each instance, the minimal strength against the best attack (with free memory access)
151 // is used as the overall security strength estimate. The strength is capped at 256, since the
152 // seed is only 256 bits long.
153 switch(m_set.code()) {
156 return 140;
159 return 179;
164 return 246;
169 return 245;
174 return 256; // 275 in the document. Capped at 256 because of the seed length.
175 }
177}
178
179std::unique_ptr<XOF> Classic_McEliece_Parameters::prg(std::span<const uint8_t> seed) const {
180 BOTAN_ASSERT_EQUAL(seed.size(), 32, "Valid seed length");
181 auto xof = XOF::create_or_throw("SHAKE-256");
182
183 xof->update(std::array<uint8_t, 1>({64}));
184 xof->update(seed);
185
186 return xof;
187}
188
189} // namespace Botan
#define BOTAN_ASSERT_EQUAL(expr1, expr2, assertion_made)
Definition assert.h:68
#define BOTAN_ASSERT(expr, assertion_made)
Definition assert.h:50
#define BOTAN_ASSERT_UNREACHABLE()
Definition assert.h:137
std::string to_string() const
Get the parameter set name for a given parameter set.
static Classic_McEliece_Parameter_Set from_string(std::string_view param_name)
Get the parameter set for a given parameter set name.
Code code() const
Get the code for a given parameter set.
static Classic_McEliece_Parameter_Set from_oid(const OID &oid)
Get the parameter set for a given OID.
static Classic_McEliece_Parameters create(Classic_McEliece_Parameter_Set set)
Create Classic McEliece parameters from a parameter set.
size_t estimated_strength() const
The estimated bit security strength of the Classic McEliece instance.
OID object_identifier() const
The OID for the Classic McEliece instance.
std::unique_ptr< XOF > prg(std::span< const uint8_t > seed) const
Create a seeded XOF object representing Classic McEliece's PRG. See Classic McEliece ISO 9....
size_t n() const
The code length of the Classic McEliece instance.
const Classic_McEliece_Polynomial_Ring & poly_ring() const
The underlying polynomial ring.
Represents the polynomial ring GF(q)[y]/F(y) where F(y) is the modulus polynomial in GF(q)[y] of degr...
Definition cmce_poly.h:104
static OID from_string(std::string_view str)
Definition asn1_oid.cpp:86
static std::unique_ptr< XOF > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition xof.cpp:42
std::string name
Strong< uint16_t, struct CmceGfMod_ > CmceGfMod
Represents a GF(q) modulus.
Definition cmce_types.h:22
Strong< uint16_t, struct CmceGfElem_ > CmceGfElem
Represents a GF(q) element.
Definition cmce_types.h:19