# ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable: 4152)
+# ifndef OPENSSL_NO_AUTOLINK
+# include "msvc_ssl_autolib.h"
+# endif
# endif
# include <openssl/applink.c>
# ifdef _MSC_VER
#if defined(OPENSSL) && defined(SYS_WINNT)
+
void ssl_applink(void);
void
ssl_applink(void)
{
-#ifdef WRAP_DBG_MALLOC
- CRYPTO_set_mem_ex_functions(wrap_dbg_malloc, wrap_dbg_realloc, wrap_dbg_free);
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+# ifdef WRAP_DBG_MALLOC
+ CRYPTO_set_mem_functions(wrap_dbg_malloc, wrap_dbg_realloc, wrap_dbg_free);
+# else
+ OPENSSL_malloc_init();
+# endif
#else
+# ifdef WRAP_DBG_MALLOC
+ CRYPTO_set_mem_ex_functions(wrap_dbg_malloc, wrap_dbg_realloc, wrap_dbg_free);
+# else
CRYPTO_malloc_init();
-#endif
+# endif
+#endif /* OpenSSL version cascade */
}
#else /* !OPENSSL || !SYS_WINNT */
#define ssl_applink() do {} while (0)
#include "config.h"
#include <string.h>
+#if defined(HAVE_INTTYPES_H) || _MSC_VER >= _MSC_VER == 1800
+# include <inttypes.h>
+#endif
+
#include <openssl/bn.h>
#include <openssl/evp.h>
--- /dev/null
+/*
+ * msvc_ssl_autolib.h -- automatic link library selection
+ *
+ * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project.
+ * The contents of 'html/copyright.html' apply.
+ * --------------------------------------------------------------------
+ *
+ * OpenSSL library names changed over time, at least once when v1.1.0
+ * emerged. For systems where the build system is inspected before
+ * the build environment is created (autconf, CMake, SCONS,...) this
+ * would be harmless, once it's known what libraries should be looked
+ * for. With MSVC / MSBUILD that's much trickier.
+ *
+ * So instead of manipulating the build environment we use the build
+ * tools themselves to create requests for linking the right library.
+ *
+ * To use this feature, it is recommended to use the precompiled
+ * VC binaries from Shining Light Productions:
+ * https://slproweb.com/products/Win32OpenSSL.html
+ * These are installed in (OPENSSL_LIB)/vc.
+ *
+ * As an alternative, create the set of build variants of OpenSSL you
+ * need, implementing the following naming scheme:
+ *
+ * basename<width><RT><DebRel>.lib
+ *
+ * so that e.g. libcrypto64MTd.lib is a 64bit binary, using a static
+ * multithreaded runtime in debug version. See the code below how this
+ * is handled.
+ * --------------------------------------------------------------------
+ */
+#pragma once
+
+#if !defined(_MSC_VER)
+# error use this header only with Micro$oft Visual C compilers!
+#elif defined(OPENSSL_NO_AUTOLINK)
+# pragma message("automatic OpenSSL library selection disabled")
+#else
+/* ---------------------------------------------------------------- */
+/* selection dance to get the right libraries linked */
+/* ---------------------------------------------------------------- */
+
+/* --*-- check if this a DEBUG or a RELEASE build --*--
+ * The '_DEBUG' macro is only set for DEBUG build variants
+ */
+# ifdef _DEBUG
+# define LTAG_DEBUG "d"
+# else
+# define LTAG_DEBUG ""
+# endif
+
+/* --*-- check platform (32 bit vs. 64 bit) --*--
+ * '_WIN64' is defined for X64 Platform only
+ */
+# ifdef _WIN64
+# define LTAG_SIZE "64"
+# else
+# define LTAG_SIZE "32"
+# endif
+
+/* --*-- check VC runtime model --*--
+ * '_DLL' is set if a runtime-in-a-dll code generation model is chosen.
+ * Note that we do not check for the single-threaded static runtime.
+ * This would make no sense, since the Windows Build *uses* threads and
+ * therefore needs a multithread runtime anyway. And Micro$oft decided
+ * somewhere after VS2008 to drop that model anyway, so it's no longer
+ * available on newer platforms.
+ */
+# ifdef _DLL
+# #define LTAG_RTLIB "MD"
+# else
+# define LTAG_RTLIB "MT"
+# endif
+
+/* --*-- place linker request in object file --*--
+ * Here we come to the reason for all that trouble: the library names
+ * to link depend on the OpenSSL version...
+ *
+ * Before v1.1.0, the 'old' (ancient?) name 'libeay32' was used,
+ * no matter what platform. (The corresponding 'ssleay32.lib' was/is
+ * not used by NTP.) Since v1.1.0, the name stems are libcrypto
+ * and libssl, and they contain the platform size (32 or 64).
+ *
+ * So we use '#pragma comment(lib,...)' to place a proper linker
+ * request in the object file, depending on the SSL version and the
+ * build variant.
+ */
+# if OPENSSL_VERSION_NUMBER >= 0x10100000L
+# pragma comment(lib, "libcrypto" LTAG_SIZE LTAG_RTLIB LTAG_DEBUG ".lib")
+# else
+# pragma comment(lib, "libeay32" LTAG_RTLIB LTAG_DEBUG ".lib")
+# endif
+
+#endif /*!defined(OPENSSL_NO_AUTOLINK)*/
/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies=" $(OPENSSL64_LIB)\libeay32.lib"
+ AdditionalLibraryDirectories=" $(OPENSSL64_LIB)\vc"
TargetMachine="17"
-/>
+ />
</VisualStudioPropertySheet>
/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies=" $(OPENSSL_LIB)\libeay32.lib"
+ AdditionalLibraryDirectories=" $(OPENSSL_LIB)\vc"
TargetMachine="1"
/>
</VisualStudioPropertySheet>
/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies=" $(OPENSSL64_LIB)\libeay32.lib"
+ AdditionalLibraryDirectories=" $(OPENSSL64_LIB)\vc"
TargetMachine="17"
/>
</VisualStudioPropertySheet>
/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies=" $(OPENSSL_LIB)\libeay32.lib"
+ AdditionalLibraryDirectories=" $(OPENSSL_LIB)\vc"
TargetMachine="1"
/>
</VisualStudioPropertySheet>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
- <AdditionalDependencies>$(OPENSSL64_LIB)\libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<TargetMachine>MachineX64</TargetMachine>
+ <AdditionalLibraryDirectories>$(OPENSSL64_LIB)\vc</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
- <AdditionalDependencies>$(OPENSSL_LIB)\libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<TargetMachine>MachineX86</TargetMachine>
+ <AdditionalLibraryDirectories>$(OPENSSL_LIB)\vc</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
<ClInclude Include="..\..\include\clockstuff.h" />
<ClInclude Include="..\..\include\config.h" />
<ClInclude Include="..\..\include\gaa_compat.h" />
+ <ClInclude Include="..\..\include\msvc_ssl_autolib.h" />
<ClInclude Include="..\..\include\netdb.h" />
<ClInclude Include="..\..\include\ntp_iocompletionport.h" />
<ClInclude Include="..\..\include\ntp_timer.h" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project>
+</Project>
\ No newline at end of file
<ClInclude Include="..\..\..\..\include\libssl_compat.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="..\..\include\msvc_ssl_autolib.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="..\..\libntp\messages.mc">
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
- <AdditionalDependencies>$(OPENSSL64_LIB)\libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<TargetMachine>MachineX64</TargetMachine>
+ <AdditionalLibraryDirectories>$(OPENSSL64_LIB)\vc</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
- <AdditionalDependencies>$(OPENSSL_LIB)\libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<TargetMachine>MachineX86</TargetMachine>
+ <AdditionalLibraryDirectories>$(OPENSSL_LIB)\vc</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
- <AdditionalDependencies>$(OPENSSL64_LIB)\libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<TargetMachine>MachineX64</TargetMachine>
+ <AdditionalLibraryDirectories>$(OPENSSL64_LIB)\vc</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
- <AdditionalDependencies>$(OPENSSL_LIB)\libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<TargetMachine>MachineX86</TargetMachine>
+ <AdditionalLibraryDirectories>$(OPENSSL_LIB)\vc</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
<ClInclude Include="..\..\include\clockstuff.h" />
<ClInclude Include="..\..\include\config.h" />
<ClInclude Include="..\..\include\gaa_compat.h" />
+ <ClInclude Include="..\..\include\msvc_ssl_autolib.h" />
<ClInclude Include="..\..\include\netdb.h" />
<ClInclude Include="..\..\include\ntp_iocompletionport.h" />
<ClInclude Include="..\..\include\ntp_timer.h" />
<ClInclude Include="..\..\..\..\include\libssl_compat.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="..\..\include\msvc_ssl_autolib.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="..\..\libntp\messages.mc">
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
- <AdditionalDependencies>$(OPENSSL64_LIB)\libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<TargetMachine>MachineX64</TargetMachine>
+ <AdditionalLibraryDirectories>$(OPENSSL64_LIB)\vc</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
- <AdditionalDependencies>$(OPENSSL_LIB)\libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<TargetMachine>MachineX86</TargetMachine>
+ <AdditionalLibraryDirectories>$(OPENSSL_LIB)\vc</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup />