diff options
author | Nick Mathewson <nickm@torproject.org> | 2015-11-25 10:42:00 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-11-25 22:29:59 -0500 |
commit | ddcbe264745a0c10d80d8ad74125d23eb251662d (patch) | |
tree | b522f4302d71982a38ad0caf34b77b6c675103c2 /src/common | |
parent | 10fdee628552bca65ddb86b17e0b057628ad3703 (diff) | |
download | tor-ddcbe264745a0c10d80d8ad74125d23eb251662d.tar.gz tor-ddcbe264745a0c10d80d8ad74125d23eb251662d.zip |
Now that crypto_rand() cannot fail, it should return void.
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/crypto.c | 12 | ||||
-rw-r--r-- | src/common/crypto.h | 4 | ||||
-rw-r--r-- | src/common/crypto_curve25519.c | 3 | ||||
-rw-r--r-- | src/common/tortls.c | 3 |
4 files changed, 9 insertions, 13 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c index 1ca86ea8f3..9e27ad30c4 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -270,8 +270,7 @@ crypto_init_siphash_key(void) if (have_seeded_siphash) return 0; - if (crypto_rand((char*) &key, sizeof(key)) < 0) - return -1; + crypto_rand((char*) &key, sizeof(key)); siphash_set_global_key(&key); have_seeded_siphash = 1; return 0; @@ -2368,27 +2367,26 @@ crypto_seed_rng(void) /** Write <b>n</b> bytes of strong random data to <b>to</b>. Return 0 on * success, -1 on failure, with support for mocking for unit tests. */ -MOCK_IMPL(int, +MOCK_IMPL(void, crypto_rand, (char *to, size_t n)) { - return crypto_rand_unmocked(to, n); + crypto_rand_unmocked(to, n); } /** Write <b>n</b> bytes of strong random data to <b>to</b>. Return 0 on * success, -1 on failure. Most callers will want crypto_rand instead. */ -int +void crypto_rand_unmocked(char *to, size_t n) { int r; if (n == 0) - return 0; + return; tor_assert(n < INT_MAX); tor_assert(to); r = RAND_bytes((unsigned char*)to, (int)n); tor_assert(r >= 0); - return 0; } /** Return a pseudorandom integer, chosen uniformly from the values diff --git a/src/common/crypto.h b/src/common/crypto.h index 60f9e28902..3b471c2956 100644 --- a/src/common/crypto.h +++ b/src/common/crypto.h @@ -260,8 +260,8 @@ int crypto_expand_key_material_rfc5869_sha256( /* random numbers */ int crypto_seed_rng(void) ATTR_WUR; -MOCK_DECL(int,crypto_rand,(char *to, size_t n)); -int crypto_rand_unmocked(char *to, size_t n); +MOCK_DECL(void,crypto_rand,(char *to, size_t n)); +void crypto_rand_unmocked(char *to, size_t n); int crypto_strongest_rand(uint8_t *out, size_t out_len); int crypto_rand_int(unsigned int max); int crypto_rand_int_range(unsigned int min, unsigned int max); diff --git a/src/common/crypto_curve25519.c b/src/common/crypto_curve25519.c index ac0b08a552..00302a2ff0 100644 --- a/src/common/crypto_curve25519.c +++ b/src/common/crypto_curve25519.c @@ -113,8 +113,7 @@ curve25519_rand_seckey_bytes(uint8_t *out, int extra_strong) { uint8_t k_tmp[CURVE25519_SECKEY_LEN]; - if (crypto_rand((char*)out, CURVE25519_SECKEY_LEN) < 0) - return -1; + crypto_rand((char*)out, CURVE25519_SECKEY_LEN); if (extra_strong && !crypto_strongest_rand(k_tmp, CURVE25519_SECKEY_LEN)) { /* If they asked for extra-strong entropy and we have some, use it as an * HMAC key to improve not-so-good entropy rather than using it directly, diff --git a/src/common/tortls.c b/src/common/tortls.c index 536043e558..e3c6859828 100644 --- a/src/common/tortls.c +++ b/src/common/tortls.c @@ -601,8 +601,7 @@ tor_tls_create_certificate(crypto_pk_t *rsa, goto error; { /* our serial number is 8 random bytes. */ - if (crypto_rand((char *)serial_tmp, sizeof(serial_tmp)) < 0) - goto error; + crypto_rand((char *)serial_tmp, sizeof(serial_tmp)); if (!(serial_number = BN_bin2bn(serial_tmp, sizeof(serial_tmp), NULL))) goto error; if (!(BN_to_ASN1_INTEGER(serial_number, X509_get_serialNumber(x509)))) |