summaryrefslogtreecommitdiff
path: root/sys/dev/rnd.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2014-06-13 08:26:11 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2014-06-13 08:26:11 +0000
commitf9ab359b99bd78300d29459fe26f256c4e874b84 (patch)
tree040ab7b6bccf670fd442d5fa8821fb351732d4c1 /sys/dev/rnd.c
parentb7015063bce0833ac21f80cc9075f6d9a67f6500 (diff)
Add new getentropy() system call. Code and pressure from matthew.
I accepted that he's right (again) to seperate this out from heavy sysctl API and this will simply a variety of things. Functionname is not used by anyone in the ports tree, so we guess we can use it. Shocking that no application has a function called this. ok matthew & others who pushed him to start this early on
Diffstat (limited to 'sys/dev/rnd.c')
-rw-r--r--sys/dev/rnd.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/sys/dev/rnd.c b/sys/dev/rnd.c
index 4fdfe64ce09..68f2eda42ca 100644
--- a/sys/dev/rnd.c
+++ b/sys/dev/rnd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rnd.c,v 1.155 2014/02/05 05:54:58 tedu Exp $ */
+/* $OpenBSD: rnd.c,v 1.156 2014/06/13 08:26:09 deraadt Exp $ */
/*
* Copyright (c) 2011 Theo de Raadt.
@@ -123,6 +123,8 @@
#include <sys/mutex.h>
#include <sys/task.h>
#include <sys/msgbuf.h>
+#include <sys/mount.h>
+#include <sys/syscallargs.h>
#include <crypto/md5.h>
@@ -928,3 +930,26 @@ randomioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
}
return 0;
}
+
+int
+sys_getentropy(struct proc *p, void *v, register_t *retval)
+{
+ struct sys_getentropy_args /* {
+ syscallarg(void *) buf;
+ syscallarg(size_t) nbyte;
+ } */ *uap = v;
+ char buf[256];
+ int error;
+ size_t nbyte;
+
+ nbyte = SCARG(uap, nbyte);
+ if (nbyte > sizeof(buf))
+ nbyte = sizeof(buf);
+
+ arc4random_buf(buf, nbyte);
+ if ((error = copyout(buf, SCARG(uap, buf), nbyte)) != 0)
+ return (error);
+
+ retval[0] = nbyte;
+ return (0);
+}