aboutsummaryrefslogtreecommitdiff
path: root/src/common/crypto.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-05-03 14:15:00 -0400
committerNick Mathewson <nickm@torproject.org>2016-05-16 08:25:59 -0400
commitd88656ec066f9fe856230f95ff76bf97f31ed46e (patch)
tree15c0879999973891e06161a9cddeb98636e17d11 /src/common/crypto.c
parentc3953348794f1689d3e2fe595f5d0045cb6c1a11 (diff)
downloadtor-d88656ec066f9fe856230f95ff76bf97f31ed46e.tar.gz
tor-d88656ec066f9fe856230f95ff76bf97f31ed46e.zip
Slight improvements to DH coverage.
Diffstat (limited to 'src/common/crypto.c')
-rw-r--r--src/common/crypto.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 37477c5701..71cab24d1d 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -2269,10 +2269,13 @@ crypto_dh_new(int dh_type)
return res;
err:
+ /* LCOV_EXCL_START
+ * This error condition is only reached when an allocation fails */
crypto_log_errors(LOG_WARN, "creating DH object");
if (res->dh) DH_free(res->dh); /* frees p and g too */
tor_free(res);
return NULL;
+ /* LCOV_EXCL_STOP */
}
/** Return a copy of <b>dh</b>, sharing its internal state. */
@@ -2304,10 +2307,15 @@ crypto_dh_generate_public(crypto_dh_t *dh)
{
again:
if (!DH_generate_key(dh->dh)) {
+ /* LCOV_EXCL_START
+ * To test this we would need some way to tell openssl to break DH. */
crypto_log_errors(LOG_WARN, "generating DH key");
return -1;
+ /* LCOV_EXCL_STOP */
}
if (tor_check_dh_key(LOG_WARN, dh->dh->pub_key)<0) {
+ /* LCOV_EXCL_START
+ * If this happens, then openssl's DH implementation is busted. */
log_warn(LD_CRYPTO, "Weird! Our own DH key was invalid. I guess once-in-"
"the-universe chances really do happen. Trying again.");
/* Free and clear the keys, so OpenSSL will actually try again. */
@@ -2315,6 +2323,7 @@ crypto_dh_generate_public(crypto_dh_t *dh)
BN_clear_free(dh->dh->priv_key);
dh->dh->pub_key = dh->dh->priv_key = NULL;
goto again;
+ /* LCOV_EXCL_STOP */
}
return 0;
}