Commit Graph

56 Commits

Author SHA1 Message Date
Victor Stinner e66987e626 os.urandom() now blocks on Linux
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-09-06 16:33:52 -07:00
Victor Stinner 3ee933f1c3 Issue #27776: dev_urandom(raise=0) now closes the file descriptor on error 2016-08-16 18:27:44 +02:00
Victor Stinner 6974cf2c27 Issue #27776: Cleanup random.c
Merge dev_urandom_python() and dev_urandom_noraise() functions to reduce code
duplication.
2016-08-16 18:46:38 +02:00
Victor Stinner cecdd9634b Issue #27776: _PyRandom_Init() doesn't call PyErr_CheckSignals() anymore
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-16 15:19:09 +02:00
Victor Stinner 4bad3b622e Issue #27776: Cleanup random.c
* 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-08-16 15:23:58 +02:00
Martin Panter d2f87472fe Issue #17596: MINGW: add wincrypt.h in Python/random.c
Based on patch by Roumen Petrov.
2016-07-29 04:00:44 +00:00
Victor Stinner a63073a807 Merge 3.5 2016-06-17 00:01:30 +02:00
Victor Stinner ec721f3305 py_getrandom(): use long type for the syscall() result
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-16 23:53:47 +02:00
Victor Stinner d017176209 Merge 3.5 2016-06-14 16:36:00 +02:00
Victor Stinner c72828ba33 cleanup random.c
Casting Py_ssize_t to Py_ssize_t is useless.
2016-06-14 16:35:49 +02:00
Victor Stinner 370f5136d4 Merge 3.5 (os.urandom, issue #27278) 2016-06-14 16:33:17 +02:00
Victor Stinner b98a36e8f3 Fix os.urandom() using getrandom() on Linux
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-14 16:31:35 +02:00
Martin Panter 596357de23 Merge comment fix from 3.5 2016-06-10 08:38:56 +00:00
Martin Panter 39b1025356 Fix typo and move comment to appropriate condition 2016-06-10 08:07:11 +00:00
Victor Stinner cfb1961f61 py_getrandom(): use char* instead of void* for the destination
Fix a "gcc -pedantic" warning on "buffer += n" because buffer type is void*.
2016-06-08 10:16:50 +02:00
Victor Stinner 9ff9cbd600 Merge 3.5 (os.urandom) 2016-06-07 11:25:43 +02:00
Victor Stinner dddf4849ec os.urandom() doesn't block on Linux anymore
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-06-07 11:21:42 +02:00
Victor Stinner 7258176c68 Merge 3.5 (os.urandom) 2016-04-12 22:38:22 +02:00
Victor Stinner 9d24271d86 Fix os.urandom() on Solaris 11.3
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.
2016-04-12 22:28:49 +02:00
Serhiy Storchaka fad85aadb0 Issue #25558: Use compile-time asserts. 2015-11-07 15:42:38 +02:00
Victor Stinner 861f067201 Merge 3.4 (os.urandom) 2015-10-01 10:00:23 +02:00
Victor Stinner 78cc2e8968 Issue #25003: os.urandom() doesn't use getentropy() on Solaris because
getentropy() is blocking, whereas os.urandom() should not block. getentropy()
is supported since Solaris 11.3.
2015-10-01 09:59:32 +02:00
Victor Stinner bae2d6203f Issue #25003: On Solaris 11.3 or newer, os.urandom() now uses the getrandom()
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-10-01 09:47:30 +02:00
Victor Stinner 61d5aab9b9 py_getrandom(): getrandom() *can* return EINTR
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-07-30 10:13:52 +02:00
Victor Stinner 81c6df5c0f (Merge 3.4) Issue #22585: os.urandom() now releases the GIL when the
getentropy() is used (OpenBSD 5.6+).
2015-03-30 11:19:07 +02:00
Victor Stinner 9aa1331c6f Issue #22585: os.urandom() now releases the GIL when the getentropy() is used
(OpenBSD 5.6+).
2015-03-30 11:18:30 +02:00
Victor Stinner 79b74aeb20 Issue #22181: os.urandom() now releases the GIL when the getrandom()
implementation is used.
2015-03-30 11:16:40 +02:00
Victor Stinner e134a7fe36 Issue #23752: _Py_fstat() is now responsible to raise the Python exception
Add _Py_fstat_noraise() function when a Python exception is not welcome.
2015-03-30 10:09:31 +02:00
Victor Stinner c9382eb7ae Issue #23707: On UNIX, os.urandom() now calls the Python signal handler when
read() is interrupted by a signal.

dev_urandom_python() now calls _Py_read() helper instead of calling directly
read().
2015-03-19 23:36:33 +01:00
Victor Stinner c7cd12da60 Issue #22181: Fix dev_urandom_noraise(), try calling py_getrandom() before
opening /dev/urandom.
2015-03-19 23:24:45 +01:00
Victor Stinner 9eb57c5fa5 Issue #22181: The availability of the getrandom() is now checked in configure,
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-19 22:21:49 +01:00
Victor Stinner 59f7fb29ec Issue #22181: On Linux, os.urandom() now uses the new getrandom() syscall if
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-18 14:39:33 +01:00
Victor Stinner a555cfcb73 Issue #23694: Enhance _Py_open(), it now raises exceptions
* _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-03-18 00:22:14 +01:00
Steve Dower f2f373f593 Issue #23152: Implement _Py_fstat() to support files larger than 2 GB on Windows.
fstat() may fail with EOVERFLOW on files larger than 2 GB because the file size type is an signed 32-bit integer.
2015-02-21 08:44:05 -08:00
Victor Stinner fe02e39029 Issue #22585: On OpenBSD 5.6 and newer, os.urandom() now calls getentropy(),
instead of reading /dev/urandom, to get pseudo-random bytes.
2014-12-21 01:16:38 +01:00
Victor Stinner 4d6a3d6c01 Issue #22585: On OpenBSD 5.6 and newer, os.urandom() now calls getentropy(),
instead of reading /dev/urandom, to get pseudo-random bytes.
2014-12-21 01:16:38 +01:00
Serhiy Storchaka 56a6d855e2 Removed duplicated words in in comments and docs. 2014-12-01 18:28:43 +02:00
Serhiy Storchaka 83000a490a Removed duplicated words in in comments and docs. 2014-12-01 18:30:14 +02:00
Tim Golden b8ac3e1a20 Issue21393 Use CryptReleaseContext to release Crypt handle on Windows 2014-05-06 13:29:45 +01:00
Victor Stinner d50c3f3f3a Issue #21393: random.c: on Windows, close the hCryptProv handle at exit 2014-05-02 22:06:44 +02:00
Antoine Pitrou e472aeafc3 Issue #21207: Detect when the os.urandom cached fd has been closed or replaced, and open it anew. 2014-04-26 14:33:03 +02:00
Christian Heimes af01f66817 Issue #16136: Remove VMS support and VMS-related code 2013-12-21 16:19:10 +01:00
Christian Heimes 985ecdcfc2 ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.
Python now uses SipHash24 on all major platforms.
2013-11-20 11:46:18 +01:00
Victor Stinner 0c083461a5 Fix compiler warning in win32_urandom(): explicit cast to DWORD in
CryptGenRandom()
2013-11-15 23:26:25 +01:00
Georg Brandl af1edb7f45 merge with 3.3 2013-10-06 18:48:30 +02:00
Georg Brandl c6a2c9b466 Closes #15213: update comment for _PyOS_URandom 2013-10-06 18:43:19 +02:00
Antoine Pitrou 4879a963d4 Issue #18756: os.urandom() now uses a lazily-opened persistent file descriptor, so as to avoid using many file descriptors when run in parallel from multiple threads. 2013-08-31 00:26:02 +02:00
Victor Stinner daf455554b Issue #18571: Implementation of the PEP 446: file descriptors and file handles
are now created non-inheritable; add functions os.get/set_inheritable(),
os.get/set_handle_inheritable() and socket.socket.get/set_inheritable().
2013-08-28 00:53:59 +02:00
Antoine Pitrou 95b21460ee Issue #18756: Improve error reporting in os.urandom() when the failure is due to something else than /dev/urandom not existing. 2013-08-16 20:49:32 +02:00
Antoine Pitrou ec34ab5010 Issue #18756: Improve error reporting in os.urandom() when the failure is due to something else than /dev/urandom not existing. 2013-08-16 20:44:38 +02:00