This repository was archived by the owner on Mar 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathlib.rs
More file actions
47 lines (39 loc) · 1.24 KB
/
lib.rs
File metadata and controls
47 lines (39 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#![no_std]
use alloc::vec;
use linux_kernel_module::sysctl::{Sysctl, SysctlStorage};
use linux_kernel_module::{self, cstr, random, Mode};
struct EntropySource;
impl SysctlStorage for EntropySource {
fn store_value(&self, _data: &[u8]) -> (usize, linux_kernel_module::KernelResult<()>) {
(0, Err(linux_kernel_module::Error::EINVAL))
}
fn read_value(
&self,
data: &mut linux_kernel_module::user_ptr::UserSlicePtrWriter,
) -> linux_kernel_module::KernelResult<()> {
let mut storage = vec![0; data.len()];
random::getrandom(&mut storage)?;
data.write(&storage)
}
}
struct RandomTestModule {
_sysctl_entropy: Sysctl<EntropySource>,
}
impl linux_kernel_module::KernelModule for RandomTestModule {
fn init() -> linux_kernel_module::KernelResult<Self> {
Ok(RandomTestModule {
_sysctl_entropy: Sysctl::register(
cstr!("rust/random-tests"),
cstr!("entropy"),
EntropySource,
Mode::from_int(0o444),
)?,
})
}
}
linux_kernel_module::kernel_module!(
RandomTestModule,
author: "Fish in a Barrel Contributors",
description: "A module for testing the CSPRNG",
license: "GPL"
);