Botan 3.4.0
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/*
80* Matches with wire encoding
81*/
82enum class Group_Params_Code : uint16_t {
83 NONE = 0,
84
85 SECP256R1 = 23,
86 SECP384R1 = 24,
87 SECP521R1 = 25,
88 BRAINPOOL256R1 = 26,
89 BRAINPOOL384R1 = 27,
90 BRAINPOOL512R1 = 28,
91
92 X25519 = 29,
93 X448 = 30,
94
95 FFDHE_2048 = 256,
96 FFDHE_3072 = 257,
97 FFDHE_4096 = 258,
98 FFDHE_6144 = 259,
99 FFDHE_8192 = 260,
100
101 // libOQS defines those in:
102 // https://github.com/open-quantum-safe/oqs-provider/blob/main/ALGORITHMS.md
103 KYBER_512_R3_OQS = 0x023A,
104 KYBER_768_R3_OQS = 0x023C,
105 KYBER_1024_R3_OQS = 0x023D,
106
110 eFRODOKEM_640_AES_OQS = 0x0200,
111 eFRODOKEM_976_AES_OQS = 0x0202,
112 eFRODOKEM_1344_AES_OQS = 0x0204,
113
114 // Cloudflare code points for hybrid PQC
115 // https://blog.cloudflare.com/post-quantum-for-all/
117
118 // libOQS defines those in:
119 // https://github.com/open-quantum-safe/oqs-provider/blob/main/ALGORITHMS.md
120 //
121 // X25519/Kyber768 is also defined in:
122 // https://datatracker.ietf.org/doc/draft-tls-westerbaan-xyber768d00/03/
125
127
130
132
134
137
140
143
146
149};
150
152 public:
153 using enum Group_Params_Code;
154
155 constexpr Group_Params() : m_code(Group_Params_Code::NONE) {}
156
157 constexpr Group_Params(Group_Params_Code code) : m_code(code) {}
158
159 constexpr Group_Params(uint16_t code) : m_code(static_cast<Group_Params_Code>(code)) {}
160
161 /**
162 * @returns std::nullopt if an unknown name
163 */
164 static std::optional<Group_Params> from_string(std::string_view group_name);
165
166 constexpr bool operator==(Group_Params_Code code) const { return m_code == code; }
167
168 constexpr bool operator==(Group_Params other) const { return m_code == other.m_code; }
169
170 constexpr bool operator<(Group_Params other) const { return m_code < other.m_code; }
171
172 constexpr Group_Params_Code code() const { return m_code; }
173
174 constexpr uint16_t wire_code() const { return static_cast<uint16_t>(m_code); }
175
176 constexpr bool is_x25519() const { return m_code == Group_Params_Code::X25519; }
177
178 constexpr bool is_x448() const { return m_code == Group_Params_Code::X448; }
179
180 constexpr bool is_ecdh_named_curve() const {
181 return m_code == Group_Params_Code::SECP256R1 || m_code == Group_Params_Code::SECP384R1 ||
182 m_code == Group_Params_Code::SECP521R1 || m_code == Group_Params_Code::BRAINPOOL256R1 ||
183 m_code == Group_Params_Code::BRAINPOOL384R1 || m_code == Group_Params_Code::BRAINPOOL512R1;
184 }
185
186 constexpr bool is_in_ffdhe_range() const {
187 // See RFC 7919
188 return wire_code() >= 256 && wire_code() < 512;
189 }
190
191 constexpr bool is_dh_named_group() const {
192 return m_code == Group_Params_Code::FFDHE_2048 || m_code == Group_Params_Code::FFDHE_3072 ||
193 m_code == Group_Params_Code::FFDHE_4096 || m_code == Group_Params_Code::FFDHE_6144 ||
194 m_code == Group_Params_Code::FFDHE_8192;
195 }
196
197 constexpr bool is_pure_kyber() const {
198 return m_code == Group_Params_Code::KYBER_512_R3_OQS || m_code == Group_Params_Code::KYBER_768_R3_OQS ||
199 m_code == Group_Params_Code::KYBER_1024_R3_OQS;
200 }
201
202 constexpr bool is_pure_frodokem() const {
203 return m_code == Group_Params_Code::eFRODOKEM_640_SHAKE_OQS ||
204 m_code == Group_Params_Code::eFRODOKEM_976_SHAKE_OQS ||
205 m_code == Group_Params_Code::eFRODOKEM_1344_SHAKE_OQS ||
206 m_code == Group_Params_Code::eFRODOKEM_640_AES_OQS ||
207 m_code == Group_Params_Code::eFRODOKEM_976_AES_OQS ||
208 m_code == Group_Params_Code::eFRODOKEM_1344_AES_OQS;
209 }
210
211 constexpr bool is_pure_ecc_group() const { return is_x25519() || is_x448() || is_ecdh_named_curve(); }
212
213 constexpr bool is_post_quantum() const { return is_pure_kyber() || is_pure_frodokem() || is_pqc_hybrid(); }
214
215 constexpr bool is_pqc_hybrid() const {
216 return m_code == Group_Params_Code::HYBRID_X25519_KYBER_512_R3_CLOUDFLARE ||
217 m_code == Group_Params_Code::HYBRID_X25519_KYBER_512_R3_OQS ||
218 m_code == Group_Params_Code::HYBRID_X25519_KYBER_768_R3_OQS ||
219 m_code == Group_Params_Code::HYBRID_X448_KYBER_768_R3_OQS ||
220 m_code == Group_Params_Code::HYBRID_X25519_eFRODOKEM_640_SHAKE_OQS ||
221 m_code == Group_Params_Code::HYBRID_X25519_eFRODOKEM_640_AES_OQS ||
222 m_code == Group_Params_Code::HYBRID_X448_eFRODOKEM_976_SHAKE_OQS ||
223 m_code == Group_Params_Code::HYBRID_X448_eFRODOKEM_976_AES_OQS ||
224 m_code == Group_Params_Code::HYBRID_SECP256R1_KYBER_512_R3_OQS ||
225 m_code == Group_Params_Code::HYBRID_SECP256R1_KYBER_768_R3_OQS ||
226 m_code == Group_Params_Code::HYBRID_SECP256R1_eFRODOKEM_640_SHAKE_OQS ||
227 m_code == Group_Params_Code::HYBRID_SECP256R1_eFRODOKEM_640_AES_OQS ||
228 m_code == Group_Params_Code::HYBRID_SECP384R1_KYBER_768_R3_OQS ||
229 m_code == Group_Params_Code::HYBRID_SECP384R1_eFRODOKEM_976_SHAKE_OQS ||
230 m_code == Group_Params_Code::HYBRID_SECP384R1_eFRODOKEM_976_AES_OQS ||
231 m_code == Group_Params_Code::HYBRID_SECP521R1_KYBER_1024_R3_OQS ||
232 m_code == Group_Params_Code::HYBRID_SECP521R1_eFRODOKEM_1344_SHAKE_OQS ||
233 m_code == Group_Params_Code::HYBRID_SECP521R1_eFRODOKEM_1344_AES_OQS;
234 }
235
236 constexpr bool is_kem() const { return is_pure_kyber() || is_pure_frodokem() || is_pqc_hybrid(); }
237
238 // Returns std::nullopt if the param has no known name
239 std::optional<std::string> to_string() const;
240
241 private:
242 Group_Params_Code m_code;
243};
244
245enum class Kex_Algo {
247 DH,
248 ECDH,
249 PSK,
250 ECDHE_PSK,
251 DHE_PSK,
252 KEM,
253 KEM_PSK,
254 HYBRID,
256
257 // To support TLS 1.3 ciphersuites, which do not determine the kex algo
259};
260
263
265 return (m == Kex_Algo::PSK || m == Kex_Algo::ECDHE_PSK || m == Kex_Algo::DHE_PSK);
266}
267
268} // namespace Botan::TLS
269
270#endif
constexpr bool operator==(Group_Params other) const
Definition tls_algos.h:168
constexpr bool is_dh_named_group() const
Definition tls_algos.h:191
constexpr bool is_in_ffdhe_range() const
Definition tls_algos.h:186
constexpr bool operator<(Group_Params other) const
Definition tls_algos.h:170
constexpr bool is_pqc_hybrid() const
Definition tls_algos.h:215
constexpr bool is_kem() const
Definition tls_algos.h:236
constexpr bool is_post_quantum() const
Definition tls_algos.h:213
constexpr bool operator==(Group_Params_Code code) const
Definition tls_algos.h:166
constexpr bool is_ecdh_named_curve() const
Definition tls_algos.h:180
constexpr uint16_t wire_code() const
Definition tls_algos.h:174
constexpr bool is_pure_frodokem() const
Definition tls_algos.h:202
constexpr bool is_pure_kyber() const
Definition tls_algos.h:197
constexpr Group_Params_Code code() const
Definition tls_algos.h:172
constexpr Group_Params(uint16_t code)
Definition tls_algos.h:159
constexpr Group_Params(Group_Params_Code code)
Definition tls_algos.h:157
constexpr bool is_x448() const
Definition tls_algos.h:178
constexpr bool is_pure_ecc_group() const
Definition tls_algos.h:211
constexpr bool is_x25519() const
Definition tls_algos.h:176
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31
#define BOTAN_TEST_API
Definition compiler.h:51
#define BOTAN_DLL
Definition build.h:64
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:264
std::string auth_method_to_string(Auth_Method method)
@ NONE
Definition filter.h:165