diff options
author | deraadt <> | 2014-07-19 00:08:43 +0000 |
---|---|---|
committer | deraadt <> | 2014-07-19 00:08:43 +0000 |
commit | 63559a378edd18f00978f68eeb77fbd0f088a804 (patch) | |
tree | d1d1ea706aec9066edcbf60e8dd1c10257101a1d /src/lib/libc/crypt/arc4random.h | |
parent | c08eb4d65e7656f34e0b7949bf7f3102cb5faaeb (diff) | |
download | openbsd-63559a378edd18f00978f68eeb77fbd0f088a804.tar.gz openbsd-63559a378edd18f00978f68eeb77fbd0f088a804.tar.bz2 openbsd-63559a378edd18f00978f68eeb77fbd0f088a804.zip |
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 'src/lib/libc/crypt/arc4random.h')
-rw-r--r-- | src/lib/libc/crypt/arc4random.h | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/lib/libc/crypt/arc4random.h b/src/lib/libc/crypt/arc4random.h index e0309a3184..d867687226 100644 --- a/src/lib/libc/crypt/arc4random.h +++ b/src/lib/libc/crypt/arc4random.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: arc4random.h,v 1.1 2014/07/18 02:05:55 deraadt Exp $ */ | 1 | /* $OpenBSD: arc4random.h,v 1.2 2014/07/19 00:08:41 deraadt Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> | 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> |
@@ -22,25 +22,28 @@ | |||
22 | * Stub functions for portability. | 22 | * Stub functions for portability. |
23 | */ | 23 | */ |
24 | 24 | ||
25 | static inline void * | 25 | static inline int |
26 | _rs_allocate(size_t len) | 26 | _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) |
27 | { | 27 | { |
28 | void *p; | 28 | struct { |
29 | struct _rs rs; | ||
30 | struct _rsx rsx; | ||
31 | } *p; | ||
29 | 32 | ||
30 | if ((p = mmap(NULL, sizeof(*rs), PROT_READ|PROT_WRITE, | 33 | if ((p = mmap(NULL, sizeof(*p), PROT_READ|PROT_WRITE, |
31 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) | 34 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) |
32 | return (NULL); | 35 | return (-1); |
33 | return (p); | 36 | if (minherit(p, sizeof(*p), MAP_INHERIT_ZERO) == -1) { |
34 | } | 37 | munmap(p, sizeof(*p)); |
38 | return (-1); | ||
39 | } | ||
35 | 40 | ||
36 | static inline void | 41 | *rsp = &p->rs; |
37 | _rs_forkdetect(void) | 42 | *rsxp = &p->rsx; |
38 | { | 43 | return (0); |
39 | } | 44 | } |
40 | 45 | ||
41 | static inline void | 46 | static inline void |
42 | _rs_forkdetectsetup(struct _rs *rs, size_t len) | 47 | _rs_forkdetect(void) |
43 | { | 48 | { |
44 | if (minherit(rs, len, MAP_INHERIT_ZERO) == -1) | ||
45 | abort(); | ||
46 | } | 49 | } |