]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add thin openssl shim for OpenSSL 1.1.x and LibreSSL compatibility functions
authorOndřej Surý <ondrej@sury.org>
Wed, 13 Jun 2018 11:42:25 +0000 (13:42 +0200)
committerOndřej Surý <ondrej@sury.org>
Wed, 13 Jun 2018 12:19:07 +0000 (14:19 +0200)
lib/isc/Makefile.in
lib/isc/openssl_shim.c [new file with mode: 0644]
lib/isc/openssl_shim.h [new file with mode: 0644]
lib/isc/win32/libisc.vcxproj.filters.in
lib/isc/win32/libisc.vcxproj.in

index 5edc5635b6e5ec3436a734387269495648e162d2..a5367839895296766d0cba38b04971f555714975 100644 (file)
@@ -56,7 +56,7 @@ OBJS =                @ISC_EXTRA_OBJS@ @ISC_PK11_O@ @ISC_PK11_RESULT_O@ \
                hmacsha.@O@ httpd.@O@ iterated_hash.@O@ \
                lex.@O@ lfsr.@O@ lib.@O@ log.@O@ \
                md5.@O@ mem.@O@ mutexblock.@O@ \
-               netaddr.@O@ netscope.@O@ nonce.@O@ pool.@O@ \
+               netaddr.@O@ netscope.@O@ nonce.@O@ openssl_shim.@O@ pool.@O@ \
                parseint.@O@ portset.@O@ quota.@O@ radix.@O@ random.@O@ \
                ratelimiter.@O@ refcount.@O@ region.@O@ regex.@O@ result.@O@ \
                rwlock.@O@ \
@@ -74,7 +74,7 @@ SRCS =                @ISC_EXTRA_SRCS@ @ISC_PK11_C@ @ISC_PK11_RESULT_C@ \
                hmacsha.c httpd.c iterated_hash.c \
                lex.c lfsr.c lib.c log.c \
                md5.c mem.c mutexblock.c \
-               netaddr.c netscope.c nonce.c pool.c \
+               netaddr.c netscope.c nonce.c openssl_shim.c pool.c \
                parseint.c portset.c quota.c radix.c random.c \
                ratelimiter.c refcount.c region.c regex.c result.c rwlock.c \
                safe.c serial.c sha1.c sha2.c sockaddr.c stats.c string.c \
