diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2014-07-19 00:08:44 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2014-07-19 00:08:44 +0000 |
commit | 211b0d727b3ed428e75706ff6887a9dd30029a33 (patch) | |
tree | 8aab649f11abac85559d2a87fc07360753179339 /lib/libcrypto | |
parent | c80b1e1bd26a00b37c28de3a88ffe420aaf1fa77 (diff) |
Change _rs_allocate so it can combine the two regions (rs and rsx)
into one if a system has an awesome getentropy(). In that case it
is valid to totally throw away the rsx state in the child. If the
getentropy() is not very good and has a lazy reseed operation, this
combining is a bad idea, and the reseed should probably continue to
use the "something old, something new" mix. _rs_allocate() can
accomodate either method, but not on the fly.
ok matthew
Diffstat (limited to 'lib/libcrypto')
-rw-r--r-- | lib/libcrypto/arc4random/arc4random_linux.h | 29 | ||||
-rw-r--r-- | lib/libcrypto/arc4random/arc4random_osx.h | 29 | ||||
-rw-r--r-- | lib/libcrypto/arc4random/arc4random_solaris.h | 29 | ||||
-rw-r--r-- | lib/libcrypto/arc4random/arc4random_win.h | 23 |
4 files changed, 55 insertions, 55 deletions
diff --git a/lib/libcrypto/arc4random/arc4random_linux.h b/lib/libcrypto/arc4random/arc4random_linux.h index f02ae388d5f..a713d15e06d 100644 --- a/lib/libcrypto/arc4random/arc4random_linux.h +++ b/lib/libcrypto/arc4random/arc4random_linux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: arc4random_linux.h,v 1.2 2014/07/18 21:40:54 matthew Exp $ */ +/* $OpenBSD: arc4random_linux.h,v 1.3 2014/07/19 00:08:43 deraadt Exp $ */ /* * Copyright (c) 1996, David Mazieres <dm@uun.org> @@ -22,15 +22,21 @@ * Stub functions for portability. */ -static inline void * -_rs_allocate(size_t len) +static inline int +_rs_allocate(struct _rs **rsp, struct _rsx **rsxp) { - void *p; - - if ((p = mmap(NULL, len, PROT_READ|PROT_WRITE, + if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) - return (NULL); - return (p); + return (-1); + + if ((*rsxp = mmap(NULL, sizeof(**rsxp) PROT_READ|PROT_WRITE, + MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) { + munmap(*rsxp, sizeof(**rsxp); + return (-1); + } + + _ARC4_ATFORK(_rs_forkhandler); + return (0); } static volatile sig_atomic_t _rs_forked; @@ -54,10 +60,3 @@ _rs_forkdetect(void) memset(rs, 0, sizeof(*rs)); } } - -static inline void -_rs_forkdetectsetup(struct _rs *rs, size_t len) -{ - _ARC4_ATFORK(_rs_forkhandler); -} - diff --git a/lib/libcrypto/arc4random/arc4random_osx.h b/lib/libcrypto/arc4random/arc4random_osx.h index 46053a45b9f..ea4bd70fcd0 100644 --- a/lib/libcrypto/arc4random/arc4random_osx.h +++ b/lib/libcrypto/arc4random/arc4random_osx.h @@ -1,4 +1,4 @@ -/* $OpenBSD: arc4random_osx.h,v 1.2 2014/07/18 21:40:54 matthew Exp $ */ +/* $OpenBSD: arc4random_osx.h,v 1.3 2014/07/19 00:08:43 deraadt Exp $ */ /* * Copyright (c) 1996, David Mazieres <dm@uun.org> @@ -22,15 +22,21 @@ * Stub functions for portability. */ -static inline void * -_rs_allocate(size_t len) +static inline int +_rs_allocate(struct _rs **rsp, struct _rsx **rsxp) { - void *p; - - if ((p = mmap(NULL, len, PROT_READ|PROT_WRITE, + if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) - return (NULL); - return (p); + return (-1); + + if ((*rsxp = mmap(NULL, sizeof(**rsxp) PROT_READ|PROT_WRITE, + MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) { + munmap(*rsxp, sizeof(**rsxp); + return (-1); + } + + _ARC4_ATFORK(_rs_forkhandler); + return (0); } static volatile sig_atomic_t _rs_forked; @@ -54,10 +60,3 @@ _rs_forkdetect(void) memset(rs, 0, sizeof(*rs)); } } - -static inline void -_rs_forkdetectsetup(struct _rs *rs, size_t len) -{ - _ARC4_ATFORK(_rs_forkhandler); -} - diff --git a/lib/libcrypto/arc4random/arc4random_solaris.h b/lib/libcrypto/arc4random/arc4random_solaris.h index 2386dbe8851..ec9353f1b77 100644 --- a/lib/libcrypto/arc4random/arc4random_solaris.h +++ b/lib/libcrypto/arc4random/arc4random_solaris.h @@ -1,4 +1,4 @@ -/* $OpenBSD: arc4random_solaris.h,v 1.2 2014/07/18 21:40:54 matthew Exp $ */ +/* $OpenBSD: arc4random_solaris.h,v 1.3 2014/07/19 00:08:43 deraadt Exp $ */ /* * Copyright (c) 1996, David Mazieres <dm@uun.org> @@ -22,15 +22,21 @@ * Stub functions for portability. */ -static inline void * -_rs_allocate(size_t len) +static inline int +_rs_allocate(struct _rs **rsp, struct _rsx **rsxp) { - void *p; - - if ((p = mmap(NULL, len, PROT_READ|PROT_WRITE, + if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) - return (NULL); - return (p); + return (-1); + + if ((*rsxp = mmap(NULL, sizeof(**rsxp) PROT_READ|PROT_WRITE, + MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) { + munmap(*rsxp, sizeof(**rsxp); + return (-1); + } + + _ARC4_ATFORK(_rs_forkhandler); + return (0); } static volatile sig_atomic_t _rs_forked; @@ -54,10 +60,3 @@ _rs_forkdetect(void) memset(rs, 0, sizeof(*rs)); } } - -static inline void -_rs_forkdetectsetup(struct _rs *rs, size_t len) -{ - _ARC4_ATFORK(_rs_forkhandler); -} - diff --git a/lib/libcrypto/arc4random/arc4random_win.h b/lib/libcrypto/arc4random/arc4random_win.h index 7d01d42be50..1fc228d1091 100644 --- a/lib/libcrypto/arc4random/arc4random_win.h +++ b/lib/libcrypto/arc4random/arc4random_win.h @@ -1,4 +1,4 @@ -/* $OpenBSD: arc4random_win.h,v 1.1 2014/07/18 02:05:55 deraadt Exp $ */ +/* $OpenBSD: arc4random_win.h,v 1.2 2014/07/19 00:08:43 deraadt Exp $ */ /* * Copyright (c) 1996, David Mazieres <dm@uun.org> @@ -22,10 +22,19 @@ * Stub functions for portability. */ -static inline void * -_rs_allocate(size_t len) +static inline int +_rs_allocate(struct _rs **rsp, struct _rsx **rsxp) { - return calloc(1, sizeof(*rs)); + *rsp = calloc(1, sizeof(**rsp)); + if (*rsp == NULL) + return (-1); + + *rsxp = calloc(1, sizeof(**rsxp)); + if (*rsxp == NULL) { + free(*rsp); + return (-1); + } + return (0); } static inline void @@ -37,9 +46,3 @@ static inline void _rs_forkdetect(void) { } - -static inline void -_rs_forkdetectsetup(struct _rs *rs, size_t len) -{ -} - |