@@ -68,23 +68,29 @@ typedef struct NRBG_type_t {
6868 int initialized ; /*!< Flag to say it was used */
6969} NRBG_type ;
7070
71+
72+ /* In non-FIPS, all platforms default to TRNG_OS and upgrade to TRNG_HW at runtime if available.
73+ This is done to prioritise compatibility on the unpredictable range and age of the virtualisatised systems we might run on,
74+ while still upgrading and using TRNG_HW in most cases.
75+ */
76+
7177#if (NON_FIPS_ICC == 1 ) /* Built as non-FIPS */
7278
73- /* These definitions match the availability of OPENSSL_HW_rand */
79+ /* These definitions try mirror the availability of OPENSSL_HW_rand to avoid a mismatch (not relevant when we use TRNG_OS) */
7480/* X86 Linux and Windows, Solaris x86 */
7581#if (defined(__i386 ) || defined(__i386__ ) || defined(_M_IX86 ) || \
7682 defined(__INTEL__ ) || \
7783 defined(__x86_64 ) || defined(__x86_64__ ) || defined(_M_AMD64 ) ) && ( !(defined(__SunOS ) && !defined(__amd64 )) \
7884 )
79-
80- static TRNG_TYPE global_trng_type = TRNG_HW ;
85+ static int global_trng_type_attempted_upgrade = 0 ;
86+ static TRNG_TYPE global_trng_type = TRNG_OS ;
8187
8288#elif defined(__s390__ ) || defined(__MVS__ )
89+ static int global_trng_type_attempted_upgrade = 0 ;
90+ static TRNG_TYPE global_trng_type = TRNG_OS ;
8391
84- static TRNG_TYPE global_trng_type = TRNG_HW ;
85-
86- /* We will do a runtime check for cpu support for darn, present since ISA3.0, and update to TRNG_HW if so */
8792#elif defined(__ppc__ ) || defined(__powerpc__ ) || defined(_AIX )
93+ /* We will do a runtime check for cpu support for darn, present since ISA3.0, and update to TRNG_HW if so */
8894 static int global_trng_type_attempted_upgrade = 0 ;
8995 static TRNG_TYPE global_trng_type = TRNG_OS ;
9096
@@ -97,7 +103,7 @@ typedef struct NRBG_type_t {
97103 static TRNG_TYPE global_trng_type = TRNG_FIPS ;
98104#endif
99105
100- /* If a user sets TRNG_OS on power , we don't want to upgrade even if HW is available */
106+ /* If a user explicitly sets a TRNG , we don't want to upgrade even if HW is available */
101107int global_trng_type_user_set = 0 ;
102108
103109static void TRNG_LocalCleanup (TRNG * T );
@@ -247,6 +253,7 @@ void checkTRNGAlias(char **trngname) {
247253 * trngname = "TRNG_OS" ;
248254 }
249255 }
256+ MARK ("TRNG aliased to" , * trngname );
250257 }
251258 }
252259}
@@ -258,6 +265,12 @@ void checkTRNGAlias(char **trngname) {
258265extern unsigned icc_failure ; /*!< Trigger for induced failure tests */
259266int SetTRNGName (char * trngname )
260267{
268+ if (NULL != trngname ) {
269+ MARK ("Request to set TRNG to" , trngname );
270+ }
271+ else {
272+ MARK ("Request to set NULL TRNG" , "" );
273+ }
261274 int rv = 0 ;
262275 int i = 0 ;
263276 checkTRNGAlias (& trngname );
@@ -288,8 +301,11 @@ TRNG_TYPE SetDefaultTrng(TRNG_TYPE trng) {
288301 case TRNG_HW :
289302 case TRNG_FIPS :
290303 if (TRNG_ARRAY [trng ].avail ()) {
304+ MARK ("TRNG set to" , TRNG_ARRAY [trng ].name );
291305 global_trng_type = trng ;
292306 global_trng_type_user_set = 1 ;
307+ } else {
308+ MARK ("TRNG attempted to be set to" , TRNG_ARRAY [trng ].name );
293309 }
294310 break ;
295311 default :
@@ -397,12 +413,39 @@ static void TRNG_ESourceCleanup(E_SOURCE *es)
397413
398414TRNG_TYPE GetDefaultTrng ()
399415{
400- #if defined(__ppc__ ) || defined(__powerpc__ ) || defined(_AIX )
401- if (!global_trng_type_attempted_upgrade && 0 == global_trng_type_user_set && 0 == strcasecmp ("TRNG_OS" , * trngname ) && ALT4_Avail ()) {
416+ #if (NON_FIPS_ICC == 1 )
417+
418+ #if (\
419+ (( defined(__i386 ) || defined(__i386__ ) || defined(_M_IX86 ) || \
420+ defined(__INTEL__ ) || \
421+ defined(__x86_64 ) || defined(__x86_64__ ) || defined(_M_AMD64 )) && (!(defined(__SunOS ) && !defined(__amd64 )))) \
422+ || \
423+ ( defined(__s390__ ) || defined(__MVS__ )) \
424+ || \
425+ ( defined(__ppc__ ) || defined(__powerpc__ ) || defined(_AIX )) \
426+ )
427+ if (!global_trng_type_attempted_upgrade ) {
428+ MARK ("Testing the availability of TRNG_HW" , "" );
429+
430+ if (0 == global_trng_type_user_set ) {
431+ if (TRNG_FIPS != global_trng_type ) {
432+ if (ALT4_Avail ()) {
433+ MARK ("Found, switching to TRNG_HW" , "" );
402434 global_trng_type = TRNG_HW ;
435+ } else {
436+ MARK ("TRNG_HW not available, remaining with" , TRNG_ARRAY [global_trng_type ].name );
437+ }
438+ } else {
439+ MARK ("TRNG_FIPS set, remaining with" , TRNG_ARRAY [global_trng_type ].name );
440+ }
441+ } else {
442+ MARK ("User TRNG set, remaining with" , TRNG_ARRAY [global_trng_type ].name );
403443 }
404444 global_trng_type_attempted_upgrade = 1 ;
405- #endif
445+ }
446+
447+ #endif /*x86_64, z/architecture, power */
448+ #endif /*non-FIPS*/
406449 return global_trng_type ;
407450}
408451/*!
0 commit comments