aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Monnerat <pm@datasphere.ch>2013-07-15 16:55:30 +0200
committerPatrick Monnerat <pm@datasphere.ch>2013-07-15 16:55:30 +0200
commit695931cf8e38da79a987ac65dc2408c7c20612c1 (patch)
treebaa4fab47fcffa2c05e99baddc7edccc88b3f9bf
parent964a7600b98dbdd4f03205b17ef93ef7850186fe (diff)
parentd4492f955d1fe915f0ac662772ad43c04682986d (diff)
Merge branch 'master' of github.com:bagder/curl
Merge for resync
-rw-r--r--lib/sslgen.c60
1 files changed, 29 insertions, 31 deletions
diff --git a/lib/sslgen.c b/lib/sslgen.c
index a633b0c5d..dee06e89c 100644
--- a/lib/sslgen.c
+++ b/lib/sslgen.c
@@ -187,45 +187,43 @@ unsigned int Curl_rand(struct SessionHandle *data)
{
unsigned int r;
static unsigned int randseed;
- static bool seeded;
+ static bool seeded = FALSE;
-#ifdef have_curlssl_random
- if(!data) {
+#ifndef have_curlssl_random
+ (void)data;
+#else
+ if(data) {
+ Curl_ssl_random(data, (unsigned char *)&r, sizeof(r));
+ return r;
+ }
#endif
- if(!seeded) {
-
#ifdef RANDOM_FILE
- /* if there's a random file to read a seed from, use it */
- int fd = open(RANDOM_FILE, O_RDONLY);
- seeded = TRUE;
- if(fd > -1) {
- /* read random data into the randseed variable */
- read(fd, &randseed, sizeof(randseed));
- close(fd);
- }
- else
-#endif /* RANDOM_FILE */
- {
- struct timeval now = curlx_tvnow();
- randseed += (unsigned int) now.tv_usec + (unsigned int)now.tv_sec;
- randseed = randseed * 1103515245 + 12345;
- randseed = randseed * 1103515245 + 12345;
- randseed = randseed * 1103515245 + 12345;
+ if(!seeded) {
+ /* if there's a random file to read a seed from, use it */
+ int fd = open(RANDOM_FILE, O_RDONLY);
+ if(fd > -1) {
+ /* read random data into the randseed variable */
+ ssize_t nread = read(fd, &randseed, sizeof(randseed));
+ if(nread == sizeof(randseed))
seeded = TRUE;
- }
+ close(fd);
}
- /* Return an unsigned 32-bit pseudo-random number. */
- r = randseed = randseed * 1103515245 + 12345;
- return (r << 16) | ((r >> 16) & 0xFFFF);
-
-#ifdef have_curlssl_random
- }
- else {
- Curl_ssl_random(data, (unsigned char *)&r, sizeof(r));
- return r;
}
#endif
+
+ if(!seeded) {
+ struct timeval now = curlx_tvnow();
+ randseed += (unsigned int)now.tv_usec + (unsigned int)now.tv_sec;
+ randseed = randseed * 1103515245 + 12345;
+ randseed = randseed * 1103515245 + 12345;
+ randseed = randseed * 1103515245 + 12345;
+ seeded = TRUE;
+ }
+
+ /* Return an unsigned 32-bit pseudo-random number. */
+ r = randseed = randseed * 1103515245 + 12345;
+ return (r << 16) | ((r >> 16) & 0xFFFF);
}
#ifdef USE_SSL