[PATCH v4 4/7] fs: add prng device
Oleksij Rempel
o.rempel at pengutronix.de
Tue Mar 21 02:24:08 PDT 2017
this should provide easy access to get_random_bytes() interfaces.
Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
---
commands/stddev.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/commands/stddev.c b/commands/stddev.c
index 318d05741..93da2c739 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);
--
2.11.0
More information about the barebox
mailing list