Skip to content

Commit aea72e2

Browse files
committed
cpuid: run the CASTs after a feature change, not on first use
1 parent cfebec3 commit aea72e2

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

wolfcrypt/src/cpuid.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -952,8 +952,9 @@
952952
}
953953

954954
/* A new feature set is a new operating environment: re-run the power-on
955-
* self test, which resets every CAST to run again on the new lanes.
956-
* The kernel module suspends signal handling around the self test. */
955+
* self test, then run every CAST on the new lanes now instead of waiting
956+
* for first use, which is what the kernel module does at load. Signals
957+
* stay suspended across both so a CAST cannot be cut short. */
957958
static WC_INLINE void cpuid_recast(void)
958959
{
959960
#if defined(HAVE_FIPS) && FIPS_VERSION3_GE(7,0,0)
@@ -963,6 +964,8 @@
963964
return;
964965
}
965966
ret = wolfCrypt_IntegrityTest_fips();
967+
if (ret == 0)
968+
ret = wc_RunAllCast_fips();
966969
(void)WC_SIG_IGNORE_END();
967970
if (ret != 0)
968971
WOLFSSL_MSG("cpuid: self test failed after a feature change");

wolfssl/wolfcrypt/cpuid.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,9 @@ typedef word32 cpuid_flags_t;
247247
}
248248

249249
/* Public APIs to modify flags. In FIPS builds a call that changes them
250-
* re-runs the power-on self test; operations in flight see the module in
251-
* its start-up state and fail until it completes. */
250+
* re-runs the power-on self test and every CAST on the new lanes;
251+
* operations in flight see the module in its start-up state and fail
252+
* until it completes. */
252253

253254
#ifdef WOLFSSL_API_PREFIX_MAP
254255
#define cpuid_select_flags wc_cpuid_select_flags

0 commit comments

Comments
 (0)