mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-04 00:25:29 +00:00
Add thin openssl shim for OpenSSL 1.1.x and LibreSSL compatibility functions
This commit is contained in:
@@ -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 \
|
||||
|
95
lib/isc/openssl_shim.c
Normal file
95
lib/isc/openssl_shim.c
Normal file
@@ -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
|
36
lib/isc/openssl_shim.h
Normal file
36
lib/isc/openssl_shim.h
Normal file
@@ -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 */
|
@@ -366,6 +366,9 @@
|
||||
<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>
|
||||
@@ -588,6 +591,9 @@
|
||||
<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>
|
||||
|
@@ -416,6 +416,7 @@ copy InstallFiles ..\Build\Release\
|
||||
<ClInclude Include="include\isc\time.h" />
|
||||
<ClInclude Include="include\isc\win32os.h" />
|
||||
<ClInclude Include="../entropy_private.h" />
|
||||
<ClInclude Include="../openssl_shim.h" />
|
||||
|
||||
<ClInclude Include="syslog.h" />
|
||||
<ClInclude Include="unistd.h" />
|
||||
@@ -462,6 +463,7 @@ copy InstallFiles ..\Build\Release\
|
||||
<ClCompile Include="..\netaddr.c" />
|
||||
<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" />
|
||||
|
Reference in New Issue
Block a user