Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f8d7aec
Got initial API added
SammyK Feb 13, 2015
26e4ed2
Got mostly working. I think Hex is broken. Need to add int.
SammyK Feb 13, 2015
3c5fcac
Updated to use zend_string but getting memory leaks. Doh!
SammyK Feb 20, 2015
e96b077
Got random_bytes() working again.
SammyK Feb 20, 2015
aa0ca69
Fix random_int() checking size of wrong var.
SammyK Feb 20, 2015
b32e0d0
Got random_int() seemingly working thanks to @ircmaxell
SammyK Feb 20, 2015
2c659ed
Make maximum argument to random_int() optional with default to INT_MAX.
SammyK Feb 20, 2015
a1e6229
Remove random_hex(). *sadface*
SammyK Feb 20, 2015
bbc9198
Detect presence of /dev/arandom
lt Feb 21, 2015
7a99db6
Tidy up `php_random_bytes` and add /dev/arandom
lt Feb 21, 2015
3d413ad
Ensure random_int() uses a uniform distribution
lt Feb 22, 2015
513d5c9
Allow full integer range from random_int()
lt Feb 24, 2015
77f99cc
Use arc4random where present
lt Feb 24, 2015
7ef5754
Merge pull request #1 from lt/rand-bytes
SammyK Feb 24, 2015
766ce0c
Add tests
SammyK Feb 24, 2015
99e36d6
Fix wording in error message. Add check for max value.
SammyK Feb 24, 2015
c6fc391
Fix return types on error. Avoid a warning on BSD systems.
SammyK Feb 25, 2015
ab02b7b
Add fd caching
lt Mar 4, 2015
fd0570b
Merge remote-tracking branch 'leigh/rand-bytes' into rand-bytes
SammyK Mar 13, 2015
7ae4917
Fixes based on PR feedback
lt Mar 27, 2015
a67e42f
Changes based on feedback
lt Apr 9, 2015
f8a6d38
Normalized the return value for errors & updated tests.
SammyK Apr 10, 2015
2990341
Fix merge conflicts
SammyK Apr 10, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove random_hex(). *sadface*
  • Loading branch information
SammyK committed Feb 20, 2015
commit a1e62293b12f4440da55846fd50cae37b4c53265
6 changes: 0 additions & 6 deletions ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1902,12 +1902,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_random_bytes, 0, 0, 0)
ZEND_ARG_INFO(0, bytes)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_random_hex, 0, 0, 0)
ZEND_ARG_INFO(0, bytes)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_random_int, 0, 0, 0)
ZEND_ARG_INFO(0, min)
ZEND_ARG_INFO(0, max)
ZEND_END_ARG_INFO()
/* }}} */
Expand Down Expand Up @@ -2835,7 +2830,6 @@ const zend_function_entry basic_functions[] = { /* {{{ */
PHP_FE(mt_getrandmax, arginfo_mt_getrandmax)

PHP_FE(random_bytes, arginfo_random_bytes)
PHP_FE(random_hex, arginfo_random_hex)
PHP_FE(random_int, arginfo_random_int)

#if HAVE_GETSERVBYNAME
Expand Down
1 change: 0 additions & 1 deletion ext/standard/php_random.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#define PHP_RANDOM_H

PHP_FUNCTION(random_bytes);
PHP_FUNCTION(random_hex);
PHP_FUNCTION(random_int);
#endif

Expand Down
53 changes: 0 additions & 53 deletions ext/standard/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,6 @@ union rand_long_buffer {
long number;
};

/*
// Copy/pasted from string.c
static char hexconvtab[] = "0123456789abcdef";

// Copy/pasted from string.c
static void php_bin_to_hex(zend_string *old, const zend_long old_len, zend_string *hex)
{
zend_long i, j;

hex = zend_string_alloc(old_len * 2, 0); // @todo is this right?

for (i = j = 0; i < old_len; i++) {
hex->val[j++] = hexconvtab[old->val[i] >> 4];
hex->val[j++] = hexconvtab[old->val[i] & 15];
}

hex->val[j] = '\0';
}
*/

// Copy/pasted from mcrypt.c
static int php_random_bytes(char *bytes, zend_long size)
{
Expand Down Expand Up @@ -127,39 +107,6 @@ PHP_FUNCTION(random_bytes)
}
/* }}} */

/* {{{ proto string random_hex(int bytes)
Return an arbitrary length of pseudo-random bytes as hexadecimal string */
PHP_FUNCTION(random_hex)
{
/*
zend_long size;
zend_string *bytes;
zend_string *hex;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &size) == FAILURE) {
return;
}

if (size <= 0 || size >= INT_MAX) {
php_error_docref(NULL, E_WARNING, "Cannot genrate a random string with a size of less than 1 or greater than %d", INT_MAX);
RETURN_FALSE;
}

if (php_random_bytes(bytes, size) == FAILURE) {
return;
}

int hex_size = size * 2;

php_bin_to_hex(bytes, hex_size, hex);

zend_string_release(bytes);
*/

RETURN_STR("Foo!");
}
/* }}} */

/* {{{ proto int random_int(int maximum)
Return an arbitrary pseudo-random integer */
PHP_FUNCTION(random_int)
Expand Down