From ac11279c60acee6df8e1d18bcc48d1194fb5c526 Mon Sep 17 00:00:00 2001 From: Daniel Pouzzner Date: Mon, 27 Apr 2026 11:37:15 -0500 Subject: [PATCH] wolfcrypt/src/random.c: * add workaround in Hash512_df() for gcc compiler bug around AVX512 and object alignment. * add missing WC_VERBOSE_RNG clause. --- wolfcrypt/src/random.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index 33ff460006..efc9eaf59a 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -1058,8 +1058,16 @@ static int Hash512_df(DRBG_SHA512_internal* drbg, byte* out, word32 outSz, byte* digest = drbg->digest_scratch; #elif defined(WOLFSSL_SMALL_STACK) byte* digest; +#else +#if defined(__GNUC__) && !defined(__clang__) && defined(__AVX512F__) + /* Use a jumbo alignment to work around a gcc compiler/optimizer bug that + * assumes AVX512 alignment in an object sized correctly for AVX512 passed + * to builtin memcpy(), which promptly crashes if not thus aligned. + */ + byte digest[WC_SHA512_DIGEST_SIZE] WOLFSSL_ALIGN(WC_SHA512_DIGEST_SIZE); #else byte digest[WC_SHA512_DIGEST_SIZE]; +#endif #endif if (drbg == NULL) { @@ -1135,6 +1143,12 @@ static int Hash512_df(DRBG_SHA512_internal* drbg, byte* out, word32 outSz, XFREE(digest, drbg->heap, DYNAMIC_TYPE_DIGEST); #endif +#ifdef WC_VERBOSE_RNG + if (ret != 0) + WOLFSSL_DEBUG_PRINTF("ERROR: %s failed with err = %d", __FUNCTION__, + ret); +#endif + return (ret == 0) ? DRBG_SUCCESS : DRBG_FAILURE; }