Coverage Report

Created: 2026-09-14 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/mbedtls/library/ssl_misc.h
Line
Count
Source
1
/**
2
 * \file ssl_misc.h
3
 *
4
 * \brief Internal functions shared by the SSL modules
5
 */
6
/*
7
 *  Copyright The Mbed TLS Contributors
8
 *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9
 */
10
#ifndef MBEDTLS_SSL_MISC_H
11
#define MBEDTLS_SSL_MISC_H
12
13
#include "mbedtls/build_info.h"
14
#include "common.h"
15
16
#include "mbedtls/error.h"
17
18
#include "mbedtls/ssl.h"
19
#include "mbedtls/debug.h"
20
#include "debug_internal.h"
21
22
#include "mbedtls/cipher.h"
23
24
#if defined(MBEDTLS_USE_PSA_CRYPTO) || defined(MBEDTLS_SSL_PROTO_TLS1_3)
25
#include "psa/crypto.h"
26
#include "psa_util_internal.h"
27
#endif
28
29
#if defined(MBEDTLS_MD_CAN_MD5)
30
#include "mbedtls/md5.h"
31
#endif
32
33
#if defined(MBEDTLS_MD_CAN_SHA1)
34
#include "mbedtls/sha1.h"
35
#endif
36
37
#if defined(MBEDTLS_MD_CAN_SHA256)
38
#include "mbedtls/sha256.h"
39
#endif
40
41
#if defined(MBEDTLS_MD_CAN_SHA512)
42
#include "mbedtls/sha512.h"
43
#endif
44
45
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) && \
46
    !defined(MBEDTLS_USE_PSA_CRYPTO)
47
#include "mbedtls/ecjpake.h"
48
#endif
49
50
#include "mbedtls/pk.h"
51
#include "ssl_ciphersuites_internal.h"
52
#include "x509_internal.h"
53
#include "pk_internal.h"
54
55
56
/* Shorthand for restartable ECC */
57
#if defined(MBEDTLS_ECP_RESTARTABLE) && \
58
    defined(MBEDTLS_SSL_CLI_C) && \
59
    defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
60
    defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
61
#define MBEDTLS_SSL_ECP_RESTARTABLE_ENABLED
62
#endif
63
64
37.5k
#define MBEDTLS_SSL_INITIAL_HANDSHAKE           0
65
37.6k
#define MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS   1   /* In progress */
66
0
#define MBEDTLS_SSL_RENEGOTIATION_DONE          2   /* Done or aborted */
67
0
#define MBEDTLS_SSL_RENEGOTIATION_PENDING       3   /* Requested (server only) */
68
69
/* Faked handshake message identity for HelloRetryRequest. */
70
0
#define MBEDTLS_SSL_TLS1_3_HS_HELLO_RETRY_REQUEST (-MBEDTLS_SSL_HS_SERVER_HELLO)
71
72
/*
73
 * Internal identity of handshake extensions
74
 */
75
5.78k
#define MBEDTLS_SSL_EXT_ID_UNRECOGNIZED                0
76
11.5k
#define MBEDTLS_SSL_EXT_ID_SERVERNAME                  1
77
#define MBEDTLS_SSL_EXT_ID_SERVERNAME_HOSTNAME         1
78
5.78k
#define MBEDTLS_SSL_EXT_ID_MAX_FRAGMENT_LENGTH         2
79
5.78k
#define MBEDTLS_SSL_EXT_ID_STATUS_REQUEST              3
80
11.5k
#define MBEDTLS_SSL_EXT_ID_SUPPORTED_GROUPS            4
81
#define MBEDTLS_SSL_EXT_ID_SUPPORTED_ELLIPTIC_CURVES   4
82
11.5k
#define MBEDTLS_SSL_EXT_ID_SIG_ALG                     5
83
5.78k
#define MBEDTLS_SSL_EXT_ID_USE_SRTP                    6
84
5.78k
#define MBEDTLS_SSL_EXT_ID_HEARTBEAT                   7
85
5.80k
#define MBEDTLS_SSL_EXT_ID_ALPN                        8
86
5.78k
#define MBEDTLS_SSL_EXT_ID_SCT                         9
87
5.78k
#define MBEDTLS_SSL_EXT_ID_CLI_CERT_TYPE              10
88
5.78k
#define MBEDTLS_SSL_EXT_ID_SERV_CERT_TYPE             11
89
5.78k
#define MBEDTLS_SSL_EXT_ID_PADDING                    12
90
5.78k
#define MBEDTLS_SSL_EXT_ID_PRE_SHARED_KEY             13
91
5.78k
#define MBEDTLS_SSL_EXT_ID_EARLY_DATA                 14
92
5.78k
#define MBEDTLS_SSL_EXT_ID_SUPPORTED_VERSIONS         15
93
5.78k
#define MBEDTLS_SSL_EXT_ID_COOKIE                     16
94
5.78k
#define MBEDTLS_SSL_EXT_ID_PSK_KEY_EXCHANGE_MODES     17
95
5.78k
#define MBEDTLS_SSL_EXT_ID_CERT_AUTH                  18
96
5.78k
#define MBEDTLS_SSL_EXT_ID_OID_FILTERS                19
97
5.78k
#define MBEDTLS_SSL_EXT_ID_POST_HANDSHAKE_AUTH        20
98
5.78k
#define MBEDTLS_SSL_EXT_ID_SIG_ALG_CERT               21
99
5.78k
#define MBEDTLS_SSL_EXT_ID_KEY_SHARE                  22
100
5.78k
#define MBEDTLS_SSL_EXT_ID_TRUNCATED_HMAC             23
101
5.78k
#define MBEDTLS_SSL_EXT_ID_SUPPORTED_POINT_FORMATS    24
102
5.78k
#define MBEDTLS_SSL_EXT_ID_ENCRYPT_THEN_MAC           25
103
5.78k
#define MBEDTLS_SSL_EXT_ID_EXTENDED_MASTER_SECRET     26
104
5.78k
#define MBEDTLS_SSL_EXT_ID_SESSION_TICKET             27
105
5.78k
#define MBEDTLS_SSL_EXT_ID_RECORD_SIZE_LIMIT          28
106
107
/* Utility for translating IANA extension type. */
108
uint32_t mbedtls_ssl_get_extension_id(unsigned int extension_type);
109
uint32_t mbedtls_ssl_get_extension_mask(unsigned int extension_type);
110
/* Macros used to define mask constants */
111
0
#define MBEDTLS_SSL_EXT_MASK(id)       (1ULL << (MBEDTLS_SSL_EXT_ID_##id))
112
/* Reset value of extension mask */
113
5.80k
#define MBEDTLS_SSL_EXT_MASK_NONE                                              0
114
115
/* In messages containing extension requests, we should ignore unrecognized
116
 * extensions. In messages containing extension responses, unrecognized
117
 * extensions should result in handshake abortion. Messages containing
118
 * extension requests include ClientHello, CertificateRequest and
119
 * NewSessionTicket. Messages containing extension responses include
120
 * ServerHello, HelloRetryRequest, EncryptedExtensions and Certificate.
121
 *
122
 * RFC 8446 section 4.1.3
123
 *
124
 * The ServerHello MUST only include extensions which are required to establish
125
 * the cryptographic context and negotiate the protocol version.
126
 *
127
 * RFC 8446 section 4.2
128
 *
129
 * If an implementation receives an extension which it recognizes and which is
130
 * not specified for the message in which it appears, it MUST abort the handshake
131
 * with an "illegal_parameter" alert.
132
 */
133
134
/* Extensions that are not recognized by TLS 1.3 */
135
#define MBEDTLS_SSL_TLS1_3_EXT_MASK_UNRECOGNIZED                               \
136
0
    (MBEDTLS_SSL_EXT_MASK(SUPPORTED_POINT_FORMATS)                | \
137
0
     MBEDTLS_SSL_EXT_MASK(ENCRYPT_THEN_MAC)                       | \
138
0
     MBEDTLS_SSL_EXT_MASK(EXTENDED_MASTER_SECRET)                 | \
139
0
     MBEDTLS_SSL_EXT_MASK(SESSION_TICKET)                         | \
140
0
     MBEDTLS_SSL_EXT_MASK(TRUNCATED_HMAC)                         | \
141
0
     MBEDTLS_SSL_EXT_MASK(UNRECOGNIZED))
142
143
/* RFC 8446 section 4.2. Allowed extensions for ClientHello */
144
#define MBEDTLS_SSL_TLS1_3_ALLOWED_EXTS_OF_CH                                  \
145
0
    (MBEDTLS_SSL_EXT_MASK(SERVERNAME)                             | \
146
0
     MBEDTLS_SSL_EXT_MASK(MAX_FRAGMENT_LENGTH)                    | \
147
0
     MBEDTLS_SSL_EXT_MASK(STATUS_REQUEST)                         | \
148
0
     MBEDTLS_SSL_EXT_MASK(SUPPORTED_GROUPS)                       | \
149
0
     MBEDTLS_SSL_EXT_MASK(SIG_ALG)                                | \
150
0
     MBEDTLS_SSL_EXT_MASK(USE_SRTP)                               | \
151
0
     MBEDTLS_SSL_EXT_MASK(HEARTBEAT)                              | \
152
0
     MBEDTLS_SSL_EXT_MASK(ALPN)                                   | \
153
0
     MBEDTLS_SSL_EXT_MASK(SCT)                                    | \
154
0
     MBEDTLS_SSL_EXT_MASK(CLI_CERT_TYPE)                          | \
155
0
     MBEDTLS_SSL_EXT_MASK(SERV_CERT_TYPE)                         | \
156
0
     MBEDTLS_SSL_EXT_MASK(PADDING)                                | \
157
0
     MBEDTLS_SSL_EXT_MASK(KEY_SHARE)                              | \
158
0
     MBEDTLS_SSL_EXT_MASK(PRE_SHARED_KEY)                         | \
159
0
     MBEDTLS_SSL_EXT_MASK(PSK_KEY_EXCHANGE_MODES)                 | \
160
0
     MBEDTLS_SSL_EXT_MASK(EARLY_DATA)                             | \
161
0
     MBEDTLS_SSL_EXT_MASK(COOKIE)                                 | \
162
0
     MBEDTLS_SSL_EXT_MASK(SUPPORTED_VERSIONS)                     | \
163
0
     MBEDTLS_SSL_EXT_MASK(CERT_AUTH)                              | \
164
0
     MBEDTLS_SSL_EXT_MASK(POST_HANDSHAKE_AUTH)                    | \
165
0
     MBEDTLS_SSL_EXT_MASK(SIG_ALG_CERT)                           | \
166
0
     MBEDTLS_SSL_EXT_MASK(RECORD_SIZE_LIMIT)                      | \
167
0
     MBEDTLS_SSL_TLS1_3_EXT_MASK_UNRECOGNIZED)
168
169
/* RFC 8446 section 4.2. Allowed extensions for EncryptedExtensions */
170
#define MBEDTLS_SSL_TLS1_3_ALLOWED_EXTS_OF_EE                                  \
171
0
    (MBEDTLS_SSL_EXT_MASK(SERVERNAME)                             | \
172
0
     MBEDTLS_SSL_EXT_MASK(MAX_FRAGMENT_LENGTH)                    | \
173
0
     MBEDTLS_SSL_EXT_MASK(SUPPORTED_GROUPS)                       | \
174
0
     MBEDTLS_SSL_EXT_MASK(USE_SRTP)                               | \
175
0
     MBEDTLS_SSL_EXT_MASK(HEARTBEAT)                              | \
176
0
     MBEDTLS_SSL_EXT_MASK(ALPN)                                   | \
177
0
     MBEDTLS_SSL_EXT_MASK(CLI_CERT_TYPE)                          | \
178
0
     MBEDTLS_SSL_EXT_MASK(SERV_CERT_TYPE)                         | \
179
0
     MBEDTLS_SSL_EXT_MASK(EARLY_DATA)                             | \
180
0
     MBEDTLS_SSL_EXT_MASK(RECORD_SIZE_LIMIT))
181
182
/* RFC 8446 section 4.2. Allowed extensions for CertificateRequest */
183
#define MBEDTLS_SSL_TLS1_3_ALLOWED_EXTS_OF_CR                                  \
184
0
    (MBEDTLS_SSL_EXT_MASK(STATUS_REQUEST)                         | \
185
0
     MBEDTLS_SSL_EXT_MASK(SIG_ALG)                                | \
186
0
     MBEDTLS_SSL_EXT_MASK(SCT)                                    | \
187
0
     MBEDTLS_SSL_EXT_MASK(CERT_AUTH)                              | \
188
0
     MBEDTLS_SSL_EXT_MASK(OID_FILTERS)                            | \
189
0
     MBEDTLS_SSL_EXT_MASK(SIG_ALG_CERT)                           | \
190
0
     MBEDTLS_SSL_TLS1_3_EXT_MASK_UNRECOGNIZED)
191
192
/* RFC 8446 section 4.2. Allowed extensions for Certificate */
193
#define MBEDTLS_SSL_TLS1_3_ALLOWED_EXTS_OF_CT                                  \
194
0
    (MBEDTLS_SSL_EXT_MASK(STATUS_REQUEST)                         | \
195
0
     MBEDTLS_SSL_EXT_MASK(SCT))
196
197
/* RFC 8446 section 4.2. Allowed extensions for ServerHello */
198
#define MBEDTLS_SSL_TLS1_3_ALLOWED_EXTS_OF_SH                                  \
199
0
    (MBEDTLS_SSL_EXT_MASK(KEY_SHARE)                              | \
200
0
     MBEDTLS_SSL_EXT_MASK(PRE_SHARED_KEY)                         | \
201
0
     MBEDTLS_SSL_EXT_MASK(SUPPORTED_VERSIONS))
202
203
/* RFC 8446 section 4.2. Allowed extensions for HelloRetryRequest */
204
#define MBEDTLS_SSL_TLS1_3_ALLOWED_EXTS_OF_HRR                                 \
205
0
    (MBEDTLS_SSL_EXT_MASK(KEY_SHARE)                              | \
206
0
     MBEDTLS_SSL_EXT_MASK(COOKIE)                                 | \
207
0
     MBEDTLS_SSL_EXT_MASK(SUPPORTED_VERSIONS))
208
209
/* RFC 8446 section 4.2. Allowed extensions for NewSessionTicket */
210
#define MBEDTLS_SSL_TLS1_3_ALLOWED_EXTS_OF_NST                                 \
211
0
    (MBEDTLS_SSL_EXT_MASK(EARLY_DATA)                             | \
212
0
     MBEDTLS_SSL_TLS1_3_EXT_MASK_UNRECOGNIZED)
213
214
/*
215
 * Helper macros for function call with return check.
216
 */
217
/*
218
 * Exit when return non-zero value
219
 */
220
#define MBEDTLS_SSL_PROC_CHK(f)                               \
221
19.1k
    do {                                                        \
222
19.1k
        ret = (f);                                            \
223
19.1k
        if (ret != 0)                                          \
224
19.1k
        {                                                       \
225
407
            goto cleanup;                                       \
226
407
        }                                                       \
227
19.1k
    } while (0)
228
/*
229
 * Exit when return negative value
230
 */
231
#define MBEDTLS_SSL_PROC_CHK_NEG(f)                           \
232
1.39k
    do {                                                        \
233
1.39k
        ret = (f);                                            \
234
1.39k
        if (ret < 0)                                           \
235
1.39k
        {                                                       \
236
176
            goto cleanup;                                       \
237
176
        }                                                       \
238
1.39k
    } while (0)
239
240
/*
241
 * DTLS retransmission states, see RFC 6347 4.2.4
242
 *
243
 * The SENDING state is merged in PREPARING for initial sends,
244
 * but is distinct for resends.
245
 *
246
 * Note: initial state is wrong for server, but is not used anyway.
247
 */
248
6.76k
#define MBEDTLS_SSL_RETRANS_PREPARING       0
249
84.2k
#define MBEDTLS_SSL_RETRANS_SENDING         1
250
28.8k
#define MBEDTLS_SSL_RETRANS_WAITING         2
251
0
#define MBEDTLS_SSL_RETRANS_FINISHED        3
252
253
/*
254
 * Allow extra bytes for record, authentication and encryption overhead:
255
 * counter (8) + header (5) + IV(16) + MAC (16-48) + padding (0-256).
256
 */
257
258
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
259
260
/* This macro determines whether CBC is supported. */
261
#if defined(MBEDTLS_SSL_HAVE_CBC)      &&                                  \
262
    (defined(MBEDTLS_SSL_HAVE_AES)     ||                                  \
263
    defined(MBEDTLS_SSL_HAVE_CAMELLIA) ||                                  \
264
    defined(MBEDTLS_SSL_HAVE_ARIA))
265
#define MBEDTLS_SSL_SOME_SUITES_USE_CBC
266
#endif
267
268
/* This macro determines whether a ciphersuite using a
269
 * stream cipher can be used. */
270
#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
271
#define MBEDTLS_SSL_SOME_SUITES_USE_STREAM
272
#endif
273
274
/* This macro determines whether the CBC construct used in TLS 1.2 is supported. */
275
#if defined(MBEDTLS_SSL_SOME_SUITES_USE_CBC) && \
276
    defined(MBEDTLS_SSL_PROTO_TLS1_2)
277
#define MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC
278
#endif
279
280
#if defined(MBEDTLS_SSL_SOME_SUITES_USE_STREAM) || \
281
    defined(MBEDTLS_SSL_SOME_SUITES_USE_CBC)
282
#define MBEDTLS_SSL_SOME_SUITES_USE_MAC
283
#endif
284
285
/* This macro determines whether a ciphersuite uses Encrypt-then-MAC with CBC */
286
#if defined(MBEDTLS_SSL_SOME_SUITES_USE_CBC) && \
287
    defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
288
#define MBEDTLS_SSL_SOME_SUITES_USE_CBC_ETM
289
#endif
290
291
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
292
293
#if defined(MBEDTLS_SSL_SOME_SUITES_USE_MAC)
294
/* Ciphersuites using HMAC */
295
#if defined(MBEDTLS_MD_CAN_SHA384)
296
60.9k
#define MBEDTLS_SSL_MAC_ADD                 48  /* SHA-384 used for HMAC */
297
#elif defined(MBEDTLS_MD_CAN_SHA256)
298
#define MBEDTLS_SSL_MAC_ADD                 32  /* SHA-256 used for HMAC */
299
#else
300
#define MBEDTLS_SSL_MAC_ADD                 20  /* SHA-1   used for HMAC */
301
#endif
302
#else /* MBEDTLS_SSL_SOME_SUITES_USE_MAC */
303
/* AEAD ciphersuites: GCM and CCM use a 128 bits tag */
304
#define MBEDTLS_SSL_MAC_ADD                 16
305
#endif
306
307
#if defined(MBEDTLS_SSL_HAVE_CBC)
308
60.9k
#define MBEDTLS_SSL_PADDING_ADD            256
309
#else
310
#define MBEDTLS_SSL_PADDING_ADD              0
311
#endif
312
313
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
314
60.9k
#define MBEDTLS_SSL_MAX_CID_EXPANSION      MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY
315
#else
316
#define MBEDTLS_SSL_MAX_CID_EXPANSION        0
317
#endif
318
319
60.9k
#define MBEDTLS_SSL_PAYLOAD_OVERHEAD (MBEDTLS_MAX_IV_LENGTH +          \
320
60.9k
                                      MBEDTLS_SSL_MAC_ADD +            \
321
60.9k
                                      MBEDTLS_SSL_PADDING_ADD +        \
322
60.9k
                                      MBEDTLS_SSL_MAX_CID_EXPANSION    \
323
60.9k
                                      )
324
325
19.7k
#define MBEDTLS_SSL_IN_PAYLOAD_LEN (MBEDTLS_SSL_PAYLOAD_OVERHEAD + \
326
19.7k
                                    (MBEDTLS_SSL_IN_CONTENT_LEN))
327
328
19.7k
#define MBEDTLS_SSL_OUT_PAYLOAD_LEN (MBEDTLS_SSL_PAYLOAD_OVERHEAD + \
329
19.7k
                                     (MBEDTLS_SSL_OUT_CONTENT_LEN))
330
331
/* The maximum number of buffered handshake messages. */
332
261k
#define MBEDTLS_SSL_MAX_BUFFERED_HS 4
333
334
/* Maximum length we can advertise as our max content length for
335
   RFC 6066 max_fragment_length extension negotiation purposes
336
   (the lesser of both sizes, if they are unequal.)
337
 */
338
256k
#define MBEDTLS_TLS_EXT_ADV_CONTENT_LEN (                            \
339
256k
        (MBEDTLS_SSL_IN_CONTENT_LEN > MBEDTLS_SSL_OUT_CONTENT_LEN)   \
340
256k
        ? (MBEDTLS_SSL_OUT_CONTENT_LEN)                            \
341
256k
        : (MBEDTLS_SSL_IN_CONTENT_LEN)                             \
342
256k
        )
343
344
/* Maximum size in bytes of list in signature algorithms ext., RFC 5246/8446 */
345
0
#define MBEDTLS_SSL_MAX_SIG_ALG_LIST_LEN       65534
346
347
/* Minimum size in bytes of list in signature algorithms ext., RFC 5246/8446 */
348
0
#define MBEDTLS_SSL_MIN_SIG_ALG_LIST_LEN       2
349
350
/* Maximum size in bytes of list in supported elliptic curve ext., RFC 4492 */
351
#define MBEDTLS_SSL_MAX_CURVE_LIST_LEN         65535
352
353
7.61k
#define MBEDTLS_RECEIVED_SIG_ALGS_SIZE         20
354
355
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
356
357
312k
#define MBEDTLS_TLS_SIG_NONE MBEDTLS_TLS1_3_SIG_NONE
358
359
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
360
1.14k
#define MBEDTLS_SSL_TLS12_SIG_AND_HASH_ALG(sig, hash) ((hash << 8) | sig)
361
0
#define MBEDTLS_SSL_TLS12_SIG_ALG_FROM_SIG_AND_HASH_ALG(alg) (alg & 0xFF)
362
0
#define MBEDTLS_SSL_TLS12_HASH_ALG_FROM_SIG_AND_HASH_ALG(alg) (alg >> 8)
363
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
364
365
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
366
367
/*
368
 * Check that we obey the standard's message size bounds
369
 */
370
371
#if MBEDTLS_SSL_IN_CONTENT_LEN > 16384
372
#error "Bad configuration - incoming record content too large."
373
#endif
374
375
#if MBEDTLS_SSL_OUT_CONTENT_LEN > 16384
376
#error "Bad configuration - outgoing record content too large."
377
#endif
378
379
#if MBEDTLS_SSL_IN_PAYLOAD_LEN > MBEDTLS_SSL_IN_CONTENT_LEN + 2048
380
#error "Bad configuration - incoming protected record payload too large."
381
#endif
382
383
#if MBEDTLS_SSL_OUT_PAYLOAD_LEN > MBEDTLS_SSL_OUT_CONTENT_LEN + 2048
384
#error "Bad configuration - outgoing protected record payload too large."
385
#endif
386
387
/* Calculate buffer sizes */
388
389
/* Note: Even though the TLS record header is only 5 bytes
390
   long, we're internally using 8 bytes to store the
391
   implicit sequence number. */
392
60.9k
#define MBEDTLS_SSL_HEADER_LEN 13
393
394
#if !defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
395
#define MBEDTLS_SSL_IN_BUFFER_LEN  \
396
    ((MBEDTLS_SSL_HEADER_LEN) + (MBEDTLS_SSL_IN_PAYLOAD_LEN))
397
#else
398
#define MBEDTLS_SSL_IN_BUFFER_LEN  \
399
19.7k
    ((MBEDTLS_SSL_HEADER_LEN) + (MBEDTLS_SSL_IN_PAYLOAD_LEN) \
400
19.7k
     + (MBEDTLS_SSL_CID_IN_LEN_MAX))
401
#endif
402
403
#if !defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
404
#define MBEDTLS_SSL_OUT_BUFFER_LEN  \
405
    ((MBEDTLS_SSL_HEADER_LEN) + (MBEDTLS_SSL_OUT_PAYLOAD_LEN))
406
#else
407
#define MBEDTLS_SSL_OUT_BUFFER_LEN                               \
408
19.7k
    ((MBEDTLS_SSL_HEADER_LEN) + (MBEDTLS_SSL_OUT_PAYLOAD_LEN)    \
409
19.7k
     + (MBEDTLS_SSL_CID_OUT_LEN_MAX))
410
#endif
411
412
18.3k
#define MBEDTLS_CLIENT_HELLO_RANDOM_LEN 32
413
0
#define MBEDTLS_SERVER_HELLO_RANDOM_LEN 32
414
415
#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
416
/**
417
 * \brief          Return the maximum fragment length (payload, in bytes) for
418
 *                 the output buffer. For the client, this is the configured
419
 *                 value. For the server, it is the minimum of two - the
420
 *                 configured value and the negotiated one.
421
 *
422
 * \sa             mbedtls_ssl_conf_max_frag_len()
423
 * \sa             mbedtls_ssl_get_max_out_record_payload()
424
 *
425
 * \param ssl      SSL context
426
 *
427
 * \return         Current maximum fragment length for the output buffer.
428
 */
429
size_t mbedtls_ssl_get_output_max_frag_len(const mbedtls_ssl_context *ssl);
430
431
/**
432
 * \brief          Return the maximum fragment length (payload, in bytes) for
433
 *                 the input buffer. This is the negotiated maximum fragment
434
 *                 length, or, if there is none, MBEDTLS_SSL_IN_CONTENT_LEN.
435
 *                 If it is not defined either, the value is 2^14. This function
436
 *                 works as its predecessor, \c mbedtls_ssl_get_max_frag_len().
437
 *
438
 * \sa             mbedtls_ssl_conf_max_frag_len()
439
 * \sa             mbedtls_ssl_get_max_in_record_payload()
440
 *
441
 * \param ssl      SSL context
442
 *
443
 * \return         Current maximum fragment length for the output buffer.
444
 */
445
size_t mbedtls_ssl_get_input_max_frag_len(const mbedtls_ssl_context *ssl);
446
#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
447
448
#if defined(MBEDTLS_SSL_RECORD_SIZE_LIMIT)
449
/**
450
 * \brief    Get the size limit in bytes for the protected outgoing records
451
 *           as defined in RFC 8449
452
 *
453
 * \param ssl      SSL context
454
 *
455
 * \return         The size limit in bytes for the protected outgoing
456
 *                 records as defined in RFC 8449.
457
 */
