blob: 1b55abab6d27eee72e57e81612cbdfb81228d2aa [file] [log] [blame]
Jerry Yu3cc4c2a2021-08-06 16:29:08 +08001/*
2 * TLS 1.3 client-side functions
3 *
4 * Copyright The Mbed TLS Contributors
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * This file is part of mbed TLS ( https://tls.mbed.org )
20 */
21
22#include "common.h"
23
24#if defined(MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL)
25
26#if defined(MBEDTLS_SSL_CLI_C)
27
Jerry Yubc20bdd2021-08-24 15:59:48 +080028#include <string.h>
29
Jerry Yu3cc4c2a2021-08-06 16:29:08 +080030#include "ssl_misc.h"
Jerry Yu56fc07f2021-09-01 17:48:49 +080031#include "mbedtls/debug.h"
32#include "mbedtls/error.h"
Jerry Yua13c7e72021-08-17 10:44:40 +080033
Jerry Yu08906d02021-08-31 11:05:27 +080034#define CLIENT_HELLO_RANDOM_LEN 32
Jerry Yu65dd2cc2021-08-18 16:38:40 +080035
Jerry Yubc20bdd2021-08-24 15:59:48 +080036/* Write extensions */
37
Jerry Yu92c6b402021-08-27 16:59:09 +080038/*
39 * ssl_tls13_write_supported_versions_ext():
40 *
41 * struct {
42 * ProtocolVersion versions<2..254>;
43 * } SupportedVersions;
44 */
Jerry Yuf4436812021-08-26 22:59:56 +080045static int ssl_tls13_write_supported_versions_ext( mbedtls_ssl_context *ssl,
Jerry Yueecfbf02021-08-30 18:32:07 +080046 unsigned char *buf,
47 unsigned char *end,
48 size_t *olen )
Jerry Yu92c6b402021-08-27 16:59:09 +080049{
50 unsigned char *p = buf;
51
52 *olen = 0;
53
Jerry Yu159c5a02021-08-31 12:51:25 +080054 MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, adding supported versions extension" ) );
Jerry Yu92c6b402021-08-27 16:59:09 +080055
Jerry Yub60e3cf2021-09-08 16:41:02 +080056 /* Check if we have space for header and length fields:
57 * - extension_type (2 bytes)
58 * - extension_data_length (2 bytes)
59 * - versions_length (1 byte )
60 * - versions (2 bytes)
Jerry Yu159c5a02021-08-31 12:51:25 +080061 */
Jerry Yu92c6b402021-08-27 16:59:09 +080062 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 7 );
63
Jerry Yu1bc2c1f2021-09-01 12:57:29 +080064 /* Write extension_type */
Jerry Yueecfbf02021-08-30 18:32:07 +080065 MBEDTLS_PUT_UINT16_BE( MBEDTLS_TLS_EXT_SUPPORTED_VERSIONS, p, 0 );
Jerry Yu92c6b402021-08-27 16:59:09 +080066
Jerry Yu1bc2c1f2021-09-01 12:57:29 +080067 /* Write extension_data_length */
Jerry Yub7ab3362021-08-31 16:16:19 +080068 MBEDTLS_PUT_UINT16_BE( 3, p, 2 );
Jerry Yueecfbf02021-08-30 18:32:07 +080069 p += 4;
Jerry Yu92c6b402021-08-27 16:59:09 +080070
Jerry Yu1bc2c1f2021-09-01 12:57:29 +080071 /* Length of versions */
Jerry Yu92c6b402021-08-27 16:59:09 +080072 *p++ = 0x2;
73
Jerry Yu0c63af62021-09-02 12:59:12 +080074 /* Write values of supported versions.
Jerry Yu1bc2c1f2021-09-01 12:57:29 +080075 *
Jerry Yu0c63af62021-09-02 12:59:12 +080076 * They are defined by the configuration.
Jerry Yu1bc2c1f2021-09-01 12:57:29 +080077 *
Jerry Yu0c63af62021-09-02 12:59:12 +080078 * Currently, only one version is advertised.
Jerry Yu92c6b402021-08-27 16:59:09 +080079 */
Jerry Yueecfbf02021-08-30 18:32:07 +080080 mbedtls_ssl_write_version( ssl->conf->max_major_ver,
81 ssl->conf->max_minor_ver,
82 ssl->conf->transport, p );
Jerry Yu92c6b402021-08-27 16:59:09 +080083
84 MBEDTLS_SSL_DEBUG_MSG( 3, ( "supported version: [%d:%d]",
Jerry Yueecfbf02021-08-30 18:32:07 +080085 ssl->conf->max_major_ver,
86 ssl->conf->max_minor_ver ) );
Jerry Yu92c6b402021-08-27 16:59:09 +080087
88 *olen = 7;
89
90 return( 0 );
91}
Jerry Yubc20bdd2021-08-24 15:59:48 +080092
93#if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
94
Jerry Yu6b64fe32021-09-01 17:05:13 +080095/*
96 * Functions for writing supported_groups extension.
97 *
98 * Stucture of supported_groups:
99 * enum {
100 * secp256r1(0x0017), secp384r1(0x0018), secp521r1(0x0019),
101 * x25519(0x001D), x448(0x001E),
102 * ffdhe2048(0x0100), ffdhe3072(0x0101), ffdhe4096(0x0102),
103 * ffdhe6144(0x0103), ffdhe8192(0x0104),
104 * ffdhe_private_use(0x01FC..0x01FF),
105 * ecdhe_private_use(0xFE00..0xFEFF),
106 * (0xFFFF)
107 * } NamedGroup;
108 * struct {
109 * NamedGroup named_group_list<2..2^16-1>;
110 * } NamedGroupList;
111 */
Jerry Yu6b64fe32021-09-01 17:05:13 +0800112#if defined(MBEDTLS_ECDH_C)
113/*
114 * In versions of TLS prior to TLS 1.3, this extension was named
115 * 'elliptic_curves' and only contained elliptic curve groups.
116 */
Jerry Yub60e3cf2021-09-08 16:41:02 +0800117static int ssl_tls13_write_named_group_list_ecdhe( mbedtls_ssl_context *ssl,
118 unsigned char *buf,
119 unsigned char *end,
120 size_t *olen )
Jerry Yu6b64fe32021-09-01 17:05:13 +0800121{
122 unsigned char *p = buf;
Jerry Yu6b64fe32021-09-01 17:05:13 +0800123
124 *olen = 0;
125
Jerry Yu7c522d42021-09-08 17:55:09 +0800126 if( ssl->conf->curve_list == NULL )
127 return( MBEDTLS_ERR_SSL_BAD_CONFIG );
128
Jerry Yu6b64fe32021-09-01 17:05:13 +0800129 for ( const mbedtls_ecp_group_id *grp_id = ssl->conf->curve_list;
130 *grp_id != MBEDTLS_ECP_DP_NONE;
131 grp_id++ )
132 {
133 const mbedtls_ecp_curve_info *info;
134 info = mbedtls_ecp_curve_info_from_grp_id( *grp_id );
135 if( info == NULL )
136 continue;
Jerry Yu7c522d42021-09-08 17:55:09 +0800137
Jerry Yub60e3cf2021-09-08 16:41:02 +0800138 if( !mbedtls_ssl_tls13_named_group_is_ecdhe( info->tls_id ) )
Jerry Yu6b64fe32021-09-01 17:05:13 +0800139 continue;
140
141 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 2);
142 MBEDTLS_PUT_UINT16_BE( info->tls_id, p, 0 );
143 p += 2;
144
145 MBEDTLS_SSL_DEBUG_MSG( 3, ( "NamedGroup: %s ( %x )",
146 mbedtls_ecp_curve_info_from_tls_id( info->tls_id )->name,
147 info->tls_id ) );
148 }
149
150 *olen = p - buf;
151
152 return( 0 );
153}
154#else
Jerry Yub60e3cf2021-09-08 16:41:02 +0800155static int ssl_tls13_write_named_group_list_ecdhe( mbedtls_ssl_context *ssl,
156 unsigned char *buf,
157 unsigned char *end,
158 size_t *olen )
Jerry Yu92c6b402021-08-27 16:59:09 +0800159{
160 ((void) ssl);
161 ((void) buf);
162 ((void) end);
Jerry Yu75336352021-09-01 15:59:36 +0800163 *olen = 0;
Jerry Yu6b64fe32021-09-01 17:05:13 +0800164 return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE );
165}
166#endif /* MBEDTLS_ECDH_C */
167
Jerry Yub60e3cf2021-09-08 16:41:02 +0800168static int ssl_tls13_write_named_group_list_dhe( mbedtls_ssl_context *ssl,
169 unsigned char *buf,
170 unsigned char *end,
171 size_t *olen )
Jerry Yu6b64fe32021-09-01 17:05:13 +0800172{
173 ((void) ssl);
174 ((void) buf);
175 ((void) end);
176 *olen = 0;
177 MBEDTLS_SSL_DEBUG_MSG( 3, ( "write_named_group_dhe is not implemented" ) );
178 return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE );
179}
180
Jerry Yu6b64fe32021-09-01 17:05:13 +0800181static int ssl_tls13_write_supported_groups_ext( mbedtls_ssl_context *ssl,
182 unsigned char *buf,
183 unsigned char *end,
184 size_t *olen )
185{
186 unsigned char *p = buf ;
Jerry Yub60e3cf2021-09-08 16:41:02 +0800187 unsigned char *name_group_list_ptr; /* Start of named_group_list */
188 size_t output_len = 0;
189 int ret_ecdhe, ret_dhe;
Jerry Yu6b64fe32021-09-01 17:05:13 +0800190
191 *olen = 0;
192
193 if( !mbedtls_ssl_conf_tls13_some_ephemeral_enabled( ssl ) )
194 return( 0 );
195
196 MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, adding supported_groups extension" ) );
197
Jerry Yub60e3cf2021-09-08 16:41:02 +0800198 /* Check if we have space for header and length fields:
199 * - extension_type (2 bytes)
200 * - extension_data_length (2 bytes)
201 * - named_group_list_length (2 bytes)
202 */
Jerry Yu6b64fe32021-09-01 17:05:13 +0800203 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 6 );
204 p += 6;
205
Jerry Yub60e3cf2021-09-08 16:41:02 +0800206 name_group_list_ptr = p;
207 ret_ecdhe = ssl_tls13_write_named_group_list_ecdhe( ssl, p, end, &output_len );
Jerry Yu6b64fe32021-09-01 17:05:13 +0800208 if( ret_ecdhe != 0 )
209 {
Jerry Yub60e3cf2021-09-08 16:41:02 +0800210 MBEDTLS_SSL_DEBUG_RET( 1, "ssl_tls13_write_named_group_list_ecdhe", ret_ecdhe );
Jerry Yu6b64fe32021-09-01 17:05:13 +0800211 }
Jerry Yub60e3cf2021-09-08 16:41:02 +0800212 p += output_len;
Jerry Yu6b64fe32021-09-01 17:05:13 +0800213
Jerry Yub60e3cf2021-09-08 16:41:02 +0800214 ret_dhe = ssl_tls13_write_named_group_list_dhe( ssl, p, end, &output_len );
Jerry Yu6b64fe32021-09-01 17:05:13 +0800215 if( ret_dhe != 0 )
216 {
Jerry Yub60e3cf2021-09-08 16:41:02 +0800217 MBEDTLS_SSL_DEBUG_RET( 1, "ssl_tls13_write_named_group_list_dhe", ret_dhe );
Jerry Yu6b64fe32021-09-01 17:05:13 +0800218 }
Jerry Yub60e3cf2021-09-08 16:41:02 +0800219 p += output_len;
Jerry Yu6b64fe32021-09-01 17:05:13 +0800220
221 /* Both ECDHE and DHE Fail. */
222 if( ret_ecdhe != 0 && ret_dhe != 0 )
223 {
224 MBEDTLS_SSL_DEBUG_MSG( 1, ( "Both ECDHE and DHE groups are fail. " ) );
225 return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
226 }
227
228 /* Length of named_group_list*/
Jerry Yub60e3cf2021-09-08 16:41:02 +0800229 size_t named_group_list_len = p - name_group_list_ptr;
230 if( named_group_list_len == 0 )
Jerry Yu6b64fe32021-09-01 17:05:13 +0800231 {
232 MBEDTLS_SSL_DEBUG_MSG( 1, ( "No Named Group Available." ) );
233 return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
234 }
235
236 /* Write extension_type */
237 MBEDTLS_PUT_UINT16_BE( MBEDTLS_TLS_EXT_SUPPORTED_GROUPS, buf, 0 );
238 /* Write extension_data_length */
Jerry Yub60e3cf2021-09-08 16:41:02 +0800239 MBEDTLS_PUT_UINT16_BE( named_group_list_len + 2, buf, 2 );
Jerry Yu6b64fe32021-09-01 17:05:13 +0800240 /* Write length of named_group_list */
Jerry Yub60e3cf2021-09-08 16:41:02 +0800241 MBEDTLS_PUT_UINT16_BE( named_group_list_len, buf, 4 );
Jerry Yu6b64fe32021-09-01 17:05:13 +0800242
Jerry Yub60e3cf2021-09-08 16:41:02 +0800243 MBEDTLS_SSL_DEBUG_BUF( 3, "Supported groups extension", buf + 4, named_group_list_len + 2 );
Jerry Yu6b64fe32021-09-01 17:05:13 +0800244
245 *olen = p - buf;
246
247 ssl->handshake->extensions_present |= MBEDTLS_SSL_EXT_SUPPORTED_GROUPS;
248
Jerry Yub60e3cf2021-09-08 16:41:02 +0800249 return( 0 );
Jerry Yu92c6b402021-08-27 16:59:09 +0800250}
Jerry Yubc20bdd2021-08-24 15:59:48 +0800251
Jerry Yu56fc07f2021-09-01 17:48:49 +0800252/*
253 * Functions for writing key_share extension.
254 */
255#if defined(MBEDTLS_ECDH_C)
Jerry Yu7c522d42021-09-08 17:55:09 +0800256static int ssl_tls13_generate_and_write_ecdh_key_exchange(
Jerry Yub60e3cf2021-09-08 16:41:02 +0800257 mbedtls_ssl_context *ssl,
258 uint16_t named_group,
259 unsigned char *buf,
260 unsigned char *end,
261 size_t *olen )
Jerry Yu92c6b402021-08-27 16:59:09 +0800262{
Jerry Yu56fc07f2021-09-01 17:48:49 +0800263 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Jerry Yu56fc07f2021-09-01 17:48:49 +0800264 const mbedtls_ecp_curve_info *curve_info =
265 mbedtls_ecp_curve_info_from_tls_id( named_group );
266
267 if( curve_info == NULL )
268 return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
269
270 MBEDTLS_SSL_DEBUG_MSG( 3, ( "offer curve %s", curve_info->name ) );
271
272 if( ( ret = mbedtls_ecdh_setup( &ssl->handshake->ecdh_ctx,
273 curve_info->grp_id ) ) != 0 )
274 {
275 MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ecp_group_load", ret );
276 return( ret );
277 }
278
279 ret = mbedtls_ecdh_tls13_make_params( &ssl->handshake->ecdh_ctx, olen,
280 buf, end - buf,
281 ssl->conf->f_rng, ssl->conf->p_rng );
282 if( ret != 0 )
283 {
284 MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ecdh_tls13_make_params", ret );
285 return( ret );
286 }
287
288 MBEDTLS_SSL_DEBUG_ECDH( 3, &ssl->handshake->ecdh_ctx,
289 MBEDTLS_DEBUG_ECDH_Q );
Jerry Yu75336352021-09-01 15:59:36 +0800290 return( 0 );
Jerry Yu92c6b402021-08-27 16:59:09 +0800291}
Jerry Yu56fc07f2021-09-01 17:48:49 +0800292#endif /* MBEDTLS_ECDH_C */
293
Jerry Yub60e3cf2021-09-08 16:41:02 +0800294static int ssl_tls13_get_default_group_id( mbedtls_ssl_context *ssl,
295 uint16_t *group_id )
Jerry Yu56fc07f2021-09-01 17:48:49 +0800296{
297 int ret = MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE;
298
299 /* Pick first entry of curve list.
300 *
301 * TODO: When we introduce PQC KEMs, we'll have a NamedGroup
302 * list instead, and can just return its first element.
303 */
304
305 /* Check if ecdhe named groups are available and pick first entry */
306#if defined(MBEDTLS_ECDH_C)
307#if !defined(MBEDTLS_ECP_C)
308 ((void) ssl);
309#endif
310#if defined(MBEDTLS_ECP_C)
311 for ( const mbedtls_ecp_group_id * grp_id = ssl->conf->curve_list;
312 *grp_id != MBEDTLS_ECP_DP_NONE;
313 grp_id++ )
314 {
315 const mbedtls_ecp_curve_info *info;
316 info = mbedtls_ecp_curve_info_from_grp_id( *grp_id );
317#else
318 for ( const mbedtls_ecp_curve_info *info = mbedtls_ecp_curve_list();
319 info->grp_id != MBEDTLS_ECP_DP_NONE;
320 info++ )
321 {
322#endif
Jerry Yub60e3cf2021-09-08 16:41:02 +0800323 if( info != NULL && mbedtls_ssl_tls13_named_group_is_ecdhe( info->tls_id ) )
Jerry Yu56fc07f2021-09-01 17:48:49 +0800324 {
Jerry Yub60e3cf2021-09-08 16:41:02 +0800325 *group_id = info->tls_id;
Jerry Yu56fc07f2021-09-01 17:48:49 +0800326 return( 0 );
327 }
328 }
329#else
330 ((void) ssl);
Jerry Yub60e3cf2021-09-08 16:41:02 +0800331 ((void) group_id);
Jerry Yu56fc07f2021-09-01 17:48:49 +0800332#endif /* MBEDTLS_ECDH_C */
333
334 /*
335 * Add DHE named groups here.
336 * Check if ecdhe named groups are available and pick first entry
337 */
338
339 return( ret );
340}
341
342/*
343 * ssl_tls13_write_key_share_ext
344 *
345 * Structure of key_share extension in ClientHelo:
346 *
347 * struct {
348 * NamedGroup group;
349 * opaque key_exchange<1..2^16-1>;
350 * } KeyShareEntry;
351 * struct {
352 * KeyShareEntry client_shares<0..2^16-1>;
353 * } KeyShareClientHello;
354 */
355static int ssl_tls13_write_key_share_ext( mbedtls_ssl_context *ssl,
356 unsigned char *buf,
357 unsigned char *end,
358 size_t *olen )
359{
360 unsigned char *p = buf;
361 unsigned char *client_shares_ptr; /* Start of client_shares */
Jerry Yub60e3cf2021-09-08 16:41:02 +0800362 size_t client_shares_len; /* Length of client_shares */
Jerry Yu56fc07f2021-09-01 17:48:49 +0800363 uint16_t group_id;
Jerry Yu56fc07f2021-09-01 17:48:49 +0800364 int ret = MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE;
365
366 *olen = 0;
367
368 if( !mbedtls_ssl_conf_tls13_some_ephemeral_enabled( ssl ) )
369 return( 0 );
370
Jerry Yub60e3cf2021-09-08 16:41:02 +0800371 /* Check if we have space for header and length fields:
Jerry Yu56fc07f2021-09-01 17:48:49 +0800372 * - extension_type (2 bytes)
373 * - extension_data_length (2 bytes)
374 * - client_shares_length (2 bytes)
375 */
376 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 6 );
377 p += 6;
378
379 MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello: adding key share extension" ) );
380
381 /* HRR could already have requested something else. */
382 group_id = ssl->handshake->offered_group_id;
Jerry Yub60e3cf2021-09-08 16:41:02 +0800383 if( !mbedtls_ssl_tls13_named_group_is_ecdhe( group_id ) &&
384 !mbedtls_ssl_tls13_named_group_is_dhe( group_id ) )
Jerry Yu56fc07f2021-09-01 17:48:49 +0800385 {
Jerry Yub60e3cf2021-09-08 16:41:02 +0800386 MBEDTLS_SSL_PROC_CHK( ssl_tls13_get_default_group_id( ssl,
Jerry Yu56fc07f2021-09-01 17:48:49 +0800387 &group_id ) );
388 }
389
390 /*
391 * Dispatch to type-specific key generation function.
392 *
393 * So far, we're only supporting ECDHE. With the introduction
394 * of PQC KEMs, we'll want to have multiple branches, one per
395 * type of KEM, and dispatch to the corresponding crypto. And
396 * only one key share entry is allowed.
397 */
398 client_shares_ptr = p;
399#if defined(MBEDTLS_ECDH_C)
Jerry Yub60e3cf2021-09-08 16:41:02 +0800400 if( mbedtls_ssl_tls13_named_group_is_ecdhe( group_id ) )
Jerry Yu56fc07f2021-09-01 17:48:49 +0800401 {
402 /* Pointer of group */
403 unsigned char *group_id_ptr = p;
404 /* Length of key_exchange */
405 size_t key_exchange_len;
406
407 /* Check there is space for header of KeyShareEntry
408 * - group (2 bytes)
409 * - key_exchange_length (2 bytes)
410 */
411 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 4 );
412 p += 4;
Jerry Yub60e3cf2021-09-08 16:41:02 +0800413 ret = ssl_tls13_generate_and_write_ecdh_key_exchange( ssl, group_id,
414 p, end,
415 &key_exchange_len );
Jerry Yu56fc07f2021-09-01 17:48:49 +0800416 p += key_exchange_len;
417 if( ret != 0 )
418 return( ret );
419
420 /* Write group */
421 MBEDTLS_PUT_UINT16_BE( group_id, group_id_ptr, 0 );
422 /* Write key_exchange_length */
423 MBEDTLS_PUT_UINT16_BE( key_exchange_len, group_id_ptr, 2 );
424 }
425 else
426#endif /* MBEDTLS_ECDH_C */
427 if( 0 /* other KEMs? */ )
428 {
429 /* Do something */
430 }
431 else
432 return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
433
Jerry Yub60e3cf2021-09-08 16:41:02 +0800434 /* Length of client_shares */
435 client_shares_len = p - client_shares_ptr;
436 if( client_shares_len == 0)
437 {
438 MBEDTLS_SSL_DEBUG_MSG( 1, ( "No key share defined." ) );
439 return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
Jerry Yu7c522d42021-09-08 17:55:09 +0800440 }
Jerry Yu56fc07f2021-09-01 17:48:49 +0800441 /* Write extension_type */
442 MBEDTLS_PUT_UINT16_BE( MBEDTLS_TLS_EXT_KEY_SHARE, buf, 0 );
443 /* Write extension_data_length */
Jerry Yub60e3cf2021-09-08 16:41:02 +0800444 MBEDTLS_PUT_UINT16_BE( client_shares_len + 2, buf, 2 );
Jerry Yu56fc07f2021-09-01 17:48:49 +0800445 /* Write client_shares_length */
Jerry Yub60e3cf2021-09-08 16:41:02 +0800446 MBEDTLS_PUT_UINT16_BE( client_shares_len, buf, 4 );
Jerry Yu56fc07f2021-09-01 17:48:49 +0800447
448 /* Update offered_group_id field */
449 ssl->handshake->offered_group_id = group_id;
450
451 /* Output the total length of key_share extension. */
452 *olen = p - buf;
453
454 MBEDTLS_SSL_DEBUG_BUF( 3, "client hello, key_share extension", buf, *olen );
455
456 ssl->handshake->extensions_present |= MBEDTLS_SSL_EXT_KEY_SHARE;
457
458cleanup:
459
460 return( ret );
461}
Jerry Yubc20bdd2021-08-24 15:59:48 +0800462
463#endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */
464
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800465/* Write cipher_suites
Jerry Yu6a643102021-08-31 14:40:36 +0800466 * CipherSuite cipher_suites<2..2^16-2>;
467 */
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800468static int ssl_tls13_write_client_hello_cipher_suites(
Jerry Yu6a643102021-08-31 14:40:36 +0800469 mbedtls_ssl_context *ssl,
470 unsigned char *buf,
471 unsigned char *end,
472 size_t *olen )
473{
Jerry Yufec982e2021-09-07 17:26:06 +0800474 unsigned char *p = buf;
Jerry Yu0c63af62021-09-02 12:59:12 +0800475 const int *ciphersuite_list;
Jerry Yubbe09522021-09-06 21:17:54 +0800476 unsigned char *cipher_suites_ptr; /* Start of the cipher_suites list */
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800477 size_t cipher_suites_len;
Jerry Yu92c6b402021-08-27 16:59:09 +0800478
Jerry Yu6a643102021-08-31 14:40:36 +0800479 *olen = 0 ;
480
481 /*
482 * Ciphersuite list
483 *
484 * This is a list of the symmetric cipher options supported by
485 * the client, specifically the record protection algorithm
486 * ( including secret key length ) and a hash to be used with
487 * HKDF, in descending order of client preference.
488 */
Jerry Yu0c63af62021-09-02 12:59:12 +0800489 ciphersuite_list = ssl->conf->ciphersuite_list;
Jerry Yu6a643102021-08-31 14:40:36 +0800490
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800491 /* Check there is space for the cipher suite list length (2 bytes). */
Jerry Yu4e388282021-09-06 21:28:08 +0800492 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 2 );
493 p += 2;
Jerry Yu6a643102021-08-31 14:40:36 +0800494
Jerry Yu0c63af62021-09-02 12:59:12 +0800495 /* Write cipher_suites */
Jerry Yu4e388282021-09-06 21:28:08 +0800496 cipher_suites_ptr = p;
Jerry Yu0c63af62021-09-02 12:59:12 +0800497 for ( size_t i = 0; ciphersuite_list[i] != 0; i++ )
Jerry Yu6a643102021-08-31 14:40:36 +0800498 {
Jerry Yu0c63af62021-09-02 12:59:12 +0800499 int cipher_suite = ciphersuite_list[i];
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800500 const mbedtls_ssl_ciphersuite_t *ciphersuite_info;
Jerry Yu6a643102021-08-31 14:40:36 +0800501
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800502 ciphersuite_info = mbedtls_ssl_ciphersuite_from_id( cipher_suite );
Jerry Yu6a643102021-08-31 14:40:36 +0800503 if( ciphersuite_info == NULL )
504 continue;
Jerry Yudbfb7bd2021-09-04 09:58:58 +0800505 if( !( MBEDTLS_SSL_MINOR_VERSION_4 >= ciphersuite_info->min_minor_ver &&
506 MBEDTLS_SSL_MINOR_VERSION_4 <= ciphersuite_info->max_minor_ver ) )
Jerry Yu6a643102021-08-31 14:40:36 +0800507 continue;
508
509 MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, add ciphersuite: %04x, %s",
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800510 (unsigned int) cipher_suite,
Jerry Yu6a643102021-08-31 14:40:36 +0800511 ciphersuite_info->name ) );
512
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800513 /* Check there is space for the cipher suite identifier (2 bytes). */
Jerry Yubbe09522021-09-06 21:17:54 +0800514 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 2 );
515 MBEDTLS_PUT_UINT16_BE( cipher_suite, p, 0 );
516 p += 2;
Jerry Yu6a643102021-08-31 14:40:36 +0800517 }
518
Jerry Yu0c63af62021-09-02 12:59:12 +0800519 /* Write the cipher_suites length in number of bytes */
Jerry Yubbe09522021-09-06 21:17:54 +0800520 cipher_suites_len = p - cipher_suites_ptr;
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800521 MBEDTLS_PUT_UINT16_BE( cipher_suites_len, buf, 0 );
Jerry Yu6a643102021-08-31 14:40:36 +0800522 MBEDTLS_SSL_DEBUG_MSG( 3,
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800523 ( "client hello, got %" MBEDTLS_PRINTF_SIZET " cipher suites",
524 cipher_suites_len/2 ) );
Jerry Yu6a643102021-08-31 14:40:36 +0800525
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800526 /* Output the total length of cipher_suites field. */
Jerry Yubbe09522021-09-06 21:17:54 +0800527 *olen = p - buf;
Jerry Yuf171e832021-08-31 18:31:09 +0800528
Jerry Yu6a643102021-08-31 14:40:36 +0800529 return( 0 );
530}
531
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800532/*
533 * Structure of ClientHello message:
534 *
535 * struct {
536 * ProtocolVersion legacy_version = 0x0303; // TLS v1.2
537 * Random random;
538 * opaque legacy_session_id<0..32>;
539 * CipherSuite cipher_suites<2..2^16-2>;
540 * opaque legacy_compression_methods<1..2^8-1>;
541 * Extension extensions<8..2^16-1>;
542 * } ClientHello;
543 */
Jerry Yu08906d02021-08-31 11:05:27 +0800544static int ssl_tls13_write_client_hello_body( mbedtls_ssl_context *ssl,
Jerry Yueecfbf02021-08-30 18:32:07 +0800545 unsigned char *buf,
Jerry Yuef387d72021-09-02 13:59:41 +0800546 unsigned char *end,
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800547 size_t *olen )
Jerry Yu65dd2cc2021-08-18 16:38:40 +0800548{
Jerry Yubc20bdd2021-08-24 15:59:48 +0800549
Jerry Yubc20bdd2021-08-24 15:59:48 +0800550 int ret;
Jerry Yu8c02bb42021-09-03 21:09:22 +0800551 unsigned char *extensions_len_ptr; /* Pointer to extensions length */
Jerry Yu790656a2021-09-01 15:51:48 +0800552 size_t output_len; /* Length of buffer used by function */
553 size_t extensions_len; /* Length of the list of extensions*/
Jerry Yubc20bdd2021-08-24 15:59:48 +0800554
Jerry Yubc20bdd2021-08-24 15:59:48 +0800555 /* Buffer management */
Jerry Yubbe09522021-09-06 21:17:54 +0800556 unsigned char *p = buf;
Jerry Yubc20bdd2021-08-24 15:59:48 +0800557
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800558 *olen = 0;
Jerry Yubc20bdd2021-08-24 15:59:48 +0800559
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800560 /* No validation needed here. It has been done by ssl_conf_check() */
Jerry Yubc20bdd2021-08-24 15:59:48 +0800561 ssl->major_ver = ssl->conf->min_major_ver;
562 ssl->minor_ver = ssl->conf->min_minor_ver;
563
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800564 /*
565 * Write legacy_version
Jerry Yu6a643102021-08-31 14:40:36 +0800566 * ProtocolVersion legacy_version = 0x0303; // TLS v1.2
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800567 *
568 * For TLS 1.3 we use the legacy version number {0x03, 0x03}
Jerry Yubc20bdd2021-08-24 15:59:48 +0800569 * instead of the true version number.
Jerry Yubc20bdd2021-08-24 15:59:48 +0800570 */
Jerry Yufec982e2021-09-07 17:26:06 +0800571 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 2 );
Jerry Yubbe09522021-09-06 21:17:54 +0800572 MBEDTLS_PUT_UINT16_BE( 0x0303, p, 0 );
Jerry Yufec982e2021-09-07 17:26:06 +0800573 p += 2;
Jerry Yubc20bdd2021-08-24 15:59:48 +0800574
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800575 /* Write the random bytes ( random ).*/
Jerry Yubbe09522021-09-06 21:17:54 +0800576 MBEDTLS_SSL_CHK_BUF_PTR( p, end, CLIENT_HELLO_RANDOM_LEN );
577 memcpy( p, ssl->handshake->randbytes, CLIENT_HELLO_RANDOM_LEN );
Jerry Yue885b762021-08-26 17:32:34 +0800578 MBEDTLS_SSL_DEBUG_BUF( 3, "client hello, random bytes",
Jerry Yubbe09522021-09-06 21:17:54 +0800579 p, CLIENT_HELLO_RANDOM_LEN );
580 p += CLIENT_HELLO_RANDOM_LEN;
Jerry Yubc20bdd2021-08-24 15:59:48 +0800581
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800582 /*
583 * Write legacy_session_id
584 *
585 * Versions of TLS before TLS 1.3 supported a "session resumption" feature
586 * which has been merged with pre-shared keys in this version. A client
587 * which has a cached session ID set by a pre-TLS 1.3 server SHOULD set
588 * this field to that value. In compatibility mode, this field MUST be
589 * non-empty, so a client not offering a pre-TLS 1.3 session MUST generate
590 * a new 32-byte value. This value need not be random but SHOULD be
591 * unpredictable to avoid implementations fixating on a specific value
592 * ( also known as ossification ). Otherwise, it MUST be set as a zero-length
593 * vector ( i.e., a zero-valued single byte length field ).
Jerry Yubc20bdd2021-08-24 15:59:48 +0800594 */
Jerry Yubbe09522021-09-06 21:17:54 +0800595 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 1 );
596 *p++ = 0; /* session id length set to zero */
Jerry Yubc20bdd2021-08-24 15:59:48 +0800597
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800598 /* Write cipher_suites */
Jerry Yubbe09522021-09-06 21:17:54 +0800599 ret = ssl_tls13_write_client_hello_cipher_suites( ssl, p, end, &output_len );
Jerry Yudbfb7bd2021-09-04 09:58:58 +0800600 if( ret != 0 )
Jerry Yu6a643102021-08-31 14:40:36 +0800601 return( ret );
Jerry Yubbe09522021-09-06 21:17:54 +0800602 p += output_len;
Jerry Yubc20bdd2021-08-24 15:59:48 +0800603
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800604 /* Write legacy_compression_methods
605 *
606 * For every TLS 1.3 ClientHello, this vector MUST contain exactly
Jerry Yubc20bdd2021-08-24 15:59:48 +0800607 * one byte set to zero, which corresponds to the 'null' compression
608 * method in prior versions of TLS.
Jerry Yubc20bdd2021-08-24 15:59:48 +0800609 */
Jerry Yubbe09522021-09-06 21:17:54 +0800610 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 2 );
611 *p++ = 1;
612 *p++ = MBEDTLS_SSL_COMPRESS_NULL;
Jerry Yubc20bdd2021-08-24 15:59:48 +0800613
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800614 /* Write extensions */
615
616 /* Keeping track of the included extensions */
617 ssl->handshake->extensions_present = MBEDTLS_SSL_EXT_NONE;
Jerry Yubc20bdd2021-08-24 15:59:48 +0800618
619 /* First write extensions, then the total length */
Jerry Yubbe09522021-09-06 21:17:54 +0800620 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 2 );
621 extensions_len_ptr = p;
622 p += 2;
Jerry Yubc20bdd2021-08-24 15:59:48 +0800623
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800624 /* Write supported_versions extension
Jerry Yubc20bdd2021-08-24 15:59:48 +0800625 *
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800626 * Supported Versions Extension is mandatory with TLS 1.3.
Jerry Yubc20bdd2021-08-24 15:59:48 +0800627 */
Jerry Yubbe09522021-09-06 21:17:54 +0800628 ret = ssl_tls13_write_supported_versions_ext( ssl, p, end, &output_len );
Jerry Yu92c6b402021-08-27 16:59:09 +0800629 if( ret != 0 )
630 return( ret );
Jerry Yubbe09522021-09-06 21:17:54 +0800631 p += output_len;
Jerry Yubc20bdd2021-08-24 15:59:48 +0800632
633#if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800634 /* Write supported_groups extension
635 *
636 * It is REQUIRED for ECDHE cipher_suites.
Jerry Yubc20bdd2021-08-24 15:59:48 +0800637 */
Jerry Yubbe09522021-09-06 21:17:54 +0800638 ret = ssl_tls13_write_supported_groups_ext( ssl, p, end, &output_len );
Jerry Yubc20bdd2021-08-24 15:59:48 +0800639 if( ret != 0 )
640 return( ret );
Jerry Yubbe09522021-09-06 21:17:54 +0800641 p += output_len;
Jerry Yubc20bdd2021-08-24 15:59:48 +0800642
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800643 /* Write key_share extension
644 *
645 * We need to send the key shares under three conditions:
Jerry Yu159c5a02021-08-31 12:51:25 +0800646 * 1) A certificate-based ciphersuite is being offered. In this case
647 * supported_groups and supported_signature extensions have been
648 * successfully added.
649 * 2) A PSK-based ciphersuite with ECDHE is offered. In this case the
Jerry Yubc20bdd2021-08-24 15:59:48 +0800650 * psk_key_exchange_modes has been added as the last extension.
Jerry Yu159c5a02021-08-31 12:51:25 +0800651 * 3) Or, in case all ciphers are supported ( which includes #1 and #2
652 * from above )
Jerry Yubc20bdd2021-08-24 15:59:48 +0800653 */
Jerry Yu56fc07f2021-09-01 17:48:49 +0800654 ret = ssl_tls13_write_key_share_ext( ssl, p, end, &output_len );
Jerry Yubc20bdd2021-08-24 15:59:48 +0800655 if( ret != 0 )
656 return( ret );
Jerry Yubbe09522021-09-06 21:17:54 +0800657 p += output_len;
Jerry Yu6a643102021-08-31 14:40:36 +0800658
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800659 /* Write signature_algorithms extension
660 *
661 * It is REQUIRED for certificate authenticated cipher_suites.
662 */
Jerry Yubbe09522021-09-06 21:17:54 +0800663 ret = mbedtls_ssl_tls13_write_sig_alg_ext( ssl, p, end, &output_len );
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800664 if( ret != 0 )
665 return( ret );
Jerry Yubbe09522021-09-06 21:17:54 +0800666 p += output_len;
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800667
Jerry Yubc20bdd2021-08-24 15:59:48 +0800668#endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */
669
670 /* Add more extensions here */
671
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800672 /* Write the length of the list of extensions. */
Jerry Yubbe09522021-09-06 21:17:54 +0800673 extensions_len = p - extensions_len_ptr - 2;
Jerry Yu790656a2021-09-01 15:51:48 +0800674 MBEDTLS_PUT_UINT16_BE( extensions_len, extensions_len_ptr, 0 );
Jerry Yubc20bdd2021-08-24 15:59:48 +0800675 MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, total extension length: %" MBEDTLS_PRINTF_SIZET ,
Jerry Yu790656a2021-09-01 15:51:48 +0800676 extensions_len ) );
677 MBEDTLS_SSL_DEBUG_BUF( 3, "client hello extensions", extensions_len_ptr, extensions_len );
Jerry Yubc20bdd2021-08-24 15:59:48 +0800678
Jerry Yubbe09522021-09-06 21:17:54 +0800679 *olen = p - buf;
Jerry Yubc20bdd2021-08-24 15:59:48 +0800680 return( 0 );
681}
682
Jerry Yu92c6b402021-08-27 16:59:09 +0800683static int ssl_tls13_finalize_client_hello( mbedtls_ssl_context* ssl )
Jerry Yubc20bdd2021-08-24 15:59:48 +0800684{
Jerry Yu92c6b402021-08-27 16:59:09 +0800685 mbedtls_ssl_handshake_set_state( ssl, MBEDTLS_SSL_SERVER_HELLO );
686 return( 0 );
687}
Jerry Yuef6b36b2021-08-24 16:29:02 +0800688
Jerry Yu92c6b402021-08-27 16:59:09 +0800689static int ssl_tls13_prepare_client_hello( mbedtls_ssl_context *ssl )
690{
691 int ret;
Jerry Yuef6b36b2021-08-24 16:29:02 +0800692
Jerry Yu92c6b402021-08-27 16:59:09 +0800693 if( ssl->conf->f_rng == NULL )
694 {
695 MBEDTLS_SSL_DEBUG_MSG( 1, ( "no RNG provided" ) );
696 return( MBEDTLS_ERR_SSL_NO_RNG );
697 }
Jerry Yuef6b36b2021-08-24 16:29:02 +0800698
Jerry Yu92c6b402021-08-27 16:59:09 +0800699 if( ( ret = ssl->conf->f_rng( ssl->conf->p_rng,
700 ssl->handshake->randbytes,
Jerry Yu08906d02021-08-31 11:05:27 +0800701 CLIENT_HELLO_RANDOM_LEN ) ) != 0 )
Jerry Yu92c6b402021-08-27 16:59:09 +0800702 {
Jerry Yu8c02bb42021-09-03 21:09:22 +0800703 MBEDTLS_SSL_DEBUG_RET( 1, "f_rng", ret );
Jerry Yu92c6b402021-08-27 16:59:09 +0800704 return( ret );
705 }
Jerry Yu6f13f642021-08-26 17:18:15 +0800706
707 return( 0 );
Jerry Yubc20bdd2021-08-24 15:59:48 +0800708}
709
Jerry Yu92c6b402021-08-27 16:59:09 +0800710/*
Jerry Yu159c5a02021-08-31 12:51:25 +0800711 * Write ClientHello handshake message.
Jerry Yu92c6b402021-08-27 16:59:09 +0800712 */
713static int ssl_tls13_write_client_hello( mbedtls_ssl_context *ssl )
Jerry Yubc20bdd2021-08-24 15:59:48 +0800714{
Jerry Yu92c6b402021-08-27 16:59:09 +0800715 int ret = 0;
716 unsigned char *buf;
717 size_t buf_len, msg_len;
718
719 MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> write client hello" ) );
720
Jerry Yu2c0fbf32021-09-02 13:53:46 +0800721 MBEDTLS_SSL_PROC_CHK( ssl_tls13_prepare_client_hello( ssl ) );
Jerry Yu92c6b402021-08-27 16:59:09 +0800722
Jerry Yu2c0fbf32021-09-02 13:53:46 +0800723 MBEDTLS_SSL_PROC_CHK( mbedtls_ssl_tls13_start_handshake_msg(
724 ssl, MBEDTLS_SSL_HS_CLIENT_HELLO,
725 &buf, &buf_len ) );
Jerry Yu92c6b402021-08-27 16:59:09 +0800726
Jerry Yu2c0fbf32021-09-02 13:53:46 +0800727 MBEDTLS_SSL_PROC_CHK( ssl_tls13_write_client_hello_body( ssl, buf,
Jerry Yuef387d72021-09-02 13:59:41 +0800728 buf + buf_len,
Jerry Yu2c0fbf32021-09-02 13:53:46 +0800729 &msg_len ) );
Jerry Yu92c6b402021-08-27 16:59:09 +0800730
Jerry Yu2c0fbf32021-09-02 13:53:46 +0800731 mbedtls_ssl_tls13_add_hs_hdr_to_checksum( ssl,
732 MBEDTLS_SSL_HS_CLIENT_HELLO,
Jerry Yu0c63af62021-09-02 12:59:12 +0800733 msg_len );
734 ssl->handshake->update_checksum( ssl, buf, msg_len );
Jerry Yu92c6b402021-08-27 16:59:09 +0800735
Jerry Yu2c0fbf32021-09-02 13:53:46 +0800736 MBEDTLS_SSL_PROC_CHK( ssl_tls13_finalize_client_hello( ssl ) );
737 MBEDTLS_SSL_PROC_CHK( mbedtls_ssl_tls13_finish_handshake_msg( ssl,
738 buf_len,
739 msg_len ) );
Jerry Yu92c6b402021-08-27 16:59:09 +0800740
741cleanup:
742
743 MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= write client hello" ) );
744 return ret;
Jerry Yu65dd2cc2021-08-18 16:38:40 +0800745}
746
Jerry Yu92c6b402021-08-27 16:59:09 +0800747int mbedtls_ssl_tls13_handshake_client_step( mbedtls_ssl_context *ssl )
Jerry Yubc20bdd2021-08-24 15:59:48 +0800748{
Jerry Yu92c6b402021-08-27 16:59:09 +0800749 int ret = 0;
Jerry Yuc8a392c2021-08-18 16:46:28 +0800750
Jerry Yu92c6b402021-08-27 16:59:09 +0800751 MBEDTLS_SSL_DEBUG_MSG( 2, ( "client state: %d", ssl->state ) );
752
753 switch( ssl->state )
754 {
755 /*
Jerry Yu0c63af62021-09-02 12:59:12 +0800756 * ssl->state is initialized as HELLO_REQUEST. It is the same
757 * as CLIENT_HELLO state.
Jerry Yu92c6b402021-08-27 16:59:09 +0800758 */
759 case MBEDTLS_SSL_HELLO_REQUEST:
760 case MBEDTLS_SSL_CLIENT_HELLO:
761 ret = ssl_tls13_write_client_hello( ssl );
762 break;
763
764 case MBEDTLS_SSL_SERVER_HELLO:
765 // Stop here : we haven't finished whole flow
766 ret = MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE;
767 mbedtls_ssl_handshake_set_state( ssl, MBEDTLS_SSL_ENCRYPTED_EXTENSIONS );
768 break;
769
770 default:
771 MBEDTLS_SSL_DEBUG_MSG( 1, ( "invalid state %d", ssl->state ) );
772 return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
773 }
774
775 return( ret );
776}
Jerry Yu65dd2cc2021-08-18 16:38:40 +0800777
Jerry Yu3cc4c2a2021-08-06 16:29:08 +0800778#endif /* MBEDTLS_SSL_CLI_C */
779
780#endif /* MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL */