diff options
Diffstat (limited to 'src/lib/libc/crypt')
-rw-r--r-- | src/lib/libc/crypt/arc4random.c | 22 | ||||
-rw-r--r-- | src/lib/libc/crypt/arc4random.h | 31 |
2 files changed, 25 insertions, 28 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 | ||
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 | } |