summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/crypto_init.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/crypto_init.c')
-rw-r--r--src/lib/libcrypto/crypto_init.c56
1 files changed, 56 insertions, 0 deletions
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 @@
1/*
2 * Copyright (c) 2018 Bob Beck <beck@openbsd.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17/* OpenSSL style init */
18
19#include <pthread.h>
20#include <stdio.h>
21
22#include <openssl/objects.h>
23#include <openssl/conf.h>
24#include <openssl/evp.h>
25#include <openssl/err.h>
26#include "cryptlib.h"
27
28static pthread_t crypto_init_thread;
29
30static void
31OPENSSL_init_crypto_internal(void)
32{
33 crypto_init_thread = pthread_self();
34 OPENSSL_cpuid_setup();
35 ERR_load_crypto_strings();
36 OpenSSL_add_all_ciphers();
37 OpenSSL_add_all_digests();
38 OPENSSL_config(NULL);
39}
40
41int
42OPENSSL_init_crypto(uint64_t opts, const void *settings)
43{
44 static pthread_once_t once = PTHREAD_ONCE_INIT;
45
46 if (pthread_equal(pthread_self(), crypto_init_thread))
47 return 1; /* don't recurse */
48
49 if (opts & OPENSSL_INIT_NO_LOAD_CONFIG)
50 OPENSSL_no_config();
51
52 if (pthread_once(&once, OPENSSL_init_crypto_internal) != 0)
53 return 0;
54
55 return 1;
56}