From 6f632fc99e61266e5bb2cedf7f7ca9d3696c6736 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Thu, 17 Oct 2024 09:16:13 +0100 Subject: [PATCH] Size: improve counter increment operation Signed-off-by: Dave Rodgman --- tf-psa-crypto/drivers/builtin/src/chacha20.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tf-psa-crypto/drivers/builtin/src/chacha20.c b/tf-psa-crypto/drivers/builtin/src/chacha20.c index a62b731182ea..a4a12add6f6e 100644 --- a/tf-psa-crypto/drivers/builtin/src/chacha20.c +++ b/tf-psa-crypto/drivers/builtin/src/chacha20.c @@ -104,9 +104,12 @@ static inline uint32x4_t chacha20_neon_vrotlq_7_u32(uint32x4_t v) // Increment the 32-bit element within v that corresponds to the ChaCha20 counter static inline uint32x4_t chacha20_neon_inc_counter(uint32x4_t v) { - const uint32_t inc_const_scalar[4] = { 1, 0, 0, 0 }; - const uint32x4_t inc_const = vld1q_u32(inc_const_scalar); - return vaddq_u32(v, inc_const); + if (MBEDTLS_IS_BIG_ENDIAN) { + v[3]++; + } else { + v[0]++; + } + return v; } typedef struct {