Skip to content

Commit d6f284d

Browse files
committed
Add GRND_INSECURE constant to os module
1 parent d9331f1 commit d6f284d

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

Doc/library/os.rst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5732,8 +5732,8 @@ Random numbers
57325732
``/dev/urandom`` devices.
57335733

57345734
The flags argument is a bit mask that can contain zero or more of the
5735-
following values ORed together: :py:const:`os.GRND_RANDOM` and
5736-
:py:data:`GRND_NONBLOCK`.
5735+
following values ORed together: :py:const:`os.GRND_RANDOM`,
5736+
:py:data:`GRND_NONBLOCK` and :py:data:`GRND_INSECURE`.
57375737

57385738
See also the `Linux getrandom() manual page
57395739
<https://man7.org/linux/man-pages/man2/getrandom.2.html>`_.
@@ -5803,3 +5803,15 @@ Random numbers
58035803
``/dev/random`` pool instead of the ``/dev/urandom`` pool.
58045804

58055805
.. versionadded:: 3.6
5806+
5807+
.. data:: GRND_INSECURE
5808+
5809+
If this flag is set, then :func:`getrandom` will return pseudo-random data
5810+
even if the entropy pool has not yet been initialized.
5811+
(It cannot be used with :py:const:`os.GRND_RANDOM`.)
5812+
5813+
.. note::
5814+
5815+
It is not suitable for scenarios requiring secure cryptography.
5816+
5817+
.. versionadded:: next

Doc/whatsnew/3.14.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,9 @@ os
491491
same process.
492492
(Contributed by Victor Stinner in :gh:`120057`.)
493493

494+
* Add the :data:`~os.GRND_INSECURE` constant to the :mod:`os` module.
495+
(Contributed by James Roy in :gh:`127776`.)
496+
494497

495498
pathlib
496499
-------
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add the :data:`~os.GRND_INSECURE` constant to the :mod:`os` module.

Modules/posixmodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17613,6 +17613,8 @@ all_ins(PyObject *m)
1761317613
#ifdef HAVE_GETRANDOM_SYSCALL
1761417614
if (PyModule_AddIntMacro(m, GRND_RANDOM)) return -1;
1761517615
if (PyModule_AddIntMacro(m, GRND_NONBLOCK)) return -1;
17616+
/* Linux 5.6+ */
17617+
if (PyModule_AddIntMacro(m, GRND_INSECURE)) return -1;
1761617618
#endif
1761717619
#ifdef HAVE_MEMFD_CREATE
1761817620
if (PyModule_AddIntMacro(m, MFD_CLOEXEC)) return -1;

0 commit comments

Comments
 (0)