Botan 3.6.1
Crypto and TLS for C&
tls_algos.h
Go to the documentation of this file.
1/*
2* (C) 2017 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#ifndef BOTAN_TLS_ALGO_IDS_H_
8#define BOTAN_TLS_ALGO_IDS_H_
9
10#include <botan/asn1_obj.h>
11#include <botan/pk_keys.h>
12#include <botan/types.h>
13#include <optional>
14#include <string>
15#include <vector>
16
17//BOTAN_FUTURE_INTERNAL_HEADER(tls_algos.h)
18
19namespace Botan::TLS {
20
48
49enum class KDF_Algo {
50 SHA_1,
51 SHA_256,
52 SHA_384,
53};
54
55std::string BOTAN_DLL kdf_algo_to_string(KDF_Algo algo);
56
57enum class Nonce_Format {
61};
62
63// TODO encoding should match signature_algorithms extension
64// TODO this should include hash etc as in TLS v1.3
65enum class Auth_Method {
66 RSA,
67 ECDSA,
68
69 // To support TLS 1.3 ciphersuites, which do not determine the auth method
71
72 // These are placed outside the encodable range
73 IMPLICIT = 0x10000
74};
75
78
79#define BOTAN_TLS_KYBER_R3_DEPRECATED \
80 BOTAN_DEPRECATED( \
81 "Kyber r3 TLS support will be removed completely in Botan 3.7.0 (early 2025) see https://github.com/randombit/botan/issues/4403")
82
83/*
84* Matches with wire encoding
85*/
86enum class Group_Params_Code : uint16_t {
87 NONE = 0,
88
89 SECP256R1 = 23,
90 SECP384R1 = 24,
91 SECP521R1 = 25,
92 BRAINPOOL256R1 = 26,
93 BRAINPOOL384R1 = 27,
94 BRAINPOOL512R1 = 28,
95
96 X25519 = 29,
97 X448 = 30,
98
99 FFDHE_2048 = 256,
100 FFDHE_3072 = 257,
101 FFDHE_4096 = 258,
102 FFDHE_6144 = 259,
103 FFDHE_8192 = 260,
104
105 // libOQS defines those in:
106 // https://github.com/open-quantum-safe/oqs-provider/blob/main/ALGORITHMS.md
110
114 eFRODOKEM_640_AES_OQS = 0x0200,
115 eFRODOKEM_976_AES_OQS = 0x0202,
116 eFRODOKEM_1344_AES_OQS = 0x0204,
117
118 // Cloudflare code points for hybrid PQC
119 // https://blog.cloudflare.com/post-quantum-for-all/
121
122 // libOQS defines those in:
123 // https://github.com/open-quantum-safe/oqs-provider/blob/main/ALGORITHMS.md
124 //
125 // X25519/Kyber768 is also defined in:
126 // https://datatracker.ietf.org/doc/draft-tls-westerbaan-xyber768d00/03/
129
130 // https://datatracker.ietf.org/doc/draft-kwiatkowski-tls-ecdhe-mlkem/02/
133
135
138
140
142
145
148
151
154
157};
158
160 public:
161 using enum Group_Params_Code;
162
163 constexpr Group_Params() : m_code(Group_Params_Code::NONE) {}
164
165 constexpr Group_Params(Group_Params_Code code) : m_code(code) {}
166
167 constexpr Group_Params(uint16_t code) : m_code(static_cast<Group_Params_Code>(code)) {}
168
169 /**
170 * @returns std::nullopt if an unknown name
171 */
172 static std::optional<Group_Params> from_string(std::string_view group_name);
173
174 constexpr bool operator==(Group_Params_Code code) const { return m_code == code; }
175
176 constexpr bool operator==(Group_Params other) const { return m_code == other.m_code; }
177
178 constexpr bool operator<(Group_Params other) const { return m_code < other.m_code; }
179
180 constexpr Group_Params_Code code() const { return m_code; }
181
182 constexpr uint16_t wire_code() const { return static_cast<uint16_t>(m_code); }
183
184 constexpr bool is_x25519() const { return m_code == Group_Params_Code::X25519; }
185
186 constexpr bool is_x448() const { return m_code == Group_Params_Code::X448; }
187
188 constexpr bool is_ecdh_named_curve() const {
189 return m_code == Group_Params_Code::SECP256R1 || m_code == Group_Params_Code::SECP384R1 ||
190 m_code == Group_Params_Code::SECP521R1 || m_code == Group_Params_Code::BRAINPOOL256R1 ||
191 m_code == Group_Params_Code::BRAINPOOL384R1 || m_code == Group_Params_Code::BRAINPOOL512R1;
192 }
193
194 constexpr bool is_in_ffdhe_range() const {
195 // See RFC 7919
196 return wire_code() >= 256 && wire_code() < 512;
197 }
198
199 constexpr bool is_dh_named_group() const {
200 return m_code == Group_Params_Code::FFDHE_2048 || m_code == Group_Params_Code::FFDHE_3072 ||
201 m_code == Group_Params_Code::FFDHE_4096 || m_code == Group_Params_Code::FFDHE_6144 ||
202 m_code == Group_Params_Code::FFDHE_8192;
203 }
204
208
209 return m_code == Group_Params_Code::KYBER_512_R3_OQS || m_code == Group_Params_Code::KYBER_768_R3_OQS ||
210 m_code == Group_Params_Code::KYBER_1024_R3_OQS;
211
213 }
214
215 constexpr bool is_pure_frodokem() const {
216 return m_code == Group_Params_Code::eFRODOKEM_640_SHAKE_OQS ||
217 m_code == Group_Params_Code::eFRODOKEM_976_SHAKE_OQS ||
218 m_code == Group_Params_Code::eFRODOKEM_1344_SHAKE_OQS ||
219 m_code == Group_Params_Code::eFRODOKEM_640_AES_OQS ||
220 m_code == Group_Params_Code::eFRODOKEM_976_AES_OQS ||
221 m_code == Group_Params_Code::eFRODOKEM_1344_AES_OQS;
222 }
223
224 constexpr bool is_pure_ecc_group() const { return is_x25519() || is_x448() || is_ecdh_named_curve(); }
225
226 constexpr bool is_post_quantum() const {
229
230 return is_pure_kyber() || is_pure_frodokem() || is_pqc_hybrid();
231
233 }
234
235 constexpr bool is_pqc_hybrid() const {
238
239 return m_code == Group_Params_Code::HYBRID_SECP256R1_ML_KEM_768 ||
240 m_code == Group_Params_Code::HYBRID_X25519_ML_KEM_768 ||
241 m_code == Group_Params_Code::HYBRID_X25519_KYBER_512_R3_CLOUDFLARE ||
242 m_code == Group_Params_Code::HYBRID_X25519_KYBER_512_R3_OQS ||
243 m_code == Group_Params_Code::HYBRID_X25519_KYBER_768_R3_OQS ||
244 m_code == Group_Params_Code::HYBRID_X448_KYBER_768_R3_OQS ||
245 m_code == Group_Params_Code::HYBRID_X25519_eFRODOKEM_640_SHAKE_OQS ||
246 m_code == Group_Params_Code::HYBRID_X25519_eFRODOKEM_640_AES_OQS ||
247 m_code == Group_Params_Code::HYBRID_X448_eFRODOKEM_976_SHAKE_OQS ||
248 m_code == Group_Params_Code::HYBRID_X448_eFRODOKEM_976_AES_OQS ||
249 m_code == Group_Params_Code::HYBRID_SECP256R1_KYBER_512_R3_OQS ||
250 m_code == Group_Params_Code::HYBRID_SECP256R1_KYBER_768_R3_OQS ||
251 m_code == Group_Params_Code::HYBRID_SECP256R1_eFRODOKEM_640_SHAKE_OQS ||
252 m_code == Group_Params_Code::HYBRID_SECP256R1_eFRODOKEM_640_AES_OQS ||
253 m_code == Group_Params_Code::HYBRID_SECP384R1_KYBER_768_R3_OQS ||
254 m_code == Group_Params_Code::HYBRID_SECP384R1_eFRODOKEM_976_SHAKE_OQS ||
255 m_code == Group_Params_Code::HYBRID_SECP384R1_eFRODOKEM_976_AES_OQS ||
256 m_code == Group_Params_Code::HYBRID_SECP521R1_KYBER_1024_R3_OQS ||
257 m_code == Group_Params_Code::HYBRID_SECP521R1_eFRODOKEM_1344_SHAKE_OQS ||
258 m_code == Group_Params_Code::HYBRID_SECP521R1_eFRODOKEM_1344_AES_OQS;
259
261 }
262
263 constexpr bool is_kem() const {
266
267 return is_pure_kyber() || is_pure_frodokem() || is_pqc_hybrid();
268
270 }
271
272 // Returns std::nullopt if the param has no known name
273 std::optional<std::string> to_string() const;
274
275 private:
276 Group_Params_Code m_code;
277};
278
279enum class Kex_Algo {
281 DH,
282 ECDH,
283 PSK,
284 ECDHE_PSK,
285 DHE_PSK,
286 KEM,
287 KEM_PSK,
288 HYBRID,
290
291 // To support TLS 1.3 ciphersuites, which do not determine the kex algo
293};
294
297
299 return (m == Kex_Algo::PSK || m == Kex_Algo::ECDHE_PSK || m == Kex_Algo::DHE_PSK);
300}
301
302} // namespace Botan::TLS
303
304#endif
constexpr bool operator==(Group_Params other) const
Definition tls_algos.h:176
constexpr bool is_dh_named_group() const
Definition tls_algos.h:199
constexpr bool is_in_ffdhe_range() const
Definition tls_algos.h:194
constexpr bool operator<(Group_Params other) const
Definition tls_algos.h:178
constexpr bool is_pqc_hybrid() const
Definition tls_algos.h:235
constexpr bool is_kem() const
Definition tls_algos.h:263
constexpr bool is_post_quantum() const
Definition tls_algos.h:226
constexpr bool operator==(Group_Params_Code code) const
Definition tls_algos.h:174
constexpr bool is_ecdh_named_curve() const
Definition tls_algos.h:188
constexpr uint16_t wire_code() const
Definition tls_algos.h:182
constexpr bool is_pure_frodokem() const
Definition tls_algos.h:215
constexpr bool is_pure_kyber() const
Definition tls_algos.h:205
constexpr Group_Params_Code code() const
Definition tls_algos.h:180
constexpr Group_Params(uint16_t code)
Definition tls_algos.h:167
constexpr Group_Params(Group_Params_Code code)
Definition tls_algos.h:165
constexpr bool is_x448() const
Definition tls_algos.h:186
constexpr bool is_pure_ecc_group() const
Definition tls_algos.h:224
constexpr bool is_x25519() const
Definition tls_algos.h:184
int(* final)(unsigned char *, CTX *)
#define BOTAN_DIAGNOSTIC_POP
Definition compiler.h:191
#define BOTAN_DIAGNOSTIC_PUSH
Definition compiler.h:188
#define BOTAN_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
Definition compiler.h:189
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31
#define BOTAN_TEST_API
Definition compiler.h:51
#define BOTAN_DLL
Definition build.h:85
Kex_Algo kex_method_from_string(std::string_view str)
Definition tls_algos.cpp:57
Auth_Method auth_method_from_string(std::string_view str)
std::string kdf_algo_to_string(KDF_Algo algo)
Definition tls_algos.cpp:15
std::string kex_method_to_string(Kex_Algo method)
Definition tls_algos.cpp:28
bool key_exchange_is_psk(Kex_Algo m)
Definition tls_algos.h:298
std::string auth_method_to_string(Auth_Method method)
@ NONE
Definition filter.h:165
#define BOTAN_TLS_KYBER_R3_DEPRECATED
Definition tls_algos.h:79