Skip to content

Commit ac11279

Browse files
committed
wolfcrypt/src/random.c:
* add workaround in Hash512_df() for gcc compiler bug around AVX512 and object alignment. * add missing WC_VERBOSE_RNG clause.
1 parent 1d80288 commit ac11279

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

wolfcrypt/src/random.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,8 +1058,16 @@ static int Hash512_df(DRBG_SHA512_internal* drbg, byte* out, word32 outSz,
10581058
byte* digest = drbg->digest_scratch;
10591059
#elif defined(WOLFSSL_SMALL_STACK)
10601060
byte* digest;
1061+
#else
1062+
#if defined(__GNUC__) && !defined(__clang__) && defined(__AVX512F__)
1063+
/* Use a jumbo alignment to work around a gcc compiler/optimizer bug that
1064+
* assumes AVX512 alignment in an object sized correctly for AVX512 passed
1065+
* to builtin memcpy(), which promptly crashes if not thus aligned.
1066+
*/
1067+
byte digest[WC_SHA512_DIGEST_SIZE] WOLFSSL_ALIGN(WC_SHA512_DIGEST_SIZE);
10611068
#else
10621069
byte digest[WC_SHA512_DIGEST_SIZE];
1070+
#endif
10631071
#endif
10641072

10651073
if (drbg == NULL) {
@@ -1135,6 +1143,12 @@ static int Hash512_df(DRBG_SHA512_internal* drbg, byte* out, word32 outSz,
11351143
XFREE(digest, drbg->heap, DYNAMIC_TYPE_DIGEST);
11361144
#endif
11371145

1146+
#ifdef WC_VERBOSE_RNG
1147+
if (ret != 0)
1148+
WOLFSSL_DEBUG_PRINTF("ERROR: %s failed with err = %d", __FUNCTION__,
1149+
ret);
1150+
#endif
1151+
11381152
return (ret == 0) ? DRBG_SUCCESS : DRBG_FAILURE;
11391153
}
11401154

0 commit comments

Comments
 (0)