diff --git a/lib/isc/openssl_shim.c b/lib/isc/openssl_shim.c
new file mode 100644 (file)
index 0000000..e53a506
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * See the COPYRIGHT file distributed with this work for additional
+ * information regarding copyright ownership.
+ */
+
+#include <config.h>
+
+#include <openssl/opensslv.h>
+
+#if HAVE_OPENSSL && (OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER))
+
+#include <stdlib.h>
+#include <string.h>
+#include "openssl_shim.h"
+#include <openssl/engine.h>
+#include <openssl/hmac.h>
+#include <openssl/crypto.h>
+
+void *OPENSSL_zalloc(size_t size)
+{
+       void *ret = OPENSSL_malloc(size);
+       if (ret != NULL) {
+               memset(ret, 0, size);
+       }
+       return ret;
+}
+
+EVP_CIPHER_CTX* EVP_CIPHER_CTX_new(void)
+{
+       EVP_CIPHER_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
+       return ctx;
+}
+
+void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx)
+{
+       if (ctx != NULL) {
+               EVP_CIPHER_CTX_cleanup(ctx);
+               OPENSSL_free(ctx);
+       }
+}
+
+EVP_MD_CTX *EVP_MD_CTX_new(void)
+{
+       EVP_MD_CTX *ctx = OPENSSL_malloc(sizeof(*ctx));
+       if (ctx != NULL) {
+               memset(ctx, 0, sizeof(*ctx));
+       }
+       return ctx;
+}
+
+void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
+{
+       if (ctx != NULL) {
+               EVP_MD_CTX_cleanup(ctx);
+               OPENSSL_free(ctx);
+       }
+}
+
+int EVP_MD_CTX_reset(EVP_MD_CTX *ctx)
+{
+       return EVP_MD_CTX_cleanup(ctx);
+}
+
+HMAC_CTX *HMAC_CTX_new(void)
+{
+       HMAC_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
+       if (ctx != NULL) {
+               if (!HMAC_CTX_reset(ctx)) {
+                       HMAC_CTX_free(ctx);
+                       return NULL;
+               }
+       }
+       return ctx;
+}
+
+void HMAC_CTX_free(HMAC_CTX *ctx)
+{
+       if (ctx != NULL) {
+               HMAC_CTX_cleanup(ctx);
+               OPENSSL_free(ctx);
+       }
+}
+
+int HMAC_CTX_reset(HMAC_CTX *ctx) {
+       HMAC_CTX_cleanup(ctx);
+       return 1;
+}
+               
+#endif
diff --git a/lib/isc/openssl_shim.h b/lib/isc/openssl_shim.h
new file mode 100644 (file)
index 0000000..b10b63b
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * See the COPYRIGHT file distributed with this work for additional
+ * information regarding copyright ownership.
+ */
+
+#ifndef ISC_OPENSSL_P_H
+#define ISC_OPENSSL_P_H
+
+#include <config.h>
+
+#include <openssl/opensslv.h>
+
+#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
+
+#include <openssl/engine.h>
+#include <openssl/hmac.h>
+
+void *OPENSSL_zalloc(size_t size);
+EVP_CIPHER_CTX* EVP_CIPHER_CTX_new(void);
+void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx);
+EVP_MD_CTX *EVP_MD_CTX_new(void);
+void EVP_MD_CTX_free(EVP_MD_CTX *ctx);
+int EVP_MD_CTX_reset(EVP_MD_CTX *ctx);
+HMAC_CTX *HMAC_CTX_new(void);
+void HMAC_CTX_free(HMAC_CTX *ctx);
+int HMAC_CTX_reset(HMAC_CTX *ctx);
+
+#endif /* ISC_OPENSSL_P_H */
+
+#endif /* ISC_OPENSSL_P_H */
index 268a4f0a9d08048ff872e9862d41516d7d19073c..49d1bdf8903b18fb306f2cd1bca32cbb4abb3704 100644 (file)
     <ClInclude Include="../entropy_private.h">
       <Filter>Win32 Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="../openssl_shim.h">
+      <Filter>Win32 Header Files</Filter>
+    </ClInclude>
     <ClInclude Include="errno2result.h">
       <Filter>Win32 Header Files</Filter>
     </ClInclude>
     <ClCompile Include="..\nonce.c">
       <Filter>Library Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\openssl_shim.c">
+      <Filter>Library Source Files</Filter>
+    </ClCompile>
     <ClCompile Include="..\parseint.c">
       <Filter>Library Source Files</Filter>
     </ClCompile>
index f6ec1c0a080c74c32ceb3cf185c7c4c3d57dc9d5..2a72d897790537658922deec77b8db2314f03fdd 100644 (file)
@@ -415,7 +415,8 @@ copy InstallFiles ..\Build\Release\
     <ClInclude Include="include\isc\thread.h" />
     <ClInclude Include="include\isc\time.h" />
     <ClInclude Include="include\isc\win32os.h" />
-    <ClInclude Include="../entropy_private.h" />\r    
+    <ClInclude Include="../entropy_private.h" />
+    <ClInclude Include="../openssl_shim.h" />\r    
     <ClInclude Include="syslog.h" />
     <ClInclude Include="unistd.h" />
 @IF PKCS11
@@ -462,6 +463,7 @@ copy InstallFiles ..\Build\Release\
     <ClCompile Include="..\netscope.c" />
     <ClCompile Include="..\nonce.c" />
     <ClCompile Include="..\nls\msgcat.c" />
+    <ClCompile Include="..\openssl_shim.c" />
     <ClCompile Include="..\parseint.c" />
     <ClCompile Include="..\pool.c" />
     <ClCompile Include="..\portset.c" />