2 * Copyright (c) 2017 Thomas Pornin <pornin@bolet.org>
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:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
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
28 * Supported cipher suites that use SHA-384 for the PRF when selected
29 * for TLS 1.2. All other cipher suites are deemed to use SHA-256.
31 static const uint16_t suites_sha384
[] = {
32 BR_TLS_RSA_WITH_AES_256_GCM_SHA384
,
33 BR_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
,
34 BR_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
,
35 BR_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
,
36 BR_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
,
37 BR_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
,
38 BR_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384
,
39 BR_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
,
40 BR_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384
43 /* see bearssl_ssl.h */
45 br_ssl_key_export(br_ssl_engine_context
*cc
,
46 void *dst
, size_t len
, const char *label
,
47 const void *context
, size_t context_len
)
49 br_tls_prf_seed_chunk chunks
[4];
55 if (cc
->application_data
!= 1) {
58 chunks
[0].data
= cc
->client_random
;
59 chunks
[0].len
= sizeof cc
->client_random
;
60 chunks
[1].data
= cc
->server_random
;
61 chunks
[1].len
= sizeof cc
->server_random
;
62 if (context
!= NULL
) {
63 br_enc16be(tmp
, (unsigned)context_len
);
66 chunks
[3].data
= context
;
67 chunks
[3].len
= context_len
;
72 prf_id
= BR_SSLPRF_SHA256
;
73 for (u
= 0; u
< (sizeof suites_sha384
) / sizeof(uint16_t); u
++) {
74 if (suites_sha384
[u
] == cc
->session
.cipher_suite
) {
75 prf_id
= BR_SSLPRF_SHA384
;
78 iprf
= br_ssl_engine_get_PRF(cc
, prf_id
);
80 cc
->session
.master_secret
, sizeof cc
->session
.master_secret
,
81 label
, num_chunks
, chunks
);