From 46697da5b3b555148c7e5a46aaf70393c6a48eb3 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Sun, 14 Jan 2024 12:59:49 +0000 Subject: [PATCH] Make gcm counter increment more efficient Signed-off-by: Dave Rodgman --- library/gcm.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/library/gcm.c b/library/gcm.c index 20d55c0a89..c677ca4d70 100644 --- a/library/gcm.c +++ b/library/gcm.c @@ -401,12 +401,9 @@ int mbedtls_gcm_update_ad(mbedtls_gcm_context *ctx, /* Increment the counter. */ static void gcm_incr(unsigned char y[16]) { - size_t i; - for (i = 16; i > 12; i--) { - if (++y[i - 1] != 0) { - break; - } - } + uint32_t x = MBEDTLS_GET_UINT32_BE(y, 12); + x++; + MBEDTLS_PUT_UINT32_BE(x, y, 12); } /* Calculate and apply the encryption mask. Process use_len bytes of data,