@@ -276,6 +276,17 @@ static S2N_RESULT s2n_ensure_uniqueness(void)
276
276
return S2N_RESULT_OK ;
277
277
}
278
278
279
+ #if S2N_LIBCRYPTO_SUPPORTS_PRIVATE_RAND
280
+ static S2N_RESULT s2n_get_libcrypto_private_random_data (struct s2n_blob * out_blob )
281
+ {
282
+ RESULT_GUARD_PTR (out_blob );
283
+ RESULT_GUARD_OSSL (RAND_priv_bytes (out_blob -> data , out_blob -> size ), S2N_ERR_DRBG );
284
+ return S2N_RESULT_OK ;
285
+ }
286
+ #else
287
+ #define s2n_get_libcrypto_private_random_data s2n_get_libcrypto_random_data
288
+ #endif
289
+
279
290
static S2N_RESULT s2n_get_libcrypto_random_data (struct s2n_blob * out_blob )
280
291
{
281
292
RESULT_GUARD_PTR (out_blob );
@@ -308,33 +319,23 @@ static S2N_RESULT s2n_get_custom_random_data(struct s2n_blob *out_blob, struct s
308
319
return S2N_RESULT_OK ;
309
320
}
310
321
311
- static S2N_RESULT s2n_get_random_data (struct s2n_blob * blob , struct s2n_drbg * drbg_state )
322
+ S2N_RESULT s2n_get_public_random_data (struct s2n_blob * blob )
312
323
{
313
- /* By default, s2n-tls uses a custom random implementation to generate random data for the TLS
314
- * handshake. When operating in FIPS mode, the FIPS-validated libcrypto implementation is used
315
- * instead.
316
- */
317
324
if (s2n_is_in_fips_mode ()) {
318
325
RESULT_GUARD (s2n_get_libcrypto_random_data (blob ));
319
- return S2N_RESULT_OK ;
326
+ } else {
327
+ RESULT_GUARD (s2n_get_custom_random_data (blob , & s2n_per_thread_rand_state .public_drbg ));
320
328
}
321
-
322
- RESULT_GUARD (s2n_get_custom_random_data (blob , drbg_state ));
323
-
324
- return S2N_RESULT_OK ;
325
- }
326
-
327
- S2N_RESULT s2n_get_public_random_data (struct s2n_blob * blob )
328
- {
329
- RESULT_GUARD (s2n_get_random_data (blob , & s2n_per_thread_rand_state .public_drbg ));
330
-
331
329
return S2N_RESULT_OK ;
332
330
}
333
331
334
332
S2N_RESULT s2n_get_private_random_data (struct s2n_blob * blob )
335
333
{
336
- RESULT_GUARD (s2n_get_random_data (blob , & s2n_per_thread_rand_state .private_drbg ));
337
-
334
+ if (s2n_is_in_fips_mode ()) {
335
+ RESULT_GUARD (s2n_get_libcrypto_private_random_data (blob ));
336
+ } else {
337
+ RESULT_GUARD (s2n_get_custom_random_data (blob , & s2n_per_thread_rand_state .private_drbg ));
338
+ }
338
339
return S2N_RESULT_OK ;
339
340
}
340
341
0 commit comments