diff options
| author | deraadt <> | 2014-07-19 00:08:43 +0000 |
|---|---|---|
| committer | deraadt <> | 2014-07-19 00:08:43 +0000 |
| commit | 7dda705eb34d88c4c8c8ece0a009c6cac7b14c67 (patch) | |
| tree | d1d1ea706aec9066edcbf60e8dd1c10257101a1d /src/lib/libc/crypt/arc4random.c | |
| parent | cb6d7664a81745720f33266734161b267e83c5dd (diff) | |
| download | openbsd-7dda705eb34d88c4c8c8ece0a009c6cac7b14c67.tar.gz openbsd-7dda705eb34d88c4c8c8ece0a009c6cac7b14c67.tar.bz2 openbsd-7dda705eb34d88c4c8c8ece0a009c6cac7b14c67.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.c')
| -rw-r--r-- | src/lib/libc/crypt/arc4random.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/lib/libc/crypt/arc4random.c b/src/lib/libc/crypt/arc4random.c index d42022c455..3c80beb3b9 100644 --- a/src/lib/libc/crypt/arc4random.c +++ b/src/lib/libc/crypt/arc4random.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: arc4random.c,v 1.47 2014/07/18 02:05:55 deraadt Exp $ */ | 1 | /* $OpenBSD: arc4random.c,v 1.48 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> |
| @@ -57,17 +57,16 @@ static struct _rs { | |||
| 57 | size_t rs_count; /* bytes till reseed */ | 57 | size_t rs_count; /* bytes till reseed */ |
| 58 | } *rs; | 58 | } *rs; |
| 59 | 59 | ||
| 60 | static inline void *_rs_allocate(size_t len); | 60 | /* Maybe be preserved in fork children, if _rs_allocate() decides. */ |
| 61 | static inline void _rs_forkdetect(void); | 61 | static struct _rsx { |
| 62 | static inline void _rs_forkdetectsetup(struct _rs *buf, size_t len); | ||
| 63 | #include "arc4random.h" | ||
| 64 | |||
| 65 | /* Preserved in fork children. */ | ||
| 66 | static struct { | ||
| 67 | chacha_ctx rs_chacha; /* chacha context for random keystream */ | 62 | chacha_ctx rs_chacha; /* chacha context for random keystream */ |
| 68 | u_char rs_buf[RSBUFSZ]; /* keystream blocks */ | 63 | u_char rs_buf[RSBUFSZ]; /* keystream blocks */ |
| 69 | } *rsx; | 64 | } *rsx; |
| 70 | 65 | ||
| 66 | static inline int _rs_allocate(struct _rs **, struct _rsx **); | ||
| 67 | static inline void _rs_forkdetect(void); | ||
| 68 | #include "arc4random.h" | ||
| 69 | |||
| 71 | static inline void _rs_rekey(u_char *dat, size_t datlen); | 70 | static inline void _rs_rekey(u_char *dat, size_t datlen); |
| 72 | 71 | ||
| 73 | static inline void | 72 | static inline void |
| @@ -77,12 +76,7 @@ _rs_init(u_char *buf, size_t n) | |||
| 77 | return; | 76 | return; |
| 78 | 77 | ||
| 79 | if (rs == NULL) { | 78 | if (rs == NULL) { |
| 80 | if ((rs = _rs_allocate(sizeof(*rs))) == NULL) | 79 | if (_rs_allocate(&rs, &rsx) == -1) |
| 81 | abort(); | ||
| 82 | _rs_forkdetectsetup(rs, sizeof(*rs)); | ||
| 83 | } | ||
| 84 | if (rsx == NULL) { | ||
| 85 | if ((rsx = _rs_allocate(sizeof(*rsx))) == NULL) | ||
| 86 | abort(); | 80 | abort(); |
| 87 | } | 81 | } |
| 88 | 82 | ||
