move base_key init

Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
This commit is contained in:
Jerry Yu 2021-12-10 17:55:23 +08:00
parent 9c07473ebc
commit b737f6a9be

View file

@ -655,8 +655,19 @@ int mbedtls_ssl_tls13_calculate_verify_data( mbedtls_ssl_context* ssl,
size_t transcript_len;
unsigned char *base_key = NULL;
size_t base_key_len = 0;
mbedtls_ssl_tls13_handshake_secrets *tls13_hs_secrets =
&ssl->handshake->tls13_hs_secrets;
if( from == MBEDTLS_SSL_IS_CLIENT )
{
base_key = tls13_hs_secrets->client_handshake_traffic_secret;
base_key_len = sizeof( tls13_hs_secrets->client_handshake_traffic_secret );
}
else
{
base_key = tls13_hs_secrets->server_handshake_traffic_secret;
base_key_len = sizeof( tls13_hs_secrets->server_handshake_traffic_secret );
}
mbedtls_md_type_t const md_type = ssl->handshake->ciphersuite_info->mac;
const mbedtls_md_info_t* const md_info =
@ -681,11 +692,6 @@ int mbedtls_ssl_tls13_calculate_verify_data( mbedtls_ssl_context* ssl,
}
MBEDTLS_SSL_DEBUG_BUF( 4, "handshake hash", transcript, transcript_len );
if( from == MBEDTLS_SSL_IS_CLIENT )
base_key = tls13_hs_secrets->client_handshake_traffic_secret;
else
base_key = tls13_hs_secrets->server_handshake_traffic_secret;
ret = ssl_tls13_calc_finished_core( md_type, base_key, transcript, dst );
if( ret != 0 )
goto exit;
@ -696,16 +702,7 @@ int mbedtls_ssl_tls13_calculate_verify_data( mbedtls_ssl_context* ssl,
exit:
/* Erase handshake secrets */
if( from == MBEDTLS_SSL_IS_CLIENT )
{
mbedtls_platform_zeroize( base_key,
sizeof( tls13_hs_secrets->client_handshake_traffic_secret ) );
}
else
{
mbedtls_platform_zeroize( base_key,
sizeof( tls13_hs_secrets->server_handshake_traffic_secret ) );
}
mbedtls_platform_zeroize( base_key, base_key_len );
mbedtls_platform_zeroize( transcript, sizeof( transcript ) );
return( ret );
}