@@ -68,23 +68,29 @@ typedef struct NRBG_type_t {
68
68
int initialized ; /*!< Flag to say it was used */
69
69
} NRBG_type ;
70
70
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
+
71
77
#if (NON_FIPS_ICC == 1 ) /* Built as non-FIPS */
72
78
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) */
74
80
/* X86 Linux and Windows, Solaris x86 */
75
81
#if (defined(__i386 ) || defined(__i386__ ) || defined(_M_IX86 ) || \
76
82
defined(__INTEL__ ) || \
77
83
defined(__x86_64 ) || defined(__x86_64__ ) || defined(_M_AMD64 ) ) && ( !(defined(__SunOS ) && !defined(__amd64 )) \
78
84
)
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 ;
81
87
82
88
#elif defined(__s390__ ) || defined(__MVS__ )
89
+ static int global_trng_type_attempted_upgrade = 0 ;
90
+ static TRNG_TYPE global_trng_type = TRNG_OS ;
83
91
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 */
87
92
#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 */
88
94
static int global_trng_type_attempted_upgrade = 0 ;
89
95
static TRNG_TYPE global_trng_type = TRNG_OS ;
90
96
@@ -97,7 +103,7 @@ typedef struct NRBG_type_t {
97
103
static TRNG_TYPE global_trng_type = TRNG_FIPS ;
98
104
#endif
99
105
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 */
101
107
int global_trng_type_user_set = 0 ;
102
108
103
109
static void TRNG_LocalCleanup (TRNG * T );
@@ -247,6 +253,7 @@ void checkTRNGAlias(char **trngname) {
247
253
* trngname = "TRNG_OS" ;
248
254
}
249
255
}
256
+ MARK ("TRNG aliased to" , * trngname );
250
257
}
251
258
}
252
259
}
@@ -258,6 +265,12 @@ void checkTRNGAlias(char **trngname) {
258
265
extern unsigned icc_failure ; /*!< Trigger for induced failure tests */
259
266
int SetTRNGName (char * trngname )
260
267
{
268
+ if (NULL != trngname ) {
269
+ MARK ("Request to set TRNG to" , trngname );
270
+ }
271
+ else {
272
+ MARK ("Request to set NULL TRNG" , "" );
273
+ }
261
274
int rv = 0 ;
262
275
int i = 0 ;
263
276
checkTRNGAlias (& trngname );
@@ -288,8 +301,11 @@ TRNG_TYPE SetDefaultTrng(TRNG_TYPE trng) {
288
301
case TRNG_HW :
289
302
case TRNG_FIPS :
290
303
if (TRNG_ARRAY [trng ].avail ()) {
304
+ MARK ("TRNG set to" , TRNG_ARRAY [trng ].name );
291
305
global_trng_type = trng ;
292
306
global_trng_type_user_set = 1 ;
307
+ } else {
308
+ MARK ("TRNG attempted to be set to" , TRNG_ARRAY [trng ].name );
293
309
}
294
310
break ;
295
311
default :
@@ -397,12 +413,39 @@ static void TRNG_ESourceCleanup(E_SOURCE *es)
397
413
398
414
TRNG_TYPE GetDefaultTrng ()
399
415
{
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" , "" );
402
434
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 );
403
443
}
404
444
global_trng_type_attempted_upgrade = 1 ;
405
- #endif
445
+ }
446
+
447
+ #endif /*x86_64, z/architecture, power */
448
+ #endif /*non-FIPS*/
406
449
return global_trng_type ;
407
450
}
408
451
/*!
0 commit comments