genode/repos/dde_rump/src/server/rump_cgd/random.cc
Christian Helmuth f1c877f205 Use Genode::size_t in rumpuser_getrandom_backend()
This streamlines the Genode-specific interface for both 32-bit and
64-bit architectures and fixes dynamic-linking issue with the rump
VFS due to differing size_t types.
2017-01-31 12:01:13 +01:00

64 lines
1.1 KiB
C++

/**
* \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/log.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)) {
Genode::error("failed to read entropy: ", err);
return 0;
}
return len;
}
};
int rumpuser_getrandom_backend(void *buf, size_t buflen, int flags, Genode::size_t *retp)
{
*retp = Entropy::e()->read((char *)buf, buflen);
return 0;
}