]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 2795] Cannot build without OpenSLL (on Win32)
authorJuergen Perlinger <perlinger@ntp.org>
Mon, 30 Mar 2015 17:10:12 +0000 (19:10 +0200)
committerJuergen Perlinger <perlinger@ntp.org>
Mon, 30 Mar 2015 17:10:12 +0000 (19:10 +0200)
 Provided a Win32 specific wrapper around libevent/arc4random.c

bk: 55198374TKQLErgwNgWWuo_iwGFoHw

ChangeLog
ports/winnt/libntp/arc4wrap.c [new file with mode: 0644]
ports/winnt/vs2005/libntp.vcproj
ports/winnt/vs2008/libntp/libntp.vcproj
ports/winnt/vs2013/libntp/libntp.vcxproj
ports/winnt/vs2013/libntp/libntp.vcxproj.filters

index ae0be3052f03382d1e8e4f9c51879c09009e8820..7ae7a5b725caeff402610fdb5651ede5d95a6711 100644 (file)
--- 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 <stenn@ntp.org>
 
 * [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 (file)
index 0000000..9513d15
--- /dev/null
@@ -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 <config.h>
+#ifdef _WIN32
+# include <wincrypt.h>
+# include <process.h>
+#else
+# error this is currently a pure windows port
+#endif
+
+#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
+#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"
index f2d0b9e714dfcd29489a99ac7222823d682a4646..fdc33744a18da2b7abdcc7b4459efc517b4deeb6 100644 (file)
                                RelativePath="..\..\..\libntp\adjtime.c"
                                >
                        </File>
+                       <File
+                               RelativePath="..\libntp\arc4wrap.c"
+                               >
+                       </File>
                        <File
                                RelativePath="..\..\..\lib\isc\assertions.c"
                                >
index 354a8ac64db2f07c29d966ef6aa4e8a81bbe2277..b87d1782d2060c8286f52b9a2e8d099822f7fb7a 100644 (file)
                                RelativePath="..\..\..\..\libntp\adjtime.c"
                                >
                        </File>
+                       <File
+                               RelativePath="..\..\libntp\arc4wrap.c"
+                               >
+                       </File>
                        <File
                                RelativePath="..\..\..\..\lib\isc\assertions.c"
                                >
                                >
                        </File>
                        <File
-                               RelativePath="..\..\include\sys\time.h"
+                               RelativePath="..\..\..\..\lib\isc\win32\include\isc\time.h"
                                >
                        </File>
                        <File
                                >
                        </File>
                        <File
-                               RelativePath="..\..\..\..\lib\isc\win32\include\isc\time.h"
+                               RelativePath="..\..\include\sys\time.h"
                                >
                        </File>
                        <File
index 2e20c71b4ce9eeaf8b74aba82d9ef21c8c7f0cdd..1289c2d77dcf6197199dcaa5d49f40d347d9de96 100644 (file)
     <ClCompile Include="..\..\..\..\lib\isc\error.c" />
     <ClCompile Include="..\..\..\..\lib\isc\event.c" />
     <ClCompile Include="..\..\..\..\libntp\findconfig.c" />
+    <ClCompile Include="..\..\libntp\arc4wrap.c" />
     <ClCompile Include="..\..\libntp\getclock.c" />
     <ClCompile Include="..\..\..\..\libntp\getopt.c" />
     <ClCompile Include="..\..\..\..\libntp\hextoint.c" />
index 4eefad71149d107aab78821c389109c94c3e6980..10596c6863af612b17855448e21b2655fcfe7544 100644 (file)
     <ClCompile Include="..\..\..\..\libntp\vint64ops.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\..\..\libntp\ntp_crypto_rnd.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\libntp\arc4wrap.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\..\..\sntp\libopts\ag-char-map.h">