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@
-/* $OpenBSD: arc4random.c,v 1.48 2014/07/19 00:08:41 deraadt Exp $ */
+/* $OpenBSD: arc4random.c,v 1.49 2014/07/20 20:51:13 bcook Exp $ */
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/time.h>
-#include <sys/mman.h>
-
-#include "thread_private.h"
#define KEYSTREAM_ONLY
#include "chacha_private.h"
u_char rnd[KEYSZ + IVSZ];
if (getentropy(rnd, sizeof rnd) == -1)
- raise(SIGKILL);
+ _getentropy_fail();
if (!rs)
_rs_init(rnd, sizeof(rnd));
-/* $OpenBSD: arc4random.h,v 1.2 2014/07/19 00:08:41 deraadt Exp $ */
+/* $OpenBSD: arc4random.h,v 1.3 2014/07/20 20:51:13 bcook Exp $ */
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
/*
* Stub functions for portability.
*/
+#include <sys/mman.h>
+
+#include <signal.h>
+
+#include "thread_private.h"
+
+static inline void
+_getentropy_fail(void)
+{
+ raise(SIGKILL);
+}
static inline int
_rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
-/* $OpenBSD: arc4random_linux.h,v 1.6 2014/07/19 15:29:25 bcook Exp $ */
+/* $OpenBSD: arc4random_linux.h,v 1.7 2014/07/20 20:51:13 bcook Exp $ */
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
* Stub functions for portability.
*/
+#include <sys/mman.h>
+
#include <pthread.h>
+#include <signal.h>
static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
#endif
+static inline void
+_getentropy_fail(void)
+{
+ raise(SIGKILL);
+}
+
static volatile sig_atomic_t _rs_forked;
static inline void
-/* $OpenBSD: arc4random_osx.h,v 1.6 2014/07/19 15:29:25 bcook Exp $ */
+/* $OpenBSD: arc4random_osx.h,v 1.7 2014/07/20 20:51:13 bcook Exp $ */
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
* Stub functions for portability.
*/
+#include <sys/mman.h>
+
#include <pthread.h>
+#include <signal.h>
static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
+static inline void
+_getentropy_fail(void)
+{
+ raise(SIGKILL);
+}
+
static volatile sig_atomic_t _rs_forked;
static inline void
-/* $OpenBSD: arc4random_solaris.h,v 1.6 2014/07/19 15:29:25 bcook Exp $ */
+/* $OpenBSD: arc4random_solaris.h,v 1.7 2014/07/20 20:51:13 bcook Exp $ */
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
* Stub functions for portability.
*/
+#include <sys/mman.h>
+
#include <pthread.h>
+#include <signal.h>
static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
+static inline void
+_getentropy_fail(void)
+{
+ raise(SIGKILL);
+}
+
static volatile sig_atomic_t _rs_forked;
static inline void
-/* $OpenBSD: arc4random_win.h,v 1.3 2014/07/20 16:59:31 bcook Exp $ */
+/* $OpenBSD: arc4random_win.h,v 1.4 2014/07/20 20:51:13 bcook Exp $ */
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
#define _ARC4_UNLOCK() ReleaseMutex(arc4random_mtx)
+static inline void
+_getentropy_fail(void)
+{
+ TerminateProcess(GetCurrentProcess(), 0);
+}
+
static inline int
_rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
{
-/* $OpenBSD: arc4random_linux.h,v 1.6 2014/07/19 15:29:25 bcook Exp $ */
+/* $OpenBSD: arc4random_linux.h,v 1.7 2014/07/20 20:51:13 bcook Exp $ */
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
* Stub functions for portability.
*/
+#include <sys/mman.h>
+
#include <pthread.h>
+#include <signal.h>
static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
#endif
+static inline void
+_getentropy_fail(void)
+{
+ raise(SIGKILL);
+}
+
static volatile sig_atomic_t _rs_forked;
static inline void
-/* $OpenBSD: arc4random_osx.h,v 1.6 2014/07/19 15:29:25 bcook Exp $ */
+/* $OpenBSD: arc4random_osx.h,v 1.7 2014/07/20 20:51:13 bcook Exp $ */
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
* Stub functions for portability.
*/
+#include <sys/mman.h>
+
#include <pthread.h>
+#include <signal.h>
static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
+static inline void
+_getentropy_fail(void)
+{
+ raise(SIGKILL);
+}
+
static volatile sig_atomic_t _rs_forked;
static inline void
-/* $OpenBSD: arc4random_solaris.h,v 1.6 2014/07/19 15:29:25 bcook Exp $ */
+/* $OpenBSD: arc4random_solaris.h,v 1.7 2014/07/20 20:51:13 bcook Exp $ */
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
* Stub functions for portability.
*/
+#include <sys/mman.h>
+
#include <pthread.h>
+#include <signal.h>
static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
+static inline void
+_getentropy_fail(void)
+{
+ raise(SIGKILL);
+}
+
static volatile sig_atomic_t _rs_forked;
static inline void
-/* $OpenBSD: arc4random_win.h,v 1.3 2014/07/20 16:59:31 bcook Exp $ */
+/* $OpenBSD: arc4random_win.h,v 1.4 2014/07/20 20:51:13 bcook Exp $ */
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
#define _ARC4_UNLOCK() ReleaseMutex(arc4random_mtx)
+static inline void
+_getentropy_fail(void)
+{
+ TerminateProcess(GetCurrentProcess(), 0);
+}
+
static inline int
_rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
{