Add simple cache backend experiment hidden behind a command line option.
[chromium-blink-merge.git] / net / ssl / ssl_cipher_suite_names.cc
blobc07d5c206d6e802031bf59749a4c16aaf6bbc885
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/ssl/ssl_cipher_suite_names.h"
7 #include <stdlib.h>
9 #include "base/logging.h"
10 #include "base/string_number_conversions.h"
11 #include "base/string_util.h"
12 #include "net/ssl/ssl_connection_status_flags.h"
14 // Rather than storing the names of all the ciphersuites we eliminate the
15 // redundancy and break each cipher suite into a key exchange method, cipher
16 // and mac. For all the ciphersuites in the IANA registry, we extract each of
17 // those components from the name, number them and pack the result into a
18 // 16-bit number thus:
19 // (MSB to LSB)
20 // <4 bits> unused
21 // <5 bits> key exchange
22 // <4 bits> cipher
23 // <3 bits> mac
25 // The following tables were generated by ssl_cipher_suite_names_generate.go,
26 // found in the same directory as this file.
28 struct CipherSuite {
29 uint16 cipher_suite, encoded;
32 static const struct CipherSuite kCipherSuites[] = {
33 {0x0, 0x0}, // TLS_NULL_WITH_NULL_NULL
34 {0x1, 0x81}, // TLS_RSA_WITH_NULL_MD5
35 {0x2, 0x82}, // TLS_RSA_WITH_NULL_SHA
36 {0x3, 0x109}, // TLS_RSA_EXPORT_WITH_RC4_40_MD5
37 {0x4, 0x91}, // TLS_RSA_WITH_RC4_128_MD5
38 {0x5, 0x92}, // TLS_RSA_WITH_RC4_128_SHA
39 {0x6, 0x119}, // TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5
40 {0x7, 0xa2}, // TLS_RSA_WITH_IDEA_CBC_SHA
41 {0x8, 0x12a}, // TLS_RSA_EXPORT_WITH_DES40_CBC_SHA
42 {0x9, 0xb2}, // TLS_RSA_WITH_DES_CBC_SHA
43 {0xa, 0xba}, // TLS_RSA_WITH_3DES_EDE_CBC_SHA
44 {0xb, 0x1aa}, // TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA
45 {0xc, 0x232}, // TLS_DH_DSS_WITH_DES_CBC_SHA
46 {0xd, 0x23a}, // TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA
47 {0xe, 0x2aa}, // TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA
48 {0xf, 0x332}, // TLS_DH_RSA_WITH_DES_CBC_SHA
49 {0x10, 0x33a}, // TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA
50 {0x11, 0x3aa}, // TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA
51 {0x12, 0x432}, // TLS_DHE_DSS_WITH_DES_CBC_SHA
52 {0x13, 0x43a}, // TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA
53 {0x14, 0x4aa}, // TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA
54 {0x15, 0x532}, // TLS_DHE_RSA_WITH_DES_CBC_SHA
55 {0x16, 0x53a}, // TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
56 {0x17, 0x589}, // TLS_DH_anon_EXPORT_WITH_RC4_40_MD5
57 {0x18, 0x611}, // TLS_DH_anon_WITH_RC4_128_MD5
58 {0x19, 0x5aa}, // TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA
59 {0x1a, 0x632}, // TLS_DH_anon_WITH_DES_CBC_SHA
60 {0x1b, 0x63a}, // TLS_DH_anon_WITH_3DES_EDE_CBC_SHA
61 {0x1e, 0x6b2}, // TLS_KRB5_WITH_DES_CBC_SHA
62 {0x1f, 0x6ba}, // TLS_KRB5_WITH_3DES_EDE_CBC_SHA
63 {0x20, 0x692}, // TLS_KRB5_WITH_RC4_128_SHA
64 {0x21, 0x6a2}, // TLS_KRB5_WITH_IDEA_CBC_SHA
65 {0x22, 0x6b1}, // TLS_KRB5_WITH_DES_CBC_MD5
66 {0x23, 0x6b9}, // TLS_KRB5_WITH_3DES_EDE_CBC_MD5
67 {0x24, 0x691}, // TLS_KRB5_WITH_RC4_128_MD5
68 {0x25, 0x6a1}, // TLS_KRB5_WITH_IDEA_CBC_MD5
69 {0x26, 0x742}, // TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA
70 {0x27, 0x71a}, // TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA
71 {0x28, 0x70a}, // TLS_KRB5_EXPORT_WITH_RC4_40_SHA
72 {0x29, 0x741}, // TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5
73 {0x2a, 0x719}, // TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5
74 {0x2b, 0x709}, // TLS_KRB5_EXPORT_WITH_RC4_40_MD5
75 {0x2c, 0x782}, // TLS_PSK_WITH_NULL_SHA
76 {0x2d, 0x802}, // TLS_DHE_PSK_WITH_NULL_SHA
77 {0x2e, 0x882}, // TLS_RSA_PSK_WITH_NULL_SHA
78 {0x2f, 0xca}, // TLS_RSA_WITH_AES_128_CBC_SHA
79 {0x30, 0x24a}, // TLS_DH_DSS_WITH_AES_128_CBC_SHA
80 {0x31, 0x34a}, // TLS_DH_RSA_WITH_AES_128_CBC_SHA
81 {0x32, 0x44a}, // TLS_DHE_DSS_WITH_AES_128_CBC_SHA
82 {0x33, 0x54a}, // TLS_DHE_RSA_WITH_AES_128_CBC_SHA
83 {0x34, 0x64a}, // TLS_DH_anon_WITH_AES_128_CBC_SHA
84 {0x35, 0xd2}, // TLS_RSA_WITH_AES_256_CBC_SHA
85 {0x36, 0x252}, // TLS_DH_DSS_WITH_AES_256_CBC_SHA
86 {0x37, 0x352}, // TLS_DH_RSA_WITH_AES_256_CBC_SHA
87 {0x38, 0x452}, // TLS_DHE_DSS_WITH_AES_256_CBC_SHA
88 {0x39, 0x552}, // TLS_DHE_RSA_WITH_AES_256_CBC_SHA
89 {0x3a, 0x652}, // TLS_DH_anon_WITH_AES_256_CBC_SHA
90 {0x3b, 0x83}, // TLS_RSA_WITH_NULL_SHA256
91 {0x3c, 0xcb}, // TLS_RSA_WITH_AES_128_CBC_SHA256
92 {0x3d, 0xd3}, // TLS_RSA_WITH_AES_256_CBC_SHA256
93 {0x3e, 0x24b}, // TLS_DH_DSS_WITH_AES_128_CBC_SHA256
94 {0x3f, 0x34b}, // TLS_DH_RSA_WITH_AES_128_CBC_SHA256
95 {0x40, 0x44b}, // TLS_DHE_DSS_WITH_AES_128_CBC_SHA256
96 {0x41, 0xda}, // TLS_RSA_WITH_CAMELLIA_128_CBC_SHA
97 {0x42, 0x25a}, // TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA
98 {0x43, 0x35a}, // TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA
99 {0x44, 0x45a}, // TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA
100 {0x45, 0x55a}, // TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA
101 {0x46, 0x65a}, // TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA
102 {0x67, 0x54b}, // TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
103 {0x68, 0x253}, // TLS_DH_DSS_WITH_AES_256_CBC_SHA256
104 {0x69, 0x353}, // TLS_DH_RSA_WITH_AES_256_CBC_SHA256
105 {0x6a, 0x453}, // TLS_DHE_DSS_WITH_AES_256_CBC_SHA256
106 {0x6b, 0x553}, // TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
107 {0x6c, 0x64b}, // TLS_DH_anon_WITH_AES_128_CBC_SHA256
108 {0x6d, 0x653}, // TLS_DH_anon_WITH_AES_256_CBC_SHA256
109 {0x84, 0xe2}, // TLS_RSA_WITH_CAMELLIA_256_CBC_SHA
110 {0x85, 0x262}, // TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA
111 {0x86, 0x362}, // TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA
112 {0x87, 0x462}, // TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA
113 {0x88, 0x562}, // TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA
114 {0x89, 0x662}, // TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA
115 {0x8a, 0x792}, // TLS_PSK_WITH_RC4_128_SHA
116 {0x8b, 0x7ba}, // TLS_PSK_WITH_3DES_EDE_CBC_SHA
117 {0x8c, 0x7ca}, // TLS_PSK_WITH_AES_128_CBC_SHA
118 {0x8d, 0x7d2}, // TLS_PSK_WITH_AES_256_CBC_SHA
119 {0x8e, 0x812}, // TLS_DHE_PSK_WITH_RC4_128_SHA
120 {0x8f, 0x83a}, // TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA
121 {0x90, 0x84a}, // TLS_DHE_PSK_WITH_AES_128_CBC_SHA
122 {0x91, 0x852}, // TLS_DHE_PSK_WITH_AES_256_CBC_SHA
123 {0x92, 0x892}, // TLS_RSA_PSK_WITH_RC4_128_SHA
124 {0x93, 0x8ba}, // TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA
125 {0x94, 0x8ca}, // TLS_RSA_PSK_WITH_AES_128_CBC_SHA
126 {0x95, 0x8d2}, // TLS_RSA_PSK_WITH_AES_256_CBC_SHA
127 {0x96, 0xea}, // TLS_RSA_WITH_SEED_CBC_SHA
128 {0x97, 0x26a}, // TLS_DH_DSS_WITH_SEED_CBC_SHA
129 {0x98, 0x36a}, // TLS_DH_RSA_WITH_SEED_CBC_SHA
130 {0x99, 0x46a}, // TLS_DHE_DSS_WITH_SEED_CBC_SHA
131 {0x9a, 0x56a}, // TLS_DHE_RSA_WITH_SEED_CBC_SHA
132 {0x9b, 0x66a}, // TLS_DH_anon_WITH_SEED_CBC_SHA
133 {0x9c, 0xf3}, // TLS_RSA_WITH_AES_128_GCM_SHA256
134 {0x9d, 0xfc}, // TLS_RSA_WITH_AES_256_GCM_SHA384
135 {0x9e, 0x573}, // TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
136 {0x9f, 0x57c}, // TLS_DHE_RSA_WITH_AES_256_GCM_SHA384
137 {0xa0, 0x373}, // TLS_DH_RSA_WITH_AES_128_GCM_SHA256
138 {0xa1, 0x37c}, // TLS_DH_RSA_WITH_AES_256_GCM_SHA384
139 {0xa2, 0x473}, // TLS_DHE_DSS_WITH_AES_128_GCM_SHA256
140 {0xa3, 0x47c}, // TLS_DHE_DSS_WITH_AES_256_GCM_SHA384
141 {0xa4, 0x273}, // TLS_DH_DSS_WITH_AES_128_GCM_SHA256
142 {0xa5, 0x27c}, // TLS_DH_DSS_WITH_AES_256_GCM_SHA384
143 {0xa6, 0x673}, // TLS_DH_anon_WITH_AES_128_GCM_SHA256
144 {0xa7, 0x67c}, // TLS_DH_anon_WITH_AES_256_GCM_SHA384
145 {0xa8, 0x7f3}, // TLS_PSK_WITH_AES_128_GCM_SHA256
146 {0xa9, 0x7fc}, // TLS_PSK_WITH_AES_256_GCM_SHA384
147 {0xaa, 0x873}, // TLS_DHE_PSK_WITH_AES_128_GCM_SHA256
148 {0xab, 0x87c}, // TLS_DHE_PSK_WITH_AES_256_GCM_SHA384
149 {0xac, 0x8f3}, // TLS_RSA_PSK_WITH_AES_128_GCM_SHA256
150 {0xad, 0x8fc}, // TLS_RSA_PSK_WITH_AES_256_GCM_SHA384
151 {0xae, 0x7cb}, // TLS_PSK_WITH_AES_128_CBC_SHA256
152 {0xaf, 0x7d4}, // TLS_PSK_WITH_AES_256_CBC_SHA384
153 {0xb0, 0x783}, // TLS_PSK_WITH_NULL_SHA256
154 {0xb1, 0x784}, // TLS_PSK_WITH_NULL_SHA384
155 {0xb2, 0x84b}, // TLS_DHE_PSK_WITH_AES_128_CBC_SHA256
156 {0xb3, 0x854}, // TLS_DHE_PSK_WITH_AES_256_CBC_SHA384
157 {0xb4, 0x803}, // TLS_DHE_PSK_WITH_NULL_SHA256
158 {0xb5, 0x804}, // TLS_DHE_PSK_WITH_NULL_SHA384
159 {0xb6, 0x8cb}, // TLS_RSA_PSK_WITH_AES_128_CBC_SHA256
160 {0xb7, 0x8d4}, // TLS_RSA_PSK_WITH_AES_256_CBC_SHA384
161 {0xb8, 0x883}, // TLS_RSA_PSK_WITH_NULL_SHA256
162 {0xb9, 0x884}, // TLS_RSA_PSK_WITH_NULL_SHA384
163 {0xba, 0xdb}, // TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256
164 {0xbb, 0x25b}, // TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256
165 {0xbc, 0x35b}, // TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256
166 {0xbd, 0x45b}, // TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256
167 {0xbe, 0x55b}, // TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256
168 {0xbf, 0x65b}, // TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256
169 {0xc0, 0xe3}, // TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256
170 {0xc1, 0x263}, // TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256
171 {0xc2, 0x363}, // TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256
172 {0xc3, 0x463}, // TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256
173 {0xc4, 0x563}, // TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256
174 {0xc5, 0x663}, // TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256
175 {0xc001, 0x902}, // TLS_ECDH_ECDSA_WITH_NULL_SHA
176 {0xc002, 0x912}, // TLS_ECDH_ECDSA_WITH_RC4_128_SHA
177 {0xc003, 0x93a}, // TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA
178 {0xc004, 0x94a}, // TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
179 {0xc005, 0x952}, // TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
180 {0xc006, 0x982}, // TLS_ECDHE_ECDSA_WITH_NULL_SHA
181 {0xc007, 0x992}, // TLS_ECDHE_ECDSA_WITH_RC4_128_SHA
182 {0xc008, 0x9ba}, // TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA
183 {0xc009, 0x9ca}, // TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
184 {0xc00a, 0x9d2}, // TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
185 {0xc00b, 0xa02}, // TLS_ECDH_RSA_WITH_NULL_SHA
186 {0xc00c, 0xa12}, // TLS_ECDH_RSA_WITH_RC4_128_SHA
187 {0xc00d, 0xa3a}, // TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA
188 {0xc00e, 0xa4a}, // TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
189 {0xc00f, 0xa52}, // TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
190 {0xc010, 0xa82}, // TLS_ECDHE_RSA_WITH_NULL_SHA
191 {0xc011, 0xa92}, // TLS_ECDHE_RSA_WITH_RC4_128_SHA
192 {0xc012, 0xaba}, // TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
193 {0xc013, 0xaca}, // TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
194 {0xc014, 0xad2}, // TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
195 {0xc015, 0xb02}, // TLS_ECDH_anon_WITH_NULL_SHA
196 {0xc016, 0xb12}, // TLS_ECDH_anon_WITH_RC4_128_SHA
197 {0xc017, 0xb3a}, // TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA
198 {0xc018, 0xb4a}, // TLS_ECDH_anon_WITH_AES_128_CBC_SHA
199 {0xc019, 0xb52}, // TLS_ECDH_anon_WITH_AES_256_CBC_SHA
200 {0xc01a, 0xbba}, // TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA
201 {0xc01b, 0xc3a}, // TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA
202 {0xc01c, 0xcba}, // TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA
203 {0xc01d, 0xbca}, // TLS_SRP_SHA_WITH_AES_128_CBC_SHA
204 {0xc01e, 0xc4a}, // TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA
205 {0xc01f, 0xcca}, // TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA
206 {0xc020, 0xbd2}, // TLS_SRP_SHA_WITH_AES_256_CBC_SHA
207 {0xc021, 0xc52}, // TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA
208 {0xc022, 0xcd2}, // TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA
209 {0xc023, 0x9cb}, // TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
210 {0xc024, 0x9d4}, // TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
211 {0xc025, 0x94b}, // TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
212 {0xc026, 0x954}, // TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
213 {0xc027, 0xacb}, // TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
214 {0xc028, 0xad4}, // TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
215 {0xc029, 0xa4b}, // TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
216 {0xc02a, 0xa54}, // TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
217 {0xc02b, 0x9f3}, // TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
218 {0xc02c, 0x9fc}, // TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
219 {0xc02d, 0x973}, // TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256
220 {0xc02e, 0x97c}, // TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384
221 {0xc02f, 0xaf3}, // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
222 {0xc030, 0xafc}, // TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
223 {0xc031, 0xa73}, // TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256
224 {0xc032, 0xa7c}, // TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384
225 {0xc033, 0xd12}, // TLS_ECDHE_PSK_WITH_RC4_128_SHA
226 {0xc034, 0xd3a}, // TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA
227 {0xc035, 0xd4a}, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA
228 {0xc036, 0xd52}, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA
229 {0xc037, 0xd4b}, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256
230 {0xc038, 0xd54}, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384
231 {0xc039, 0xd02}, // TLS_ECDHE_PSK_WITH_NULL_SHA
232 {0xc03a, 0xd03}, // TLS_ECDHE_PSK_WITH_NULL_SHA256
233 {0xc03b, 0xd04}, // TLS_ECDHE_PSK_WITH_NULL_SHA384
236 static const struct {
237 char name[15];
238 } kKeyExchangeNames[27] = {
239 {"NULL"}, // 0
240 {"RSA"}, // 1
241 {"RSA_EXPORT"}, // 2
242 {"DH_DSS_EXPORT"}, // 3
243 {"DH_DSS"}, // 4
244 {"DH_RSA_EXPORT"}, // 5
245 {"DH_RSA"}, // 6
246 {"DHE_DSS_EXPORT"}, // 7
247 {"DHE_DSS"}, // 8
248 {"DHE_RSA_EXPORT"}, // 9
249 {"DHE_RSA"}, // 10
250 {"DH_anon_EXPORT"}, // 11
251 {"DH_anon"}, // 12
252 {"KRB5"}, // 13
253 {"KRB5_EXPORT"}, // 14
254 {"PSK"}, // 15
255 {"DHE_PSK"}, // 16
256 {"RSA_PSK"}, // 17
257 {"ECDH_ECDSA"}, // 18
258 {"ECDHE_ECDSA"}, // 19
259 {"ECDH_RSA"}, // 20
260 {"ECDHE_RSA"}, // 21
261 {"ECDH_anon"}, // 22
262 {"SRP_SHA"}, // 23
263 {"SRP_SHA_RSA"}, // 24
264 {"SRP_SHA_DSS"}, // 25
265 {"ECDHE_PSK"}, // 26
268 static const struct {
269 char name[17];
270 } kCipherNames[16] = {
271 {"NULL"}, // 0
272 {"RC4_40"}, // 1
273 {"RC4_128"}, // 2
274 {"RC2_CBC_40"}, // 3
275 {"IDEA_CBC"}, // 4
276 {"DES40_CBC"}, // 5
277 {"DES_CBC"}, // 6
278 {"3DES_EDE_CBC"}, // 7
279 {"DES_CBC_40"}, // 8
280 {"AES_128_CBC"}, // 9
281 {"AES_256_CBC"}, // 10
282 {"CAMELLIA_128_CBC"}, // 11
283 {"CAMELLIA_256_CBC"}, // 12
284 {"SEED_CBC"}, // 13
285 {"AES_128_GCM"}, // 14
286 {"AES_256_GCM"}, // 15
289 static const struct {
290 char name[7];
291 } kMacNames[5] = {
292 {"NULL"}, // 0
293 {"MD5"}, // 1
294 {"SHA1"}, // 2
295 {"SHA256"}, // 3
296 {"SHA384"}, // 4
300 namespace net {
302 static int CipherSuiteCmp(const void* ia, const void* ib) {
303 const CipherSuite* a = static_cast<const CipherSuite*>(ia);
304 const CipherSuite* b = static_cast<const CipherSuite*>(ib);
306 if (a->cipher_suite < b->cipher_suite) {
307 return -1;
308 } else if (a->cipher_suite == b->cipher_suite) {
309 return 0;
310 } else {
311 return 1;
315 void SSLCipherSuiteToStrings(const char** key_exchange_str,
316 const char** cipher_str,
317 const char** mac_str, uint16 cipher_suite) {
318 *key_exchange_str = *cipher_str = *mac_str = "???";
320 struct CipherSuite desired = {0};
321 desired.cipher_suite = cipher_suite;
323 void* r = bsearch(&desired, kCipherSuites,
324 arraysize(kCipherSuites), sizeof(kCipherSuites[0]),
325 CipherSuiteCmp);
327 if (!r)
328 return;
330 const CipherSuite* cs = static_cast<CipherSuite*>(r);
332 const int key_exchange = cs->encoded >> 7;
333 const int cipher = (cs->encoded >> 3) & 0xf;
334 const int mac = cs->encoded & 0x7;
336 *key_exchange_str = kKeyExchangeNames[key_exchange].name;
337 *cipher_str = kCipherNames[cipher].name;
338 *mac_str = kMacNames[mac].name;
341 void SSLVersionToString(const char** name, int ssl_version) {
342 switch (ssl_version) {
343 case SSL_CONNECTION_VERSION_SSL2:
344 *name = "SSL 2.0";
345 break;
346 case SSL_CONNECTION_VERSION_SSL3:
347 *name = "SSL 3.0";
348 break;
349 case SSL_CONNECTION_VERSION_TLS1:
350 *name = "TLS 1.0";
351 break;
352 case SSL_CONNECTION_VERSION_TLS1_1:
353 *name = "TLS 1.1";
354 break;
355 case SSL_CONNECTION_VERSION_TLS1_2:
356 *name = "TLS 1.2";
357 break;
358 default:
359 NOTREACHED() << ssl_version;
360 *name = "???";
361 break;
365 bool ParseSSLCipherString(const std::string& cipher_string,
366 uint16* cipher_suite) {
367 int value = 0;
368 if (cipher_string.size() == 6 &&
369 StartsWithASCII(cipher_string, "0x", false /* case insensitive */) &&
370 base::HexStringToInt(cipher_string, &value)) {
371 *cipher_suite = static_cast<uint16>(value);
372 return true;
374 return false;
377 } // namespace net