aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2003-09-10 00:47:24 +0000
committerNick Mathewson <nickm@torproject.org>2003-09-10 00:47:24 +0000
commit9955b265ab77c712861f33411e521c9761184226 (patch)
tree3cd11789926945c80a6f34ae0101437fe60cb12b /src/common
parent67697d5ab197c09f90adafef7d82895cfdbbb085 (diff)
downloadtor-9955b265ab77c712861f33411e521c9761184226.tar.gz
tor-9955b265ab77c712861f33411e521c9761184226.zip
Make crypto structures private to crypto.c
svn:r437
Diffstat (limited to 'src/common')
-rw-r--r--src/common/crypto.c59
-rw-r--r--src/common/crypto.h20
2 files changed, 47 insertions, 32 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 06e66857e2..5474d4f635 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -40,6 +40,24 @@
#define RETURN_SSL_OUTCOME(exp) return !(exp)
#endif
+struct crypto_pk_env_t
+{
+ int type;
+ int refs; /* reference counting; so we don't have to copy keys */
+ unsigned char *key;
+ /* auxiliary data structure(s) used by the underlying crypto library */
+ unsigned char *aux;
+};
+
+struct crypto_cipher_env_t
+{
+ int type;
+ unsigned char *key;
+ unsigned char *iv;
+ /* auxiliary data structure(s) used by the underlying crypto library */
+ unsigned char *aux;
+};
+
/* static INLINE const EVP_CIPHER *
crypto_cipher_evp_cipher(int type, int enc);
*/
@@ -102,31 +120,37 @@ int crypto_global_cleanup()
return 0;
}
-crypto_pk_env_t *crypto_new_pk_env(int type)
+crypto_pk_env_t *_crypto_new_pk_env_rsa(RSA *rsa)
{
crypto_pk_env_t *env;
-
+ assert(rsa);
env = (crypto_pk_env_t *)tor_malloc(sizeof(crypto_pk_env_t));
-
- env->type = type;
+ env->type = CRYPTO_PK_RSA;
env->refs = 1;
- env->key = NULL;
+ env->key = (unsigned char*)rsa;
env->aux = NULL;
-
+ return env;
+}
+
+RSA *_crypto_pk_env_get_rsa(crypto_pk_env_t *env)
+{
+ if (env->type != CRYPTO_PK_RSA)
+ return NULL;
+ return (RSA*)env->key;
+}
+
+crypto_pk_env_t *crypto_new_pk_env(int type)
+{
+ RSA *rsa;
+
switch(type) {
case CRYPTO_PK_RSA:
- env->key = (unsigned char *)RSA_new();
- if (!env->key) {
- free(env);
- return NULL;
- }
- break;
+ rsa = RSA_new();
+ if (!rsa) return NULL;
+ return _crypto_new_pk_env_rsa(rsa);
default:
- free(env);
return NULL;
}
-
- return env;
}
void crypto_free_pk_env(crypto_pk_env_t *env)
@@ -617,6 +641,11 @@ int crypto_cipher_set_key(crypto_cipher_env_t *env, unsigned char *key)
return 0;
}
+unsigned char *crypto_cipher_get_key(crypto_cipher_env_t *env)
+{
+ return env->key;
+}
+
int crypto_cipher_encrypt_init_cipher(crypto_cipher_env_t *env)
{
assert(env);
diff --git a/src/common/crypto.h b/src/common/crypto.h
index 051251329a..f723e71952 100644
--- a/src/common/crypto.h
+++ b/src/common/crypto.h
@@ -18,23 +18,8 @@
#define CRYPTO_PK_RSA 0
-typedef struct
-{
- int type;
- int refs; /* reference counting; so we don't have to copy keys */
- unsigned char *key;
- /* auxiliary data structure(s) used by the underlying crypto library */
- unsigned char *aux;
-} crypto_pk_env_t;
-
-typedef struct
-{
- int type;
- unsigned char *key;
- unsigned char *iv;
- /* auxiliary data structure(s) used by the underlying crypto library */
- unsigned char *aux;
-} crypto_cipher_env_t;
+typedef struct crypto_pk_env_t crypto_pk_env_t;
+typedef struct crypto_cipher_env_t crypto_cipher_env_t;
/* global state */
int crypto_global_init();
@@ -94,6 +79,7 @@ int crypto_cipher_set_iv(crypto_cipher_env_t *env, unsigned char *iv);
int crypto_cipher_set_key(crypto_cipher_env_t *env, unsigned char *key);
int crypto_cipher_encrypt_init_cipher(crypto_cipher_env_t *env);
int crypto_cipher_decrypt_init_cipher(crypto_cipher_env_t *env);
+unsigned char *crypto_cipher_get_key(crypto_cipher_env_t *env);
int crypto_cipher_encrypt(crypto_cipher_env_t *env, unsigned char *from, unsigned int fromlen, unsigned char *to);
int crypto_cipher_decrypt(crypto_cipher_env_t *env, unsigned char *from, unsigned int fromlen, unsigned char *to);