summaryrefslogtreecommitdiff
path: root/deps/openssl/openssl/crypto/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'deps/openssl/openssl/crypto/init.c')
-rw-r--r--deps/openssl/openssl/crypto/init.c108
1 files changed, 82 insertions, 26 deletions
diff --git a/deps/openssl/openssl/crypto/init.c b/deps/openssl/openssl/crypto/init.c
index 2ad946c5bf..209d1a483d 100644
--- a/deps/openssl/openssl/crypto/init.c
+++ b/deps/openssl/openssl/crypto/init.c
@@ -7,23 +7,26 @@
* https://www.openssl.org/source/license.html
*/
-#include <internal/cryptlib_int.h>
+#include "e_os.h"
+#include "internal/cryptlib_int.h"
#include <openssl/err.h>
-#include <internal/rand.h>
-#include <internal/bio.h>
+#include "internal/rand_int.h"
+#include "internal/bio.h"
#include <openssl/evp.h>
-#include <internal/evp_int.h>
-#include <internal/conf.h>
-#include <internal/async.h>
-#include <internal/engine.h>
-#include <internal/comp.h>
-#include <internal/err.h>
-#include <internal/err_int.h>
-#include <internal/objects.h>
+#include "internal/evp_int.h"
+#include "internal/conf.h"
+#include "internal/async.h"
+#include "internal/engine.h"
+#include "internal/comp.h"
+#include "internal/err.h"
+#include "internal/err_int.h"
+#include "internal/objects.h"
#include <stdlib.h>
#include <assert.h>
-#include <internal/thread_once.h>
-#include <internal/dso.h>
+#include "internal/thread_once.h"
+#include "internal/dso_conf.h"
+#include "internal/dso.h"
+#include "internal/store.h"
static int stopped = 0;
@@ -90,6 +93,9 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_base)
#ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_base: Setting up stop handlers\n");
#endif
+#ifndef OPENSSL_NO_CRYPTO_MDEBUG
+ ossl_malloc_setup_failures();
+#endif
if (!CRYPTO_THREAD_init_local(&key, ossl_init_thread_destructor))
return 0;
if ((init_lock = CRYPTO_THREAD_lock_new()) == NULL)
@@ -191,7 +197,7 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_load_crypto_strings)
# endif
ret = err_load_crypto_strings_int();
load_crypto_strings_inited = 1;
-#endif
+#endif
return ret;
}
@@ -284,16 +290,15 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_engine_openssl)
engine_load_openssl_int();
return 1;
}
-# if !defined(OPENSSL_NO_HW) && \
- (defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV))
-static CRYPTO_ONCE engine_cryptodev = CRYPTO_ONCE_STATIC_INIT;
-DEFINE_RUN_ONCE_STATIC(ossl_init_engine_cryptodev)
+# ifndef OPENSSL_NO_DEVCRYPTOENG
+static CRYPTO_ONCE engine_devcrypto = CRYPTO_ONCE_STATIC_INIT;
+DEFINE_RUN_ONCE_STATIC(ossl_init_engine_devcrypto)
{
# ifdef OPENSSL_INIT_DEBUG
- fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_cryptodev: "
- "engine_load_cryptodev_int()\n");
+ fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_devcrypto: "
+ "engine_load_devcrypto_int()\n");
# endif
- engine_load_cryptodev_int();
+ engine_load_devcrypto_int();
return 1;
}
# endif
@@ -394,6 +399,14 @@ static void ossl_init_thread_stop(struct thread_local_inits_st *locals)
err_delete_thread_state();
}
+ if (locals->rand) {
+#ifdef OPENSSL_INIT_DEBUG
+ fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_stop: "
+ "drbg_delete_thread_state()\n");
+#endif
+ drbg_delete_thread_state();
+ }
+
OPENSSL_free(locals);
}
@@ -431,6 +444,14 @@ int ossl_init_thread_start(uint64_t opts)
locals->err_state = 1;
}
+ if (opts & OPENSSL_INIT_THREAD_RAND) {
+#ifdef OPENSSL_INIT_DEBUG
+ fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "
+ "marking thread for rand\n");
+#endif
+ locals->rand = 1;
+ }
+
return 1;
}
@@ -464,6 +485,7 @@ void OPENSSL_cleanup(void)
stop_handlers = NULL;
CRYPTO_THREAD_lock_free(init_lock);
+ init_lock = NULL;
/*
* We assume we are single-threaded for this function, i.e. no race
@@ -534,16 +556,20 @@ void OPENSSL_cleanup(void)
* obj_cleanup_int() must be called last
*/
rand_cleanup_int();
+ rand_drbg_cleanup_int();
conf_modules_free_int();
#ifndef OPENSSL_NO_ENGINE
engine_cleanup_int();
#endif
+ ossl_store_cleanup_int();
crypto_cleanup_all_ex_data_int();
bio_cleanup();
evp_cleanup_int();
obj_cleanup_int();
err_cleanup();
+ CRYPTO_secure_malloc_done();
+
base_inited = 0;
}
@@ -593,6 +619,10 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
&& !RUN_ONCE(&add_all_digests, ossl_init_add_all_digests))
return 0;
+ if ((opts & OPENSSL_INIT_ATFORK)
+ && !openssl_init_fork_handlers())
+ return 0;
+
if ((opts & OPENSSL_INIT_NO_LOAD_CONFIG)
&& !RUN_ONCE(&config, ossl_init_no_config))
return 0;
@@ -615,10 +645,9 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
if ((opts & OPENSSL_INIT_ENGINE_OPENSSL)
&& !RUN_ONCE(&engine_openssl, ossl_init_engine_openssl))
return 0;
-# if !defined(OPENSSL_NO_HW) && \
- (defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV))
+# if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_DEVCRYPTOENG)
if ((opts & OPENSSL_INIT_ENGINE_CRYPTODEV)
- && !RUN_ONCE(&engine_cryptodev, ossl_init_engine_cryptodev))
+ && !RUN_ONCE(&engine_devcrypto, ossl_init_engine_devcrypto))
return 0;
# endif
# ifndef OPENSSL_NO_RDRAND
@@ -715,9 +744,10 @@ int OPENSSL_atexit(void (*handler)(void))
}
#endif
- newhand = OPENSSL_malloc(sizeof(*newhand));
- if (newhand == NULL)
+ if ((newhand = OPENSSL_malloc(sizeof(*newhand))) == NULL) {
+ CRYPTOerr(CRYPTO_F_OPENSSL_ATEXIT, ERR_R_MALLOC_FAILURE);
return 0;
+ }
newhand->handler = handler;
newhand->next = stop_handlers;
@@ -725,3 +755,29 @@ int OPENSSL_atexit(void (*handler)(void))
return 1;
}
+
+#ifdef OPENSSL_SYS_UNIX
+/*
+ * The following three functions are for OpenSSL developers. This is
+ * where we set/reset state across fork (called via pthread_atfork when
+ * it exists, or manually by the application when it doesn't).
+ *
+ * WARNING! If you put code in either OPENSSL_fork_parent or
+ * OPENSSL_fork_child, you MUST MAKE SURE that they are async-signal-
+ * safe. See this link, for example:
+ * http://man7.org/linux/man-pages/man7/signal-safety.7.html
+ */
+
+void OPENSSL_fork_prepare(void)
+{
+}
+
+void OPENSSL_fork_parent(void)
+{
+}
+
+void OPENSSL_fork_child(void)
+{
+ rand_fork();
+}
+#endif