aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-04-06 20:16:12 +0000
committerNick Mathewson <nickm@torproject.org>2004-04-06 20:16:12 +0000
commit6290d027c97ecdf2b6c75762fcc226ea006d0be3 (patch)
treec2dcd168ab8cbb708b1133a55eb24f8b7db5f1a6 /src/common
parentce51a30adc4392cff170c4ef22fb396cd09dbeaa (diff)
downloadtor-6290d027c97ecdf2b6c75762fcc226ea006d0be3.tar
tor-6290d027c97ecdf2b6c75762fcc226ea006d0be3.tar.gz
Continue attack on magic numbers; use new crypto wrappers where possible
svn:r1504
Diffstat (limited to 'src/common')
-rw-r--r--src/common/crypto.c6
-rw-r--r--src/common/util.c9
-rw-r--r--src/common/util.h1
3 files changed, 16 insertions, 0 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index b3f8c7e35..ebbb5b28c 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -560,6 +560,12 @@ int crypto_pk_public_hybrid_encrypt(crypto_pk_env_t *env,
if (!cipher) return -1;
if (crypto_cipher_generate_key(cipher)<0)
goto err;
+ /* You can't just run around RSA-encrypting any bitstream: if it's
+ * greater than the RSA key, then OpenSSL will happily encrypt, and
+ * later decrypt to the wrong value. So we set the first bit of
+ * 'cipher->key' to 0 if we aren't padding. This means that our
+ * symmetric key is really only 127 bits.
+ */
if (padding == PK_NO_PADDING)
cipher->key[0] &= 0x7f;
if (crypto_cipher_encrypt_init_cipher(cipher)<0)
diff --git a/src/common/util.c b/src/common/util.c
index 23a4aa55f..6ba926086 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -162,6 +162,15 @@ void hex_encode(const char *from, int fromlen, char *to)
*to = '\0';
}
+const char *hex_str(const char *from, int fromlen)
+{
+ static char buf[65];
+ if (fromlen>(sizeof(buf)-1)/2)
+ fromlen = (sizeof(buf)-1)/2;
+ hex_encode(from,fromlen,buf);
+ return buf;
+}
+
/*
* A simple smartlist interface to make an unordered list of acceptable
* nodes and then choose a random one.
diff --git a/src/common/util.h b/src/common/util.h
index de73eb742..48f06e424 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -95,6 +95,7 @@ void set_uint32(char *cp, uint32_t v);
#endif
void hex_encode(const char *from, int fromlen, char *to);
+const char *hex_str(const char *from, int fromlen);
typedef struct smartlist_t smartlist_t;