diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2014-06-14 18:01:43 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2014-06-14 18:01:43 +0000 |
commit | cbf3e14ec7834e54db468122cf6865c84e80d25b (patch) | |
tree | 0f4072bf208ecf532b24841cc42cb5e6da132f13 /sys/dev | |
parent | ba0463e107f357d96efbd924e14f1514be0cdd26 (diff) |
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
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/rnd.c | 16 |
1 files changed, 6 insertions, 10 deletions
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); } |