Added AES+GHASH implementation using AES-NI opcodes; also ARM-Thumb assembly for...
[BearSSL] / samples / custom_profile.c
1 /*
2 * Copyright (c) 2016 Thomas Pornin <pornin@bolet.org>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25 #include "bearssl.h"
26
27 /*
28 * A "profile" is an initialisation function for a SSL context, that
29 * configures a list of cipher suites and algorithm implementations.
30 * While BearSSL comes with a few predefined profiles, you might one
31 * to define you own, using the example below as guidance.
32 *
33 * Each individual initialisation call sets a parameter or an algorithm
34 * support. Setting a specific algorithm pulls in the implementation of
35 * that algorithm in the compiled binary, as per static linking
36 * behaviour. Removing some of this calls will then reduce total code
37 * footprint, but also mechanically prevents some features to be
38 * supported (protocol versions and cipher suites).
39 *
40 * The two below define profiles for the client and the server contexts,
41 * respectively. Of course, in a typical size-constrained application,
42 * you would use one or the other, not both, to avoid pulling in code
43 * for both.
44 */
45
46 void
47 example_client_profile(br_ssl_client_context *cc
48 /* and possibly some other arguments */)
49 {
50 /*
51 * A list of cipher suites, by preference (first is most
52 * preferred). The list below contains all cipher suites supported
53 * by BearSSL; trim it done to your needs.
54 */
55 static const uint16_t suites[] = {
56 BR_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
57 BR_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
58 BR_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
59 BR_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
60 BR_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
61 BR_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
62 BR_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,
63 BR_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
64 BR_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384,
65 BR_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,
66 BR_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
67 BR_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
68 BR_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
69 BR_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
70 BR_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256,
71 BR_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256,
72 BR_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384,
73 BR_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384,
74 BR_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256,
75 BR_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256,
76 BR_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384,
77 BR_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384,
78 BR_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA,
79 BR_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA,
80 BR_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA,
81 BR_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA,
82 BR_TLS_RSA_WITH_AES_128_GCM_SHA256,
83 BR_TLS_RSA_WITH_AES_256_GCM_SHA384,
84 BR_TLS_RSA_WITH_AES_128_CBC_SHA256,
85 BR_TLS_RSA_WITH_AES_256_CBC_SHA256,
86 BR_TLS_RSA_WITH_AES_128_CBC_SHA,
87 BR_TLS_RSA_WITH_AES_256_CBC_SHA,
88 BR_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA,
89 BR_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA,
90 BR_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA,
91 BR_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA,
92 BR_TLS_RSA_WITH_3DES_EDE_CBC_SHA
93 };
94
95 /*
96 * Client context must be cleared at some point. This sets
97 * every value and pointer to 0 or NULL.
98 */
99 br_ssl_client_zero(cc);
100
101 /*
102 * Define minimum and maximum protocol versions. Supported
103 * versions are:
104 * BR_TLS10 TLS 1.0
105 * BR_TLS11 TLS 1.1
106 * BR_TLS12 TLS 1.2
107 */
108 br_ssl_engine_set_versions(&cc->eng, BR_TLS10, BR_TLS12);
109
110 /*
111 * Set the PRF implementation(s).
112 * For TLS 1.0 and 1.1, the "prf10" is needed.
113 * For TLS 1.2, this depends on the cipher suite:
114 * -- cipher suites with a name ending in "SHA384" need "prf_sha384";
115 * -- all others need "prf_sha256".
116 *
117 * Note that a cipher suite like TLS_RSA_WITH_AES_128_CBC_SHA will
118 * use SHA-1 for the per-record MAC (that's what the final "SHA"
119 * means), but still SHA-256 for the PRF when selected along with
120 * the TLS-1.2 protocol version.
121 */
122 br_ssl_engine_set_prf10(&cc->eng, &br_tls10_prf);
123 br_ssl_engine_set_prf_sha256(&cc->eng, &br_tls12_sha256_prf);
124 br_ssl_engine_set_prf_sha384(&cc->eng, &br_tls12_sha384_prf);
125
126 /*
127 * Set hash functions for the engine. Required hash functions
128 * depend on the protocol and cipher suite:
129 *
130 * -- TLS 1.0 and 1.1 require both MD5 and SHA-1.
131 * -- With TLS 1.2, cipher suites with a name ending in "SHA384"
132 * require SHA-384.
133 * -- With TLS 1.2, cipher suites with a name ending in "SHA256"
134 * require SHA-256.
135 * -- With TLS 1.2, cipher suites with a name ending in "SHA"
136 * require both SHA-256 and SHA-1.
137 *
138 * Moreover, these hash functions are also used to compute
139 * hashes supporting signatures on the server side (for ECDHE_*
140 * cipher suites), and on the client side (for client
141 * certificates, except in the case of full static ECDH). In TLS
142 * 1.0 and 1.1, SHA-1 (and also MD5) will be used, but with TLS
143 * 1.2 these hash functions are negotiated between client and
144 * server; SHA-256 and/or SHA-384 should be sufficient in
145 * practice.
146 *
147 * Note that with current implementations, SHA-224 and SHA-256
148 * share the same file, so if you use one, you may have the other
149 * one with no additional overhead. Similarly, SHA-384 and SHA-512
150 * share the same implementation code.
151 */
152 br_ssl_engine_set_hash(&cc->eng, br_md5_ID, &br_md5_vtable);
153 br_ssl_engine_set_hash(&cc->eng, br_sha1_ID, &br_sha1_vtable);
154 br_ssl_engine_set_hash(&cc->eng, br_sha224_ID, &br_sha224_vtable);
155 br_ssl_engine_set_hash(&cc->eng, br_sha256_ID, &br_sha256_vtable);
156 br_ssl_engine_set_hash(&cc->eng, br_sha384_ID, &br_sha384_vtable);
157 br_ssl_engine_set_hash(&cc->eng, br_sha512_ID, &br_sha512_vtable);
158
159 /*
160 * Set the cipher suites. All specified cipher suite MUST be
161 * supported, and the relevant algorithms MUST have been
162 * configured (failure to provide needed implementations may
163 * trigger unwanted behaviours like segfaults or overflows).
164 */
165 br_ssl_engine_set_suites(&cc->eng, suites,
166 (sizeof suites) / (sizeof suites[0]));
167
168 /*
169 * Public-key algorithm imeplementations.
170 *
171 * -- RSA public core ("rsapub") is needed for "RSA" key exchange
172 * (cipher suites whose name starts with TLS_RSA).
173 *
174 * -- RSA signature verification ("rsavrfy") is needed for
175 * "ECDHE_RSA" cipher suites (not ECDH_RSA).
176 *
177 * -- Elliptic curve implementation ("ec") is needed for cipher
178 * suites that use elliptic curves (both "ECDH" and "ECDHE"
179 * cipher suites).
180 *
181 * -- ECDSA signature verification is needed for "ECDHE_ECDSA"
182 * cipher suites (but not for ECDHE_RSA, ECDH_ECDSA or ECDH_RSA).
183 *
184 * The RSA code comes in three variants, called "i15", "i31" and
185 * "i32". The "i31" code is somewhat faster than the "i32" code.
186 * Usually, "i31" is faster than "i15", except on some specific
187 * architectures (ARM Cortex M0, M0+, M1 and M3) where the "i15"
188 * should be prefered (the "i15" code is constant-time, while
189 * the "i31" is not, and the "i15" code is faster anyway).
190 *
191 * ECDSA code also comes in "i15" and "i31" variants. As in the
192 * case of RSA, the "i31" code is faster, except on the small
193 * ARM Cortex M, where the "i15" code is faster and safer.
194 *
195 * There are no less than 10 elliptic curve implementations:
196 *
197 * - ec_c25519_i15, ec_c25519_i31, ec_c25519_m15 and ec_c25519_m31
198 * implement Curve25519.
199 *
200 * - ec_p256_m15 and ec_p256_m31 implement NIST curve P-256.
201 *
202 * - ec_prime_i15 and ec_prime_i31 implement NIST curves P-256,
203 * P-384 and P-521.
204 *
205 * - ec_all_m15 is an aggregate implementation that uses
206 * ec_c25519_m15, ec_p256_m15 and ec_prime_i15.
207 *
208 * - ec_all_m31 is an aggregate implementation that uses
209 * ec_c25519_m31, ec_p256_m31 and ec_prime_i31.
210 *
211 * For a given curve, "m15" is faster than "i15" (but possibly
212 * with a larger code footprint) and "m31" is faster than "i31"
213 * (there again with a larger code footprint). For best
214 * performance, use ec_all_m31, except on the small ARM Cortex M
215 * where ec_all_m15 should be used. Referencing the other
216 * implementations directly will result in smaller code, but
217 * support for fewer curves and possibly lower performance.
218 */
219 br_ssl_client_set_rsapub(cc, &br_rsa_i31_public);
220 br_ssl_client_set_rsavrfy(cc, &br_rsa_i31_pkcs1_vrfy);
221 br_ssl_engine_set_ec(&cc->eng, &br_ec_all_m31);
222 br_ssl_client_set_ecdsa(cc, &br_ecdsa_i31_vrfy_asn1);
223
224 /*
225 * Record handler:
226 * -- Cipher suites in AES_128_CBC, AES_256_CBC and 3DES_EDE_CBC
227 * need the CBC record handler ("set_cbc").
228 * -- Cipher suites in AES_128_GCM and AES_256_GCM need the GCM
229 * record handler ("set_gcm").
230 * -- Cipher suites in CHACHA20_POLY1305 need the ChaCha20+Poly1305
231 * record handler ("set_chapol").
232 */
233 br_ssl_engine_set_cbc(&cc->eng,
234 &br_sslrec_in_cbc_vtable,
235 &br_sslrec_out_cbc_vtable);
236 br_ssl_engine_set_gcm(&cc->eng,
237 &br_sslrec_in_gcm_vtable,
238 &br_sslrec_out_gcm_vtable);
239 br_ssl_engine_set_chapol(&cc->eng,
240 &br_sslrec_in_chapol_vtable,
241 &br_sslrec_out_chapol_vtable);
242
243 /*
244 * Symmetric encryption:
245 * -- AES_128_CBC and AES_256_CBC require an "aes_cbc" implementation
246 * (actually two implementations, for encryption and decryption).
247 * -- 3DES_EDE_CBC requires a "des_cbc" implementation
248 * (actually two implementations, for encryption and decryption).
249 * -- AES_128_GCM and AES_256_GCM require an "aes_ctr" imeplementation
250 * and also a GHASH implementation.
251 *
252 * Two 3DES implementations are provided:
253 *
254 * des_tab Classical table-based implementation; it is
255 * not constant-time.
256 *
257 * dest_ct Constant-time DES/3DES implementation. It is
258 * slower than des_tab.
259 *
260 * Four AES implementations are provided:
261 *
262 * aes_ct Constant-time AES implementation, for 32-bit
263 * systems.
264 *
265 * aes_ct64 Constant-time AES implementation, for 64-bit
266 * systems. It actually also runs on 32-bit systems,
267 * but, on such systems, it yields larger code and
268 * slightly worse performance. On 64-bit systems,
269 * aes_ct64 is about twice faster than aes_ct for
270 * CTR processing (GCM encryption and decryption),
271 * and for CBC (decryption only).
272 *
273 * aes_small Smallest implementation provided, but also the
274 * slowest, and it is not constant-time. Use it
275 * only if desperate for code size.
276 *
277 * aes_big Classical table-based AES implementation. This
278 * is decently fast and still resonably compact,
279 * but it is not constant-time.
280 *
281 * aes_x86ni Very fast implementation that uses the AES-NI
282 * opcodes on recent x86 CPU.
283 *
284 * Whether having constant-time implementations is absolutely
285 * required for security depends on the context (in particular
286 * whether the target architecture actually has cache memory),
287 * and while side-channel analysis for non-constant-time AES
288 * code has been demonstrated in lab conditions, it certainly
289 * does not apply to all actual usages, and it has never been
290 * spotted in the wild. It is still considered cautious to use
291 * constant-time code by default, and to consider the other
292 * implementations only if duly measured performance issues make
293 * it mandatory.
294 */
295 br_ssl_engine_set_aes_cbc(&cc->eng,
296 &br_aes_ct_cbcenc_vtable,
297 &br_aes_ct_cbcdec_vtable);
298 br_ssl_engine_set_aes_ctr(&cc->eng,
299 &br_aes_ct_ctr_vtable);
300 /* Alternate: aes_ct64
301 br_ssl_engine_set_aes_cbc(&cc->eng,
302 &br_aes_ct64_cbcenc_vtable,
303 &br_aes_ct64_cbcdec_vtable);
304 br_ssl_engine_set_aes_ctr(&cc->eng,
305 &br_aes_ct64_ctr_vtable);
306 */
307 /* Alternate: aes_small
308 br_ssl_engine_set_aes_cbc(&cc->eng,
309 &br_aes_small_cbcenc_vtable,
310 &br_aes_small_cbcdec_vtable);
311 br_ssl_engine_set_aes_ctr(&cc->eng,
312 &br_aes_small_ctr_vtable);
313 */
314 /* Alternate: aes_big
315 br_ssl_engine_set_aes_cbc(&cc->eng,
316 &br_aes_big_cbcenc_vtable,
317 &br_aes_big_cbcdec_vtable);
318 br_ssl_engine_set_aes_ctr(&cc->eng,
319 &br_aes_big_ctr_vtable);
320 */
321 br_ssl_engine_set_des_cbc(&cc->eng,
322 &br_des_ct_cbcenc_vtable,
323 &br_des_ct_cbcdec_vtable);
324 /* Alternate: des_tab
325 br_ssl_engine_set_des_cbc(&cc->eng,
326 &br_des_tab_cbcenc_vtable,
327 &br_des_tab_cbcdec_vtable);
328 */
329
330 /*
331 * GHASH is needed for AES_128_GCM and AES_256_GCM. Three
332 * implementations are provided:
333 *
334 * ctmul Uses 32-bit multiplications with a 64-bit result.
335 *
336 * ctmul32 Uses 32-bit multiplications with a 32-bit result.
337 *
338 * ctmul64 Uses 64-bit multiplications with a 64-bit result.
339 *
340 * On 64-bit platforms, ctmul64 is the smallest and fastest of
341 * the three. On 32-bit systems, ctmul should be prefered. The
342 * ctmul32 implementation is meant to be used for the specific
343 * 32-bit systems that do not have a 32x32->64 multiplier (i.e.
344 * the ARM Cortex-M0 and Cortex-M0+).
345 *
346 * These implementations are all constant-time as long as the
347 * underlying multiplication opcode is constant-time (which is
348 * true for all modern systems, but not for older architectures
349 * such that ARM9 or 80486).
350 */
351 br_ssl_engine_set_ghash(&cc->eng,
352 &br_ghash_ctmul);
353 /* Alternate: ghash_ctmul32
354 br_ssl_engine_set_ghash(&cc->eng,
355 &br_ghash_ctmul32);
356 */
357 /* Alternate: ghash_ctmul64
358 br_ssl_engine_set_ghash(&cc->eng,
359 &br_ghash_ctmul64);
360 */
361
362 #if 0
363 /*
364 * For a client, the normal case is to validate the server
365 * certificate with regards to a set of trust anchors. This
366 * entails using a br_x509_minimal_context structure, configured
367 * with the relevant algorithms, as shown below.
368 *
369 * Alternatively, the client could "know" the intended server
370 * public key through an out-of-band mechanism, in which case
371 * a br_x509_knownkey_context is appropriate, for a much reduced
372 * code footprint.
373 *
374 * We assume here that the following extra parameters have been
375 * provided:
376 *
377 * xc engine context (br_x509_minimal_context *)
378 * trust_anchors trust anchors (br_x509_trust_anchor *)
379 * trust_anchors_num number of trust anchors (size_t)
380 */
381
382 /*
383 * The X.509 engine needs a hash function for processing the
384 * subject and issuer DN of certificates and trust anchors. Any
385 * supported hash function is appropriate; here we use SHA-256.
386 * The trust an
387 */
388 br_x509_minimal_init(xc, &br_sha256_vtable,
389 trust_anchors, trust_anchors_num);
390
391 /*
392 * Set suites and asymmetric crypto implementations. We use the
393 * "i31" code for RSA (it is somewhat faster than the "i32"
394 * implementation). These implementations are used for
395 * signature verification on certificates, but not for the
396 * SSL-specific usage of the server's public key. For instance,
397 * if the server has an EC public key but the rest of the chain
398 * (intermediate CA, root...) use RSA, then you would need only
399 * the RSA verification function below.
400 */
401 br_x509_minimal_set_rsa(xc, &br_rsa_i31_pkcs1_vrfy);
402 br_x509_minimal_set_ecdsa(xc,
403 &br_ec_prime_i31, &br_ecdsa_i31_vrfy_asn1);
404
405 /*
406 * Set supported hash functions. These are for signatures on
407 * certificates. There again, you only need the hash functions
408 * that are actually used in certificates, but if a given
409 * function was included for the SSL engine, you may as well
410 * add it here.
411 *
412 * Note: the engine explicitly rejects signatures that use MD5.
413 * Thus, there is no need for MD5 here.
414 */
415 br_ssl_engine_set_hash(xc, br_sha1_ID, &br_sha1_vtable);
416 br_ssl_engine_set_hash(xc, br_sha224_ID, &br_sha224_vtable);
417 br_ssl_engine_set_hash(xc, br_sha256_ID, &br_sha256_vtable);
418 br_ssl_engine_set_hash(xc, br_sha384_ID, &br_sha384_vtable);
419 br_ssl_engine_set_hash(xc, br_sha512_ID, &br_sha512_vtable);
420
421 /*
422 * Link the X.509 engine in the SSL engine.
423 */
424 br_ssl_engine_set_x509(&cc->eng, &xc->vtable);
425 #endif
426 }
427
428 /*
429 * Example server profile. Most of it is shared with the client
430 * profile, so see the comments in the client function for details.
431 *
432 * This example function assumes a server with a (unique) RSA private
433 * key, so the list of cipher suites is trimmed down for RSA.
434 */
435 void
436 example_server_profile(br_ssl_server_context *cc,
437 const br_x509_certificate *chain, size_t chain_len,
438 const br_rsa_private_key *sk)
439 {
440 static const uint16_t suites[] = {
441 BR_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
442 BR_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
443 BR_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
444 BR_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,
445 BR_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
446 BR_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
447 BR_TLS_RSA_WITH_AES_128_GCM_SHA256,
448 BR_TLS_RSA_WITH_AES_256_GCM_SHA384,
449 BR_TLS_RSA_WITH_AES_128_CBC_SHA256,
450 BR_TLS_RSA_WITH_AES_256_CBC_SHA256,
451 BR_TLS_RSA_WITH_AES_128_CBC_SHA,
452 BR_TLS_RSA_WITH_AES_256_CBC_SHA,
453 BR_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA,
454 BR_TLS_RSA_WITH_3DES_EDE_CBC_SHA
455 };
456
457 br_ssl_server_zero(cc);
458 br_ssl_engine_set_versions(&cc->eng, BR_TLS10, BR_TLS12);
459
460 br_ssl_engine_set_prf10(&cc->eng, &br_tls10_prf);
461 br_ssl_engine_set_prf_sha256(&cc->eng, &br_tls12_sha256_prf);
462 br_ssl_engine_set_prf_sha384(&cc->eng, &br_tls12_sha384_prf);
463
464 /*
465 * Apart from the requirements listed in the client side, these
466 * hash functions are also used by the server to compute its
467 * signature on ECDHE parameters. Which functions are needed
468 * depends on what the client may support; furthermore, the
469 * client may fail to send the relevant extension, in which
470 * case the server will default to whatever it can (as per the
471 * standard, it should be SHA-1 in that case).
472 */
473 br_ssl_engine_set_hash(&cc->eng, br_md5_ID, &br_md5_vtable);
474 br_ssl_engine_set_hash(&cc->eng, br_sha1_ID, &br_sha1_vtable);
475 br_ssl_engine_set_hash(&cc->eng, br_sha224_ID, &br_sha224_vtable);
476 br_ssl_engine_set_hash(&cc->eng, br_sha256_ID, &br_sha256_vtable);
477 br_ssl_engine_set_hash(&cc->eng, br_sha384_ID, &br_sha384_vtable);
478 br_ssl_engine_set_hash(&cc->eng, br_sha512_ID, &br_sha512_vtable);
479
480 br_ssl_engine_set_suites(&cc->eng, suites,
481 (sizeof suites) / (sizeof suites[0]));
482
483 /*
484 * Elliptic curve implementation is used for ECDHE suites (but
485 * not for ECDH).
486 */
487 br_ssl_engine_set_ec(&cc->eng, &br_ec_prime_i31);
488
489 /*
490 * Set the "server policy": handler for the certificate chain
491 * and private key operations. Here, we indicate that the RSA
492 * private key is fit for both signing and decrypting, and we
493 * provide the two relevant implementations.
494
495 * BR_KEYTYPE_KEYX allows TLS_RSA_*, BR_KEYTYPE_SIGN allows
496 * TLS_ECDHE_RSA_*.
497 */
498 br_ssl_server_set_single_rsa(cc, chain, chain_len, sk,
499 BR_KEYTYPE_KEYX | BR_KEYTYPE_SIGN,
500 br_rsa_i31_private, br_rsa_i31_pkcs1_sign);
501 /*
502 * If the server used an EC private key, this call would look
503 * like this:
504
505 br_ssl_server_set_single_ec(cc, chain, chain_len, sk,
506 BR_KEYTYPE_KEYX | BR_KEYTYPE_SIGN,
507 cert_issuer_key_type,
508 &br_ec_prime_i31, br_ecdsa_i31_sign_asn1);
509
510 * Note the tricky points:
511 *
512 * -- "ECDH" cipher suites use only the EC code (&br_ec_prime_i31);
513 * the ECDHE_ECDSA cipher suites need both the EC code and
514 * the ECDSA signature implementation.
515 *
516 * -- For "ECDH" (not "ECDHE") cipher suites, the engine must
517 * know the key type (RSA or EC) for the intermediate CA that
518 * issued the server's certificate; this is an artefact of
519 * how the protocol is defined. BearSSL won't try to decode
520 * the server's certificate to obtain that information (it
521 * could do that, the code is there, but it would increase the
522 * footprint). So this must be provided by the caller.
523 *
524 * -- BR_KEYTYPE_KEYX allows ECDH, BR_KEYTYPE_SIGN allows
525 * ECDHE_ECDSA.
526 */
527
528 br_ssl_engine_set_cbc(&cc->eng,
529 &br_sslrec_in_cbc_vtable,
530 &br_sslrec_out_cbc_vtable);
531 br_ssl_engine_set_gcm(&cc->eng,
532 &br_sslrec_in_gcm_vtable,
533 &br_sslrec_out_gcm_vtable);
534
535 br_ssl_engine_set_aes_cbc(&cc->eng,
536 &br_aes_ct_cbcenc_vtable,
537 &br_aes_ct_cbcdec_vtable);
538 br_ssl_engine_set_aes_ctr(&cc->eng,
539 &br_aes_ct_ctr_vtable);
540 /* Alternate: aes_ct64
541 br_ssl_engine_set_aes_cbc(&cc->eng,
542 &br_aes_ct64_cbcenc_vtable,
543 &br_aes_ct64_cbcdec_vtable);
544 br_ssl_engine_set_aes_ctr(&cc->eng,
545 &br_aes_ct64_ctr_vtable);
546 */
547 /* Alternate: aes_small
548 br_ssl_engine_set_aes_cbc(&cc->eng,
549 &br_aes_small_cbcenc_vtable,
550 &br_aes_small_cbcdec_vtable);
551 br_ssl_engine_set_aes_ctr(&cc->eng,
552 &br_aes_small_ctr_vtable);
553 */
554 /* Alternate: aes_big
555 br_ssl_engine_set_aes_cbc(&cc->eng,
556 &br_aes_big_cbcenc_vtable,
557 &br_aes_big_cbcdec_vtable);
558 br_ssl_engine_set_aes_ctr(&cc->eng,
559 &br_aes_big_ctr_vtable);
560 */
561 br_ssl_engine_set_des_cbc(&cc->eng,
562 &br_des_ct_cbcenc_vtable,
563 &br_des_ct_cbcdec_vtable);
564 /* Alternate: des_tab
565 br_ssl_engine_set_des_cbc(&cc->eng,
566 &br_des_tab_cbcenc_vtable,
567 &br_des_tab_cbcdec_vtable);
568 */
569
570 br_ssl_engine_set_ghash(&cc->eng,
571 &br_ghash_ctmul);
572 /* Alternate: ghash_ctmul32
573 br_ssl_engine_set_ghash(&cc->eng,
574 &br_ghash_ctmul32);
575 */
576 /* Alternate: ghash_ctmul64
577 br_ssl_engine_set_ghash(&cc->eng,
578 &br_ghash_ctmul64);
579 */
580 }