commit 5b7a12d58a9e58d35c0007062377ea308faf1989 Author: Fernando Fernandez Mancera ffmancera@riseup.net Date: Tue May 8 15:40:11 2018 +0200
Add crypto_log_errors() to crypto_util.[ch]
crypto_log_errors() has been moved to crypto_util.[ch]. It was duplicated in some files so they have been removed too.
Follows #24658.
Signed-off-by: Fernando Fernandez Mancera ffmancera@riseup.net --- src/common/crypto.c | 21 --------------------- src/common/crypto_rsa.c | 21 --------------------- src/common/crypto_util.c | 20 ++++++++++++++++++++ src/common/crypto_util.h | 3 +++ src/tools/tor-gencert.c | 23 ----------------------- 5 files changed, 23 insertions(+), 65 deletions(-)
diff --git a/src/common/crypto.c b/src/common/crypto.c index 052f31723..6518ea9cc 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -86,27 +86,6 @@ static int crypto_early_initialized_ = 0; /** Boolean: has OpenSSL's crypto been initialized? */ static int crypto_global_initialized_ = 0;
-/** Log all pending crypto errors at level <b>severity</b>. Use - * <b>doing</b> to describe our current activities. - */ -static void -crypto_log_errors(int severity, const char *doing) -{ - unsigned long err; - const char *msg, *lib, *func; - while ((err = ERR_get_error()) != 0) { - msg = (const char*)ERR_reason_error_string(err); - lib = (const char*)ERR_lib_error_string(err); - func = (const char*)ERR_func_error_string(err); - if (!msg) msg = "(null)"; - if (!lib) lib = "(null)"; - if (!func) func = "(null)"; - if (BUG(!doing)) doing = "(null)"; - tor_log(severity, LD_CRYPTO, "crypto error while %s: %s (in %s:%s)", - doing, msg, lib, func); - } -} - #ifndef DISABLE_ENGINES /** Log any OpenSSL engines we're using at NOTICE. */ static void diff --git a/src/common/crypto_rsa.c b/src/common/crypto_rsa.c index 0a88b0e77..5d44dd67f 100644 --- a/src/common/crypto_rsa.c +++ b/src/common/crypto_rsa.c @@ -44,27 +44,6 @@ struct crypto_pk_t RSA *key; /**< The key itself */ };
-/** Log all pending crypto errors at level <b>severity</b>. Use - * <b>doing</b> to describe our current activities. - */ -static void -crypto_log_errors(int severity, const char *doing) -{ - unsigned long err; - const char *msg, *lib, *func; - while ((err = ERR_get_error()) != 0) { - msg = (const char*)ERR_reason_error_string(err); - lib = (const char*)ERR_lib_error_string(err); - func = (const char*)ERR_func_error_string(err); - if (!msg) msg = "(null)"; - if (!lib) lib = "(null)"; - if (!func) func = "(null)"; - if (BUG(!doing)) doing = "(null)"; - tor_log(severity, LD_CRYPTO, "crypto error while %s: %s (in %s:%s)", - doing, msg, lib, func); - } -} - /** Return the number of bytes added by padding method <b>padding</b>. */ int diff --git a/src/common/crypto_util.c b/src/common/crypto_util.c index b0d5b6b2f..1e1e7284e 100644 --- a/src/common/crypto_util.c +++ b/src/common/crypto_util.c @@ -27,10 +27,13 @@
DISABLE_GCC_WARNING(redundant-decls)
+#include <openssl/err.h> #include <openssl/crypto.h>
ENABLE_GCC_WARNING(redundant-decls)
+#include "torlog.h" + /** * Destroy the <b>sz</b> bytes of data stored at <b>mem</b>, setting them to * the value <b>byte</b>. @@ -103,5 +106,22 @@ memwipe(void *mem, uint8_t byte, size_t sz) memset(mem, byte, sz); }
+void +crypto_log_errors(int severity, const char *doing) +{ + unsigned long err; + const char *msg, *lib, *func; + while ((err = ERR_get_error()) != 0) { + msg = (const char*)ERR_reason_error_string(err); + lib = (const char*)ERR_lib_error_string(err); + func = (const char*)ERR_func_error_string(err); + if (!msg) msg = "(null)"; + if (!lib) lib = "(null)"; + if (!func) func = "(null)"; + if (BUG(!doing)) doing = "(null)"; + tor_log(severity, LD_CRYPTO, "crypto error while %s: %s (in %s:%s)", + doing, msg, lib, func); + } +} #endif /* !defined(CRYPTO_UTIL_PRIVATE) */
diff --git a/src/common/crypto_util.h b/src/common/crypto_util.h index 922942b37..31af52bff 100644 --- a/src/common/crypto_util.h +++ b/src/common/crypto_util.h @@ -18,6 +18,9 @@ /** OpenSSL-based utility functions. */ void memwipe(void *mem, uint8_t byte, size_t sz);
+/** Log utility function */ +void crypto_log_errors(int severity, const char *doing); + #ifdef CRYPTO_UTIL_PRIVATE #ifdef TOR_UNIT_TESTS #endif /* defined(TOR_UNIT_TESTS) */ diff --git a/src/tools/tor-gencert.c b/src/tools/tor-gencert.c index aafefdad7..ff3ce517e 100644 --- a/src/tools/tor-gencert.c +++ b/src/tools/tor-gencert.c @@ -78,29 +78,6 @@ show_help(void) "[--passphrase-fd <fd>]\n"); }
-/* XXXX copied from crypto.c */ -static void -crypto_log_errors(int severity, const char *doing) -{ - unsigned long err; - const char *msg, *lib, *func; - while ((err = ERR_get_error()) != 0) { - msg = (const char*)ERR_reason_error_string(err); - lib = (const char*)ERR_lib_error_string(err); - func = (const char*)ERR_func_error_string(err); - if (!msg) msg = "(null)"; - if (!lib) lib = "(null)"; - if (!func) func = "(null)"; - if (doing) { - tor_log(severity, LD_CRYPTO, "crypto error while %s: %s (in %s:%s)", - doing, msg, lib, func); - } else { - tor_log(severity, LD_CRYPTO, "crypto error: %s (in %s:%s)", - msg, lib, func); - } - } -} - /** Read the passphrase from the passphrase fd. */ static int load_passphrase(void)