diff --git a/library/chacha20.c b/library/chacha20.c index 0e057f0e3..658f04690 100644 --- a/library/chacha20.c +++ b/library/chacha20.c @@ -164,10 +164,7 @@ static void chacha20_block( const uint32_t initial_state[16], { size_t offset = i * 4U; - keystream[offset ] = MBEDTLS_BYTE_0( working_state[i] ); - keystream[offset + 1U] = MBEDTLS_BYTE_1( working_state[i] ); - keystream[offset + 2U] = MBEDTLS_BYTE_2( working_state[i] ); - keystream[offset + 3U] = MBEDTLS_BYTE_3( working_state[i] ); + MBEDTLS_PUT_UINT32_LE(working_state[i], keystream, offset); } mbedtls_platform_zeroize( working_state, sizeof( working_state ) ); diff --git a/library/chachapoly.c b/library/chachapoly.c index 696d97bf0..dc75b2030 100644 --- a/library/chachapoly.c +++ b/library/chachapoly.c @@ -263,22 +263,8 @@ int mbedtls_chachapoly_finish( mbedtls_chachapoly_context *ctx, /* 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] = 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 ); + MBEDTLS_PUT_UINT64_LE(ctx->aad_len, len_block, 0); + MBEDTLS_PUT_UINT64_LE(ctx->ciphertext_len, len_block, 8); ret = mbedtls_poly1305_update( &ctx->poly1305_ctx, len_block, 16U ); if( ret != 0 ) diff --git a/library/ssl_cookie.c b/library/ssl_cookie.c index b2260338b..071e55e9a 100644 --- a/library/ssl_cookie.c +++ b/library/ssl_cookie.c @@ -166,10 +166,7 @@ int mbedtls_ssl_cookie_write( void *p_ctx, t = ctx->serial++; #endif - (*p)[0] = MBEDTLS_BYTE_3( t ); - (*p)[1] = MBEDTLS_BYTE_2( t ); - (*p)[2] = MBEDTLS_BYTE_1( t ); - (*p)[3] = MBEDTLS_BYTE_0( t ); + MBEDTLS_PUT_UINT32_BE(t, *p, 0); *p += 4; #if defined(MBEDTLS_THREADING_C)