From ce467cd3914525bed65499df09bcc95bc072cff3 Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Mon, 19 Jul 2021 14:47:57 +0800 Subject: [PATCH] create functions for tls1.3 fix redefined error Change-Id: Ibb97cab50ca18801b7309c36c5b816890e3674c8 CustomizedGitHooks: yes Signed-off-by: Jerry Yu --- library/ssl_tls.c | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/library/ssl_tls.c b/library/ssl_tls.c index aabb52eb52df..49a74187462e 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -709,11 +709,11 @@ static void ssl_calc_finished_tls_sha384( mbedtls_ssl_context *, unsigned char * #if defined(MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL) #if defined(MBEDTLS_SHA256_C) -static void ssl_update_checksum_sha256( mbedtls_ssl_context *, const unsigned char *, size_t ); +static void ssl_update_checksum_sha256_tls13( mbedtls_ssl_context *, const unsigned char *, size_t ); #endif #if defined(MBEDTLS_SHA512_C) -static void ssl_update_checksum_sha384( mbedtls_ssl_context *, const unsigned char *, size_t ); +static void ssl_update_checksum_sha384_tls13( mbedtls_ssl_context *, const unsigned char *, size_t ); #endif #if defined(MBEDTLS_SHA256_C) @@ -3088,12 +3088,28 @@ void mbedtls_ssl_optimize_checksum( mbedtls_ssl_context *ssl, #if defined(MBEDTLS_SSL_PROTO_TLS1_2) || defined(MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL) #if defined(MBEDTLS_SHA512_C) if( ciphersuite_info->mac == MBEDTLS_MD_SHA384 ) - ssl->handshake->update_checksum = ssl_update_checksum_sha384; + { +#if defined(MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL) + if(ssl->minor_ver==MBEDTLS_SSL_MINOR_VERSION_4 + && ssl->major_ver == MBEDTLS_SSL_MAJOR_VERSION_3) + ssl->handshake->update_checksum = ssl_update_checksum_sha384_tls13; + else +#endif + ssl->handshake->update_checksum = ssl_update_checksum_sha384; + } else #endif #if defined(MBEDTLS_SHA256_C) if( ciphersuite_info->mac != MBEDTLS_MD_SHA384 ) - ssl->handshake->update_checksum = ssl_update_checksum_sha256; + { +#if defined(MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL) + if(ssl->minor_ver==MBEDTLS_SSL_MINOR_VERSION_4 + && ssl->major_ver == MBEDTLS_SSL_MAJOR_VERSION_3) + ssl->handshake->update_checksum = ssl_update_checksum_sha256_tls13; + else +#endif + ssl->handshake->update_checksum = ssl_update_checksum_sha256; + } else #endif #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ @@ -3133,7 +3149,7 @@ void mbedtls_ssl_reset_checksum( mbedtls_ssl_context *ssl ) #endif /* defined(MBEDTLS_SSL_PROTO_TLS1_2_OR_EARLIER) */ #if defined(MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL) -static void ssl_update_checksum_start( mbedtls_ssl_context *ssl, +static void ssl_update_checksum_start_tls13( mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len ) { #if defined(MBEDTLS_SSL_DEBUG_HANDSHAKE_HASHES) @@ -3252,7 +3268,7 @@ static void ssl_update_checksum_sha384( mbedtls_ssl_context *ssl, #if defined(MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL) #if defined(MBEDTLS_SHA256_C) -static void ssl_update_checksum_sha256( mbedtls_ssl_context* ssl, +static void ssl_update_checksum_sha256_tls13( mbedtls_ssl_context* ssl, const unsigned char* buf, size_t len ) { int ret = 0; @@ -3297,7 +3313,7 @@ exit:; #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) -static void ssl_update_checksum_sha384( mbedtls_ssl_context* ssl, +static void ssl_update_checksum_sha384_tls13( mbedtls_ssl_context* ssl, const unsigned char* buf, size_t len ) { int ret = 0; @@ -3947,7 +3963,7 @@ int mbedtls_ssl_parse_finished( mbedtls_ssl_context *ssl ) } #endif /* defined(MBEDTLS_SSL_PROTO_TLS1_2_OR_EARLIER) */ -static void ssl_handshake_params_init( mbedtls_ssl_handshake_params *handshake ) +static void ssl_handshake_params_init( mbedtls_ssl_handshake_params *handshake,mbedtls_ssl_context * ssl ) { memset( handshake, 0, sizeof( mbedtls_ssl_handshake_params ) ); @@ -3978,8 +3994,13 @@ static void ssl_handshake_params_init( mbedtls_ssl_handshake_params *handshake ) #endif #endif #endif /* MBEDTLS_SSL_PROTO_TLS1_2 || MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL */ - - handshake->update_checksum = ssl_update_checksum_start; +#if defined(MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL) + if(ssl->minor_ver==MBEDTLS_SSL_MINOR_VERSION_4 + && ssl->major_ver == MBEDTLS_SSL_MAJOR_VERSION_3) + handshake->update_checksum = ssl_update_checksum_start_tls13; + else +#endif + handshake->update_checksum = ssl_update_checksum_start; #if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \ defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED) @@ -4178,7 +4199,7 @@ static int ssl_handshake_init( mbedtls_ssl_context *ssl ) /* Initialize structures */ mbedtls_ssl_session_init( ssl->session_negotiate ); - ssl_handshake_params_init( ssl->handshake ); + ssl_handshake_params_init( ssl->handshake, ssl); #if defined(MBEDTLS_SSL_PROTO_TLS1_2_OR_EARLIER) mbedtls_ssl_transform_init( ssl->transform_negotiate );