Botan 3.0.0
Crypto and TLS for C&
tls_algos.cpp
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#include <botan/ec_group.h>
8#include <botan/tls_algos.h>
9#include <botan/exceptn.h>
10#include <botan/internal/fmt.h>
11
12namespace Botan::TLS {
13
15 {
16 switch(algo)
17 {
18 case KDF_Algo::SHA_1:
19 return "SHA-1";
21 return "SHA-256";
23 return "SHA-384";
24 }
25
26 throw Invalid_State("kdf_algo_to_string unknown enum value");
27 }
28
29std::string kex_method_to_string(Kex_Algo method)
30 {
31 switch(method)
32 {
34 return "RSA";
35 case Kex_Algo::DH:
36 return "DH";
37 case Kex_Algo::ECDH:
38 return "ECDH";
39 case Kex_Algo::PSK:
40 return "PSK";
42 return "ECDHE_PSK";
44 return "DHE_PSK";
46 return "UNDEFINED";
47 }
48
49 throw Invalid_State("kex_method_to_string unknown enum value");
50 }
51
52Kex_Algo kex_method_from_string(std::string_view str)
53 {
54 if(str == "RSA")
56
57 if(str == "DH")
58 return Kex_Algo::DH;
59
60 if(str == "ECDH")
61 return Kex_Algo::ECDH;
62
63 if(str == "PSK")
64 return Kex_Algo::PSK;
65
66 if(str == "ECDHE_PSK")
68
69 if(str == "DHE_PSK")
70 return Kex_Algo::DHE_PSK;
71
72 if(str == "UNDEFINED")
74
75 throw Invalid_Argument(fmt("Unknown kex method '{}'", str));
76 }
77
79 {
80 switch(method)
81 {
83 return "RSA";
85 return "ECDSA";
87 return "IMPLICIT";
89 return "UNDEFINED";
90 }
91
92 throw Invalid_State("auth_method_to_string unknown enum value");
93 }
94
96 {
97 if(str == "RSA")
98 return Auth_Method::RSA;
99 if(str == "ECDSA")
100 return Auth_Method::ECDSA;
101 if(str == "IMPLICIT")
103 if(str == "UNDEFINED")
105
106 throw Invalid_Argument(fmt("Unknown TLS signature method '{}'", str));
107 }
108
110 {
111 uint16_t group_id = static_cast<uint16_t>(group);
112 return (group_id >= 256 && group_id < 512);
113 }
114
115Group_Params group_param_from_string(std::string_view group_name)
116 {
117 if(group_name == "secp256r1")
119 if(group_name == "secp384r1")
121 if(group_name == "secp521r1")
123 if(group_name == "brainpool256r1")
125 if(group_name == "brainpool384r1")
127 if(group_name == "brainpool512r1")
129 if(group_name == "x25519")
131
132 if(group_name == "ffdhe/ietf/2048")
134 if(group_name == "ffdhe/ietf/3072")
136 if(group_name == "ffdhe/ietf/4096")
138 if(group_name == "ffdhe/ietf/6144")
140 if(group_name == "ffdhe/ietf/8192")
142
143 return Group_Params::NONE; // unknown
144 }
145
147 {
148 switch(group)
149 {
151 return "secp256r1";
153 return "secp384r1";
155 return "secp521r1";
157 return "brainpool256r1";
159 return "brainpool384r1";
161 return "brainpool512r1";
163 return "x25519";
164
166 return "ffdhe/ietf/2048";
168 return "ffdhe/ietf/3072";
170 return "ffdhe/ietf/4096";
172 return "ffdhe/ietf/6144";
174 return "ffdhe/ietf/8192";
175
176 default:
177 return "";
178 }
179 }
180
181}
Kex_Algo kex_method_from_string(std::string_view str)
Definition: tls_algos.cpp:52
Auth_Method auth_method_from_string(std::string_view str)
Definition: tls_algos.cpp:95
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:29
bool group_param_is_dh(Group_Params group)
Definition: tls_algos.cpp:109
std::string group_param_to_string(Group_Params group)
Definition: tls_algos.cpp:146
std::string auth_method_to_string(Auth_Method method)
Definition: tls_algos.cpp:78
Group_Params group_param_from_string(std::string_view group_name)
Definition: tls_algos.cpp:115
std::string fmt(std::string_view format, const T &... args)
Definition: fmt.h:60