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>
diff --git a/library/ccm.c b/library/ccm.c
index 0188075..a21a37f 100644
--- a/library/ccm.c
+++ b/library/ccm.c
@@ -221,8 +221,7 @@
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 );
diff --git a/library/common.h b/library/common.h
index fb4194e..c35bc04 100644
--- a/library/common.h
+++ b/library/common.h
@@ -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 ) )
diff --git a/library/ecp.c b/library/ecp.c
index cc8a26c..7f9e104 100644
--- a/library/ecp.c
+++ b/library/ecp.c
@@ -1160,8 +1160,7 @@
/*
* 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 );
}
diff --git a/library/ssl_cli.c b/library/ssl_cli.c
index 3cdfca6..e37e63d 100644
--- a/library/ssl_cli.c
+++ b/library/ssl_cli.c
@@ -794,7 +794,7 @@
*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) */