diff options
author | Oleksij Rempel <o.rempel@pengutronix.de> | 2017-03-22 10:14:36 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2017-03-30 08:23:20 +0200 |
commit | 35ca79bb22b64c4fc78691743ce42379c29fd247 (patch) | |
tree | 43770e3423757414fedae4ea9dea8c67e6197406 /commands/stddev.c | |
parent | 451733ac8a5020d92b4ce4b1566bcb08f8cacc71 (diff) | |
download | barebox-35ca79bb22b64c4fc78691743ce42379c29fd247.tar.gz barebox-35ca79bb22b64c4fc78691743ce42379c29fd247.tar.xz |
fs: add prng device
this should provide easy access to get_random_bytes() interfaces.
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/stddev.c')
-rw-r--r-- | commands/stddev.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/commands/stddev.c b/commands/stddev.c index 318d057417..93da2c7398 100644 --- a/commands/stddev.c +++ b/commands/stddev.c @@ -17,6 +17,7 @@ #include <common.h> #include <init.h> +#include <stdlib.h> static ssize_t zero_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags) { @@ -100,3 +101,31 @@ static int null_init(void) } device_initcall(null_init); + +static ssize_t prng_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags) +{ + get_random_bytes(buf, count); + return count; +} + +static struct file_operations prngops = { + .read = prng_read, + .lseek = dev_lseek_default, +}; + +static int prng_init(void) +{ + struct cdev *cdev; + + cdev = xzalloc(sizeof (*cdev)); + + cdev->name = "prng"; + cdev->flags = DEVFS_IS_CHARACTER_DEV; + cdev->ops = &prngops; + + devfs_create(cdev); + + return 0; +} + +device_initcall(prng_init); |