summaryrefslogtreecommitdiffstats
path: root/Python/random.c
Commit message (Collapse)AuthorAgeFilesLines
* os.urandom() now blocks on LinuxVictor Stinner2016-09-061-31/+46
| | | | | | | 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.
* Issue #27776: dev_urandom(raise=0) now closes the file descriptor on errorVictor Stinner2016-08-161-0/+1
|
* Issue #27776: Cleanup random.cVictor Stinner2016-08-161-121/+110
| | | | | Merge dev_urandom_python() and dev_urandom_noraise() functions to reduce code duplication.
* Issue #27776: _PyRandom_Init() doesn't call PyErr_CheckSignals() anymoreVictor Stinner2016-08-161-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().
* Issue #27776: Cleanup random.cVictor Stinner2016-08-161-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
* Issue #17596: MINGW: add wincrypt.h in Python/random.cMartin Panter2016-07-291-0/+3
| | | | Based on patch by Roumen Petrov.
* Merge 3.5Victor Stinner2016-06-161-2/+2
|\
| * py_getrandom(): use long type for the syscall() resultVictor Stinner2016-06-161-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.
* | Merge 3.5Victor Stinner2016-06-141-1/+1
|\ \ | |/
| * cleanup random.cVictor Stinner2016-06-141-1/+1
| | | | | | | | Casting Py_ssize_t to Py_ssize_t is useless.
* | Merge 3.5 (os.urandom, issue #27278)Victor Stinner2016-06-141-1/+1
|\ \ | |/
| * Fix os.urandom() using getrandom() on LinuxVictor Stinner2016-06-141-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.
* | Merge comment fix from 3.5Martin Panter2016-06-101-2/+2
|\ \ | |/
| * Fix typo and move comment to appropriate conditionMartin Panter2016-06-101-2/+2
| |
* | py_getrandom(): use char* instead of void* for the destinationVictor Stinner2016-06-081-5/+8
| | | | | | | | Fix a "gcc -pedantic" warning on "buffer += n" because buffer type is void*.
* | Merge 3.5 (os.urandom)Victor Stinner2016-06-071-3/+21
|\ \ | |/
| * os.urandom() doesn't block on Linux anymoreVictor Stinner2016-06-071-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.
* | Merge 3.5 (os.urandom)Victor Stinner2016-04-121-5/+12
|\ \ | |/
| * Fix os.urandom() on Solaris 11.3Victor Stinner2016-04-121-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.
* | Issue #25558: Use compile-time asserts.Serhiy Storchaka2015-11-071-1/+1
|/
* Merge 3.4 (os.urandom)Victor Stinner2015-10-011-0/+2
|\
| * Issue #25003: os.urandom() doesn't use getentropy() on Solaris becauseVictor Stinner2015-10-011-4/+8
| | | | | | | | | | getentropy() is blocking, whereas os.urandom() should not block. getentropy() is supported since Solaris 11.3.
* | Issue #25003: On Solaris 11.3 or newer, os.urandom() now uses the getrandom()Victor Stinner2015-10-011-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.
* | py_getrandom(): getrandom() *can* return EINTRVictor Stinner2015-07-301-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.
* | (Merge 3.4) Issue #22585: os.urandom() now releases the GIL when theVictor Stinner2015-03-301-6/+14
|\ \ | |/ | | | | getentropy() is used (OpenBSD 5.6+).
| * Issue #22585: os.urandom() now releases the GIL when the getentropy() is usedVictor Stinner2015-03-301-6/+14
| | | | | | | | (OpenBSD 5.6+).
| * Issue #22585: On OpenBSD 5.6 and newer, os.urandom() now calls getentropy(),Victor Stinner2014-12-211-7/+41
| | | | | | | | instead of reading /dev/urandom, to get pseudo-random bytes.
* | Issue #22181: os.urandom() now releases the GIL when the getrandom()Victor Stinner2015-03-301-2/+11
| | | | | | | | implementation is used.
* | Issue #23752: _Py_fstat() is now responsible to raise the Python exceptionVictor Stinner2015-03-301-2/+1
| | | | | | | | Add _Py_fstat_noraise() function when a Python exception is not welcome.
* | Issue #23707: On UNIX, os.urandom() now calls the Python signal handler whenVictor Stinner2015-03-191-19/+11
| | | | | | | | | | | | | | read() is interrupted by a signal. dev_urandom_python() now calls _Py_read() helper instead of calling directly read().
* | Issue #22181: Fix dev_urandom_noraise(), try calling py_getrandom() beforeVictor Stinner2015-03-191-4/+4
| | | | | | | | opening /dev/urandom.
* | Issue #22181: The availability of the getrandom() is now checked in configure,Victor Stinner2015-03-191-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().
* | Issue #22181: On Linux, os.urandom() now uses the new getrandom() syscall ifVictor Stinner2015-03-181-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.
* | Issue #23694: Enhance _Py_open(), it now raises exceptionsVictor Stinner2015-03-171-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
* | Issue #23152: Implement _Py_fstat() to support files larger than 2 GB on ↵Steve Dower2015-02-211-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.
* | Issue #22585: On OpenBSD 5.6 and newer, os.urandom() now calls getentropy(),Victor Stinner2014-12-211-4/+35
| | | | | | | | instead of reading /dev/urandom, to get pseudo-random bytes.
* | Removed duplicated words in in comments and docs.Serhiy Storchaka2014-12-011-1/+1
|\ \ | |/
| * Removed duplicated words in in comments and docs.Serhiy Storchaka2014-12-011-1/+1
| |
* | Issue21393 Use CryptReleaseContext to release Crypt handle on WindowsTim Golden2014-05-061-1/+1
| |
* | Issue #21393: random.c: on Windows, close the hCryptProv handle at exitVictor Stinner2014-05-021-3/+6
|/
* Issue #21207: Detect when the os.urandom cached fd has been closed or ↵Antoine Pitrou2014-04-261-10/+39
| | | | replaced, and open it anew.
* Issue #16136: Remove VMS support and VMS-related codeChristian Heimes2013-12-211-33/+4
|
* ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.Christian Heimes2013-11-201-6/+7
| | | | Python now uses SipHash24 on all major platforms.
* Fix compiler warning in win32_urandom(): explicit cast to DWORD inVictor Stinner2013-11-151-1/+1
| | | | CryptGenRandom()
* merge with 3.3Georg Brandl2013-10-061-2/+3
|\
| * Closes #15213: update comment for _PyOS_URandomGeorg Brandl2013-10-061-2/+3
| |
* | Issue #18756: os.urandom() now uses a lazily-opened persistent file ↵Antoine Pitrou2013-08-301-13/+42
| | | | | | | | descriptor, so as to avoid using many file descriptors when run in parallel from multiple threads.
* | Issue #18571: Implementation of the PEP 446: file descriptors and file handlesVictor Stinner2013-08-271-2/+2
| | | | | | | | | | are now created non-inheritable; add functions os.get/set_inheritable(), os.get/set_handle_inheritable() and socket.socket.get/set_inheritable().
* | Issue #18756: Improve error reporting in os.urandom() when the failure is ↵Antoine Pitrou2013-08-161-2/+6
|\ \ | |/ | | | | due to something else than /dev/urandom not existing.
| * Issue #18756: Improve error reporting in os.urandom() when the failure is ↵Antoine Pitrou2013-08-161-2/+6
| | | | | | | | due to something else than /dev/urandom not existing.