[New-bugs-announce] [issue27279] Add random.cryptorandom() and random.pseudorandom, deprecate os.urandom()

Marc-Andre Lemburg report at bugs.python.org
Thu Jun 9 03:54:24 EDT 2016

New submission from Marc-Andre Lemburg:

I propose to deprecate os.urandom() altogether due to all the
issues we've discussed on all those recent tickets, see e.g. 
#26839, #27250, #25420.

Unlike what we've told people for many years, it's clear that in the
age of VMs/containers getting booted/started every few seconds, it's
not longer the generic correct answer to people asking for random
data, since it doesn't make a difference between crypto random and 
pseudo random data.

By far most use cases only need pseudo random data and only very
few applications require crypto random data.

Instead, let's define something everybody can start to use correctly
and get sane behavior on most if not all platforms. As Larry
suggested in #27266, getrandom() is a good starting point for this,
since it's adoption is spreading fast and it provides the necessary
features we need for the two new APIs.

I propose these new APIs:

 * random.cryptorandom() for getting OS crypto random data

 * random.pseudorandom() for getting OS pseudo random data

Crypto applications will then clearly know that random.cryptorandom()
is the right choice for them and everyone else can use 

random.cryptorandom() will guarantee that the returned data
is safe for crypto applications on all platforms, blocking or
raising an exception if necessary to make sure only safe
data is returned. The API should get a parameter to determine
whether to raise or block.

random.pseudorandom() will guarantee to not block and always
return random data that can be used as seeds for simulations, 
games, tests, monte carlo, etc.

The APIs should use the getrandom() C API, where available,
with appropriate default settings, i.e. blocking or raising
for random.cryptorandom() and non-blocking, non-raising for

The existing os.urandom() would then be deprecated to guide
new developments to the these new APIs, getting rid of the
ambiguities and problems this interface has on several platforms
(see all the other tickets and https://en.wikipedia.org/wiki//dev/random
for details).

components: Library (Lib)
messages: 267970
nosy: lemburg
priority: normal
severity: normal
status: open
title: Add random.cryptorandom() and random.pseudorandom, deprecate os.urandom()
versions: Python 3.6

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list