Browse Source

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>
Fernando Fernandez Mancera 6 years ago
parent
commit
5b7a12d58a
5 changed files with 23 additions and 65 deletions
  1. 0 21
      src/common/crypto.c
  2. 0 21
      src/common/crypto_rsa.c
  3. 20 0
      src/common/crypto_util.c
  4. 3 0
      src/common/crypto_util.h
  5. 0 23
      src/tools/tor-gencert.c

+ 0 - 21
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

+ 0 - 21
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

+ 20 - 0
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) */
 

+ 3 - 0
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) */

+ 0 - 23
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)