summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-09-16 10:18:02 -0400
committerNick Mathewson <nickm@torproject.org>2016-09-16 10:20:08 -0400
commit83129031b1a1a3c719810d30df0e3ec6fa320661 (patch)
treeb59822b425414831cdcbab5db3fe649b36a4f2ac
parentff116b780896bb735f887a669d87694bb6d8a964 (diff)
downloadtor-83129031b1a1a3c719810d30df0e3ec6fa320661.tar.gz
tor-83129031b1a1a3c719810d30df0e3ec6fa320661.zip
Remove a needless level of indirection from crypto_cipher_t
Now that crypto_cipher_t only contains a pointer, it no longer has any reason for an independent existence.
-rw-r--r--src/common/crypto.c23
-rw-r--r--src/common/crypto.h2
2 files changed, 7 insertions, 18 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index f6ee6b0d6a..fb7734026c 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -120,13 +120,6 @@ struct crypto_pk_t
RSA *key; /**< The key itself */
};
-/** Key and stream information for a stream cipher. */
-struct crypto_cipher_t
-{
- aes_cnt_cipher_t *cipher; /**< The key in format usable for counter-mode AES
- * encryption */
-};
-
/** A structure to hold the first half (x, g^x) of a Diffie-Hellman handshake
* while we're waiting for the second.*/
struct crypto_dh_t {
@@ -559,8 +552,7 @@ crypto_cipher_new_with_iv(const char *key, const char *iv)
tor_assert(key);
tor_assert(iv);
- env = tor_malloc(sizeof(crypto_cipher_t));
- env->cipher = aes_new_cipher((const uint8_t*)key, (const uint8_t*)iv, 128);
+ env = aes_new_cipher((const uint8_t*)key, (const uint8_t*)iv, 128);
return env;
}
@@ -583,10 +575,7 @@ crypto_cipher_free(crypto_cipher_t *env)
if (!env)
return;
- tor_assert(env->cipher);
- aes_cipher_free(env->cipher);
- memwipe(env, 0, sizeof(crypto_cipher_t));
- tor_free(env);
+ aes_cipher_free(env);
}
/* public key crypto */
@@ -1586,14 +1575,14 @@ crypto_cipher_encrypt(crypto_cipher_t *env, char *to,
const char *from, size_t fromlen)
{
tor_assert(env);
- tor_assert(env->cipher);
+ tor_assert(env);
tor_assert(from);
tor_assert(fromlen);
tor_assert(to);
tor_assert(fromlen < SIZE_T_CEILING);
memcpy(to, from, fromlen);
- aes_crypt_inplace(env->cipher, to, fromlen);
+ aes_crypt_inplace(env, to, fromlen);
return 0;
}
@@ -1611,7 +1600,7 @@ crypto_cipher_decrypt(crypto_cipher_t *env, char *to,
tor_assert(fromlen < SIZE_T_CEILING);
memcpy(to, from, fromlen);
- aes_crypt_inplace(env->cipher, to, fromlen);
+ aes_crypt_inplace(env, to, fromlen);
return 0;
}
@@ -1622,7 +1611,7 @@ void
crypto_cipher_crypt_inplace(crypto_cipher_t *env, char *buf, size_t len)
{
tor_assert(len < SIZE_T_CEILING);
- aes_crypt_inplace(env->cipher, buf, len);
+ aes_crypt_inplace(env, buf, len);
}
/** Encrypt <b>fromlen</b> bytes (at least 1) from <b>from</b> with the key in
diff --git a/src/common/crypto.h b/src/common/crypto.h
index 2d1155e205..e60cf34343 100644
--- a/src/common/crypto.h
+++ b/src/common/crypto.h
@@ -117,7 +117,7 @@ typedef struct {
} common_digests_t;
typedef struct crypto_pk_t crypto_pk_t;
-typedef struct crypto_cipher_t crypto_cipher_t;
+typedef struct aes_cnt_cipher crypto_cipher_t;
typedef struct crypto_digest_t crypto_digest_t;
typedef struct crypto_xof_t crypto_xof_t;
typedef struct crypto_dh_t crypto_dh_t;