diff options
Diffstat (limited to '')
| -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 | ||
