mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-11 12:45:39 +00:00
Review corrections 2
-Fix MSVC compiler warnings about size_t to uint32_t conversions by updating GET/PUT functions signature to use size_t. -Add type casts to functions calling GET/PUT conversions -Remove additional space after return statement
This commit is contained in:
parent
6e3f09b431
commit
4f4849a379
|
@ -201,7 +201,7 @@ struct tm *mbedtls_platform_gmtime_r( const mbedtls_time_t *tt,
|
|||
* \return Address to end of buffer where number is written.
|
||||
*/
|
||||
unsigned char* mbedtls_platform_put_uint32_be( unsigned char *buf,
|
||||
uint32_t num );
|
||||
size_t num );
|
||||
|
||||
/**
|
||||
* \brief Convert 24-bit number to big endian format.
|
||||
|
@ -215,7 +215,7 @@ unsigned char* mbedtls_platform_put_uint32_be( unsigned char *buf,
|
|||
* \return Address to end of buffer where number is written.
|
||||
*/
|
||||
unsigned char* mbedtls_platform_put_uint24_be( unsigned char *buf,
|
||||
uint32_t num );
|
||||
size_t num );
|
||||
|
||||
/**
|
||||
* \brief Convert 16-bit number to big endian format.
|
||||
|
@ -229,7 +229,7 @@ unsigned char* mbedtls_platform_put_uint24_be( unsigned char *buf,
|
|||
* \return Address to end of buffer where number is written.
|
||||
*/
|
||||
unsigned char* mbedtls_platform_put_uint16_be( unsigned char *buf,
|
||||
uint32_t num );
|
||||
size_t num );
|
||||
|
||||
/**
|
||||
* \brief Convert 32-bit number from big endian format.
|
||||
|
@ -241,7 +241,7 @@ unsigned char* mbedtls_platform_put_uint16_be( unsigned char *buf,
|
|||
*
|
||||
* \return Converted number.
|
||||
*/
|
||||
uint32_t mbedtls_platform_get_uint32_be( const unsigned char *buf );
|
||||
size_t mbedtls_platform_get_uint32_be( const unsigned char *buf );
|
||||
|
||||
/**
|
||||
* \brief Convert 24-bit number from big endian format.
|
||||
|
@ -253,7 +253,7 @@ uint32_t mbedtls_platform_get_uint32_be( const unsigned char *buf );
|
|||
*
|
||||
* \return Converted number.
|
||||
*/
|
||||
uint32_t mbedtls_platform_get_uint24_be( const unsigned char *buf );
|
||||
size_t mbedtls_platform_get_uint24_be( const unsigned char *buf );
|
||||
|
||||
/**
|
||||
* \brief Convert 16-bit number from big endian format.
|
||||
|
@ -265,7 +265,7 @@ uint32_t mbedtls_platform_get_uint24_be( const unsigned char *buf );
|
|||
*
|
||||
* \return Converted number.
|
||||
*/
|
||||
uint16_t mbedtls_platform_get_uint16_be( const unsigned char *buf );
|
||||
size_t mbedtls_platform_get_uint16_be( const unsigned char *buf );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -136,7 +136,7 @@ struct tm *mbedtls_platform_gmtime_r( const mbedtls_time_t *tt,
|
|||
#endif /* MBEDTLS_HAVE_TIME_DATE && MBEDTLS_PLATFORM_GMTIME_R_ALT */
|
||||
|
||||
unsigned char* mbedtls_platform_put_uint32_be( unsigned char *buf,
|
||||
uint32_t num )
|
||||
size_t num )
|
||||
{
|
||||
*buf++ = (unsigned char) ( num >> 24 );
|
||||
*buf++ = (unsigned char) ( num >> 16 );
|
||||
|
@ -147,7 +147,7 @@ unsigned char* mbedtls_platform_put_uint32_be( unsigned char *buf,
|
|||
}
|
||||
|
||||
unsigned char* mbedtls_platform_put_uint24_be( unsigned char *buf,
|
||||
uint32_t num )
|
||||
size_t num )
|
||||
{
|
||||
*buf++ = (unsigned char) ( num >> 16 );
|
||||
*buf++ = (unsigned char) ( num >> 8 );
|
||||
|
@ -157,7 +157,7 @@ unsigned char* mbedtls_platform_put_uint24_be( unsigned char *buf,
|
|||
}
|
||||
|
||||
unsigned char* mbedtls_platform_put_uint16_be( unsigned char *buf,
|
||||
uint32_t num )
|
||||
size_t num )
|
||||
{
|
||||
*buf++ = (unsigned char) ( num >> 8 );
|
||||
*buf++ = (unsigned char) ( num );
|
||||
|
@ -165,7 +165,7 @@ unsigned char* mbedtls_platform_put_uint16_be( unsigned char *buf,
|
|||
return buf;
|
||||
}
|
||||
|
||||
uint32_t mbedtls_platform_get_uint32_be( const unsigned char *buf )
|
||||
size_t mbedtls_platform_get_uint32_be( const unsigned char *buf )
|
||||
{
|
||||
return ( ( (unsigned int) buf[0] << 24 ) |
|
||||
( (unsigned int) buf[1] << 16 ) |
|
||||
|
@ -173,14 +173,14 @@ uint32_t mbedtls_platform_get_uint32_be( const unsigned char *buf )
|
|||
( (unsigned int) buf[3] ) );
|
||||
}
|
||||
|
||||
uint32_t mbedtls_platform_get_uint24_be( const unsigned char *buf )
|
||||
size_t mbedtls_platform_get_uint24_be( const unsigned char *buf )
|
||||
{
|
||||
return ( ( buf[0] << 16 ) |
|
||||
( buf[1] << 8) |
|
||||
( buf[2] ) );
|
||||
}
|
||||
|
||||
uint16_t mbedtls_platform_get_uint16_be( const unsigned char *buf )
|
||||
size_t mbedtls_platform_get_uint16_be( const unsigned char *buf )
|
||||
{
|
||||
return ( ( buf[0] << 8 ) |
|
||||
( buf[1] ) );
|
||||
|
|
|
@ -199,7 +199,7 @@ int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
|
|||
for( i = 0; i < 64; i++ )
|
||||
{
|
||||
if( i < 16 )
|
||||
W[i] = mbedtls_platform_get_uint32_be( &data[4 * i] );
|
||||
W[i] = (uint32_t)mbedtls_platform_get_uint32_be( &data[4 * i] );
|
||||
else
|
||||
R( i );
|
||||
|
||||
|
@ -210,7 +210,7 @@ int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
|
|||
}
|
||||
#else /* MBEDTLS_SHA256_SMALLER */
|
||||
for( i = 0; i < 16; i++ )
|
||||
W[i] = mbedtls_platform_get_uint32_be( &data[4 * i] );
|
||||
W[i] = (uint32_t)mbedtls_platform_get_uint32_be( &data[4 * i] );
|
||||
|
||||
for( i = 0; i < 16; i += 8 )
|
||||
{
|
||||
|
|
|
@ -1707,7 +1707,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl )
|
|||
#endif /* !MBEDTLS_SSL_CONF_FIXED_MAJOR_VER */
|
||||
}
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "server hello, current time: %lu", mbedtls_platform_get_uint32_be(&buf[2])) );
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "server hello, current time: %lu", (unsigned long)mbedtls_platform_get_uint32_be(&buf[2])) );
|
||||
|
||||
memcpy( ssl->handshake->randbytes + 32, buf + 2, 32 );
|
||||
|
||||
|
@ -1750,7 +1750,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl )
|
|||
}
|
||||
|
||||
/* ciphersuite (used later) */
|
||||
i = mbedtls_platform_get_uint16_be( &buf[ 35 + n ] );
|
||||
i = (int)mbedtls_platform_get_uint16_be( &buf[ 35 + n ] );
|
||||
|
||||
/*
|
||||
* Read and check compression
|
||||
|
@ -4056,7 +4056,7 @@ static int ssl_parse_new_session_ticket( mbedtls_ssl_context *ssl )
|
|||
|
||||
msg = ssl->in_msg + mbedtls_ssl_hs_hdr_len( ssl );
|
||||
|
||||
lifetime = mbedtls_platform_get_uint32_be( msg );
|
||||
lifetime = (uint32_t)mbedtls_platform_get_uint32_be( msg );
|
||||
|
||||
ticket_len = mbedtls_platform_get_uint16_be( &msg[4] );
|
||||
|
||||
|
|
|
@ -238,7 +238,7 @@ int mbedtls_ssl_cookie_check( void *p_ctx,
|
|||
cur_time = ctx->serial;
|
||||
#endif
|
||||
|
||||
cookie_time = mbedtls_platform_get_uint32_be( cookie );
|
||||
cookie_time = (unsigned long)mbedtls_platform_get_uint32_be( cookie );
|
||||
|
||||
if( ctx->timeout != 0 && cur_time - cookie_time > ctx->timeout )
|
||||
return( -1 );
|
||||
|
|
|
@ -756,7 +756,8 @@ static int ssl_check_key_curve( mbedtls_pk_context *pk,
|
|||
|
||||
while( ec_tls_ids_len-- != 0 )
|
||||
{
|
||||
uint16_t const cur_tls_id = mbedtls_platform_get_uint16_be( acceptable_ec_tls_ids );
|
||||
uint16_t const cur_tls_id = (uint16_t)
|
||||
mbedtls_platform_get_uint16_be( acceptable_ec_tls_ids );
|
||||
|
||||
if( cur_tls_id == tls_id )
|
||||
return( 0 );
|
||||
|
@ -1166,9 +1167,9 @@ static int ssl_parse_client_hello_v2( mbedtls_ssl_context *ssl )
|
|||
*/
|
||||
MBEDTLS_SSL_DEBUG_BUF( 4, "record contents", buf, n );
|
||||
|
||||
ciph_len = mbedtls_platform_get_uint16_be( &buf[0] );
|
||||
sess_len = mbedtls_platform_get_uint16_be( &buf[2] );
|
||||
chal_len = mbedtls_platform_get_uint16_be( &buf[4] );
|
||||
ciph_len = (unsigned int)mbedtls_platform_get_uint16_be( &buf[0] );
|
||||
sess_len = (unsigned int)mbedtls_platform_get_uint16_be( &buf[2] );
|
||||
chal_len = (unsigned int)mbedtls_platform_get_uint16_be( &buf[4] );
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "ciph_len: %d, sess_len: %d, chal_len: %d",
|
||||
ciph_len, sess_len, chal_len ) );
|
||||
|
@ -1582,7 +1583,8 @@ read_record_header:
|
|||
if( ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS )
|
||||
{
|
||||
/* This couldn't be done in ssl_prepare_handshake_record() */
|
||||
unsigned int cli_msg_seq = mbedtls_platform_get_uint16_be( &ssl->in_msg[4] );
|
||||
unsigned int cli_msg_seq = (unsigned int)
|
||||
mbedtls_platform_get_uint16_be( &ssl->in_msg[4] );
|
||||
|
||||
if( cli_msg_seq != ssl->handshake->in_msg_seq )
|
||||
{
|
||||
|
@ -1597,7 +1599,8 @@ read_record_header:
|
|||
else
|
||||
#endif
|
||||
{
|
||||
unsigned int cli_msg_seq = mbedtls_platform_get_uint16_be( &ssl->in_msg[4] );
|
||||
unsigned int cli_msg_seq = (unsigned int)
|
||||
mbedtls_platform_get_uint16_be( &ssl->in_msg[4] );
|
||||
|
||||
ssl->handshake->out_msg_seq = cli_msg_seq;
|
||||
ssl->handshake->in_msg_seq = cli_msg_seq + 1;
|
||||
|
|
|
@ -497,7 +497,7 @@ static unsigned int ssl_mfl_code_to_length( int mfl )
|
|||
switch( mfl )
|
||||
{
|
||||
case MBEDTLS_SSL_MAX_FRAG_LEN_NONE:
|
||||
return ( MBEDTLS_TLS_EXT_ADV_CONTENT_LEN );
|
||||
return( MBEDTLS_TLS_EXT_ADV_CONTENT_LEN );
|
||||
case MBEDTLS_SSL_MAX_FRAG_LEN_512:
|
||||
return 512;
|
||||
case MBEDTLS_SSL_MAX_FRAG_LEN_1024:
|
||||
|
@ -507,7 +507,7 @@ static unsigned int ssl_mfl_code_to_length( int mfl )
|
|||
case MBEDTLS_SSL_MAX_FRAG_LEN_4096:
|
||||
return 4096;
|
||||
default:
|
||||
return ( MBEDTLS_TLS_EXT_ADV_CONTENT_LEN );
|
||||
return( MBEDTLS_TLS_EXT_ADV_CONTENT_LEN );
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
|
||||
|
@ -2186,6 +2186,8 @@ int mbedtls_ssl_psk_derive_premaster( mbedtls_ssl_context *ssl, mbedtls_key_exch
|
|||
p = mbedtls_platform_put_uint16_be( p, zlen );
|
||||
p += zlen;
|
||||
|
||||
MBEDTLS_SSL_DEBUG_ECDH( 3, &ssl->handshake->ecdh_ctx,
|
||||
MBEDTLS_DEBUG_ECDH_Z );
|
||||
}
|
||||
else
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED */
|
||||
|
@ -4624,12 +4626,12 @@ static int ssl_hs_is_proper_fragment( mbedtls_ssl_context *ssl )
|
|||
|
||||
static uint32_t ssl_get_hs_frag_len( mbedtls_ssl_context const *ssl )
|
||||
{
|
||||
return ( mbedtls_platform_get_uint24_be( &ssl->in_msg[9] ) );
|
||||
return( (uint32_t)mbedtls_platform_get_uint24_be( &ssl->in_msg[9] ) );
|
||||
}
|
||||
|
||||
static uint32_t ssl_get_hs_frag_off( mbedtls_ssl_context const *ssl )
|
||||
{
|
||||
return ( mbedtls_platform_get_uint24_be( &ssl->in_msg[6] ) );
|
||||
return( (uint32_t)mbedtls_platform_get_uint24_be( &ssl->in_msg[6] ) );
|
||||
}
|
||||
|
||||
static int ssl_check_hs_header( mbedtls_ssl_context const *ssl )
|
||||
|
@ -4732,7 +4734,7 @@ static size_t ssl_get_reassembly_buffer_size( size_t msg_len,
|
|||
|
||||
static uint32_t ssl_get_hs_total_len( mbedtls_ssl_context const *ssl )
|
||||
{
|
||||
return ( mbedtls_platform_get_uint24_be( &ssl->in_msg[1] ) );
|
||||
return( (uint32_t)mbedtls_platform_get_uint24_be( &ssl->in_msg[1] ) );
|
||||
}
|
||||
|
||||
int mbedtls_ssl_prepare_handshake_record( mbedtls_ssl_context *ssl )
|
||||
|
@ -4754,7 +4756,8 @@ int mbedtls_ssl_prepare_handshake_record( mbedtls_ssl_context *ssl )
|
|||
if( MBEDTLS_SSL_TRANSPORT_IS_DTLS( ssl->conf->transport ) )
|
||||
{
|
||||
int ret;
|
||||
unsigned int recv_msg_seq = mbedtls_platform_get_uint16_be( &ssl->in_msg[4] );
|
||||
unsigned int recv_msg_seq = (unsigned int)
|
||||
mbedtls_platform_get_uint16_be( &ssl->in_msg[4] );
|
||||
|
||||
if( ssl_check_hs_header( ssl ) != 0 )
|
||||
{
|
||||
|
@ -5427,7 +5430,8 @@ static int ssl_parse_record_header( mbedtls_ssl_context const *ssl,
|
|||
#if defined(MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE) && defined(MBEDTLS_SSL_SRV_C)
|
||||
static int ssl_check_client_reconnect( mbedtls_ssl_context *ssl )
|
||||
{
|
||||
unsigned int rec_epoch = mbedtls_platform_get_uint16_be( &ssl->in_ctr[0] );
|
||||
unsigned int rec_epoch = (unsigned int)
|
||||
mbedtls_platform_get_uint16_be( &ssl->in_ctr[0] );
|
||||
|
||||
/*
|
||||
* Check for an epoch 0 ClientHello. We can't use in_msg here to
|
||||
|
@ -5774,7 +5778,7 @@ static int ssl_load_buffered_message( mbedtls_ssl_context *ssl )
|
|||
if( ( hs_buf->is_valid == 1 ) && ( hs_buf->is_complete == 1 ) )
|
||||
{
|
||||
/* Synthesize a record containing the buffered HS message. */
|
||||
size_t msg_len = mbedtls_platform_get_uint24_be( &hs_buf->data[1] );
|
||||
uint32_t msg_len = (uint32_t)mbedtls_platform_get_uint24_be( &hs_buf->data[1] );
|
||||
|
||||
/* Double-check that we haven't accidentally buffered
|
||||
* a message that doesn't fit into the input buffer. */
|
||||
|
@ -5873,7 +5877,8 @@ static int ssl_buffer_message( mbedtls_ssl_context *ssl )
|
|||
case MBEDTLS_SSL_MSG_HANDSHAKE:
|
||||
{
|
||||
unsigned recv_msg_seq_offset;
|
||||
unsigned recv_msg_seq = mbedtls_platform_get_uint16_be( &ssl->in_msg[4] );
|
||||
unsigned recv_msg_seq = (unsigned)
|
||||
mbedtls_platform_get_uint16_be( &ssl->in_msg[4] );
|
||||
|
||||
mbedtls_ssl_hs_buffer *hs_buf;
|
||||
size_t msg_len = ssl->in_hslen - 12;
|
||||
|
@ -9446,7 +9451,7 @@ static size_t ssl_get_current_mtu( const mbedtls_ssl_context *ssl )
|
|||
if( mbedtls_ssl_conf_get_endpoint( ssl->conf ) == MBEDTLS_SSL_IS_CLIENT &&
|
||||
( ssl->state == MBEDTLS_SSL_CLIENT_HELLO ||
|
||||
ssl->state == MBEDTLS_SSL_SERVER_HELLO ) )
|
||||
return ( 0 );
|
||||
return( 0 );
|
||||
|
||||
if( ssl->handshake == NULL || ssl->handshake->mtu == 0 )
|
||||
return( ssl->mtu );
|
||||
|
@ -9974,7 +9979,7 @@ static int ssl_session_load( mbedtls_ssl_session *session,
|
|||
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
|
||||
}
|
||||
|
||||
ciphersuite = mbedtls_platform_get_uint16_be( p );
|
||||
ciphersuite = (int)mbedtls_platform_get_uint16_be( p );
|
||||
p += 2;
|
||||
|
||||
#if !defined(MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE)
|
||||
|
@ -9998,7 +10003,7 @@ static int ssl_session_load( mbedtls_ssl_session *session,
|
|||
memcpy( session->master, p, 48 );
|
||||
p += 48;
|
||||
|
||||
session->verify_result = mbedtls_platform_get_uint32_be( p );
|
||||
session->verify_result = (uint32_t)mbedtls_platform_get_uint32_be( p );
|
||||
p += 4;
|
||||
|
||||
/* Immediately clear invalid pointer values that have been read, in case
|
||||
|
@ -10113,7 +10118,7 @@ static int ssl_session_load( mbedtls_ssl_session *session,
|
|||
if( 4 > (size_t)( end - p ) )
|
||||
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
|
||||
|
||||
session->ticket_lifetime = mbedtls_platform_get_uint32_be( p );
|
||||
session->ticket_lifetime = (uint32_t)mbedtls_platform_get_uint32_be( p );
|
||||
p += 4;
|
||||
#endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
|
||||
|
||||
|
@ -11500,7 +11505,7 @@ static int ssl_context_load( mbedtls_ssl_context *ssl,
|
|||
if( (size_t)( end - p ) < 4 )
|
||||
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
|
||||
|
||||
ssl->badmac_seen = mbedtls_platform_get_uint32_be( p );
|
||||
ssl->badmac_seen = (unsigned)mbedtls_platform_get_uint32_be( p );
|
||||
p += 4;
|
||||
#endif /* MBEDTLS_SSL_DTLS_BADMAC_LIMIT */
|
||||
|
||||
|
@ -11545,8 +11550,7 @@ static int ssl_context_load( mbedtls_ssl_context *ssl,
|
|||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
if( (size_t)( end - p ) < 2 )
|
||||
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
|
||||
|
||||
ssl->mtu = mbedtls_platform_get_uint16_be( p );
|
||||
ssl->mtu = (uint16_t)mbedtls_platform_get_uint16_be( p );
|
||||
p += 2;
|
||||
#endif /* MBEDTLS_SSL_PROTO_DTLS */
|
||||
|
||||
|
|
Loading…
Reference in a new issue