diff options
author | deraadt <> | 2014-07-18 02:05:55 +0000 |
---|---|---|
committer | deraadt <> | 2014-07-18 02:05:55 +0000 |
commit | acdbce862be55ac5aef43be691bd06f8b9fab41b (patch) | |
tree | ab83a774dd030d8ad707e272102749a0d84230c0 /src/lib/libcrypto/crypto/arc4random_linux.h | |
parent | eb33ac700a48895a01fed57fc9e3c0ef20f9824e (diff) | |
download | openbsd-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
Diffstat (limited to 'src/lib/libcrypto/crypto/arc4random_linux.h')
-rw-r--r-- | src/lib/libcrypto/crypto/arc4random_linux.h | 66 |
1 files changed, 66 insertions, 0 deletions
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 | |||
25 | static 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 | |||
36 | static 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 | |||
47 | static 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 | |||
61 | static inline void | ||
62 | _rs_forkdetectsetup(struct _rs *rs, size_t len) | ||
63 | { | ||
64 | _ARC4_ATFORK(_rs_forkhandler); | ||
65 | } | ||
66 | |||