Improve documentation and add more uses of MBEDTLS_PUT

minor changes, such as improving the documentation for the byte reading
macros, and using MBEDTLS_PUT_UINT16_xy in place of byte reading
macro combinations

Signed-off-by: Joe Subbiani <joe.subbiani@arm.com>
This commit is contained in:
Joe Subbiani 2021-07-21 15:22:47 +01:00
parent 896f4eeaf7
commit d3a3f21ad5
4 changed files with 5 additions and 8 deletions

View File

@ -221,8 +221,7 @@ static int ccm_auth_crypt( mbedtls_ccm_context *ctx, int mode, size_t length,
src = add;
memset( b, 0, 16 );
b[0] = MBEDTLS_BYTE_1( add_len );
b[1] = MBEDTLS_BYTE_0( add_len );
MBEDTLS_PUT_UINT16_BE( add_len, b, 0 );
use_len = len_left < 16 - 2 ? len_left : 16 - 2;
memcpy( b + 2, src, use_len );

View File

@ -61,9 +61,8 @@
/** Byte Reading Macros
*
* Obtain the most significant byte of x using 0xff
* Using MBEDTLS_BYTE_a will shift a*8 bits
* to retrieve the next byte of information
* Given a multi-byte integer \p x, MBEDTLS_BYTE_n retrieves the n-th
* byte from x, where byte 0 is the least significant byte.
*/
#define MBEDTLS_BYTE_0( x ) ( (uint8_t) ( ( x ) & 0xff ) )
#define MBEDTLS_BYTE_1( x ) ( (uint8_t) ( ( ( x ) >> 8 ) & 0xff ) )

View File

@ -1160,8 +1160,7 @@ int mbedtls_ecp_tls_write_group( const mbedtls_ecp_group *grp, size_t *olen,
/*
* Next two bytes are the namedcurve value
*/
buf[0] = MBEDTLS_BYTE_1( curve_info->tls_id );
buf[1] = MBEDTLS_BYTE_0( curve_info->tls_id );
MBEDTLS_PUT_UINT16_BE( curve_info->tls_id, buf, 0 );
return( 0 );
}

View File

@ -794,7 +794,7 @@ static int ssl_write_use_srtp_ext( mbedtls_ssl_context *ssl,
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_USE_SRTP );
*p++ = MBEDTLS_BYTE_1( ext_len & 0xFF00 );
*p++ = MBEDTLS_BYTE_1( ext_len );
*p++ = MBEDTLS_BYTE_0( ext_len );
/* protection profile length: 2*(ssl->conf->dtls_srtp_profile_list_len) */