diff options
| author | Stefan | 2010-04-13 11:49:00 +0200 |
|---|---|---|
| committer | Stefan | 2010-04-13 11:49:00 +0200 |
| commit | ba38594769bc6d4bf3dbb6ab8a666a165a77b8b4 (patch) | |
| tree | 949459fde9313d1b1e79bc65828cca5d6e9b90aa | |
| parent | 21f3250b0862db027bf08c95ff8aa8e2ad1ab790 (diff) | |
Improve random number generator seeding with extra juice from /dev/urandom
| -rw-r--r-- | execute.c | 14 |
1 files changed, 12 insertions, 2 deletions
| @@ -1315,6 +1315,7 @@ static void suhosin_gen_entropy(php_uint32 *seedbuf TSRMLS_DC) | |||
| 1315 | unsigned long stack_value = (unsigned long)&code_value; | 1315 | unsigned long stack_value = (unsigned long)&code_value; |
| 1316 | unsigned long heap_value = (unsigned long)SUHOSIN_G(r_state); | 1316 | unsigned long heap_value = (unsigned long)SUHOSIN_G(r_state); |
| 1317 | suhosin_SHA256_CTX context; | 1317 | suhosin_SHA256_CTX context; |
| 1318 | int fd; | ||
| 1318 | 1319 | ||
| 1319 | code_value ^= code_value >> 32; | 1320 | code_value ^= code_value >> 32; |
| 1320 | stack_value ^= stack_value >> 32; | 1321 | stack_value ^= stack_value >> 32; |
| @@ -1330,9 +1331,18 @@ static void suhosin_gen_entropy(php_uint32 *seedbuf TSRMLS_DC) | |||
| 1330 | seedbuf[4] = getpid(); | 1331 | seedbuf[4] = getpid(); |
| 1331 | #endif | 1332 | #endif |
| 1332 | seedbuf[5] = (php_uint32) 0x7fffffff * php_combined_lcg(TSRMLS_C); | 1333 | seedbuf[5] = (php_uint32) 0x7fffffff * php_combined_lcg(TSRMLS_C); |
| 1333 | 1334 | ||
| 1335 | #ifndef PHP_WIN32 | ||
| 1336 | fd = VCWD_OPEN("/dev/urandom", O_RDONLY); | ||
| 1337 | if (fd >= 0) { | ||
| 1338 | /* ignore error case - if urandom doesn't give us any/enough random bytes */ | ||
| 1339 | read(fd, &seedbuf[6], 2 * sizeof(php_uint32)); | ||
| 1340 | close(fd); | ||
| 1341 | } | ||
| 1342 | #endif | ||
| 1343 | |||
| 1334 | suhosin_SHA256Init(&context); | 1344 | suhosin_SHA256Init(&context); |
| 1335 | suhosin_SHA256Update(&context, (void *) seedbuf, sizeof(php_uint32) * 6); | 1345 | suhosin_SHA256Update(&context, (void *) seedbuf, sizeof(php_uint32) * 8); |
| 1336 | suhosin_SHA256Final(seedbuf, &context); | 1346 | suhosin_SHA256Final(seedbuf, &context); |
| 1337 | } | 1347 | } |
| 1338 | /* }}} */ | 1348 | /* }}} */ |
