Jerry Yu | 65dd2cc | 2021-08-18 16:38:40 +0800 | [diff] [blame] | 1 | /* |
| 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 Yu | c8a392c | 2021-08-18 16:46:28 +0800 | [diff] [blame] | 26 | #include "mbedtls/error.h" |
| 27 | |
Jerry Yu | 65dd2cc | 2021-08-18 16:38:40 +0800 | [diff] [blame] | 28 | #include "ssl_misc.h" |
| 29 | |
| 30 | int mbedtls_ssl_start_handshake_msg( mbedtls_ssl_context *ssl, |
| 31 | unsigned hs_type, |
| 32 | unsigned char **buf, |
| 33 | size_t *buflen ) |
| 34 | { |
Jerry Yu | c8a392c | 2021-08-18 16:46:28 +0800 | [diff] [blame] | 35 | *buf = ssl->out_msg + 4; |
| 36 | *buflen = MBEDTLS_SSL_OUT_CONTENT_LEN - 4; |
| 37 | |
| 38 | ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE; |
| 39 | ssl->out_msg[0] = hs_type; |
| 40 | |
| 41 | return( 0 ); |
Jerry Yu | 65dd2cc | 2021-08-18 16:38:40 +0800 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | int mbedtls_ssl_finish_handshake_msg( mbedtls_ssl_context *ssl, |
| 45 | size_t buf_len, |
| 46 | size_t msg_len ) |
| 47 | { |
Jerry Yu | c8a392c | 2021-08-18 16:46:28 +0800 | [diff] [blame] | 48 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Jerry Yu | 65dd2cc | 2021-08-18 16:38:40 +0800 | [diff] [blame] | 49 | ((void) buf_len); |
Jerry Yu | c8a392c | 2021-08-18 16:46:28 +0800 | [diff] [blame] | 50 | |
| 51 | ssl->out_msglen = msg_len + 4; |
| 52 | MBEDTLS_SSL_PROC_CHK( mbedtls_ssl_write_handshake_msg_ext, ( ssl, 0 ) ); |
| 53 | |
| 54 | cleanup: |
| 55 | return( ret ); |
Jerry Yu | 65dd2cc | 2021-08-18 16:38:40 +0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void mbedtls_ssl_add_hs_hdr_to_checksum( mbedtls_ssl_context *ssl, |
| 59 | unsigned hs_type, |
| 60 | size_t total_hs_len ) |
| 61 | { |
| 62 | unsigned char hs_hdr[4]; |
| 63 | |
| 64 | /* Build HS header for checksum update. */ |
| 65 | hs_hdr[0] = hs_type; |
| 66 | hs_hdr[1] = (unsigned char)( total_hs_len >> 16 ); |
| 67 | hs_hdr[2] = (unsigned char)( total_hs_len >> 8 ); |
| 68 | hs_hdr[3] = (unsigned char)( total_hs_len >> 0 ); |
| 69 | |
| 70 | ssl->handshake->update_checksum( ssl, hs_hdr, sizeof( hs_hdr ) ); |
| 71 | } |
| 72 | |
| 73 | #endif /* MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL */ |
| 74 | |
| 75 | #endif /* MBEDTLS_SSL_TLS_C */ |