From d18ae25f28e72831dc3c51f78e0735342540098b Mon Sep 17 00:00:00 2001 From: beck <> Date: Sat, 17 Mar 2018 16:20:01 +0000 Subject: Bring in compatibility for OpenSSL 1.1 style init functions. This adds OPENSSL_init_crypto and OPENSSL_init_ssl, as well thread safety modifications for the existing LibreSSL init functions. The initialization routines are called automatically by the normal entry points into the library, as in newer OpenSSL ok jsing@, nits by tb@ and deraadt@ --- src/lib/libcrypto/crypto_init.c | 56 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/lib/libcrypto/crypto_init.c (limited to 'src/lib/libcrypto/crypto_init.c') diff --git a/src/lib/libcrypto/crypto_init.c b/src/lib/libcrypto/crypto_init.c new file mode 100644 index 0000000000..f3d1a2bce9 --- /dev/null +++ b/src/lib/libcrypto/crypto_init.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2018 Bob Beck + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* OpenSSL style init */ + +#include +#include + +#include +#include +#include +#include +#include "cryptlib.h" + +static pthread_t crypto_init_thread; + +static void +OPENSSL_init_crypto_internal(void) +{ + crypto_init_thread = pthread_self(); + OPENSSL_cpuid_setup(); + ERR_load_crypto_strings(); + OpenSSL_add_all_ciphers(); + OpenSSL_add_all_digests(); + OPENSSL_config(NULL); +} + +int +OPENSSL_init_crypto(uint64_t opts, const void *settings) +{ + static pthread_once_t once = PTHREAD_ONCE_INIT; + + if (pthread_equal(pthread_self(), crypto_init_thread)) + return 1; /* don't recurse */ + + if (opts & OPENSSL_INIT_NO_LOAD_CONFIG) + OPENSSL_no_config(); + + if (pthread_once(&once, OPENSSL_init_crypto_internal) != 0) + return 0; + + return 1; +} -- cgit v1.2.3-55-g6feb