You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
os urandom does not document CCRandomGenerateBytes #116245
The documentation for os.urandom clearly states that for Linux systems getrandom() is used when available (and then depending on python release and Linux version the behavior changes).
The documentation also clearly states that for Windows os.urandom uses BCryptGenRandom (which was previously CryptGenRandom before release 3.11).
The documentation then states that on a "Unix-like system" that reads to /dev/urandom are done.
However macOS is not mentioned (which could technically be covered by the "Unix-like system" and is often misinterpreted that way).
The /mimalloc/prim/unix/prim.c file (around lines 730-760) define macOS functionality using CCRandomGenerateBytes and then falling back to arc4random_buf.
The documentation is not up to date, but not in the way you mention. The implementation for os.urandom in the end calls pyurandom in Python/bootstrap.c, and that calls getentropy(3) on macOS 10.12 or later and reads from /dev/urandom on older versions of macOS.
The fact that getentropy is used is only mentioned in a version changed notice that only mentions OpenBSD.
Activity
ronaldoussoren commentedon Mar 3, 2024
The documentation is not up to date, but not in the way you mention. The implementation for
os.urandomin the end callspyurandomin Python/bootstrap.c, and that callsgetentropy(3)on macOS 10.12 or later and reads from/dev/urandomon older versions of macOS.The fact that
getentropyis used is only mentioned in a version changed notice that only mentions OpenBSD.RappelBerryPi commentedon Mar 3, 2024
Thank you for the correction of my misunderstanding.
Also thank you for updating the doc.
gh-116245: Document `getentropy()` use in `os.urandom()` (#162108)
[3.14] gh-116245: Document `getentropy()` use in `os.urandom()` (GH-1…
[3.15] gh-116245: Document `getentropy()` use in `os.urandom()` (GH-1…