458
size_t mbedtls_ssl_get_output_record_size_limit(const mbedtls_ssl_context *ssl);
459
#endif /* MBEDTLS_SSL_RECORD_SIZE_LIMIT */
460
461
#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
462
static inline size_t mbedtls_ssl_get_output_buflen(const mbedtls_ssl_context *ctx)
463
10.7k
{
464
10.7k
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
465
10.7k
    return mbedtls_ssl_get_output_max_frag_len(ctx)
466
10.7k
           + MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD
467
10.7k
           + MBEDTLS_SSL_CID_OUT_LEN_MAX;
468
#else
469
    return mbedtls_ssl_get_output_max_frag_len(ctx)
470
           + MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD;
471
#endif
472
10.7k
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_get_output_buflen
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_get_output_buflen
ssl_tls.c:mbedtls_ssl_get_output_buflen
Line
Count
Source
463
10.7k
{
464
10.7k
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
465
10.7k
    return mbedtls_ssl_get_output_max_frag_len(ctx)
466
10.7k
           + MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD
467
10.7k
           + MBEDTLS_SSL_CID_OUT_LEN_MAX;
468
#else
469
    return mbedtls_ssl_get_output_max_frag_len(ctx)
470
           + MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD;
471
#endif
472
10.7k
}
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_get_output_buflen
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_get_output_buflen
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_get_output_buflen
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_get_output_buflen
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_get_output_buflen
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_get_output_buflen
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_get_output_buflen
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_get_output_buflen
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_get_output_buflen
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_get_output_buflen
473
474
static inline size_t mbedtls_ssl_get_input_buflen(const mbedtls_ssl_context *ctx)
475
10.7k
{
476
10.7k
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
477
10.7k
    return mbedtls_ssl_get_input_max_frag_len(ctx)
478
10.7k
           + MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD
479
10.7k
           + MBEDTLS_SSL_CID_IN_LEN_MAX;
480
#else
481
    return mbedtls_ssl_get_input_max_frag_len(ctx)
482
           + MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD;
483
#endif
484
10.7k
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_get_input_buflen
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_get_input_buflen
ssl_tls.c:mbedtls_ssl_get_input_buflen
Line
Count
Source
475
10.7k
{
476
10.7k
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
477
10.7k
    return mbedtls_ssl_get_input_max_frag_len(ctx)
478
10.7k
           + MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD
479
10.7k
           + MBEDTLS_SSL_CID_IN_LEN_MAX;
480
#else
481
    return mbedtls_ssl_get_input_max_frag_len(ctx)
482
           + MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD;
483
#endif
484
10.7k
}
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_get_input_buflen
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_get_input_buflen
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_get_input_buflen
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_get_input_buflen
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_get_input_buflen
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_get_input_buflen
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_get_input_buflen
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_get_input_buflen
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_get_input_buflen
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_get_input_buflen
485
#endif
486
487
/** Get `ssl->badmac_seen`. This field is encoded as
488
 * mbedtls_ssl_context::badmac_seen_or_in_hsfraglen in DTLS contexts,
489
 * and doesn't exist in TLS contexts.
490
 *
491
 * \param[in] ssl       The SSL context to read.
492
 *
493
 * \return In DTLS, the value of `badmac_seen`. In TLS, 0 (there can't have
494
 *         been a record with a bad MAC in TLS, since those abort the
495
 *         connection immediately).
496
 */
497
static inline unsigned mbedtls_ssl_get_badmac_seen(const mbedtls_ssl_context *ssl)
498
0
{
499
0
#if defined(MBEDTLS_SSL_PROTO_DTLS)
500
0
    if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
501
0
        return ssl->badmac_seen_or_in_hsfraglen;
502
0
    }
503
0
#endif
504
0
    (void) ssl;
505
0
    return 0;
506
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_get_badmac_seen
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_get_badmac_seen
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_get_badmac_seen
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_get_badmac_seen
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_get_badmac_seen
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_get_badmac_seen
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_get_badmac_seen
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_get_badmac_seen
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_get_badmac_seen
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_get_badmac_seen
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_get_badmac_seen
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_get_badmac_seen
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_get_badmac_seen
507
508
#if defined(MBEDTLS_SSL_PROTO_DTLS)
509
/* We shouldn't be trying to set badmac_seen if DTLS support is disabled
510
 * at compile time. If this is called from a code block that checks for the
511
 * DTLS protocol at run time, it should be guarded by
512
 * defined(MBEDTLS_SSL_PROTO_DTLS). */
513
/** Set `ssl->badmac_seen`. This field is encoded as
514
 * mbedtls_ssl_context::badmac_seen_or_in_hsfraglen in DTLS contexts,
515
 * and doesn't exist in TLS contexts.
516
 *
517
 * \param[in,out] ssl   The SSL context to modify.
518
 * \param badmac_seen   The new value of `badmac_seen`.
519
 *
520
 * \return 0 in DTLS, #MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED in TLS.
521
 */
522
MBEDTLS_CHECK_RETURN_CRITICAL
523
static inline int mbedtls_ssl_set_badmac_seen(mbedtls_ssl_context *ssl,
524
                                              unsigned badmac_seen)
525
0
{
526
0
    if ((ssl)->conf->transport != MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
527
0
        MBEDTLS_SSL_DEBUG_RET(1, ("Internal error: trying to set badmac_seen in TLS"),
528
0
                              MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED);
529
0
        return MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
530
0
    }
531
0
    ssl->badmac_seen_or_in_hsfraglen = badmac_seen;
532
0
    return 0;
533
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_set_badmac_seen
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_set_badmac_seen
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_set_badmac_seen
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_set_badmac_seen
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_set_badmac_seen
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_set_badmac_seen
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_set_badmac_seen
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_set_badmac_seen
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_set_badmac_seen
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_set_badmac_seen
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_set_badmac_seen
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_set_badmac_seen
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_set_badmac_seen
534
#endif
535
536
/** Get `ssl->in_hsfraglen`. This field is encoded as
537
 * mbedtls_ssl_context::badmac_seen_or_in_hsfraglen in TLS contexts,
538
 * and doesn't exist in DTLS contexts.
539
 *
540
 * \param[in] ssl       The SSL context to read.
541
 *
542
 * \return In TLS, the value of `in_hsfraglen`. In DTLS, 0 (handshake
543
 *         message defragmentation is handled different in DTLS, and
544
 *         does not use this field).
545
 */
546
static inline unsigned mbedtls_ssl_get_in_hsfraglen(const mbedtls_ssl_context *ssl)
547
270k
{
548
270k
#if defined(MBEDTLS_SSL_PROTO_DTLS)
549
270k
    if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
550
104k
        return 0;
551
104k
    }
552
165k
#endif
553
165k
    return ssl->badmac_seen_or_in_hsfraglen;
554
270k
}
ssl_msg.c:mbedtls_ssl_get_in_hsfraglen
Line
Count
Source
547
270k
{
548
270k
#if defined(MBEDTLS_SSL_PROTO_DTLS)
549
270k
    if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
550
104k
        return 0;
551
104k
    }
552
165k
#endif
553
165k
    return ssl->badmac_seen_or_in_hsfraglen;
554
270k
}
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_get_in_hsfraglen
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_get_in_hsfraglen
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_get_in_hsfraglen
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_get_in_hsfraglen
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_get_in_hsfraglen
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_get_in_hsfraglen
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_get_in_hsfraglen
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_get_in_hsfraglen
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_get_in_hsfraglen
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_get_in_hsfraglen
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_get_in_hsfraglen
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_get_in_hsfraglen
555
556
/** Set `ssl->in_hsfraglen`. This field is encoded as
557
 * mbedtls_ssl_context::badmac_seen_or_in_hsfraglen in TLS contexts,
558
 * and doesn't exist in DTLS contexts.
559
 *
560
 * \param[in,out] ssl   The SSL context to modify.
561
 * \param in_hsfraglen  The new value of `in_hsfraglen`.
562
 *
563
 * \return 0 in TLS, #MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED in DTLS.
564
 */
565
MBEDTLS_CHECK_RETURN_CRITICAL
566
static inline int mbedtls_ssl_set_in_hsfraglen(mbedtls_ssl_context *ssl,
567
                                               unsigned in_hsfraglen)
568
33.3k
{
569
33.3k
#if defined(MBEDTLS_SSL_PROTO_DTLS)
570
33.3k
    if ((ssl)->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
571
0
        MBEDTLS_SSL_DEBUG_RET(1, ("Internal error: trying to set in_hsfraglen in DTLS"),
572
0
                              MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED);
573
0
        return MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
574
0
    }
575
33.3k
#endif
576
33.3k
    ssl->badmac_seen_or_in_hsfraglen = in_hsfraglen;
577
33.3k
    return 0;
578
33.3k
}
ssl_msg.c:mbedtls_ssl_set_in_hsfraglen
Line
Count
Source
568
33.3k
{
569
33.3k
#if defined(MBEDTLS_SSL_PROTO_DTLS)
570
33.3k
    if ((ssl)->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
571
0
        MBEDTLS_SSL_DEBUG_RET(1, ("Internal error: trying to set in_hsfraglen in DTLS"),
572
0
                              MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED);
573
0
        return MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
574
0
    }
575
33.3k
#endif
576
33.3k
    ssl->badmac_seen_or_in_hsfraglen = in_hsfraglen;
577
33.3k
    return 0;
578
33.3k
}
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_set_in_hsfraglen
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_set_in_hsfraglen
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_set_in_hsfraglen
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_set_in_hsfraglen
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_set_in_hsfraglen
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_set_in_hsfraglen
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_set_in_hsfraglen
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_set_in_hsfraglen
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_set_in_hsfraglen
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_set_in_hsfraglen
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_set_in_hsfraglen
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_set_in_hsfraglen
579
580
/*
581
 * TLS extension flags (for extensions with outgoing ServerHello content
582
 * that need it (e.g. for RENEGOTIATION_INFO the server already knows because
583
 * of state of the renegotiation flag, so no indicator is required)
584
 */
585
4.00k
#define MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS_PRESENT (1 << 0)
586
869
#define MBEDTLS_TLS_EXT_ECJPAKE_KKPP_OK                 (1 << 1)
587
588
/**
589
 * \brief        This function checks if the remaining size in a buffer is
590
 *               greater or equal than a needed space.
591
 *
592
 * \param cur    Pointer to the current position in the buffer.
593
 * \param end    Pointer to one past the end of the buffer.
594
 * \param need   Needed space in bytes.
595
 *
596
 * \return       Zero if the needed space is available in the buffer, non-zero
597
 *               otherwise.
598
 */
599
#if !defined(MBEDTLS_TEST_HOOKS)
600
static inline int mbedtls_ssl_chk_buf_ptr(const uint8_t *cur,
601
                                          const uint8_t *end, size_t need)
602
{
603
    return (cur > end) || (need > (size_t) (end - cur));
604
}
605
#else
606
typedef struct {
607
    const uint8_t *cur;
608
    const uint8_t *end;
609
    size_t need;
610
} mbedtls_ssl_chk_buf_ptr_args;
611
612
void mbedtls_ssl_set_chk_buf_ptr_fail_args(
613
    const uint8_t *cur, const uint8_t *end, size_t need);
614
void mbedtls_ssl_reset_chk_buf_ptr_fail_args(void);
615
616
MBEDTLS_CHECK_RETURN_CRITICAL
617
int mbedtls_ssl_cmp_chk_buf_ptr_fail_args(mbedtls_ssl_chk_buf_ptr_args *args);
618
619
static inline int mbedtls_ssl_chk_buf_ptr(const uint8_t *cur,
620
                                          const uint8_t *end, size_t need)
621
934k
{
622
934k
    if ((cur > end) || (need > (size_t) (end - cur))) {
623
468
        mbedtls_ssl_set_chk_buf_ptr_fail_args(cur, end, need);
624
468
        return 1;
625
468
    }
626
934k
    return 0;
627
934k
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_chk_buf_ptr
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_chk_buf_ptr
ssl_tls.c:mbedtls_ssl_chk_buf_ptr
Line
Count
Source
621
142k
{
622
142k
    if ((cur > end) || (need > (size_t) (end - cur))) {
623
340
        mbedtls_ssl_set_chk_buf_ptr_fail_args(cur, end, need);
624
340
        return 1;
625
340
    }
626
141k
    return 0;
627
142k
}
ssl_tls12_client.c:mbedtls_ssl_chk_buf_ptr
Line
Count
Source
621
23.7k
{
622
23.7k
    if ((cur > end) || (need > (size_t) (end - cur))) {
623
4
        mbedtls_ssl_set_chk_buf_ptr_fail_args(cur, end, need);
624
4
        return 1;
625
4
    }
626
23.7k
    return 0;
627
23.7k
}
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_chk_buf_ptr
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_chk_buf_ptr
ssl_tls13_server.c:mbedtls_ssl_chk_buf_ptr
Line
Count
Source
621
9.39k
{
622
9.39k
    if ((cur > end) || (need > (size_t) (end - cur))) {
623
69
        mbedtls_ssl_set_chk_buf_ptr_fail_args(cur, end, need);
624
69
        return 1;
625
69
    }
626
9.33k
    return 0;
627
9.39k
}
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_chk_buf_ptr
ssl_tls13_generic.c:mbedtls_ssl_chk_buf_ptr
Line
Count
Source
621
14.9k
{
622
14.9k
    if ((cur > end) || (need > (size_t) (end - cur))) {
623
55
        mbedtls_ssl_set_chk_buf_ptr_fail_args(cur, end, need);
624
55
        return 1;
625
55
    }
626
14.8k
    return 0;
627
14.9k
}
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_chk_buf_ptr
ssl_client.c:mbedtls_ssl_chk_buf_ptr
Line
Count
Source
621
744k
{
622
744k
    if ((cur > end) || (need > (size_t) (end - cur))) {
623
0
        mbedtls_ssl_set_chk_buf_ptr_fail_args(cur, end, need);
624
0
        return 1;
625
0
    }
626
744k
    return 0;
627
744k
}
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_chk_buf_ptr
ssl_cookie.c:mbedtls_ssl_chk_buf_ptr
Line
Count
Source
621
30
{
622
30
    if ((cur > end) || (need > (size_t) (end - cur))) {
623
0
        mbedtls_ssl_set_chk_buf_ptr_fail_args(cur, end, need);
624
0
        return 1;
625
0
    }
626
30
    return 0;
627
30
}
628
#endif /* MBEDTLS_TEST_HOOKS */
629
630
/**
631
 * \brief        This macro checks if the remaining size in a buffer is
632
 *               greater or equal than a needed space. If it is not the case,
633
 *               it returns an SSL_BUFFER_TOO_SMALL error.
634
 *
635
 * \param cur    Pointer to the current position in the buffer.
636
 * \param end    Pointer to one past the end of the buffer.
637
 * \param need   Needed space in bytes.
638
 *
639
 */
640
#define MBEDTLS_SSL_CHK_BUF_PTR(cur, end, need)                        \
641
807k
    do {                                                                 \
642
807k
        if (mbedtls_ssl_chk_buf_ptr((cur), (end), (need)) != 0) \
643
807k
        {                                                                \
644
0
            return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL;                  \
645
0
        }                                                                \
646
807k
    } while (0)
647
648
/**
649
 * \brief        This macro checks if the remaining length in an input buffer is
650
 *               greater or equal than a needed length. If it is not the case, it
651
 *               returns #MBEDTLS_ERR_SSL_DECODE_ERROR error and pends a
652
 *               #MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR alert message.
653
 *
654
 *               This is a function-like macro. It is guaranteed to evaluate each
655
 *               argument exactly once.
656
 *
657
 * \param cur    Pointer to the current position in the buffer.
658
 * \param end    Pointer to one past the end of the buffer.
659
 * \param need   Needed length in bytes.
660
 *
661
 */
662
#define MBEDTLS_SSL_CHK_BUF_READ_PTR(cur, end, need)                          \
663
126k
    do {                                                                        \
664
126k
        if (mbedtls_ssl_chk_buf_ptr((cur), (end), (need)) != 0)        \
665
126k
        {                                                                       \
666
468
            MBEDTLS_SSL_DEBUG_MSG(1,                                           \
667
468
                                  ("missing input data in %s", __func__));  \
668
468
            MBEDTLS_SSL_PEND_FATAL_ALERT(MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR,   \
669
468
                                         MBEDTLS_ERR_SSL_DECODE_ERROR);       \
670
468
            return MBEDTLS_ERR_SSL_DECODE_ERROR;                             \
671
468
        }                                                                       \
672
126k
    } while (0)
673
674
#ifdef __cplusplus
675
extern "C" {
676
#endif
677
678
typedef int  mbedtls_ssl_tls_prf_cb(const unsigned char *secret, size_t slen,
679
                                    const char *label,
680
                                    const unsigned char *random, size_t rlen,
681
                                    unsigned char *dstbuf, size_t dlen);
682
683
/* cipher.h exports the maximum IV, key and block length from
684
 * all ciphers enabled in the config, regardless of whether those
685
 * ciphers are actually usable in SSL/TLS. Notably, XTS is enabled
686
 * in the default configuration and uses 64 Byte keys, but it is
687
 * not used for record protection in SSL/TLS.
688
 *
689
 * In order to prevent unnecessary inflation of key structures,
690
 * we introduce SSL-specific variants of the max-{key,block,IV}
691
 * macros here which are meant to only take those ciphers into
692
 * account which can be negotiated in SSL/TLS.
693
 *
694
 * Since the current definitions of MBEDTLS_MAX_{KEY|BLOCK|IV}_LENGTH
695
 * in cipher.h are rough overapproximations of the real maxima, here
696
 * we content ourselves with replicating those overapproximations
697
 * for the maximum block and IV length, and excluding XTS from the
698
 * computation of the maximum key length. */
699
#define MBEDTLS_SSL_MAX_BLOCK_LENGTH 16
700
#define MBEDTLS_SSL_MAX_IV_LENGTH    16
701
#define MBEDTLS_SSL_MAX_KEY_LENGTH   32
702
703
/**
704
 * \brief   The data structure holding the cryptographic material (key and IV)
705
 *          used for record protection in TLS 1.3.
706
 */
707
struct mbedtls_ssl_key_set {
708
    /*! The key for client->server records. */
709
    unsigned char client_write_key[MBEDTLS_SSL_MAX_KEY_LENGTH];
710
    /*! The key for server->client records. */
711
    unsigned char server_write_key[MBEDTLS_SSL_MAX_KEY_LENGTH];
712
    /*! The IV  for client->server records. */
713
    unsigned char client_write_iv[MBEDTLS_SSL_MAX_IV_LENGTH];
714
    /*! The IV  for server->client records. */
715
    unsigned char server_write_iv[MBEDTLS_SSL_MAX_IV_LENGTH];
716
717
    size_t key_len; /*!< The length of client_write_key and
718
                     *   server_write_key, in Bytes. */
719
    size_t iv_len;  /*!< The length of client_write_iv and
720
                     *   server_write_iv, in Bytes. */
721
};
722
typedef struct mbedtls_ssl_key_set mbedtls_ssl_key_set;
723
724
typedef struct {
725
    unsigned char binder_key[MBEDTLS_TLS1_3_MD_MAX_SIZE];
726
    unsigned char client_early_traffic_secret[MBEDTLS_TLS1_3_MD_MAX_SIZE];
727
    unsigned char early_exporter_master_secret[MBEDTLS_TLS1_3_MD_MAX_SIZE];
728
} mbedtls_ssl_tls13_early_secrets;
729
730
typedef struct {
731
    unsigned char client_handshake_traffic_secret[MBEDTLS_TLS1_3_MD_MAX_SIZE];
732
    unsigned char server_handshake_traffic_secret[MBEDTLS_TLS1_3_MD_MAX_SIZE];
733
} mbedtls_ssl_tls13_handshake_secrets;
734
735
/*
736
 * This structure contains the parameters only needed during handshake.
737
 */
738
struct mbedtls_ssl_handshake_params {
739
    /* Frequently-used boolean or byte fields (placed early to take
740
     * advantage of smaller code size for indirect access on Arm Thumb) */
741
    uint8_t resume;                     /*!<  session resume indicator*/
742
    uint8_t cli_exts;                   /*!< client extension presence*/
743
744
#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
745
    uint8_t sni_authmode;               /*!< authmode from SNI callback     */
746
#endif
747
748
#if defined(MBEDTLS_SSL_SRV_C)
749
    /* Flag indicating if a CertificateRequest message has been sent
750
     * to the client or not. */
751
    uint8_t certificate_request_sent;
752
#if defined(MBEDTLS_SSL_EARLY_DATA)
753
    /* Flag indicating if the server has accepted early data or not. */
754
    uint8_t early_data_accepted;
755
#endif
756
#endif /* MBEDTLS_SSL_SRV_C */
757
758
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
759
    uint8_t new_session_ticket;         /*!< use NewSessionTicket?    */
760
#endif /* MBEDTLS_SSL_SESSION_TICKETS */
761
762
#if defined(MBEDTLS_SSL_CLI_C)
763
    /** Minimum TLS version to be negotiated.
764
     *
765
     * It is set up in the ClientHello writing preparation stage and used
766
     * throughout the ClientHello writing. Not relevant anymore as soon as
767
     * the protocol version has been negotiated thus as soon as the
768
     * ServerHello is received.
769
     * For a fresh handshake not linked to any previous handshake, it is
770
     * equal to the configured minimum minor version to be negotiated. When
771
     * renegotiating or resuming a session, it is equal to the previously
772
     * negotiated minor version.
773
     *
774
     * There is no maximum TLS version field in this handshake context.
775
     * From the start of the handshake, we need to define a current protocol
776
     * version for the record layer which we define as the maximum TLS
777
     * version to be negotiated. The `tls_version` field of the SSL context is
778
     * used to store this maximum value until it contains the actual
779
     * negotiated value.
780
     */
781
    mbedtls_ssl_protocol_version min_tls_version;
782
#endif
783
784
#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
785
    uint8_t extended_ms;                /*!< use Extended Master Secret? */
786
#endif
787
788
#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
789
    uint8_t async_in_progress; /*!< an asynchronous operation is in progress */
790
#endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
791
792
#if defined(MBEDTLS_SSL_PROTO_DTLS)
793
    unsigned char retransmit_state;     /*!<  Retransmission state           */
794
#endif
795
796
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
797
    unsigned char group_list_heap_allocated;
798
    unsigned char sig_algs_heap_allocated;
799
#endif
800
801
#if defined(MBEDTLS_SSL_ECP_RESTARTABLE_ENABLED)
802
    uint8_t ecrs_enabled;               /*!< Handshake supports EC restart? */
803
    enum { /* this complements ssl->state with info on intra-state operations */
804
        ssl_ecrs_none = 0,              /*!< nothing going on (yet)         */
805
        ssl_ecrs_crt_verify,            /*!< Certificate: crt_verify()      */
806
        ssl_ecrs_ske_start_processing,  /*!< ServerKeyExchange: pk_verify() */
807
        ssl_ecrs_cke_ecdh_calc_secret,  /*!< ClientKeyExchange: ECDH step 2 */
808
        ssl_ecrs_crt_vrfy_sign,         /*!< CertificateVerify: pk_sign()   */
809
    } ecrs_state;                       /*!< current (or last) operation    */
810
    mbedtls_x509_crt *ecrs_peer_cert;   /*!< The peer's CRT chain.          */
811
    size_t ecrs_n;                      /*!< place for saving a length      */
812
#endif
813
814
    mbedtls_ssl_ciphersuite_t const *ciphersuite_info;
815
816
    MBEDTLS_CHECK_RETURN_CRITICAL
817
    int (*update_checksum)(mbedtls_ssl_context *, const unsigned char *, size_t);
818
    MBEDTLS_CHECK_RETURN_CRITICAL
819
    int (*calc_verify)(const mbedtls_ssl_context *, unsigned char *, size_t *);
820
    MBEDTLS_CHECK_RETURN_CRITICAL
821
    int (*calc_finished)(mbedtls_ssl_context *, unsigned char *, int);
822
    mbedtls_ssl_tls_prf_cb *tls_prf;
823
824
    /*
825
     * Handshake specific crypto variables
826
     */
827
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
828
    uint8_t key_exchange_mode; /*!< Selected key exchange mode */
829
830
    /**
831
     * Flag indicating if, in the course of the current handshake, an
832
     * HelloRetryRequest message has been sent by the server or received by
833
     * the client (<> 0) or not (0).
834
     */
835
    uint8_t hello_retry_request_flag;
836
837
#if defined(MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE)
838
    /**
839
     * Flag indicating if, in the course of the current handshake, a dummy
840
     * change_cipher_spec (CCS) record has already been sent. Used to send only
841
     * one CCS per handshake while not complicating the handshake state
842
     * transitions for that purpose.
843
     */
844
    uint8_t ccs_sent;
845
#endif
846
847
#if defined(MBEDTLS_SSL_SRV_C)
848
#if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_PSK_ENABLED)
849
    uint8_t tls13_kex_modes; /*!< Key exchange modes supported by the client */
850
#endif
851
    /** selected_group of key_share extension in HelloRetryRequest message. */
852
    uint16_t hrr_selected_group;
853
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
854
    uint16_t new_session_tickets_count;         /*!< number of session tickets */
855
#endif
856
#endif /* MBEDTLS_SSL_SRV_C */
857
858
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
859
860
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
861
    uint16_t received_sig_algs[MBEDTLS_RECEIVED_SIG_ALGS_SIZE];
862
#endif
863
864
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
865
    const uint16_t *group_list;
866
    const uint16_t *sig_algs;
867
#endif
868
869
#if defined(MBEDTLS_DHM_C)
870
    mbedtls_dhm_context dhm_ctx;                /*!<  DHM key exchange        */
871
#endif
872
873
#if !defined(MBEDTLS_USE_PSA_CRYPTO) && \
874
    defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDH_OR_ECDHE_1_2_ENABLED)
875
    mbedtls_ecdh_context ecdh_ctx;              /*!<  ECDH key exchange       */
876
#endif /* !MBEDTLS_USE_PSA_CRYPTO &&
877
          MBEDTLS_KEY_EXCHANGE_SOME_ECDH_OR_ECDHE_1_2_ENABLED */
878
879
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_XXDH_PSA_ANY_ENABLED)
880
    psa_key_type_t xxdh_psa_type;
881
    size_t xxdh_psa_bits;
882
    mbedtls_svc_key_id_t xxdh_psa_privkey;
883
    uint8_t xxdh_psa_privkey_is_external;
884
    unsigned char xxdh_psa_peerkey[PSA_EXPORT_PUBLIC_KEY_MAX_SIZE];
885
    size_t xxdh_psa_peerkey_len;
886
#endif /* MBEDTLS_KEY_EXCHANGE_SOME_XXDH_PSA_ANY_ENABLED */
887
888
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
889
#if defined(MBEDTLS_USE_PSA_CRYPTO)
890
    psa_pake_operation_t psa_pake_ctx;        /*!< EC J-PAKE key exchange */
891
    mbedtls_svc_key_id_t psa_pake_password;
892
    uint8_t psa_pake_ctx_is_ok;
893
#else
894
    mbedtls_ecjpake_context ecjpake_ctx;        /*!< EC J-PAKE key exchange */
895
#endif /* MBEDTLS_USE_PSA_CRYPTO */
896
#if defined(MBEDTLS_SSL_CLI_C)
897
    unsigned char *ecjpake_cache;               /*!< Cache for ClientHello ext */
898
    size_t ecjpake_cache_len;                   /*!< Length of cached data */
899
#endif
900
#endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
901
902
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDH_OR_ECDHE_ANY_ENABLED) || \
903
    defined(MBEDTLS_KEY_EXCHANGE_ECDSA_CERT_REQ_ANY_ALLOWED_ENABLED) || \
904
    defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
905
    uint16_t *curves_tls_id;      /*!<  List of TLS IDs of supported elliptic curves */
906
#endif
907
908
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
909
#if defined(MBEDTLS_USE_PSA_CRYPTO)
910
    mbedtls_svc_key_id_t psk_opaque;            /*!< Opaque PSK from the callback   */
911
    uint8_t psk_opaque_is_internal;
912
#else
913
    unsigned char *psk;                 /*!<  PSK from the callback         */
914
    size_t psk_len;                     /*!<  Length of PSK from callback   */
915
#endif /* MBEDTLS_USE_PSA_CRYPTO */
916
    uint16_t    selected_identity;
917
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED */
918
919
#if defined(MBEDTLS_SSL_ECP_RESTARTABLE_ENABLED)
920
    mbedtls_x509_crt_restart_ctx ecrs_ctx;  /*!< restart context            */
921
#endif
922
923
#if defined(MBEDTLS_X509_CRT_PARSE_C)
924
    mbedtls_ssl_key_cert *key_cert;     /*!< chosen key/cert pair (server)  */
925
#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
926
    mbedtls_ssl_key_cert *sni_key_cert; /*!< key/cert list from SNI         */
927
    mbedtls_x509_crt *sni_ca_chain;     /*!< trusted CAs from SNI callback  */
928
    mbedtls_x509_crl *sni_ca_crl;       /*!< trusted CAs CRLs from SNI      */
929
#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
930
#endif /* MBEDTLS_X509_CRT_PARSE_C */
931
932
#if defined(MBEDTLS_X509_CRT_PARSE_C) &&        \
933
    !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
934
    mbedtls_pk_context peer_pubkey;     /*!< The public key from the peer.  */
935
#endif /* MBEDTLS_X509_CRT_PARSE_C && !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
936
937
    struct {
938
        size_t total_bytes_buffered; /*!< Cumulative size of heap allocated
939
                                      *   buffers used for message buffering. */
940
941
        uint8_t seen_ccs;               /*!< Indicates if a CCS message has
942
                                         *   been seen in the current flight. */
943
944
        struct mbedtls_ssl_hs_buffer {
945
            unsigned is_valid      : 1;
946
            unsigned is_fragmented : 1;
947
            unsigned is_complete   : 1;
948
            unsigned char *data;
949
            size_t data_len;
950
        } hs[MBEDTLS_SSL_MAX_BUFFERED_HS];
951
952
        struct {
953
            unsigned char *data;
954
            size_t len;
955
            unsigned epoch;
956
        } future_record;
957
958
    } buffering;
959
960
#if defined(MBEDTLS_SSL_CLI_C) && \
961
    (defined(MBEDTLS_SSL_PROTO_DTLS) || \
962
    defined(MBEDTLS_SSL_PROTO_TLS1_3))
963
    unsigned char *cookie;              /*!< HelloVerifyRequest cookie for DTLS
964
                                         *   HelloRetryRequest cookie for TLS 1.3 */
965
#if !defined(MBEDTLS_SSL_PROTO_TLS1_3)
966
    /* RFC 6347 page 15
967
       ...
968
       opaque cookie<0..2^8-1>;
969
       ...
970
     */
971
    uint8_t cookie_len;
972
#else
973
    /* RFC 8446 page 39
974
       ...
975
       opaque cookie<0..2^16-1>;
976
       ...
977
       If TLS1_3 is enabled, the max length is 2^16 - 1
978
     */
979
    uint16_t cookie_len;                /*!< DTLS: HelloVerifyRequest cookie length
980
                                         *   TLS1_3: HelloRetryRequest cookie length */
981
#endif
982
#endif /* MBEDTLS_SSL_CLI_C &&
983
          ( MBEDTLS_SSL_PROTO_DTLS ||
984
            MBEDTLS_SSL_PROTO_TLS1_3 ) */
985
#if defined(MBEDTLS_SSL_SRV_C) && defined(MBEDTLS_SSL_PROTO_DTLS)
986
    unsigned char cookie_verify_result; /*!< Srv: flag for sending a cookie */
987
#endif /* MBEDTLS_SSL_SRV_C && MBEDTLS_SSL_PROTO_DTLS */
988
989
#if defined(MBEDTLS_SSL_PROTO_DTLS)
990
    unsigned int out_msg_seq;           /*!<  Outgoing handshake sequence number */
991
    unsigned int in_msg_seq;            /*!<  Incoming handshake sequence number */
992
993
    uint32_t retransmit_timeout;        /*!<  Current value of timeout       */
994
    mbedtls_ssl_flight_item *flight;    /*!<  Current outgoing flight        */
995
    mbedtls_ssl_flight_item *cur_msg;   /*!<  Current message in flight      */
996
    unsigned char *cur_msg_p;           /*!<  Position in current message    */
997
    unsigned int in_flight_start_seq;   /*!<  Minimum message sequence in the
998
                                              flight being received          */
999
    mbedtls_ssl_transform *alt_transform_out;   /*!<  Alternative transform for
1000
                                                   resending messages             */
1001
    unsigned char alt_out_ctr[MBEDTLS_SSL_SEQUENCE_NUMBER_LEN]; /*!<  Alternative record epoch/counter
1002
                                                                      for resending messages         */
1003
1004
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1005
    /* The state of CID configuration in this handshake. */
1006
1007
    uint8_t cid_in_use; /*!< This indicates whether the use of the CID extension
1008
                         *   has been negotiated. Possible values are
1009
                         *   #MBEDTLS_SSL_CID_ENABLED and
1010
                         *   #MBEDTLS_SSL_CID_DISABLED. */
1011
    unsigned char peer_cid[MBEDTLS_SSL_CID_OUT_LEN_MAX];   /*! The peer's CID */
1012
    uint8_t peer_cid_len;                                  /*!< The length of
1013
                                                            *   \c peer_cid.  */
1014
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1015
1016
    uint16_t mtu;                       /*!<  Handshake mtu, used to fragment outgoing messages */
1017
#endif /* MBEDTLS_SSL_PROTO_DTLS */
1018
1019
    /*
1020
     * Checksum contexts
1021
     */
1022
#if defined(MBEDTLS_MD_CAN_SHA256)
1023
#if defined(MBEDTLS_USE_PSA_CRYPTO)
1024
    psa_hash_operation_t fin_sha256_psa;
1025
#else
1026
    mbedtls_md_context_t fin_sha256;
1027
#endif
1028
#endif
1029
#if defined(MBEDTLS_MD_CAN_SHA384)
1030
#if defined(MBEDTLS_USE_PSA_CRYPTO)
1031
    psa_hash_operation_t fin_sha384_psa;
1032
#else
1033
    mbedtls_md_context_t fin_sha384;
1034
#endif
1035
#endif
1036
1037
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
1038
    uint16_t offered_group_id; /* The NamedGroup value for the group
1039
                                * that is being used for ephemeral
1040
                                * key exchange.
1041
                                *
1042
                                * On the client: Defaults to the first
1043
                                * entry in the client's group list,
1044
                                * but can be overwritten by the HRR. */
1045
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
1046
1047
#if defined(MBEDTLS_SSL_CLI_C)
1048
    uint8_t client_auth;       /*!< used to check if CertificateRequest has been
1049
                                    received from server side. If CertificateRequest
1050
                                    has been received, Certificate and CertificateVerify
1051
                                    should be sent to server */
1052
#endif /* MBEDTLS_SSL_CLI_C */
1053
    /*
1054
     * State-local variables used during the processing
1055
     * of a specific handshake state.
1056
     */
1057
    union {
1058
        /* Outgoing Finished message */
1059
        struct {
1060
            uint8_t preparation_done;
1061
1062
            /* Buffer holding digest of the handshake up to
1063
             * but excluding the outgoing finished message. */
1064
            unsigned char digest[MBEDTLS_TLS1_3_MD_MAX_SIZE];
1065
            size_t digest_len;
1066
        } finished_out;
1067
1068
        /* Incoming Finished message */
1069
        struct {
1070
            uint8_t preparation_done;
1071
1072
            /* Buffer holding digest of the handshake up to but
1073
             * excluding the peer's incoming finished message. */
1074
            unsigned char digest[MBEDTLS_TLS1_3_MD_MAX_SIZE];
1075
            size_t digest_len;
1076
        } finished_in;
1077
1078
    } state_local;
1079
1080
    /* End of state-local variables. */
1081
1082
    unsigned char randbytes[MBEDTLS_CLIENT_HELLO_RANDOM_LEN +
1083
                            MBEDTLS_SERVER_HELLO_RANDOM_LEN];
1084
    /*!<  random bytes            */
1085
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
1086
    unsigned char premaster[MBEDTLS_PREMASTER_SIZE];
1087
    /*!<  premaster secret        */
1088
    size_t pmslen;                      /*!<  premaster length        */
1089
#endif
1090
1091
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
1092
    uint32_t sent_extensions;       /*!< extensions sent by endpoint */
1093
    uint32_t received_extensions;   /*!< extensions received by endpoint */
1094
1095
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
1096
    unsigned char certificate_request_context_len;
1097
    unsigned char *certificate_request_context;
1098
#endif
1099
1100
    /** TLS 1.3 transform for encrypted handshake messages. */
1101
    mbedtls_ssl_transform *transform_handshake;
1102
    union {
1103
        unsigned char early[MBEDTLS_TLS1_3_MD_MAX_SIZE];
1104
        unsigned char handshake[MBEDTLS_TLS1_3_MD_MAX_SIZE];
1105
        unsigned char app[MBEDTLS_TLS1_3_MD_MAX_SIZE];
1106
    } tls13_master_secrets;
1107
1108
    mbedtls_ssl_tls13_handshake_secrets tls13_hs_secrets;
1109
#if defined(MBEDTLS_SSL_EARLY_DATA)
1110
    /** TLS 1.3 transform for early data and handshake messages. */
1111
    mbedtls_ssl_transform *transform_earlydata;
1112
#endif
1113
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
1114
1115
#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
1116
    /** Asynchronous operation context. This field is meant for use by the
1117
     * asynchronous operation callbacks (mbedtls_ssl_config::f_async_sign_start,
1118
     * mbedtls_ssl_config::f_async_decrypt_start,
1119
     * mbedtls_ssl_config::f_async_resume, mbedtls_ssl_config::f_async_cancel).
1120
     * The library does not use it internally. */
1121
    void *user_async_ctx;
1122
#endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
1123
1124
#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
1125
    const unsigned char *sni_name;      /*!< raw SNI                        */
1126
    size_t sni_name_len;                /*!< raw SNI len                    */
1127
#if defined(MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED)
1128
    const mbedtls_x509_crt *dn_hints;   /*!< acceptable client cert issuers */
1129
#endif
1130
#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
1131
};
1132
1133
typedef struct mbedtls_ssl_hs_buffer mbedtls_ssl_hs_buffer;
1134
1135
/*
1136
 * Representation of decryption/encryption transformations on records
1137
 *
1138
 * There are the following general types of record transformations:
1139
 * - Stream transformations (TLS versions == 1.2 only)
1140
 *   Transformation adding a MAC and applying a stream-cipher
1141
 *   to the authenticated message.
1142
 * - CBC block cipher transformations ([D]TLS versions == 1.2 only)
1143
 *   For TLS 1.2, no IV is generated at key extraction time, but every
1144
 *   encrypted record is explicitly prefixed by the IV with which it was
1145
 *   encrypted.
1146
 * - AEAD transformations ([D]TLS versions == 1.2 only)
1147
 *   These come in two fundamentally different versions, the first one
1148
 *   used in TLS 1.2, excluding ChaChaPoly ciphersuites, and the second
1149
 *   one used for ChaChaPoly ciphersuites in TLS 1.2 as well as for TLS 1.3.
1150
 *   In the first transformation, the IV to be used for a record is obtained
1151
 *   as the concatenation of an explicit, static 4-byte IV and the 8-byte
1152
 *   record sequence number, and explicitly prepending this sequence number
1153
 *   to the encrypted record. In contrast, in the second transformation
1154
 *   the IV is obtained by XOR'ing a static IV obtained at key extraction
1155
 *   time with the 8-byte record sequence number, without prepending the
1156
 *   latter to the encrypted record.
1157
 *
1158
 * Additionally, DTLS 1.2 + CID as well as TLS 1.3 use an inner plaintext
1159
 * which allows to add flexible length padding and to hide a record's true
1160
 * content type.
1161
 *
1162
 * In addition to type and version, the following parameters are relevant:
1163
 * - The symmetric cipher algorithm to be used.
1164
 * - The (static) encryption/decryption keys for the cipher.
1165
 * - For stream/CBC, the type of message digest to be used.
1166
 * - For stream/CBC, (static) encryption/decryption keys for the digest.
1167
 * - For AEAD transformations, the size (potentially 0) of an explicit,
1168
 *   random initialization vector placed in encrypted records.
1169
 * - For some transformations (currently AEAD) an implicit IV. It is static
1170
 *   and (if present) is combined with the explicit IV in a transformation-
1171
 *   -dependent way (e.g. appending in TLS 1.2 and XOR'ing in TLS 1.3).
1172
 * - For stream/CBC, a flag determining the order of encryption and MAC.
1173
 * - The details of the transformation depend on the SSL/TLS version.
1174
 * - The length of the authentication tag.
1175
 *
1176
 * The struct below refines this abstract view as follows:
1177
 * - The cipher underlying the transformation is managed in
1178
 *   cipher contexts cipher_ctx_{enc/dec}, which must have the
1179
 *   same cipher type. The mode of these cipher contexts determines
1180
 *   the type of the transformation in the sense above: e.g., if
1181
 *   the type is MBEDTLS_CIPHER_AES_256_CBC resp. MBEDTLS_CIPHER_AES_192_GCM
1182
 *   then the transformation has type CBC resp. AEAD.
1183
 * - The cipher keys are never stored explicitly but
1184
 *   are maintained within cipher_ctx_{enc/dec}.
1185
 * - For stream/CBC transformations, the message digest contexts
1186
 *   used for the MAC's are stored in md_ctx_{enc/dec}. These contexts
1187
 *   are unused for AEAD transformations.
1188
 * - For stream/CBC transformations, the MAC keys are not stored explicitly
1189
 *   but maintained within md_ctx_{enc/dec}.
1190
 * - The mac_enc and mac_dec fields are unused for EAD transformations.
1191
 * - For transformations using an implicit IV maintained within
1192
 *   the transformation context, its contents are stored within
1193
 *   iv_{enc/dec}.
1194
 * - The value of ivlen indicates the length of the IV.
1195
 *   This is redundant in case of stream/CBC transformations
1196
 *   which always use 0 resp. the cipher's block length as the
1197
 *   IV length, but is needed for AEAD ciphers and may be
1198
 *   different from the underlying cipher's block length
1199
 *   in this case.
1200
 * - The field fixed_ivlen is nonzero for AEAD transformations only
1201
 *   and indicates the length of the static part of the IV which is
1202
 *   constant throughout the communication, and which is stored in
1203
 *   the first fixed_ivlen bytes of the iv_{enc/dec} arrays.
1204
 * - tls_version denotes the 2-byte TLS version
1205
 * - For stream/CBC transformations, maclen denotes the length of the
1206
 *   authentication tag, while taglen is unused and 0.
1207
 * - For AEAD transformations, taglen denotes the length of the
1208
 *   authentication tag, while maclen is unused and 0.
1209
 * - For CBC transformations, encrypt_then_mac determines the
1210
 *   order of encryption and authentication. This field is unused
1211
 *   in other transformations.
1212
 *
1213
 */
