From 7a29b1e4fdad6f523fe154bf8971a79cd646871e Mon Sep 17 00:00:00 2001 From: Daniel Pouzzner Date: Wed, 14 Aug 2024 15:23:48 -0500 Subject: [PATCH] add comments explaining dependence on idempotency for race-free dynamics re checkedAESNI, haveAESNI, intel_flags, and sha_method. see #7863. --- wolfcrypt/src/aes.c | 4 ++++ wolfcrypt/src/sha256.c | 4 ++++ wolfcrypt/src/sha512.c | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/wolfcrypt/src/aes.c b/wolfcrypt/src/aes.c index 93f91816b4..e3afa4a922 100644 --- a/wolfcrypt/src/aes.c +++ b/wolfcrypt/src/aes.c @@ -613,6 +613,10 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits #define AESNI_ALIGN 16 #endif + /* note that all write access to these static variables must be idempotent, + * as arranged by Check_CPU_support_AES(), else they will be susceptible to + * data races. + */ static int checkedAESNI = 0; static int haveAESNI = 0; static word32 intel_flags = 0; diff --git a/wolfcrypt/src/sha256.c b/wolfcrypt/src/sha256.c index 180a6c044b..2ba9ca62d1 100644 --- a/wolfcrypt/src/sha256.c +++ b/wolfcrypt/src/sha256.c @@ -408,6 +408,10 @@ static int InitSha256(wc_Sha256* sha256) SHA256_SSE2, SHA256_C }; #ifndef WC_C_DYNAMIC_FALLBACK + /* note that all write access to this static variable must be idempotent, + * as arranged by Sha256_SetTransform(), else it will be susceptible to + * data races. + */ static enum sha_methods sha_method = SHA256_UNSET; #endif diff --git a/wolfcrypt/src/sha512.c b/wolfcrypt/src/sha512.c index 203267163a..77313f7a2a 100644 --- a/wolfcrypt/src/sha512.c +++ b/wolfcrypt/src/sha512.c @@ -489,6 +489,10 @@ static int InitSha512_256(wc_Sha512* sha512) SHA512_AVX1_RORX, SHA512_AVX2_RORX, SHA512_C }; #ifndef WC_C_DYNAMIC_FALLBACK + /* note that all write access to this static variable must be idempotent, + * as arranged by Sha512_SetTransform(), else it will be susceptible to + * data races. + */ static enum sha_methods sha_method = SHA512_UNSET; #endif