diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/arc4random/arc4random_win.h | 22 | ||||
| -rw-r--r-- | src/lib/libcrypto/crypto/arc4random_win.h | 22 |
2 files changed, 42 insertions, 2 deletions
diff --git a/src/lib/libcrypto/arc4random/arc4random_win.h b/src/lib/libcrypto/arc4random/arc4random_win.h index 1fc228d109..1e044de109 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.2 2014/07/19 00:08:43 deraadt Exp $ */ | 1 | /* $OpenBSD: arc4random_win.h,v 1.3 2014/07/20 16:59:31 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,6 +22,26 @@ | |||
| 22 | * Stub functions for portability. | 22 | * Stub functions for portability. |
| 23 | */ | 23 | */ |
| 24 | 24 | ||
| 25 | #include <windows.h> | ||
| 26 | |||
| 27 | static volatile HANDLE arc4random_mtx = NULL; | ||
| 28 | |||
| 29 | /* | ||
| 30 | * Initialize the mutex on the first lock attempt. On collision, each thread | ||
| 31 | * will attempt to allocate a mutex and compare-and-swap it into place as the | ||
| 32 | * global mutex. On failure to swap in the global mutex, the mutex is closed. | ||
| 33 | */ | ||
| 34 | #define _ARC4_LOCK() { \ | ||
| 35 | if (!arc4random_mtx) { \ | ||
| 36 | HANDLE p = CreateMutex(NULL, FALSE, NULL); \ | ||
| 37 | if (InterlockedCompareExchangePointer((void **)&arc4random_mtx, (void *)p, NULL)) \ | ||
| 38 | CloseHandle(p); \ | ||
| 39 | } \ | ||
| 40 | WaitForSingleObject(arc4random_mtx, INFINITE); \ | ||
| 41 | } \ | ||
| 42 | |||
| 43 | #define _ARC4_UNLOCK() ReleaseMutex(arc4random_mtx) | ||
| 44 | |||
| 25 | static inline int | 45 | static inline int |
| 26 | _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) | 46 | _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) |
| 27 | { | 47 | { |
diff --git a/src/lib/libcrypto/crypto/arc4random_win.h b/src/lib/libcrypto/crypto/arc4random_win.h index 1fc228d109..1e044de109 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.2 2014/07/19 00:08:43 deraadt Exp $ */ | 1 | /* $OpenBSD: arc4random_win.h,v 1.3 2014/07/20 16:59:31 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,6 +22,26 @@ | |||
| 22 | * Stub functions for portability. | 22 | * Stub functions for portability. |
| 23 | */ | 23 | */ |
| 24 | 24 | ||
| 25 | #include <windows.h> | ||
| 26 | |||
| 27 | static volatile HANDLE arc4random_mtx = NULL; | ||
| 28 | |||
| 29 | /* | ||
| 30 | * Initialize the mutex on the first lock attempt. On collision, each thread | ||
| 31 | * will attempt to allocate a mutex and compare-and-swap it into place as the | ||
| 32 | * global mutex. On failure to swap in the global mutex, the mutex is closed. | ||
| 33 | */ | ||
| 34 | #define _ARC4_LOCK() { \ | ||
| 35 | if (!arc4random_mtx) { \ | ||
| 36 | HANDLE p = CreateMutex(NULL, FALSE, NULL); \ | ||
| 37 | if (InterlockedCompareExchangePointer((void **)&arc4random_mtx, (void *)p, NULL)) \ | ||
| 38 | CloseHandle(p); \ | ||
| 39 | } \ | ||
| 40 | WaitForSingleObject(arc4random_mtx, INFINITE); \ | ||
| 41 | } \ | ||
| 42 | |||
| 43 | #define _ARC4_UNLOCK() ReleaseMutex(arc4random_mtx) | ||
| 44 | |||
| 25 | static inline int | 45 | static inline int |
| 26 | _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) | 46 | _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) |
| 27 | { | 47 | { |
