Skip to content

Commit

Permalink
vfs/xoroshiro: add PRNG plugin using Xoroshiro128+
Browse files Browse the repository at this point in the history
This plugin provides a PRNG based on the Xoroshiro128+ algorithm
that reseeds itself after a specific amount of state was consumed.

For more detailed information please take a look at its README in
'repos/os/src/lib/vfs/xoroshiro/README'.

Fixes genodelabs#5407.
  • Loading branch information
cnuke committed Dec 16, 2024
1 parent cf21c1a commit 3db40db
Show file tree
Hide file tree
Showing 8 changed files with 422 additions and 0 deletions.
94 changes: 94 additions & 0 deletions repos/gems/run/vfs_xoroshiro.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
build { lib/vfs_xoroshiro lib/vfs_jitterentropy }

create_boot_directory

import_from_depot \
[depot_user]/src/[base_src] \
[depot_user]/src/coreutils \
[depot_user]/src/init \
[depot_user]/src/fs_rom \
[depot_user]/src/libc \
[depot_user]/src/vfs \
[depot_user]/src/posix

install_config {
<config verbose="yes">
<parent-provides>
<service name="ROM"/>
<service name="LOG"/>
<service name="RM"/>
<service name="CPU"/>
<service name="PD"/>
<service name="IRQ"/>
<service name="IO_MEM"/>
<service name="IO_PORT"/>
</parent-provides>

<default-route>
<any-service> <parent/> </any-service>
</default-route>
<default caps="100"/>

<start name="timer">
<resource name="RAM" quantum="1M"/>
<provides><service name="Timer"/></provides>
</start>

<start name="vfs">
<resource name="RAM" quantum="4M"/>
<provides><service name="File_system"/></provides>
<config>
<vfs>
<ram/>
<tar name="coreutils.tar" />
</vfs>
<default-policy root="/" writeable="yes"/>
</config>
</start>

<start name="vfs_rom">
<resource name="RAM" quantum="10M"/>
<binary name="fs_rom"/>
<provides> <service name="ROM"/> </provides>
<config/>
<route>
<service name="File_system"> <child name="vfs"/> </service>
<any-service> <parent/> </any-service>
</route>
</start>

<start name="/bin/dd" caps="500">
<resource name="RAM" quantum="16M"/>
<config>
<libc stdin="/dev/null" stdout="/dev/log" stderr="/dev/log"
rtc="/dev/null"/>
<vfs>
<dir name="dev">
<log/>
<null/>
<jitterentropy name="entropy"/>
<xoroshiro name="random" seed_file="/dev/entropy"/>
</dir>
</vfs>
<arg value="dd"/>
<arg value="if=/dev/random"/>
<arg value="of=/dev/null"/>
<arg value="bs=1M"/>
<arg value="count=128"/>
</config>
<route>
<service name="File_system"> <child name="vfs"/> </service>
<service name="ROM" label_suffix=".lib.so"> <parent/> </service>
<service name="ROM" label_last="/bin/dd"> <child name="vfs_rom"/> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
</start>

</config>
}

build_boot_image [build_artifacts]

append qemu_args " -nographic "

run_genode_until "child .* exited with exit value 0.*\n" 20
12 changes: 12 additions & 0 deletions repos/os/lib/mk/vfs_xoroshiro.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
VFS_DIR := $(REP_DIR)/src/lib/vfs/xoroshiro

SRC_CC := vfs.cc

# for base/internal/xoroshiro.h
REP_INC_DIR += src/include/base/internal

LD_OPT += --version-script=$(VFS_DIR)/symbol.map

SHARED_LIB := yes

vpath %.cc $(VFS_DIR)
17 changes: 17 additions & 0 deletions repos/os/recipes/src/vfs_xoroshiro/content.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
MIRROR_FROM_REP_DIR := src/lib/vfs/xoroshiro lib/mk/vfs_xoroshiro.mk

content: $(MIRROR_FROM_REP_DIR) LICENSE

$(MIRROR_FROM_REP_DIR):
$(mirror_from_rep_dir)

MIRROR_FROM_BASE_DIR := src/include/base/internal/xoroshiro.h

content: $(MIRROR_FROM_BASE_DIR)

$(MIRROR_FROM_BASE_DIR):
mkdir -p $(dir $@)
cp -r $(addprefix $(GENODE_DIR)/repos/base/,$@) $(dir $@)

LICENSE:
cp $(GENODE_DIR)/LICENSE $@
1 change: 1 addition & 0 deletions repos/os/recipes/src/vfs_xoroshiro/hash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-12-16 af40f4293fa0bc3a44ff27b6a174d37a0ecce3eb
3 changes: 3 additions & 0 deletions repos/os/recipes/src/vfs_xoroshiro/used_apis
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
base
os
vfs
20 changes: 20 additions & 0 deletions repos/os/src/lib/vfs/xoroshiro/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The VFS xoroshiro plugin provides a PRNG based on the Xoroshiro12+
algorithm. It is seeded initially and reseeded regularly after a fixed
amount of bytes, around 1 MiB, were produced by reading a seed file.

The plugin supports the following configuration options:

* :name: sets the file-name under which the plugins exposes itself
to the VFS, the default is 'xoroshiro'.

* :seed_file: specifies the file in the VFS that is read to reseed
the PRNG, the default is '/dev/entropy'.

The following examplary config snippets illustrates its usage:

! <vfs>
! <dir name="dev">
! <jitterentropy name="entropy"/>
! <xoroshiro name="random"/>
! </dir>
! </vfs>
9 changes: 9 additions & 0 deletions repos/os/src/lib/vfs/xoroshiro/symbol.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
global:

vfs_file_system_factory;

local:

*;
};
Loading

0 comments on commit 3db40db

Please sign in to comment.