Add random number scheme, update userutils to use it
This commit is contained in:
parent
c4d3257868
commit
ead01ea2da
2
Makefile
2
Makefile
|
@ -401,6 +401,7 @@ userutils: \
|
||||||
filesystem/bin/getty \
|
filesystem/bin/getty \
|
||||||
filesystem/bin/id \
|
filesystem/bin/id \
|
||||||
filesystem/bin/login \
|
filesystem/bin/login \
|
||||||
|
filesystem/bin/passwd \
|
||||||
filesystem/bin/su \
|
filesystem/bin/su \
|
||||||
filesystem/bin/sudo
|
filesystem/bin/sudo
|
||||||
|
|
||||||
|
@ -410,6 +411,7 @@ schemes: \
|
||||||
filesystem/bin/example \
|
filesystem/bin/example \
|
||||||
filesystem/bin/ipd \
|
filesystem/bin/ipd \
|
||||||
filesystem/bin/orbital \
|
filesystem/bin/orbital \
|
||||||
|
filesystem/bin/randd \
|
||||||
filesystem/bin/tcpd \
|
filesystem/bin/tcpd \
|
||||||
filesystem/bin/udpd
|
filesystem/bin/udpd
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
randd
|
||||||
initfs:bin/pcid /etc/pcid.toml
|
initfs:bin/pcid /etc/pcid.toml
|
||||||
ethernetd
|
ethernetd
|
||||||
arpd
|
arpd
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
root;F3C2DB8A2B386A467FE3BA116DD2D2E3EAAE98546FCC8321FDBD4C1F6D65A2;0;0;root;file:root;file:bin/ion
|
root;$argon2i$m=4096,t=10,p=1$Tnc4UVV0N00$ML9LIOujd3nmAfkAwEcSTMPqakWUF0OUiLWrIy0nGLk;0;0;root;file:root;file:bin/ion
|
||||||
user;;1000;1000;user;file:home/user;file:bin/ion
|
user;;1000;1000;user;file:home/user;file:bin/ion
|
||||||
|
|
|
@ -3,11 +3,11 @@ name = "E1000 NIC"
|
||||||
class = 2
|
class = 2
|
||||||
vendor = 32902
|
vendor = 32902
|
||||||
device = 4110
|
device = 4110
|
||||||
command = ["file:bin/e1000d", "$BAR0", "$IRQ"]
|
command = ["e1000d", "$BAR0", "$IRQ"]
|
||||||
|
|
||||||
[[drivers]]
|
[[drivers]]
|
||||||
name = "RTL8168 NIC"
|
name = "RTL8168 NIC"
|
||||||
class = 2
|
class = 2
|
||||||
vendor = 4332
|
vendor = 4332
|
||||||
device = 33128
|
device = 33128
|
||||||
command = ["file:bin/rtl8168d", "$BAR2", "$IRQ"]
|
command = ["rtl8168d", "$BAR2", "$IRQ"]
|
||||||
|
|
2
libstd
2
libstd
|
@ -1 +1 @@
|
||||||
Subproject commit 00d7f8a547b83e604f1a3b6df769a6e77e7feed9
|
Subproject commit 4f642eed87af22913af7bef9c71910ee1765445e
|
|
@ -1 +1 @@
|
||||||
Subproject commit edc8da6807a18bc2ae7c4482ae4a84ca9dad4f4a
|
Subproject commit 517ca6d125e90d6b30e45a759f54b1d1b3b346d4
|
|
@ -1 +1 @@
|
||||||
Subproject commit e0fe388ccfe8873cc6e42dc99556bccc191528fb
|
Subproject commit 46631df4f09c39ff760b48d25249a48840ee20fa
|
3
schemes/randd/Cargo.toml
Normal file
3
schemes/randd/Cargo.toml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
[package]
|
||||||
|
name = "randd"
|
||||||
|
version = "0.1.0"
|
59
schemes/randd/src/main.rs
Normal file
59
schemes/randd/src/main.rs
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
#![feature(asm)]
|
||||||
|
|
||||||
|
extern crate syscall;
|
||||||
|
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{Read, Write};
|
||||||
|
use std::thread;
|
||||||
|
|
||||||
|
use syscall::{Packet, Result, Scheme};
|
||||||
|
|
||||||
|
//TODO: Use a CSPRNG, allow write of entropy
|
||||||
|
struct RandScheme;
|
||||||
|
|
||||||
|
impl Scheme for RandScheme {
|
||||||
|
fn open(&self, _path: &[u8], _flags: usize, _uid: u32, _gid: u32) -> Result<usize> {
|
||||||
|
Ok(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dup(&self, file: usize) -> Result<usize> {
|
||||||
|
Ok(file)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read(&self, _file: usize, buf: &mut [u8]) -> Result<usize> {
|
||||||
|
let mut i = 0;
|
||||||
|
for chunk in buf.chunks_mut(8) {
|
||||||
|
let mut rand: u64;
|
||||||
|
unsafe {
|
||||||
|
asm!("rdrand rax"
|
||||||
|
: "={rax}"(rand)
|
||||||
|
:
|
||||||
|
:
|
||||||
|
: "intel", "volatile");
|
||||||
|
}
|
||||||
|
for b in chunk.iter_mut() {
|
||||||
|
*b = rand as u8;
|
||||||
|
rand = rand >> 8;
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn close(&self, _file: usize) -> Result<usize> {
|
||||||
|
Ok(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main(){
|
||||||
|
thread::spawn(move || {
|
||||||
|
let mut socket = File::create(":rand").expect("rand: failed to create rand scheme");
|
||||||
|
let scheme = RandScheme;
|
||||||
|
loop {
|
||||||
|
let mut packet = Packet::default();
|
||||||
|
socket.read(&mut packet).expect("rand: failed to read events from rand scheme");
|
||||||
|
scheme.handle(&mut packet);
|
||||||
|
socket.write(&packet).expect("rand: failed to write responses to rand scheme");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in a new issue