Use byte reading macros in places not using a byte mask
byte shifting opertations throughout library/ were only replaced with
the byte reading macros when an 0xff mask was being used.
The byte reading macros are now more widley used, however they have not
been used in all cases of a byte shift operation, as it detracted from
the immediate readability or otherwise did not seem appropriate.
Signed-off-by: Joe Subbiani <joe.subbiani@arm.com>
diff --git a/library/chachapoly.c b/library/chachapoly.c
index 77d5477..696d97b 100644
--- a/library/chachapoly.c
+++ b/library/chachapoly.c
@@ -263,22 +263,22 @@
/* The lengths of the AAD and ciphertext are processed by
* Poly1305 as the final 128-bit block, encoded as little-endian integers.
*/
- len_block[ 0] = (unsigned char)( ctx->aad_len );
- len_block[ 1] = (unsigned char)( ctx->aad_len >> 8 );
- len_block[ 2] = (unsigned char)( ctx->aad_len >> 16 );
- len_block[ 3] = (unsigned char)( ctx->aad_len >> 24 );
- len_block[ 4] = (unsigned char)( ctx->aad_len >> 32 );
- len_block[ 5] = (unsigned char)( ctx->aad_len >> 40 );
- len_block[ 6] = (unsigned char)( ctx->aad_len >> 48 );
- len_block[ 7] = (unsigned char)( ctx->aad_len >> 56 );
- len_block[ 8] = (unsigned char)( ctx->ciphertext_len );
- len_block[ 9] = (unsigned char)( ctx->ciphertext_len >> 8 );
- len_block[10] = (unsigned char)( ctx->ciphertext_len >> 16 );
- len_block[11] = (unsigned char)( ctx->ciphertext_len >> 24 );
- len_block[12] = (unsigned char)( ctx->ciphertext_len >> 32 );
- len_block[13] = (unsigned char)( ctx->ciphertext_len >> 40 );
- len_block[14] = (unsigned char)( ctx->ciphertext_len >> 48 );
- len_block[15] = (unsigned char)( ctx->ciphertext_len >> 56 );
+ len_block[ 0] = MBEDTLS_BYTE_0( ctx->aad_len );
+ len_block[ 1] = MBEDTLS_BYTE_1( ctx->aad_len );
+ len_block[ 2] = MBEDTLS_BYTE_2( ctx->aad_len );
+ len_block[ 3] = MBEDTLS_BYTE_3( ctx->aad_len );
+ len_block[ 4] = MBEDTLS_BYTE_4( ctx->aad_len );
+ len_block[ 5] = MBEDTLS_BYTE_5( ctx->aad_len );
+ len_block[ 6] = MBEDTLS_BYTE_6( ctx->aad_len );
+ len_block[ 7] = MBEDTLS_BYTE_7( ctx->aad_len );
+ len_block[ 8] = MBEDTLS_BYTE_0( ctx->ciphertext_len );
+ len_block[ 9] = MBEDTLS_BYTE_1( ctx->ciphertext_len );
+ len_block[10] = MBEDTLS_BYTE_2( ctx->ciphertext_len );
+ len_block[11] = MBEDTLS_BYTE_3( ctx->ciphertext_len );
+ len_block[12] = MBEDTLS_BYTE_4( ctx->ciphertext_len );
+ len_block[13] = MBEDTLS_BYTE_5( ctx->ciphertext_len );
+ len_block[14] = MBEDTLS_BYTE_6( ctx->ciphertext_len );
+ len_block[15] = MBEDTLS_BYTE_7( ctx->ciphertext_len );
ret = mbedtls_poly1305_update( &ctx->poly1305_ctx, len_block, 16U );
if( ret != 0 )