diff options
author | Fernando Fernandez Mancera <ffmancera@riseup.net> | 2018-01-26 16:43:46 +0100 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-02-01 12:08:54 -0500 |
commit | 3812319bb16f8687c7b21c9b7bcd86b2ed62663a (patch) | |
tree | 55ebecfd512e662f6a9a71c864cedc1d4902538c /src/common/crypto_rsa.c | |
parent | 54783b4c22675925fcfcac77cb95193bc5c32d03 (diff) | |
download | tor-3812319bb16f8687c7b21c9b7bcd86b2ed62663a.tar.gz tor-3812319bb16f8687c7b21c9b7bcd86b2ed62663a.zip |
Tweaks into functions and variables in crypto_rsa.[ch]
crypto_get_rsa_padding_overhead() and crypto_get_rsa_padding() are
not static inline anymore in order to split the crypto_rsa module
from crypto.[ch].
Also included necessary modules in order to solve dependency issues.
Also made two functions in crypto.c use crypto_pk_asn1_encdoe()
instead of reaching into the crypto_pk_t struct.
Diffstat (limited to 'src/common/crypto_rsa.c')
-rw-r--r-- | src/common/crypto_rsa.c | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/src/common/crypto_rsa.c b/src/common/crypto_rsa.c index 1308c48193..92b5978eaf 100644 --- a/src/common/crypto_rsa.c +++ b/src/common/crypto_rsa.c @@ -10,17 +10,62 @@ **/ #include "crypto_rsa.h" - -/** A public key, or a public/private key-pair. */ +#include "crypto.h" +#include "compat_openssl.h" +#include "crypto_curve25519.h" +#include "crypto_ed25519.h" +#include "crypto_format.h" + +DISABLE_GCC_WARNING(redundant-decls) + +#include <openssl/err.h> +#include <openssl/rsa.h> +#include <openssl/pem.h> +#include <openssl/evp.h> +#include <openssl/engine.h> +#include <openssl/rand.h> +#include <openssl/bn.h> +#include <openssl/dh.h> +#include <openssl/conf.h> +#include <openssl/hmac.h> + +ENABLE_GCC_WARNING(redundant-decls) + +#include "torlog.h" +#include "util.h" +#include "util_format.h" + +/** Declaration for crypto_pk_t structure. */ struct crypto_pk_t { int refs; /**< reference count, so we don't have to copy keys */ 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>. */ -static inline int +int crypto_get_rsa_padding_overhead(int padding) { switch (padding) @@ -32,7 +77,7 @@ crypto_get_rsa_padding_overhead(int padding) /** Given a padding method <b>padding</b>, return the correct OpenSSL constant. */ -static inline int +int crypto_get_rsa_padding(int padding) { switch (padding) @@ -714,7 +759,7 @@ crypto_pk_private_sign(const crypto_pk_t *env, char *to, size_t tolen, * Return -1 on error, or the number of characters used on success. */ int -crypto_pk_asn1_encode(crypto_pk_t *pk, char *dest, size_t dest_len) +crypto_pk_asn1_encode(const crypto_pk_t *pk, char *dest, size_t dest_len) { int len; unsigned char *buf = NULL; |