| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#pragma once |
| 17 |
|
| 18 |
#include <stdint.h> |
| 19 |
|
| 20 |
#include "crypto/s2n_hkdf.h" |
| 21 |
#include "crypto/s2n_hmac.h" |
| 22 |
#include "stuffer/s2n_stuffer.h" |
| 23 |
#include "tls/s2n_psk.h" |
| 24 |
#include "tls/s2n_tls_parameters.h" |
| 25 |
#include "utils/s2n_blob.h" |
| 26 |
#include "utils/s2n_mem.h" |
| 27 |
#include "utils/s2n_safety.h" |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
#define S2N_TLS13_SECRET_MAX_LEN SHA384_DIGEST_LENGTH |
| 36 |
|
| 37 |
struct s2n_tls13_keys { |
| 38 |
s2n_hmac_algorithm hmac_algorithm; |
| 39 |
s2n_hash_algorithm hash_algorithm; |
| 40 |
|
| 41 |
uint8_t size; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
struct s2n_blob extract_secret; |
| 47 |
struct s2n_blob derive_secret; |
| 48 |
uint8_t extract_secret_bytes[S2N_TLS13_SECRET_MAX_LEN]; |
| 49 |
uint8_t derive_secret_bytes[S2N_TLS13_SECRET_MAX_LEN]; |
| 50 |
|
| 51 |
struct s2n_hmac_state hmac; |
| 52 |
}; |
| 53 |
|
| 54 |
|
| 55 |
extern const struct s2n_blob s2n_tls13_label_derived_secret; |
| 56 |
extern const struct s2n_blob s2n_tls13_label_external_psk_binder_key; |
| 57 |
extern const struct s2n_blob s2n_tls13_label_resumption_psk_binder_key; |
| 58 |
|
| 59 |
extern const struct s2n_blob s2n_tls13_label_client_early_traffic_secret; |
| 60 |
extern const struct s2n_blob s2n_tls13_label_early_exporter_master_secret; |
| 61 |
|
| 62 |
extern const struct s2n_blob s2n_tls13_label_client_handshake_traffic_secret; |
| 63 |
extern const struct s2n_blob s2n_tls13_label_server_handshake_traffic_secret; |
| 64 |
|
| 65 |
extern const struct s2n_blob s2n_tls13_label_client_application_traffic_secret; |
| 66 |
extern const struct s2n_blob s2n_tls13_label_server_application_traffic_secret; |
| 67 |
|
| 68 |
extern const struct s2n_blob s2n_tls13_label_exporter_master_secret; |
| 69 |
extern const struct s2n_blob s2n_tls13_label_resumption_master_secret; |
| 70 |
|
| 71 |
extern const struct s2n_blob s2n_tls13_label_finished; |
| 72 |
|
| 73 |
extern const struct s2n_blob s2n_tls13_label_exporter; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
extern const struct s2n_blob s2n_tls13_label_traffic_secret_key; |
| 78 |
extern const struct s2n_blob s2n_tls13_label_traffic_secret_iv; |
| 79 |
|
| 80 |
#define s2n_tls13_key_blob(name, bytes) \ |
| 81 |
s2n_stack_blob(name, bytes, S2N_TLS13_SECRET_MAX_LEN) |
| 82 |
|
| 83 |
int s2n_tls13_keys_init(struct s2n_tls13_keys *handshake, s2n_hmac_algorithm alg); |
| 84 |
int s2n_tls13_keys_free(struct s2n_tls13_keys *keys); |
| 85 |
|
| 86 |
int s2n_tls13_derive_traffic_keys(struct s2n_tls13_keys *handshake, struct s2n_blob *secret, struct s2n_blob *key, struct s2n_blob *iv); |
| 87 |
int s2n_tls13_derive_finished_key(struct s2n_tls13_keys *keys, struct s2n_blob *secret_key, struct s2n_blob *output_finish_key); |
| 88 |
int s2n_tls13_calculate_finished_mac(struct s2n_tls13_keys *keys, struct s2n_blob *finished_key, struct s2n_hash_state *hash_state, struct s2n_blob *finished_verify); |
| 89 |
int s2n_tls13_update_application_traffic_secret(struct s2n_tls13_keys *keys, struct s2n_blob *old_secret, struct s2n_blob *new_secret); |
| 90 |
S2N_RESULT s2n_tls13_derive_session_ticket_secret(struct s2n_tls13_keys *keys, struct s2n_blob *resumption_secret, |
| 91 |
struct s2n_blob *ticket_nonce, struct s2n_blob *secret_blob); |