GET macros use a target variable
The GET macros used to write to a macro parameter, but now
they can be used to assign a value to the desired variable
rather than pass it in as an argument and have it modified
in the macro function.
Due to this MBEDTLS_BYTES_TO_U32_LE is the same as
MBEDTLS_GET_UINT32_LE and was there for replaced in the
appropriate files and removed from common.h
Signed-off-by: Joe Subbiani <joe.subbiani@arm.com>
diff --git a/library/common.h b/library/common.h
index 5115465..4ecc016 100644
--- a/library/common.h
+++ b/library/common.h
@@ -78,38 +78,45 @@
#define MBEDTLS_BYTE_3( x ) ( (uint8_t) ( ( ( x ) >> 24 ) & 0xff ) )
/**
- * 32-bit integer manipulation macros
+ * 32-bit integer manipulation GET macros (big endian)
*
- * \brief Using GET-
- * From input data, take the most significant bytes
- * and concatonate them as you shift along
- * Using PUT-
- * Read from a 32 bit integer and store each byte
- * in memory, offset by a byte each, resulting in
- * each byte being adjacent in memory.
+ * \brief Use this to assign an unsigned 32 bit integer
+ * by taking data stored adjacent in memory that
+ * can be accessed via on offset
+ * Big Endian is used when wanting to
+ * transmit the most signifcant bits first
*
- * \param n 32 bit integer where data is accessed via
- * PUT or stored using GET
+ * \param data The data used to translate to a 32 bit
+ * integer
+ * \param offset the shift in bytes to access the next byte
+ * of data
+ */
+#ifndef MBEDTLS_GET_UINT32_BE
+#define MBEDTLS_GET_UINT32_BE( data , offset ) \
+ ( \
+ ( (uint32_t) ( data )[( offset ) ] << 24 ) \
+ | ( (uint32_t) ( data )[( offset ) + 1] << 16 ) \
+ | ( (uint32_t) ( data )[( offset ) + 2] << 8 ) \
+ | ( (uint32_t) ( data )[( offset ) + 3] ) \
+ )
+#endif
+
+/**
+ * 32-bit integer manipulation PUT macros (big endian)
+ *
+ * \brief Read from a 32 bit integer and store each byte
+ * in memory, offset by a specified amount, resulting
+ * in each byte being adjacent in memory.
+ * Big Endian is used when wanting to
+ * transmit the most signifcant bits first
+ *
+ * \param n 32 bit integer where data is accessed
* \param b const unsigned char array of data to be
* manipulated
* \param i offset in bytes, In the case of UINT32, i
* would increment by 4 every use assuming
* the data is being stored in the same location
*/
-
-/**
- * 32-bit integer manipulation macros (big endian)
- */
-#ifndef MBEDTLS_GET_UINT32_BE
-#define MBEDTLS_GET_UINT32_BE(n,b,i) \
- do { \
- (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
- | ( (uint32_t) (b)[(i) + 1] << 16 ) \
- | ( (uint32_t) (b)[(i) + 2] << 8 ) \
- | ( (uint32_t) (b)[(i) + 3] ); \
- } while( 0 )
-#endif
-
#ifndef MBEDTLS_PUT_UINT32_BE
#define MBEDTLS_PUT_UINT32_BE(n,b,i) \
do { \
@@ -121,18 +128,45 @@
#endif
/**
- * 32-bit integer manipulation macros (little endian)
+ * 32-bit integer manipulation GET macros (little endian)
+ *
+ * \brief Use this to assign an unsigned 32 bit integer
+ * by taking data stored adjacent in memory that
+ * can be accessed via on offset
+ * Little Endian is used when wanting to
+ * transmit the least signifcant bits first
+ *
+ * \param data The data used to translate to a 32 bit
+ * integer
+ * \param offset the shift in bytes to access the next byte
+ * of data
*/
#ifndef MBEDTLS_GET_UINT32_LE
-#define MBEDTLS_GET_UINT32_LE(n,b,i) \
- do { \
- (n) = ( (uint32_t) (b)[(i) ] ) \
- | ( (uint32_t) (b)[(i) + 1] << 8 ) \
- | ( (uint32_t) (b)[(i) + 2] << 16 ) \
- | ( (uint32_t) (b)[(i) + 3] << 24 ); \
- } while( 0 )
+#define MBEDTLS_GET_UINT32_LE( data, offset ) \
+ ( \
+ ( (uint32_t) ( data )[( offset ) ] ) \
+ | ( (uint32_t) ( data )[( offset ) + 1] << 8 ) \
+ | ( (uint32_t) ( data )[( offset ) + 2] << 16 ) \
+ | ( (uint32_t) ( data )[( offset ) + 3] << 24 ) \
+ )
#endif
+/**
+ * 32-bit integer manipulation PUT macros (little endian)
+ *
+ * \brief Read from a 32 bit integer and store each byte
+ * in memory, offset by a specified amount, resulting
+ * in each byte being adjacent in memory.
+ * Little Endian is used when wanting to
+ * transmit the least signifcant bits first
+ *
+ * \param n 32 bit integer where data is accessed
+ * \param b const unsigned char array of data to be
+ * manipulated
+ * \param i offset in bytes, In the case of UINT32, i
+ * would increment by 4 every use assuming
+ * the data is being stored in the same location
+ */
#ifndef MBEDTLS_PUT_UINT32_LE
#define MBEDTLS_PUT_UINT32_LE(n,b,i) \
do { \
@@ -144,46 +178,43 @@
#endif
/**
- * 32-bit integer conversion from bytes (little endian)
+ * 16-bit integer manipulation GET macros (little endian)
+ *
+ * \brief Use this to assign an unsigned 16 bit integer
+ * by taking data stored adjacent in memory that
+ * can be accessed via on offset
+ * Little Endian is used when wanting to
+ * transmit the least signifcant bits first
+ *
+ * \param data The data used to translate to a 16 bit
+ * integer
+ * \param offset the shit in bytes to access the next byte
+ * of data
*/
-#define MBEDTLS_BYTES_TO_U32_LE( data, offset ) \
- ( (uint32_t) (data)[offset] \
- | (uint32_t) ( (uint32_t) (data)[( offset ) + 1] << 8 ) \
- | (uint32_t) ( (uint32_t) (data)[( offset ) + 2] << 16 ) \
- | (uint32_t) ( (uint32_t) (data)[( offset ) + 3] << 24 ) \
+#ifndef MBEDTLS_GET_UINT16_LE
+#define MBEDTLS_GET_UINT16_LE( data, offset ) \
+ ( \
+ ( (uint16_t) ( data )[( offset ) ] ) \
+ | ( (uint16_t) ( data )[( offset ) + 1] << 8 ) \
)
+#endif
/**
- * 16-bit integer manipulation macros
+ * 16-bit integer manipulation PUT macros (little endian)
*
- * \brief Using GET-
- * From input data, take the most significant bytes
- * and concatonate them as you shift along
- * Using PUT-
- * Read from a 16 bit integer and store each byte
- * in memory, offset by a byte each, resulting in
- * each byte being adjacent in memory.
+ * \brief Read from a 16 bit integer and store each byte
+ * in memory, offset by a specified amount, resulting
+ * in each byte being adjacent in memory.
+ * Little Endian is used when wanting to
+ * transmit the least signifcant bits first
*
- * \param n 16 bit integer where data is accessed via
- * PUT or stored using GET
+ * \param n 16 bit integer where data is accessed
* \param b const unsigned char array of data to be
* manipulated
* \param i offset in bytes, In the case of UINT16, i
* would increment by 2 every use assuming
* the data is being stored in the same location
*/
-
-/**
- * 16-bit integer manipulation macros (little endian)
- */
-#ifndef MBEDTLS_GET_UINT16_LE
-#define MBEDTLS_GET_UINT16_LE( n, b, i ) \
-{ \
- (n) = ( (uint16_t) (b)[(i) ] ) \
- | ( (uint16_t) (b)[(i) + 1] << 8 ); \
-}
-#endif
-
#ifndef MBEDTLS_PUT_UINT16_LE
#define MBEDTLS_PUT_UINT16_LE( n, b, i ) \
{ \