1a8e1175bSopenharmony_ci/* 2a8e1175bSopenharmony_ci * TLS 1.3 key schedule 3a8e1175bSopenharmony_ci * 4a8e1175bSopenharmony_ci * Copyright The Mbed TLS Contributors 5a8e1175bSopenharmony_ci * SPDX-License-Identifier: Apache-2.0 6a8e1175bSopenharmony_ci * 7a8e1175bSopenharmony_ci * Licensed under the Apache License, Version 2.0 ( the "License" ); you may 8a8e1175bSopenharmony_ci * not use this file except in compliance with the License. 9a8e1175bSopenharmony_ci * You may obtain a copy of the License at 10a8e1175bSopenharmony_ci * 11a8e1175bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 12a8e1175bSopenharmony_ci * 13a8e1175bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 14a8e1175bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15a8e1175bSopenharmony_ci * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16a8e1175bSopenharmony_ci * See the License for the specific language governing permissions and 17a8e1175bSopenharmony_ci * limitations under the License. 18a8e1175bSopenharmony_ci */ 19a8e1175bSopenharmony_ci#if !defined(MBEDTLS_SSL_TLS1_3_KEYS_H) 20a8e1175bSopenharmony_ci#define MBEDTLS_SSL_TLS1_3_KEYS_H 21a8e1175bSopenharmony_ci 22a8e1175bSopenharmony_ci/* This requires MBEDTLS_SSL_TLS1_3_LABEL( idx, name, string ) to be defined at 23a8e1175bSopenharmony_ci * the point of use. See e.g. the definition of mbedtls_ssl_tls13_labels_union 24a8e1175bSopenharmony_ci * below. */ 25a8e1175bSopenharmony_ci#define MBEDTLS_SSL_TLS1_3_LABEL_LIST \ 26a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LABEL(finished, "finished") \ 27a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LABEL(resumption, "resumption") \ 28a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LABEL(traffic_upd, "traffic upd") \ 29a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LABEL(exporter, "exporter") \ 30a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LABEL(key, "key") \ 31a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LABEL(iv, "iv") \ 32a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LABEL(c_hs_traffic, "c hs traffic") \ 33a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LABEL(c_ap_traffic, "c ap traffic") \ 34a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LABEL(c_e_traffic, "c e traffic") \ 35a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LABEL(s_hs_traffic, "s hs traffic") \ 36a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LABEL(s_ap_traffic, "s ap traffic") \ 37a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LABEL(s_e_traffic, "s e traffic") \ 38a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LABEL(e_exp_master, "e exp master") \ 39a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LABEL(res_master, "res master") \ 40a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LABEL(exp_master, "exp master") \ 41a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LABEL(ext_binder, "ext binder") \ 42a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LABEL(res_binder, "res binder") \ 43a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LABEL(derived, "derived") \ 44a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LABEL(client_cv, "TLS 1.3, client CertificateVerify") \ 45a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LABEL(server_cv, "TLS 1.3, server CertificateVerify") 46a8e1175bSopenharmony_ci 47a8e1175bSopenharmony_ci#define MBEDTLS_SSL_TLS1_3_CONTEXT_UNHASHED 0 48a8e1175bSopenharmony_ci#define MBEDTLS_SSL_TLS1_3_CONTEXT_HASHED 1 49a8e1175bSopenharmony_ci 50a8e1175bSopenharmony_ci#define MBEDTLS_SSL_TLS1_3_PSK_EXTERNAL 0 51a8e1175bSopenharmony_ci#define MBEDTLS_SSL_TLS1_3_PSK_RESUMPTION 1 52a8e1175bSopenharmony_ci 53a8e1175bSopenharmony_ci#if defined(MBEDTLS_SSL_PROTO_TLS1_3) 54a8e1175bSopenharmony_ci 55a8e1175bSopenharmony_ci#define MBEDTLS_SSL_TLS1_3_LABEL(name, string) \ 56a8e1175bSopenharmony_ci const unsigned char name [sizeof(string) - 1]; 57a8e1175bSopenharmony_ci 58a8e1175bSopenharmony_ciunion mbedtls_ssl_tls13_labels_union { 59a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LABEL_LIST 60a8e1175bSopenharmony_ci}; 61a8e1175bSopenharmony_cistruct mbedtls_ssl_tls13_labels_struct { 62a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LABEL_LIST 63a8e1175bSopenharmony_ci}; 64a8e1175bSopenharmony_ci#undef MBEDTLS_SSL_TLS1_3_LABEL 65a8e1175bSopenharmony_ci 66a8e1175bSopenharmony_ciextern const struct mbedtls_ssl_tls13_labels_struct mbedtls_ssl_tls13_labels; 67a8e1175bSopenharmony_ci 68a8e1175bSopenharmony_ci#define MBEDTLS_SSL_TLS1_3_LBL_LEN(LABEL) \ 69a8e1175bSopenharmony_ci sizeof(mbedtls_ssl_tls13_labels.LABEL) 70a8e1175bSopenharmony_ci 71a8e1175bSopenharmony_ci#define MBEDTLS_SSL_TLS1_3_LBL_WITH_LEN(LABEL) \ 72a8e1175bSopenharmony_ci mbedtls_ssl_tls13_labels.LABEL, \ 73a8e1175bSopenharmony_ci MBEDTLS_SSL_TLS1_3_LBL_LEN(LABEL) 74a8e1175bSopenharmony_ci 75a8e1175bSopenharmony_ci#define MBEDTLS_SSL_TLS1_3_KEY_SCHEDULE_MAX_LABEL_LEN \ 76a8e1175bSopenharmony_ci sizeof(union mbedtls_ssl_tls13_labels_union) 77a8e1175bSopenharmony_ci 78a8e1175bSopenharmony_ci/* The maximum length of HKDF contexts used in the TLS 1.3 standard. 79a8e1175bSopenharmony_ci * Since contexts are always hashes of message transcripts, this can 80a8e1175bSopenharmony_ci * be approximated from above by the maximum hash size. */ 81a8e1175bSopenharmony_ci#define MBEDTLS_SSL_TLS1_3_KEY_SCHEDULE_MAX_CONTEXT_LEN \ 82a8e1175bSopenharmony_ci PSA_HASH_MAX_SIZE 83a8e1175bSopenharmony_ci 84a8e1175bSopenharmony_ci/* Maximum desired length for expanded key material generated 85a8e1175bSopenharmony_ci * by HKDF-Expand-Label. 86a8e1175bSopenharmony_ci * 87a8e1175bSopenharmony_ci * Warning: If this ever needs to be increased, the implementation 88a8e1175bSopenharmony_ci * ssl_tls13_hkdf_encode_label() in ssl_tls13_keys.c needs to be 89a8e1175bSopenharmony_ci * adjusted since it currently assumes that HKDF key expansion 90a8e1175bSopenharmony_ci * is never used with more than 255 Bytes of output. */ 91a8e1175bSopenharmony_ci#define MBEDTLS_SSL_TLS1_3_KEY_SCHEDULE_MAX_EXPANSION_LEN 255 92a8e1175bSopenharmony_ci 93a8e1175bSopenharmony_ci/** 94a8e1175bSopenharmony_ci * \brief The \c HKDF-Expand-Label function from 95a8e1175bSopenharmony_ci * the TLS 1.3 standard RFC 8446. 96a8e1175bSopenharmony_ci * 97a8e1175bSopenharmony_ci * <tt> 98a8e1175bSopenharmony_ci * HKDF-Expand-Label( Secret, Label, Context, Length ) = 99a8e1175bSopenharmony_ci * HKDF-Expand( Secret, HkdfLabel, Length ) 100a8e1175bSopenharmony_ci * </tt> 101a8e1175bSopenharmony_ci * 102a8e1175bSopenharmony_ci * \param hash_alg The identifier for the hash algorithm to use. 103a8e1175bSopenharmony_ci * \param secret The \c Secret argument to \c HKDF-Expand-Label. 104a8e1175bSopenharmony_ci * This must be a readable buffer of length 105a8e1175bSopenharmony_ci * \p secret_len Bytes. 106a8e1175bSopenharmony_ci * \param secret_len The length of \p secret in Bytes. 107a8e1175bSopenharmony_ci * \param label The \c Label argument to \c HKDF-Expand-Label. 108a8e1175bSopenharmony_ci * This must be a readable buffer of length 109a8e1175bSopenharmony_ci * \p label_len Bytes. 110a8e1175bSopenharmony_ci * \param label_len The length of \p label in Bytes. 111a8e1175bSopenharmony_ci * \param ctx The \c Context argument to \c HKDF-Expand-Label. 112a8e1175bSopenharmony_ci * This must be a readable buffer of length \p ctx_len Bytes. 113a8e1175bSopenharmony_ci * \param ctx_len The length of \p context in Bytes. 114a8e1175bSopenharmony_ci * \param buf The destination buffer to hold the expanded secret. 115a8e1175bSopenharmony_ci * This must be a writable buffer of length \p buf_len Bytes. 116a8e1175bSopenharmony_ci * \param buf_len The desired size of the expanded secret in Bytes. 117a8e1175bSopenharmony_ci * 118a8e1175bSopenharmony_ci * \returns \c 0 on success. 119a8e1175bSopenharmony_ci * \return A negative error code on failure. 120a8e1175bSopenharmony_ci */ 121a8e1175bSopenharmony_ci 122a8e1175bSopenharmony_ciMBEDTLS_CHECK_RETURN_CRITICAL 123a8e1175bSopenharmony_ciint mbedtls_ssl_tls13_hkdf_expand_label( 124a8e1175bSopenharmony_ci psa_algorithm_t hash_alg, 125a8e1175bSopenharmony_ci const unsigned char *secret, size_t secret_len, 126a8e1175bSopenharmony_ci const unsigned char *label, size_t label_len, 127a8e1175bSopenharmony_ci const unsigned char *ctx, size_t ctx_len, 128a8e1175bSopenharmony_ci unsigned char *buf, size_t buf_len); 129a8e1175bSopenharmony_ci 130a8e1175bSopenharmony_ci/** 131a8e1175bSopenharmony_ci * \brief This function is part of the TLS 1.3 key schedule. 132a8e1175bSopenharmony_ci * It extracts key and IV for the actual client/server traffic 133a8e1175bSopenharmony_ci * from the client/server traffic secrets. 134a8e1175bSopenharmony_ci * 135a8e1175bSopenharmony_ci * From RFC 8446: 136a8e1175bSopenharmony_ci * 137a8e1175bSopenharmony_ci * <tt> 138a8e1175bSopenharmony_ci * [sender]_write_key = HKDF-Expand-Label(Secret, "key", "", key_length) 139a8e1175bSopenharmony_ci * [sender]_write_iv = HKDF-Expand-Label(Secret, "iv", "", iv_length)* 140a8e1175bSopenharmony_ci * </tt> 141a8e1175bSopenharmony_ci * 142a8e1175bSopenharmony_ci * \param hash_alg The identifier for the hash algorithm to be used 143a8e1175bSopenharmony_ci * for the HKDF-based expansion of the secret. 144a8e1175bSopenharmony_ci * \param client_secret The client traffic secret. 145a8e1175bSopenharmony_ci * This must be a readable buffer of size 146a8e1175bSopenharmony_ci * \p secret_len Bytes 147a8e1175bSopenharmony_ci * \param server_secret The server traffic secret. 148a8e1175bSopenharmony_ci * This must be a readable buffer of size 149a8e1175bSopenharmony_ci * \p secret_len Bytes 150a8e1175bSopenharmony_ci * \param secret_len Length of the secrets \p client_secret and 151a8e1175bSopenharmony_ci * \p server_secret in Bytes. 152a8e1175bSopenharmony_ci * \param key_len The desired length of the key to be extracted in Bytes. 153a8e1175bSopenharmony_ci * \param iv_len The desired length of the IV to be extracted in Bytes. 154a8e1175bSopenharmony_ci * \param keys The address of the structure holding the generated 155a8e1175bSopenharmony_ci * keys and IVs. 156a8e1175bSopenharmony_ci * 157a8e1175bSopenharmony_ci * \returns \c 0 on success. 158a8e1175bSopenharmony_ci * \returns A negative error code on failure. 159a8e1175bSopenharmony_ci */ 160a8e1175bSopenharmony_ci 161a8e1175bSopenharmony_ciMBEDTLS_CHECK_RETURN_CRITICAL 162a8e1175bSopenharmony_ciint mbedtls_ssl_tls13_make_traffic_keys( 163a8e1175bSopenharmony_ci psa_algorithm_t hash_alg, 164a8e1175bSopenharmony_ci const unsigned char *client_secret, 165a8e1175bSopenharmony_ci const unsigned char *server_secret, size_t secret_len, 166a8e1175bSopenharmony_ci size_t key_len, size_t iv_len, 167a8e1175bSopenharmony_ci mbedtls_ssl_key_set *keys); 168a8e1175bSopenharmony_ci 169a8e1175bSopenharmony_ci/** 170a8e1175bSopenharmony_ci * \brief The \c Derive-Secret function from the TLS 1.3 standard RFC 8446. 171a8e1175bSopenharmony_ci * 172a8e1175bSopenharmony_ci * <tt> 173a8e1175bSopenharmony_ci * Derive-Secret( Secret, Label, Messages ) = 174a8e1175bSopenharmony_ci * HKDF-Expand-Label( Secret, Label, 175a8e1175bSopenharmony_ci * Hash( Messages ), 176a8e1175bSopenharmony_ci * Hash.Length ) ) 177a8e1175bSopenharmony_ci * </tt> 178a8e1175bSopenharmony_ci * 179a8e1175bSopenharmony_ci * \param hash_alg The identifier for the hash function used for the 180a8e1175bSopenharmony_ci * applications of HKDF. 181a8e1175bSopenharmony_ci * \param secret The \c Secret argument to the \c Derive-Secret function. 182a8e1175bSopenharmony_ci * This must be a readable buffer of length 183a8e1175bSopenharmony_ci * \p secret_len Bytes. 184a8e1175bSopenharmony_ci * \param secret_len The length of \p secret in Bytes. 185a8e1175bSopenharmony_ci * \param label The \c Label argument to the \c Derive-Secret function. 186a8e1175bSopenharmony_ci * This must be a readable buffer of length 187a8e1175bSopenharmony_ci * \p label_len Bytes. 188a8e1175bSopenharmony_ci * \param label_len The length of \p label in Bytes. 189a8e1175bSopenharmony_ci * \param ctx The hash of the \c Messages argument to the 190a8e1175bSopenharmony_ci * \c Derive-Secret function, or the \c Messages argument 191a8e1175bSopenharmony_ci * itself, depending on \p ctx_hashed. 192a8e1175bSopenharmony_ci * \param ctx_len The length of \p ctx in Bytes. 193a8e1175bSopenharmony_ci * \param ctx_hashed This indicates whether the \p ctx contains the hash of 194a8e1175bSopenharmony_ci * the \c Messages argument in the application of the 195a8e1175bSopenharmony_ci * \c Derive-Secret function 196a8e1175bSopenharmony_ci * (value MBEDTLS_SSL_TLS1_3_CONTEXT_HASHED), or whether 197a8e1175bSopenharmony_ci * it is the content of \c Messages itself, in which case 198a8e1175bSopenharmony_ci * the function takes care of the hashing 199a8e1175bSopenharmony_ci * (value MBEDTLS_SSL_TLS1_3_CONTEXT_UNHASHED). 200a8e1175bSopenharmony_ci * \param dstbuf The target buffer to write the output of 201a8e1175bSopenharmony_ci * \c Derive-Secret to. This must be a writable buffer of 202a8e1175bSopenharmony_ci * size \p dtsbuf_len Bytes. 203a8e1175bSopenharmony_ci * \param dstbuf_len The length of \p dstbuf in Bytes. 204a8e1175bSopenharmony_ci * 205a8e1175bSopenharmony_ci * \returns \c 0 on success. 206a8e1175bSopenharmony_ci * \returns A negative error code on failure. 207a8e1175bSopenharmony_ci */ 208a8e1175bSopenharmony_ciMBEDTLS_CHECK_RETURN_CRITICAL 209a8e1175bSopenharmony_ciint mbedtls_ssl_tls13_derive_secret( 210a8e1175bSopenharmony_ci psa_algorithm_t hash_alg, 211a8e1175bSopenharmony_ci const unsigned char *secret, size_t secret_len, 212a8e1175bSopenharmony_ci const unsigned char *label, size_t label_len, 213a8e1175bSopenharmony_ci const unsigned char *ctx, size_t ctx_len, 214a8e1175bSopenharmony_ci int ctx_hashed, 215a8e1175bSopenharmony_ci unsigned char *dstbuf, size_t dstbuf_len); 216a8e1175bSopenharmony_ci 217a8e1175bSopenharmony_ci/** 218a8e1175bSopenharmony_ci * \brief Derive TLS 1.3 early data key material from early secret. 219a8e1175bSopenharmony_ci * 220a8e1175bSopenharmony_ci * This is a small wrapper invoking mbedtls_ssl_tls13_derive_secret() 221a8e1175bSopenharmony_ci * with the appropriate labels. 222a8e1175bSopenharmony_ci * 223a8e1175bSopenharmony_ci * <tt> 224a8e1175bSopenharmony_ci * Early Secret 225a8e1175bSopenharmony_ci * | 226a8e1175bSopenharmony_ci * +-----> Derive-Secret(., "c e traffic", ClientHello) 227a8e1175bSopenharmony_ci * | = client_early_traffic_secret 228a8e1175bSopenharmony_ci * | 229a8e1175bSopenharmony_ci * +-----> Derive-Secret(., "e exp master", ClientHello) 230a8e1175bSopenharmony_ci * . = early_exporter_master_secret 231a8e1175bSopenharmony_ci * . 232a8e1175bSopenharmony_ci * . 233a8e1175bSopenharmony_ci * </tt> 234a8e1175bSopenharmony_ci * 235a8e1175bSopenharmony_ci * \note To obtain the actual key and IV for the early data traffic, 236a8e1175bSopenharmony_ci * the client secret derived by this function need to be 237a8e1175bSopenharmony_ci * further processed by mbedtls_ssl_tls13_make_traffic_keys(). 238a8e1175bSopenharmony_ci * 239a8e1175bSopenharmony_ci * \note The binder key, which is also generated from the early secret, 240a8e1175bSopenharmony_ci * is omitted here. Its calculation is part of the separate routine 241a8e1175bSopenharmony_ci * mbedtls_ssl_tls13_create_psk_binder(). 242a8e1175bSopenharmony_ci * 243a8e1175bSopenharmony_ci * \param hash_alg The hash algorithm associated with the PSK for which 244a8e1175bSopenharmony_ci * early data key material is being derived. 245a8e1175bSopenharmony_ci * \param early_secret The early secret from which the early data key material 246a8e1175bSopenharmony_ci * should be derived. This must be a readable buffer whose 247a8e1175bSopenharmony_ci * length is the digest size of the hash algorithm 248a8e1175bSopenharmony_ci * represented by \p md_size. 249a8e1175bSopenharmony_ci * \param transcript The transcript of the handshake so far, calculated with 250a8e1175bSopenharmony_ci * respect to \p hash_alg. This must be a readable buffer 251a8e1175bSopenharmony_ci * whose length is the digest size of the hash algorithm 252a8e1175bSopenharmony_ci * represented by \p md_size. 253a8e1175bSopenharmony_ci * \param derived The address of the structure in which to store 254a8e1175bSopenharmony_ci * the early data key material. 255a8e1175bSopenharmony_ci * 256a8e1175bSopenharmony_ci * \returns \c 0 on success. 257a8e1175bSopenharmony_ci * \returns A negative error code on failure. 258a8e1175bSopenharmony_ci */ 259a8e1175bSopenharmony_ciMBEDTLS_CHECK_RETURN_CRITICAL 260a8e1175bSopenharmony_ciint mbedtls_ssl_tls13_derive_early_secrets( 261a8e1175bSopenharmony_ci psa_algorithm_t hash_alg, 262a8e1175bSopenharmony_ci unsigned char const *early_secret, 263a8e1175bSopenharmony_ci unsigned char const *transcript, size_t transcript_len, 264a8e1175bSopenharmony_ci mbedtls_ssl_tls13_early_secrets *derived); 265a8e1175bSopenharmony_ci 266a8e1175bSopenharmony_ci/** 267a8e1175bSopenharmony_ci * \brief Derive TLS 1.3 handshake key material from the handshake secret. 268a8e1175bSopenharmony_ci * 269a8e1175bSopenharmony_ci * This is a small wrapper invoking mbedtls_ssl_tls13_derive_secret() 270a8e1175bSopenharmony_ci * with the appropriate labels from the standard. 271a8e1175bSopenharmony_ci * 272a8e1175bSopenharmony_ci * <tt> 273a8e1175bSopenharmony_ci * Handshake Secret 274a8e1175bSopenharmony_ci * | 275a8e1175bSopenharmony_ci * +-----> Derive-Secret( ., "c hs traffic", 276a8e1175bSopenharmony_ci * | ClientHello...ServerHello ) 277a8e1175bSopenharmony_ci * | = client_handshake_traffic_secret 278a8e1175bSopenharmony_ci * | 279a8e1175bSopenharmony_ci * +-----> Derive-Secret( ., "s hs traffic", 280a8e1175bSopenharmony_ci * . ClientHello...ServerHello ) 281a8e1175bSopenharmony_ci * . = server_handshake_traffic_secret 282a8e1175bSopenharmony_ci * . 283a8e1175bSopenharmony_ci * </tt> 284a8e1175bSopenharmony_ci * 285a8e1175bSopenharmony_ci * \note To obtain the actual key and IV for the encrypted handshake traffic, 286a8e1175bSopenharmony_ci * the client and server secret derived by this function need to be 287a8e1175bSopenharmony_ci * further processed by mbedtls_ssl_tls13_make_traffic_keys(). 288a8e1175bSopenharmony_ci * 289a8e1175bSopenharmony_ci * \param hash_alg The hash algorithm associated with the ciphersuite 290a8e1175bSopenharmony_ci * that's being used for the connection. 291a8e1175bSopenharmony_ci * \param handshake_secret The handshake secret from which the handshake key 292a8e1175bSopenharmony_ci * material should be derived. This must be a readable 293a8e1175bSopenharmony_ci * buffer whose length is the digest size of the hash 294a8e1175bSopenharmony_ci * algorithm represented by \p md_size. 295a8e1175bSopenharmony_ci * \param transcript The transcript of the handshake so far, calculated 296a8e1175bSopenharmony_ci * with respect to \p hash_alg. This must be a readable 297a8e1175bSopenharmony_ci * buffer whose length is the digest size of the hash 298a8e1175bSopenharmony_ci * algorithm represented by \p md_size. 299a8e1175bSopenharmony_ci * \param derived The address of the structure in which to 300a8e1175bSopenharmony_ci * store the handshake key material. 301a8e1175bSopenharmony_ci * 302a8e1175bSopenharmony_ci * \returns \c 0 on success. 303a8e1175bSopenharmony_ci * \returns A negative error code on failure. 304a8e1175bSopenharmony_ci */ 305a8e1175bSopenharmony_ciMBEDTLS_CHECK_RETURN_CRITICAL 306a8e1175bSopenharmony_ciint mbedtls_ssl_tls13_derive_handshake_secrets( 307a8e1175bSopenharmony_ci psa_algorithm_t hash_alg, 308a8e1175bSopenharmony_ci unsigned char const *handshake_secret, 309a8e1175bSopenharmony_ci unsigned char const *transcript, size_t transcript_len, 310a8e1175bSopenharmony_ci mbedtls_ssl_tls13_handshake_secrets *derived); 311a8e1175bSopenharmony_ci 312a8e1175bSopenharmony_ci/** 313a8e1175bSopenharmony_ci * \brief Derive TLS 1.3 application key material from the master secret. 314a8e1175bSopenharmony_ci * 315a8e1175bSopenharmony_ci * This is a small wrapper invoking mbedtls_ssl_tls13_derive_secret() 316a8e1175bSopenharmony_ci * with the appropriate labels from the standard. 317a8e1175bSopenharmony_ci * 318a8e1175bSopenharmony_ci * <tt> 319a8e1175bSopenharmony_ci * Master Secret 320a8e1175bSopenharmony_ci * | 321a8e1175bSopenharmony_ci * +-----> Derive-Secret( ., "c ap traffic", 322a8e1175bSopenharmony_ci * | ClientHello...server Finished ) 323a8e1175bSopenharmony_ci * | = client_application_traffic_secret_0 324a8e1175bSopenharmony_ci * | 325a8e1175bSopenharmony_ci * +-----> Derive-Secret( ., "s ap traffic", 326a8e1175bSopenharmony_ci * | ClientHello...Server Finished ) 327a8e1175bSopenharmony_ci * | = server_application_traffic_secret_0 328a8e1175bSopenharmony_ci * | 329a8e1175bSopenharmony_ci * +-----> Derive-Secret( ., "exp master", 330a8e1175bSopenharmony_ci * . ClientHello...server Finished) 331a8e1175bSopenharmony_ci * . = exporter_master_secret 332a8e1175bSopenharmony_ci * . 333a8e1175bSopenharmony_ci * </tt> 334a8e1175bSopenharmony_ci * 335a8e1175bSopenharmony_ci * \note To obtain the actual key and IV for the (0-th) application traffic, 336a8e1175bSopenharmony_ci * the client and server secret derived by this function need to be 337a8e1175bSopenharmony_ci * further processed by mbedtls_ssl_tls13_make_traffic_keys(). 338a8e1175bSopenharmony_ci * 339a8e1175bSopenharmony_ci * \param hash_alg The hash algorithm associated with the ciphersuite 340a8e1175bSopenharmony_ci * that's being used for the connection. 341a8e1175bSopenharmony_ci * \param master_secret The master secret from which the application key 342a8e1175bSopenharmony_ci * material should be derived. This must be a readable 343a8e1175bSopenharmony_ci * buffer whose length is the digest size of the hash 344a8e1175bSopenharmony_ci * algorithm represented by \p md_size. 345a8e1175bSopenharmony_ci * \param transcript The transcript of the handshake up to and including 346a8e1175bSopenharmony_ci * the ServerFinished message, calculated with respect 347a8e1175bSopenharmony_ci * to \p hash_alg. This must be a readable buffer whose 348a8e1175bSopenharmony_ci * length is the digest size of the hash algorithm 349a8e1175bSopenharmony_ci * represented by \p hash_alg. 350a8e1175bSopenharmony_ci * \param derived The address of the structure in which to 351a8e1175bSopenharmony_ci * store the application key material. 352a8e1175bSopenharmony_ci * 353a8e1175bSopenharmony_ci * \returns \c 0 on success. 354a8e1175bSopenharmony_ci * \returns A negative error code on failure. 355a8e1175bSopenharmony_ci */ 356a8e1175bSopenharmony_ciMBEDTLS_CHECK_RETURN_CRITICAL 357a8e1175bSopenharmony_ciint mbedtls_ssl_tls13_derive_application_secrets( 358a8e1175bSopenharmony_ci psa_algorithm_t hash_alg, 359a8e1175bSopenharmony_ci unsigned char const *master_secret, 360a8e1175bSopenharmony_ci unsigned char const *transcript, size_t transcript_len, 361a8e1175bSopenharmony_ci mbedtls_ssl_tls13_application_secrets *derived); 362a8e1175bSopenharmony_ci 363a8e1175bSopenharmony_ci/** 364a8e1175bSopenharmony_ci * \brief Derive TLS 1.3 resumption master secret from the master secret. 365a8e1175bSopenharmony_ci * 366a8e1175bSopenharmony_ci * This is a small wrapper invoking mbedtls_ssl_tls13_derive_secret() 367a8e1175bSopenharmony_ci * with the appropriate labels from the standard. 368a8e1175bSopenharmony_ci * 369a8e1175bSopenharmony_ci * \param hash_alg The hash algorithm used in the application for which 370a8e1175bSopenharmony_ci * key material is being derived. 371a8e1175bSopenharmony_ci * \param application_secret The application secret from which the resumption master 372a8e1175bSopenharmony_ci * secret should be derived. This must be a readable 373a8e1175bSopenharmony_ci * buffer whose length is the digest size of the hash 374a8e1175bSopenharmony_ci * algorithm represented by \p md_size. 375a8e1175bSopenharmony_ci * \param transcript The transcript of the handshake up to and including 376a8e1175bSopenharmony_ci * the ClientFinished message, calculated with respect 377a8e1175bSopenharmony_ci * to \p hash_alg. This must be a readable buffer whose 378a8e1175bSopenharmony_ci * length is the digest size of the hash algorithm 379a8e1175bSopenharmony_ci * represented by \p hash_alg. 380a8e1175bSopenharmony_ci * \param transcript_len The length of \p transcript in Bytes. 381a8e1175bSopenharmony_ci * \param derived The address of the structure in which to 382a8e1175bSopenharmony_ci * store the resumption master secret. 383a8e1175bSopenharmony_ci * 384a8e1175bSopenharmony_ci * \returns \c 0 on success. 385a8e1175bSopenharmony_ci * \returns A negative error code on failure. 386a8e1175bSopenharmony_ci */ 387a8e1175bSopenharmony_ciMBEDTLS_CHECK_RETURN_CRITICAL 388a8e1175bSopenharmony_ciint mbedtls_ssl_tls13_derive_resumption_master_secret( 389a8e1175bSopenharmony_ci psa_algorithm_t hash_alg, 390a8e1175bSopenharmony_ci unsigned char const *application_secret, 391a8e1175bSopenharmony_ci unsigned char const *transcript, size_t transcript_len, 392a8e1175bSopenharmony_ci mbedtls_ssl_tls13_application_secrets *derived); 393a8e1175bSopenharmony_ci 394a8e1175bSopenharmony_ci/** 395a8e1175bSopenharmony_ci * \brief Compute the next secret in the TLS 1.3 key schedule 396a8e1175bSopenharmony_ci * 397a8e1175bSopenharmony_ci * The TLS 1.3 key schedule proceeds as follows to compute 398a8e1175bSopenharmony_ci * the three main secrets during the handshake: The early 399a8e1175bSopenharmony_ci * secret for early data, the handshake secret for all 400a8e1175bSopenharmony_ci * other encrypted handshake messages, and the master 401a8e1175bSopenharmony_ci * secret for all application traffic. 402a8e1175bSopenharmony_ci * 403a8e1175bSopenharmony_ci * <tt> 404a8e1175bSopenharmony_ci * 0 405a8e1175bSopenharmony_ci * | 406a8e1175bSopenharmony_ci * v 407a8e1175bSopenharmony_ci * PSK -> HKDF-Extract = Early Secret 408a8e1175bSopenharmony_ci * | 409a8e1175bSopenharmony_ci * v 410a8e1175bSopenharmony_ci * Derive-Secret( ., "derived", "" ) 411a8e1175bSopenharmony_ci * | 412a8e1175bSopenharmony_ci * v 413a8e1175bSopenharmony_ci * (EC)DHE -> HKDF-Extract = Handshake Secret 414a8e1175bSopenharmony_ci * | 415a8e1175bSopenharmony_ci * v 416a8e1175bSopenharmony_ci * Derive-Secret( ., "derived", "" ) 417a8e1175bSopenharmony_ci * | 418a8e1175bSopenharmony_ci * v 419a8e1175bSopenharmony_ci * 0 -> HKDF-Extract = Master Secret 420a8e1175bSopenharmony_ci * </tt> 421a8e1175bSopenharmony_ci * 422a8e1175bSopenharmony_ci * Each of the three secrets in turn is the basis for further 423a8e1175bSopenharmony_ci * key derivations, such as the derivation of traffic keys and IVs; 424a8e1175bSopenharmony_ci * see e.g. mbedtls_ssl_tls13_make_traffic_keys(). 425a8e1175bSopenharmony_ci * 426a8e1175bSopenharmony_ci * This function implements one step in this evolution of secrets: 427a8e1175bSopenharmony_ci * 428a8e1175bSopenharmony_ci * <tt> 429a8e1175bSopenharmony_ci * old_secret 430a8e1175bSopenharmony_ci * | 431a8e1175bSopenharmony_ci * v 432a8e1175bSopenharmony_ci * Derive-Secret( ., "derived", "" ) 433a8e1175bSopenharmony_ci * | 434a8e1175bSopenharmony_ci * v 435a8e1175bSopenharmony_ci * input -> HKDF-Extract = new_secret 436a8e1175bSopenharmony_ci * </tt> 437a8e1175bSopenharmony_ci * 438a8e1175bSopenharmony_ci * \param hash_alg The identifier for the hash function used for the 439a8e1175bSopenharmony_ci * applications of HKDF. 440a8e1175bSopenharmony_ci * \param secret_old The address of the buffer holding the old secret 441a8e1175bSopenharmony_ci * on function entry. If not \c NULL, this must be a 442a8e1175bSopenharmony_ci * readable buffer whose size matches the output size 443a8e1175bSopenharmony_ci * of the hash function represented by \p hash_alg. 444a8e1175bSopenharmony_ci * If \c NULL, an all \c 0 array will be used instead. 445a8e1175bSopenharmony_ci * \param input The address of the buffer holding the additional 446a8e1175bSopenharmony_ci * input for the key derivation (e.g., the PSK or the 447a8e1175bSopenharmony_ci * ephemeral (EC)DH secret). If not \c NULL, this must be 448a8e1175bSopenharmony_ci * a readable buffer whose size \p input_len Bytes. 449a8e1175bSopenharmony_ci * If \c NULL, an all \c 0 array will be used instead. 450a8e1175bSopenharmony_ci * \param input_len The length of \p input in Bytes. 451a8e1175bSopenharmony_ci * \param secret_new The address of the buffer holding the new secret 452a8e1175bSopenharmony_ci * on function exit. This must be a writable buffer 453a8e1175bSopenharmony_ci * whose size matches the output size of the hash 454a8e1175bSopenharmony_ci * function represented by \p hash_alg. 455a8e1175bSopenharmony_ci * This may be the same as \p secret_old. 456a8e1175bSopenharmony_ci * 457a8e1175bSopenharmony_ci * \returns \c 0 on success. 458a8e1175bSopenharmony_ci * \returns A negative error code on failure. 459a8e1175bSopenharmony_ci */ 460a8e1175bSopenharmony_ci 461a8e1175bSopenharmony_ciMBEDTLS_CHECK_RETURN_CRITICAL 462a8e1175bSopenharmony_ciint mbedtls_ssl_tls13_evolve_secret( 463a8e1175bSopenharmony_ci psa_algorithm_t hash_alg, 464a8e1175bSopenharmony_ci const unsigned char *secret_old, 465a8e1175bSopenharmony_ci const unsigned char *input, size_t input_len, 466a8e1175bSopenharmony_ci unsigned char *secret_new); 467a8e1175bSopenharmony_ci 468a8e1175bSopenharmony_ci/** 469a8e1175bSopenharmony_ci * \brief Calculate a TLS 1.3 PSK binder. 470a8e1175bSopenharmony_ci * 471a8e1175bSopenharmony_ci * \param ssl The SSL context. This is used for debugging only and may 472a8e1175bSopenharmony_ci * be \c NULL if MBEDTLS_DEBUG_C is disabled. 473a8e1175bSopenharmony_ci * \param hash_alg The hash algorithm associated to the PSK \p psk. 474a8e1175bSopenharmony_ci * \param psk The buffer holding the PSK for which to create a binder. 475a8e1175bSopenharmony_ci * \param psk_len The size of \p psk in bytes. 476a8e1175bSopenharmony_ci * \param psk_type This indicates whether the PSK \p psk is externally 477a8e1175bSopenharmony_ci * provisioned (#MBEDTLS_SSL_TLS1_3_PSK_EXTERNAL) or a 478a8e1175bSopenharmony_ci * resumption PSK (#MBEDTLS_SSL_TLS1_3_PSK_RESUMPTION). 479a8e1175bSopenharmony_ci * \param transcript The handshake transcript up to the point where the 480a8e1175bSopenharmony_ci * PSK binder calculation happens. This must be readable, 481a8e1175bSopenharmony_ci * and its size must be equal to the digest size of 482a8e1175bSopenharmony_ci * the hash algorithm represented by \p hash_alg. 483a8e1175bSopenharmony_ci * \param result The address at which to store the PSK binder on success. 484a8e1175bSopenharmony_ci * This must be writable, and its size must be equal to the 485a8e1175bSopenharmony_ci * digest size of the hash algorithm represented by 486a8e1175bSopenharmony_ci * \p hash_alg. 487a8e1175bSopenharmony_ci * 488a8e1175bSopenharmony_ci * \returns \c 0 on success. 489a8e1175bSopenharmony_ci * \returns A negative error code on failure. 490a8e1175bSopenharmony_ci */ 491a8e1175bSopenharmony_ciMBEDTLS_CHECK_RETURN_CRITICAL 492a8e1175bSopenharmony_ciint mbedtls_ssl_tls13_create_psk_binder(mbedtls_ssl_context *ssl, 493a8e1175bSopenharmony_ci const psa_algorithm_t hash_alg, 494a8e1175bSopenharmony_ci unsigned char const *psk, size_t psk_len, 495a8e1175bSopenharmony_ci int psk_type, 496a8e1175bSopenharmony_ci unsigned char const *transcript, 497a8e1175bSopenharmony_ci unsigned char *result); 498a8e1175bSopenharmony_ci 499a8e1175bSopenharmony_ci/** 500a8e1175bSopenharmony_ci * \bref Setup an SSL transform structure representing the 501a8e1175bSopenharmony_ci * record protection mechanism used by TLS 1.3 502a8e1175bSopenharmony_ci * 503a8e1175bSopenharmony_ci * \param transform The SSL transform structure to be created. This must have 504a8e1175bSopenharmony_ci * been initialized through mbedtls_ssl_transform_init() and 505a8e1175bSopenharmony_ci * not used in any other way prior to calling this function. 506a8e1175bSopenharmony_ci * In particular, this function does not clean up the 507a8e1175bSopenharmony_ci * transform structure prior to installing the new keys. 508a8e1175bSopenharmony_ci * \param endpoint Indicates whether the transform is for the client 509a8e1175bSopenharmony_ci * (value #MBEDTLS_SSL_IS_CLIENT) or the server 510a8e1175bSopenharmony_ci * (value #MBEDTLS_SSL_IS_SERVER). 511a8e1175bSopenharmony_ci * \param ciphersuite The numerical identifier for the ciphersuite to use. 512a8e1175bSopenharmony_ci * This must be one of the identifiers listed in 513a8e1175bSopenharmony_ci * ssl_ciphersuites.h. 514a8e1175bSopenharmony_ci * \param traffic_keys The key material to use. No reference is stored in 515a8e1175bSopenharmony_ci * the SSL transform being generated, and the caller 516a8e1175bSopenharmony_ci * should destroy the key material afterwards. 517a8e1175bSopenharmony_ci * \param ssl (Debug-only) The SSL context to use for debug output 518a8e1175bSopenharmony_ci * in case of failure. This parameter is only needed if 519a8e1175bSopenharmony_ci * #MBEDTLS_DEBUG_C is set, and is ignored otherwise. 520a8e1175bSopenharmony_ci * 521a8e1175bSopenharmony_ci * \return \c 0 on success. In this case, \p transform is ready to 522a8e1175bSopenharmony_ci * be used with mbedtls_ssl_transform_decrypt() and 523a8e1175bSopenharmony_ci * mbedtls_ssl_transform_encrypt(). 524a8e1175bSopenharmony_ci * \return A negative error code on failure. 525a8e1175bSopenharmony_ci */ 526a8e1175bSopenharmony_ciMBEDTLS_CHECK_RETURN_CRITICAL 527a8e1175bSopenharmony_ciint mbedtls_ssl_tls13_populate_transform(mbedtls_ssl_transform *transform, 528a8e1175bSopenharmony_ci int endpoint, 529a8e1175bSopenharmony_ci int ciphersuite, 530a8e1175bSopenharmony_ci mbedtls_ssl_key_set const *traffic_keys, 531a8e1175bSopenharmony_ci mbedtls_ssl_context *ssl); 532a8e1175bSopenharmony_ci 533a8e1175bSopenharmony_ci/* 534a8e1175bSopenharmony_ci * TLS 1.3 key schedule evolutions 535a8e1175bSopenharmony_ci * 536a8e1175bSopenharmony_ci * Early -> Handshake -> Application 537a8e1175bSopenharmony_ci * 538a8e1175bSopenharmony_ci * Small wrappers around mbedtls_ssl_tls13_evolve_secret(). 539a8e1175bSopenharmony_ci */ 540a8e1175bSopenharmony_ci 541a8e1175bSopenharmony_ci/** 542a8e1175bSopenharmony_ci * \brief Begin TLS 1.3 key schedule by calculating early secret. 543a8e1175bSopenharmony_ci * 544a8e1175bSopenharmony_ci * The TLS 1.3 key schedule can be viewed as a simple state machine 545a8e1175bSopenharmony_ci * with states Initial -> Early -> Handshake -> Application, and 546a8e1175bSopenharmony_ci * this function represents the Initial -> Early transition. 547a8e1175bSopenharmony_ci * 548a8e1175bSopenharmony_ci * \param ssl The SSL context to operate on. 549a8e1175bSopenharmony_ci * 550a8e1175bSopenharmony_ci * \returns \c 0 on success. 551a8e1175bSopenharmony_ci * \returns A negative error code on failure. 552a8e1175bSopenharmony_ci */ 553a8e1175bSopenharmony_ciMBEDTLS_CHECK_RETURN_CRITICAL 554a8e1175bSopenharmony_ciint mbedtls_ssl_tls13_key_schedule_stage_early(mbedtls_ssl_context *ssl); 555a8e1175bSopenharmony_ci 556a8e1175bSopenharmony_ci/** 557a8e1175bSopenharmony_ci * \brief Compute TLS 1.3 resumption master secret. 558a8e1175bSopenharmony_ci * 559a8e1175bSopenharmony_ci * \param ssl The SSL context to operate on. This must be in 560a8e1175bSopenharmony_ci * key schedule stage \c Application, see 561a8e1175bSopenharmony_ci * mbedtls_ssl_tls13_key_schedule_stage_application(). 562a8e1175bSopenharmony_ci * 563a8e1175bSopenharmony_ci * \returns \c 0 on success. 564a8e1175bSopenharmony_ci * \returns A negative error code on failure. 565a8e1175bSopenharmony_ci */ 566a8e1175bSopenharmony_ciMBEDTLS_CHECK_RETURN_CRITICAL 567a8e1175bSopenharmony_ciint mbedtls_ssl_tls13_compute_resumption_master_secret(mbedtls_ssl_context *ssl); 568a8e1175bSopenharmony_ci 569a8e1175bSopenharmony_ci/** 570a8e1175bSopenharmony_ci * \brief Calculate the verify_data value for the client or server TLS 1.3 571a8e1175bSopenharmony_ci * Finished message. 572a8e1175bSopenharmony_ci * 573a8e1175bSopenharmony_ci * \param ssl The SSL context to operate on. This must be in 574a8e1175bSopenharmony_ci * key schedule stage \c Handshake, see 575a8e1175bSopenharmony_ci * mbedtls_ssl_tls13_key_schedule_stage_application(). 576a8e1175bSopenharmony_ci * \param dst The address at which to write the verify_data value. 577a8e1175bSopenharmony_ci * \param dst_len The size of \p dst in bytes. 578a8e1175bSopenharmony_ci * \param actual_len The address at which to store the amount of data 579a8e1175bSopenharmony_ci * actually written to \p dst upon success. 580a8e1175bSopenharmony_ci * \param which The message to calculate the `verify_data` for: 581a8e1175bSopenharmony_ci * - #MBEDTLS_SSL_IS_CLIENT for the Client's Finished message 582a8e1175bSopenharmony_ci * - #MBEDTLS_SSL_IS_SERVER for the Server's Finished message 583a8e1175bSopenharmony_ci * 584a8e1175bSopenharmony_ci * \note Both client and server call this function twice, once to 585a8e1175bSopenharmony_ci * generate their own Finished message, and once to verify the 586a8e1175bSopenharmony_ci * peer's Finished message. 587a8e1175bSopenharmony_ci 588a8e1175bSopenharmony_ci * \returns \c 0 on success. 589a8e1175bSopenharmony_ci * \returns A negative error code on failure. 590a8e1175bSopenharmony_ci */ 591a8e1175bSopenharmony_ciMBEDTLS_CHECK_RETURN_CRITICAL 592a8e1175bSopenharmony_ciint mbedtls_ssl_tls13_calculate_verify_data(mbedtls_ssl_context *ssl, 593a8e1175bSopenharmony_ci unsigned char *dst, 594a8e1175bSopenharmony_ci size_t dst_len, 595a8e1175bSopenharmony_ci size_t *actual_len, 596a8e1175bSopenharmony_ci int which); 597a8e1175bSopenharmony_ci 598a8e1175bSopenharmony_ci#if defined(MBEDTLS_SSL_EARLY_DATA) 599a8e1175bSopenharmony_ci/** 600a8e1175bSopenharmony_ci * \brief Compute TLS 1.3 early transform 601a8e1175bSopenharmony_ci * 602a8e1175bSopenharmony_ci * \param ssl The SSL context to operate on. 603a8e1175bSopenharmony_ci * 604a8e1175bSopenharmony_ci * \returns \c 0 on success. 605a8e1175bSopenharmony_ci * \returns A negative error code on failure. 606a8e1175bSopenharmony_ci * 607a8e1175bSopenharmony_ci * \warning The function does not compute the early master secret. Call 608a8e1175bSopenharmony_ci * mbedtls_ssl_tls13_key_schedule_stage_early() before to 609a8e1175bSopenharmony_ci * call this function to generate the early master secret. 610a8e1175bSopenharmony_ci * \note For a client/server endpoint, the function computes only the 611a8e1175bSopenharmony_ci * encryption/decryption part of the transform as the decryption/ 612a8e1175bSopenharmony_ci * encryption part is not defined by the specification (no early 613a8e1175bSopenharmony_ci * traffic from the server to the client). 614a8e1175bSopenharmony_ci */ 615a8e1175bSopenharmony_ciMBEDTLS_CHECK_RETURN_CRITICAL 616a8e1175bSopenharmony_ciint mbedtls_ssl_tls13_compute_early_transform(mbedtls_ssl_context *ssl); 617a8e1175bSopenharmony_ci#endif /* MBEDTLS_SSL_EARLY_DATA */ 618a8e1175bSopenharmony_ci 619a8e1175bSopenharmony_ci/** 620a8e1175bSopenharmony_ci * \brief Compute TLS 1.3 handshake transform 621a8e1175bSopenharmony_ci * 622a8e1175bSopenharmony_ci * \param ssl The SSL context to operate on. The early secret must have been 623a8e1175bSopenharmony_ci * computed. 624a8e1175bSopenharmony_ci * 625a8e1175bSopenharmony_ci * \returns \c 0 on success. 626a8e1175bSopenharmony_ci * \returns A negative error code on failure. 627a8e1175bSopenharmony_ci */ 628a8e1175bSopenharmony_ciMBEDTLS_CHECK_RETURN_CRITICAL 629a8e1175bSopenharmony_ciint mbedtls_ssl_tls13_compute_handshake_transform(mbedtls_ssl_context *ssl); 630a8e1175bSopenharmony_ci 631a8e1175bSopenharmony_ci/** 632a8e1175bSopenharmony_ci * \brief Compute TLS 1.3 application transform 633a8e1175bSopenharmony_ci * 634a8e1175bSopenharmony_ci * \param ssl The SSL context to operate on. The early secret must have been 635a8e1175bSopenharmony_ci * computed. 636a8e1175bSopenharmony_ci * 637a8e1175bSopenharmony_ci * \returns \c 0 on success. 638a8e1175bSopenharmony_ci * \returns A negative error code on failure. 639a8e1175bSopenharmony_ci */ 640a8e1175bSopenharmony_ciMBEDTLS_CHECK_RETURN_CRITICAL 641a8e1175bSopenharmony_ciint mbedtls_ssl_tls13_compute_application_transform(mbedtls_ssl_context *ssl); 642a8e1175bSopenharmony_ci 643a8e1175bSopenharmony_ci#if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_PSK_ENABLED) 644a8e1175bSopenharmony_ci/** 645a8e1175bSopenharmony_ci * \brief Export TLS 1.3 PSK from handshake context 646a8e1175bSopenharmony_ci * 647a8e1175bSopenharmony_ci * \param[in] ssl The SSL context to operate on. 648a8e1175bSopenharmony_ci * \param[out] psk PSK output pointer. 649a8e1175bSopenharmony_ci * \param[out] psk_len Length of PSK. 650a8e1175bSopenharmony_ci * 651a8e1175bSopenharmony_ci * \returns \c 0 if there is a configured PSK and it was exported 652a8e1175bSopenharmony_ci * successfully. 653a8e1175bSopenharmony_ci * \returns A negative error code on failure. 654a8e1175bSopenharmony_ci */ 655a8e1175bSopenharmony_ciMBEDTLS_CHECK_RETURN_CRITICAL 656a8e1175bSopenharmony_ciint mbedtls_ssl_tls13_export_handshake_psk(mbedtls_ssl_context *ssl, 657a8e1175bSopenharmony_ci unsigned char **psk, 658a8e1175bSopenharmony_ci size_t *psk_len); 659a8e1175bSopenharmony_ci#endif 660a8e1175bSopenharmony_ci 661a8e1175bSopenharmony_ci#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */ 662a8e1175bSopenharmony_ci 663a8e1175bSopenharmony_ci#endif /* MBEDTLS_SSL_TLS1_3_KEYS_H */ 664