pc: use lx_emul_gen_random_bytes() for randomness

Fixes #4544
This commit is contained in:
Christian Helmuth 2022-06-23 13:45:16 +02:00
parent 427f3bb634
commit 47c924d1f5
12 changed files with 59 additions and 73 deletions

View File

@ -1,6 +1,7 @@
/**
* \brief Dummy definitions of lx_emul
* \author Stefan Kalkowski
* \author Christian Helmuth
* \date 2022-01-10
*/
@ -48,9 +49,7 @@ int wait_for_random_bytes(void)
u32 get_random_u32(void)
{
u8 buf[4];
lx_emul_gen_random_bytes(buf, sizeof(buf));
return *((u32*)&buf);
return lx_emul_gen_random_uint();
}
@ -58,18 +57,16 @@ u32 get_random_u32(void)
u32 prandom_u32(void)
{
u8 buf[4];
lx_emul_gen_random_bytes(buf, sizeof(buf));
return *((u32*)&buf);
return lx_emul_gen_random_uint();
}
#include <linux/random.h>
int __must_check get_random_bytes_arch(void * buf,int nbytes)
int __must_check get_random_bytes_arch(void * buf, int nbytes)
{
lx_emul_gen_random_bytes(buf, nbytes);
return 0;
return nbytes;
}

View File

@ -3,6 +3,7 @@
* \author Josef Soentgen
* \author Stefan Kalkowski
* \author Martin Stein
* \author Christian Helmuth
* \date 2022-05-19
*
* :Warning:
@ -41,6 +42,7 @@ void lx_emul_gen_random_bytes(void *dst,
* Return a random unsigned integer value.
*/
unsigned int lx_emul_gen_random_uint(void);
unsigned long long lx_emul_gen_random_u64(void);
#ifdef __cplusplus
}

View File

@ -3,6 +3,7 @@
* \author Josef Soentgen
* \author Stefan Kalkowski
* \author Martin Stein
* \author Christian Helmuth
* \date 2022-05-19
*
* :Warning:
@ -220,3 +221,9 @@ unsigned int lx_emul_gen_random_uint()
{
return (unsigned int)xoroshiro().get_u64();
}
unsigned long long lx_emul_gen_random_u64()
{
return xoroshiro().get_u64();
}

View File

@ -18,6 +18,7 @@ SRC_CC += lx_emul/clock.cc
SRC_CC += lx_emul/io_mem.cc
SRC_CC += lx_emul/io_port.cc
SRC_CC += lx_emul/irq.cc
SRC_CC += lx_emul/random.cc
SRC_C += lx_emul/shadow/kernel/dma/mapping.c
SRC_C += lx_emul/shadow/kernel/irq/spurious.c
SRC_C += lx_emul/shadow/kernel/rcu/tree.c
@ -51,6 +52,7 @@ SRC_C += lx_emul/shadow/fs/libfs.c
SRC_C += lx_emul/shadow/kernel/rcu/tiny.c
SRC_C += lx_emul/shadow/lib/logic_iomem.c
SRC_C += lx_emul/shadow/drivers/char/random.c
SRC_C += lx_emul/shadow/drivers/acpi/bus.c
SRC_C += lx_emul/shadow/drivers/acpi/device_sysfs.c
SRC_C += lx_emul/shadow/drivers/acpi/glue.c

View File

@ -1,9 +1,10 @@
base
os
platform_session
timer_session
report_session
capture_session
blit
capture_session
genode_c_api
jitterentropy
os
pc_linux
platform_session
report_session
timer_session

View File

@ -1,8 +1,9 @@
base
genode_c_api
jitterentropy
os
pc_linux
platform_session
report_session
timer_session
usb_session
report_session
genode_c_api
pc_linux

View File

@ -1,7 +1,7 @@
/*
* \brief Dummy definitions of Linux Kernel functions
* \author Automatically generated file - do no edit
* \date 2022-05-06
* \date 2022-06-24
*/
#include <lx_emul.h>
@ -620,22 +620,6 @@ int get_option(char ** str,int * pint)
}
#include <linux/random.h>
u32 get_random_u32(void)
{
lx_emul_trace_and_stop(__func__);
}
#include <linux/random.h>
u64 get_random_u64(void)
{
lx_emul_trace_and_stop(__func__);
}
#include <linux/i2c.h>
s32 i2c_smbus_read_block_data(const struct i2c_client * client,u8 command,u8 * values)

