mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-19 05:37:54 +00:00
rump: Add 'get_random_backend' function
A rump server may now implement its own random number generator, the default impelementation will not generate random number. Issue #1409
This commit is contained in:
parent
a594ae703d
commit
422923cc95
21
repos/dde_rump/include/util/random.h
Normal file
21
repos/dde_rump/include/util/random.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* \brief Overwritable backend-random methods
|
||||||
|
* \author Sebastian Sumpf
|
||||||
|
* \date 2015-02-13
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 Genode Labs GmbH
|
||||||
|
*
|
||||||
|
* This file is part of the Genode OS framework, which is distributed
|
||||||
|
* under the terms of the GNU General Public License version 2.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _INCLUDE__UTIL__RANDOM_H_
|
||||||
|
#define _INCLUDE__UTIL__RANDOM_H_
|
||||||
|
|
||||||
|
#include <base/stdint.h>
|
||||||
|
|
||||||
|
int rumpuser_getrandom_backend(void *buf, Genode::size_t buflen, int flags, Genode::size_t *retp);
|
||||||
|
|
||||||
|
#endif /* _INCLUDE__UTIL__RANDOM_H_ */
|
@ -12,11 +12,6 @@ RMAKE = $(RUMP_TOOLS)/rumpmake
|
|||||||
#
|
#
|
||||||
VERBOSE_LEVEL ?= 0
|
VERBOSE_LEVEL ?= 0
|
||||||
|
|
||||||
#
|
|
||||||
# Libraries
|
|
||||||
#
|
|
||||||
LIBS += jitterentropy
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Sources
|
# Sources
|
||||||
#
|
#
|
||||||
|
@ -19,14 +19,9 @@
|
|||||||
#include <base/sleep.h>
|
#include <base/sleep.h>
|
||||||
#include <os/timed_semaphore.h>
|
#include <os/timed_semaphore.h>
|
||||||
#include <util/allocator_fap.h>
|
#include <util/allocator_fap.h>
|
||||||
|
#include <util/random.h>
|
||||||
#include <util/string.h>
|
#include <util/string.h>
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
namespace Jitter {
|
|
||||||
#include <jitterentropy.h>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void wait_for_continue();
|
extern "C" void wait_for_continue();
|
||||||
enum { SUPPORTED_RUMP_VERSION = 17 };
|
enum { SUPPORTED_RUMP_VERSION = 17 };
|
||||||
|
|
||||||
@ -36,38 +31,6 @@ static bool verbose = false;
|
|||||||
struct rumpuser_hyperup _rump_upcalls;
|
struct rumpuser_hyperup _rump_upcalls;
|
||||||
|
|
||||||
|
|
||||||
/***********************************
|
|
||||||
** Jitter entropy for randomness **
|
|
||||||
***********************************/
|
|
||||||
|
|
||||||
struct Entropy
|
|
||||||
{
|
|
||||||
struct Jitter::rand_data *ec_stir;
|
|
||||||
|
|
||||||
Entropy()
|
|
||||||
{
|
|
||||||
Jitter::jent_entropy_init();
|
|
||||||
ec_stir = Jitter::jent_entropy_collector_alloc(0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Entropy *e()
|
|
||||||
{
|
|
||||||
static Entropy _e;
|
|
||||||
return &_e;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t read(char *buf, size_t len)
|
|
||||||
{
|
|
||||||
int err;
|
|
||||||
if ((err = Jitter::jent_read_entropy(ec_stir, buf, len) < 0)) {
|
|
||||||
PERR("Failed to read entropy: %d", err);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/********************
|
/********************
|
||||||
** Initialization **
|
** Initialization **
|
||||||
********************/
|
********************/
|
||||||
@ -90,9 +53,6 @@ int rumpuser_init(int version, const struct rumpuser_hyperup *hyp)
|
|||||||
*/
|
*/
|
||||||
Genode::Timeout_thread::alarm_timer();
|
Genode::Timeout_thread::alarm_timer();
|
||||||
|
|
||||||
/* initialize jitter entropy */
|
|
||||||
Entropy::e();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,8 +296,7 @@ int rumpuser_clock_sleep(int enum_rumpclock, int64_t sec, long nsec)
|
|||||||
|
|
||||||
int rumpuser_getrandom(void *buf, size_t buflen, int flags, size_t *retp)
|
int rumpuser_getrandom(void *buf, size_t buflen, int flags, size_t *retp)
|
||||||
{
|
{
|
||||||
*retp = Entropy::e()->read((char *)buf, buflen);
|
return rumpuser_getrandom_backend(buf, buflen, flags, retp);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,6 +15,15 @@
|
|||||||
#include <util/string.h>
|
#include <util/string.h>
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* On some platforms (namely ARM) we end-up pulling in string.h prototypes
|
||||||
|
*/
|
||||||
|
extern "C" void *memcpy(void *d, void *s, Genode::size_t n)
|
||||||
|
{
|
||||||
|
return Genode::memcpy(d, s, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
extern "C" void *memset(void *s, int c, Genode::size_t n)
|
extern "C" void *memset(void *s, int c, Genode::size_t n)
|
||||||
{
|
{
|
||||||
return Genode::memset(s, c, n);
|
return Genode::memset(s, c, n);
|
||||||
|
64
repos/dde_rump/src/server/rump_cgd/random.cc
Normal file
64
repos/dde_rump/src/server/rump_cgd/random.cc
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/**
|
||||||
|
* \brief Add random support for CGD
|
||||||
|
* \author Sebastian Sumpf
|
||||||
|
* \date 2015-02-13
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 Genode Labs GmbH
|
||||||
|
*
|
||||||
|
* This file is part of the Genode OS framework, which is distributed
|
||||||
|
* under the terms of the GNU General Public License version 2.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <base/printf.h>
|
||||||
|
#include <util/random.h>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
namespace Jitter {
|
||||||
|
#include <jitterentropy.h>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef Genode::size_t size_t;
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
** Jitter entropy for randomness **
|
||||||
|
***********************************/
|
||||||
|
|
||||||
|
struct Entropy
|
||||||
|
{
|
||||||
|
struct Jitter::rand_data *ec_stir;
|
||||||
|
|
||||||
|
Entropy()
|
||||||
|
{
|
||||||
|
Jitter::jent_entropy_init();
|
||||||
|
ec_stir = Jitter::jent_entropy_collector_alloc(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Entropy *e()
|
||||||
|
{
|
||||||
|
static Entropy _e;
|
||||||
|
return &_e;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t read(char *buf, size_t len)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
if ((err = Jitter::jent_read_entropy(ec_stir, buf, len) < 0)) {
|
||||||
|
PERR("Failed to read entropy: %d", err);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int rumpuser_getrandom_backend(void *buf, size_t buflen, int flags, size_t *retp)
|
||||||
|
{
|
||||||
|
*retp = Entropy::e()->read((char *)buf, buflen);
|
||||||
|
*retp = buflen;
|
||||||
|
return 0;
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
TARGET = rump_cgd
|
TARGET = rump_cgd
|
||||||
SRC_CC = cgd.cc main.cc
|
|
||||||
LIBS = rump rump_cgd server startup
|
SRC_CC = cgd.cc main.cc random.cc
|
||||||
|
LIBS = rump rump_cgd server startup jitterentropy
|
||||||
|
21
repos/dde_rump/src/server/rump_fs/random.cc
Normal file
21
repos/dde_rump/src/server/rump_fs/random.cc
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* \brief Dummy random support
|
||||||
|
* \author Sebastian Sumpf
|
||||||
|
* \date 2015-02-16
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 Genode Labs GmbH
|
||||||
|
*
|
||||||
|
* This file is part of the Genode OS framework, which is distributed
|
||||||
|
* under the terms of the GNU General Public License version 2.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <util/random.h>
|
||||||
|
|
||||||
|
|
||||||
|
int rumpuser_getrandom_backend(void *buf, Genode::size_t buflen, int flags, Genode::size_t *retp)
|
||||||
|
{
|
||||||
|
*retp = buflen;
|
||||||
|
return 0;
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
TARGET = rump_fs
|
TARGET = rump_fs
|
||||||
SRC_CC = main.cc file_system.cc
|
SRC_CC = main.cc file_system.cc random.cc
|
||||||
LIBS = rump rump_fs server startup
|
LIBS = rump rump_fs server startup
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user