com php-src: Refactor password_hash to use random_byt es internally to generate salts: ext/standard/passw ord.c

From: Date: Mon, 14 Dec 2015 08:05:16 +0000
Subject: com php-src: Refactor password_hash to use random_byt es internally to generate salts: ext/standard/passw ord.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-90259@lists.php.net to get a copy of this message
Commit: 02e85045dc2d37848037e120bba7638f803078f6 Author: Anthony Ferrara <ircmaxell@gmail.com> Sun, 18 Oct 2015 18:53:43 -0400 Committer: Anatol Belski <ab@php.net> Mon, 14 Dec 2015 09:05:16 +0100 Parents: 6a35e3b383567501509d8a30cb7f109cb127ffd5 Branches: PHP-7.0 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=02e85045dc2d37848037e120bba7638f803078f6 Log: Refactor password_hash to use random_bytes internally to generate salts Changed paths: M ext/standard/password.c Diff: diff --git a/ext/standard/password..c b/ext/standard/password.c index 859dbe9..6f0b31b 100644 --- a/ext/standard/password.c +++ b/ext/standard/password.c @@ -30,6 +30,7 @@ #include "base64.h" #include "zend_interfaces.h" #include "info.h" +#include "php_random.h" #if PHP_WIN32 #include "win32/winutil.h" @@ -123,37 +124,10 @@ static int php_password_make_salt(size_t length, char *ret) /* {{{ */ buffer = (char *) safe_emalloc(raw_length, 1, 1); -#if PHP_WIN32 - { - BYTE *iv_b = (BYTE *) buffer; - if (php_win32_get_random_bytes(iv_b, raw_length) == SUCCESS) { - buffer_valid = 1; - } - } -#else - { - int fd, n; - size_t read_bytes = 0; - fd = open("/dev/urandom", O_RDONLY); - if (fd >= 0) { - while (read_bytes < raw_length) { - n = read(fd, buffer + read_bytes, raw_length - read_bytes); - if (n < 0) { - break; - } - read_bytes += (size_t) n; - } - close(fd); - } - if (read_bytes >= raw_length) { - buffer_valid = 1; - } - } -#endif - if (!buffer_valid) { - for (i = 0; i < raw_length; i++) { - buffer[i] ^= (char) (255.0 * php_rand() / RAND_MAX); - } + if (FAILURE == php_random_bytes_silent(buffer, raw_length)) { + php_error_docref(NULL, E_WARNING, "Unable to generate salt"); + efree(buffer); + return FAILURE; } result = safe_emalloc(length, 1, 1);

« previous php.cvs (#90259) next »