Botan 3.11.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/types.h>
11#include <optional>
12#include <string>
13
14//BOTAN_FUTURE_INTERNAL_HEADER(tls_algos.h)
15
16namespace Botan::TLS {
17
45
46enum class KDF_Algo : uint8_t {
50};
51
52std::string BOTAN_DLL kdf_algo_to_string(KDF_Algo algo);
53
60
61// TODO encoding should match signature_algorithms extension
62// TODO this should include hash etc as in TLS v1.3
63enum class Auth_Method : uint32_t {
64 RSA = 0,
65 ECDSA = 1,
66
67 // To support TLS 1.3 ciphersuites, which do not determine the auth method
69
70 // These are placed outside the encodable range
71 IMPLICIT = 0x10000
72};
73
76
77/*
78* Matches with wire encoding
79*/
80enum class Group_Params_Code : uint16_t {
81 NONE = 0,
82
89
90 X25519 = 29,
91 X448 = 30,
92
98
99 // https://datatracker.ietf.org/doc/draft-connolly-tls-mlkem-key-agreement/05/
100 ML_KEM_512 = 0x0200,
101 ML_KEM_768 = 0x0201,
102 ML_KEM_1024 = 0x0202,
103
104 // libOQS defines those in:
105 // https://github.com/open-quantum-safe/oqs-provider/blob/main/ALGORITHMS.md
106 // (last update: 6th June 2025 - matching oqs commit 9447f68)
113
114 // https://datatracker.ietf.org/doc/draft-kwiatkowski-tls-ecdhe-mlkem/03/
118
119 // https://github.com/open-quantum-safe/oqs-provider/blob/main/ALGORITHMS.md
120 // (last update: 6th June 2025 - matching oqs commit 9447f68)
123
126
129
132
135};
136
138 public:
139 using enum Group_Params_Code;
140
141 constexpr Group_Params() : m_code(Group_Params_Code::NONE) {}
142
143 // NOLINTNEXTLINE(*-explicit-conversions)
144 constexpr Group_Params(Group_Params_Code code) : m_code(code) {}
145
146 // NOLINTNEXTLINE(*-explicit-conversions)
147 constexpr Group_Params(uint16_t code) : m_code(static_cast<Group_Params_Code>(code)) {}
148
149 /**
150 * @returns std::nullopt if an unknown name
151 */
152 static std::optional<Group_Params> from_string(std::string_view group_name);
153
154 constexpr bool operator==(Group_Params_Code code) const { return m_code == code; }
155
156 constexpr bool operator==(Group_Params other) const { return m_code == other.m_code; }
157
158 constexpr bool operator<(Group_Params other) const { return m_code < other.m_code; }
159
160 constexpr Group_Params_Code code() const { return m_code; }
161
162 constexpr uint16_t wire_code() const { return static_cast<uint16_t>(m_code); }
163
164 /**
165 * Returns false if this group/KEX is not available in the build configuration
166 */
167 bool is_available() const;
168
169 constexpr bool is_x25519() const { return m_code == Group_Params_Code::X25519; }
170
171 constexpr bool is_x448() const { return m_code == Group_Params_Code::X448; }
172
178
179 constexpr bool is_in_ffdhe_range() const {
180 // See RFC 7919
181 return wire_code() >= 256 && wire_code() < 512;
182 }
183
184 constexpr bool is_dh_named_group() const {
185 return m_code == Group_Params_Code::FFDHE_2048 || m_code == Group_Params_Code::FFDHE_3072 ||
188 }
189
190 constexpr bool is_pure_ml_kem() const {
191 return m_code == Group_Params_Code::ML_KEM_512 || m_code == Group_Params_Code::ML_KEM_768 ||
193 }
194
203
204 constexpr bool is_pure_ecc_group() const { return is_x25519() || is_x448() || is_ecdh_named_curve(); }
205
214
220
233
234 constexpr bool is_pqc_hybrid() const { return is_pqc_hybrid_ml_kem() || is_pqc_hybrid_frodokem(); }
235
244
245 // If this is a pqc hybrid group, returns the ECC ID
246 std::optional<Group_Params_Code> pqc_hybrid_ecc() const;
247
248 // Returns std::nullopt if the param has no known name
249 std::optional<std::string> to_string() const;
250
251 private:
252 Group_Params_Code m_code;
253};
254
255enum class Kex_Algo : uint8_t {
266
267 // To support TLS 1.3 ciphersuites, which do not determine the kex algo
269};
270
273
275 return (m == Kex_Algo::PSK || m == Kex_Algo::ECDHE_PSK || m == Kex_Algo::DHE_PSK);
276}
277
278// As defined in RFC 8446 4.4.2
279enum class Certificate_Type : uint8_t { X509 = 0, RawPublicKey = 2 };
280
282Certificate_Type certificate_type_from_string(const std::string& type_str);
283
284} // namespace Botan::TLS
285
286#endif
#define BOTAN_DIAGNOSTIC_POP
Definition api.h:122
#define BOTAN_DIAGNOSTIC_PUSH
Definition api.h:119
#define BOTAN_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
Definition api.h:120
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_TEST_API
Definition api.h:41
constexpr bool operator==(Group_Params other) const
Definition tls_algos.h:156
constexpr bool is_dh_named_group() const
Definition tls_algos.h:184
constexpr bool is_in_ffdhe_range() const
Definition tls_algos.h:179
constexpr bool operator<(Group_Params other) const
Definition tls_algos.h:158
constexpr bool is_pqc_hybrid() const
Definition tls_algos.h:234
constexpr bool is_kem() const
Definition tls_algos.h:236
constexpr bool is_post_quantum() const
Definition tls_algos.h:206
constexpr bool operator==(Group_Params_Code code) const
Definition tls_algos.h:154
constexpr bool is_ecdh_named_curve() const
Definition tls_algos.h:173
constexpr uint16_t wire_code() const
Definition tls_algos.h:162
constexpr bool is_pure_frodokem() const
Definition tls_algos.h:195
constexpr Group_Params_Code code() const
Definition tls_algos.h:160
constexpr Group_Params(uint16_t code)
Definition tls_algos.h:147
constexpr bool is_pqc_hybrid_frodokem() const
Definition tls_algos.h:221
constexpr bool is_pure_ml_kem() const
Definition tls_algos.h:190
constexpr Group_Params(Group_Params_Code code)
Definition tls_algos.h:144
constexpr bool is_pqc_hybrid_ml_kem() const
Definition tls_algos.h:215
constexpr bool is_x448() const
Definition tls_algos.h:171
constexpr bool is_pure_ecc_group() const
Definition tls_algos.h:204
constexpr bool is_x25519() const
Definition tls_algos.h:169
#define BOTAN_DLL
Definition build.h:93
Kex_Algo kex_method_from_string(std::string_view str)
Definition tls_algos.cpp:56
std::string certificate_type_to_string(Certificate_Type type)
Auth_Method auth_method_from_string(std::string_view str)
std::string kdf_algo_to_string(KDF_Algo algo)
Definition tls_algos.cpp:14
std::string kex_method_to_string(Kex_Algo method)
Definition tls_algos.cpp:27
bool key_exchange_is_psk(Kex_Algo m)
Definition tls_algos.h:274
std::string auth_method_to_string(Auth_Method method)
Certificate_Type certificate_type_from_string(const std::string &type_str)
@ NONE
Definition filter.h:170
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition exceptn.cpp:13