summaryrefslogtreecommitdiff
path: root/Python/random.c
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2013-11-20 11:46:18 +0100
committerChristian Heimes <christian@cheimes.de>2013-11-20 11:46:18 +0100
commit1f4288b872047826fa7bc66ab5fe785e61a095b1 (patch)
tree264dc2c60ccdd280c2c69e1927201472990a8ee2 /Python/random.c
parent38385a82df002518c5637c38f50d53b0d5e2dc2e (diff)
downloadcpython-1f4288b872047826fa7bc66ab5fe785e61a095b1.tar.gz
ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.
Python now uses SipHash24 on all major platforms.
Diffstat (limited to 'Python/random.c')
-rw-r--r--Python/random.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/Python/random.c b/Python/random.c
index d9c7e77109..de8e9e72c7 100644
--- a/Python/random.c
+++ b/Python/random.c
@@ -95,7 +95,7 @@ static int urandom_fd = -1;
/* Read size bytes from /dev/urandom into buffer.
Call Py_FatalError() on error. */
static void
-dev_urandom_noraise(char *buffer, Py_ssize_t size)
+dev_urandom_noraise(unsigned char *buffer, Py_ssize_t size)
{
int fd;
Py_ssize_t n;
@@ -249,8 +249,9 @@ void
_PyRandom_Init(void)
{
char *env;
- void *secret = &_Py_HashSecret;
+ unsigned char *secret = (unsigned char *)&_Py_HashSecret.uc;
Py_ssize_t secret_size = sizeof(_Py_HashSecret_t);
+ assert(secret_size == sizeof(_Py_HashSecret.uc));
if (_Py_HashSecret_Initialized)
return;
@@ -278,17 +279,17 @@ _PyRandom_Init(void)
memset(secret, 0, secret_size);
}
else {
- lcg_urandom(seed, (unsigned char*)secret, secret_size);
+ lcg_urandom(seed, secret, secret_size);
}
}
else {
#ifdef MS_WINDOWS
- (void)win32_urandom((unsigned char *)secret, secret_size, 0);
+ (void)win32_urandom(secret, secret_size, 0);
#else /* #ifdef MS_WINDOWS */
# ifdef __VMS
- vms_urandom((unsigned char *)secret, secret_size, 0);
+ vms_urandom(secret, secret_size, 0);
# else
- dev_urandom_noraise((char*)secret, secret_size);
+ dev_urandom_noraise(secret, secret_size);
# endif
#endif
}