diff options
Diffstat (limited to 'src/common/crypto.c')
-rw-r--r-- | src/common/crypto.c | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c index b66736edd3..9fcd17742c 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -1114,6 +1114,12 @@ crypto_strongest_rand_syscall(uint8_t *out, size_t out_len) { tor_assert(out_len <= MAX_STRONGEST_RAND_SIZE); + /* We only log at notice-level here because in the case that this function + * fails the crypto_strongest_rand_raw() caller will log with a warning-level + * message and let crypto_strongest_rand() error out and finally terminating + * Tor with an assertion error. + */ + #ifdef TOR_UNIT_TESTS if (break_strongest_rng_syscall) return -1; @@ -1126,21 +1132,21 @@ crypto_strongest_rand_syscall(uint8_t *out, size_t out_len) if (!provider_set) { if (!CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { - log_warn(LD_CRYPTO, "Can't get CryptoAPI provider [1]"); + log_notice(LD_CRYPTO, "Unable to set Windows CryptoAPI provider [1]."); return -1; } provider_set = 1; } if (!CryptGenRandom(provider, out_len, out)) { - log_warn(LD_CRYPTO, "Can't get entropy from CryptoAPI."); + log_notice(LD_CRYPTO, "Unable get entropy from the Windows CryptoAPI."); return -1; } return 0; #elif defined(__linux__) && defined(SYS_getrandom) - static int getrandom_works = 1; /* Be optimitic about our chances... */ + static int getrandom_works = 1; /* Be optimistic about our chances... */ - /* getrandom() isn't as straight foward as getentropy(), and has + /* getrandom() isn't as straightforward as getentropy(), and has * no glibc wrapper. * * As far as I can tell from getrandom(2) and the source code, the @@ -1153,7 +1159,7 @@ crypto_strongest_rand_syscall(uint8_t *out, size_t out_len) * * We optimistically assume that getrandom() is available and functional * because it is the way of the future, and 2 branch mispredicts pale in - * comparision to the overheads involved with failing to open + * comparison to the overheads involved with failing to open * /dev/srandom followed by opening and reading from /dev/urandom. */ if (PREDICT_LIKELY(getrandom_works)) { @@ -1174,13 +1180,15 @@ crypto_strongest_rand_syscall(uint8_t *out, size_t out_len) /* Useful log message for errno. */ if (errno == ENOSYS) { - log_warn(LD_CRYPTO, "Can't get entropy from getrandom()." - " You are running a version of Tor built to support" - " getrandom(), but the kernel doesn't implement this" - " function--probably because it is too old?"); + log_notice(LD_CRYPTO, "Can't get entropy from getrandom()." + " You are running a version of Tor built to support" + " getrandom(), but the kernel doesn't implement this" + " function--probably because it is too old?" + " Trying fallback method instead."); } else { - log_warn(LD_CRYPTO, "Can't get entropy from getrandom(): %s.", - strerror(errno)); + log_notice(LD_CRYPTO, "Can't get entropy from getrandom(): %s." + " Trying fallback method instead.", + strerror(errno)); } getrandom_works = 0; /* Don't bother trying again. */ @@ -1232,7 +1240,7 @@ crypto_strongest_rand_fallback(uint8_t *out, size_t out_len) size_t n; for (i = 0; filenames[i]; ++i) { - log_debug(LD_FS, "Considering %s for entropy", filenames[i]); + log_debug(LD_FS, "Considering %s as entropy source", filenames[i]); fd = open(sandbox_intern_string(filenames[i]), O_RDONLY, 0); if (fd<0) continue; log_info(LD_CRYPTO, "Reading entropy from \"%s\"", filenames[i]); @@ -1241,9 +1249,10 @@ crypto_strongest_rand_fallback(uint8_t *out, size_t out_len) if (n != out_len) { /* LCOV_EXCL_START * We can't make /dev/foorandom actually fail. */ - log_warn(LD_CRYPTO, - "Error reading from entropy source (read only %lu bytes).", - (unsigned long)n); + log_notice(LD_CRYPTO, + "Error reading from entropy source %s (read only %lu bytes).", + filenames[i], + (unsigned long)n); return -1; /* LCOV_EXCL_STOP */ } |