@@ -383,6 +383,31 @@ char* myoptarg = NULL;
383383int DoneHandShake = 0 ;
384384#endif
385385
386+
387+ #if defined(HAVE_FIPS ) && defined(HAVE_FIPS_VERSION ) && (HAVE_FIPS_VERSION == 5 )
388+ static int run_all_CAST (void )
389+ {
390+ int ret = 0 ;
391+
392+ for (int i = 0 ; i < FIPS_CAST_COUNT ; i ++ ) {
393+ if ((ret = wc_RunCast_fips (i )) != 0 ) {
394+ #ifdef NO_ERROR_STRINGS
395+ fprintf (stderr ,
396+ "ERROR: FIPS CAST failed with return code: %d\n" , ret );
397+ #else
398+ fprintf (stderr ,
399+ "ERROR: FIPS CAST failed for algorithm: %s\n" ,
400+ wc_GetErrorString (ret ));
401+ #endif
402+ return ret ;
403+ }
404+ }
405+
406+ return ret ;
407+ }
408+ #endif /* HAVE_FIPS && HAVE_FIPS_VERSION == 5 */
409+
410+
386411static double gettime_secs (int reset )
387412{
388413 struct timeval tv ;
@@ -1863,6 +1888,23 @@ int bench_tls(void* args)
18631888 /* Initialize wolfSSL */
18641889 wolfSSL_Init ();
18651890
1891+ #if defined(HAVE_FIPS ) && defined(HAVE_FIPS_VERSION ) && (HAVE_FIPS_VERSION == 5 )
1892+ /*
1893+ * When running benchmarks on FIPS builds, we need to run ALL CASTs up
1894+ * front before spawning client/server threads, otherwise there is the
1895+ * possibility that both threads try to run a CAST at the same time during
1896+ * the handshake. In this scenario, the thread that doesn't win the race
1897+ * will not be able to run the CAST, since it returns "busy", which is treated
1898+ * as a failure. Running the CASTs up front is a simpler solution than
1899+ * implementing an additional layer of synchronization.
1900+ */
1901+ if ((ret = run_all_CAST ()) != 0 )
1902+ {
1903+ fprintf (stderr , "CAST failed. Exiting benchmark\n" );
1904+ goto exit ;
1905+ }
1906+ #endif /* HAVE_FIPS && HAVE_FIPS_VERSION == 5 */
1907+
18661908 /* Parse command line arguments */
18671909 while ((ch = mygetopt (argc , argv , "?" "udeil:p:t:vT:sch:P:mS:g" )) != -1 ) {
18681910 switch (ch ) {
0 commit comments