aboutsummaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2012-12-25 22:43:01 -0500
committerNick Mathewson <nickm@torproject.org>2013-01-03 11:29:49 -0500
commitd3de0b91fb322c00d11857d89a8420af0d466e39 (patch)
tree1c33f8f2126db0ede938cbff1d5a111640cf167d /src/or
parent94cb7bd24d2ffda9038c267b3ee0837dd64ec903 (diff)
downloadtor-d3de0b91fb322c00d11857d89a8420af0d466e39.tar
tor-d3de0b91fb322c00d11857d89a8420af0d466e39.tar.gz
Check all crypto_rand return values for ntor.
Diffstat (limited to 'src/or')
-rw-r--r--src/or/onion_fast.c7
-rw-r--r--src/or/onion_ntor.c5
-rw-r--r--src/or/router.c6
3 files changed, 13 insertions, 5 deletions
diff --git a/src/or/onion_fast.c b/src/or/onion_fast.c
index eb9eceba8..c1a05233e 100644
--- a/src/or/onion_fast.c
+++ b/src/or/onion_fast.c
@@ -29,8 +29,11 @@ fast_onionskin_create(fast_handshake_state_t **handshake_state_out,
uint8_t *handshake_out)
{
fast_handshake_state_t *s;
- *handshake_state_out = s =tor_malloc(sizeof(fast_handshake_state_t));
- crypto_rand((char*)s->state, sizeof(s->state));
+ *handshake_state_out = s = tor_malloc(sizeof(fast_handshake_state_t));
+ if (crypto_rand((char*)s->state, sizeof(s->state)) < 0) {
+ tor_free(s);
+ return -1;
+ }
memcpy(handshake_out, s->state, DIGEST_LEN);
return 0;
}
diff --git a/src/or/onion_ntor.c b/src/or/onion_ntor.c
index b601d1ebb..58ab107f1 100644
--- a/src/or/onion_ntor.c
+++ b/src/or/onion_ntor.c
@@ -78,7 +78,10 @@ onion_skin_ntor_create(const uint8_t *router_id,
memcpy(state->router_id, router_id, DIGEST_LEN);
memcpy(&state->pubkey_B, router_key, sizeof(curve25519_public_key_t));
- curve25519_secret_key_generate(&state->seckey_x, 0);
+ if (curve25519_secret_key_generate(&state->seckey_x, 0) < 0) {
+ tor_free(state);
+ return -1;
+ }
curve25519_public_key_generate(&state->pubkey_X, &state->seckey_x);
op = onion_skin_out;
diff --git a/src/or/router.c b/src/or/router.c
index 961fd48d1..cc9702d1a 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -339,7 +339,8 @@ rotate_onion_key(void)
tor_free(fname_prev);
fname = get_datadir_fname2("keys", "secret_onion_key_ntor");
fname_prev = get_datadir_fname2("keys", "secret_onion_key_ntor.old");
- curve25519_keypair_generate(&new_curve25519_keypair, 1);
+ if (curve25519_keypair_generate(&new_curve25519_keypair, 1) < 0)
+ goto error;
if (file_status(fname) == FN_FILE) {
if (replace_file(fname, fname_prev))
goto error;
@@ -481,7 +482,8 @@ init_curve25519_keypair_from_file(curve25519_keypair_t *keys_out,
}
log_info(LD_GENERAL, "No key found in \"%s\"; generating fresh key.",
fname);
- curve25519_keypair_generate(keys_out, 1);
+ if (curve25519_keypair_generate(keys_out, 1) < 0)
+ goto error;
if (curve25519_keypair_write_to_file(keys_out, fname, tag)<0) {
log(severity, LD_FS,
"Couldn't write generated key to \"%s\".", fname);