1214
struct mbedtls_ssl_transform {
1215
    /*
1216
     * Session specific crypto layer
1217
     */
1218
    size_t minlen;                      /*!<  min. ciphertext length  */
1219
    size_t ivlen;                       /*!<  IV length               */
1220
    size_t fixed_ivlen;                 /*!<  Fixed part of IV (AEAD) */
1221
    size_t maclen;                      /*!<  MAC(CBC) len            */
1222
    size_t taglen;                      /*!<  TAG(AEAD) len           */
1223
1224
    unsigned char iv_enc[16];           /*!<  IV (encryption)         */
1225
    unsigned char iv_dec[16];           /*!<  IV (decryption)         */
1226
1227
#if defined(MBEDTLS_SSL_SOME_SUITES_USE_MAC)
1228
1229
#if defined(MBEDTLS_USE_PSA_CRYPTO)
1230
    mbedtls_svc_key_id_t psa_mac_enc;           /*!<  MAC (encryption)        */
1231
    mbedtls_svc_key_id_t psa_mac_dec;           /*!<  MAC (decryption)        */
1232
    psa_algorithm_t psa_mac_alg;                /*!<  psa MAC algorithm       */
1233
#else
1234
    mbedtls_md_context_t md_ctx_enc;            /*!<  MAC (encryption)        */
1235
    mbedtls_md_context_t md_ctx_dec;            /*!<  MAC (decryption)        */
1236
#endif /* MBEDTLS_USE_PSA_CRYPTO */
1237
1238
#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1239
    int encrypt_then_mac;       /*!< flag for EtM activation                */
1240
#endif
1241
1242
#endif /* MBEDTLS_SSL_SOME_SUITES_USE_MAC */
1243
1244
    mbedtls_ssl_protocol_version tls_version;
1245
1246
#if defined(MBEDTLS_USE_PSA_CRYPTO)
1247
    mbedtls_svc_key_id_t psa_key_enc;           /*!<  psa encryption key      */
1248
    mbedtls_svc_key_id_t psa_key_dec;           /*!<  psa decryption key      */
1249
    psa_algorithm_t psa_alg;                    /*!<  psa algorithm           */
1250
#else
1251
    mbedtls_cipher_context_t cipher_ctx_enc;    /*!<  encryption context      */
1252
    mbedtls_cipher_context_t cipher_ctx_dec;    /*!<  decryption context      */
1253
#endif /* MBEDTLS_USE_PSA_CRYPTO */
1254
1255
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1256
    uint8_t in_cid_len;
1257
    uint8_t out_cid_len;
1258
    unsigned char in_cid[MBEDTLS_SSL_CID_IN_LEN_MAX];
1259
    unsigned char out_cid[MBEDTLS_SSL_CID_OUT_LEN_MAX];
1260
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1261
1262
#if defined(MBEDTLS_SSL_KEEP_RANDBYTES)
1263
    /* We need the Hello random bytes in order to re-derive keys from the
1264
     * Master Secret and other session info and for the keying material
1265
     * exporter in TLS 1.2.
1266
     * See ssl_tls12_populate_transform() */
1267
    unsigned char randbytes[MBEDTLS_SERVER_HELLO_RANDOM_LEN +
1268
                            MBEDTLS_CLIENT_HELLO_RANDOM_LEN];
1269
    /*!< ServerHello.random+ClientHello.random */
1270
#endif /* defined(MBEDTLS_SSL_KEEP_RANDBYTES) */
1271
};
1272
1273
/*
1274
 * Return 1 if the transform uses an AEAD cipher, 0 otherwise.
1275
 * Equivalently, return 0 if a separate MAC is used, 1 otherwise.
1276
 */
1277
static inline int mbedtls_ssl_transform_uses_aead(
1278
    const mbedtls_ssl_transform *transform)
