From 4f2d4420df8cc5479a3119055ecdc7807bd2d848 Mon Sep 17 00:00:00 2001 From: David Garske Date: Fri, 1 Mar 2019 10:50:08 -0800 Subject: [PATCH] Cleanups for hard coded 12 and 16 in AES GCM code. Allow STM32 GCM IV 12 thru 16. --- wolfcrypt/src/aes.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/wolfcrypt/src/aes.c b/wolfcrypt/src/aes.c index cf80d204e..dbf77cdca 100644 --- a/wolfcrypt/src/aes.c +++ b/wolfcrypt/src/aes.c @@ -3887,7 +3887,7 @@ static void AES_GCM_encrypt(const unsigned char *in, __m128i tmp3, tmp4, tmp5, tmp6, tmp7, tmp8; #endif - if (ibytes == 12) + if (ibytes == GCM_NONCE_MID_SZ) aes_gcm_calc_iv_12(KEY, ivec, nr, H, Y, T); else aes_gcm_calc_iv(KEY, ivec, ibytes, nr, H, Y, T); @@ -4325,7 +4325,7 @@ static void AES_GCM_decrypt(const unsigned char *in, __m128i tmp3, tmp4, tmp5, tmp6, tmp7, tmp8; #endif /* AES_GCM_AESNI_NO_UNROLL */ - if (ibytes == 12) + if (ibytes == GCM_NONCE_MID_SZ) aes_gcm_calc_iv_12(KEY, ivec, nr, H, Y, T); else aes_gcm_calc_iv(KEY, ivec, ibytes, nr, H, Y, T); @@ -5495,9 +5495,9 @@ int wc_AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz, #endif /* WOLFSSL_ASYNC_CRYPT */ #ifdef STM32_CRYPTO_AES_GCM - /* STM hardware only supports IV of 12 or 16 bytes */ + /* STM hardware only supports IV of 12 thru 16 bytes */ /* The STM standard peripheral library API's doesn't support partial blocks */ - if ((ivSz == 12 || ivSz == 16) + if (ivSz >= GCM_NONCE_MID_SZ && ivSz <= GCM_NONCE_MAX_SZ #ifdef STD_PERI_LIB && partial == 0 #endif @@ -5911,9 +5911,9 @@ int wc_AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz, #endif /* WOLFSSL_ASYNC_CRYPT */ #ifdef STM32_CRYPTO_AES_GCM - /* STM hardware only supports IV of 12 or 16 bytes */ + /* STM hardware only supports IV of 12 thru 16 bytes */ /* The STM standard peripheral library API's doesn't support partial blocks */ - if ((ivSz == 12 || ivSz == 16) + if (ivSz >= GCM_NONCE_MID_SZ && ivSz <= GCM_NONCE_MAX_SZ #ifdef STD_PERI_LIB && partial == 0 #endif