|
121 | 121 | /* #define DEBUG_YMM */ |
122 | 122 | #endif |
123 | 123 |
|
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 | | - |
135 | 124 | #if defined(WOLFSSL_IMX6_CAAM) && !defined(NO_IMX6_CAAM_HASH) && \ |
136 | 125 | !defined(WOLFSSL_QNX_CAAM) |
137 | 126 | /* functions defined in wolfcrypt/src/port/caam/caam_sha.c */ |
@@ -1400,17 +1389,23 @@ static WC_INLINE int Sha512Final(wc_Sha512* sha512) |
1400 | 1389 | #elif defined(STM32_HASH_SHA512) |
1401 | 1390 | #else |
1402 | 1391 |
|
1403 | | -static int Sha512FinalRaw(wc_Sha512* sha512, byte* hash, size_t digestSz) |
| 1392 | +static int Sha512FinalRaw(wc_Sha512* sha512, byte* hash, word32 digestSz) |
1404 | 1393 | { |
1405 | 1394 | if (sha512 == NULL || hash == NULL) { |
1406 | 1395 | return BAD_FUNC_ARG; |
1407 | 1396 | } |
1408 | 1397 |
|
1409 | 1398 | #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 |
1413 | 1407 | XMEMCPY(hash, sha512->digest, digestSz); |
| 1408 | +#endif |
1414 | 1409 |
|
1415 | 1410 | return 0; |
1416 | 1411 | } |
@@ -1807,10 +1802,10 @@ int wc_Sha384FinalRaw(wc_Sha384* sha384, byte* hash) |
1807 | 1802 | } |
1808 | 1803 |
|
1809 | 1804 | #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 |
1813 | 1807 | XMEMCPY(hash, sha384->digest, WC_SHA384_DIGEST_SIZE); |
| 1808 | +#endif |
1814 | 1809 |
|
1815 | 1810 | return 0; |
1816 | 1811 | } |
|
0 commit comments