linux-crng-ioctl
Rust wrappers for the ioctls of the Linux kernel CRNG and for its
/proc/sys/kernel/random/* interface. Linux only.
ioctl
The ioctl module operates on /dev/random:
| Function | ioctl | Privileges |
|---|---|---|
get_ent_cnt() |
RNDGETENTCNT |
none |
add_to_ent_cnt(bits) |
RNDADDTOENTCNT |
CAP_SYS_ADMIN |
add_randomness_to_kernel(entropy, bits) |
RNDADDENTROPY |
CAP_SYS_ADMIN |
clear_entropy_count() |
RNDZAPENTCNT |
CAP_SYS_ADMIN |
clear_pool() |
RNDCLEARPOOL |
CAP_SYS_ADMIN |
force_kernel_crng_reseed() |
RNDRESEEDCRNG |
CAP_SYS_ADMIN |
use ;
let entropy = ;
add_randomness_to_kernel?;
println!;
Only credit entropy which really is entropy: the amount of bits passed to
add_randomness_to_kernel is what the kernel adds to its entropy count. It is
rejected if it exceeds entropy.len() * 8, and one call writes at most 2 kB.
proc
The proc module reads the read-only files below
/proc/sys/kernel/random/: boot_id(), uuid(), entropy_avail(),
poolsize(), urandom_min_reseed_secs() and write_wakeup_threshold().
use ;
println!;
Tests
The test suite skips the cases which need CAP_SYS_ADMIN when it does not have
them, so cargo test works as an ordinary user.