1279
0
{
1280
0
#if defined(MBEDTLS_SSL_SOME_SUITES_USE_MAC)
1281
0
    return transform->maclen == 0 && transform->taglen != 0;
1282
#else
1283
    (void) transform;
1284
    return 1;
1285
#endif
1286
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_transform_uses_aead
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_transform_uses_aead
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_transform_uses_aead
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_transform_uses_aead
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_transform_uses_aead
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_transform_uses_aead
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_transform_uses_aead
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_transform_uses_aead
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_transform_uses_aead
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_transform_uses_aead
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_transform_uses_aead
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_transform_uses_aead
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_transform_uses_aead
1287
1288
/*
1289
 * Internal representation of record frames
1290
 *
1291
 * Instances come in two flavors:
1292
 * (1) Encrypted
1293
 *     These always have data_offset = 0
1294
 * (2) Unencrypted
1295
 *     These have data_offset set to the amount of
1296
 *     pre-expansion during record protection. Concretely,
1297
 *     this is the length of the fixed part of the explicit IV
1298
 *     used for encryption, or 0 if no explicit IV is used
1299
 *     (e.g. for stream ciphers).
1300
 *
1301
 * The reason for the data_offset in the unencrypted case
1302
 * is to allow for in-place conversion of an unencrypted to
1303
 * an encrypted record. If the offset wasn't included, the
1304
 * encrypted content would need to be shifted afterwards to
1305
 * make space for the fixed IV.
1306
 *
1307
 */
1308
#if MBEDTLS_SSL_CID_OUT_LEN_MAX > MBEDTLS_SSL_CID_IN_LEN_MAX
1309
#define MBEDTLS_SSL_CID_LEN_MAX MBEDTLS_SSL_CID_OUT_LEN_MAX
1310
#else
1311
#define MBEDTLS_SSL_CID_LEN_MAX MBEDTLS_SSL_CID_IN_LEN_MAX
1312
#endif
1313
1314
typedef struct {
1315
    uint8_t ctr[MBEDTLS_SSL_SEQUENCE_NUMBER_LEN];  /* In TLS:  The implicit record sequence number.
1316
                                                    * In DTLS: The 2-byte epoch followed by
1317
                                                    *          the 6-byte sequence number.
1318
                                                    * This is stored as a raw big endian byte array
1319
                                                    * as opposed to a uint64_t because we rarely
1320
                                                    * need to perform arithmetic on this, but do
1321
                                                    * need it as a Byte array for the purpose of
1322
                                                    * MAC computations.                             */
1323
    uint8_t type;           /* The record content type.                      */
1324
    uint8_t ver[2];         /* SSL/TLS version as present on the wire.
1325
                             * Convert to internal presentation of versions
1326
                             * using mbedtls_ssl_read_version() and
1327
                             * mbedtls_ssl_write_version().
1328
                             * Keep wire-format for MAC computations.        */
1329
1330
    unsigned char *buf;     /* Memory buffer enclosing the record content    */
1331
    size_t buf_len;         /* Buffer length                                 */
1332
    size_t data_offset;     /* Offset of record content                      */
1333
    size_t data_len;        /* Length of record content                      */
1334
1335
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1336
    uint8_t cid_len;        /* Length of the CID (0 if not present)          */
1337
    unsigned char cid[MBEDTLS_SSL_CID_LEN_MAX];   /* The CID                 */
1338
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1339
} mbedtls_record;
1340
1341
#if defined(MBEDTLS_X509_CRT_PARSE_C)
1342
/*
1343
 * List of certificate + private key pairs
1344
 */
1345
struct mbedtls_ssl_key_cert {
1346
    mbedtls_x509_crt *cert;                 /*!< cert                       */
1347
    mbedtls_pk_context *key;                /*!< private key                */
1348
    mbedtls_ssl_key_cert *next;             /*!< next key/cert pair         */
1349
};
1350
#endif /* MBEDTLS_X509_CRT_PARSE_C */
1351
1352
#if defined(MBEDTLS_SSL_PROTO_DTLS)
1353
/*
1354
 * List of handshake messages kept around for resending
1355
 */
1356
struct mbedtls_ssl_flight_item {
1357
    unsigned char *p;       /*!< message, including handshake headers   */
1358
    size_t len;             /*!< length of p                            */
1359
    unsigned char type;     /*!< type of the message: handshake or CCS  */
1360
    mbedtls_ssl_flight_item *next;  /*!< next handshake message(s)              */
1361
};
1362
#endif /* MBEDTLS_SSL_PROTO_DTLS */
1363
1364
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
1365
/**
1366
 * \brief Given an SSL context and its associated configuration, write the TLS
1367
 *        1.2 specific extensions of the ClientHello message.
1368
 *
1369
 * \param[in]   ssl     SSL context
1370
 * \param[in]   buf     Base address of the buffer where to write the extensions
1371
 * \param[in]   end     End address of the buffer where to write the extensions
1372
 * \param       uses_ec Whether one proposed ciphersuite uses an elliptic curve
1373
 *                      (<> 0) or not ( 0 ).
1374
 * \param[out]  out_len Length of the data written into the buffer \p buf
1375
 */
1376
MBEDTLS_CHECK_RETURN_CRITICAL
1377
int mbedtls_ssl_tls12_write_client_hello_exts(mbedtls_ssl_context *ssl,
1378
                                              unsigned char *buf,
1379
                                              const unsigned char *end,
1380
                                              int uses_ec,
1381
                                              size_t *out_len);
1382
#endif
1383
1384
#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
1385
    defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
1386
1387
/**
1388
 * \brief Find the preferred hash for a given signature algorithm.
1389
 *
1390
 * \param[in]   ssl     SSL context
1391
 * \param[in]   sig_alg A signature algorithm identifier as defined in the
1392
 *                      TLS 1.2 SignatureAlgorithm enumeration.
1393
 *
1394
 * \return  The preferred hash algorithm for \p sig_alg. It is a hash algorithm
1395
 *          identifier as defined in the TLS 1.2 HashAlgorithm enumeration.
1396
 */
1397
unsigned int mbedtls_ssl_tls12_get_preferred_hash_for_sig_alg(
1398
    mbedtls_ssl_context *ssl,
1399
    unsigned int sig_alg);
1400
1401
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 &&
1402
          MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */
1403
1404
/**
1405
 * \brief           Free referenced items in an SSL transform context and clear
1406
 *                  memory
1407
 *
1408
 * \param transform SSL transform context
1409
 */
1410
void mbedtls_ssl_transform_free(mbedtls_ssl_transform *transform);
1411
1412
/**
1413
 * \brief           Free referenced items in an SSL handshake context and clear
1414
 *                  memory
1415
 *
1416
 * \param ssl       SSL context
1417
 */
1418
void mbedtls_ssl_handshake_free(mbedtls_ssl_context *ssl);
1419
1420
/* set inbound transform of ssl context */
1421
void mbedtls_ssl_set_inbound_transform(mbedtls_ssl_context *ssl,
1422
                                       mbedtls_ssl_transform *transform);
1423
1424
/* set outbound transform of ssl context */
1425
void mbedtls_ssl_set_outbound_transform(mbedtls_ssl_context *ssl,
1426
                                        mbedtls_ssl_transform *transform);
1427
1428
MBEDTLS_CHECK_RETURN_CRITICAL
1429
int mbedtls_ssl_handshake_client_step(mbedtls_ssl_context *ssl);
1430
MBEDTLS_CHECK_RETURN_CRITICAL
1431
int mbedtls_ssl_handshake_server_step(mbedtls_ssl_context *ssl);
1432
void mbedtls_ssl_handshake_wrapup(mbedtls_ssl_context *ssl);
1433
1434
#if defined(MBEDTLS_DEBUG_C)
1435
/* Declared in "ssl_debug_helpers.h". We can't include this file from
1436
 * "ssl_misc.h" because it includes "ssl_misc.h" because it needs some
1437
 * type definitions. TODO: split the type definitions and the helper
1438
 * functions into different headers.
1439
 */
1440
const char *mbedtls_ssl_states_str(mbedtls_ssl_states state);
1441
#endif
1442
1443
static inline void mbedtls_ssl_handshake_set_state(mbedtls_ssl_context *ssl,
1444
                                                   mbedtls_ssl_states state)
1445
33.8k
{
1446
33.8k
    MBEDTLS_SSL_DEBUG_MSG(3, ("handshake state: %d (%s) -> %d (%s)",
1447
33.8k
                              ssl->state, mbedtls_ssl_states_str((mbedtls_ssl_states) ssl->state),
1448
33.8k
                              (int) state, mbedtls_ssl_states_str(state)));
1449
33.8k
    ssl->state = (int) state;
1450
33.8k
}
ssl_msg.c:mbedtls_ssl_handshake_set_state
Line
Count
Source
1445
1.38k
{
1446
1.38k
    MBEDTLS_SSL_DEBUG_MSG(3, ("handshake state: %d (%s) -> %d (%s)",
1447
1.38k
                              ssl->state, mbedtls_ssl_states_str((mbedtls_ssl_states) ssl->state),
1448
1.38k
                              (int) state, mbedtls_ssl_states_str(state)));
1449
1.38k
    ssl->state = (int) state;
1450
1.38k
}
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_handshake_set_state
ssl_tls.c:mbedtls_ssl_handshake_set_state
Line
Count
Source
1445
11.6k
{
1446
11.6k
    MBEDTLS_SSL_DEBUG_MSG(3, ("handshake state: %d (%s) -> %d (%s)",
1447
11.6k
                              ssl->state, mbedtls_ssl_states_str((mbedtls_ssl_states) ssl->state),
1448
11.6k
                              (int) state, mbedtls_ssl_states_str(state)));
1449
11.6k
    ssl->state = (int) state;
1450
11.6k
}
ssl_tls12_client.c:mbedtls_ssl_handshake_set_state
Line
Count
Source
1445
10.0k
{
1446
10.0k
    MBEDTLS_SSL_DEBUG_MSG(3, ("handshake state: %d (%s) -> %d (%s)",
1447
10.0k
                              ssl->state, mbedtls_ssl_states_str((mbedtls_ssl_states) ssl->state),
1448
10.0k
                              (int) state, mbedtls_ssl_states_str(state)));
1449
10.0k
    ssl->state = (int) state;
1450
10.0k
}
ssl_tls12_server.c:mbedtls_ssl_handshake_set_state
Line
Count
Source
1445
3.22k
{
1446
3.22k
    MBEDTLS_SSL_DEBUG_MSG(3, ("handshake state: %d (%s) -> %d (%s)",
1447
3.22k
                              ssl->state, mbedtls_ssl_states_str((mbedtls_ssl_states) ssl->state),
1448
3.22k
                              (int) state, mbedtls_ssl_states_str(state)));
1449
3.22k
    ssl->state = (int) state;
1450
3.22k
}
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_handshake_set_state
ssl_tls13_server.c:mbedtls_ssl_handshake_set_state
Line
Count
Source
1445
1.77k
{
1446
1.77k
    MBEDTLS_SSL_DEBUG_MSG(3, ("handshake state: %d (%s) -> %d (%s)",
1447
1.77k
                              ssl->state, mbedtls_ssl_states_str((mbedtls_ssl_states) ssl->state),
1448
1.77k
                              (int) state, mbedtls_ssl_states_str(state)));
1449
1.77k
    ssl->state = (int) state;
1450
1.77k
}
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_handshake_set_state
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_handshake_set_state
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_handshake_set_state
ssl_client.c:mbedtls_ssl_handshake_set_state
Line
Count
Source
1445
5.78k
{
1446
5.78k
    MBEDTLS_SSL_DEBUG_MSG(3, ("handshake state: %d (%s) -> %d (%s)",
1447
5.78k
                              ssl->state, mbedtls_ssl_states_str((mbedtls_ssl_states) ssl->state),
1448
5.78k
                              (int) state, mbedtls_ssl_states_str(state)));
1449
5.78k
    ssl->state = (int) state;
1450
5.78k
}
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_handshake_set_state
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_handshake_set_state
1451
1452
static inline void mbedtls_ssl_handshake_increment_state(mbedtls_ssl_context *ssl)
1453
16.6k
{
1454
16.6k
    mbedtls_ssl_handshake_set_state(ssl, (mbedtls_ssl_states) (ssl->state + 1));
1455
16.6k
}
ssl_msg.c:mbedtls_ssl_handshake_increment_state
Line
Count
Source
1453
1.38k
{
1454
1.38k
    mbedtls_ssl_handshake_set_state(ssl, (mbedtls_ssl_states) (ssl->state + 1));
1455
1.38k
}
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_handshake_increment_state
ssl_tls.c:mbedtls_ssl_handshake_increment_state
Line
Count
Source
1453
4.53k
{
1454
4.53k
    mbedtls_ssl_handshake_set_state(ssl, (mbedtls_ssl_states) (ssl->state + 1));
1455
4.53k
}
ssl_tls12_client.c:mbedtls_ssl_handshake_increment_state
Line
Count
Source
1453
9.36k
{
1454
9.36k
    mbedtls_ssl_handshake_set_state(ssl, (mbedtls_ssl_states) (ssl->state + 1));
1455
9.36k
}
ssl_tls12_server.c:mbedtls_ssl_handshake_increment_state
Line
Count
Source
1453
1.36k
{
1454
1.36k
    mbedtls_ssl_handshake_set_state(ssl, (mbedtls_ssl_states) (ssl->state + 1));
1455
1.36k
}
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_handshake_increment_state
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_handshake_increment_state
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_handshake_increment_state
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_handshake_increment_state
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_handshake_increment_state
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_handshake_increment_state
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_handshake_increment_state
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_handshake_increment_state
1456
1457
MBEDTLS_CHECK_RETURN_CRITICAL
1458
int mbedtls_ssl_send_fatal_handshake_failure(mbedtls_ssl_context *ssl);
1459
1460
MBEDTLS_CHECK_RETURN_CRITICAL
1461
int mbedtls_ssl_reset_checksum(mbedtls_ssl_context *ssl);
1462
1463
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
1464
MBEDTLS_CHECK_RETURN_CRITICAL
1465
int mbedtls_ssl_derive_keys(mbedtls_ssl_context *ssl);
1466
#endif /* MBEDTLS_SSL_PROTO_TLS1_2  */
1467
1468
MBEDTLS_CHECK_RETURN_CRITICAL
1469
int mbedtls_ssl_handle_message_type(mbedtls_ssl_context *ssl);
1470
MBEDTLS_CHECK_RETURN_CRITICAL
1471
int mbedtls_ssl_prepare_handshake_record(mbedtls_ssl_context *ssl);
1472
MBEDTLS_CHECK_RETURN_CRITICAL
1473
int mbedtls_ssl_update_handshake_status(mbedtls_ssl_context *ssl);
1474
1475
/**
1476
 * \brief       Update record layer
1477
 *
1478
 *              This function roughly separates the implementation
1479
 *              of the logic of (D)TLS from the implementation
1480
 *              of the secure transport.
1481
 *
1482
 * \param  ssl              The SSL context to use.
1483
 * \param  update_hs_digest This indicates if the handshake digest
1484
 *                          should be automatically updated in case
1485
 *                          a handshake message is found.
1486
 *
1487
 * \return      0 or non-zero error code.
1488
 *
1489
 * \note        A clarification on what is called 'record layer' here
1490
 *              is in order, as many sensible definitions are possible:
1491
 *
1492
 *              The record layer takes as input an untrusted underlying
1493
 *              transport (stream or datagram) and transforms it into
1494
 *              a serially multiplexed, secure transport, which
1495
 *              conceptually provides the following:
1496
 *
1497
 *              (1) Three datagram based, content-agnostic transports
1498
 *                  for handshake, alert and CCS messages.
1499
 *              (2) One stream- or datagram-based transport
1500
 *                  for application data.
1501
 *              (3) Functionality for changing the underlying transform
1502
 *                  securing the contents.
1503
 *
1504
 *              The interface to this functionality is given as follows:
1505
 *
1506
 *              a Updating
1507
 *                [Currently implemented by mbedtls_ssl_read_record]
1508
 *
1509
 *                Check if and on which of the four 'ports' data is pending:
1510
 *                Nothing, a controlling datagram of type (1), or application
1511
 *                data (2). In any case data is present, internal buffers
1512
 *                provide access to the data for the user to process it.
1513
 *                Consumption of type (1) datagrams is done automatically
1514
 *                on the next update, invalidating that the internal buffers
1515
 *                for previous datagrams, while consumption of application
1516
 *                data (2) is user-controlled.
1517
 *
1518
 *              b Reading of application data
1519
 *                [Currently manual adaption of ssl->in_offt pointer]
1520
 *
1521
 *                As mentioned in the last paragraph, consumption of data
1522
 *                is different from the automatic consumption of control
1523
 *                datagrams (1) because application data is treated as a stream.
1524
 *
1525
 *              c Tracking availability of application data
1526
 *                [Currently manually through decreasing ssl->in_msglen]
1527
 *
1528
 *                For efficiency and to retain datagram semantics for
1529
 *                application data in case of DTLS, the record layer
1530
 *                provides functionality for checking how much application
1531
 *                data is still available in the internal buffer.
1532
 *
1533
 *              d Changing the transformation securing the communication.
1534
 *
1535
 *              Given an opaque implementation of the record layer in the
1536
 *              above sense, it should be possible to implement the logic
1537
 *              of (D)TLS on top of it without the need to know anything
1538
 *              about the record layer's internals. This is done e.g.
1539
 *              in all the handshake handling functions, and in the
1540
 *              application data reading function mbedtls_ssl_read.
1541
 *
1542
 * \note        The above tries to give a conceptual picture of the
1543
 *              record layer, but the current implementation deviates
1544
 *              from it in some places. For example, our implementation of
1545
 *              the update functionality through mbedtls_ssl_read_record
1546
 *              discards datagrams depending on the current state, which
1547
 *              wouldn't fall under the record layer's responsibility
1548
 *              following the above definition.
1549
 *
1550
 */
1551
MBEDTLS_CHECK_RETURN_CRITICAL
1552
int mbedtls_ssl_read_record(mbedtls_ssl_context *ssl,
1553
                            unsigned update_hs_digest);
1554
MBEDTLS_CHECK_RETURN_CRITICAL
1555
int mbedtls_ssl_fetch_input(mbedtls_ssl_context *ssl, size_t nb_want);
1556
1557
/*
1558
 * Write handshake message header
1559
 */
1560
MBEDTLS_CHECK_RETURN_CRITICAL
1561
int mbedtls_ssl_start_handshake_msg(mbedtls_ssl_context *ssl, unsigned char hs_type,
1562
                                    unsigned char **buf, size_t *buf_len);
1563
1564
MBEDTLS_CHECK_RETURN_CRITICAL
1565
int mbedtls_ssl_write_handshake_msg_ext(mbedtls_ssl_context *ssl,
1566
                                        int update_checksum,
1567
                                        int force_flush);
1568
static inline int mbedtls_ssl_write_handshake_msg(mbedtls_ssl_context *ssl)
1569
9.46k
{
1570
9.46k
    return mbedtls_ssl_write_handshake_msg_ext(ssl, 1 /* update checksum */, 1 /* force flush */);
1571
9.46k
}
ssl_msg.c:mbedtls_ssl_write_handshake_msg
Line
Count
Source
1569
979
{
1570
979
    return mbedtls_ssl_write_handshake_msg_ext(ssl, 1 /* update checksum */, 1 /* force flush */);
1571
979
}
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_write_handshake_msg
ssl_tls.c:mbedtls_ssl_write_handshake_msg
Line
Count
Source
1569
981
{
1570
981
    return mbedtls_ssl_write_handshake_msg_ext(ssl, 1 /* update checksum */, 1 /* force flush */);
1571
981
}
ssl_tls12_client.c:mbedtls_ssl_write_handshake_msg
Line
Count
Source
1569
979
{
1570
979
    return mbedtls_ssl_write_handshake_msg_ext(ssl, 1 /* update checksum */, 1 /* force flush */);
1571
979
}
ssl_tls12_server.c:mbedtls_ssl_write_handshake_msg
Line
Count
Source
1569
742
{
1570
742
    return mbedtls_ssl_write_handshake_msg_ext(ssl, 1 /* update checksum */, 1 /* force flush */);
1571
742
}
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_write_handshake_msg
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_write_handshake_msg
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_write_handshake_msg
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_write_handshake_msg
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_write_handshake_msg
ssl_client.c:mbedtls_ssl_write_handshake_msg
Line
Count
Source
1569
5.78k
{
1570
5.78k
    return mbedtls_ssl_write_handshake_msg_ext(ssl, 1 /* update checksum */, 1 /* force flush */);
1571
5.78k
}
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_write_handshake_msg
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_write_handshake_msg
1572
1573
/*
1574
 * Write handshake message tail
1575
 */
1576
MBEDTLS_CHECK_RETURN_CRITICAL
1577
int mbedtls_ssl_finish_handshake_msg(mbedtls_ssl_context *ssl,
1578
                                     size_t buf_len, size_t msg_len);
1579
1580
MBEDTLS_CHECK_RETURN_CRITICAL
1581
int mbedtls_ssl_write_record(mbedtls_ssl_context *ssl, int force_flush);
1582
MBEDTLS_CHECK_RETURN_CRITICAL
1583
int mbedtls_ssl_flush_output(mbedtls_ssl_context *ssl);
1584
1585
MBEDTLS_CHECK_RETURN_CRITICAL
1586
int mbedtls_ssl_parse_certificate(mbedtls_ssl_context *ssl);
1587
MBEDTLS_CHECK_RETURN_CRITICAL
1588
int mbedtls_ssl_write_certificate(mbedtls_ssl_context *ssl);
1589
1590
MBEDTLS_CHECK_RETURN_CRITICAL
1591
int mbedtls_ssl_parse_change_cipher_spec(mbedtls_ssl_context *ssl);
1592
MBEDTLS_CHECK_RETURN_CRITICAL
1593
int mbedtls_ssl_write_change_cipher_spec(mbedtls_ssl_context *ssl);
1594
1595
MBEDTLS_CHECK_RETURN_CRITICAL
1596
int mbedtls_ssl_parse_finished(mbedtls_ssl_context *ssl);
1597
MBEDTLS_CHECK_RETURN_CRITICAL
1598
int mbedtls_ssl_write_finished(mbedtls_ssl_context *ssl);
1599
1600
void mbedtls_ssl_optimize_checksum(mbedtls_ssl_context *ssl,
1601
                                   const mbedtls_ssl_ciphersuite_t *ciphersuite_info);
1602
1603
/*
1604
 * Update checksum of handshake messages.
1605
 */
1606
MBEDTLS_CHECK_RETURN_CRITICAL
1607
int mbedtls_ssl_add_hs_msg_to_checksum(mbedtls_ssl_context *ssl,
1608
                                       unsigned hs_type,
1609
                                       unsigned char const *msg,
1610
                                       size_t msg_len);
1611
1612
MBEDTLS_CHECK_RETURN_CRITICAL
1613
int mbedtls_ssl_add_hs_hdr_to_checksum(mbedtls_ssl_context *ssl,
1614
                                       unsigned hs_type,
1615
                                       size_t total_hs_len);
1616
1617
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
1618
#if !defined(MBEDTLS_USE_PSA_CRYPTO)
1619
MBEDTLS_CHECK_RETURN_CRITICAL
1620
int mbedtls_ssl_psk_derive_premaster(mbedtls_ssl_context *ssl,
1621
                                     mbedtls_key_exchange_type_t key_ex);
1622
#endif /* !MBEDTLS_USE_PSA_CRYPTO */
1623
#endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */
1624
1625
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
1626
#if defined(MBEDTLS_SSL_CLI_C) || defined(MBEDTLS_SSL_SRV_C)
1627
MBEDTLS_CHECK_RETURN_CRITICAL
1628
int mbedtls_ssl_conf_has_static_psk(mbedtls_ssl_config const *conf);
1629
#endif
1630
#if defined(MBEDTLS_USE_PSA_CRYPTO)
1631
/**
1632
 * Get the first defined opaque PSK by order of precedence:
1633
 * 1. handshake PSK set by \c mbedtls_ssl_set_hs_psk_opaque() in the PSK
1634
 *    callback
1635
 * 2. static PSK configured by \c mbedtls_ssl_conf_psk_opaque()
1636
 * Return an opaque PSK
1637
 */
1638
static inline mbedtls_svc_key_id_t mbedtls_ssl_get_opaque_psk(
1639
    const mbedtls_ssl_context *ssl)
1640
0
{
1641
0
    if (!mbedtls_svc_key_id_is_null(ssl->handshake->psk_opaque)) {
1642
0
        return ssl->handshake->psk_opaque;
1643
0
    }
1644
1645
0
    if (!mbedtls_svc_key_id_is_null(ssl->conf->psk_opaque)) {
1646
0
        return ssl->conf->psk_opaque;
1647
0
    }
1648
1649
0
    return MBEDTLS_SVC_KEY_ID_INIT;
1650
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_get_opaque_psk
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_get_opaque_psk
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_get_opaque_psk
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_get_opaque_psk
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_get_opaque_psk
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_get_opaque_psk
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_get_opaque_psk
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_get_opaque_psk
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_get_opaque_psk
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_get_opaque_psk
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_get_opaque_psk
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_get_opaque_psk
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_get_opaque_psk
1651
#else
1652
/**
1653
 * Get the first defined PSK by order of precedence:
1654
 * 1. handshake PSK set by \c mbedtls_ssl_set_hs_psk() in the PSK callback
1655
 * 2. static PSK configured by \c mbedtls_ssl_conf_psk()
1656
 * Return a code and update the pair (PSK, PSK length) passed to this function
1657
 */
1658
static inline int mbedtls_ssl_get_psk(const mbedtls_ssl_context *ssl,
1659
                                      const unsigned char **psk, size_t *psk_len)
1660
0
{
1661
0
    if (ssl->handshake->psk != NULL && ssl->handshake->psk_len > 0) {
1662
0
        *psk = ssl->handshake->psk;
1663
0
        *psk_len = ssl->handshake->psk_len;
1664
0
    } else if (ssl->conf->psk != NULL && ssl->conf->psk_len > 0) {
1665
0
        *psk = ssl->conf->psk;
1666
0
        *psk_len = ssl->conf->psk_len;
1667
0
    } else {
1668
0
        *psk = NULL;
1669
0
        *psk_len = 0;
1670
0
        return MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED;
1671
0
    }
1672
1673
0
    return 0;
1674
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_get_psk
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_get_psk
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_get_psk
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_get_psk
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_get_psk
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_get_psk
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_get_psk
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_get_psk
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_get_psk
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_get_psk
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_get_psk
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_get_psk
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_get_psk
1675
#endif /* MBEDTLS_USE_PSA_CRYPTO */
1676
1677
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED */
1678
1679
#if defined(MBEDTLS_PK_C)
1680
unsigned char mbedtls_ssl_sig_from_pk(mbedtls_pk_context *pk);
1681
unsigned char mbedtls_ssl_sig_from_pk_alg(mbedtls_pk_type_t type);
1682
mbedtls_pk_type_t mbedtls_ssl_pk_alg_from_sig(unsigned char sig);
1683
#endif
1684
1685
mbedtls_md_type_t mbedtls_ssl_md_alg_from_hash(unsigned char hash);
1686
unsigned char mbedtls_ssl_hash_from_md_alg(int md);
1687
1688
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
1689
MBEDTLS_CHECK_RETURN_CRITICAL
1690
int mbedtls_ssl_set_calc_verify_md(mbedtls_ssl_context *ssl, int md);
1691
#endif
1692
1693
MBEDTLS_CHECK_RETURN_CRITICAL
1694
int mbedtls_ssl_check_curve_tls_id(const mbedtls_ssl_context *ssl, uint16_t tls_id);
1695
#if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
1696
MBEDTLS_CHECK_RETURN_CRITICAL
1697
int mbedtls_ssl_check_curve(const mbedtls_ssl_context *ssl, mbedtls_ecp_group_id grp_id);
1698
#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
1699
1700
/**
1701
 * \brief Return PSA EC info for the specified TLS ID.
1702
 *
1703
 * \param tls_id    The TLS ID to look for
1704
 * \param type      If the TLD ID is supported, then proper \c psa_key_type_t
1705
 *                  value is returned here. Can be NULL.
1706
 * \param bits      If the TLD ID is supported, then proper bit size is returned
1707
 *                  here. Can be NULL.
1708
 * \return          PSA_SUCCESS if the TLS ID is supported,
1709
 *                  PSA_ERROR_NOT_SUPPORTED otherwise
1710
 *
1711
 * \note            If either \c family or \c bits parameters are NULL, then
1712
 *                  the corresponding value is not returned.
1713
 *                  The function can be called with both parameters as NULL
1714
 *                  simply to check if a specific TLS ID is supported.
1715
 */
1716
int mbedtls_ssl_get_psa_curve_info_from_tls_id(uint16_t tls_id,
1717
                                               psa_key_type_t *type,
1718
                                               size_t *bits);
1719
1720
/**
1721
 * \brief Return \c mbedtls_ecp_group_id for the specified TLS ID.
1722
 *
1723
 * \param tls_id    The TLS ID to look for
1724
 * \return          Proper \c mbedtls_ecp_group_id if the TLS ID is supported,
1725
 *                  or MBEDTLS_ECP_DP_NONE otherwise
1726
 */
1727
mbedtls_ecp_group_id mbedtls_ssl_get_ecp_group_id_from_tls_id(uint16_t tls_id);
1728
1729
/**
1730
 * \brief Return TLS ID for the specified \c mbedtls_ecp_group_id.
1731
 *
1732
 * \param grp_id    The \c mbedtls_ecp_group_id ID to look for
1733
 * \return          Proper TLS ID if the \c mbedtls_ecp_group_id is supported,
1734
 *                  or 0 otherwise
1735
 */
1736
uint16_t mbedtls_ssl_get_tls_id_from_ecp_group_id(mbedtls_ecp_group_id grp_id);
1737
1738
#if defined(MBEDTLS_DEBUG_C)
1739
/**
1740
 * \brief Return EC's name for the specified TLS ID.
1741
 *
1742
 * \param tls_id    The TLS ID to look for
1743
 * \return          A pointer to a const string with the proper name. If TLS
1744
 *                  ID is not supported, a NULL pointer is returned instead.
1745
 */
1746
const char *mbedtls_ssl_get_curve_name_from_tls_id(uint16_t tls_id);
1747
#endif
1748
1749
#if defined(MBEDTLS_SSL_DTLS_SRTP)
1750
static inline mbedtls_ssl_srtp_profile mbedtls_ssl_check_srtp_profile_value
1751
    (const uint16_t srtp_profile_value)
1752
0
{
1753
0
    switch (srtp_profile_value) {
1754
0
        case MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80:
1755
0
        case MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32:
1756
0
        case MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80:
1757
0
        case MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32:
1758
0
            return srtp_profile_value;
1759
0
        default: break;
1760
0
    }
1761
0
    return MBEDTLS_TLS_SRTP_UNSET;
1762
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_check_srtp_profile_value
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_check_srtp_profile_value
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_check_srtp_profile_value
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_check_srtp_profile_value
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_check_srtp_profile_value
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_check_srtp_profile_value
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_check_srtp_profile_value
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_check_srtp_profile_value
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_check_srtp_profile_value
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_check_srtp_profile_value
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_check_srtp_profile_value
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_check_srtp_profile_value
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_check_srtp_profile_value
1763
#endif
1764
1765
#if defined(MBEDTLS_X509_CRT_PARSE_C)
1766
static inline mbedtls_pk_context *mbedtls_ssl_own_key(mbedtls_ssl_context *ssl)
1767
0
{
1768
0
    mbedtls_ssl_key_cert *key_cert;
1769
1770
0
    if (ssl->handshake != NULL && ssl->handshake->key_cert != NULL) {
1771
0
        key_cert = ssl->handshake->key_cert;
1772
0
    } else {
1773
0
        key_cert = ssl->conf->key_cert;
1774
0
    }
1775
1776
0
    return key_cert == NULL ? NULL : key_cert->key;
1777
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_own_key
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_own_key
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_own_key
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_own_key
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_own_key
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_own_key
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_own_key
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_own_key
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_own_key
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_own_key
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_own_key
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_own_key
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_own_key
1778
1779
static inline mbedtls_x509_crt *mbedtls_ssl_own_cert(mbedtls_ssl_context *ssl)
1780
5
{
1781
5
    mbedtls_ssl_key_cert *key_cert;
1782
1783
5
    if (ssl->handshake != NULL && ssl->handshake->key_cert != NULL) {
1784
0
        key_cert = ssl->handshake->key_cert;
1785
5
    } else {
1786
5
        key_cert = ssl->conf->key_cert;
1787
5
    }
1788
1789
5
    return key_cert == NULL ? NULL : key_cert->cert;
1790
5
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_own_cert
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_own_cert
ssl_tls.c:mbedtls_ssl_own_cert
Line
Count
Source
1780
4
{
1781
4
    mbedtls_ssl_key_cert *key_cert;
1782
1783
4
    if (ssl->handshake != NULL && ssl->handshake->key_cert != NULL) {
1784
0
        key_cert = ssl->handshake->key_cert;
1785
4
    } else {
1786
4
        key_cert = ssl->conf->key_cert;
1787
4
    }
1788
1789
4
    return key_cert == NULL ? NULL : key_cert->cert;
1790
4
}
ssl_tls12_client.c:mbedtls_ssl_own_cert
Line
Count
Source
1780
1
{
1781
1
    mbedtls_ssl_key_cert *key_cert;
1782
1783
1
    if (ssl->handshake != NULL && ssl->handshake->key_cert != NULL) {
1784
0
        key_cert = ssl->handshake->key_cert;
1785
1
    } else {
1786
1
        key_cert = ssl->conf->key_cert;
1787
1
    }
1788
1789
1
    return key_cert == NULL ? NULL : key_cert->cert;
1790
1
}
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_own_cert
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_own_cert
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_own_cert
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_own_cert
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_own_cert
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_own_cert
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_own_cert
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_own_cert
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_own_cert
1791
1792
/*
1793
 * Verify a certificate.
1794
 *
1795
 * [in/out] ssl: misc. things read
1796
 *               ssl->session_negotiate->verify_result updated
1797
 * [in] authmode: one of MBEDTLS_SSL_VERIFY_{NONE,OPTIONAL,REQUIRED}
1798
 * [in] chain: the certificate chain to verify (ie the peer's chain)
1799
 * [in] ciphersuite_info: For TLS 1.2, this session's ciphersuite;
1800
 *                        for TLS 1.3, may be left NULL.
1801
 * [in] rs_ctx: restart context if restartable ECC is in use;
1802
 *              leave NULL for no restartable behaviour.
1803
 *
1804
 * Return:
1805
 * - 0 if the handshake should continue. Depending on the
1806
 *   authmode it means:
1807
 *   - REQUIRED: the certificate was found to be valid, trusted & acceptable.
1808
 *     ssl->session_negotiate->verify_result is 0.
1809
 *   - OPTIONAL: the certificate may or may not be acceptable, but
1810
 *     ssl->session_negotiate->verify_result was updated with the result.
1811
 *   - NONE: the certificate wasn't even checked.
1812
 * - MBEDTLS_ERR_X509_CERT_VERIFY_FAILED or MBEDTLS_ERR_SSL_BAD_CERTIFICATE if
1813
 *   the certificate was found to be invalid/untrusted/unacceptable and the
1814
 *   handshake should be aborted (can only happen with REQUIRED).
1815
 * - another error code if another error happened (out-of-memory, etc.)
1816
 */
1817
MBEDTLS_CHECK_RETURN_CRITICAL
1818
int mbedtls_ssl_verify_certificate(mbedtls_ssl_context *ssl,
1819
                                   int authmode,
1820
                                   mbedtls_x509_crt *chain,
1821
                                   const mbedtls_ssl_ciphersuite_t *ciphersuite_info,
1822
                                   void *rs_ctx);
1823
1824
/*
1825
 * Check usage of a certificate wrt usage extensions:
1826
 * keyUsage and extendedKeyUsage.
1827
 * (Note: nSCertType is deprecated and not standard, we don't check it.)
1828
 *
1829
 * Note: if tls_version is 1.3, ciphersuite is ignored and can be NULL.
1830
 *
1831
 * Note: recv_endpoint is the receiver's endpoint.
1832
 *
1833
 * Return 0 if everything is OK, -1 if not.
1834
 */
1835
MBEDTLS_CHECK_RETURN_CRITICAL
1836
int mbedtls_ssl_check_cert_usage(const mbedtls_x509_crt *cert,
1837
                                 const mbedtls_ssl_ciphersuite_t *ciphersuite,
1838
                                 int recv_endpoint,
1839
                                 mbedtls_ssl_protocol_version tls_version,
1840
                                 uint32_t *flags);
1841
#endif /* MBEDTLS_X509_CRT_PARSE_C */
1842
1843
void mbedtls_ssl_write_version(unsigned char version[2], int transport,
1844
                               mbedtls_ssl_protocol_version tls_version);
1845
uint16_t mbedtls_ssl_read_version(const unsigned char version[2],
1846
                                  int transport);
1847
1848
static inline size_t mbedtls_ssl_in_hdr_len(const mbedtls_ssl_context *ssl)
1849
125k
{
1850
#if !defined(MBEDTLS_SSL_PROTO_DTLS)
1851
    ((void) ssl);
1852
#endif
1853
1854
125k
#if defined(MBEDTLS_SSL_PROTO_DTLS)
1855
125k
    if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
1856
54.6k
        return 13;
1857
54.6k
    } else
1858
70.6k
#endif /* MBEDTLS_SSL_PROTO_DTLS */
1859
70.6k
    {
1860
70.6k
        return 5;
1861
70.6k
    }
1862
125k
}
ssl_msg.c:mbedtls_ssl_in_hdr_len
Line
Count
Source
1849
125k
{
1850
#if !defined(MBEDTLS_SSL_PROTO_DTLS)
1851
    ((void) ssl);
1852
#endif
1853
1854
125k
#if defined(MBEDTLS_SSL_PROTO_DTLS)
1855
125k
    if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
1856
54.6k
        return 13;
1857
54.6k
    } else
1858
70.6k
#endif /* MBEDTLS_SSL_PROTO_DTLS */
1859
70.6k
    {
1860
70.6k
        return 5;
1861
70.6k
    }
1862
125k
}
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_in_hdr_len
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_in_hdr_len
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_in_hdr_len
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_in_hdr_len
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_in_hdr_len
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_in_hdr_len
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_in_hdr_len
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_in_hdr_len
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_in_hdr_len
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_in_hdr_len
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_in_hdr_len
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_in_hdr_len
1863
1864
static inline size_t mbedtls_ssl_out_hdr_len(const mbedtls_ssl_context *ssl)
1865
154k
{
1866
154k
    return (size_t) (ssl->out_iv - ssl->out_hdr);
1867
154k
}
ssl_msg.c:mbedtls_ssl_out_hdr_len
Line
Count
Source
1865
154k
{
1866
154k
    return (size_t) (ssl->out_iv - ssl->out_hdr);
1867
154k
}
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_out_hdr_len
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_out_hdr_len
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_out_hdr_len
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_out_hdr_len
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_out_hdr_len
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_out_hdr_len
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_out_hdr_len
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_out_hdr_len
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_out_hdr_len
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_out_hdr_len
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_out_hdr_len
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_out_hdr_len
1868
1869
static inline size_t mbedtls_ssl_hs_hdr_len(const mbedtls_ssl_context *ssl)
1870
112k
{
1871
112k
#if defined(MBEDTLS_SSL_PROTO_DTLS)
1872
112k
    if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
1873
106k
        return 12;
1874
106k
    }
1875
#else
1876
    ((void) ssl);
1877
#endif
1878
5.91k
    return 4;
1879
112k
}
ssl_msg.c:mbedtls_ssl_hs_hdr_len
Line
Count
Source
1870
74.7k
{
1871
74.7k
#if defined(MBEDTLS_SSL_PROTO_DTLS)
1872
74.7k
    if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
1873
71.4k
        return 12;
1874
71.4k
    }
1875
#else
1876
    ((void) ssl);
1877
#endif
1878
3.35k
    return 4;
1879
74.7k
}
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_hs_hdr_len
ssl_tls.c:mbedtls_ssl_hs_hdr_len
Line
Count
Source
1870
11.5k
{
1871
11.5k
#if defined(MBEDTLS_SSL_PROTO_DTLS)
1872
11.5k
    if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
1873
11.5k
        return 12;
1874
11.5k
    }
1875
#else
1876
    ((void) ssl);
1877
#endif
1878
0
    return 4;
1879
11.5k
}
ssl_tls12_client.c:mbedtls_ssl_hs_hdr_len
Line
Count
Source
1870
21.7k
{
1871
21.7k
#if defined(MBEDTLS_SSL_PROTO_DTLS)
1872
21.7k
    if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
1873
21.7k
        return 12;
1874
21.7k
    }
1875
#else
1876
    ((void) ssl);
1877
#endif
1878
0
    return 4;
1879
21.7k
}
ssl_tls12_server.c:mbedtls_ssl_hs_hdr_len
Line
Count
Source
1870
4.22k
{
1871
4.22k
#if defined(MBEDTLS_SSL_PROTO_DTLS)
1872
4.22k
    if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
1873
1.66k
        return 12;
1874
1.66k
    }
