diff options
author | Sascha Schumann <sas@php.net> | 2000-07-25 22:17:20 +0000 |
---|---|---|
committer | Sascha Schumann <sas@php.net> | 2000-07-25 22:17:20 +0000 |
commit | 79186d4fe9d5b211a3c7f2ff98b8694c2d54ec12 (patch) | |
tree | d05646f02c73f526d5bb5c9c2edecebfc957e0c0 /ext/mcrypt | |
parent | 19687ea1ed0fd31168c7097ea9b1a69b095ccc27 (diff) | |
download | php-git-79186d4fe9d5b211a3c7f2ff98b8694c2d54ec12.tar.gz |
Read from /dev/u?random until the buffer is filled.
Submitted by: Derick Rethans <d.rethans@jdimedia.nl>
Diffstat (limited to 'ext/mcrypt')
-rw-r--r-- | ext/mcrypt/mcrypt.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/ext/mcrypt/mcrypt.c b/ext/mcrypt/mcrypt.c index 9f18aaa832..c52a4291f6 100644 --- a/ext/mcrypt/mcrypt.c +++ b/ext/mcrypt/mcrypt.c @@ -205,6 +205,7 @@ PHP_FUNCTION(mcrypt_create_iv) if(source == RANDOM || source == URANDOM) { int fd; + size_t read_bytes = 0; fd = open(source == RANDOM ? "/dev/random" : "/dev/urandom", O_RDONLY); @@ -213,7 +214,13 @@ PHP_FUNCTION(mcrypt_create_iv) php_error(E_WARNING, "cannot open source device"); RETURN_FALSE; } - n = read(fd, iv, i); + while (read_bytes < i) { + n = read(fd, iv + read_bytes, i - read_bytes); + if (n < 0) + break; + read_bytes += n; + } + n = read_bytes; close(fd); } else { while(i) { |