diff options
author | George Kadianakis <desnacked@gmail.com> | 2011-11-24 22:32:10 +0100 |
---|---|---|
committer | George Kadianakis <desnacked@gmail.com> | 2011-11-24 22:32:10 +0100 |
commit | 2ef68980a778666bcc9b3b492c4acbd7af27fc28 (patch) | |
tree | 8331554dd3964726504e2a165c9113e512d72047 /src/common | |
parent | cabb8e54c7240aeb20ccfa745d75c5ad4063edb3 (diff) | |
download | tor-2ef68980a778666bcc9b3b492c4acbd7af27fc28.tar.gz tor-2ef68980a778666bcc9b3b492c4acbd7af27fc28.zip |
Move store_dynamic_prime() to crypto.c.
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/crypto.c | 40 | ||||
-rw-r--r-- | src/common/crypto.h | 2 |
2 files changed, 38 insertions, 4 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c index 72c3dd7c12..a3c292324b 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 5b753b83d6..8c99dd7a37 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, |