summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-06-06 20:02:09 +0000
committerNick Mathewson <nickm@torproject.org>2005-06-06 20:02:09 +0000
commit5420aed38ed6fd8e735a5be839174e16faeef9d1 (patch)
treee511e5a4d5bbbe31e24767e4dd3e561c1d4d30f0 /src
parentbaa10cbbfaa73c748b58794803c1c4d4e57d29ec (diff)
downloadtor-5420aed38ed6fd8e735a5be839174e16faeef9d1.tar.gz
tor-5420aed38ed6fd8e735a5be839174e16faeef9d1.zip
Possible bugfix for 151: backport candidate.
svn:r4318
Diffstat (limited to 'src')
-rw-r--r--src/common/crypto.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 7f86bfc372..ca50d877ae 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -1425,25 +1425,19 @@ int crypto_seed_rng(void)
char buf[DIGEST_LEN+1];
if (!provider_set) {
- if (!CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, CRYPT_MACHINE_KEYSET)) {
+ if (!CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
if (GetLastError() != NTE_BAD_KEYSET) {
log_fn(LOG_ERR,"Can't get CryptoAPI provider [1]");
return -1;
}
- /* Yes, we need to try it twice. */
- if (!CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL,
- CRYPT_MACHINE_KEYSET | CRYPT_NEWKEYSET)) {
- log_fn(LOG_ERR,"Can't get CryptoAPI provider [2], error code: %x", GetLastError());
- return -1;
- }
}
provider_set = 1;
}
- if (!CryptGenRandom(provider, DIGEST_LEN, buf)) {
+ if (!CryptGenRandom(provider, sizeof(buf), buf)) {
log_fn(LOG_ERR,"Can't get entropy from CryptoAPI.");
return -1;
}
- RAND_seed(buf, DIGEST_LEN);
+ RAND_seed(buf, sizeof(buf));
/* And add the current screen state to the entropy pool for
* good measure. */
RAND_screen();
@@ -1460,13 +1454,13 @@ int crypto_seed_rng(void)
fd = open(filenames[i], O_RDONLY, 0);
if (fd<0) continue;
log_fn(LOG_INFO, "Seeding RNG from %s", filenames[i]);
- n = read(fd, buf, DIGEST_LEN);
+ n = read_all(fd, buf, sizeof(buf), 0);
close(fd);
- if (n != DIGEST_LEN) {
+ if (n != sizeof(buf)) {
log_fn(LOG_WARN, "Error reading from entropy source");
return -1;
}
- RAND_seed(buf, DIGEST_LEN);
+ RAND_seed(buf, sizeof(buf));
return 0;
}