summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbcook <>2014-07-20 20:51:13 +0000
committerbcook <>2014-07-20 20:51:13 +0000
commitf34324d947b29b5a35a325bbd3901294355b4f39 (patch)
tree3cffc18607d7ee2f36193cbc2c6420f39f8d8d9f
parent6f021fc4705d719c57993c7f3e916ed71f4480eb (diff)
downloadopenbsd-f34324d947b29b5a35a325bbd3901294355b4f39.tar.gz
openbsd-f34324d947b29b5a35a325bbd3901294355b4f39.tar.bz2
openbsd-f34324d947b29b5a35a325bbd3901294355b4f39.zip
Move more OS-specific functionality to arc4random.h headers.
Move <sys/mman.h> and raise(SIGKILL) calls to OS-specific headers. On OpenBSD, move thread_private.h as well to arc4random.h. On Windows, use TerminateProcess on getentropy failure. ok deraadt@
-rw-r--r--src/lib/libc/crypt/arc4random.c7
-rw-r--r--src/lib/libc/crypt/arc4random.h13
-rw-r--r--src/lib/libcrypto/arc4random/arc4random_linux.h11
-rw-r--r--src/lib/libcrypto/arc4random/arc4random_osx.h11
-rw-r--r--src/lib/libcrypto/arc4random/arc4random_solaris.h11
-rw-r--r--src/lib/libcrypto/arc4random/arc4random_win.h8
-rw-r--r--src/lib/libcrypto/crypto/arc4random_linux.h11
-rw-r--r--src/lib/libcrypto/crypto/arc4random_osx.h11
-rw-r--r--src/lib/libcrypto/crypto/arc4random_solaris.h11
-rw-r--r--src/lib/libcrypto/crypto/arc4random_win.h8
10 files changed, 88 insertions, 14 deletions
diff --git a/src/lib/libc/crypt/arc4random.c b/src/lib/libc/crypt/arc4random.c
index 3c80beb3b9..e4b6369bf1 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.48 2014/07/19 00:08:41 deraadt Exp $ */ 1/* $OpenBSD: arc4random.c,v 1.49 2014/07/20 20:51:13 bcook Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org> 4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -32,9 +32,6 @@
32#include <sys/types.h> 32#include <sys/types.h>
33#include <sys/param.h> 33#include <sys/param.h>
34#include <sys/time.h> 34#include <sys/time.h>
35#include <sys/mman.h>
36
37#include "thread_private.h"
38 35
39#define KEYSTREAM_ONLY 36#define KEYSTREAM_ONLY
40#include "chacha_private.h" 37#include "chacha_private.h"
@@ -90,7 +87,7 @@ _rs_stir(void)
90 u_char rnd[KEYSZ + IVSZ]; 87 u_char rnd[KEYSZ + IVSZ];
91 88
92 if (getentropy(rnd, sizeof rnd) == -1) 89 if (getentropy(rnd, sizeof rnd) == -1)
93 raise(SIGKILL); 90 _getentropy_fail();
94 91
95 if (!rs) 92 if (!rs)
96 _rs_init(rnd, sizeof(rnd)); 93 _rs_init(rnd, sizeof(rnd));
diff --git a/src/lib/libc/crypt/arc4random.h b/src/lib/libc/crypt/arc4random.h
index d867687226..d29873cca4 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.2 2014/07/19 00:08:41 deraadt Exp $ */ 1/* $OpenBSD: arc4random.h,v 1.3 2014/07/20 20:51:13 bcook Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org> 4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -21,6 +21,17 @@
21/* 21/*
22 * Stub functions for portability. 22 * Stub functions for portability.
23 */ 23 */
24#include <sys/mman.h>
25
26#include <signal.h>
27
28#include "thread_private.h"
29
30static inline void
31_getentropy_fail(void)
32{
33 raise(SIGKILL);
34}
24 35
25static inline int 36static inline int
26_rs_allocate(struct _rs **rsp, struct _rsx **rsxp) 37_rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
diff --git a/src/lib/libcrypto/arc4random/arc4random_linux.h b/src/lib/libcrypto/arc4random/arc4random_linux.h
index 0da5a4a433..7acba3f78e 100644
--- a/src/lib/libcrypto/arc4random/arc4random_linux.h
+++ b/src/lib/libcrypto/arc4random/arc4random_linux.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: arc4random_linux.h,v 1.6 2014/07/19 15:29:25 bcook Exp $ */ 1/* $OpenBSD: arc4random_linux.h,v 1.7 2014/07/20 20:51:13 bcook Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org> 4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -22,7 +22,10 @@
22 * Stub functions for portability. 22 * Stub functions for portability.
23 */ 23 */
24 24
25#include <sys/mman.h>
26
25#include <pthread.h> 27#include <pthread.h>
28#include <signal.h>
26 29
27static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER; 30static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
28#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx) 31#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
@@ -36,6 +39,12 @@ extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void
36#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f)) 39#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
37#endif 40#endif
38 41
42static inline void
43_getentropy_fail(void)
44{
45 raise(SIGKILL);
46}
47
39static volatile sig_atomic_t _rs_forked; 48static volatile sig_atomic_t _rs_forked;
40 49
41static inline void 50static inline void
diff --git a/src/lib/libcrypto/arc4random/arc4random_osx.h b/src/lib/libcrypto/arc4random/arc4random_osx.h
index aacbef9aae..c14e044fe2 100644
--- a/src/lib/libcrypto/arc4random/arc4random_osx.h
+++ b/src/lib/libcrypto/arc4random/arc4random_osx.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: arc4random_osx.h,v 1.6 2014/07/19 15:29:25 bcook Exp $ */ 1/* $OpenBSD: arc4random_osx.h,v 1.7 2014/07/20 20:51:13 bcook Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org> 4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -22,7 +22,10 @@
22 * Stub functions for portability. 22 * Stub functions for portability.
23 */ 23 */
24 24
25#include <sys/mman.h>
26
25#include <pthread.h> 27#include <pthread.h>
28#include <signal.h>
26 29
27static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER; 30static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
28#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx) 31#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
@@ -30,6 +33,12 @@ static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
30 33
31#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f)) 34#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
32 35
36static inline void
37_getentropy_fail(void)
38{
39 raise(SIGKILL);
40}
41
33static volatile sig_atomic_t _rs_forked; 42static volatile sig_atomic_t _rs_forked;
34 43
35static inline void 44static inline void
diff --git a/src/lib/libcrypto/arc4random/arc4random_solaris.h b/src/lib/libcrypto/arc4random/arc4random_solaris.h
index 18b1bd54e0..2082a4728f 100644
--- a/src/lib/libcrypto/arc4random/arc4random_solaris.h
+++ b/src/lib/libcrypto/arc4random/arc4random_solaris.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: arc4random_solaris.h,v 1.6 2014/07/19 15:29:25 bcook Exp $ */ 1/* $OpenBSD: arc4random_solaris.h,v 1.7 2014/07/20 20:51:13 bcook Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org> 4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -22,7 +22,10 @@
22 * Stub functions for portability. 22 * Stub functions for portability.
23 */ 23 */
24 24
25#include <sys/mman.h>
26
25#include <pthread.h> 27#include <pthread.h>
28#include <signal.h>
26 29
27static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER; 30static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
28#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx) 31#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
@@ -30,6 +33,12 @@ static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
30 33
31#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f)) 34#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
32 35
36static inline void
37_getentropy_fail(void)
38{
39 raise(SIGKILL);
40}
41
33static volatile sig_atomic_t _rs_forked; 42static volatile sig_atomic_t _rs_forked;
34 43
35static inline void 44static inline void
diff --git a/src/lib/libcrypto/arc4random/arc4random_win.h b/src/lib/libcrypto/arc4random/arc4random_win.h
index 1e044de109..b7a5a36013 100644
--- a/src/lib/libcrypto/arc4random/arc4random_win.h
+++ b/src/lib/libcrypto/arc4random/arc4random_win.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: arc4random_win.h,v 1.3 2014/07/20 16:59:31 bcook Exp $ */ 1/* $OpenBSD: arc4random_win.h,v 1.4 2014/07/20 20:51:13 bcook Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org> 4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -42,6 +42,12 @@ static volatile HANDLE arc4random_mtx = NULL;
42 42
43#define _ARC4_UNLOCK() ReleaseMutex(arc4random_mtx) 43#define _ARC4_UNLOCK() ReleaseMutex(arc4random_mtx)
44 44
45static inline void
46_getentropy_fail(void)
47{
48 TerminateProcess(GetCurrentProcess(), 0);
49}
50
45static inline int 51static inline int
46_rs_allocate(struct _rs **rsp, struct _rsx **rsxp) 52_rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
47{ 53{
diff --git a/src/lib/libcrypto/crypto/arc4random_linux.h b/src/lib/libcrypto/crypto/arc4random_linux.h
index 0da5a4a433..7acba3f78e 100644
--- a/src/lib/libcrypto/crypto/arc4random_linux.h
+++ b/src/lib/libcrypto/crypto/arc4random_linux.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: arc4random_linux.h,v 1.6 2014/07/19 15:29:25 bcook Exp $ */ 1/* $OpenBSD: arc4random_linux.h,v 1.7 2014/07/20 20:51:13 bcook Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org> 4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -22,7 +22,10 @@
22 * Stub functions for portability. 22 * Stub functions for portability.
23 */ 23 */
24 24
25#include <sys/mman.h>
26
25#include <pthread.h> 27#include <pthread.h>
28#include <signal.h>
26 29
27static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER; 30static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
28#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx) 31#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
@@ -36,6 +39,12 @@ extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void
36#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f)) 39#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
37#endif 40#endif
38 41
42static inline void
43_getentropy_fail(void)
44{
45 raise(SIGKILL);
46}
47
39static volatile sig_atomic_t _rs_forked; 48static volatile sig_atomic_t _rs_forked;
40 49
41static inline void 50static inline void
diff --git a/src/lib/libcrypto/crypto/arc4random_osx.h b/src/lib/libcrypto/crypto/arc4random_osx.h
index aacbef9aae..c14e044fe2 100644
--- a/src/lib/libcrypto/crypto/arc4random_osx.h
+++ b/src/lib/libcrypto/crypto/arc4random_osx.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: arc4random_osx.h,v 1.6 2014/07/19 15:29:25 bcook Exp $ */ 1/* $OpenBSD: arc4random_osx.h,v 1.7 2014/07/20 20:51:13 bcook Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org> 4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -22,7 +22,10 @@
22 * Stub functions for portability. 22 * Stub functions for portability.
23 */ 23 */
24 24
25#include <sys/mman.h>
26
25#include <pthread.h> 27#include <pthread.h>
28#include <signal.h>
26 29
27static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER; 30static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
28#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx) 31#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
@@ -30,6 +33,12 @@ static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
30 33
31#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f)) 34#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
32 35
36static inline void
37_getentropy_fail(void)
38{
39 raise(SIGKILL);
40}
41
33static volatile sig_atomic_t _rs_forked; 42static volatile sig_atomic_t _rs_forked;
34 43
35static inline void 44static inline void
diff --git a/src/lib/libcrypto/crypto/arc4random_solaris.h b/src/lib/libcrypto/crypto/arc4random_solaris.h
index 18b1bd54e0..2082a4728f 100644
--- a/src/lib/libcrypto/crypto/arc4random_solaris.h
+++ b/src/lib/libcrypto/crypto/arc4random_solaris.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: arc4random_solaris.h,v 1.6 2014/07/19 15:29:25 bcook Exp $ */ 1/* $OpenBSD: arc4random_solaris.h,v 1.7 2014/07/20 20:51:13 bcook Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org> 4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -22,7 +22,10 @@
22 * Stub functions for portability. 22 * Stub functions for portability.
23 */ 23 */
24 24
25#include <sys/mman.h>
26
25#include <pthread.h> 27#include <pthread.h>
28#include <signal.h>
26 29
27static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER; 30static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
28#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx) 31#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
@@ -30,6 +33,12 @@ static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
30 33
31#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f)) 34#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
32 35
36static inline void
37_getentropy_fail(void)
38{
39 raise(SIGKILL);
40}
41
33static volatile sig_atomic_t _rs_forked; 42static volatile sig_atomic_t _rs_forked;
34 43
35static inline void 44static inline void
diff --git a/src/lib/libcrypto/crypto/arc4random_win.h b/src/lib/libcrypto/crypto/arc4random_win.h
index 1e044de109..b7a5a36013 100644
--- a/src/lib/libcrypto/crypto/arc4random_win.h
+++ b/src/lib/libcrypto/crypto/arc4random_win.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: arc4random_win.h,v 1.3 2014/07/20 16:59:31 bcook Exp $ */ 1/* $OpenBSD: arc4random_win.h,v 1.4 2014/07/20 20:51:13 bcook Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org> 4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -42,6 +42,12 @@ static volatile HANDLE arc4random_mtx = NULL;
42 42
43#define _ARC4_UNLOCK() ReleaseMutex(arc4random_mtx) 43#define _ARC4_UNLOCK() ReleaseMutex(arc4random_mtx)
44 44
45static inline void
46_getentropy_fail(void)
47{
48 TerminateProcess(GetCurrentProcess(), 0);
49}
50
45static inline int 51static inline int
46_rs_allocate(struct _rs **rsp, struct _rsx **rsxp) 52_rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
47{ 53{