1875
#else
1876
    ((void) ssl);
1877
#endif
1878
2.56k
    return 4;
1879
4.22k
}
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_hs_hdr_len
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_hs_hdr_len
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_hs_hdr_len
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_hs_hdr_len
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_hs_hdr_len
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_hs_hdr_len
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_hs_hdr_len
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_hs_hdr_len
1880
1881
#if defined(MBEDTLS_SSL_PROTO_DTLS)
1882
void mbedtls_ssl_send_flight_completed(mbedtls_ssl_context *ssl);
1883
void mbedtls_ssl_recv_flight_completed(mbedtls_ssl_context *ssl);
1884
MBEDTLS_CHECK_RETURN_CRITICAL
1885
int mbedtls_ssl_resend(mbedtls_ssl_context *ssl);
1886
MBEDTLS_CHECK_RETURN_CRITICAL
1887
int mbedtls_ssl_flight_transmit(mbedtls_ssl_context *ssl);
1888
#endif
1889
1890
/* Visible for testing purposes only */
1891
#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
1892
MBEDTLS_CHECK_RETURN_CRITICAL
1893
int mbedtls_ssl_dtls_replay_check(mbedtls_ssl_context const *ssl);
1894
void mbedtls_ssl_dtls_replay_update(mbedtls_ssl_context *ssl);
1895
#endif
1896
1897
MBEDTLS_CHECK_RETURN_CRITICAL
1898
int mbedtls_ssl_session_copy(mbedtls_ssl_session *dst,
1899
                             const mbedtls_ssl_session *src);
1900
1901
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
1902
/* The hash buffer must have at least MBEDTLS_MD_MAX_SIZE bytes of length. */
1903
MBEDTLS_CHECK_RETURN_CRITICAL
1904
int mbedtls_ssl_get_key_exchange_md_tls1_2(mbedtls_ssl_context *ssl,
1905
                                           unsigned char *hash, size_t *hashlen,
1906
                                           unsigned char *data, size_t data_len,
1907
                                           mbedtls_md_type_t md_alg);
1908
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
1909
1910
#ifdef __cplusplus
1911
}
1912
#endif
1913
1914
void mbedtls_ssl_transform_init(mbedtls_ssl_transform *transform);
1915
MBEDTLS_CHECK_RETURN_CRITICAL
1916
int mbedtls_ssl_encrypt_buf(mbedtls_ssl_context *ssl,
1917
                            mbedtls_ssl_transform *transform,
1918
                            mbedtls_record *rec,
1919
                            int (*f_rng)(void *, unsigned char *, size_t),
1920
                            void *p_rng);
1921
MBEDTLS_CHECK_RETURN_CRITICAL
1922
int mbedtls_ssl_decrypt_buf(mbedtls_ssl_context const *ssl,
1923
                            mbedtls_ssl_transform *transform,
1924
                            mbedtls_record *rec);
1925
1926
/* Length of the "epoch" field in the record header */
1927
static inline size_t mbedtls_ssl_ep_len(const mbedtls_ssl_context *ssl)
1928
94.2k
{
1929
94.2k
#if defined(MBEDTLS_SSL_PROTO_DTLS)
1930
94.2k
    if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
1931
90.3k
        return 2;
1932
90.3k
    }
1933
#else
1934
    ((void) ssl);
1935
#endif
1936
3.91k
    return 0;
1937
94.2k
}
ssl_msg.c:mbedtls_ssl_ep_len
Line
Count
Source
1928
94.2k
{
1929
94.2k
#if defined(MBEDTLS_SSL_PROTO_DTLS)
1930
94.2k
    if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
1931
90.3k
        return 2;
1932
90.3k
    }
1933
#else
1934
    ((void) ssl);
1935
#endif
1936
3.91k
    return 0;
1937
94.2k
}
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_ep_len
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_ep_len
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_ep_len
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_ep_len
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_ep_len
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_ep_len
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_ep_len
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_ep_len
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_ep_len
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_ep_len
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_ep_len
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_ep_len
1938
1939
#if defined(MBEDTLS_SSL_PROTO_DTLS)
1940
MBEDTLS_CHECK_RETURN_CRITICAL
1941
int mbedtls_ssl_resend_hello_request(mbedtls_ssl_context *ssl);
1942
#endif /* MBEDTLS_SSL_PROTO_DTLS */
1943
1944
void mbedtls_ssl_set_timer(mbedtls_ssl_context *ssl, uint32_t millisecs);
1945
MBEDTLS_CHECK_RETURN_CRITICAL
1946
int mbedtls_ssl_check_timer(mbedtls_ssl_context *ssl);
1947
1948
void mbedtls_ssl_reset_in_pointers(mbedtls_ssl_context *ssl);
1949
void mbedtls_ssl_update_in_pointers(mbedtls_ssl_context *ssl);
1950
void mbedtls_ssl_reset_out_pointers(mbedtls_ssl_context *ssl);
1951
void mbedtls_ssl_update_out_pointers(mbedtls_ssl_context *ssl,
1952
                                     mbedtls_ssl_transform *transform);
1953
1954
MBEDTLS_CHECK_RETURN_CRITICAL
1955
int mbedtls_ssl_session_reset_int(mbedtls_ssl_context *ssl, int partial);
1956
void mbedtls_ssl_session_reset_msg_layer(mbedtls_ssl_context *ssl,
1957
                                         int partial);
1958
1959
/*
1960
 * Send pending alert
1961
 */
1962
MBEDTLS_CHECK_RETURN_CRITICAL
1963
int mbedtls_ssl_handle_pending_alert(mbedtls_ssl_context *ssl);
1964
1965
/*
1966
 * Set pending fatal alert flag.
1967
 */
1968
void mbedtls_ssl_pend_fatal_alert(mbedtls_ssl_context *ssl,
1969
                                  unsigned char alert_type,
1970
                                  int alert_reason);
1971
1972
/* Alias of mbedtls_ssl_pend_fatal_alert */
1973
#define MBEDTLS_SSL_PEND_FATAL_ALERT(type, user_return_value)         \
1974
836
    mbedtls_ssl_pend_fatal_alert(ssl, type, user_return_value)
1975
1976
#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
1977
void mbedtls_ssl_dtls_replay_reset(mbedtls_ssl_context *ssl);
1978
#endif
1979
1980
void mbedtls_ssl_handshake_wrapup_free_hs_transform(mbedtls_ssl_context *ssl);
1981
1982
#if defined(MBEDTLS_SSL_RENEGOTIATION)
1983
MBEDTLS_CHECK_RETURN_CRITICAL
1984
int mbedtls_ssl_start_renegotiation(mbedtls_ssl_context *ssl);
1985
#endif /* MBEDTLS_SSL_RENEGOTIATION */
1986
1987
#if defined(MBEDTLS_SSL_PROTO_DTLS)
1988
size_t mbedtls_ssl_get_current_mtu(const mbedtls_ssl_context *ssl);
1989
void mbedtls_ssl_buffering_free(mbedtls_ssl_context *ssl);
1990
void mbedtls_ssl_flight_free(mbedtls_ssl_flight_item *flight);
1991
#endif /* MBEDTLS_SSL_PROTO_DTLS */
1992
1993
/**
1994
 * ssl utils functions for checking configuration.
1995
 */
