File tree Expand file tree Collapse file tree 1 file changed +5
-31
lines changed Expand file tree Collapse file tree 1 file changed +5
-31
lines changed Original file line number Diff line number Diff line change 30
30
#include "base64.h"
31
31
#include "zend_interfaces.h"
32
32
#include "info.h"
33
+ #include "php_random.h"
33
34
34
35
#if PHP_WIN32
35
36
#include "win32/winutil.h"
@@ -123,37 +124,10 @@ static int php_password_make_salt(size_t length, char *ret) /* {{{ */
123
124
124
125
buffer = (char * ) safe_emalloc (raw_length , 1 , 1 );
125
126
126
- #if PHP_WIN32
127
- {
128
- BYTE * iv_b = (BYTE * ) buffer ;
129
- if (php_win32_get_random_bytes (iv_b , raw_length ) == SUCCESS ) {
130
- buffer_valid = 1 ;
131
- }
132
- }
133
- #else
134
- {
135
- int fd , n ;
136
- size_t read_bytes = 0 ;
137
- fd = open ("/dev/urandom" , O_RDONLY );
138
- if (fd >= 0 ) {
139
- while (read_bytes < raw_length ) {
140
- n = read (fd , buffer + read_bytes , raw_length - read_bytes );
141
- if (n < 0 ) {
142
- break ;
143
- }
144
- read_bytes += (size_t ) n ;
145
- }
146
- close (fd );
147
- }
148
- if (read_bytes >= raw_length ) {
149
- buffer_valid = 1 ;
150
- }
151
- }
152
- #endif
153
- if (!buffer_valid ) {
154
- for (i = 0 ; i < raw_length ; i ++ ) {
155
- buffer [i ] ^= (char ) (255.0 * php_rand () / RAND_MAX );
156
- }
127
+ if (FAILURE == php_random_bytes_silent (buffer , raw_length )) {
128
+ php_error_docref (NULL , E_WARNING , "Unable to generate salt" );
129
+ efree (buffer );
130
+ return FAILURE ;
157
131
}
158
132
159
133
result = safe_emalloc (length , 1 , 1 );
You can’t perform that action at this time.
0 commit comments