diff --git a/wolfcrypt/src/md5.c b/wolfcrypt/src/md5.c index 94c8152e1..243a997e4 100644 --- a/wolfcrypt/src/md5.c +++ b/wolfcrypt/src/md5.c @@ -311,8 +311,7 @@ int wc_Md5Update(wc_Md5* md5, const byte* data, word32 len) { int ret = 0; word32 blocksLen; - byte* local; - word32* local32; + byte* local; if (md5 == NULL || (data == NULL && len > 0)) { return BAD_FUNC_ARG; @@ -339,7 +338,6 @@ int wc_Md5Update(wc_Md5* md5, const byte* data, word32 len) AddLength(md5, len); local = (byte*)md5->buffer; - local32 = md5->buffer; /* process any remainder from previous operation */ if (md5->buffLen > 0) { @@ -352,7 +350,7 @@ int wc_Md5Update(wc_Md5* md5, const byte* data, word32 len) if (md5->buffLen == WC_MD5_BLOCK_SIZE) { #if defined(BIG_ENDIAN_ORDER) && !defined(FREESCALE_MMCAU_SHA) - ByteReverseWords(local32, local32, WC_MD5_BLOCK_SIZE); + ByteReverseWords(md5->buffer, md5->buffer, WC_MD5_BLOCK_SIZE); #endif ret = XTRANSFORM(md5, (const byte*)local); @@ -377,6 +375,7 @@ int wc_Md5Update(wc_Md5* md5, const byte* data, word32 len) } #else while (len >= WC_MD5_BLOCK_SIZE) { + word32* local32 = md5->buffer; /* optimization to avoid memcpy if data pointer is properly aligned */ /* Big Endian requires byte swap, so can't use data directly */ #if defined(WC_HASH_DATA_ALIGNMENT) && !defined(BIG_ENDIAN_ORDER) diff --git a/wolfcrypt/src/sha.c b/wolfcrypt/src/sha.c index 842aa0d62..b2dee4323 100644 --- a/wolfcrypt/src/sha.c +++ b/wolfcrypt/src/sha.c @@ -489,7 +489,6 @@ int wc_ShaUpdate(wc_Sha* sha, const byte* data, word32 len) int ret = 0; word32 blocksLen; byte* local; - word32* local32; if (sha == NULL || (data == NULL && len > 0)) { return BAD_FUNC_ARG; @@ -524,7 +523,6 @@ int wc_ShaUpdate(wc_Sha* sha, const byte* data, word32 len) AddLength(sha, len); local = (byte*)sha->buffer; - local32 = sha->buffer; /* process any remainder from previous operation */ if (sha->buffLen > 0) { @@ -537,7 +535,7 @@ int wc_ShaUpdate(wc_Sha* sha, const byte* data, word32 len) if (sha->buffLen == WC_SHA_BLOCK_SIZE) { #if defined(LITTLE_ENDIAN_ORDER) && !defined(FREESCALE_MMCAU_SHA) - ByteReverseWords(local32, local32, WC_SHA_BLOCK_SIZE); + ByteReverseWords(sha->buffer, sha->buffer, WC_SHA_BLOCK_SIZE); #endif #if defined(WOLFSSL_ESP32WROOM32_CRYPT) && \ @@ -574,6 +572,7 @@ int wc_ShaUpdate(wc_Sha* sha, const byte* data, word32 len) } #else while (len >= WC_SHA_BLOCK_SIZE) { + word32* local32 = sha->buffer; /* optimization to avoid memcpy if data pointer is properly aligned */ /* Little Endian requires byte swap, so can't use data directly */ #if defined(WC_HASH_DATA_ALIGNMENT) && !defined(LITTLE_ENDIAN_ORDER) diff --git a/wolfcrypt/src/sha256.c b/wolfcrypt/src/sha256.c index ad7e5805c..9948c6c11 100644 --- a/wolfcrypt/src/sha256.c +++ b/wolfcrypt/src/sha256.c @@ -810,8 +810,7 @@ static int InitSha256(wc_Sha256* sha256) { int ret = 0; word32 blocksLen; - byte* local; - word32* local32; + byte* local; if (sha256 == NULL || (data == NULL && len > 0)) { return BAD_FUNC_ARG; @@ -831,7 +830,6 @@ static int InitSha256(wc_Sha256* sha256) AddLength(sha256, len); local = (byte*)sha256->buffer; - local32 = sha256->buffer; /* process any remainder from previous operation */ if (sha256->buffLen > 0) { @@ -848,7 +846,8 @@ static int InitSha256(wc_Sha256* sha256) if (!IS_INTEL_AVX1(intel_flags) && !IS_INTEL_AVX2(intel_flags)) #endif { - ByteReverseWords(local32, local32, WC_SHA256_BLOCK_SIZE); + ByteReverseWords(sha256->buffer, sha256->buffer, + WC_SHA256_BLOCK_SIZE); } #endif @@ -897,6 +896,7 @@ static int InitSha256(wc_Sha256* sha256) #if !defined(XTRANSFORM_LEN) || defined(HAVE_INTEL_AVX1) || defined(HAVE_INTEL_AVX2) { while (len >= WC_SHA256_BLOCK_SIZE) { + word32* local32 = sha256->buffer; /* optimization to avoid memcpy if data pointer is properly aligned */ /* Intel transform function requires use of sha256->buffer */ /* Little Endian requires byte swap, so can't use data directly */