Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5732,8 +5732,8 @@ Random numbers
``/dev/urandom`` devices.

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

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

.. versionadded:: 3.6

.. data:: GRND_INSECURE

If this flag is set, then :func:`getrandom` will return pseudo-random data
even if the entropy pool has not yet been initialized.
(It cannot be used with :py:const:`os.GRND_RANDOM`.)

.. note::

It is not suitable for scenarios requiring secure cryptography.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider whether we need to keep this entry.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not, if you know that you want GRND_INSECURE then you probably know what it does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I will keep it.


.. versionadded:: next
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add the :data:`~os.GRND_INSECURE` constant to the :mod:`os` module.
2 changes: 2 additions & 0 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -17613,6 +17613,8 @@ all_ins(PyObject *m)
#ifdef HAVE_GETRANDOM_SYSCALL
if (PyModule_AddIntMacro(m, GRND_RANDOM)) return -1;
if (PyModule_AddIntMacro(m, GRND_NONBLOCK)) return -1;
/* Linux 5.6+ */
if (PyModule_AddIntMacro(m, GRND_INSECURE)) return -1;
#endif
#ifdef HAVE_MEMFD_CREATE
if (PyModule_AddIntMacro(m, MFD_CLOEXEC)) return -1;
Expand Down
Loading