From dd82550a5e8dab342ab1c5d46c51b781fa6ab568 Mon Sep 17 00:00:00 2001 From: "teor (Tim Wilson-Brown)" Date: Mon, 16 Nov 2015 12:34:53 +1100 Subject: [PATCH 1/5] Add missing " in AccountingMax comment in or.h --- src/or/or.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/or/or.h b/src/or/or.h index 651d8bed0c..48dd0bdc10 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -3808,7 +3808,7 @@ typedef struct { * hibernate." */ /** How do we determine when our AccountingMax has been reached? * "max" for when in or out reaches AccountingMax - * "sum for when in plus out reaches AccountingMax */ + * "sum" for when in plus out reaches AccountingMax */ char *AccountingRule_option; enum { ACCT_MAX, ACCT_SUM } AccountingRule; From d3b7546753fbf37dfe2dc5dc774492c8d501409f Mon Sep 17 00:00:00 2001 From: "teor (Tim Wilson-Brown)" Date: Mon, 16 Nov 2015 16:27:11 +1100 Subject: [PATCH 2/5] Add a missing "if" in the comment on warn_nonlocal_controller_ports Also reflow all the lines of that comment so that they're under the maximum width. --- src/or/config.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/or/config.c b/src/or/config.c index 22039b46ef..311d838b74 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -5803,9 +5803,9 @@ warn_nonlocal_ext_orports(const smartlist_t *ports, const char *portname) } SMARTLIST_FOREACH_END(port); } -/** Given a list of port_cfg_t in ports, warn any controller port there - * is listening on any non-loopback address. If forbid_nonlocal is - * true, then emit a stronger warning and remove the port from the list. +/** Given a list of port_cfg_t in ports, warn if any controller port + * there is listening on any non-loopback address. If forbid_nonlocal + * is true, then emit a stronger warning and remove the port from the list. */ static void warn_nonlocal_controller_ports(smartlist_t *ports, unsigned forbid_nonlocal) From 604d3ee48d5a407e525045138d45d40943b0eff6 Mon Sep 17 00:00:00 2001 From: "teor (Tim Wilson-Brown)" Date: Mon, 23 Nov 2015 10:26:07 +1100 Subject: [PATCH 3/5] Comment only: crypto_seed_rng no longer has a "startup" parameter --- src/common/crypto.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/common/crypto.c b/src/common/crypto.c index 7b38568360..f5f9bbef0d 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -2335,8 +2335,7 @@ crypto_strongest_rand(uint8_t *out, size_t out_len) } /** Seed OpenSSL's random number generator with bytes from the operating - * system. startup should be true iff we have just started Tor and - * have not yet allocated a bunch of fds. Return 0 on success, -1 on failure. + * system. Return 0 on success, -1 on failure. */ int crypto_seed_rng(void) From 84d1373ba075febd5c362701a4dfee66ca9a5c19 Mon Sep 17 00:00:00 2001 From: "teor (Tim Wilson-Brown)" Date: Mon, 23 Nov 2015 18:59:11 +1100 Subject: [PATCH 4/5] Fix typo in comment on crypto_add_spaces_to_fp --- src/common/crypto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/crypto.c b/src/common/crypto.c index f5f9bbef0d..80345d430c 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -1332,7 +1332,7 @@ crypto_pk_get_all_digests(crypto_pk_t *pk, digests_t *digests_out) } /** Copy in to the outlen-byte buffer out, adding spaces - * every four spaces. */ + * every four characters. */ void crypto_add_spaces_to_fp(char *out, size_t outlen, const char *in) { From 5b2adfb3d431b8f39cbddbd530840cacbb9b5ce5 Mon Sep 17 00:00:00 2001 From: "teor (Tim Wilson-Brown)" Date: Mon, 23 Nov 2015 20:31:57 +1100 Subject: [PATCH 5/5] Fix comments to describe actual return values (crypto.c) --- src/common/crypto.c | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/common/crypto.c b/src/common/crypto.c index 80345d430c..a5a01ae382 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -432,7 +432,8 @@ crypto_pk_get_rsa_(crypto_pk_t *env) } /** used by tortls.c: get an equivalent EVP_PKEY* for a crypto_pk_t. Iff - * private is set, include the private-key portion of the key. */ + * private is set, include the private-key portion of the key. Return a valid + * pointer on success, and NULL on failure. */ MOCK_IMPL(EVP_PKEY *, crypto_pk_get_evp_pkey_,(crypto_pk_t *env, int private)) { @@ -656,7 +657,8 @@ crypto_pk_read_private_key_from_filename(crypto_pk_t *env, return 0; } -/** Helper function to implement crypto_pk_write_*_key_to_string. */ +/** Helper function to implement crypto_pk_write_*_key_to_string. Return 0 on + * success, -1 on failure. */ static int crypto_pk_write_key_to_string_impl(crypto_pk_t *env, char **dest, size_t *len, int is_public) @@ -897,7 +899,8 @@ crypto_pk_dup_key(crypto_pk_t *env) return env; } -/** Make a real honest-to-goodness copy of env, and return it. */ +/** Make a real honest-to-goodness copy of env, and return it. + * Returns NULL on failure. */ crypto_pk_t * crypto_pk_copy_full(crypto_pk_t *env) { @@ -1189,7 +1192,8 @@ crypto_pk_public_hybrid_encrypt(crypto_pk_t *env, return -1; } -/** Invert crypto_pk_public_hybrid_encrypt. */ +/** Invert crypto_pk_public_hybrid_encrypt. Returns the number of bytes + * written on success, -1 on failure. */ int crypto_pk_private_hybrid_decrypt(crypto_pk_t *env, char *to, @@ -1484,7 +1488,7 @@ crypto_cipher_get_key(crypto_cipher_t *env) /** Encrypt fromlen bytes from from using the cipher * env; on success, store the result to to and return 0. - * On failure, return -1. + * Does not check for failure. */ int crypto_cipher_encrypt(crypto_cipher_t *env, char *to, @@ -1503,7 +1507,7 @@ crypto_cipher_encrypt(crypto_cipher_t *env, char *to, /** Decrypt fromlen bytes from from using the cipher * env; on success, store the result to to and return 0. - * On failure, return -1. + * Does not check for failure. */ int crypto_cipher_decrypt(crypto_cipher_t *env, char *to, @@ -1519,7 +1523,7 @@ crypto_cipher_decrypt(crypto_cipher_t *env, char *to, } /** Encrypt len bytes on from using the cipher in env; - * on success, return 0. On failure, return -1. + * on success, return 0. Does not check for failure. */ int crypto_cipher_crypt_inplace(crypto_cipher_t *env, char *buf, size_t len) @@ -1591,7 +1595,7 @@ crypto_cipher_decrypt_with_iv(const char *key, /** Compute the SHA1 digest of the len bytes on data stored in * m. Write the DIGEST_LEN byte result into digest. - * Return 0 on success, -1 on failure. + * Return 0 on success, 1 on failure. */ int crypto_digest(char *digest, const char *m, size_t len) @@ -1603,7 +1607,7 @@ crypto_digest(char *digest, const char *m, size_t len) /** Compute a 256-bit digest of len bytes in data stored in m, * using the algorithm algorithm. Write the DIGEST_LEN256-byte result - * into digest. Return 0 on success, -1 on failure. */ + * into digest. Return 0 on success, 1 on failure. */ int crypto_digest256(char *digest, const char *m, size_t len, digest_algorithm_t algorithm) @@ -1836,7 +1840,7 @@ crypto_digest_smartlist_prefix(char *digest_out, size_t len_out, /** Compute the HMAC-SHA-256 of the msg_len bytes in msg, using * the key of length key_len. Store the DIGEST256_LEN-byte - * result in hmac_out. + * result in hmac_out. Asserts on failure. */ void crypto_hmac_sha256(char *hmac_out, @@ -1941,7 +1945,8 @@ init_dh_param(void) */ #define DH_PRIVATE_KEY_BITS 320 -/** Allocate and return a new DH object for a key exchange. +/** Allocate and return a new DH object for a key exchange. Returns NULL on + * failure. */ crypto_dh_t * crypto_dh_new(int dh_type) @@ -2196,7 +2201,7 @@ crypto_expand_key_material_TAP(const uint8_t *key_in, size_t key_in_len, * secret key material; the salt_in_len bytes at salt_in and the * info_in_len bytes in info_in_len are the algorithm's "salt" * and "info" parameters respectively. On success, write key_out_len - * bytes to key_out and return 0. On failure, return -1. + * bytes to key_out and return 0. Assert on failure. */ int crypto_expand_key_material_rfc5869_sha256( @@ -2280,7 +2285,7 @@ crypto_seed_weak_rng(tor_weak_rng_t *rng) } /** Try to get out_len bytes of the strongest entropy we can generate, - * storing it into out. + * storing it into out. Return -1 on success, 0 on failure. */ int crypto_strongest_rand(uint8_t *out, size_t out_len) @@ -2373,7 +2378,7 @@ crypto_rand, (char *to, size_t n)) } /** Write n bytes of strong random data to to. Return 0 on - * success, -1 on failure. Most callers will want crypto_rand instead. + * success, assert on failure. Most callers will want crypto_rand instead. */ int crypto_rand_unmocked(char *to, size_t n) @@ -2410,8 +2415,8 @@ crypto_rand_int(unsigned int max) } } -/** Return a pseudorandom integer, chosen uniformly from the values i - * such that min <= i < max. +/** Return a pseudorandom integer, chosen uniformly from the values i such + * that min <= i < max. * * min MUST be in range [0, max). * max MUST be in range (min, INT_MAX]. @@ -2488,7 +2493,7 @@ crypto_rand_double(void) /** Generate and return a new random hostname starting with prefix, * ending with suffix, and containing no fewer than * min_rand_len and no more than max_rand_len random base32 - * characters between. + * characters. Does not check for failure. * * Clip max_rand_len to MAX_DNS_LABEL_SIZE. **/ @@ -2670,7 +2675,7 @@ tor_set_openssl_thread_id(CRYPTO_THREADID *threadid) /** @{ */ /** Helper: Construct mutexes, and set callbacks to help OpenSSL handle being - * multithreaded. */ + * multithreaded. Returns 0. */ static int setup_openssl_threading(void) { @@ -2688,7 +2693,8 @@ setup_openssl_threading(void) return 0; } -/** Uninitialize the crypto library. Return 0 on success, -1 on failure. +/** Uninitialize the crypto library. Return 0 on success. Does not detect + * failure. */ int crypto_global_cleanup(void)