1996
1997
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
1998
static inline int mbedtls_ssl_conf_is_tls13_only(const mbedtls_ssl_config *conf)
1999
8.97k
{
2000
8.97k
    return conf->min_tls_version == MBEDTLS_SSL_VERSION_TLS1_3 &&
2001
0
           conf->max_tls_version == MBEDTLS_SSL_VERSION_TLS1_3;
2002
8.97k
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_conf_is_tls13_only
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_conf_is_tls13_only
ssl_tls.c:mbedtls_ssl_conf_is_tls13_only
Line
Count
Source
1999
8.97k
{
2000
8.97k
    return conf->min_tls_version == MBEDTLS_SSL_VERSION_TLS1_3 &&
2001
0
           conf->max_tls_version == MBEDTLS_SSL_VERSION_TLS1_3;
2002
8.97k
}
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_conf_is_tls13_only
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_conf_is_tls13_only
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_conf_is_tls13_only
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_conf_is_tls13_only
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_conf_is_tls13_only
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_conf_is_tls13_only
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_conf_is_tls13_only
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_conf_is_tls13_only
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_conf_is_tls13_only
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_conf_is_tls13_only
2003
2004
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
2005
2006
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
2007
static inline int mbedtls_ssl_conf_is_tls12_only(const mbedtls_ssl_config *conf)
2008
28.6k
{
2009
28.6k
    return conf->min_tls_version == MBEDTLS_SSL_VERSION_TLS1_2 &&
2010
28.6k
           conf->max_tls_version == MBEDTLS_SSL_VERSION_TLS1_2;
2011
28.6k
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_conf_is_tls12_only
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_conf_is_tls12_only
ssl_tls.c:mbedtls_ssl_conf_is_tls12_only
Line
Count
Source
2008
28.6k
{
2009
28.6k
    return conf->min_tls_version == MBEDTLS_SSL_VERSION_TLS1_2 &&
2010
28.6k
           conf->max_tls_version == MBEDTLS_SSL_VERSION_TLS1_2;
2011
28.6k
}
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_conf_is_tls12_only
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_conf_is_tls12_only
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_conf_is_tls12_only
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_conf_is_tls12_only
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_conf_is_tls12_only
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_conf_is_tls12_only
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_conf_is_tls12_only
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_conf_is_tls12_only
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_conf_is_tls12_only
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_conf_is_tls12_only
2012
2013
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
2014
2015
static inline int mbedtls_ssl_conf_is_tls13_enabled(const mbedtls_ssl_config *conf)
2016
277
{
2017
277
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
2018
277
    return conf->min_tls_version <= MBEDTLS_SSL_VERSION_TLS1_3 &&
2019
277
           conf->max_tls_version >= MBEDTLS_SSL_VERSION_TLS1_3;
2020
#else
2021
    ((void) conf);
2022
    return 0;
2023
#endif
2024
277
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_conf_is_tls13_enabled
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_conf_is_tls13_enabled
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_conf_is_tls13_enabled
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_conf_is_tls13_enabled
ssl_tls12_server.c:mbedtls_ssl_conf_is_tls13_enabled
Line
Count
Source
2016
277
{
2017
277
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
2018
277
    return conf->min_tls_version <= MBEDTLS_SSL_VERSION_TLS1_3 &&
2019
277
           conf->max_tls_version >= MBEDTLS_SSL_VERSION_TLS1_3;
2020
#else
2021
    ((void) conf);
2022
    return 0;
2023
#endif
2024
277
}
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_conf_is_tls13_enabled
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_conf_is_tls13_enabled
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_conf_is_tls13_enabled
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_conf_is_tls13_enabled
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_conf_is_tls13_enabled
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_conf_is_tls13_enabled
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_conf_is_tls13_enabled
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_conf_is_tls13_enabled
2025
2026
static inline int mbedtls_ssl_conf_is_tls12_enabled(const mbedtls_ssl_config *conf)
2027
1.41k
{
2028
1.41k
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
2029
1.41k
    return conf->min_tls_version <= MBEDTLS_SSL_VERSION_TLS1_2 &&
2030
1.41k
           conf->max_tls_version >= MBEDTLS_SSL_VERSION_TLS1_2;
2031
#else
2032
    ((void) conf);
2033
    return 0;
2034
#endif
2035
1.41k
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_conf_is_tls12_enabled
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_conf_is_tls12_enabled
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_conf_is_tls12_enabled
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_conf_is_tls12_enabled
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_conf_is_tls12_enabled
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_conf_is_tls12_enabled
ssl_tls13_server.c:mbedtls_ssl_conf_is_tls12_enabled
Line
Count
Source
2027
1.41k
{
2028
1.41k
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
2029
1.41k
    return conf->min_tls_version <= MBEDTLS_SSL_VERSION_TLS1_2 &&
2030
1.41k
           conf->max_tls_version >= MBEDTLS_SSL_VERSION_TLS1_2;
2031
#else
2032
    ((void) conf);
2033
    return 0;
2034
#endif
2035
1.41k
}
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_conf_is_tls12_enabled
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_conf_is_tls12_enabled
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_conf_is_tls12_enabled
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_conf_is_tls12_enabled
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_conf_is_tls12_enabled
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_conf_is_tls12_enabled
2036
2037
#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && defined(MBEDTLS_SSL_PROTO_TLS1_3)
2038
static inline int mbedtls_ssl_conf_is_hybrid_tls12_tls13(const mbedtls_ssl_config *conf)
2039
1.80k
{
2040
1.80k
    return conf->min_tls_version == MBEDTLS_SSL_VERSION_TLS1_2 &&
2041
1.80k
           conf->max_tls_version == MBEDTLS_SSL_VERSION_TLS1_3;
2042
1.80k
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_conf_is_hybrid_tls12_tls13
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_conf_is_hybrid_tls12_tls13
ssl_tls.c:mbedtls_ssl_conf_is_hybrid_tls12_tls13
Line
Count
Source
2039
1.80k
{
2040
1.80k
    return conf->min_tls_version == MBEDTLS_SSL_VERSION_TLS1_2 &&
2041
1.80k
           conf->max_tls_version == MBEDTLS_SSL_VERSION_TLS1_3;
2042
1.80k
}
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_conf_is_hybrid_tls12_tls13
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_conf_is_hybrid_tls12_tls13
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_conf_is_hybrid_tls12_tls13
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_conf_is_hybrid_tls12_tls13
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_conf_is_hybrid_tls12_tls13
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_conf_is_hybrid_tls12_tls13
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_conf_is_hybrid_tls12_tls13
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_conf_is_hybrid_tls12_tls13
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_conf_is_hybrid_tls12_tls13
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_conf_is_hybrid_tls12_tls13
2043
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 && MBEDTLS_SSL_PROTO_TLS1_3 */
2044
2045
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
2046
2047
/** \brief Initialize the PSA crypto subsystem if necessary.
2048
 *
2049
 * Call this function before doing any cryptography in a TLS 1.3 handshake.
2050
 *
2051
 * This is necessary in Mbed TLS 3.x for backward compatibility.
2052
 * Up to Mbed TLS 3.5, in the default configuration, you could perform
2053
 * a TLS connection with default parameters without having called
2054
 * psa_crypto_init(), since the TLS layer only supported TLS 1.2 and
2055
 * did not use PSA crypto. (TLS 1.2 only uses PSA crypto if
2056
 * MBEDTLS_USE_PSA_CRYPTO is enabled, which is not the case in the default
2057
 * configuration.) Starting with Mbed TLS 3.6.0, TLS 1.3 is enabled
2058
 * by default, and the TLS 1.3 layer uses PSA crypto. This means that
2059
 * applications that are not otherwise using PSA crypto and that worked
2060
 * with Mbed TLS 3.5 started failing in TLS 3.6.0 if they connected to
2061
 * a peer that supports TLS 1.3. See
2062
 * https://github.com/Mbed-TLS/mbedtls/issues/9072
2063
 */
2064
int mbedtls_ssl_tls13_crypto_init(mbedtls_ssl_context *ssl);
2065
2066
extern const uint8_t mbedtls_ssl_tls13_hello_retry_request_magic[
2067
    MBEDTLS_SERVER_HELLO_RANDOM_LEN];
2068
MBEDTLS_CHECK_RETURN_CRITICAL
2069
int mbedtls_ssl_tls13_process_finished_message(mbedtls_ssl_context *ssl);
2070
MBEDTLS_CHECK_RETURN_CRITICAL
2071
int mbedtls_ssl_tls13_write_finished_message(mbedtls_ssl_context *ssl);
2072
void mbedtls_ssl_tls13_handshake_wrapup(mbedtls_ssl_context *ssl);
2073
2074
/**
2075
 * \brief Given an SSL context and its associated configuration, write the TLS
2076
 *        1.3 specific extensions of the ClientHello message.
2077
 *
2078
 * \param[in]   ssl     SSL context
2079
 * \param[in]   buf     Base address of the buffer where to write the extensions
2080
 * \param[in]   end     End address of the buffer where to write the extensions
2081
 * \param[out]  out_len Length of the data written into the buffer \p buf
2082
 */
2083
MBEDTLS_CHECK_RETURN_CRITICAL
2084
int mbedtls_ssl_tls13_write_client_hello_exts(mbedtls_ssl_context *ssl,
2085
                                              unsigned char *buf,
2086
                                              unsigned char *end,
2087
                                              size_t *out_len);
2088
2089
/**
2090
 * \brief           TLS 1.3 client side state machine entry
2091
 *
2092
 * \param ssl       SSL context
2093
 */
2094
MBEDTLS_CHECK_RETURN_CRITICAL
2095
int mbedtls_ssl_tls13_handshake_client_step(mbedtls_ssl_context *ssl);
2096
2097
/**
2098
 * \brief           TLS 1.3 server side state machine entry
2099
 *
2100
 * \param ssl       SSL context
2101
 */
2102
MBEDTLS_CHECK_RETURN_CRITICAL
2103
int mbedtls_ssl_tls13_handshake_server_step(mbedtls_ssl_context *ssl);
2104
2105
2106
/*
2107
 * Helper functions around key exchange modes.
2108
 */
2109
static inline int mbedtls_ssl_conf_tls13_is_kex_mode_enabled(mbedtls_ssl_context *ssl,
2110
                                                             int kex_mode_mask)
2111
0
{
2112
0
    return (ssl->conf->tls13_kex_modes & kex_mode_mask) != 0;
2113
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_conf_tls13_is_kex_mode_enabled
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_conf_tls13_is_kex_mode_enabled
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_conf_tls13_is_kex_mode_enabled
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_conf_tls13_is_kex_mode_enabled
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_conf_tls13_is_kex_mode_enabled
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_conf_tls13_is_kex_mode_enabled
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_conf_tls13_is_kex_mode_enabled
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_conf_tls13_is_kex_mode_enabled
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_conf_tls13_is_kex_mode_enabled
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_conf_tls13_is_kex_mode_enabled
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_conf_tls13_is_kex_mode_enabled
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_conf_tls13_is_kex_mode_enabled
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_conf_tls13_is_kex_mode_enabled
2114
2115
static inline int mbedtls_ssl_conf_tls13_is_psk_enabled(mbedtls_ssl_context *ssl)
2116
0
{
2117
0
    return mbedtls_ssl_conf_tls13_is_kex_mode_enabled(ssl,
2118
0
                                                      MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK);
2119
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_conf_tls13_is_psk_enabled
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_conf_tls13_is_psk_enabled
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_conf_tls13_is_psk_enabled
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_conf_tls13_is_psk_enabled
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_conf_tls13_is_psk_enabled
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_conf_tls13_is_psk_enabled
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_conf_tls13_is_psk_enabled
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_conf_tls13_is_psk_enabled
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_conf_tls13_is_psk_enabled
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_conf_tls13_is_psk_enabled
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_conf_tls13_is_psk_enabled
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_conf_tls13_is_psk_enabled
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_conf_tls13_is_psk_enabled
2120
2121
static inline int mbedtls_ssl_conf_tls13_is_psk_ephemeral_enabled(mbedtls_ssl_context *ssl)
2122
0
{
2123
0
    return mbedtls_ssl_conf_tls13_is_kex_mode_enabled(ssl,
2124
0
                                                      MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL);
2125
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_conf_tls13_is_psk_ephemeral_enabled
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_conf_tls13_is_psk_ephemeral_enabled
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_conf_tls13_is_psk_ephemeral_enabled
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_conf_tls13_is_psk_ephemeral_enabled
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_conf_tls13_is_psk_ephemeral_enabled
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_conf_tls13_is_psk_ephemeral_enabled
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_conf_tls13_is_psk_ephemeral_enabled
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_conf_tls13_is_psk_ephemeral_enabled
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_conf_tls13_is_psk_ephemeral_enabled
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_conf_tls13_is_psk_ephemeral_enabled
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_conf_tls13_is_psk_ephemeral_enabled
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_conf_tls13_is_psk_ephemeral_enabled
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_conf_tls13_is_psk_ephemeral_enabled
2126
2127
static inline int mbedtls_ssl_conf_tls13_is_ephemeral_enabled(mbedtls_ssl_context *ssl)
2128
0
{
2129
0
    return mbedtls_ssl_conf_tls13_is_kex_mode_enabled(ssl,
2130
0
                                                      MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL);
2131
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_conf_tls13_is_ephemeral_enabled
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_conf_tls13_is_ephemeral_enabled
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_conf_tls13_is_ephemeral_enabled
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_conf_tls13_is_ephemeral_enabled
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_conf_tls13_is_ephemeral_enabled
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_conf_tls13_is_ephemeral_enabled
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_conf_tls13_is_ephemeral_enabled
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_conf_tls13_is_ephemeral_enabled
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_conf_tls13_is_ephemeral_enabled
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_conf_tls13_is_ephemeral_enabled
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_conf_tls13_is_ephemeral_enabled
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_conf_tls13_is_ephemeral_enabled
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_conf_tls13_is_ephemeral_enabled
2132
2133
static inline int mbedtls_ssl_conf_tls13_is_some_ephemeral_enabled(mbedtls_ssl_context *ssl)
2134
0
{
2135
0
    return mbedtls_ssl_conf_tls13_is_kex_mode_enabled(ssl,
2136
0
                                                      MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ALL);
2137
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_conf_tls13_is_some_ephemeral_enabled
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_conf_tls13_is_some_ephemeral_enabled
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_conf_tls13_is_some_ephemeral_enabled
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_conf_tls13_is_some_ephemeral_enabled
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_conf_tls13_is_some_ephemeral_enabled
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_conf_tls13_is_some_ephemeral_enabled
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_conf_tls13_is_some_ephemeral_enabled
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_conf_tls13_is_some_ephemeral_enabled
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_conf_tls13_is_some_ephemeral_enabled
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_conf_tls13_is_some_ephemeral_enabled
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_conf_tls13_is_some_ephemeral_enabled
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_conf_tls13_is_some_ephemeral_enabled
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_conf_tls13_is_some_ephemeral_enabled
2138
2139
static inline int mbedtls_ssl_conf_tls13_is_some_psk_enabled(mbedtls_ssl_context *ssl)
2140
0
{
2141
0
    return mbedtls_ssl_conf_tls13_is_kex_mode_enabled(ssl,
2142
0
                                                      MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ALL);
2143
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_conf_tls13_is_some_psk_enabled
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_conf_tls13_is_some_psk_enabled
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_conf_tls13_is_some_psk_enabled
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_conf_tls13_is_some_psk_enabled
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_conf_tls13_is_some_psk_enabled
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_conf_tls13_is_some_psk_enabled
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_conf_tls13_is_some_psk_enabled
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_conf_tls13_is_some_psk_enabled
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_conf_tls13_is_some_psk_enabled
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_conf_tls13_is_some_psk_enabled
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_conf_tls13_is_some_psk_enabled
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_conf_tls13_is_some_psk_enabled
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_conf_tls13_is_some_psk_enabled
2144
2145
#if defined(MBEDTLS_SSL_SRV_C) && \
2146
    defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_PSK_ENABLED)
2147
/**
2148
 * Given a list of key exchange modes, check if at least one of them is
2149
 * supported by peer.
2150
 *
2151
 * \param[in] ssl  SSL context
2152
 * \param kex_modes_mask  Mask of the key exchange modes to check
2153
 *
2154
 * \return Non-zero if at least one of the key exchange modes is supported by
2155
 *         the peer, otherwise \c 0.
2156
 */
2157
static inline int mbedtls_ssl_tls13_is_kex_mode_supported(mbedtls_ssl_context *ssl,
2158
                                                          int kex_modes_mask)
2159
0
{
2160
0
    return (ssl->handshake->tls13_kex_modes & kex_modes_mask) != 0;
2161
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls13_is_kex_mode_supported
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls13_is_kex_mode_supported
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_tls13_is_kex_mode_supported
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls13_is_kex_mode_supported
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls13_is_kex_mode_supported
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls13_is_kex_mode_supported
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls13_is_kex_mode_supported
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls13_is_kex_mode_supported
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls13_is_kex_mode_supported
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls13_is_kex_mode_supported
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_tls13_is_kex_mode_supported
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls13_is_kex_mode_supported
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls13_is_kex_mode_supported
2162
2163
static inline int mbedtls_ssl_tls13_is_psk_supported(mbedtls_ssl_context *ssl)
2164
0
{
2165
0
    return mbedtls_ssl_tls13_is_kex_mode_supported(ssl,
2166
0
                                                   MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK);
2167
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls13_is_psk_supported
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls13_is_psk_supported
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_tls13_is_psk_supported
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls13_is_psk_supported
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls13_is_psk_supported
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls13_is_psk_supported
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls13_is_psk_supported
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls13_is_psk_supported
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls13_is_psk_supported
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls13_is_psk_supported
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_tls13_is_psk_supported
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls13_is_psk_supported
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls13_is_psk_supported
2168
2169
static inline int mbedtls_ssl_tls13_is_psk_ephemeral_supported(
2170
    mbedtls_ssl_context *ssl)
2171
0
{
2172
0
    return mbedtls_ssl_tls13_is_kex_mode_supported(ssl,
2173
0
                                                   MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL);
2174
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls13_is_psk_ephemeral_supported
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls13_is_psk_ephemeral_supported
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_tls13_is_psk_ephemeral_supported
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls13_is_psk_ephemeral_supported
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls13_is_psk_ephemeral_supported
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls13_is_psk_ephemeral_supported
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls13_is_psk_ephemeral_supported
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls13_is_psk_ephemeral_supported
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls13_is_psk_ephemeral_supported
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls13_is_psk_ephemeral_supported
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_tls13_is_psk_ephemeral_supported
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls13_is_psk_ephemeral_supported
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls13_is_psk_ephemeral_supported
2175
2176
static inline int mbedtls_ssl_tls13_is_ephemeral_supported(mbedtls_ssl_context *ssl)
2177
0
{
2178
0
    return mbedtls_ssl_tls13_is_kex_mode_supported(ssl,
2179
0
                                                   MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL);
2180
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls13_is_ephemeral_supported
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls13_is_ephemeral_supported
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_tls13_is_ephemeral_supported
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls13_is_ephemeral_supported
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls13_is_ephemeral_supported
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls13_is_ephemeral_supported
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls13_is_ephemeral_supported
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls13_is_ephemeral_supported
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls13_is_ephemeral_supported
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls13_is_ephemeral_supported
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_tls13_is_ephemeral_supported
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls13_is_ephemeral_supported
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls13_is_ephemeral_supported
2181
2182
static inline int mbedtls_ssl_tls13_is_some_ephemeral_supported(mbedtls_ssl_context *ssl)
2183
0
{
2184
0
    return mbedtls_ssl_tls13_is_kex_mode_supported(ssl,
2185
0
                                                   MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ALL);
2186
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls13_is_some_ephemeral_supported
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls13_is_some_ephemeral_supported
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_tls13_is_some_ephemeral_supported
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls13_is_some_ephemeral_supported
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls13_is_some_ephemeral_supported
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls13_is_some_ephemeral_supported
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls13_is_some_ephemeral_supported
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls13_is_some_ephemeral_supported
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls13_is_some_ephemeral_supported
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls13_is_some_ephemeral_supported
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_tls13_is_some_ephemeral_supported
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls13_is_some_ephemeral_supported
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls13_is_some_ephemeral_supported
2187
2188
static inline int mbedtls_ssl_tls13_is_some_psk_supported(mbedtls_ssl_context *ssl)
2189
0
{
2190
0
    return mbedtls_ssl_tls13_is_kex_mode_supported(ssl,
2191
0
                                                   MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ALL);
2192
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls13_is_some_psk_supported
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls13_is_some_psk_supported
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_tls13_is_some_psk_supported
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls13_is_some_psk_supported
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls13_is_some_psk_supported
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls13_is_some_psk_supported
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls13_is_some_psk_supported
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls13_is_some_psk_supported
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls13_is_some_psk_supported
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls13_is_some_psk_supported
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_tls13_is_some_psk_supported
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls13_is_some_psk_supported
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls13_is_some_psk_supported
2193
#endif /* MBEDTLS_SSL_SRV_C &&
2194
          MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_PSK_ENABLED */
2195
2196
/*
2197
 * Helper functions for extensions checking.
2198
 */
2199
2200
MBEDTLS_CHECK_RETURN_CRITICAL
2201
int mbedtls_ssl_tls13_check_received_extension(
2202
    mbedtls_ssl_context *ssl,
2203
    int hs_msg_type,
2204
    unsigned int received_extension_type,
2205
    uint32_t hs_msg_allowed_extensions_mask);
2206
2207
static inline void mbedtls_ssl_tls13_set_hs_sent_ext_mask(
2208
    mbedtls_ssl_context *ssl, unsigned int extension_type)
2209
17.3k
{
2210
17.3k
    ssl->handshake->sent_extensions |=
2211
17.3k
        mbedtls_ssl_get_extension_mask(extension_type);
2212
17.3k
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls13_set_hs_sent_ext_mask
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls13_set_hs_sent_ext_mask
ssl_tls.c:mbedtls_ssl_tls13_set_hs_sent_ext_mask
Line
Count
Source
2209
5.79k
{
2210
5.79k
    ssl->handshake->sent_extensions |=
2211
5.79k
        mbedtls_ssl_get_extension_mask(extension_type);
2212
5.79k
}
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls13_set_hs_sent_ext_mask
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls13_set_hs_sent_ext_mask
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls13_set_hs_sent_ext_mask
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls13_set_hs_sent_ext_mask
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls13_set_hs_sent_ext_mask
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls13_set_hs_sent_ext_mask
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls13_set_hs_sent_ext_mask
ssl_client.c:mbedtls_ssl_tls13_set_hs_sent_ext_mask
Line
Count
Source
2209
11.5k
{
2210
11.5k
    ssl->handshake->sent_extensions |=
2211
11.5k
        mbedtls_ssl_get_extension_mask(extension_type);
2212
11.5k
}
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls13_set_hs_sent_ext_mask
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls13_set_hs_sent_ext_mask
2213
2214
/*
2215
 * Helper functions to check the selected key exchange mode.
2216
 */
2217
static inline int mbedtls_ssl_tls13_key_exchange_mode_check(
2218
    mbedtls_ssl_context *ssl, int kex_mask)
2219
0
{
2220
0
    return (ssl->handshake->key_exchange_mode & kex_mask) != 0;
2221
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls13_key_exchange_mode_check
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls13_key_exchange_mode_check
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_tls13_key_exchange_mode_check
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls13_key_exchange_mode_check
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls13_key_exchange_mode_check
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls13_key_exchange_mode_check
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls13_key_exchange_mode_check
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls13_key_exchange_mode_check
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls13_key_exchange_mode_check
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls13_key_exchange_mode_check
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_tls13_key_exchange_mode_check
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls13_key_exchange_mode_check
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls13_key_exchange_mode_check
2222
2223
static inline int mbedtls_ssl_tls13_key_exchange_mode_with_psk(
2224
    mbedtls_ssl_context *ssl)
2225
0
{
2226
0
    return mbedtls_ssl_tls13_key_exchange_mode_check(ssl,
2227
0
                                                     MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ALL);
2228
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls13_key_exchange_mode_with_psk
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls13_key_exchange_mode_with_psk
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_tls13_key_exchange_mode_with_psk
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls13_key_exchange_mode_with_psk
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls13_key_exchange_mode_with_psk
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls13_key_exchange_mode_with_psk
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls13_key_exchange_mode_with_psk
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls13_key_exchange_mode_with_psk
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls13_key_exchange_mode_with_psk
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls13_key_exchange_mode_with_psk
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_tls13_key_exchange_mode_with_psk
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls13_key_exchange_mode_with_psk
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls13_key_exchange_mode_with_psk
2229
2230
static inline int mbedtls_ssl_tls13_key_exchange_mode_with_ephemeral(
2231
    mbedtls_ssl_context *ssl)
2232
0
{
2233
0
    return mbedtls_ssl_tls13_key_exchange_mode_check(ssl,
2234
0
                                                     MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ALL);
2235
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls13_key_exchange_mode_with_ephemeral
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls13_key_exchange_mode_with_ephemeral
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_tls13_key_exchange_mode_with_ephemeral
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls13_key_exchange_mode_with_ephemeral
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls13_key_exchange_mode_with_ephemeral
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls13_key_exchange_mode_with_ephemeral
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls13_key_exchange_mode_with_ephemeral
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls13_key_exchange_mode_with_ephemeral
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls13_key_exchange_mode_with_ephemeral
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls13_key_exchange_mode_with_ephemeral
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_tls13_key_exchange_mode_with_ephemeral
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls13_key_exchange_mode_with_ephemeral
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls13_key_exchange_mode_with_ephemeral
2236
2237
/*
2238
 * Fetch TLS 1.3 handshake message header
2239
 */
2240
MBEDTLS_CHECK_RETURN_CRITICAL
2241
int mbedtls_ssl_tls13_fetch_handshake_msg(mbedtls_ssl_context *ssl,
2242
                                          unsigned hs_type,
2243
                                          unsigned char **buf,
2244
                                          size_t *buf_len);
2245
2246
/**
2247
 * \brief Detect if a list of extensions contains a supported_versions
2248
 *        extension or not.
2249
 *
2250
 * \param[in] ssl  SSL context
2251
 * \param[in] buf  Address of the first byte of the extensions vector.
2252
 * \param[in] end  End of the buffer containing the list of extensions.
2253
 * \param[out] supported_versions_data  If the extension is present, address of
2254
 *                                      its first byte of data, NULL otherwise.
2255
 * \param[out] supported_versions_data_end  If the extension is present, address
2256
 *                                          of the first byte immediately
2257
 *                                          following the extension data, NULL
2258
 *                                          otherwise.
2259
 * \return 0  if the list of extensions does not contain a supported_versions
2260
 *            extension.
2261
 * \return 1  if the list of extensions contains a supported_versions
2262
 *            extension.
2263
 * \return    A negative value if an error occurred while parsing the
2264
 *            extensions.
2265
 */
2266
MBEDTLS_CHECK_RETURN_CRITICAL
2267
int mbedtls_ssl_tls13_is_supported_versions_ext_present_in_exts(
2268
    mbedtls_ssl_context *ssl,
2269
    const unsigned char *buf, const unsigned char *end,
2270
    const unsigned char **supported_versions_data,
2271
    const unsigned char **supported_versions_data_end);
2272
2273
/*
2274
 * Handler of TLS 1.3 server certificate message
2275
 */
2276
MBEDTLS_CHECK_RETURN_CRITICAL
2277
int mbedtls_ssl_tls13_process_certificate(mbedtls_ssl_context *ssl);
2278
2279
#if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED)
2280
/*
2281
 * Handler of TLS 1.3 write Certificate message
2282
 */
2283
MBEDTLS_CHECK_RETURN_CRITICAL
2284
int mbedtls_ssl_tls13_write_certificate(mbedtls_ssl_context *ssl);
2285
2286
/*
2287
 * Handler of TLS 1.3 write Certificate Verify message
2288
 */
2289
MBEDTLS_CHECK_RETURN_CRITICAL
2290
int mbedtls_ssl_tls13_write_certificate_verify(mbedtls_ssl_context *ssl);
2291
2292
#endif /* MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED */
2293
2294
/*
2295
 * Generic handler of Certificate Verify
2296
 */
2297
MBEDTLS_CHECK_RETURN_CRITICAL
2298
int mbedtls_ssl_tls13_process_certificate_verify(mbedtls_ssl_context *ssl);
2299
2300
/*
2301
 * Write of dummy-CCS's for middlebox compatibility
2302
 */
2303
MBEDTLS_CHECK_RETURN_CRITICAL
2304
int mbedtls_ssl_tls13_write_change_cipher_spec(mbedtls_ssl_context *ssl);
2305
2306
MBEDTLS_CHECK_RETURN_CRITICAL
2307
int mbedtls_ssl_reset_transcript_for_hrr(mbedtls_ssl_context *ssl);
2308
2309
#if defined(PSA_WANT_ALG_ECDH) || defined(PSA_WANT_ALG_FFDH)
2310
MBEDTLS_CHECK_RETURN_CRITICAL
2311
int mbedtls_ssl_tls13_generate_and_write_xxdh_key_exchange(
2312
    mbedtls_ssl_context *ssl,
2313
    uint16_t named_group,
2314
    unsigned char *buf,
2315
    unsigned char *end,
2316
    size_t *out_len);
2317
#endif /* PSA_WANT_ALG_ECDH || PSA_WANT_ALG_FFDH */
2318
2319
#if defined(MBEDTLS_SSL_EARLY_DATA)
2320
int mbedtls_ssl_tls13_write_early_data_ext(mbedtls_ssl_context *ssl,
2321
                                           int in_new_session_ticket,
2322
                                           unsigned char *buf,
2323
                                           const unsigned char *end,
2324
                                           size_t *out_len);
2325
2326
int mbedtls_ssl_tls13_check_early_data_len(mbedtls_ssl_context *ssl,
2327
                                           size_t early_data_len);
2328
2329
typedef enum {
2330
/*
2331
 * The client has not sent the first ClientHello yet, the negotiation of early
2332
 * data has not started yet.
2333
 */
2334
    MBEDTLS_SSL_EARLY_DATA_STATE_IDLE,
2335
2336
/*
2337
 * In its ClientHello, the client has not included an early data indication
2338
 * extension.
2339
 */
2340
    MBEDTLS_SSL_EARLY_DATA_STATE_NO_IND_SENT,
2341
2342
/*
2343
 * The client has sent an early data indication extension in its first
2344
 * ClientHello, it has not received the response (ServerHello or
2345
 * HelloRetryRequest) from the server yet. The transform to protect early data
2346
 * is not set either as for middlebox compatibility a dummy CCS may have to be
2347
 * sent in clear. Early data cannot be sent to the server yet.
2348
 */
2349
    MBEDTLS_SSL_EARLY_DATA_STATE_IND_SENT,
2350
2351
/*
2352
 * The client has sent an early data indication extension in its first
2353
 * ClientHello, it has not received the response (ServerHello or
2354
 * HelloRetryRequest) from the server yet. The transform to protect early data
2355
 * has been set and early data can be written now.
2356
 */
2357
    MBEDTLS_SSL_EARLY_DATA_STATE_CAN_WRITE,
2358
2359
/*
2360
 * The client has indicated the use of early data and the server has accepted
2361
 * it.
2362
 */
2363
    MBEDTLS_SSL_EARLY_DATA_STATE_ACCEPTED,
2364
2365
/*
2366
 * The client has indicated the use of early data but the server has rejected
2367
 * it.
2368
 */
2369
    MBEDTLS_SSL_EARLY_DATA_STATE_REJECTED,
2370
2371
/*
2372
 * The client has sent an early data indication extension in its first
2373
 * ClientHello, the server has accepted them and the client has received the
2374
 * server Finished message. It cannot send early data to the server anymore.
2375
 */
2376
    MBEDTLS_SSL_EARLY_DATA_STATE_SERVER_FINISHED_RECEIVED,
2377
2378
} mbedtls_ssl_early_data_state;
2379
#endif /* MBEDTLS_SSL_EARLY_DATA */
2380
2381
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
2382
2383
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
2384
/*
2385
 * Write Signature Algorithm extension
2386
 */
2387
MBEDTLS_CHECK_RETURN_CRITICAL
2388
int mbedtls_ssl_write_sig_alg_ext(mbedtls_ssl_context *ssl, unsigned char *buf,
2389
                                  const unsigned char *end, size_t *out_len);
2390
/*
2391
 * Parse TLS Signature Algorithm extension
2392
 */
2393
MBEDTLS_CHECK_RETURN_CRITICAL
2394
int mbedtls_ssl_parse_sig_alg_ext(mbedtls_ssl_context *ssl,
2395
                                  const unsigned char *buf,
2396
                                  const unsigned char *end);
2397
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
2398
2399
/* Get handshake transcript */
2400
MBEDTLS_CHECK_RETURN_CRITICAL
2401
int mbedtls_ssl_get_handshake_transcript(mbedtls_ssl_context *ssl,
2402
                                         const mbedtls_md_type_t md,
2403
                                         unsigned char *dst,
2404
                                         size_t dst_len,
2405
                                         size_t *olen);
2406
2407
/*
2408
 * Return supported groups.
2409
 *
2410
 * In future, invocations can be changed to ssl->conf->group_list
2411
 * when mbedtls_ssl_conf_curves() is deleted.
2412
 *
2413
 * ssl->handshake->group_list is either a translation of curve_list to IANA TLS group
2414
 * identifiers when mbedtls_ssl_conf_curves() has been used, or a pointer to
2415
 * ssl->conf->group_list when mbedtls_ssl_conf_groups() has been more recently invoked.
2416
 *
2417
 */
2418
static inline const void *mbedtls_ssl_get_groups(const mbedtls_ssl_context *ssl)
2419
6.87k
{
2420
    #if defined(MBEDTLS_DEPRECATED_REMOVED) || !defined(MBEDTLS_ECP_C)
2421
    return ssl->conf->group_list;
2422
    #else
2423
6.87k
    if ((ssl->handshake != NULL) && (ssl->handshake->group_list != NULL)) {
2424
6.87k
        return ssl->handshake->group_list;
2425
6.87k
    } else {
2426
0
        return ssl->conf->group_list;
2427
0
    }
2428
6.87k
    #endif
2429
6.87k
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_get_groups
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_get_groups
ssl_tls.c:mbedtls_ssl_get_groups
Line
Count
Source
2419
1.02k
{
2420
    #if defined(MBEDTLS_DEPRECATED_REMOVED) || !defined(MBEDTLS_ECP_C)
2421
    return ssl->conf->group_list;
2422
    #else
2423
1.02k
    if ((ssl->handshake != NULL) && (ssl->handshake->group_list != NULL)) {
2424
1.02k
        return ssl->handshake->group_list;
2425
1.02k
    } else {
2426
0
        return ssl->conf->group_list;
2427
0
    }
2428
1.02k
    #endif
2429
1.02k
}
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_get_groups
ssl_tls12_server.c:mbedtls_ssl_get_groups
Line
Count
Source
2419
76
{
2420
    #if defined(MBEDTLS_DEPRECATED_REMOVED) || !defined(MBEDTLS_ECP_C)
2421
    return ssl->conf->group_list;
2422
    #else
2423
76
    if ((ssl->handshake != NULL) && (ssl->handshake->group_list != NULL)) {
2424
76
        return ssl->handshake->group_list;
2425
76
    } else {
2426
0
        return ssl->conf->group_list;
2427
0
    }
2428
76
    #endif
2429
76
}
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_get_groups
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_get_groups
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_get_groups
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_get_groups
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_get_groups
ssl_client.c:mbedtls_ssl_get_groups
Line
Count
Source
2419
5.78k
{
2420
    #if defined(MBEDTLS_DEPRECATED_REMOVED) || !defined(MBEDTLS_ECP_C)
2421
    return ssl->conf->group_list;
2422
    #else
2423
5.78k
    if ((ssl->handshake != NULL) && (ssl->handshake->group_list != NULL)) {
2424
5.78k
        return ssl->handshake->group_list;
2425
5.78k
    } else {
2426
0
        return ssl->conf->group_list;
2427
0
    }
2428
5.78k
    #endif
2429
5.78k
}
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_get_groups
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_get_groups
2430
2431
/*
2432
 * Helper functions for NamedGroup.
2433
 */
2434
static inline int mbedtls_ssl_tls12_named_group_is_ecdhe(uint16_t named_group)
2435
75.1k
{
2436
    /*
2437
     * RFC 8422 section 5.1.1
2438
     */
2439
75.1k
    return named_group == MBEDTLS_SSL_IANA_TLS_GROUP_X25519    ||
2440
69.3k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_BP256R1   ||
2441
63.5k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_BP384R1   ||
2442
57.8k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_BP512R1   ||
2443
52.0k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_X448      ||
2444
           /* Below deprecated curves should be removed with notice to users */
2445
46.2k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP192K1 ||
2446
46.2k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP192R1 ||
2447
46.2k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP224K1 ||
2448
46.2k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP224R1 ||
2449
46.2k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP256K1 ||
2450
46.2k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP256R1 ||
2451
40.4k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP384R1 ||
2452
34.6k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP521R1;
2453
75.1k
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls12_named_group_is_ecdhe
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls12_named_group_is_ecdhe
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_tls12_named_group_is_ecdhe
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls12_named_group_is_ecdhe
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls12_named_group_is_ecdhe
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls12_named_group_is_ecdhe
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls12_named_group_is_ecdhe
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls12_named_group_is_ecdhe
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls12_named_group_is_ecdhe
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls12_named_group_is_ecdhe
ssl_client.c:mbedtls_ssl_tls12_named_group_is_ecdhe
Line
Count
Source
2435
75.1k
{
2436
    /*
2437
     * RFC 8422 section 5.1.1
2438
     */
2439
75.1k
    return named_group == MBEDTLS_SSL_IANA_TLS_GROUP_X25519    ||
2440
69.3k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_BP256R1   ||
2441
63.5k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_BP384R1   ||
2442
57.8k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_BP512R1   ||
2443
52.0k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_X448      ||
2444
           /* Below deprecated curves should be removed with notice to users */
2445
46.2k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP192K1 ||
2446
46.2k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP192R1 ||
2447
46.2k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP224K1 ||
2448
46.2k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP224R1 ||
2449
46.2k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP256K1 ||
2450
46.2k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP256R1 ||
2451
40.4k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP384R1 ||
2452
34.6k
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP521R1;
2453
75.1k
}
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls12_named_group_is_ecdhe
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls12_named_group_is_ecdhe
2454
2455
static inline int mbedtls_ssl_tls13_named_group_is_ecdhe(uint16_t named_group)
2456
0
{
2457
0
    return named_group == MBEDTLS_SSL_IANA_TLS_GROUP_X25519    ||
2458
0
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP256R1 ||
2459
0
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP384R1 ||
2460
0
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP521R1 ||
2461
0
           named_group == MBEDTLS_SSL_IANA_TLS_GROUP_X448;
2462
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls13_named_group_is_ecdhe
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls13_named_group_is_ecdhe
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_tls13_named_group_is_ecdhe
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls13_named_group_is_ecdhe
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls13_named_group_is_ecdhe
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls13_named_group_is_ecdhe
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls13_named_group_is_ecdhe
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls13_named_group_is_ecdhe
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls13_named_group_is_ecdhe
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls13_named_group_is_ecdhe
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_tls13_named_group_is_ecdhe
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls13_named_group_is_ecdhe
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls13_named_group_is_ecdhe
2463
2464
static inline int mbedtls_ssl_tls13_named_group_is_ffdh(uint16_t named_group)
2465
0
{
2466
0
    return named_group >= MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE2048 &&
2467
0
           named_group <= MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE8192;
2468
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls13_named_group_is_ffdh
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls13_named_group_is_ffdh
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_tls13_named_group_is_ffdh
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls13_named_group_is_ffdh
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls13_named_group_is_ffdh
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls13_named_group_is_ffdh
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls13_named_group_is_ffdh
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls13_named_group_is_ffdh
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls13_named_group_is_ffdh
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls13_named_group_is_ffdh
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_tls13_named_group_is_ffdh
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls13_named_group_is_ffdh
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls13_named_group_is_ffdh
2469
2470
static inline int mbedtls_ssl_named_group_is_offered(
2471
    const mbedtls_ssl_context *ssl, uint16_t named_group)
2472
0
{
2473
0
    const uint16_t *group_list = mbedtls_ssl_get_groups(ssl);
2474
2475
0
    if (group_list == NULL) {
2476
0
        return 0;
2477
0
    }
2478
2479
0
    for (; *group_list != 0; group_list++) {
2480
0
        if (*group_list == named_group) {
2481
0
            return 1;
2482
0
        }
2483
0
    }
2484
2485
0
    return 0;
2486
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_named_group_is_offered
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_named_group_is_offered
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_named_group_is_offered
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_named_group_is_offered
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_named_group_is_offered
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_named_group_is_offered
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_named_group_is_offered
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_named_group_is_offered
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_named_group_is_offered
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_named_group_is_offered
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_named_group_is_offered
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_named_group_is_offered
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_named_group_is_offered
2487
2488
static inline int mbedtls_ssl_named_group_is_supported(uint16_t named_group)
2489
0
{
2490
0
#if defined(PSA_WANT_ALG_ECDH)
2491
0
    if (mbedtls_ssl_tls13_named_group_is_ecdhe(named_group)) {
2492
0
        if (mbedtls_ssl_get_ecp_group_id_from_tls_id(named_group) !=
2493
0
            MBEDTLS_ECP_DP_NONE) {
2494
0
            return 1;
2495
0
        }
2496
0
    }
2497
0
#endif
2498
0
#if defined(PSA_WANT_ALG_FFDH)
2499
0
    if (mbedtls_ssl_tls13_named_group_is_ffdh(named_group)) {
2500
0
        return 1;
2501
0
    }
2502
0
#endif
2503
#if !defined(PSA_WANT_ALG_ECDH) && !defined(PSA_WANT_ALG_FFDH)
2504
    (void) named_group;
2505
#endif
2506
0
    return 0;
2507
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_named_group_is_supported
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_named_group_is_supported
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_named_group_is_supported
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_named_group_is_supported
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_named_group_is_supported
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_named_group_is_supported
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_named_group_is_supported
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_named_group_is_supported
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_named_group_is_supported
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_named_group_is_supported
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_named_group_is_supported
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_named_group_is_supported
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_named_group_is_supported
2508
2509
/*
2510
 * Return supported signature algorithms.
2511
 *
2512
 * In future, invocations can be changed to ssl->conf->sig_algs when
2513
 * mbedtls_ssl_conf_sig_hashes() is deleted.
2514
 *
2515
 * ssl->handshake->sig_algs is either a translation of sig_hashes to IANA TLS
2516
 * signature algorithm identifiers when mbedtls_ssl_conf_sig_hashes() has been
2517
 * used, or a pointer to ssl->conf->sig_algs when mbedtls_ssl_conf_sig_algs() has
2518
 * been more recently invoked.
2519
 *
2520
 */
2521
static inline const void *mbedtls_ssl_get_sig_algs(
2522
    const mbedtls_ssl_context *ssl)
2523
17.2k
{
2524
17.2k
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
2525
2526
17.2k
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
2527
17.2k
    if (ssl->handshake != NULL &&
2528
17.2k
        ssl->handshake->sig_algs_heap_allocated == 1 &&
2529
0
        ssl->handshake->sig_algs != NULL) {
2530
0
        return ssl->handshake->sig_algs;
2531
0
    }
2532
17.2k
#endif
2533
17.2k
    return ssl->conf->sig_algs;
2534
2535
#else /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
2536
2537
    ((void) ssl);
2538
    return NULL;
2539
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
2540
17.2k
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_get_sig_algs
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_get_sig_algs
ssl_tls.c:mbedtls_ssl_get_sig_algs
Line
Count
Source
2523
16.9k
{
2524
16.9k
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
2525
2526
16.9k
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
2527
16.9k
    if (ssl->handshake != NULL &&
2528
16.9k
        ssl->handshake->sig_algs_heap_allocated == 1 &&
2529
0
        ssl->handshake->sig_algs != NULL) {
2530
0
        return ssl->handshake->sig_algs;
2531
0
    }
2532
16.9k
#endif
2533
16.9k
    return ssl->conf->sig_algs;
2534
2535
#else /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
2536
2537
    ((void) ssl);
2538
    return NULL;
2539
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
2540
16.9k
}
ssl_tls12_client.c:mbedtls_ssl_get_sig_algs
Line
Count
Source
2523
356
{
2524
356
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
2525
2526
356
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
2527
356
    if (ssl->handshake != NULL &&
2528
356
        ssl->handshake->sig_algs_heap_allocated == 1 &&
2529
0
        ssl->handshake->sig_algs != NULL) {
2530
0
        return ssl->handshake->sig_algs;
2531
0
    }
2532
356
#endif
2533
356
    return ssl->conf->sig_algs;
2534
2535
#else /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
2536
2537
    ((void) ssl);
2538
    return NULL;
2539
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
2540
356
}
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_get_sig_algs
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_get_sig_algs
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_get_sig_algs
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_get_sig_algs
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_get_sig_algs
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_get_sig_algs
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_get_sig_algs
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_get_sig_algs
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_get_sig_algs
2541
2542
#if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED)
2543
static inline int mbedtls_ssl_sig_alg_is_received(const mbedtls_ssl_context *ssl,
2544
                                                  uint16_t own_sig_alg)
2545
0
{
2546
0
    const uint16_t *sig_alg = ssl->handshake->received_sig_algs;
2547
0
    if (sig_alg == NULL) {
2548
0
        return 0;
2549
0
    }
2550
0
2551
0
    for (; *sig_alg != MBEDTLS_TLS_SIG_NONE; sig_alg++) {
2552
0
        if (*sig_alg == own_sig_alg) {
2553
0
            return 1;
2554
0
        }
2555
0
    }
2556
0
    return 0;
2557
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_sig_alg_is_received
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_sig_alg_is_received
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_sig_alg_is_received
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_sig_alg_is_received
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_sig_alg_is_received
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_sig_alg_is_received
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_sig_alg_is_received
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_sig_alg_is_received
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_sig_alg_is_received
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_sig_alg_is_received
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_sig_alg_is_received
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_sig_alg_is_received
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_sig_alg_is_received
2558
2559
static inline int mbedtls_ssl_tls13_sig_alg_for_cert_verify_is_supported(
2560
    const uint16_t sig_alg)
2561
0
{
2562
0
    switch (sig_alg) {
2563
0
#if defined(MBEDTLS_PK_CAN_ECDSA_SOME)
2564
0
#if defined(PSA_WANT_ALG_SHA_256) && defined(PSA_WANT_ECC_SECP_R1_256)
2565
0
        case MBEDTLS_TLS1_3_SIG_ECDSA_SECP256R1_SHA256:
2566
0
            break;
2567
0
#endif /* PSA_WANT_ALG_SHA_256 && MBEDTLS_ECP_DP_SECP256R1_ENABLED */
2568
0
#if defined(PSA_WANT_ALG_SHA_384) && defined(PSA_WANT_ECC_SECP_R1_384)
2569
0
        case MBEDTLS_TLS1_3_SIG_ECDSA_SECP384R1_SHA384:
2570
0
            break;
2571
0
#endif /* PSA_WANT_ALG_SHA_384 && MBEDTLS_ECP_DP_SECP384R1_ENABLED */
2572
0
#if defined(PSA_WANT_ALG_SHA_512) && defined(PSA_WANT_ECC_SECP_R1_521)
2573
0
        case MBEDTLS_TLS1_3_SIG_ECDSA_SECP521R1_SHA512:
2574
0
            break;
2575
0
#endif /* PSA_WANT_ALG_SHA_512 && MBEDTLS_ECP_DP_SECP521R1_ENABLED */
2576
0
#endif /* MBEDTLS_PK_CAN_ECDSA_SOME */
2577
2578
0
#if defined(MBEDTLS_PKCS1_V21)
2579
0
#if defined(PSA_WANT_ALG_SHA_256)
2580
0
        case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA256:
2581
0
            break;
2582
0
#endif /* PSA_WANT_ALG_SHA_256  */
2583
0
#if defined(PSA_WANT_ALG_SHA_384)
2584
0
        case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA384:
2585
0
            break;
2586
0
#endif /* PSA_WANT_ALG_SHA_384 */
2587
0
#if defined(PSA_WANT_ALG_SHA_512)
2588
0
        case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA512:
2589
0
            break;
2590
0
#endif /* PSA_WANT_ALG_SHA_512 */
2591
0
#endif /* MBEDTLS_PKCS1_V21 */
2592
0
        default:
2593
0
            return 0;
2594
0
    }
2595
0
    return 1;
2596
2597
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls13_sig_alg_for_cert_verify_is_supported
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls13_sig_alg_for_cert_verify_is_supported
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_tls13_sig_alg_for_cert_verify_is_supported
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls13_sig_alg_for_cert_verify_is_supported
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls13_sig_alg_for_cert_verify_is_supported
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls13_sig_alg_for_cert_verify_is_supported
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls13_sig_alg_for_cert_verify_is_supported
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls13_sig_alg_for_cert_verify_is_supported
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls13_sig_alg_for_cert_verify_is_supported
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls13_sig_alg_for_cert_verify_is_supported
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_tls13_sig_alg_for_cert_verify_is_supported
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls13_sig_alg_for_cert_verify_is_supported
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls13_sig_alg_for_cert_verify_is_supported
2598
2599
static inline int mbedtls_ssl_tls13_sig_alg_is_supported(
2600
    const uint16_t sig_alg)
2601
0
{
2602
0
    switch (sig_alg) {
2603
0
#if defined(MBEDTLS_PKCS1_V15)
2604
0
#if defined(MBEDTLS_MD_CAN_SHA256)
2605
0
        case MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA256:
2606
0
            break;
2607
0
#endif /* MBEDTLS_MD_CAN_SHA256 */
2608
0
#if defined(MBEDTLS_MD_CAN_SHA384)
2609
0
        case MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA384:
2610
0
            break;
2611
0
#endif /* MBEDTLS_MD_CAN_SHA384 */
2612
0
#if defined(MBEDTLS_MD_CAN_SHA512)
2613
0
        case MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA512:
2614
0
            break;
2615
0
#endif /* MBEDTLS_MD_CAN_SHA512 */
2616
0
#endif /* MBEDTLS_PKCS1_V15 */
2617
0
        default:
2618
0
            return mbedtls_ssl_tls13_sig_alg_for_cert_verify_is_supported(
2619
0
                sig_alg);
2620
0
    }
2621
0
    return 1;
2622
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls13_sig_alg_is_supported
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls13_sig_alg_is_supported
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_tls13_sig_alg_is_supported
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls13_sig_alg_is_supported
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls13_sig_alg_is_supported
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls13_sig_alg_is_supported
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls13_sig_alg_is_supported
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls13_sig_alg_is_supported
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls13_sig_alg_is_supported
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls13_sig_alg_is_supported
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_tls13_sig_alg_is_supported
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls13_sig_alg_is_supported
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls13_sig_alg_is_supported
2623
2624
MBEDTLS_CHECK_RETURN_CRITICAL
2625
int mbedtls_ssl_tls13_check_sig_alg_cert_key_match(uint16_t sig_alg,
2626
                                                   mbedtls_pk_context *key);
2627
#endif /* MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED */
2628
2629
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
2630
static inline int mbedtls_ssl_sig_alg_is_offered(const mbedtls_ssl_context *ssl,
2631
                                                 uint16_t proposed_sig_alg)
2632
11.4k
{
2633
11.4k
    const uint16_t *sig_alg = mbedtls_ssl_get_sig_algs(ssl);
2634
11.4k
    if (sig_alg == NULL) {
2635
0
        return 0;
2636
0
    }
2637
2638
77.0k
    for (; *sig_alg != MBEDTLS_TLS_SIG_NONE; sig_alg++) {
2639
73.5k
        if (*sig_alg == proposed_sig_alg) {
2640
7.96k
            return 1;
2641
7.96k
        }
2642
73.5k
    }
2643
3.51k
    return 0;
2644
11.4k
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_sig_alg_is_offered
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_sig_alg_is_offered
ssl_tls.c:mbedtls_ssl_sig_alg_is_offered
Line
Count
Source
2632
11.1k
{
2633
11.1k
    const uint16_t *sig_alg = mbedtls_ssl_get_sig_algs(ssl);
2634
11.1k
    if (sig_alg == NULL) {
2635
0
        return 0;
2636
0
    }
2637
2638
75.6k
    for (; *sig_alg != MBEDTLS_TLS_SIG_NONE; sig_alg++) {
2639
72.1k
        if (*sig_alg == proposed_sig_alg) {
2640
7.61k
            return 1;
2641
7.61k
        }
2642
72.1k
    }
2643
3.50k
    return 0;
2644
11.1k
}
ssl_tls12_client.c:mbedtls_ssl_sig_alg_is_offered
Line
Count
Source
2632
356
{
2633
356
    const uint16_t *sig_alg = mbedtls_ssl_get_sig_algs(ssl);
2634
356
    if (sig_alg == NULL) {
2635
0
        return 0;
2636
0
    }
2637
2638
1.39k
    for (; *sig_alg != MBEDTLS_TLS_SIG_NONE; sig_alg++) {
2639
1.38k
        if (*sig_alg == proposed_sig_alg) {
2640
349
            return 1;
2641
349
        }
2642
1.38k
    }
2643
7
    return 0;
2644
356
}
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_sig_alg_is_offered
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_sig_alg_is_offered
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_sig_alg_is_offered
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_sig_alg_is_offered
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_sig_alg_is_offered
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_sig_alg_is_offered
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_sig_alg_is_offered
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_sig_alg_is_offered
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_sig_alg_is_offered
2645
2646
static inline int mbedtls_ssl_get_pk_type_and_md_alg_from_sig_alg(
2647
    uint16_t sig_alg, mbedtls_pk_type_t *pk_type, mbedtls_md_type_t *md_alg)
2648
600
{
2649
600
    *pk_type = mbedtls_ssl_pk_alg_from_sig(sig_alg & 0xff);
2650
600
    *md_alg = mbedtls_ssl_md_alg_from_hash((sig_alg >> 8) & 0xff);
2651
2652
600
    if (*pk_type != MBEDTLS_PK_NONE && *md_alg != MBEDTLS_MD_NONE) {
2653
308
        return 0;
2654
308
    }
2655
2656
292
    switch (sig_alg) {
2657
0
#if defined(MBEDTLS_PKCS1_V21)
2658
0
#if defined(MBEDTLS_MD_CAN_SHA256)
2659
21
        case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA256:
2660
21
            *md_alg = MBEDTLS_MD_SHA256;
2661
21
            *pk_type = MBEDTLS_PK_RSASSA_PSS;
2662
21
            break;
2663
0
#endif /* MBEDTLS_MD_CAN_SHA256  */
2664
0
#if defined(MBEDTLS_MD_CAN_SHA384)
2665
19
        case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA384:
2666
19
            *md_alg = MBEDTLS_MD_SHA384;
2667
19
            *pk_type = MBEDTLS_PK_RSASSA_PSS;
2668
19
            break;
2669
0
#endif /* MBEDTLS_MD_CAN_SHA384 */
2670
0
#if defined(MBEDTLS_MD_CAN_SHA512)
2671
8
        case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA512:
2672
8
            *md_alg = MBEDTLS_MD_SHA512;
2673
8
            *pk_type = MBEDTLS_PK_RSASSA_PSS;
2674
8
            break;
2675
0
#endif /* MBEDTLS_MD_CAN_SHA512 */
2676
0
#endif /* MBEDTLS_PKCS1_V21 */
2677
244
        default:
2678
244
            return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE;
2679
292
    }
2680
48
    return 0;
2681
292
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_get_pk_type_and_md_alg_from_sig_alg
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_get_pk_type_and_md_alg_from_sig_alg
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_get_pk_type_and_md_alg_from_sig_alg
ssl_tls12_client.c:mbedtls_ssl_get_pk_type_and_md_alg_from_sig_alg
Line
Count
Source
2648
600
{
2649
600
    *pk_type = mbedtls_ssl_pk_alg_from_sig(sig_alg & 0xff);
2650
600
    *md_alg = mbedtls_ssl_md_alg_from_hash((sig_alg >> 8) & 0xff);
2651
2652
600
    if (*pk_type != MBEDTLS_PK_NONE && *md_alg != MBEDTLS_MD_NONE) {
2653
308
        return 0;
2654
308
    }
2655
2656
292
    switch (sig_alg) {
2657
0
#if defined(MBEDTLS_PKCS1_V21)
2658
0
#if defined(MBEDTLS_MD_CAN_SHA256)
2659
21
        case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA256:
2660
21
            *md_alg = MBEDTLS_MD_SHA256;
2661
21
            *pk_type = MBEDTLS_PK_RSASSA_PSS;
2662
21
            break;
2663
0
#endif /* MBEDTLS_MD_CAN_SHA256  */
2664
0
#if defined(MBEDTLS_MD_CAN_SHA384)
2665
19
        case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA384:
2666
19
            *md_alg = MBEDTLS_MD_SHA384;
2667
19
            *pk_type = MBEDTLS_PK_RSASSA_PSS;
2668
19
            break;
2669
0
#endif /* MBEDTLS_MD_CAN_SHA384 */
2670
0
#if defined(MBEDTLS_MD_CAN_SHA512)
2671
8
        case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA512:
2672
8
            *md_alg = MBEDTLS_MD_SHA512;
2673
8
            *pk_type = MBEDTLS_PK_RSASSA_PSS;
2674
8
            break;
2675
0
#endif /* MBEDTLS_MD_CAN_SHA512 */
2676
0
#endif /* MBEDTLS_PKCS1_V21 */
2677
244
        default:
2678
244
            return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE;
2679
292
    }
2680
48
    return 0;
2681
292
}
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_get_pk_type_and_md_alg_from_sig_alg
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_get_pk_type_and_md_alg_from_sig_alg
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_get_pk_type_and_md_alg_from_sig_alg
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_get_pk_type_and_md_alg_from_sig_alg
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_get_pk_type_and_md_alg_from_sig_alg
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_get_pk_type_and_md_alg_from_sig_alg
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_get_pk_type_and_md_alg_from_sig_alg
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_get_pk_type_and_md_alg_from_sig_alg
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_get_pk_type_and_md_alg_from_sig_alg
2682
2683
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
2684
static inline int mbedtls_ssl_tls12_sig_alg_is_supported(
2685
    const uint16_t sig_alg)
2686
138k
{
2687
    /* High byte is hash */
2688
138k
    unsigned char hash = MBEDTLS_BYTE_1(sig_alg);
2689
138k
    unsigned char sig = MBEDTLS_BYTE_0(sig_alg);
2690
2691
138k
    switch (hash) {
2692
0
#if defined(MBEDTLS_MD_CAN_MD5)
2693
4.01k
        case MBEDTLS_SSL_HASH_MD5:
2694
4.01k
            break;
2695
0
#endif
2696
2697
0
#if defined(MBEDTLS_MD_CAN_SHA1)
2698
4.01k
        case MBEDTLS_SSL_HASH_SHA1:
2699
4.01k
            break;
2700
0
#endif
2701
2702
0
#if defined(MBEDTLS_MD_CAN_SHA224)
2703
3.89k
        case MBEDTLS_SSL_HASH_SHA224:
2704
3.89k
            break;
2705
0
#endif
2706
2707
0
#if defined(MBEDTLS_MD_CAN_SHA256)
2708
17.1k
        case MBEDTLS_SSL_HASH_SHA256:
2709
17.1k
            break;
2710
0
#endif
2711
2712
0
#if defined(MBEDTLS_MD_CAN_SHA384)
2713
14.8k
        case MBEDTLS_SSL_HASH_SHA384:
2714
14.8k
            break;
2715
0
#endif
2716
2717
0
#if defined(MBEDTLS_MD_CAN_SHA512)
2718
16.1k
        case MBEDTLS_SSL_HASH_SHA512:
2719
16.1k
            break;
2720
0
#endif
2721
2722
78.8k
        default:
2723
78.8k
            return 0;
2724
138k
    }
2725
2726
60.0k
    switch (sig) {
2727
0
#if defined(MBEDTLS_RSA_C)
2728
23.0k
        case MBEDTLS_SSL_SIG_RSA:
2729
23.0k
            break;
2730
0
#endif
2731
2732
0
#if defined(MBEDTLS_KEY_EXCHANGE_ECDSA_CERT_REQ_ALLOWED_ENABLED)
2733
23.0k
        case MBEDTLS_SSL_SIG_ECDSA:
2734
23.0k
            break;
2735
0
#endif
2736
2737
13.9k
        default:
2738
13.9k
            return 0;
2739
60.0k
    }
2740
2741
46.1k
    return 1;
2742
60.0k
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls12_sig_alg_is_supported
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls12_sig_alg_is_supported
ssl_tls.c:mbedtls_ssl_tls12_sig_alg_is_supported
Line
Count
Source
2686
138k
{
2687
    /* High byte is hash */
2688
138k
    unsigned char hash = MBEDTLS_BYTE_1(sig_alg);
2689
138k
    unsigned char sig = MBEDTLS_BYTE_0(sig_alg);
2690
2691
138k
    switch (hash) {
2692
0
#if defined(MBEDTLS_MD_CAN_MD5)
2693
4.01k
        case MBEDTLS_SSL_HASH_MD5:
2694
4.01k
            break;
2695
0
#endif
2696
2697
0
#if defined(MBEDTLS_MD_CAN_SHA1)
2698
4.01k
        case MBEDTLS_SSL_HASH_SHA1:
2699
4.01k
            break;
2700
0
#endif
2701
2702
0
#if defined(MBEDTLS_MD_CAN_SHA224)
2703
3.89k
        case MBEDTLS_SSL_HASH_SHA224:
2704
3.89k
            break;
2705
0
#endif
2706
2707
0
#if defined(MBEDTLS_MD_CAN_SHA256)
2708
17.1k
        case MBEDTLS_SSL_HASH_SHA256:
2709
17.1k
            break;
2710
0
#endif
2711
2712
0
#if defined(MBEDTLS_MD_CAN_SHA384)
2713
14.7k
        case MBEDTLS_SSL_HASH_SHA384:
2714
14.7k
            break;
2715
0
#endif
2716
2717
0
#if defined(MBEDTLS_MD_CAN_SHA512)
2718
16.0k
        case MBEDTLS_SSL_HASH_SHA512:
2719
16.0k
            break;
2720
0
#endif
2721
2722
78.7k
        default:
2723
78.7k
            return 0;
2724
138k
    }
2725
2726
59.7k
    switch (sig) {
2727
0
#if defined(MBEDTLS_RSA_C)
2728
23.0k
        case MBEDTLS_SSL_SIG_RSA:
2729
23.0k
            break;
2730
0
#endif
2731
2732
0
#if defined(MBEDTLS_KEY_EXCHANGE_ECDSA_CERT_REQ_ALLOWED_ENABLED)
2733
22.7k
        case MBEDTLS_SSL_SIG_ECDSA:
2734
22.7k
            break;
2735
0
#endif
2736
2737
13.9k
        default:
2738
13.9k
            return 0;
2739
59.7k
    }
2740
2741
45.8k
    return 1;
2742
59.7k
}
ssl_tls12_client.c:mbedtls_ssl_tls12_sig_alg_is_supported
Line
Count
Source
2686
356
{
2687
    /* High byte is hash */
2688
356
    unsigned char hash = MBEDTLS_BYTE_1(sig_alg);
2689
356
    unsigned char sig = MBEDTLS_BYTE_0(sig_alg);
2690
2691
356
    switch (hash) {
2692
0
#if defined(MBEDTLS_MD_CAN_MD5)
2693
3
        case MBEDTLS_SSL_HASH_MD5:
2694
3
            break;
2695
0
#endif
2696
2697
0
#if defined(MBEDTLS_MD_CAN_SHA1)
2698
3
        case MBEDTLS_SSL_HASH_SHA1:
2699
3
            break;
2700
0
#endif
2701
2702
0
#if defined(MBEDTLS_MD_CAN_SHA224)
2703
1
        case MBEDTLS_SSL_HASH_SHA224:
2704
1
            break;
2705
0
#endif
2706
2707
0
#if defined(MBEDTLS_MD_CAN_SHA256)
2708
66
        case MBEDTLS_SSL_HASH_SHA256:
2709
66
            break;
2710
0
#endif
2711
2712
0
#if defined(MBEDTLS_MD_CAN_SHA384)
2713
104
        case MBEDTLS_SSL_HASH_SHA384:
2714
104
            break;
2715
0
#endif
2716
2717
0
#if defined(MBEDTLS_MD_CAN_SHA512)
2718
131
        case MBEDTLS_SSL_HASH_SHA512:
2719
131
            break;
2720
0
#endif
2721
2722
48
        default:
2723
48
            return 0;
2724
356
    }
2725
2726
308
    switch (sig) {
2727
0
#if defined(MBEDTLS_RSA_C)
2728
24
        case MBEDTLS_SSL_SIG_RSA:
2729
24
            break;
2730
0
#endif
2731
2732
0
#if defined(MBEDTLS_KEY_EXCHANGE_ECDSA_CERT_REQ_ALLOWED_ENABLED)
2733
284
        case MBEDTLS_SSL_SIG_ECDSA:
2734
284
            break;
2735
0
#endif
2736
2737
0
        default:
2738
0
            return 0;
2739
308
    }
2740
2741
308
    return 1;
2742
308
}
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls12_sig_alg_is_supported
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls12_sig_alg_is_supported
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls12_sig_alg_is_supported
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls12_sig_alg_is_supported
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls12_sig_alg_is_supported
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls12_sig_alg_is_supported
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_tls12_sig_alg_is_supported
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls12_sig_alg_is_supported
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls12_sig_alg_is_supported
2743
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
2744
2745
static inline int mbedtls_ssl_sig_alg_is_supported(
2746
    const mbedtls_ssl_context *ssl,
2747
    const uint16_t sig_alg)
2748
138k
{
2749
2750
138k
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
2751
138k
    if (ssl->tls_version == MBEDTLS_SSL_VERSION_TLS1_2) {
2752
138k
        return mbedtls_ssl_tls12_sig_alg_is_supported(sig_alg);
2753
138k
    }
2754
0
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
2755
2756
0
#if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED)
2757
0
    if (ssl->tls_version == MBEDTLS_SSL_VERSION_TLS1_3) {
2758
0
        return mbedtls_ssl_tls13_sig_alg_is_supported(sig_alg);
2759
0
    }
2760
0
#endif
2761
0
    ((void) ssl);
2762
0
    ((void) sig_alg);
2763
0
    return 0;
2764
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_sig_alg_is_supported
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_sig_alg_is_supported
ssl_tls.c:mbedtls_ssl_sig_alg_is_supported
Line
Count
Source
2748
138k
{
2749
2750
138k
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
2751
138k
    if (ssl->tls_version == MBEDTLS_SSL_VERSION_TLS1_2) {
2752
138k
        return mbedtls_ssl_tls12_sig_alg_is_supported(sig_alg);
2753
138k
    }
2754
0
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
2755
2756
0
#if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED)
2757
0
    if (ssl->tls_version == MBEDTLS_SSL_VERSION_TLS1_3) {
2758
0
        return mbedtls_ssl_tls13_sig_alg_is_supported(sig_alg);
2759
0
    }
2760
0
#endif
2761
0
    ((void) ssl);
2762
0
    ((void) sig_alg);
2763
0
    return 0;
2764
0
}
ssl_tls12_client.c:mbedtls_ssl_sig_alg_is_supported
Line
Count
Source
2748
356
{
2749
2750
356
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
2751
356
    if (ssl->tls_version == MBEDTLS_SSL_VERSION_TLS1_2) {
2752
356
        return mbedtls_ssl_tls12_sig_alg_is_supported(sig_alg);
2753
356
    }
2754
0
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
2755
2756
0
#if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED)
2757
0
    if (ssl->tls_version == MBEDTLS_SSL_VERSION_TLS1_3) {
2758
0
        return mbedtls_ssl_tls13_sig_alg_is_supported(sig_alg);
2759
0
    }
2760
0
#endif
2761
0
    ((void) ssl);
2762
0
    ((void) sig_alg);
2763
0
    return 0;
2764
0
}
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_sig_alg_is_supported
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_sig_alg_is_supported
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_sig_alg_is_supported
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_sig_alg_is_supported
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_sig_alg_is_supported
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_sig_alg_is_supported
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_sig_alg_is_supported
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_sig_alg_is_supported
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_sig_alg_is_supported
2765
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
2766
2767
#if defined(MBEDTLS_USE_PSA_CRYPTO) || defined(MBEDTLS_SSL_PROTO_TLS1_3)
2768
/* Corresponding PSA algorithm for MBEDTLS_CIPHER_NULL.
2769
 * Same value is used for PSA_ALG_CATEGORY_CIPHER, hence it is
2770
 * guaranteed to not be a valid PSA algorithm identifier.
2771
 */
2772
0
#define MBEDTLS_SSL_NULL_CIPHER 0x04000000
2773
2774
/**
2775
 * \brief       Translate mbedtls cipher type/taglen pair to psa:
2776
 *              algorithm, key type and key size.
2777
 *
2778
 * \param  mbedtls_cipher_type [in] given mbedtls cipher type
2779
 * \param  taglen              [in] given tag length
2780
 *                                  0 - default tag length
2781
 * \param  alg                 [out] corresponding PSA alg
2782
 *                                   There is no corresponding PSA
2783
 *                                   alg for MBEDTLS_CIPHER_NULL, so
2784
 *                                   in this case MBEDTLS_SSL_NULL_CIPHER
2785
 *                                   is returned via this parameter
2786
 * \param  key_type            [out] corresponding PSA key type
2787
 * \param  key_size            [out] corresponding PSA key size
2788
 *
2789
 * \return                     PSA_SUCCESS on success or PSA_ERROR_NOT_SUPPORTED if
2790
 *                             conversion is not supported.
2791
 */
2792
psa_status_t mbedtls_ssl_cipher_to_psa(mbedtls_cipher_type_t mbedtls_cipher_type,
2793
                                       size_t taglen,
2794
                                       psa_algorithm_t *alg,
2795
                                       psa_key_type_t *key_type,
2796
                                       size_t *key_size);
2797
2798
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
2799
/**
2800
 * \brief       Convert given PSA status to mbedtls error code.
2801
 *
2802
 * \param  status      [in] given PSA status
2803
 *
2804
 * \return             corresponding mbedtls error code
2805
 */
2806
static inline MBEDTLS_DEPRECATED int psa_ssl_status_to_mbedtls(psa_status_t status)
2807
0
{
2808
0
    switch (status) {
2809
0
        case PSA_SUCCESS:
2810
0
            return 0;
2811
0
        case PSA_ERROR_INSUFFICIENT_MEMORY:
2812
0
            return MBEDTLS_ERR_SSL_ALLOC_FAILED;
2813
0
        case PSA_ERROR_NOT_SUPPORTED:
2814
0
            return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE;
2815
0
        case PSA_ERROR_INVALID_SIGNATURE:
2816
0
            return MBEDTLS_ERR_SSL_INVALID_MAC;
2817
0
        case PSA_ERROR_INVALID_ARGUMENT:
2818
0
            return MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
2819
0
        case PSA_ERROR_BAD_STATE:
2820
0
            return MBEDTLS_ERR_SSL_INTERNAL_ERROR;
2821
0
        case PSA_ERROR_BUFFER_TOO_SMALL:
2822
0
            return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL;
2823
0
        default:
2824
0
            return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
2825
0
    }
2826
0
}
Unexecuted instantiation: ssl_msg.c:psa_ssl_status_to_mbedtls
Unexecuted instantiation: ssl_ticket.c:psa_ssl_status_to_mbedtls
Unexecuted instantiation: ssl_tls.c:psa_ssl_status_to_mbedtls
Unexecuted instantiation: ssl_tls12_client.c:psa_ssl_status_to_mbedtls
Unexecuted instantiation: ssl_tls12_server.c:psa_ssl_status_to_mbedtls
Unexecuted instantiation: ssl_tls13_keys.c:psa_ssl_status_to_mbedtls
Unexecuted instantiation: ssl_tls13_server.c:psa_ssl_status_to_mbedtls
Unexecuted instantiation: ssl_tls13_client.c:psa_ssl_status_to_mbedtls
Unexecuted instantiation: ssl_tls13_generic.c:psa_ssl_status_to_mbedtls
Unexecuted instantiation: ssl_ciphersuites.c:psa_ssl_status_to_mbedtls
Unexecuted instantiation: ssl_client.c:psa_ssl_status_to_mbedtls
Unexecuted instantiation: ssl_debug_helpers_generated.c:psa_ssl_status_to_mbedtls
Unexecuted instantiation: ssl_cookie.c:psa_ssl_status_to_mbedtls
2827
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
2828
#endif /* MBEDTLS_USE_PSA_CRYPTO || MBEDTLS_SSL_PROTO_TLS1_3 */
2829
2830
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) && \
2831
    defined(MBEDTLS_USE_PSA_CRYPTO)
2832
2833
typedef enum {
2834
    MBEDTLS_ECJPAKE_ROUND_ONE,
2835
    MBEDTLS_ECJPAKE_ROUND_TWO
2836
} mbedtls_ecjpake_rounds_t;
2837
2838
/**
2839
 * \brief       Parse the provided input buffer for getting the first round
2840
 *              of key exchange. This code is common between server and client
2841
 *
2842
 * \param  pake_ctx [in] the PAKE's operation/context structure
2843
 * \param  buf      [in] input buffer to parse
2844
 * \param  len      [in] length of the input buffer
2845
 * \param  round    [in] either MBEDTLS_ECJPAKE_ROUND_ONE or
2846
 *                       MBEDTLS_ECJPAKE_ROUND_TWO
2847
 *
2848
 * \return               0 on success or a negative error code in case of failure
2849
 */
2850
int mbedtls_psa_ecjpake_read_round(
2851
    psa_pake_operation_t *pake_ctx,
2852
    const unsigned char *buf,
2853
    size_t len, mbedtls_ecjpake_rounds_t round);
2854
2855
/**
2856
 * \brief       Write the first round of key exchange into the provided output
2857
 *              buffer. This code is common between server and client
2858
 *
2859
 * \param  pake_ctx [in] the PAKE's operation/context structure
2860
 * \param  buf      [out] the output buffer in which data will be written to
2861
 * \param  len      [in] length of the output buffer
2862
 * \param  olen     [out] the length of the data really written on the buffer
2863
 * \param  round    [in] either MBEDTLS_ECJPAKE_ROUND_ONE or
2864
 *                       MBEDTLS_ECJPAKE_ROUND_TWO
2865
 *
2866
 * \return               0 on success or a negative error code in case of failure
2867
 */
2868
int mbedtls_psa_ecjpake_write_round(
2869
    psa_pake_operation_t *pake_ctx,
2870
    unsigned char *buf,
2871
    size_t len, size_t *olen,
2872
    mbedtls_ecjpake_rounds_t round);
2873
2874
#endif //MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED && MBEDTLS_USE_PSA_CRYPTO
2875
2876
/**
2877
 * \brief       TLS record protection modes
2878
 */
2879
typedef enum {
2880
    MBEDTLS_SSL_MODE_STREAM = 0,
2881
    MBEDTLS_SSL_MODE_CBC,
2882
    MBEDTLS_SSL_MODE_CBC_ETM,
2883
    MBEDTLS_SSL_MODE_AEAD
2884
} mbedtls_ssl_mode_t;
2885
2886
mbedtls_ssl_mode_t mbedtls_ssl_get_mode_from_transform(
2887
    const mbedtls_ssl_transform *transform);
2888
2889
#if defined(MBEDTLS_SSL_SOME_SUITES_USE_CBC_ETM)
2890
mbedtls_ssl_mode_t mbedtls_ssl_get_mode_from_ciphersuite(
2891
    int encrypt_then_mac,
2892
    const mbedtls_ssl_ciphersuite_t *suite);
2893
#else
2894
mbedtls_ssl_mode_t mbedtls_ssl_get_mode_from_ciphersuite(
2895
    const mbedtls_ssl_ciphersuite_t *suite);
2896
#endif /* MBEDTLS_SSL_SOME_SUITES_USE_CBC_ETM */
2897
2898
#if defined(PSA_WANT_ALG_ECDH) || defined(PSA_WANT_ALG_FFDH)
2899
2900
MBEDTLS_CHECK_RETURN_CRITICAL
2901
int mbedtls_ssl_tls13_read_public_xxdhe_share(mbedtls_ssl_context *ssl,
2902
                                              const unsigned char *buf,
2903
                                              size_t buf_len);
2904
2905
#endif /* PSA_WANT_ALG_ECDH || PSA_WANT_ALG_FFDH */
2906
2907
static inline int mbedtls_ssl_tls13_cipher_suite_is_offered(
2908
    mbedtls_ssl_context *ssl, int cipher_suite)
2909
0
{
2910
0
    const int *ciphersuite_list = ssl->conf->ciphersuite_list;
2911
2912
    /* Check whether we have offered this ciphersuite */
2913
0
    for (size_t i = 0; ciphersuite_list[i] != 0; i++) {
2914
0
        if (ciphersuite_list[i] == cipher_suite) {
2915
0
            return 1;
2916
0
        }
2917
0
    }
2918
0
    return 0;
2919
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls13_cipher_suite_is_offered
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls13_cipher_suite_is_offered
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_tls13_cipher_suite_is_offered
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls13_cipher_suite_is_offered
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls13_cipher_suite_is_offered
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls13_cipher_suite_is_offered
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls13_cipher_suite_is_offered
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls13_cipher_suite_is_offered
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls13_cipher_suite_is_offered
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls13_cipher_suite_is_offered
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_tls13_cipher_suite_is_offered
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls13_cipher_suite_is_offered
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls13_cipher_suite_is_offered
2920
2921
/**
2922
 * \brief Validate cipher suite against config in SSL context.
2923
 *
2924
 * \param ssl              SSL context
2925
 * \param suite_info       Cipher suite to validate
2926
 * \param min_tls_version  Minimal TLS version to accept a cipher suite
2927
 * \param max_tls_version  Maximal TLS version to accept a cipher suite
2928
 *
2929
 * \return 0 if valid, negative value otherwise.
2930
 */
2931
MBEDTLS_CHECK_RETURN_CRITICAL
2932
int mbedtls_ssl_validate_ciphersuite(
2933
    const mbedtls_ssl_context *ssl,
2934
    const mbedtls_ssl_ciphersuite_t *suite_info,
2935
    mbedtls_ssl_protocol_version min_tls_version,
2936
    mbedtls_ssl_protocol_version max_tls_version);
2937
2938
#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
2939
MBEDTLS_CHECK_RETURN_CRITICAL
2940
int mbedtls_ssl_parse_server_name_ext(mbedtls_ssl_context *ssl,
2941
                                      const unsigned char *buf,
2942
                                      const unsigned char *end);
2943
#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
2944
2945
#if defined(MBEDTLS_SSL_RECORD_SIZE_LIMIT)
2946
0
#define MBEDTLS_SSL_RECORD_SIZE_LIMIT_EXTENSION_DATA_LENGTH (2)
2947
0
#define MBEDTLS_SSL_RECORD_SIZE_LIMIT_MIN (64)      /* As defined in RFC 8449 */
2948
2949
MBEDTLS_CHECK_RETURN_CRITICAL
2950
int mbedtls_ssl_tls13_parse_record_size_limit_ext(mbedtls_ssl_context *ssl,
2951
                                                  const unsigned char *buf,
2952
                                                  const unsigned char *end);
2953
2954
MBEDTLS_CHECK_RETURN_CRITICAL
2955
int mbedtls_ssl_tls13_write_record_size_limit_ext(mbedtls_ssl_context *ssl,
2956
                                                  unsigned char *buf,
2957
                                                  const unsigned char *end,
2958
                                                  size_t *out_len);
2959
#endif /* MBEDTLS_SSL_RECORD_SIZE_LIMIT */
2960
2961
#if defined(MBEDTLS_SSL_ALPN)
2962
MBEDTLS_CHECK_RETURN_CRITICAL
2963
int mbedtls_ssl_parse_alpn_ext(mbedtls_ssl_context *ssl,
2964
                               const unsigned char *buf,
2965
                               const unsigned char *end);
2966
2967
2968
MBEDTLS_CHECK_RETURN_CRITICAL
2969
int mbedtls_ssl_write_alpn_ext(mbedtls_ssl_context *ssl,
2970
                               unsigned char *buf,
2971
                               unsigned char *end,
2972
                               size_t *out_len);
2973
#endif /* MBEDTLS_SSL_ALPN */
2974
2975
#if defined(MBEDTLS_TEST_HOOKS)
2976
int mbedtls_ssl_check_dtls_clihlo_cookie(
2977
    mbedtls_ssl_context *ssl,
2978
    const unsigned char *cli_id, size_t cli_id_len,
2979
    const unsigned char *in, size_t in_len,
2980
    unsigned char *obuf, size_t buf_len, size_t *olen);
2981
#endif
2982
2983
#if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_PSK_ENABLED)
2984
/**
2985
 * \brief Given an SSL context and its associated configuration, write the TLS
2986
 *        1.3 specific Pre-Shared key extension.
2987
 *
2988
 * \param[in]   ssl     SSL context
2989
 * \param[in]   buf     Base address of the buffer where to write the extension
2990
 * \param[in]   end     End address of the buffer where to write the extension
2991
 * \param[out]  out_len Length in bytes of the Pre-Shared key extension: data
2992
 *                      written into the buffer \p buf by this function plus
2993
 *                      the length of the binders to be written.
2994
 * \param[out]  binders_len Length of the binders to be written at the end of
2995
 *                          the extension.
2996
 */
2997
MBEDTLS_CHECK_RETURN_CRITICAL
2998
int mbedtls_ssl_tls13_write_identities_of_pre_shared_key_ext(
2999
    mbedtls_ssl_context *ssl,
3000
    unsigned char *buf, unsigned char *end,
3001
    size_t *out_len, size_t *binders_len);
3002
3003
/**
3004
 * \brief Given an SSL context and its associated configuration, write the TLS
3005
 *        1.3 specific Pre-Shared key extension binders at the end of the
3006
 *        ClientHello.
3007
 *
3008
 * \param[in]   ssl     SSL context
3009
 * \param[in]   buf     Base address of the buffer where to write the binders
3010
 * \param[in]   end     End address of the buffer where to write the binders
3011
 */
3012
MBEDTLS_CHECK_RETURN_CRITICAL
3013
int mbedtls_ssl_tls13_write_binders_of_pre_shared_key_ext(
3014
    mbedtls_ssl_context *ssl,
3015
    unsigned char *buf, unsigned char *end);
3016
#endif /* MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_PSK_ENABLED */
3017
3018
#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
3019
/** Get the host name from the SSL context.
3020
 *
3021
 * \param[in]   ssl     SSL context
3022
 *
3023
 * \return The \p hostname pointer from the SSL context.
3024
 *         \c NULL if mbedtls_ssl_set_hostname() has never been called on
3025
 *         \p ssl or if it was last called with \p NULL.
3026
 */
3027
const char *mbedtls_ssl_get_hostname_pointer(const mbedtls_ssl_context *ssl);
3028
#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
3029
3030
#if defined(MBEDTLS_SSL_PROTO_TLS1_3) && \
3031
    defined(MBEDTLS_SSL_SESSION_TICKETS) && \
3032
    defined(MBEDTLS_SSL_SERVER_NAME_INDICATION) && \
3033
    defined(MBEDTLS_SSL_CLI_C)
3034
MBEDTLS_CHECK_RETURN_CRITICAL
3035
int mbedtls_ssl_session_set_hostname(mbedtls_ssl_session *session,
3036
                                     const char *hostname);
3037
#endif
3038
3039
#if defined(MBEDTLS_SSL_SRV_C) && defined(MBEDTLS_SSL_EARLY_DATA) && \
3040
    defined(MBEDTLS_SSL_ALPN)
3041
MBEDTLS_CHECK_RETURN_CRITICAL
3042
int mbedtls_ssl_session_set_ticket_alpn(mbedtls_ssl_session *session,
3043
                                        const char *alpn);
3044
#endif
3045
3046
#if defined(MBEDTLS_SSL_PROTO_TLS1_3) && defined(MBEDTLS_SSL_SESSION_TICKETS)
3047
3048
0
#define MBEDTLS_SSL_TLS1_3_MAX_ALLOWED_TICKET_LIFETIME (604800)
3049
3050
static inline unsigned int mbedtls_ssl_tls13_session_get_ticket_flags(
3051
    mbedtls_ssl_session *session, unsigned int flags)
3052
0
{
3053
0
    return session->ticket_flags &
3054
0
           (flags & MBEDTLS_SSL_TLS1_3_TICKET_FLAGS_MASK);
3055
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls13_session_get_ticket_flags
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls13_session_get_ticket_flags
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_tls13_session_get_ticket_flags
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls13_session_get_ticket_flags
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls13_session_get_ticket_flags
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls13_session_get_ticket_flags
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls13_session_get_ticket_flags
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls13_session_get_ticket_flags
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls13_session_get_ticket_flags
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls13_session_get_ticket_flags
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_tls13_session_get_ticket_flags
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls13_session_get_ticket_flags
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls13_session_get_ticket_flags
3056
3057
/**
3058
 * Check if at least one of the given flags is set in
3059
 * the session ticket. See the definition of
3060
 * `MBEDTLS_SSL_TLS1_3_TICKET_FLAGS_MASK` to get all
3061
 * permitted flags.
3062
 */
3063
static inline int mbedtls_ssl_tls13_session_ticket_has_flags(
3064
    mbedtls_ssl_session *session, unsigned int flags)
3065
0
{
3066
0
    return mbedtls_ssl_tls13_session_get_ticket_flags(session, flags) != 0;
3067
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls13_session_ticket_has_flags
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls13_session_ticket_has_flags
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_tls13_session_ticket_has_flags
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls13_session_ticket_has_flags
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls13_session_ticket_has_flags
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls13_session_ticket_has_flags
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls13_session_ticket_has_flags
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls13_session_ticket_has_flags
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls13_session_ticket_has_flags
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls13_session_ticket_has_flags
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_tls13_session_ticket_has_flags
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls13_session_ticket_has_flags
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls13_session_ticket_has_flags
3068
3069
static inline int mbedtls_ssl_tls13_session_ticket_allow_psk(
3070
    mbedtls_ssl_session *session)
3071
0
{
3072
0
    return mbedtls_ssl_tls13_session_ticket_has_flags(
3073
0
        session, MBEDTLS_SSL_TLS1_3_TICKET_ALLOW_PSK_RESUMPTION);
3074
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls13_session_ticket_allow_psk
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls13_session_ticket_allow_psk
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_tls13_session_ticket_allow_psk
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls13_session_ticket_allow_psk
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls13_session_ticket_allow_psk
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls13_session_ticket_allow_psk
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls13_session_ticket_allow_psk
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls13_session_ticket_allow_psk
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls13_session_ticket_allow_psk
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls13_session_ticket_allow_psk
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_tls13_session_ticket_allow_psk
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls13_session_ticket_allow_psk
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls13_session_ticket_allow_psk
3075
3076
static inline int mbedtls_ssl_tls13_session_ticket_allow_psk_ephemeral(
3077
    mbedtls_ssl_session *session)
3078
0
{
3079
0
    return mbedtls_ssl_tls13_session_ticket_has_flags(
3080
0
        session, MBEDTLS_SSL_TLS1_3_TICKET_ALLOW_PSK_EPHEMERAL_RESUMPTION);
3081
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls13_session_ticket_allow_psk_ephemeral
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls13_session_ticket_allow_psk_ephemeral
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_tls13_session_ticket_allow_psk_ephemeral
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls13_session_ticket_allow_psk_ephemeral
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls13_session_ticket_allow_psk_ephemeral
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls13_session_ticket_allow_psk_ephemeral
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls13_session_ticket_allow_psk_ephemeral
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls13_session_ticket_allow_psk_ephemeral
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls13_session_ticket_allow_psk_ephemeral
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls13_session_ticket_allow_psk_ephemeral
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_tls13_session_ticket_allow_psk_ephemeral
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls13_session_ticket_allow_psk_ephemeral
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls13_session_ticket_allow_psk_ephemeral
3082
3083
static inline unsigned int mbedtls_ssl_tls13_session_ticket_allow_early_data(
3084
    mbedtls_ssl_session *session)
3085
0
{
3086
0
    return mbedtls_ssl_tls13_session_ticket_has_flags(
3087
0
        session, MBEDTLS_SSL_TLS1_3_TICKET_ALLOW_EARLY_DATA);
3088
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls13_session_ticket_allow_early_data
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls13_session_ticket_allow_early_data
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_tls13_session_ticket_allow_early_data
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls13_session_ticket_allow_early_data
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls13_session_ticket_allow_early_data
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls13_session_ticket_allow_early_data
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls13_session_ticket_allow_early_data
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls13_session_ticket_allow_early_data
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls13_session_ticket_allow_early_data
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls13_session_ticket_allow_early_data
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_tls13_session_ticket_allow_early_data
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls13_session_ticket_allow_early_data
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls13_session_ticket_allow_early_data
3089
3090
static inline void mbedtls_ssl_tls13_session_set_ticket_flags(
3091
    mbedtls_ssl_session *session, unsigned int flags)
3092
0
{
3093
0
    session->ticket_flags |= (flags & MBEDTLS_SSL_TLS1_3_TICKET_FLAGS_MASK);
3094
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls13_session_set_ticket_flags
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls13_session_set_ticket_flags
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_tls13_session_set_ticket_flags
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls13_session_set_ticket_flags
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls13_session_set_ticket_flags
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls13_session_set_ticket_flags
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls13_session_set_ticket_flags
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls13_session_set_ticket_flags
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls13_session_set_ticket_flags
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls13_session_set_ticket_flags
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_tls13_session_set_ticket_flags
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls13_session_set_ticket_flags
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls13_session_set_ticket_flags
3095
3096
static inline void mbedtls_ssl_tls13_session_clear_ticket_flags(
3097
    mbedtls_ssl_session *session, unsigned int flags)
3098
0
{
3099
0
    session->ticket_flags &= ~(flags & MBEDTLS_SSL_TLS1_3_TICKET_FLAGS_MASK);
3100
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_tls13_session_clear_ticket_flags
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_tls13_session_clear_ticket_flags
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_tls13_session_clear_ticket_flags
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_tls13_session_clear_ticket_flags
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_tls13_session_clear_ticket_flags
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_tls13_session_clear_ticket_flags
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_tls13_session_clear_ticket_flags
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_tls13_session_clear_ticket_flags
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_tls13_session_clear_ticket_flags
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_tls13_session_clear_ticket_flags
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_tls13_session_clear_ticket_flags
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_tls13_session_clear_ticket_flags
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_tls13_session_clear_ticket_flags
3101
3102
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 && MBEDTLS_SSL_SESSION_TICKETS */
3103
3104
#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
3105
17.0k
#define MBEDTLS_SSL_SESSION_TICKETS_TLS1_2_BIT 0
3106
10.6k
#define MBEDTLS_SSL_SESSION_TICKETS_TLS1_3_BIT 1
3107
3108
#define MBEDTLS_SSL_SESSION_TICKETS_TLS1_2_MASK \
3109
11.6k
    (1 << MBEDTLS_SSL_SESSION_TICKETS_TLS1_2_BIT)
3110
#define MBEDTLS_SSL_SESSION_TICKETS_TLS1_3_MASK \
3111
5.33k
    (1 << MBEDTLS_SSL_SESSION_TICKETS_TLS1_3_BIT)
3112
3113
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
3114
static inline int mbedtls_ssl_conf_get_session_tickets(
3115
    const mbedtls_ssl_config *conf)
3116
6.33k
{
3117
6.33k
    return conf->session_tickets & MBEDTLS_SSL_SESSION_TICKETS_TLS1_2_MASK ?
3118
6.33k
           MBEDTLS_SSL_SESSION_TICKETS_ENABLED :
3119
6.33k
           MBEDTLS_SSL_SESSION_TICKETS_DISABLED;
3120
6.33k
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_conf_get_session_tickets
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_conf_get_session_tickets
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_conf_get_session_tickets
ssl_tls12_client.c:mbedtls_ssl_conf_get_session_tickets
Line
Count
Source
3116
6.33k
{
3117
6.33k
    return conf->session_tickets & MBEDTLS_SSL_SESSION_TICKETS_TLS1_2_MASK ?
3118
6.33k
           MBEDTLS_SSL_SESSION_TICKETS_ENABLED :
3119
6.33k
           MBEDTLS_SSL_SESSION_TICKETS_DISABLED;
3120
6.33k
}
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_conf_get_session_tickets
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_conf_get_session_tickets
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_conf_get_session_tickets
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_conf_get_session_tickets
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_conf_get_session_tickets
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_conf_get_session_tickets
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_conf_get_session_tickets
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_conf_get_session_tickets
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_conf_get_session_tickets
3121
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
3122
3123
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
3124
static inline int mbedtls_ssl_conf_is_signal_new_session_tickets_enabled(
3125
    const mbedtls_ssl_config *conf)
3126
0
{
3127
0
    return conf->session_tickets & MBEDTLS_SSL_SESSION_TICKETS_TLS1_3_MASK ?
3128
0
           MBEDTLS_SSL_TLS1_3_SIGNAL_NEW_SESSION_TICKETS_ENABLED :
3129
0
           MBEDTLS_SSL_TLS1_3_SIGNAL_NEW_SESSION_TICKETS_DISABLED;
3130
0
}
Unexecuted instantiation: ssl_msg.c:mbedtls_ssl_conf_is_signal_new_session_tickets_enabled
Unexecuted instantiation: ssl_ticket.c:mbedtls_ssl_conf_is_signal_new_session_tickets_enabled
Unexecuted instantiation: ssl_tls.c:mbedtls_ssl_conf_is_signal_new_session_tickets_enabled
Unexecuted instantiation: ssl_tls12_client.c:mbedtls_ssl_conf_is_signal_new_session_tickets_enabled
Unexecuted instantiation: ssl_tls12_server.c:mbedtls_ssl_conf_is_signal_new_session_tickets_enabled
Unexecuted instantiation: ssl_tls13_keys.c:mbedtls_ssl_conf_is_signal_new_session_tickets_enabled
Unexecuted instantiation: ssl_tls13_server.c:mbedtls_ssl_conf_is_signal_new_session_tickets_enabled
Unexecuted instantiation: ssl_tls13_client.c:mbedtls_ssl_conf_is_signal_new_session_tickets_enabled
Unexecuted instantiation: ssl_tls13_generic.c:mbedtls_ssl_conf_is_signal_new_session_tickets_enabled
Unexecuted instantiation: ssl_ciphersuites.c:mbedtls_ssl_conf_is_signal_new_session_tickets_enabled
Unexecuted instantiation: ssl_client.c:mbedtls_ssl_conf_is_signal_new_session_tickets_enabled
Unexecuted instantiation: ssl_debug_helpers_generated.c:mbedtls_ssl_conf_is_signal_new_session_tickets_enabled
Unexecuted instantiation: ssl_cookie.c:mbedtls_ssl_conf_is_signal_new_session_tickets_enabled
3131
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
3132
#endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
3133
3134
#if defined(MBEDTLS_SSL_CLI_C) && defined(MBEDTLS_SSL_PROTO_TLS1_3)
3135
int mbedtls_ssl_tls13_finalize_client_hello(mbedtls_ssl_context *ssl);
3136
#endif
3137
3138
#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_SSL_SOME_SUITES_USE_MAC)
3139
3140
/** Compute the HMAC of variable-length data with constant flow.
3141
 *
3142
 * This function computes the HMAC of the concatenation of \p add_data and \p
3143
 * data, and does with a code flow and memory access pattern that does not
3144
 * depend on \p data_len_secret, but only on \p min_data_len and \p
3145
 * max_data_len. In particular, this function always reads exactly \p
3146
 * max_data_len bytes from \p data.
3147
 *
3148
 * \param ctx               The HMAC context. It must have keys configured
3149
 *                          with mbedtls_md_hmac_starts() and use one of the
3150
 *                          following hashes: SHA-384, SHA-256, SHA-1 or MD-5.
3151
 *                          It is reset using mbedtls_md_hmac_reset() after
3152
 *                          the computation is complete to prepare for the
3153
 *                          next computation.
3154
 * \param add_data          The first part of the message whose HMAC is being
3155
 *                          calculated. This must point to a readable buffer
3156
 *                          of \p add_data_len bytes.
3157
 * \param add_data_len      The length of \p add_data in bytes.
3158
 * \param data              The buffer containing the second part of the
3159
 *                          message. This must point to a readable buffer
3160
 *                          of \p max_data_len bytes.
3161
 * \param data_len_secret   The length of the data to process in \p data.
3162
 *                          This must be no less than \p min_data_len and no
3163
 *                          greater than \p max_data_len.
3164
 * \param min_data_len      The minimal length of the second part of the
3165
 *                          message, read from \p data.
3166
 * \param max_data_len      The maximal length of the second part of the
3167
 *                          message, read from \p data.
3168
 * \param output            The HMAC will be written here. This must point to
3169
 *                          a writable buffer of sufficient size to hold the
3170
 *                          HMAC value.
3171
 *
3172
 * \retval 0 on success.
3173
 * \retval #MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED
3174
 *         The hardware accelerator failed.
3175
 */
3176
#if defined(MBEDTLS_USE_PSA_CRYPTO)
3177
int mbedtls_ct_hmac(mbedtls_svc_key_id_t key,
3178
                    psa_algorithm_t mac_alg,
3179
                    const unsigned char *add_data,
3180
                    size_t add_data_len,
3181
                    const unsigned char *data,
3182
                    size_t data_len_secret,
3183
                    size_t min_data_len,
3184
                    size_t max_data_len,
3185
                    unsigned char *output);
3186
#else
3187
int mbedtls_ct_hmac(mbedtls_md_context_t *ctx,
3188
                    const unsigned char *add_data,
3189
                    size_t add_data_len,
3190
                    const unsigned char *data,
3191
                    size_t data_len_secret,
3192
                    size_t min_data_len,
3193
                    size_t max_data_len,
3194
                    unsigned char *output);
3195
#endif /* defined(MBEDTLS_USE_PSA_CRYPTO) */
3196
#endif /* MBEDTLS_TEST_HOOKS && defined(MBEDTLS_SSL_SOME_SUITES_USE_MAC) */
3197
3198
#endif /* ssl_misc.h */