From f9ab359b99bd78300d29459fe26f256c4e874b84 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Fri, 13 Jun 2014 08:26:11 +0000 Subject: 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 --- sys/dev/rnd.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'sys/dev/rnd.c') 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 #include #include +#include +#include #include @@ -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); +} -- cgit v1.2.3