From 9b3b19407a31a04d859c3ccb31293ff2af1e9b50 Mon Sep 17 00:00:00 2001 From: Arto Kinnunen Date: Mon, 9 Sep 2019 17:02:35 +0300 Subject: [PATCH] Review corrections 4 - Try to follow english grammar in function documentation - Fix too long line - Remove additional brackets - Follow mbedtls coding style in for-statement --- include/mbedtls/platform_util.h | 62 ++++++++++++++++----------------- library/sha256.c | 4 +-- library/ssl_cli.c | 7 ++-- 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/include/mbedtls/platform_util.h b/include/mbedtls/platform_util.h index 01e7f3052..fbb595a16 100644 --- a/include/mbedtls/platform_util.h +++ b/include/mbedtls/platform_util.h @@ -190,78 +190,76 @@ struct tm *mbedtls_platform_gmtime_r( const mbedtls_time_t *tt, #endif /* MBEDTLS_HAVE_TIME_DATE */ /** - * \brief Convert 32-bit number to big endian format. + * \brief Convert a 32-bit number to the big endian format and write it to + * the given buffer. * - * This function converts 32-bit number to big endian format and - * writes it to the given buffer. + * \param buf Address where the converted number is written. + * \param num A number that needs to be converted to the big endian format. * - * \param buf Address where converted number is written. - * \param num Number that needs to be converted to big endian. - * - * \return Address to end of buffer where number is written. + * \return Address to the end of buffer where the converted number is + * written. */ unsigned char* mbedtls_platform_put_uint32_be( unsigned char *buf, size_t num ); /** - * \brief Convert 24-bit number to big endian format. + * \brief Convert a 24-bit number to the big endian format and write it to + * the given buffer. * - * This function converts 24-bit number to big endian format and - * writes it to the given buffer. + * \param buf Address where the converted number is written. + * \param num A number that needs to be converted to the big endian format. * - * \param buf Address where converted number is written. - * \param num Number that needs to be converted to big endian. - * - * \return Address to end of buffer where number is written. + * \return Address to the end of buffer where the converted number is + * written. */ unsigned char* mbedtls_platform_put_uint24_be( unsigned char *buf, size_t num ); /** - * \brief Convert 16-bit number to big endian format. + * \brief Convert a 16-bit number to the big endian format and write it to + * the given buffer. * - * This function converts 16-bit number to big endian format and - * writes it to the given buffer. * - * \param buf Address where converted number is written. - * \param num Number that needs to be converted to big endian. + * \param buf Address where the converted number is written. + * \param num A number that needs to be converted to the big endian format. * - * \return Address to end of buffer where number is written. + * \return Address to the end of buffer where the converted number is + * written. */ unsigned char* mbedtls_platform_put_uint16_be( unsigned char *buf, size_t num ); /** - * \brief Convert 32-bit number from big endian format. + * \brief Convert a 32-bit number from the big endian format. * - * The function reads 32-bit number form Big Endian format and - * returns it to the caller. + * The function reads a 32-bit number from the given buffer in the + * big endian format and returns it to the caller. * - * \param buf Buffer where 32-bit number locates. + * \param buf Buffer where the 32-bit number locates. * * \return Converted number. */ size_t mbedtls_platform_get_uint32_be( const unsigned char *buf ); /** - * \brief Convert 24-bit number from big endian format. + * \brief Convert a 24-bit number from the big endian format. * - * The function reads 24-bit number form Big Endian format and - * returns it to the caller. + * The function reads a 14-bit number from the given buffer in the + * big endian format and returns it to the caller. * - * \param buf Buffer where 24-bit number locates. + * \param buf Buffer where the 24-bit number locates. * * \return Converted number. */ size_t mbedtls_platform_get_uint24_be( const unsigned char *buf ); /** - * \brief Convert 16-bit number from big endian format. + * \brief Convert a 16-bit number from the big endian format. * - * The function reads 16-bit number form Big Endian format and - * returns it to the caller. + * The function reads a 16-bit number from the given buffer in the + * big endian format and returns it to the caller. * - * \param buf Buffer where 16-bit number locates. + * \param buf Buffer where the 16-bit number locates. * * \return Converted number. */ diff --git a/library/sha256.c b/library/sha256.c index 314cb2c1a..d0bf54275 100644 --- a/library/sha256.c +++ b/library/sha256.c @@ -320,7 +320,7 @@ void mbedtls_sha256_update( mbedtls_sha256_context *ctx, int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, unsigned char output[32] ) { - int ret; + int ret, s_pos, o_pos; uint32_t used; uint32_t high, low; @@ -367,7 +367,7 @@ int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, * Output final state */ - for ( int s_pos = 0, o_pos = 0; s_pos < 7; s_pos++, o_pos += 4 ) + for( s_pos = 0, o_pos = 0; s_pos < 7; s_pos++, o_pos += 4 ) { mbedtls_platform_put_uint32_be( &output[o_pos], ctx->state[s_pos] ); } diff --git a/library/ssl_cli.c b/library/ssl_cli.c index 8ce158258..6b240afdf 100644 --- a/library/ssl_cli.c +++ b/library/ssl_cli.c @@ -281,8 +281,8 @@ static void ssl_write_supported_elliptic_curves_ext( mbedtls_ssl_context *ssl, } p = mbedtls_platform_put_uint16_be( p, MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES ); - p = mbedtls_platform_put_uint16_be( p, ( elliptic_curve_len + 2 ) ); - p = mbedtls_platform_put_uint16_be( p, ( elliptic_curve_len ) ); + p = mbedtls_platform_put_uint16_be( p, elliptic_curve_len + 2 ); + p = mbedtls_platform_put_uint16_be( p, elliptic_curve_len ); MBEDTLS_SSL_BEGIN_FOR_EACH_SUPPORTED_EC_TLS_ID( tls_id ) p = mbedtls_platform_put_uint16_be( p, tls_id ); @@ -1706,7 +1706,8 @@ 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", (unsigned long)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 );