Skip to content

Commit

Permalink
add comments explaining dependence on idempotency for race-free dynam…
Browse files Browse the repository at this point in the history
…ics re checkedAESNI, haveAESNI, intel_flags, and sha_method. see #7863.
  • Loading branch information
douzzer committed Aug 14, 2024
1 parent 1fa2d2d commit 7a29b1e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions wolfcrypt/src/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions wolfcrypt/src/sha256.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions wolfcrypt/src/sha512.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7a29b1e

Please sign in to comment.