XenevaOS
Loading...
Searching...
No Matches
ssl_tls13_keys.h
Go to the documentation of this file.
1/*
2 * TLS 1.3 key schedule
3 *
4 * Copyright The Mbed TLS Contributors
5 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
6 */
7#if !defined(MBEDTLS_SSL_TLS1_3_KEYS_H)
8#define MBEDTLS_SSL_TLS1_3_KEYS_H
9
10/* This requires MBEDTLS_SSL_TLS1_3_LABEL( idx, name, string ) to be defined at
11 * the point of use. See e.g. the definition of mbedtls_ssl_tls13_labels_union
12 * below. */
13#define MBEDTLS_SSL_TLS1_3_LABEL_LIST \
14 MBEDTLS_SSL_TLS1_3_LABEL(finished, "finished") \
15 MBEDTLS_SSL_TLS1_3_LABEL(resumption, "resumption") \
16 MBEDTLS_SSL_TLS1_3_LABEL(traffic_upd, "traffic upd") \
17 MBEDTLS_SSL_TLS1_3_LABEL(exporter, "exporter") \
18 MBEDTLS_SSL_TLS1_3_LABEL(key, "key") \
19 MBEDTLS_SSL_TLS1_3_LABEL(iv, "iv") \
20 MBEDTLS_SSL_TLS1_3_LABEL(c_hs_traffic, "c hs traffic") \
21 MBEDTLS_SSL_TLS1_3_LABEL(c_ap_traffic, "c ap traffic") \
22 MBEDTLS_SSL_TLS1_3_LABEL(c_e_traffic, "c e traffic") \
23 MBEDTLS_SSL_TLS1_3_LABEL(s_hs_traffic, "s hs traffic") \
24 MBEDTLS_SSL_TLS1_3_LABEL(s_ap_traffic, "s ap traffic") \
25 MBEDTLS_SSL_TLS1_3_LABEL(s_e_traffic, "s e traffic") \
26 MBEDTLS_SSL_TLS1_3_LABEL(e_exp_master, "e exp master") \
27 MBEDTLS_SSL_TLS1_3_LABEL(res_master, "res master") \
28 MBEDTLS_SSL_TLS1_3_LABEL(exp_master, "exp master") \
29 MBEDTLS_SSL_TLS1_3_LABEL(ext_binder, "ext binder") \
30 MBEDTLS_SSL_TLS1_3_LABEL(res_binder, "res binder") \
31 MBEDTLS_SSL_TLS1_3_LABEL(derived, "derived") \
32 MBEDTLS_SSL_TLS1_3_LABEL(client_cv, "TLS 1.3, client CertificateVerify") \
33 MBEDTLS_SSL_TLS1_3_LABEL(server_cv, "TLS 1.3, server CertificateVerify")
34
35#define MBEDTLS_SSL_TLS1_3_CONTEXT_UNHASHED 0
36#define MBEDTLS_SSL_TLS1_3_CONTEXT_HASHED 1
37
38#define MBEDTLS_SSL_TLS1_3_PSK_EXTERNAL 0
39#define MBEDTLS_SSL_TLS1_3_PSK_RESUMPTION 1
40
41#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
42
43/* We need to tell the compiler that we meant to leave out the null character. */
44#define MBEDTLS_SSL_TLS1_3_LABEL(name, string) \
45 const unsigned char name [sizeof(string) - 1] MBEDTLS_ATTRIBUTE_UNTERMINATED_STRING;
46
47union mbedtls_ssl_tls13_labels_union {
49};
50struct mbedtls_ssl_tls13_labels_struct {
52};
53#undef MBEDTLS_SSL_TLS1_3_LABEL
54
55extern const struct mbedtls_ssl_tls13_labels_struct mbedtls_ssl_tls13_labels;
56
57#define MBEDTLS_SSL_TLS1_3_LBL_LEN(LABEL) \
58 sizeof(mbedtls_ssl_tls13_labels.LABEL)
59
60#define MBEDTLS_SSL_TLS1_3_LBL_WITH_LEN(LABEL) \
61 mbedtls_ssl_tls13_labels.LABEL, \
62 MBEDTLS_SSL_TLS1_3_LBL_LEN(LABEL)
63
64/* Maximum length of the label field in the HkdfLabel struct defined in
65 * RFC 8446, Section 7.1, excluding the "tls13 " prefix. */
66#define MBEDTLS_SSL_TLS1_3_HKDF_LABEL_MAX_LABEL_LEN 249
67
68/* The maximum length of HKDF contexts used in the TLS 1.3 standard.
69 * Since contexts are always hashes of message transcripts, this can
70 * be approximated from above by the maximum hash size. */
71#define MBEDTLS_SSL_TLS1_3_KEY_SCHEDULE_MAX_CONTEXT_LEN \
72 PSA_HASH_MAX_SIZE
73
74/* Maximum desired length for expanded key material generated
75 * by HKDF-Expand-Label. This algorithm can output up to 255 * hash_size
76 * bytes of key material where hash_size is the output size of the
77 * underlying hash function. */
78#define MBEDTLS_SSL_TLS1_3_KEY_SCHEDULE_MAX_EXPANSION_LEN \
79 (255 * MBEDTLS_TLS1_3_MD_MAX_SIZE)
80
111int mbedtls_ssl_tls13_hkdf_expand_label(
112 psa_algorithm_t hash_alg,
113 const unsigned char *secret, size_t secret_len,
114 const unsigned char *label, size_t label_len,
115 const unsigned char *ctx, size_t ctx_len,
116 unsigned char *buf, size_t buf_len);
117
150int mbedtls_ssl_tls13_make_traffic_keys(
151 psa_algorithm_t hash_alg,
152 const unsigned char *client_secret,
153 const unsigned char *server_secret, size_t secret_len,
154 size_t key_len, size_t iv_len,
155 mbedtls_ssl_key_set *keys);
156
197int mbedtls_ssl_tls13_derive_secret(
198 psa_algorithm_t hash_alg,
199 const unsigned char *secret, size_t secret_len,
200 const unsigned char *label, size_t label_len,
201 const unsigned char *ctx, size_t ctx_len,
202 int ctx_hashed,
203 unsigned char *dstbuf, size_t dstbuf_len);
204
248int mbedtls_ssl_tls13_derive_early_secrets(
249 psa_algorithm_t hash_alg,
250 unsigned char const *early_secret,
251 unsigned char const *transcript, size_t transcript_len,
253
294int mbedtls_ssl_tls13_derive_handshake_secrets(
295 psa_algorithm_t hash_alg,
296 unsigned char const *handshake_secret,
297 unsigned char const *transcript, size_t transcript_len,
299
345int mbedtls_ssl_tls13_derive_application_secrets(
346 psa_algorithm_t hash_alg,
347 unsigned char const *master_secret,
348 unsigned char const *transcript, size_t transcript_len,
350
376int mbedtls_ssl_tls13_derive_resumption_master_secret(
377 psa_algorithm_t hash_alg,
378 unsigned char const *application_secret,
379 unsigned char const *transcript, size_t transcript_len,
381
450int mbedtls_ssl_tls13_evolve_secret(
451 psa_algorithm_t hash_alg,
452 const unsigned char *secret_old,
453 const unsigned char *input, size_t input_len,
454 unsigned char *secret_new);
455
480int mbedtls_ssl_tls13_create_psk_binder(mbedtls_ssl_context *ssl,
481 const psa_algorithm_t hash_alg,
482 unsigned char const *psk, size_t psk_len,
483 int psk_type,
484 unsigned char const *transcript,
485 unsigned char *result);
486
515int mbedtls_ssl_tls13_populate_transform(mbedtls_ssl_transform *transform,
516 int endpoint,
517 int ciphersuite,
518 mbedtls_ssl_key_set const *traffic_keys,
520
521/*
522 * TLS 1.3 key schedule evolutions
523 *
524 * Early -> Handshake -> Application
525 *
526 * Small wrappers around mbedtls_ssl_tls13_evolve_secret().
527 */
528
542int mbedtls_ssl_tls13_key_schedule_stage_early(mbedtls_ssl_context *ssl);
543
555int mbedtls_ssl_tls13_compute_resumption_master_secret(mbedtls_ssl_context *ssl);
556
580int mbedtls_ssl_tls13_calculate_verify_data(mbedtls_ssl_context *ssl,
581 unsigned char *dst,
582 size_t dst_len,
583 size_t *actual_len,
584 int which);
585
586#if defined(MBEDTLS_SSL_EARLY_DATA)
604int mbedtls_ssl_tls13_compute_early_transform(mbedtls_ssl_context *ssl);
605#endif /* MBEDTLS_SSL_EARLY_DATA */
606
617int mbedtls_ssl_tls13_compute_handshake_transform(mbedtls_ssl_context *ssl);
618
629int mbedtls_ssl_tls13_compute_application_transform(mbedtls_ssl_context *ssl);
630
631#if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_PSK_ENABLED)
644int mbedtls_ssl_tls13_export_handshake_psk(mbedtls_ssl_context *ssl,
645 unsigned char **psk,
646 size_t *psk_len);
647#endif
648
660int mbedtls_ssl_tls13_exporter(const psa_algorithm_t hash_alg,
661 const unsigned char *secret, const size_t secret_len,
662 const unsigned char *label, const size_t label_len,
663 const unsigned char *context_value, const size_t context_len,
664 uint8_t *out, const size_t out_len);
665
666#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
667
668#endif /* MBEDTLS_SSL_TLS1_3_KEYS_H */
void * endpoint
Definition main.cpp:149
#define out(...)
Definition main.cpp:65
unsigned char uint8_t
Definition acefiex.h:161
uint32_t psa_algorithm_t
Encoding of a cryptographic algorithm.
Definition crypto_types.h:134
#define MBEDTLS_CHECK_RETURN_CRITICAL
Definition platform_util.h:77
#define MBEDTLS_SSL_TLS1_3_LABEL_LIST
Definition ssl_tls13_keys.h:13
Definition ssl.h:1731
The data structure holding the cryptographic material (key and IV) used for record protection in TLS ...
Definition ssl_misc.h:614
Definition ssl_misc.h:631
Definition ssl_misc.h:637
Definition ssl_misc.h:1121
struct VirtioInputEvent * input
Definition virtiokbd.c:46