Skip to content

Commit 4d1fa1b

Browse files
authored
Merge pull request #9160 from douzzer/20250903-PR8329-rework
20250903-PR8329-rework
2 parents 5108dcd + ee2e634 commit 4d1fa1b

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

wolfcrypt/src/sha512.c

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,6 @@
121121
/* #define DEBUG_YMM */
122122
#endif
123123

124-
#if defined(HAVE_BYTEREVERSE64) && \
125-
!defined(HAVE_INTEL_AVX1) && !defined(HAVE_INTEL_AVX2)
126-
#define ByteReverseWords64(out, in, size) ByteReverseWords64_1(out, size)
127-
#define ByteReverseWords64_1(buf, size) \
128-
{ unsigned int i ;\
129-
for(i=0; i< size/sizeof(word64); i++){\
130-
__asm__ volatile("bswapq %0":"+r"(buf[i])::) ;\
131-
}\
132-
}
133-
#endif
134-
135124
#if defined(WOLFSSL_IMX6_CAAM) && !defined(NO_IMX6_CAAM_HASH) && \
136125
!defined(WOLFSSL_QNX_CAAM)
137126
/* functions defined in wolfcrypt/src/port/caam/caam_sha.c */
@@ -1400,17 +1389,23 @@ static WC_INLINE int Sha512Final(wc_Sha512* sha512)
14001389
#elif defined(STM32_HASH_SHA512)
14011390
#else
14021391

1403-
static int Sha512FinalRaw(wc_Sha512* sha512, byte* hash, size_t digestSz)
1392+
static int Sha512FinalRaw(wc_Sha512* sha512, byte* hash, word32 digestSz)
14041393
{
14051394
if (sha512 == NULL || hash == NULL) {
14061395
return BAD_FUNC_ARG;
14071396
}
14081397

14091398
#ifdef LITTLE_ENDIAN_ORDER
1410-
ByteReverseWords64(sha512->digest, sha512->digest, WC_SHA512_DIGEST_SIZE);
1411-
#endif
1412-
1399+
if ((digestSz & 0x7) == 0)
1400+
ByteReverseWords64((word64 *)hash, sha512->digest, digestSz);
1401+
else {
1402+
ByteReverseWords64(sha512->digest, sha512->digest,
1403+
WC_SHA512_DIGEST_SIZE);
1404+
XMEMCPY(hash, sha512->digest, digestSz);
1405+
}
1406+
#else
14131407
XMEMCPY(hash, sha512->digest, digestSz);
1408+
#endif
14141409

14151410
return 0;
14161411
}
@@ -1807,10 +1802,10 @@ int wc_Sha384FinalRaw(wc_Sha384* sha384, byte* hash)
18071802
}
18081803

18091804
#ifdef LITTLE_ENDIAN_ORDER
1810-
ByteReverseWords64(sha384->digest, sha384->digest, WC_SHA384_DIGEST_SIZE);
1811-
#endif
1812-
1805+
ByteReverseWords64((word64 *)hash, sha384->digest, WC_SHA384_DIGEST_SIZE);
1806+
#else
18131807
XMEMCPY(hash, sha384->digest, WC_SHA384_DIGEST_SIZE);
1808+
#endif
18141809

18151810
return 0;
18161811
}

0 commit comments

Comments
 (0)