diff options
author | Benjamin Peterson <benjamin@python.org> | 2014-11-03 15:11:53 -0500 |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2014-11-03 15:11:53 -0500 |
commit | c84f5e48d5387cbcb779c9354132bb6a48d07ea3 (patch) | |
tree | eea40c044a2802b7112691f1614766faea81af2e /Python/random.c | |
parent | 41540bf9aa1b0dfb206088945acfd7bb74d440d0 (diff) | |
parent | 00261b71a55839b4b53a50d7ab7b416110570d10 (diff) | |
download | cpython-c84f5e48d5387cbcb779c9354132bb6a48d07ea3.tar.gz |
merge 3.2
Diffstat (limited to 'Python/random.c')
-rw-r--r-- | Python/random.c | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/Python/random.c b/Python/random.c index 825260f36b..337be86087 100644 --- a/Python/random.c +++ b/Python/random.c @@ -165,8 +165,12 @@ dev_urandom_python(char *buffer, Py_ssize_t size) Py_END_ALLOW_THREADS if (fd < 0) { - PyErr_SetString(PyExc_NotImplementedError, - "/dev/urandom (or equivalent) not found"); + if (errno == ENOENT || errno == ENXIO || + errno == ENODEV || errno == EACCES) + PyErr_SetString(PyExc_NotImplementedError, + "/dev/urandom (or equivalent) not found"); + else + PyErr_SetFromErrno(PyExc_OSError); return -1; } @@ -220,8 +224,9 @@ lcg_urandom(unsigned int x0, unsigned char *buffer, size_t size) } } -/* Fill buffer with size pseudo-random bytes, not suitable for cryptographic - use, from the operating random number generator (RNG). +/* Fill buffer with size pseudo-random bytes from the operating system random + number generator (RNG). It is suitable for for most cryptographic purposes + except long living private keys for asymmetric encryption. Return 0 on success, raise an exception and return -1 on error. */ int @@ -258,17 +263,6 @@ _PyRandom_Init(void) _Py_HashSecret_Initialized = 1; /* - By default, hash randomization is disabled, and only - enabled if PYTHONHASHSEED is set to non-empty or if - "-R" is provided at the command line: - */ - if (!Py_HashRandomizationFlag) { - /* Disable the randomized hash: */ - memset(secret, 0, secret_size); - return; - } - - /* Hash randomization is enabled. Generate a per-process secret, using PYTHONHASHSEED if provided. */ |