Re: [PATCH v2] rust: Add support for feeding entropy to randomness pool
From: Alice Ryhl
Date: Thu Dec 18 2025 - 02:57:12 EST
On Tue, Dec 16, 2025 at 1:37 AM Matthew Maurer <mmaurer@xxxxxxxxxx> wrote:
>
> Adds just enough support to allow device drivers to feed entropy to the
> central pool.
>
> Signed-off-by: Matthew Maurer <mmaurer@xxxxxxxxxx>
Some nits below. With those fixed:
Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
> +//! Randomness.
> +//!
> +//! C header: [`include/linux/random.h`](../../../../include/linux/random.h)
Needs to use srctree instead of ../
> +use crate::bindings;
> +use crate::ffi::c_void;
Please import the prelude here.
> +/// Adds the given buffer to the entropy pool, but does not credit any entropy.
> +///
> +/// This is intended for use mixing in data that is likely to differ between devices or boots, but
> +/// may otherwise be predictable. Examples include MAC addresses or RTC values. This slightly
> +/// improves randomness in entropy-constrained environments (especially common for embedded
> +/// devices).
> +pub fn add_device_randomness(buf: &[u8]) {
> + // SAFETY: We just need the pointer to be valid for the length, which a slice provides.
> + unsafe { bindings::add_device_randomness(buf.as_ptr().cast::<c_void>(), buf.len()) };
> +}