[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Make crypto structures private to crypto.c



Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv20645/src/common

Modified Files:
	crypto.c crypto.h 
Log Message:
Make crypto structures private to crypto.c

Index: crypto.c
===================================================================
RCS file: /home/or/cvsroot/src/common/crypto.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- crypto.c	4 Sep 2003 16:05:08 -0000	1.31
+++ crypto.c	10 Sep 2003 00:47:24 -0000	1.32
@@ -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 @@
   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)
@@ -615,6 +639,11 @@
   memcpy((void*)env->key, (void*)key, key_len);
   
   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)

Index: crypto.h
===================================================================
RCS file: /home/or/cvsroot/src/common/crypto.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- crypto.h	4 Sep 2003 16:05:08 -0000	1.15
+++ crypto.h	10 Sep 2003 00:47:24 -0000	1.16
@@ -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_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);