From af2c6cc9320eb455ea837ef5c17604346868782b Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Wed, 17 Dec 2025 16:04:25 +1000 Subject: [PATCH] AES-GCM ARM32/Thumb2 ASM: don't change aes->reg in decrypt OpenSSL compatability layer expects aes->reg to be unmodified by AES-GCM decrypt call. ARM32/Thumb2 assembly implementation modifies buffer. Keep a copy and restore aes->reg after call. --- wolfcrypt/src/aes.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/wolfcrypt/src/aes.c b/wolfcrypt/src/aes.c index 7a7263c92..cdc32c739 100644 --- a/wolfcrypt/src/aes.c +++ b/wolfcrypt/src/aes.c @@ -10561,9 +10561,18 @@ int wc_AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz, #if defined(WOLFSSL_ARMASM) #ifndef WOLFSSL_ARMASM_NO_HW_CRYPTO #ifndef __aarch64__ - ret = AES_GCM_decrypt_AARCH32(in, out, sz, iv, ivSz, authTag, authTagSz, - authIn, authInSz, (byte*)aes->key, aes->gcm.H, (byte*)aes->tmp, - (byte*)aes->reg, aes->rounds); + { + #ifdef OPENSSL_EXTRA + word32 reg[WC_AES_BLOCK_SIZE / sizeof(word32)]; + XMEMCPY(reg, aes->reg, sizeof(reg)); + #endif + ret = AES_GCM_decrypt_AARCH32(in, out, sz, iv, ivSz, authTag, authTagSz, + authIn, authInSz, (byte*)aes->key, aes->gcm.H, (byte*)aes->tmp, + (byte*)aes->reg, aes->rounds); + #ifdef OPENSSL_EXTRA + XMEMCPY(aes->reg, reg, sizeof(reg)); + #endif + } #else if (aes->use_aes_hw_crypto && aes->use_pmull_hw_crypto) { #ifdef WOLFSSL_ARMASM_CRYPTO_SHA3