Commit Graph

22 Commits

Author SHA1 Message Date
Xinchen Hui
4bebcb84ad Fixed condition check 2017-04-10 14:47:24 +08:00
Benjamin Robin
513582814b Fixed bug #74105
If getrandom syscall is unavailable (ENOSYS), try to fallback on
/dev/urandom.
2017-02-17 18:42:35 +01:00
Leigh
14c72cc582 Fix check for linux getrandom syscall 2017-01-09 23:29:07 +01:00
Sammy Kaye Powers
478f119ab9 Update copyright headers to 2017 2017-01-04 11:14:55 -06:00
Leigh
c3361f16c7 Add php_random_int internal API
This is the internal API compliment to `php_random_bytes`
2016-10-20 10:18:07 +01:00
Lior Kaplan
2eb1f38d24 Happy new year (Update copyright to 2016) 2016-01-01 20:03:16 +02:00
Scott
c0ce2281bc Update random.c
Supersedes #1589
2015-12-08 13:16:48 +01:00
Anthony Ferrara
908f67b1d4 Expose php_random_bytes as a first-class API within internals
This also defines two macros: php_random_bytes_throw and php_random_bytes_silent depending on use case which will throw exceptions or not respectively
2015-12-08 13:12:45 +01:00
Scott
00e3b7614e Update random.c
Ref: beb826f6fd
2015-12-01 10:33:33 +08:00
Leigh
faf835be2b Use arc4random on OpenBSD 5.5+ and NetBSD 7+
As discussed with @weltling, keeping arc4random on the condition that the OS has a solid implementation of it
2015-10-30 19:08:20 +00:00
Leigh
a53510239f Remove arc4random
There has been a lot of discussion around whether arc4random should be included. Given how many different impementations of it are in the wild, we can't guarantee a secure implementation on all platforms.
2015-10-26 20:40:28 +00:00
Scott
63617a678f Fixed bug #70641 (Random_* - Better compatibility on Linux distros)
See:
* https://bugs.php.net/bug.php?id=70641
* https://github.com/php/php-src/pull/1513#issuecomment-145571829
2015-10-06 01:03:04 +02:00
Scott
694b9af5b6 Remove makedev() check. 2015-09-29 09:14:30 +02:00
Scott
46aa628605 Different error message if makedev check fails 2015-09-29 09:14:29 +02:00
Scott
6554f721f7 Add support for getrandom(2), add type check on file descriptor
Fix to_read, throw exception if syscall fails

Fixes thanks to feedback from sarnold at ##crypto on freenode

Correction on error conditions

Remove dead code (thanks @defuse)

It turns out getrandom can take >256, getentropy refuses.

Better semantics

Thanks @defuse for catching my silly mistake here

Cast to size_t to be explicit

Let's simplify the logic a bit

Let's be consistent; define everything before we do any logic

Continuously check that the file descriptor is still a valid one

Add device type check on fd initialization
2015-09-29 09:14:28 +02:00
Bob Weinand
c12917aa45 Merged RFC Random Functions Throwing Exceptions in PHP 7
Squashes commits from PR #1397

commit cd5dcc8c9eb43603d908abcea69c9e18df0f2ed5
Author: SammyK <sammyk@sammykmedia.com>
Date:   Tue Sep 8 13:53:42 2015 -0500

    Add min max samezies

commit b719499218a4e84efecd4dc1d4235d16142c9793
Author: SammyK <sammyk@sammykmedia.com>
Date:   Wed Sep 2 07:00:25 2015 -0500

    Make random_bytes() throw Error when $length <= 0 and random_int() throw Error when $min > $max

commit 0cca557291c278716ec4b00b32fc2bdc1c1c8848
Author: SammyK <sammyk@sammykmedia.com>
Date:   Wed Sep 2 06:55:59 2015 -0500

    Make random_*() functions throw Error exception when random bytes cannot be obtained

commit 998c7f1e209123605b41139e8d9093075ce16bd6
Author: SammyK <sammyk@sammykmedia.com>
Date:   Wed Sep 2 06:41:20 2015 -0500

    Make random_*() functions throw TypeError when zend_parse_parameters fails

commit 99d305c18820ff55d82d952777cbcdf1cf0158be
Author: SammyK <sammyk@sammykmedia.com>
Date:   Mon Jul 6 19:50:47 2015 -0500

    Make exceptions less specific

commit b042dfab290713366741a663a420cf12bf802f39
Author: SammyK <sammyk@sammykmedia.com>
Date:   Mon Jul 6 17:20:13 2015 -0500

    Upgrade warnings to RuntimeExceptions
2015-09-09 01:00:29 +02:00
Anatol Belski
cbcacbb2da improve condition
read() == 0 is EOL
2015-08-12 10:20:26 +02:00
Dmitry Stogov
4a2e40bb86 Use ZSTR_ API to access zend_string elements (this is just renaming without semantick changes). 2015-06-30 04:05:24 +03:00
Lauri Kenttä
cf7e5357a4 random_int: Fix power of two check.
(x & ~x) is always 0.
((x & (~x + 1)) != x) works.
((x & (x - 1)) != 0) works too.
2015-05-10 13:00:45 +02:00
SammyK
dd2692621d Add tests for CSPRNG, fix C99 comments
Also replace one return; with RETURN_FALSE; for consistency.
2015-05-09 22:29:26 +02:00
Leigh
5f1b83e9bb Improve CSPRNG implementation 2015-05-09 21:57:59 +02:00
SammyK
bc54d139aa Initial implementation for CSPRNG API 2015-05-09 21:57:50 +02:00