Document common.h and remove changelog

Added documenttion comments to common.h and removed the changelog
as it is not really necessary for refactoring.

Also modified a comment in aria.c to be clearer

Signed-off-by: Joe Subbiani <joe.subbiani@arm.com>
This commit is contained in:
Joe Subbiani 2021-07-07 15:16:56 +01:00
parent 9fa9ac3612
commit 394bdd662b
3 changed files with 47 additions and 15 deletions
ChangeLog.d
library

@ -1,9 +0,0 @@
Changes
* Create 4 byte reading macros in library/common.h, used in files
within the same directory: MBEDTLS_BYTE_0... MBEDTLS_BYTE_3.
* Move the (PUT and GET) UINT32_ (BE and LE) macro functions into
library/common.h. Rename with the prefix MBEDTLS_ to satisfy
test/scripts/check-names.sh (e.g MBEDTLS_PUT_UINT32_LE).
* Move BYTES_TO_U32_LE macro function to library/common.h, also given
the prefix MBEDTLS_.
Fixes #4274.

@ -385,7 +385,8 @@ static void aria_fe_xor( uint32_t r[4], const uint32_t p[4],
* Big endian 128-bit rotation: r = a ^ (b <<< n), used only in key setup. * Big endian 128-bit rotation: r = a ^ (b <<< n), used only in key setup.
* *
* We chose to store bytes into 32-bit words in little-endian format (see * We chose to store bytes into 32-bit words in little-endian format (see
* GET/MBEDTLS_PUT_UINT32_LE) so we need to reverse bytes here. * MBEDTLS_GET_UINT32_LE / MBEDTLS_PUT_UINT32_LE ) so we need to reverse
* bytes here.
*/ */
static void aria_rot128( uint32_t r[4], const uint32_t a[4], static void aria_rot128( uint32_t r[4], const uint32_t a[4],
const uint32_t b[4], uint8_t n ) const uint32_t b[4], uint8_t n )

@ -68,15 +68,36 @@ extern void (*mbedtls_test_hook_test_fail)( const char * test, int line, const c
/** Byte Reading Macros /** Byte Reading Macros
* *
* To tidy up code and save horizontal and vertical space, use byte * Obtain the most significant byte of x using 0xff
* reading macros to cast * Using MBEDTLS_BYTE_a will shift a*8 bits
* to retrieve the next byte of information
*/ */
#define MBEDTLS_BYTE_0( x ) ( (uint8_t) ( ( x ) & 0xff ) ) #define MBEDTLS_BYTE_0( x ) ( (uint8_t) ( ( x ) & 0xff ) )
#define MBEDTLS_BYTE_1( x ) ( (uint8_t) ( ( ( x ) >> 8 ) & 0xff ) ) #define MBEDTLS_BYTE_1( x ) ( (uint8_t) ( ( ( x ) >> 8 ) & 0xff ) )
#define MBEDTLS_BYTE_2( x ) ( (uint8_t) ( ( ( x ) >> 16 ) & 0xff ) ) #define MBEDTLS_BYTE_2( x ) ( (uint8_t) ( ( ( x ) >> 16 ) & 0xff ) )
#define MBEDTLS_BYTE_3( x ) ( (uint8_t) ( ( ( x ) >> 24 ) & 0xff ) ) #define MBEDTLS_BYTE_3( x ) ( (uint8_t) ( ( ( x ) >> 24 ) & 0xff ) )
/* /**
* 32-bit integer manipulation macros
*
* \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.
*
* \param n 32 bit integer where data is accessed via
* PUT or stored using GET
* \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) * 32-bit integer manipulation macros (big endian)
*/ */
#ifndef MBEDTLS_GET_UINT32_BE #ifndef MBEDTLS_GET_UINT32_BE
@ -99,7 +120,7 @@ extern void (*mbedtls_test_hook_test_fail)( const char * test, int line, const c
} while( 0 ) } while( 0 )
#endif #endif
/* /**
* 32-bit integer manipulation macros (little endian) * 32-bit integer manipulation macros (little endian)
*/ */
#ifndef MBEDTLS_GET_UINT32_LE #ifndef MBEDTLS_GET_UINT32_LE
@ -132,8 +153,27 @@ extern void (*mbedtls_test_hook_test_fail)( const char * test, int line, const c
| (uint32_t) ( (uint32_t) (data)[( offset ) + 3] << 24 ) \ | (uint32_t) ( (uint32_t) (data)[( offset ) + 3] << 24 ) \
) )
/**
* 16-bit integer manipulation macros
*
* \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.
*
* \param n 16 bit integer where data is accessed via
* PUT or stored using GET
* \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) * 16-bit integer manipulation macros (little endian)
*/ */
#ifndef MBEDTLS_GET_UINT16_LE #ifndef MBEDTLS_GET_UINT16_LE