From 35ca79bb22b64c4fc78691743ce42379c29fd247 Mon Sep 17 00:00:00 2001 From: Oleksij Rempel Date: Wed, 22 Mar 2017 10:14:36 +0100 Subject: fs: add prng device this should provide easy access to get_random_bytes() interfaces. Signed-off-by: Oleksij Rempel Signed-off-by: Sascha Hauer --- commands/stddev.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'commands') 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 #include +#include 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); -- cgit v1.2.3