View File

@ -3,7 +3,7 @@ REQUIRES := x86
REL_PRG_DIR := $(PRG_DIR)/../..
TARGET := pc_intel_fb_drv
LIBS := base pc_lx_emul blit
LIBS := base pc_lx_emul blit jitterentropy
INC_DIR += $(REL_PRG_DIR)
INC_DIR += $(REL_PRG_DIR)/shadow
@ -22,7 +22,6 @@ SRC_C += timeout.c
SRC_C += lx_emul/common_dummies.c
SRC_C += lx_emul/spec/x86/pci.c
SRC_C += lx_emul/shadow/mm/page_alloc.c
SRC_C += lx_emul/shadow/drivers/char/random.c
vpath %.c $(REL_PRG_DIR)
vpath %.cc $(REL_PRG_DIR)

View File

@ -3,7 +3,7 @@ REQUIRES := x86
REL_PRG_DIR := $(PRG_DIR)/../..
TARGET := pc_usb_host_drv
LIBS := base pc_lx_emul
LIBS := base pc_lx_emul jitterentropy
INC_DIR += $(REL_PRG_DIR)
SRC_CC += main.cc
@ -15,7 +15,6 @@ SRC_C += $(notdir $(wildcard $(REL_PRG_DIR)/generated_dummies.c))
SRC_C += common_dummies.c
SRC_C += lx_emul/spec/x86/pci.c
SRC_C += lx_emul/usb.c
SRC_C += lx_emul/shadow/drivers/char/random.c
SRC_C += lx_emul/shadow/lib/kobject_uevent.c
vpath %.c $(REP_DIR)/src/lib/pc

View File

@ -1,6 +1,7 @@
/*
* \brief Replaces drivers/char/random.c
* \author Josef Soentgen
* \author Christian Helmuth
* \date 2022-04-05
*/
@ -12,17 +13,40 @@
*/
#include <lx_emul.h>
#include <lx_emul/random.h>
#include <linux/random.h>
void get_random_bytes(void * buf,int nbytes)
void add_input_randomness(unsigned int type,unsigned int code,unsigned int value)
{
lx_emul_trace(__func__);
lx_emul_trace(__func__);
}
int __must_check get_random_bytes_arch(void * buf,int nbytes)
u32 get_random_u32(void)
{
lx_emul_trace(__func__);
return 0;
return lx_emul_gen_random_uint();
}
u64 get_random_u64(void)
{
return lx_emul_gen_random_u64();
}
int __must_check get_random_bytes_arch(void *buf, int nbytes)
{
if (nbytes < 0)
return -1;
lx_emul_gen_random_bytes(buf, nbytes);
return nbytes;
}
void get_random_bytes(void *buf, int nbytes)
{
nbytes = get_random_bytes_arch(buf, nbytes);
}

View File

@ -1,7 +1,7 @@
/*
* \brief Dummy definitions of Linux Kernel functions
* \author Automatically generated file - do no edit
* \date 2022-05-06
* \date 2022-06-24
*/
#include <lx_emul.h>
@ -578,11 +578,6 @@ bool is_software_node(const struct fwnode_handle * fwnode)
}
#include <linux/jiffies.h>
unsigned long volatile __cacheline_aligned_in_smp __jiffy_arch_data jiffies;
#include <linux/kobject.h>
struct kobject *kernel_kobj;

View File

@ -455,31 +455,6 @@ void __put_page(struct page * page)
}
#include <linux/random.h>
u32 get_random_u32(void)
{
return lx_emul_gen_random_uint();
}
int __must_check get_random_bytes_arch(void *buf, int nbytes)
{
if (nbytes < 0)
return -1;
lx_emul_gen_random_bytes(buf, (unsigned long)nbytes);
return 0;
}
void get_random_bytes(void *buf, int nbytes)
{
int const err = get_random_bytes_arch(buf, nbytes);
(void)err;
}
#include <linux/prandom.h>
void prandom_bytes(void *buf, size_t bytes)