diff options
author | Bodo Möller <bodo@openssl.org> | 2000-01-24 10:03:24 +0000 |
---|---|---|
committer | Bodo Möller <bodo@openssl.org> | 2000-01-24 10:03:24 +0000 |
commit | 05ccd698b986131a217f85281977e767673b27d1 (patch) | |
tree | e1885e54a8cff160871b0a2a95e94437da6daccb /crypto/rand/randfile.c | |
parent | f13b93d3b46d5fa0a2b0c4ec9854a3962a73d198 (diff) |
RAND_load_file(..., -1) now means "read the complete file";
this is what we now use to read $RANDFILE / $HOME/.rnd.
(Previously, after 'cat'ting lots of stuff into .rnd
only the first MB would be looked at.)
Bugfix for apps/enc.c: Continue if RAND_pseudo_bytes returns 0
(only -1 is an error).
Diffstat (limited to 'crypto/rand/randfile.c')
-rw-r--r-- | crypto/rand/randfile.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/crypto/rand/randfile.c b/crypto/rand/randfile.c index 375c339e5c..cea9f54e73 100644 --- a/crypto/rand/randfile.c +++ b/crypto/rand/randfile.c @@ -82,6 +82,9 @@ int RAND_load_file(const char *file, long bytes) { + /* If bytes >= 0, read up to 'bytes' bytes. + * if bytes == -1, read complete file. */ + MS_STATIC unsigned char buf[BUFSIZE]; struct stat sb; int i,ret=0,n; @@ -93,20 +96,26 @@ int RAND_load_file(const char *file, long bytes) /* If the state fails, put some crap in anyway */ RAND_add(&sb,sizeof(sb),0); if (i < 0) return(0); - if (bytes <= 0) return(ret); + if (bytes == 0) return(ret); in=fopen(file,"rb"); if (in == NULL) goto err; for (;;) { - n=(bytes < BUFSIZE)?(int)bytes:BUFSIZE; + if (bytes > 0) + n = (bytes < BUFSIZE)?(int)bytes:BUFSIZE; + else + n = BUFSIZE; i=fread(buf,1,n,in); if (i <= 0) break; /* even if n != i, use the full array */ RAND_add(buf,n,i); ret+=i; - bytes-=n; - if (bytes <= 0) break; + if (bytes > 0) + { + bytes-=n; + if (bytes == 0) break; + } } fclose(in); memset(buf,0,BUFSIZE); |