Debian Codegraph @

crt/s2n/tls/s2n_prf.h

raw symbols SCIP
1 /*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15
16 #pragma once
17
18 #include <stdint.h>
19
20 #include "crypto/s2n_hmac.h"
21 #include "tls/s2n_connection.h"
22 #include "utils/s2n_blob.h"
23
24 /* Enough to support TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, 2*SHA384_DIGEST_LEN + 2*AES256_KEY_SIZE */
25 #define S2N_MAX_KEY_BLOCK_LEN 160
26
27 union p_hash_state {
28 struct s2n_hmac_state s2n_hmac;
29 };
30
31 struct s2n_prf_working_space {
32 union p_hash_state p_hash;
33 uint8_t digest0[S2N_MAX_DIGEST_LEN];
34 uint8_t digest1[S2N_MAX_DIGEST_LEN];
35 };
36
37 /* TLS key expansion results in an array of contiguous data which is then
38 * interpreted as the MAC, KEY and IV for the client and server.
39 *
40 * The following is the memory layout of the key material:
41 *
42 * [ CLIENT_MAC, SERVER_MAC, CLIENT_KEY, SERVER_KEY, CLIENT_IV, SERVER_IV ]
43 */
44 struct s2n_key_material {
45 /* key material data resulting from key expansion */
46 uint8_t key_block[S2N_MAX_KEY_BLOCK_LEN];
47
48 /* pointers into data representing specific key information */
49 struct s2n_blob client_mac;
50 struct s2n_blob server_mac;
51 struct s2n_blob client_key;
52 struct s2n_blob server_key;
53 struct s2n_blob client_iv;
54 struct s2n_blob server_iv;
55 };
56
57 S2N_RESULT s2n_key_material_init(struct s2n_key_material *key_material, struct s2n_connection *conn);
58
59 S2N_RESULT s2n_prf_new(struct s2n_connection *conn);
60 S2N_RESULT s2n_prf_wipe(struct s2n_connection *conn);
61 S2N_RESULT s2n_prf_free(struct s2n_connection *conn);
62
63 int s2n_prf_calculate_master_secret(struct s2n_connection *conn, struct s2n_blob *premaster_secret);
64 int s2n_prf_hybrid_master_secret(struct s2n_connection *conn, struct s2n_blob *premaster_secret);
65 S2N_RESULT s2n_prf_generate_key_material(struct s2n_connection *conn, struct s2n_key_material *key_material);
66 int s2n_prf_key_expansion(struct s2n_connection *conn);
67 int s2n_prf_server_finished(struct s2n_connection *conn);
68 int s2n_prf_client_finished(struct s2n_connection *conn);