bpo-40286: Add randbytes() method to random.Random (GH-19527)

Add random.randbytes() function and random.Random.randbytes()
method to generate random bytes.

Modify secrets.token_bytes() to use SystemRandom.randbytes()
rather than calling directly os.urandom().

Rename also genrand_int32() to genrand_uint32(), since it returns an
unsigned 32-bit integer, not a signed integer.

The _random module is now built with Py_BUILD_CORE_MODULE defined.
This commit is contained in:
Victor Stinner 2020-04-17 19:05:35 +02:00 committed by GitHub
parent 22386bb4ef
commit 9f5fe7910f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 177 additions and 12 deletions

View file

@ -808,7 +808,8 @@ class PyBuildExt(build_ext):
self.add(Extension('_datetime', ['_datetimemodule.c'],
libraries=['m']))
# random number generator implemented in C
self.add(Extension("_random", ["_randommodule.c"]))
self.add(Extension("_random", ["_randommodule.c"],
extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
# bisect
self.add(Extension("_bisect", ["_bisectmodule.c"]))
# heapq