blob: f33c2f636b5f29816384ca066af9122e829de472 [file] [log] [blame]
Jerry Yu65dd2cc2021-08-18 16:38:40 +08001/*
2 * TLS 1.3 functionality shared between client and server
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
20#include "common.h"
21
22#if defined(MBEDTLS_SSL_TLS_C)
23
24#if defined(MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL)
25
Jerry Yuc8a392c2021-08-18 16:46:28 +080026#include "mbedtls/error.h"
27
Jerry Yu65dd2cc2021-08-18 16:38:40 +080028#include "ssl_misc.h"
29
Jerry Yuf4436812021-08-26 22:59:56 +080030int mbedtls_ssl_tls13_start_handshake_msg( mbedtls_ssl_context *ssl,
Jerry Yueecfbf02021-08-30 18:32:07 +080031 unsigned hs_type,
32 unsigned char **buf,
33 size_t *buflen )
Jerry Yu65dd2cc2021-08-18 16:38:40 +080034{
Jerry Yu1bc2c1f2021-09-01 12:57:29 +080035 /*
36 * Reserve 4 bytes for hanshake header. ( Section 4,RFC 8446 )
37 * ...
38 * HandshakeType msg_type;
39 * uint24 length;
40 * ...
41 */
Jerry Yuc8a392c2021-08-18 16:46:28 +080042 *buf = ssl->out_msg + 4;
43 *buflen = MBEDTLS_SSL_OUT_CONTENT_LEN - 4;
44
45 ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE;
46 ssl->out_msg[0] = hs_type;
47
48 return( 0 );
Jerry Yu65dd2cc2021-08-18 16:38:40 +080049}
50
Jerry Yuf4436812021-08-26 22:59:56 +080051int mbedtls_ssl_tls13_finish_handshake_msg( mbedtls_ssl_context *ssl,
Jerry Yueecfbf02021-08-30 18:32:07 +080052 size_t buf_len,
53 size_t msg_len )
Jerry Yu65dd2cc2021-08-18 16:38:40 +080054{
Jerry Yuc8a392c2021-08-18 16:46:28 +080055 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Jerry Yu65dd2cc2021-08-18 16:38:40 +080056 ((void) buf_len);
Jerry Yuc8a392c2021-08-18 16:46:28 +080057
Jerry Yu1bc2c1f2021-09-01 12:57:29 +080058 /* Add reserved 4 bytes for handshake header */
Jerry Yuc8a392c2021-08-18 16:46:28 +080059 ssl->out_msglen = msg_len + 4;
60 MBEDTLS_SSL_PROC_CHK( mbedtls_ssl_write_handshake_msg_ext, ( ssl, 0 ) );
61
62cleanup:
63 return( ret );
Jerry Yu65dd2cc2021-08-18 16:38:40 +080064}
65
Jerry Yuf4436812021-08-26 22:59:56 +080066void mbedtls_ssl_tls13_add_hs_hdr_to_checksum( mbedtls_ssl_context *ssl,
Jerry Yueecfbf02021-08-30 18:32:07 +080067 unsigned hs_type,
68 size_t total_hs_len )
Jerry Yu65dd2cc2021-08-18 16:38:40 +080069{
70 unsigned char hs_hdr[4];
71
72 /* Build HS header for checksum update. */
Jerry Yu2ac64192021-08-26 18:38:58 +080073 hs_hdr[0] = MBEDTLS_BYTE_0( hs_type );
74 hs_hdr[1] = MBEDTLS_BYTE_2( total_hs_len );
75 hs_hdr[2] = MBEDTLS_BYTE_1( total_hs_len );
76 hs_hdr[3] = MBEDTLS_BYTE_0( total_hs_len );
Jerry Yu65dd2cc2021-08-18 16:38:40 +080077
78 ssl->handshake->update_checksum( ssl, hs_hdr, sizeof( hs_hdr ) );
79}
80
Jerry Yubc20bdd2021-08-24 15:59:48 +080081#if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
82
83/*
Jerry Yue41dec02021-08-31 10:57:07 +080084 * mbedtls_ssl_tls13_write_sig_alg_ext( )
Jerry Yubc20bdd2021-08-24 15:59:48 +080085 *
86 * enum {
87 * ....
88 * ecdsa_secp256r1_sha256( 0x0403 ),
89 * ecdsa_secp384r1_sha384( 0x0503 ),
90 * ecdsa_secp521r1_sha512( 0x0603 ),
91 * ....
92 * } SignatureScheme;
93 *
94 * struct {
95 * SignatureScheme supported_signature_algorithms<2..2^16-2>;
96 * } SignatureSchemeList;
97 *
98 * Only if we handle at least one key exchange that needs signatures.
99 */
100
Jerry Yue41dec02021-08-31 10:57:07 +0800101int mbedtls_ssl_tls13_write_sig_alg_ext( mbedtls_ssl_context *ssl,
102 unsigned char *buf,
103 unsigned char *end,
104 size_t *olen )
Jerry Yubc20bdd2021-08-24 15:59:48 +0800105{
106 ((void) ssl);
107 ((void) buf);
108 ((void) end);
109 ((void) olen);
110 return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE );
111}
112
113#endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */
114
Jerry Yu65dd2cc2021-08-18 16:38:40 +0800115#endif /* MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL */
116
117#endif /* MBEDTLS_SSL_TLS_C */