summaryrefslogtreecommitdiff
path: root/Python/random.c
AgeCommit message (Collapse)AuthorLines
2017-01-07Issue #29157: Prefer getrandom() over getentropy()Victor Stinner-87/+187
* dev_urandom() now calls py_getentropy(). Prepare the fallback to support getentropy() failure and falls back on reading from /dev/urandom. * Simplify dev_urandom(). pyurandom() is now responsible to call getentropy() or getrandom(). Enhance also dev_urandom() and pyurandom() documentation. * getrandom() is now preferred over getentropy(). The glibc 2.24 now implements getentropy() on Linux using the getrandom() syscall. But getentropy() doesn't support non-blocking mode. Since getrandom() is tried first, it's not more needed to explicitly exclude getentropy() on Solaris. Replace: "if defined(HAVE_GETENTROPY) && !defined(sun)" with "if defined(HAVE_GETENTROPY)" * Enhance py_getrandom() documentation. py_getentropy() now supports ENOSYS, EPERM & EINTR
2017-01-01merge 3.5 (#29057)Benjamin Peterson-1/+1
2017-01-01only include sys/random.h if it seems like it might have something useful ↵Benjamin Peterson-1/+1
(#29057)
2016-12-19merge 3.5 (#28932)Benjamin Peterson-1/+1
2016-12-19add a specific configure check for sys/random.h (closes #28932)Benjamin Peterson-1/+1
2016-11-12Issue #28676: merge from 3.5Ned Deily-2/+3
2016-11-12Issue #28676: Prevent missing 'getentropy' declaration warning on macOS.Ned Deily-2/+3
Patch by Gareth Rees.
2016-09-20(Merge 3.5) Catch EPERM error in py_getrandom()Victor Stinner-8/+11
Issue #27955: Fallback on reading /dev/urandom device when the getrandom() syscall fails with EPERM, for example when blocked by SECCOMP.
2016-09-20Catch EPERM error in py_getrandom()Victor Stinner-7/+8
Issue #27955: Fallback on reading /dev/urandom device when the getrandom() syscall fails with EPERM, for example when blocked by SECCOMP.
2016-09-20Cleanup random.cVictor Stinner-28/+53
Issue #27955: modify py_getrnadom() and dev_urandom() * Add comments from Python 3.7 * PEP 7 style: add {...}
2016-09-06os.urandom() now blocks on LinuxVictor Stinner-30/+45
Issue #27776: The os.urandom() function does now block on Linux 3.17 and newer until the system urandom entropy pool is initialized to increase the security. This change is part of the PEP 524.
2016-08-16Issue #27776: dev_urandom(raise=0) now closes the file descriptor on errorVictor Stinner-0/+1
2016-08-16Issue #27776: Cleanup random.cVictor Stinner-121/+110
Merge dev_urandom_python() and dev_urandom_noraise() functions to reduce code duplication.
2016-08-16Issue #27776: _PyRandom_Init() doesn't call PyErr_CheckSignals() anymoreVictor Stinner-3/+6
Modify py_getrandom() to not call PyErr_CheckSignals() if raise is zero. _PyRandom_Init() is called very early in the Python initialization, so it's safer to not call PyErr_CheckSignals().
2016-08-16Issue #27776: Cleanup random.cVictor Stinner-55/+74
* Add pyurandom() helper function to factorize the code * don't call Py_FatalError() in helper functions, but only in _PyRandom_Init() if pyurandom() failed, to uniformize the code
2016-07-29Issue #17596: MINGW: add wincrypt.h in Python/random.cMartin Panter-0/+3
Based on patch by Roumen Petrov.
2016-06-17Merge 3.5Victor Stinner-2/+2
2016-06-16py_getrandom(): use long type for the syscall() resultVictor Stinner-2/+2
Issue #27278. It should fix a conversion warning. In practice, the Linux kernel doesn't return more than 32 MB per call to the getrandom() syscall.
2016-06-14Merge 3.5Victor Stinner-1/+1
2016-06-14cleanup random.cVictor Stinner-1/+1
Casting Py_ssize_t to Py_ssize_t is useless.
2016-06-14Merge 3.5 (os.urandom, issue #27278)Victor Stinner-1/+1
2016-06-14Fix os.urandom() using getrandom() on LinuxVictor Stinner-1/+1
Issue #27278: Fix os.urandom() implementation using getrandom() on Linux. Truncate size to INT_MAX and loop until we collected enough random bytes, instead of casting a directly Py_ssize_t to int.
2016-06-10Merge comment fix from 3.5Martin Panter-2/+2
2016-06-10Fix typo and move comment to appropriate conditionMartin Panter-2/+2
2016-06-08py_getrandom(): use char* instead of void* for the destinationVictor Stinner-5/+8
Fix a "gcc -pedantic" warning on "buffer += n" because buffer type is void*.
2016-06-07Merge 3.5 (os.urandom)Victor Stinner-3/+21
2016-06-07os.urandom() doesn't block on Linux anymoreVictor Stinner-3/+21
Issue #26839: On Linux, os.urandom() now calls getrandom() with GRND_NONBLOCK to fall back on reading /dev/urandom if the urandom entropy pool is not initialized yet. Patch written by Colm Buckley.
2016-04-12Merge 3.5 (os.urandom)Victor Stinner-5/+12
2016-04-12Fix os.urandom() on Solaris 11.3Victor Stinner-5/+12
Issue #26735: Fix os.urandom() on Solaris 11.3 and newer when reading more than 1,024 bytes: call getrandom() multiple times with a limit of 1024 bytes per call.
2015-11-07Issue #25558: Use compile-time asserts.Serhiy Storchaka-1/+1
2015-10-01Merge 3.4 (os.urandom)Victor Stinner-0/+2
2015-10-01Issue #25003: os.urandom() doesn't use getentropy() on Solaris becauseVictor Stinner-4/+8
getentropy() is blocking, whereas os.urandom() should not block. getentropy() is supported since Solaris 11.3.
2015-10-01Issue #25003: On Solaris 11.3 or newer, os.urandom() now uses the getrandom()Victor Stinner-15/+34
function instead of the getentropy() function. The getentropy() function is blocking to generate very good quality entropy, os.urandom() doesn't need such high-quality entropy.
2015-07-30py_getrandom(): getrandom() *can* return EINTRVictor Stinner-1/+0
See the latest version of getrandom() manual page: http://man7.org/linux/man-pages/man2/getrandom.2.html#NOTES The behavior when a call to getrandom() that is blocked while reading from /dev/urandom is interrupted by a signal handler depends on the initialization state of the entropy buffer and on the request size, buflen. If the entropy is not yet initialized, then the call will fail with the EINTR error. If the entropy pool has been initialized and the request size is large (buflen > 256), the call either succeeds, returning a partially filled buffer, or fails with the error EINTR. If the entropy pool has been initialized and the request size is small (buflen <= 256), then getrandom() will not fail with EINTR. Instead, it will return all of the bytes that have been requested. Note: py_getrandom() calls getrandom() with flags=0.
2015-03-30(Merge 3.4) Issue #22585: os.urandom() now releases the GIL when theVictor Stinner-6/+14
getentropy() is used (OpenBSD 5.6+).
2015-03-30Issue #22585: os.urandom() now releases the GIL when the getentropy() is usedVictor Stinner-6/+14
(OpenBSD 5.6+).
2015-03-30Issue #22181: os.urandom() now releases the GIL when the getrandom()Victor Stinner-2/+11
implementation is used.
2015-03-30Issue #23752: _Py_fstat() is now responsible to raise the Python exceptionVictor Stinner-2/+1
Add _Py_fstat_noraise() function when a Python exception is not welcome.
2015-03-19Issue #23707: On UNIX, os.urandom() now calls the Python signal handler whenVictor Stinner-19/+11
read() is interrupted by a signal. dev_urandom_python() now calls _Py_read() helper instead of calling directly read().
2015-03-19Issue #22181: Fix dev_urandom_noraise(), try calling py_getrandom() beforeVictor Stinner-4/+4
opening /dev/urandom.
2015-03-19Issue #22181: The availability of the getrandom() is now checked in configure,Victor Stinner-8/+5
and stored in pyconfig.h as the new HAVE_GETRANDOM_SYSCALL define. Fix os.urandom() tests using file descriptors if os.urandom() uses getrandom().
2015-03-18Issue #22181: On Linux, os.urandom() now uses the new getrandom() syscall ifVictor Stinner-6/+84
available, syscall introduced in the Linux kernel 3.17. It is more reliable and more secure, because it avoids the need of a file descriptor and waits until the kernel has enough entropy.
2015-03-18Issue #23694: Enhance _Py_open(), it now raises exceptionsVictor Stinner-7/+3
* _Py_open() now raises exceptions on error. If open() fails, it raises an OSError with the filename. * _Py_open() now releases the GIL while calling open() * Add _Py_open_noraise() when _Py_open() cannot be used because the GIL is not held
2015-02-21Issue #23152: Implement _Py_fstat() to support files larger than 2 GB on ↵Steve Dower-3/+3
Windows. fstat() may fail with EOVERFLOW on files larger than 2 GB because the file size type is an signed 32-bit integer.
2014-12-21Issue #22585: On OpenBSD 5.6 and newer, os.urandom() now calls getentropy(),Victor Stinner-7/+41
instead of reading /dev/urandom, to get pseudo-random bytes.
2014-12-21Issue #22585: On OpenBSD 5.6 and newer, os.urandom() now calls getentropy(),Victor Stinner-4/+35
instead of reading /dev/urandom, to get pseudo-random bytes.
2014-12-01Removed duplicated words in in comments and docs.Serhiy Storchaka-1/+1
2014-12-01Removed duplicated words in in comments and docs.Serhiy Storchaka-1/+1
2014-05-06Issue21393 Use CryptReleaseContext to release Crypt handle on WindowsTim Golden-1/+1
2014-05-02Issue #21393: random.c: on Windows, close the hCryptProv handle at exitVictor Stinner-3/+6