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

[tor-commits] [tor/master] Move store_dynamic_prime() to crypto.c.



commit 2ef68980a778666bcc9b3b492c4acbd7af27fc28
Author: George Kadianakis <desnacked@xxxxxxxxx>
Date:   Thu Nov 24 22:32:10 2011 +0100

    Move store_dynamic_prime() to crypto.c.
---
 src/common/crypto.c |   40 ++++++++++++++++++++++++++++++++++++--
 src/common/crypto.h |    2 +-
 src/or/router.c     |   52 +++++---------------------------------------------
 src/or/router.h     |    1 -
 4 files changed, 44 insertions(+), 51 deletions(-)

diff --git a/src/common/crypto.c b/src/common/crypto.c
index 72c3dd7..a3c2923 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -1849,10 +1849,44 @@ crypto_generate_dynamic_prime(void)
   return dynamic_prime;
 }
 
-BIGNUM *
-crypto_get_tls_dh_prime(void)
+/** Store our dynamic prime to <b>fname</b> for future use. */
+int
+router_store_dynamic_prime(const char *fname)
 {
-  return dh_param_p_tls;
+  FILE *fp = NULL;
+  int retval = -1;
+  file_status_t fname_status = file_status(fname);
+
+  tor_assert(fname);
+
+  if (fname_status == FN_FILE) {
+    /* If the fname is a file, then the dynamic prime is already stored. */
+    retval = 0;
+    goto done;
+  } else if (fname_status != FN_NOENT) {
+    log_info(LD_GENERAL, "Dynamic prime filename is occupied.");
+    goto done;
+  }
+
+  tor_assert(fname_status == FN_NOENT);
+
+  if (!(fp = fopen(fname, "w"))) {
+    log_notice(LD_GENERAL, "Error while creating dynamic prime file.");
+    goto done;
+  }
+
+  if (BN_print_fp(fp, dh_param_p_tls) == 0) {
+    log_warn(LD_GENERAL, "Error while printing dynamic prime to file.");
+    goto done;
+  }
+
+  retval = 0;
+
+ done:
+  if (fp)
+    fclose(fp);
+
+  return retval;
 }
 
 /** Set the global TLS Diffie-Hellman modulus.
diff --git a/src/common/crypto.h b/src/common/crypto.h
index 5b753b8..8c99dd7 100644
--- a/src/common/crypto.h
+++ b/src/common/crypto.h
@@ -97,7 +97,7 @@ void crypto_free_pk_env(crypto_pk_env_t *env);
 
 void crypto_set_tls_dh_prime(int use_dynamic_primes,
                              BIGNUM *stored_dynamic_prime);
-BIGNUM * crypto_get_tls_dh_prime(void);
+int router_store_dynamic_prime(const char *fname);
 
 /* convenience function: wraps crypto_create_crypto_env, set_key, and init. */
 crypto_cipher_env_t *crypto_create_init_cipher(const char *key,
diff --git a/src/or/router.c b/src/or/router.c
index 6b38c79..dd5b9ff 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -485,46 +485,6 @@ v3_authority_check_key_expiry(void)
 }
 
 
-/** Store <b>dynamic_prime</b> to disk for future use. */
-int
-router_store_dynamic_prime(const BIGNUM *dynamic_prime)
-{
-  FILE *fp = NULL;
-  char *fname = get_datadir_fname2("keys", "dynamic_prime");
-  int retval = -1;
-  file_status_t fname_status = file_status(fname);
-
-  if (fname_status == FN_FILE) {
-    /* If the fname is a file, then the dynamic prime is already stored. */
-    retval = 0;
-    goto done;
-  } else if (fname_status != FN_NOENT) {
-    log_info(LD_GENERAL, "Dynamic prime filename is occupied.");
-    goto done;
-  }
-
-  tor_assert(fname_status == FN_NOENT);
-
-  if (!(fp = fopen(fname, "w"))) {
-    log_notice(LD_GENERAL, "Error while creating dynamic prime file.");
-    goto done;
-  }
-
-  if (BN_print_fp(fp, dynamic_prime) == 0) {
-    log_warn(LD_GENERAL, "Error while printing dynamic prime to file.");
-    goto done;
-  }
-
-  retval = 0;
-
- done:
-  if (fp)
-    fclose(fp);
-  tor_free(fname);
-
-  return retval;
-}
-
 /** Return the dynamic prime stored in the disk. If there is no
     dynamic prime stored in the disk, return NULL. */
 BIGNUM *
@@ -722,12 +682,12 @@ init_keys(void)
 
   /** 3b. If we use a dynamic prime, store it to disk. */
   if (get_options()->DynamicPrimes) {
-    BIGNUM *dynamic_prime = crypto_get_tls_dh_prime();
-    if (dynamic_prime) {
-      if (router_store_dynamic_prime(dynamic_prime) < 0)
-        log_notice(LD_GENERAL, "Failed while storing dynamic prime. "
-                   "Make sure your data directory is sane.");
-    }
+      const char *fname = get_datadir_fname2("keys", "dynamic_prime");
+      if (crypto_store_dynamic_prime(fname)) {
+          log_notice(LD_GENERAL, "Failed while storing dynamic prime. "
+                     "Make sure your data directory is sane.");
+      }
+      tor_free(fname);
   }
 
   /* 4. Build our router descriptor. */
diff --git a/src/or/router.h b/src/or/router.h
index 41ff139..a998335 100644
--- a/src/or/router.h
+++ b/src/or/router.h
@@ -30,7 +30,6 @@ crypto_pk_env_t *init_key_from_file(const char *fname, int generate,
                                     int severity);
 
 BIGNUM *router_get_stored_dynamic_prime(void);
-int router_store_dynamic_prime(const BIGNUM *dynamic_prime);
 
 void v3_authority_check_key_expiry(void);
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits