summaryrefslogtreecommitdiff
path: root/src/common/crypto.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2008-12-29 02:20:57 +0000
committerNick Mathewson <nickm@torproject.org>2008-12-29 02:20:57 +0000
commitb0a8ecd19377d13592819b1bc17ea513523b2ed4 (patch)
treef83674bc4df65150a034b55d20d9ee618656b148 /src/common/crypto.c
parent46f8ef8116de5effdb8a5a62f4821662bbc31db7 (diff)
downloadtor-b0a8ecd19377d13592819b1bc17ea513523b2ed4.tar.gz
tor-b0a8ecd19377d13592819b1bc17ea513523b2ed4.zip
Use RSA_generate_key_ex where available.
svn:r17804
Diffstat (limited to 'src/common/crypto.c')
-rw-r--r--src/common/crypto.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 6686017bc1..2c892fbc1e 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -406,7 +406,33 @@ crypto_pk_generate_key(crypto_pk_env_t *env)
if (env->key)
RSA_free(env->key);
+#if OPENSSL_VERSION_NUMBER < 0x00908000l
+ /* In openssl 0.9.7, RSA_generate_key is all we have. */
env->key = RSA_generate_key(PK_BYTES*8,65537, NULL, NULL);
+#else
+ /* In openssl 0.9.8, RSA_generate_key is deprecated. */
+ {
+ BIGNUM *e = BN_new();
+ RSA *r = NULL;
+ if (!e)
+ goto done;
+ if (! BN_set_word(e, 65537))
+ goto done;
+ r = RSA_new();
+ if (!r)
+ goto done;
+ if (RSA_generate_key_ex(r, PK_BYTES*8, e, NULL) == -1)
+ goto done;
+
+ env->key = r;
+ r = NULL;
+ done:
+ if (e)
+ BN_free(e);
+ if (r)
+ RSA_free(r);
+ }
+#endif
if (!env->key) {
crypto_log_errors(LOG_WARN, "generating RSA key");
return -1;