summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorderaadt <>2014-07-18 02:05:55 +0000
committerderaadt <>2014-07-18 02:05:55 +0000
commitacdbce862be55ac5aef43be691bd06f8b9fab41b (patch)
treeab83a774dd030d8ad707e272102749a0d84230c0
parenteb33ac700a48895a01fed57fc9e3c0ef20f9824e (diff)
downloadopenbsd-acdbce862be55ac5aef43be691bd06f8b9fab41b.tar.gz
openbsd-acdbce862be55ac5aef43be691bd06f8b9fab41b.tar.bz2
openbsd-acdbce862be55ac5aef43be691bd06f8b9fab41b.zip
Seperate arc4random's os-dependent parts into static inline functions,
making it much easier for libressl -portable to fill in the gaps. ok bcook beck
-rw-r--r--src/lib/libc/crypt/arc4random.c47
-rw-r--r--src/lib/libc/crypt/arc4random.h46
-rw-r--r--src/lib/libcrypto/arc4random/arc4random_linux.h66
-rw-r--r--src/lib/libcrypto/arc4random/arc4random_osx.h66
-rw-r--r--src/lib/libcrypto/arc4random/arc4random_solaris.h66
-rw-r--r--src/lib/libcrypto/arc4random/arc4random_win.h45
-rw-r--r--src/lib/libcrypto/crypto/arc4random_linux.h66
-rw-r--r--src/lib/libcrypto/crypto/arc4random_osx.h66
-rw-r--r--src/lib/libcrypto/crypto/arc4random_solaris.h66
-rw-r--r--src/lib/libcrypto/crypto/arc4random_win.h45
10 files changed, 543 insertions, 36 deletions
diff --git a/src/lib/libc/crypt/arc4random.c b/src/lib/libc/crypt/arc4random.c
index 565bfa0333..d42022c455 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.46 2014/07/17 14:30:41 deraadt Exp $ */ 1/* $OpenBSD: arc4random.c,v 1.47 2014/07/18 02:05:55 deraadt Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org> 4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -52,11 +52,16 @@
52#define RSBUFSZ (16*BLOCKSZ) 52#define RSBUFSZ (16*BLOCKSZ)
53 53
54/* Marked MAP_INHERIT_ZERO, so zero'd out in fork children. */ 54/* Marked MAP_INHERIT_ZERO, so zero'd out in fork children. */
55static struct { 55static struct _rs {
56 size_t rs_have; /* valid bytes at end of rs_buf */ 56 size_t rs_have; /* valid bytes at end of rs_buf */
57 size_t rs_count; /* bytes till reseed */ 57 size_t rs_count; /* bytes till reseed */
58} *rs; 58} *rs;
59 59
60static inline void *_rs_allocate(size_t len);
61static inline void _rs_forkdetect(void);
62static inline void _rs_forkdetectsetup(struct _rs *buf, size_t len);
63#include "arc4random.h"
64
60/* Preserved in fork children. */ 65/* Preserved in fork children. */
61static struct { 66static struct {
62 chacha_ctx rs_chacha; /* chacha context for random keystream */ 67 chacha_ctx rs_chacha; /* chacha context for random keystream */
@@ -65,19 +70,6 @@ static struct {
65 70
66static inline void _rs_rekey(u_char *dat, size_t datlen); 71static inline void _rs_rekey(u_char *dat, size_t datlen);
67 72
68#ifndef MAP_INHERIT_ZERO
69static inline void
70_rs_forkhandler(void)
71{
72 /*
73 * Race-free because we're running single-threaded in a new
74 * address space, and once allocated rs is never deallocated.
75 */
76 if (rs)
77 rs->rs_count = 0;
78}
79#endif /* MAP_INHERIT_ZERO */
80
81static inline void 73static inline void
82_rs_init(u_char *buf, size_t n) 74_rs_init(u_char *buf, size_t n)
83{ 75{
@@ -85,19 +77,12 @@ _rs_init(u_char *buf, size_t n)
85 return; 77 return;
86 78
87 if (rs == NULL) { 79 if (rs == NULL) {
88 if ((rs = mmap(NULL, sizeof(*rs), PROT_READ|PROT_WRITE, 80 if ((rs = _rs_allocate(sizeof(*rs))) == NULL)
89 MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED)
90 abort();
91#ifdef MAP_INHERIT_ZERO
92 if (minherit(rs, sizeof(*rs), MAP_INHERIT_ZERO) == -1)
93 abort(); 81 abort();
94#else 82 _rs_forkdetectsetup(rs, sizeof(*rs));
95 _ARC4_ATFORK(_rs_forkhandler);
96#endif
97 } 83 }
98 if (rsx == NULL) { 84 if (rsx == NULL) {
99 if ((rsx = mmap(NULL, sizeof(*rsx), PROT_READ|PROT_WRITE, 85 if ((rsx = _rs_allocate(sizeof(*rsx))) == NULL)
100 MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED)
101 abort(); 86 abort();
102 } 87 }
103 88
@@ -129,17 +114,7 @@ _rs_stir(void)
129static inline void 114static inline void
130_rs_stir_if_needed(size_t len) 115_rs_stir_if_needed(size_t len)
131{ 116{
132#ifndef MAP_INHERIT_ZERO 117 _rs_forkdetect();
133 static pid_t _rs_pid = 0;
134 pid_t pid = getpid();
135
136 /* If a system lacks MAP_INHERIT_ZERO, resort to getpid() */
137 if (_rs_pid == 0 || _rs_pid != pid) {
138 _rs_pid = pid;
139 if (rs)
140 rs->rs_count = 0;
141 }
142#endif
143 if (!rs || rs->rs_count <= len) 118 if (!rs || rs->rs_count <= len)
144 _rs_stir(); 119 _rs_stir();
145 if (rs->rs_count <= len) 120 if (rs->rs_count <= len)
diff --git a/src/lib/libc/crypt/arc4random.h b/src/lib/libc/crypt/arc4random.h
new file mode 100644
index 0000000000..e0309a3184
--- /dev/null
+++ b/src/lib/libc/crypt/arc4random.h
@@ -0,0 +1,46 @@
1/* $OpenBSD: arc4random.h,v 1.1 2014/07/18 02:05:55 deraadt Exp $ */
2
3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
5 * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
6 * Copyright (c) 2013, Markus Friedl <markus@openbsd.org>
7 *
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
21/*
22 * Stub functions for portability.
23 */
24
25static inline void *
26_rs_allocate(size_t len)
27{
28 void *p;
29
30 if ((p = mmap(NULL, sizeof(*rs), PROT_READ|PROT_WRITE,
31 MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED)
32 return (NULL);
33 return (p);
34}
35
36static inline void
37_rs_forkdetect(void)
38{
39}
40
41static inline void
42_rs_forkdetectsetup(struct _rs *rs, size_t len)
43{
44 if (minherit(rs, len, MAP_INHERIT_ZERO) == -1)
45 abort();
46}
diff --git a/src/lib/libcrypto/arc4random/arc4random_linux.h b/src/lib/libcrypto/arc4random/arc4random_linux.h
new file mode 100644
index 0000000000..2319ccbf42
--- /dev/null
+++ b/src/lib/libcrypto/arc4random/arc4random_linux.h
@@ -0,0 +1,66 @@
1/* $OpenBSD: arc4random_linux.h,v 1.1 2014/07/18 02:05:55 deraadt Exp $ */
2
3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
5 * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
6 * Copyright (c) 2013, Markus Friedl <markus@openbsd.org>
7 *
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
21/*
22 * Stub functions for portability.
23 */
24
25static inline void *
26_rs_allocate(size_t len)
27{
28 void *p;
29
30 if ((p = mmap(NULL, sizeof(*rs), PROT_READ|PROT_WRITE,
31 MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED)
32 return (NULL);
33 return (p);
34}
35
36static inline void
37_rs_forkhandler(void)
38{
39 /*
40 * Race-free because we're running single-threaded in a new
41 * address space, and once allocated rs is never deallocated.
42 */
43 if (rs)
44 rs->rs_count = 0;
45}
46
47static inline void
48_rs_forkdetect(void)
49{
50 static pid_t _rs_pid = 0;
51 pid_t pid = getpid();
52
53 /* If a system lacks MAP_INHERIT_ZERO, resort to getpid() */
54 if (_rs_pid == 0 || _rs_pid != pid) {
55 _rs_pid = pid;
56 if (rs)
57 rs->rs_count = 0;
58 }
59}
60
61static inline void
62_rs_forkdetectsetup(struct _rs *rs, size_t len)
63{
64 _ARC4_ATFORK(_rs_forkhandler);
65}
66
diff --git a/src/lib/libcrypto/arc4random/arc4random_osx.h b/src/lib/libcrypto/arc4random/arc4random_osx.h
new file mode 100644
index 0000000000..88433e17dd
--- /dev/null
+++ b/src/lib/libcrypto/arc4random/arc4random_osx.h
@@ -0,0 +1,66 @@
1/* $OpenBSD: arc4random_osx.h,v 1.1 2014/07/18 02:05:55 deraadt Exp $ */
2
3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
5 * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
6 * Copyright (c) 2013, Markus Friedl <markus@openbsd.org>
7 *
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
21/*
22 * Stub functions for portability.
23 */
24
25static inline void *
26_rs_allocate(size_t len)
27{
28 void *p;
29
30 if ((p = mmap(NULL, sizeof(*rs), PROT_READ|PROT_WRITE,
31 MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED)
32 return (NULL);
33 return (p);
34}
35
36static inline void
37_rs_forkhandler(void)
38{
39 /*
40 * Race-free because we're running single-threaded in a new
41 * address space, and once allocated rs is never deallocated.
42 */
43 if (rs)
44 rs->rs_count = 0;
45}
46
47static inline void
48_rs_forkdetect(void)
49{
50 static pid_t _rs_pid = 0;
51 pid_t pid = getpid();
52
53 /* If a system lacks MAP_INHERIT_ZERO, resort to getpid() */
54 if (_rs_pid == 0 || _rs_pid != pid) {
55 _rs_pid = pid;
56 if (rs)
57 rs->rs_count = 0;
58 }
59}
60
61static inline void
62_rs_forkdetectsetup(struct _rs *rs, size_t len)
63{
64 _ARC4_ATFORK(_rs_forkhandler);
65}
66
diff --git a/src/lib/libcrypto/arc4random/arc4random_solaris.h b/src/lib/libcrypto/arc4random/arc4random_solaris.h
new file mode 100644
index 0000000000..ca8e107e40
--- /dev/null
+++ b/src/lib/libcrypto/arc4random/arc4random_solaris.h
@@ -0,0 +1,66 @@
1/* $OpenBSD: arc4random_solaris.h,v 1.1 2014/07/18 02:05:55 deraadt Exp $ */
2
3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
5 * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
6 * Copyright (c) 2013, Markus Friedl <markus@openbsd.org>
7 *
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
21/*
22 * Stub functions for portability.
23 */
24
25static inline void *
26_rs_allocate(size_t len)
27{
28 void *p;
29
30 if ((p = mmap(NULL, sizeof(*rs), PROT_READ|PROT_WRITE,
31 MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED)
32 return (NULL);
33 return (p);
34}
35
36static inline void
37_rs_forkhandler(void)
38{
39 /*
40 * Race-free because we're running single-threaded in a new
41 * address space, and once allocated rs is never deallocated.
42 */
43 if (rs)
44 rs->rs_count = 0;
45}
46
47static inline void
48_rs_forkdetect(void)
49{
50 static pid_t _rs_pid = 0;
51 pid_t pid = getpid();
52
53 /* If a system lacks MAP_INHERIT_ZERO, resort to getpid() */
54 if (_rs_pid == 0 || _rs_pid != pid) {
55 _rs_pid = pid;
56 if (rs)
57 rs->rs_count = 0;
58 }
59}
60
61static inline void
62_rs_forkdetectsetup(struct _rs *rs, size_t len)
63{
64 _ARC4_ATFORK(_rs_forkhandler);
65}
66
diff --git a/src/lib/libcrypto/arc4random/arc4random_win.h b/src/lib/libcrypto/arc4random/arc4random_win.h
new file mode 100644
index 0000000000..7d01d42be5
--- /dev/null
+++ b/src/lib/libcrypto/arc4random/arc4random_win.h
@@ -0,0 +1,45 @@
1/* $OpenBSD: arc4random_win.h,v 1.1 2014/07/18 02:05:55 deraadt Exp $ */
2
3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
5 * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
6 * Copyright (c) 2013, Markus Friedl <markus@openbsd.org>
7 *
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
21/*
22 * Stub functions for portability.
23 */
24
25static inline void *
26_rs_allocate(size_t len)
27{
28 return calloc(1, sizeof(*rs));
29}
30
31static inline void
32_rs_forkhandler(void)
33{
34}
35
36static inline void
37_rs_forkdetect(void)
38{
39}
40
41static inline void
42_rs_forkdetectsetup(struct _rs *rs, size_t len)
43{
44}
45
diff --git a/src/lib/libcrypto/crypto/arc4random_linux.h b/src/lib/libcrypto/crypto/arc4random_linux.h
new file mode 100644
index 0000000000..2319ccbf42
--- /dev/null
+++ b/src/lib/libcrypto/crypto/arc4random_linux.h
@@ -0,0 +1,66 @@
1/* $OpenBSD: arc4random_linux.h,v 1.1 2014/07/18 02:05:55 deraadt Exp $ */
2
3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
5 * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
6 * Copyright (c) 2013, Markus Friedl <markus@openbsd.org>
7 *
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
21/*
22 * Stub functions for portability.
23 */
24
25static inline void *
26_rs_allocate(size_t len)
27{
28 void *p;
29
30 if ((p = mmap(NULL, sizeof(*rs), PROT_READ|PROT_WRITE,
31 MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED)
32 return (NULL);
33 return (p);
34}
35
36static inline void
37_rs_forkhandler(void)
38{
39 /*
40 * Race-free because we're running single-threaded in a new
41 * address space, and once allocated rs is never deallocated.
42 */
43 if (rs)
44 rs->rs_count = 0;
45}
46
47static inline void
48_rs_forkdetect(void)
49{
50 static pid_t _rs_pid = 0;
51 pid_t pid = getpid();
52
53 /* If a system lacks MAP_INHERIT_ZERO, resort to getpid() */
54 if (_rs_pid == 0 || _rs_pid != pid) {
55 _rs_pid = pid;
56 if (rs)
57 rs->rs_count = 0;
58 }
59}
60
61static inline void
62_rs_forkdetectsetup(struct _rs *rs, size_t len)
63{
64 _ARC4_ATFORK(_rs_forkhandler);
65}
66
diff --git a/src/lib/libcrypto/crypto/arc4random_osx.h b/src/lib/libcrypto/crypto/arc4random_osx.h
new file mode 100644
index 0000000000..88433e17dd
--- /dev/null
+++ b/src/lib/libcrypto/crypto/arc4random_osx.h
@@ -0,0 +1,66 @@
1/* $OpenBSD: arc4random_osx.h,v 1.1 2014/07/18 02:05:55 deraadt Exp $ */
2
3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
5 * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
6 * Copyright (c) 2013, Markus Friedl <markus@openbsd.org>
7 *
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
21/*
22 * Stub functions for portability.
23 */
24
25static inline void *
26_rs_allocate(size_t len)
27{
28 void *p;
29
30 if ((p = mmap(NULL, sizeof(*rs), PROT_READ|PROT_WRITE,
31 MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED)
32 return (NULL);
33 return (p);
34}
35
36static inline void
37_rs_forkhandler(void)
38{
39 /*
40 * Race-free because we're running single-threaded in a new
41 * address space, and once allocated rs is never deallocated.
42 */
43 if (rs)
44 rs->rs_count = 0;
45}
46
47static inline void
48_rs_forkdetect(void)
49{
50 static pid_t _rs_pid = 0;
51 pid_t pid = getpid();
52
53 /* If a system lacks MAP_INHERIT_ZERO, resort to getpid() */
54 if (_rs_pid == 0 || _rs_pid != pid) {
55 _rs_pid = pid;
56 if (rs)
57 rs->rs_count = 0;
58 }
59}
60
61static inline void
62_rs_forkdetectsetup(struct _rs *rs, size_t len)
63{
64 _ARC4_ATFORK(_rs_forkhandler);
65}
66
diff --git a/src/lib/libcrypto/crypto/arc4random_solaris.h b/src/lib/libcrypto/crypto/arc4random_solaris.h
new file mode 100644
index 0000000000..ca8e107e40
--- /dev/null
+++ b/src/lib/libcrypto/crypto/arc4random_solaris.h
@@ -0,0 +1,66 @@
1/* $OpenBSD: arc4random_solaris.h,v 1.1 2014/07/18 02:05:55 deraadt Exp $ */
2
3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
5 * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
6 * Copyright (c) 2013, Markus Friedl <markus@openbsd.org>
7 *
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
21/*
22 * Stub functions for portability.
23 */
24
25static inline void *
26_rs_allocate(size_t len)
27{
28 void *p;
29
30 if ((p = mmap(NULL, sizeof(*rs), PROT_READ|PROT_WRITE,
31 MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED)
32 return (NULL);
33 return (p);
34}
35
36static inline void
37_rs_forkhandler(void)
38{
39 /*
40 * Race-free because we're running single-threaded in a new
41 * address space, and once allocated rs is never deallocated.
42 */
43 if (rs)
44 rs->rs_count = 0;
45}
46
47static inline void
48_rs_forkdetect(void)
49{
50 static pid_t _rs_pid = 0;
51 pid_t pid = getpid();
52
53 /* If a system lacks MAP_INHERIT_ZERO, resort to getpid() */
54 if (_rs_pid == 0 || _rs_pid != pid) {
55 _rs_pid = pid;
56 if (rs)
57 rs->rs_count = 0;
58 }
59}
60
61static inline void
62_rs_forkdetectsetup(struct _rs *rs, size_t len)
63{
64 _ARC4_ATFORK(_rs_forkhandler);
65}
66
diff --git a/src/lib/libcrypto/crypto/arc4random_win.h b/src/lib/libcrypto/crypto/arc4random_win.h
new file mode 100644
index 0000000000..7d01d42be5
--- /dev/null
+++ b/src/lib/libcrypto/crypto/arc4random_win.h
@@ -0,0 +1,45 @@
1/* $OpenBSD: arc4random_win.h,v 1.1 2014/07/18 02:05:55 deraadt Exp $ */
2
3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
5 * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
6 * Copyright (c) 2013, Markus Friedl <markus@openbsd.org>
7 *
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
21/*
22 * Stub functions for portability.
23 */
24
25static inline void *
26_rs_allocate(size_t len)
27{
28 return calloc(1, sizeof(*rs));
29}
30
31static inline void
32_rs_forkhandler(void)
33{
34}
35
36static inline void
37_rs_forkdetect(void)
38{
39}
40
41static inline void
42_rs_forkdetectsetup(struct _rs *rs, size_t len)
43{
44}
45