From cbf3e14ec7834e54db468122cf6865c84e80d25b Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Sat, 14 Jun 2014 18:01:43 +0000 Subject: Change return value of getentropy() to int 0 for success. Maximum buffersize is enforced strictly, this supplies sufficient entropy payload to act as seed material. Discourage general use of this API, but lock down this function name as the go-to for userland PRNG seeding. Improve documentation. ok miod matthew --- sys/dev/rnd.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'sys/dev') diff --git a/sys/dev/rnd.c b/sys/dev/rnd.c index 68f2eda42ca..d6414b6de34 100644 --- a/sys/dev/rnd.c +++ b/sys/dev/rnd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rnd.c,v 1.156 2014/06/13 08:26:09 deraadt Exp $ */ +/* $OpenBSD: rnd.c,v 1.157 2014/06/14 18:01:42 deraadt Exp $ */ /* * Copyright (c) 2011 Theo de Raadt. @@ -940,16 +940,12 @@ sys_getentropy(struct proc *p, void *v, register_t *retval) } */ *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) + if (SCARG(uap, nbyte) > sizeof(buf)) + return (EIO); + arc4random_buf(buf, SCARG(uap, nbyte)); + if ((error = copyout(buf, SCARG(uap, buf), SCARG(uap, nbyte))) != 0) return (error); - - retval[0] = nbyte; + retval[0] = 0; return (0); } -- cgit v1.2.3