summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2011-06-03 11:36:21 -0400
committerNick Mathewson <nickm@torproject.org>2011-06-03 11:36:21 -0400
commit12f9c91c06edf09d8acf40b08aece22b77258dbc (patch)
treeaf0ba8d5fe9ed5f420bf1d62ef4ef124725a4861 /src
parent50e4c98a5acb6d10203cc943a336abb7715414cf (diff)
parent7aa20b20bffcbc4c9b4e3eb1c874616e1cab119f (diff)
downloadtor-12f9c91c06edf09d8acf40b08aece22b77258dbc.tar.gz
tor-12f9c91c06edf09d8acf40b08aece22b77258dbc.zip
Merge remote-tracking branch 'origin/maint-0.2.2'
Diffstat (limited to 'src')
-rw-r--r--src/common/crypto.c11
-rw-r--r--src/common/crypto.h1
-rw-r--r--src/or/routerparse.c4
-rw-r--r--src/test/test_crypto.c2
4 files changed, 16 insertions, 2 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 684ede06a6..424a6f4175 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -777,6 +777,17 @@ crypto_pk_keysize(crypto_pk_env_t *env)
return (size_t) RSA_size(env->key);
}
+/** Return the size of the public key modulus of <b>env</b>, in bits. */
+int
+crypto_pk_num_bits(crypto_pk_env_t *env)
+{
+ tor_assert(env);
+ tor_assert(env->key);
+ tor_assert(env->key->n);
+
+ return BN_num_bits(env->key->n);
+}
+
/** Increase the reference count of <b>env</b>, and return it.
*/
crypto_pk_env_t *
diff --git a/src/common/crypto.h b/src/common/crypto.h
index f28087589e..9b4eee622b 100644
--- a/src/common/crypto.h
+++ b/src/common/crypto.h
@@ -119,6 +119,7 @@ int crypto_pk_write_private_key_to_filename(crypto_pk_env_t *env,
int crypto_pk_check_key(crypto_pk_env_t *env);
int crypto_pk_cmp_keys(crypto_pk_env_t *a, crypto_pk_env_t *b);
size_t crypto_pk_keysize(crypto_pk_env_t *env);
+int crypto_pk_num_bits(crypto_pk_env_t *env);
crypto_pk_env_t *crypto_pk_dup_key(crypto_pk_env_t *orig);
crypto_pk_env_t *crypto_pk_copy_full(crypto_pk_env_t *orig);
int crypto_pk_key_is_private(const crypto_pk_env_t *key);
diff --git a/src/or/routerparse.c b/src/or/routerparse.c
index 79ce2b13c0..b146e5e3c9 100644
--- a/src/or/routerparse.c
+++ b/src/or/routerparse.c
@@ -3774,9 +3774,9 @@ token_check_object(memarea_t *area, const char *kwd,
break;
case NEED_KEY_1024: /* There must be a 1024-bit public key. */
case NEED_SKEY_1024: /* There must be a 1024-bit private key. */
- if (tok->key && crypto_pk_keysize(tok->key) != PK_BYTES) {
+ if (tok->key && crypto_pk_num_bits(tok->key) != PK_BYTES*8) {
tor_snprintf(ebuf, sizeof(ebuf), "Wrong size on key for %s: %d bits",
- kwd, (int)crypto_pk_keysize(tok->key)*8);
+ kwd, crypto_pk_num_bits(tok->key));
RET_ERR(ebuf);
}
/* fall through */
diff --git a/src/test/test_crypto.c b/src/test/test_crypto.c
index bf2cc48174..121af279c7 100644
--- a/src/test/test_crypto.c
+++ b/src/test/test_crypto.c
@@ -343,7 +343,9 @@ test_crypto_pk(void)
test_eq(0, crypto_pk_cmp_keys(pk1, pk2));
test_eq(128, crypto_pk_keysize(pk1));
+ test_eq(1024, crypto_pk_num_bits(pk1));
test_eq(128, crypto_pk_keysize(pk2));
+ test_eq(1024, crypto_pk_num_bits(pk2));
test_eq(128, crypto_pk_public_encrypt(pk2, data1, sizeof(data1),
"Hello whirled.", 15,