From: Juergen Perlinger Date: Mon, 30 Mar 2015 17:10:12 +0000 (+0200) Subject: [Bug 2795] Cannot build without OpenSLL (on Win32) X-Git-Tag: NTP_4_3_12~3^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=879b4d78b3b7ef8dc4e38fda0547e02e8f4f6f96;p=thirdparty%2Fntp.git [Bug 2795] Cannot build without OpenSLL (on Win32) Provided a Win32 specific wrapper around libevent/arc4random.c bk: 55198374TKQLErgwNgWWuo_iwGFoHw --- diff --git a/ChangeLog b/ChangeLog index ae0be3052..7ae7a5b72 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ --- +* [Bug 2795] Cannot build without OpenSLL (on Win32) + Provided a Win32 specific wrapper around libevent/arc4random.c +--- (4.2.8p2-RC1) 2015/03/30 Released by Harlan Stenn * [Bug 1787] DCF77's formerly "antenna" bit is "call bit" since 2003. diff --git a/ports/winnt/libntp/arc4wrap.c b/ports/winnt/libntp/arc4wrap.c new file mode 100644 index 000000000..9513d154a --- /dev/null +++ b/ports/winnt/libntp/arc4wrap.c @@ -0,0 +1,84 @@ +/* + * arc4wrap.c - wrapper for libevent's ARCFOUR random number generator + * + * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project. + * The contents of 'html/copyright.html' apply. + * -------------------------------------------------------------------- + * This is an inclusion wrapper for the ARCFOUR implementation in + * libevent. It's main usage is to enable a openSSL-free build on Win32 + * without a full integration of libevent. This provides Win32 specific + * glue to make the PRNG working. Porting to POSIX should be easy, but + * on most POSIX systems using openSSL is no problem and falling back to + * using ARCFOUR instead of the openSSL PRNG is not necessary. And even + * if it is, there's a good chance that ARCFOUR is a system library. + */ +#include +#ifdef _WIN32 +# include +# include +#else +# error this is currently a pure windows port +#endif + +#include +#include +#include +#include "ntp_types.h" +#include "ntp_stdlib.h" + +/* ARCFOUR implementation glue */ +/* export type is empty, since this goes into a static library*/ +#define ARC4RANDOM_EXPORT +/* we use default uint32_t as UINT32 */ +#define ARC4RANDOM_UINT32 uint32_t +/* do not use ARCFOUR's default includes - we gobble it all up here. */ +#define ARC4RANDOM_NO_INCLUDES +/* And the locking. Could probably be left empty. */ +#define ARC4_LOCK_() private_lock_() +#define ARC4_UNLOCK_() private_unlock_() + +/* support code */ + +static void +evutil_memclear_( + void *buf, + size_t len) +{ + memset(buf, 0, len); +} + +/* locking uses a manual thread-safe ONCE pattern. There's no static + * initialiser pattern that can be used for critical sections, and + * we must make sure we do the creation exactly once on the first call. + */ + +static long once_ = 0; +static CRITICAL_SECTION csec_; + +static void +private_lock_(void) +{ +again: + switch (InterlockedCompareExchange(&once_, 1, 0)) { + case 0: + InitializeCriticalSection(&csec_); + InterlockedExchange(&once_, 2); + case 2: + EnterCriticalSection(&csec_); + break; + + default: + YieldProcessor(); + goto again; + } +} + +static void +private_unlock_(void) +{ + if (InterlockedExchangeAdd(&once_, 0) == 2) + LeaveCriticalSection(&csec_); +} + +#pragma warning(disable : 4244) +#include "../../../sntp/libevent/arc4random.c" diff --git a/ports/winnt/vs2005/libntp.vcproj b/ports/winnt/vs2005/libntp.vcproj index f2d0b9e71..fdc33744a 100644 --- a/ports/winnt/vs2005/libntp.vcproj +++ b/ports/winnt/vs2005/libntp.vcproj @@ -180,6 +180,10 @@ RelativePath="..\..\..\libntp\adjtime.c" > + + diff --git a/ports/winnt/vs2008/libntp/libntp.vcproj b/ports/winnt/vs2008/libntp/libntp.vcproj index 354a8ac64..b87d1782d 100644 --- a/ports/winnt/vs2008/libntp/libntp.vcproj +++ b/ports/winnt/vs2008/libntp/libntp.vcproj @@ -192,6 +192,10 @@ RelativePath="..\..\..\..\libntp\adjtime.c" > + + @@ -874,7 +878,7 @@ > + diff --git a/ports/winnt/vs2013/libntp/libntp.vcxproj.filters b/ports/winnt/vs2013/libntp/libntp.vcxproj.filters index 4eefad711..10596c686 100644 --- a/ports/winnt/vs2013/libntp/libntp.vcxproj.filters +++ b/ports/winnt/vs2013/libntp/libntp.vcxproj.filters @@ -317,6 +317,12 @@ Source Files + + Source Files + + + Source Files +