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
diff --git a/library/platform_util.c b/library/platform_util.c
index 062aa3e..8f8a3aa 100644
--- a/library/platform_util.c
+++ b/library/platform_util.c
@@ -136,7 +136,7 @@
#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_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_uint16_be( unsigned char *buf,
- uint32_t num )
+ size_t num )
{
*buf++ = (unsigned char) ( num >> 8 );
*buf++ = (unsigned char) ( num );
@@ -165,7 +165,7 @@
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 @@
( (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] ) );
diff --git a/library/sha256.c b/library/sha256.c
index 1c1df02..314cb2c 100644
--- a/library/sha256.c
+++ b/library/sha256.c
@@ -199,7 +199,7 @@
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 @@
}
#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 )
{
diff --git a/library/ssl_cli.c b/library/ssl_cli.c
index 530b067..331285f 100644
--- a/library/ssl_cli.c
+++ b/library/ssl_cli.c
@@ -1707,7 +1707,7 @@
#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 @@
}
/* 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 @@
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] );
diff --git a/library/ssl_cookie.c b/library/ssl_cookie.c
index a06cc3c..67f9114 100644
--- a/library/ssl_cookie.c
+++ b/library/ssl_cookie.c
@@ -238,7 +238,7 @@
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 );
diff --git a/library/ssl_srv.c b/library/ssl_srv.c
index 4601574..fa073e4 100644
--- a/library/ssl_srv.c
+++ b/library/ssl_srv.c
@@ -756,7 +756,8 @@
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 @@
*/
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 @@
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 @@
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;
diff --git a/library/ssl_tls.c b/library/ssl_tls.c
index c8e7080..2829d65 100644
--- a/library/ssl_tls.c
+++ b/library/ssl_tls.c
@@ -497,7 +497,7 @@
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 @@
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 @@
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 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 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 @@
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 @@
#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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
#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 */