summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-09-16 11:21:33 -0400
committerNick Mathewson <nickm@torproject.org>2016-09-16 11:21:33 -0400
commit6cb9c2cf77cc8375f89cc8d625d0b60e292d8160 (patch)
tree85dc1028688591761703dd06ee9de7ebc8563649 /src/common
parent83129031b1a1a3c719810d30df0e3ec6fa320661 (diff)
downloadtor-6cb9c2cf77cc8375f89cc8d625d0b60e292d8160.tar.gz
tor-6cb9c2cf77cc8375f89cc8d625d0b60e292d8160.zip
Add support for AES256 and AES192
(This will be used by prop224)
Diffstat (limited to 'src/common')
-rw-r--r--src/common/aes.c2
-rw-r--r--src/common/crypto.c39
-rw-r--r--src/common/crypto.h4
3 files changed, 34 insertions, 11 deletions
diff --git a/src/common/aes.c b/src/common/aes.c
index 7131ce199d..cb8fb681e4 100644
--- a/src/common/aes.c
+++ b/src/common/aes.c
@@ -48,7 +48,7 @@ ENABLE_GCC_WARNING(redundant-decls)
/* We have five strategies for implementing AES counter mode.
*
- * Best with x86 and x86_64: Use EVP_aes_ctr128() and EVP_EncryptUpdate().
+ * Best with x86 and x86_64: Use EVP_aes_*_ctr() and EVP_EncryptUpdate().
* This is possible with OpenSSL 1.0.1, where the counter-mode implementation
* can use bit-sliced or vectorized AES or AESNI as appropriate.
*
diff --git a/src/common/crypto.c b/src/common/crypto.c
index fb7734026c..72c1c45983 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -542,29 +542,48 @@ crypto_pk_free(crypto_pk_t *env)
}
/** Allocate and return a new symmetric cipher using the provided key and iv.
- * The key is CIPHER_KEY_LEN bytes; the IV is CIPHER_IV_LEN bytes. Both
- * must be provided.
- */
+ * The key is <b>bits</b> bits long; the IV is CIPHER_IV_LEN bytes. Both
+ * must be provided. Key length must be 128, 192, or 256 */
crypto_cipher_t *
-crypto_cipher_new_with_iv(const char *key, const char *iv)
+crypto_cipher_new_with_iv_and_bits(const uint8_t *key,
+ const uint8_t *iv,
+ int bits)
{
- crypto_cipher_t *env;
tor_assert(key);
tor_assert(iv);
- env = aes_new_cipher((const uint8_t*)key, (const uint8_t*)iv, 128);
+ return aes_new_cipher((const uint8_t*)key, (const uint8_t*)iv, bits);
+}
- return env;
+/** Allocate and return a new symmetric cipher using the provided key and iv.
+ * The key is CIPHER_KEY_LEN bytes; the IV is CIPHER_IV_LEN bytes. Both
+ * must be provided.
+ */
+crypto_cipher_t *
+crypto_cipher_new_with_iv(const char *key, const char *iv)
+{
+ return crypto_cipher_new_with_iv_and_bits((uint8_t*)key, (uint8_t*)iv,
+ 128);
}
/** Return a new crypto_cipher_t with the provided <b>key</b> and an IV of all
- * zero bytes. */
+ * zero bytes and key length <b>bits</b>. Key length must be 128, 192, or
+ * 256. */
crypto_cipher_t *
-crypto_cipher_new(const char *key)
+crypto_cipher_new_with_bits(const char *key, int bits)
{
char zeroiv[CIPHER_IV_LEN];
memset(zeroiv, 0, sizeof(zeroiv));
- return crypto_cipher_new_with_iv(key, zeroiv);
+ return crypto_cipher_new_with_iv_and_bits((uint8_t*)key, (uint8_t*)zeroiv,
+ bits);
+}
+
+/** Return a new crypto_cipher_t with the provided <b>key</b> (of
+ * CIPHER_KEY_LEN bytes) and an IV of all zero bytes. */
+crypto_cipher_t *
+crypto_cipher_new(const char *key)
+{
+ return crypto_cipher_new_with_bits(key, 128);
}
/** Free a symmetric cipher.
diff --git a/src/common/crypto.h b/src/common/crypto.h
index e60cf34343..116e0a62fd 100644
--- a/src/common/crypto.h
+++ b/src/common/crypto.h
@@ -138,7 +138,11 @@ void crypto_pk_free(crypto_pk_t *env);
void crypto_set_tls_dh_prime(void);
crypto_cipher_t *crypto_cipher_new(const char *key);
+crypto_cipher_t *crypto_cipher_new_with_bits(const char *key, int bits);
crypto_cipher_t *crypto_cipher_new_with_iv(const char *key, const char *iv);
+crypto_cipher_t *crypto_cipher_new_with_iv_and_bits(const uint8_t *key,
+ const uint8_t *iv,
+ int bits);
void crypto_cipher_free(crypto_cipher_t *env);
/* public key crypto */