[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Add crypto module as a subsystem.
commit 50436ccea4bd200e45196ccce7acff28f293a4de
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Fri Nov 2 11:21:06 2018 -0400
Add crypto module as a subsystem.
---
src/app/main/main.c | 7 -------
src/app/main/subsystem_list.c | 2 ++
src/lib/crypt_ops/.may_include | 1 +
src/lib/crypt_ops/crypto_init.c | 26 ++++++++++++++++++++++++++
src/lib/crypt_ops/crypto_sys.h | 14 ++++++++++++++
src/lib/crypt_ops/include.am | 1 +
src/test/testing_common.c | 2 --
7 files changed, 44 insertions(+), 9 deletions(-)
diff --git a/src/app/main/main.c b/src/app/main/main.c
index 3e80725b9..74c3c41e5 100644
--- a/src/app/main/main.c
+++ b/src/app/main/main.c
@@ -535,12 +535,6 @@ tor_init(int argc, char *argv[])
tor_snprintf(progname, sizeof(progname), "Tor %s", get_version());
log_set_application_name(progname);
- /* Set up the crypto nice and early */
- if (crypto_early_init() < 0) {
- log_err(LD_GENERAL, "Unable to initialize the crypto subsystem!");
- return -1;
- }
-
/* Initialize the history structures. */
rep_hist_init();
/* Initialize the service cache. */
@@ -859,7 +853,6 @@ tor_cleanup(void)
later, if it makes shutdown unacceptably slow. But for
now, leave it here: it's helped us catch bugs in the
past. */
- crypto_global_cleanup();
}
/** Read/create keys as needed, and echo our fingerprint to stdout. */
diff --git a/src/app/main/subsystem_list.c b/src/app/main/subsystem_list.c
index cb186c14d..dd6456822 100644
--- a/src/app/main/subsystem_list.c
+++ b/src/app/main/subsystem_list.c
@@ -8,6 +8,7 @@
#include "lib/cc/compat_compiler.h"
#include "lib/cc/torint.h"
+#include "lib/crypt_ops/crypto_sys.h"
#include "lib/err/torerr_sys.h"
#include "lib/log/log_sys.h"
#include "lib/net/network_sys.h"
@@ -27,6 +28,7 @@ const subsys_fns_t *tor_subsystems[] = {
&sys_threads,
&sys_logging,
&sys_network,
+ &sys_crypto,
};
const unsigned n_tor_subsystems = ARRAY_LENGTH(tor_subsystems);
diff --git a/src/lib/crypt_ops/.may_include b/src/lib/crypt_ops/.may_include
index a0fa4ec05..352fde858 100644
--- a/src/lib/crypt_ops/.may_include
+++ b/src/lib/crypt_ops/.may_include
@@ -12,6 +12,7 @@ lib/malloc/*.h
lib/intmath/*.h
lib/sandbox/*.h
lib/string/*.h
+lib/subsys/*.h
lib/testsupport/testsupport.h
lib/thread/*.h
lib/log/*.h
diff --git a/src/lib/crypt_ops/crypto_init.c b/src/lib/crypt_ops/crypto_init.c
index 9d6e2da0d..cc7865ef7 100644
--- a/src/lib/crypt_ops/crypto_init.c
+++ b/src/lib/crypt_ops/crypto_init.c
@@ -20,6 +20,9 @@
#include "lib/crypt_ops/crypto_openssl_mgt.h"
#include "lib/crypt_ops/crypto_nss_mgt.h"
#include "lib/crypt_ops/crypto_rand.h"
+#include "lib/crypt_ops/crypto_sys.h"
+
+#include "lib/subsys/subsys.h"
#include "siphash.h"
@@ -202,3 +205,26 @@ tor_is_using_nss(void)
return 0;
#endif
}
+
+static int
+init_crypto_sys(void)
+{
+ if (crypto_early_init() < 0)
+ return -1;
+ crypto_dh_init();
+ return 0;
+}
+
+static void
+shutdown_crypto_sys(void)
+{
+ crypto_global_cleanup();
+}
+
+const struct subsys_fns_t sys_crypto = {
+ .name = "crypto",
+ .supported = true,
+ .level = -60,
+ .initialize = init_crypto_sys,
+ .shutdown = shutdown_crypto_sys,
+};
diff --git a/src/lib/crypt_ops/crypto_sys.h b/src/lib/crypt_ops/crypto_sys.h
new file mode 100644
index 000000000..31644d088
--- /dev/null
+++ b/src/lib/crypt_ops/crypto_sys.h
@@ -0,0 +1,14 @@
+/* Copyright (c) 2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file log_crypto.h
+ * \brief Declare subsystem object for the crypto module.
+ **/
+
+#ifndef TOR_CRYPTO_SYS_H
+#define TOR_CRYPTO_SYS_H
+
+extern const struct subsys_fns_t sys_crypto;
+
+#endif /* !defined(TOR_CRYPTO_SYS_H) */
diff --git a/src/lib/crypt_ops/include.am b/src/lib/crypt_ops/include.am
index 1022096fd..d0ccc13bf 100644
--- a/src/lib/crypt_ops/include.am
+++ b/src/lib/crypt_ops/include.am
@@ -66,5 +66,6 @@ noinst_HEADERS += \
src/lib/crypt_ops/crypto_rand.h \
src/lib/crypt_ops/crypto_rsa.h \
src/lib/crypt_ops/crypto_s2k.h \
+ src/lib/crypt_ops/crypto_sys.h \
src/lib/crypt_ops/crypto_util.h \
src/lib/crypt_ops/digestset.h
diff --git a/src/test/testing_common.c b/src/test/testing_common.c
index 818bb58c9..d4c563233 100644
--- a/src/test/testing_common.c
+++ b/src/test/testing_common.c
@@ -331,8 +331,6 @@ main(int c, const char **v)
free_pregenerated_keys();
- crypto_global_cleanup();
-
if (have_failed)
return 1;
else
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits