libspl/random: add switch to force pseudo-random numbers for all calls

ztest wants to force all kernel random calls to use the pseudo-random
generator (/dev/urandom), to avoid depleting the system entropy pool
just for testing.

Up until the previous commit, it did this by switching the path that the
libzpool (now libspl) random API would use to get random data from; that
is, it took advantage of an implementation detail.

Now that that hole is closed to it, we need another method. This commit
introduces that; a simple API call to enable/disable "force pseudo"
mode.

Sponsored-by: https://despairlabs.com/sponsor/
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <robn@despairlabs.com>
Closes #17861
This commit is contained in:
Rob Norris
2025-11-11 11:16:30 +11:00
committed by Brian Behlendorf
parent 4d451bae8a
commit 23d17f3587
3 changed files with 18 additions and 0 deletions
+2
View File
@@ -32,6 +32,8 @@
extern int random_get_bytes(uint8_t *ptr, size_t len);
extern int random_get_pseudo_bytes(uint8_t *ptr, size_t len);
extern void random_force_pseudo(boolean_t onoff);
static __inline__ uint32_t
random_in_range(uint32_t range)
{