3
:py:mod:`rand` --- An interface to the OpenSSL pseudo random number generator
4
=============================================================================
6
.. py:module:: OpenSSL.rand
7
:synopsis: An interface to the OpenSSL pseudo random number generator
10
This module handles the OpenSSL pseudo random number generator (PRNG) and
11
declares the following:
13
.. py:function:: add(string, entropy)
15
Mix bytes from *string* into the PRNG state. The *entropy* argument is
16
(the lower bound of) an estimate of how much randomness is contained in
17
*string*, measured in bytes. For more information, see e.g. :rfc:`1750`.
20
.. py:function:: bytes(num_bytes)
22
Get some random bytes from the PRNG as a string.
24
This is a wrapper for the C function :py:func:`RAND_bytes`.
27
.. py:function:: cleanup()
29
Erase the memory used by the PRNG.
31
This is a wrapper for the C function :py:func:`RAND_cleanup`.
34
.. py:function:: egd(path[, bytes])
36
Query the `Entropy Gathering Daemon <http://www.lothar.com/tech/crypto/>`_ on
37
socket *path* for *bytes* bytes of random data and uses :py:func:`add` to
38
seed the PRNG. The default value of *bytes* is 255.
41
.. py:function:: load_file(path[, bytes])
43
Read *bytes* bytes (or all of it, if *bytes* is negative) of data from the
44
file *path* to seed the PRNG. The default value of *bytes* is -1.
47
.. py:function:: screen()
49
Add the current contents of the screen to the PRNG state.
51
Availability: Windows.
54
.. py:function:: seed(string)
56
This is equivalent to calling :py:func:`add` with *entropy* as the length
60
.. py:function:: status()
62
Returns true if the PRNG has been seeded with enough data, and false otherwise.
65
.. py:function:: write_file(path)
67
Write a number of random bytes (currently 1024) to the file *path*. This
68
file can then be used with :py:func:`load_file` to seed the PRNG again.
71
.. py:exception:: Error
73
If the current RAND method supports any errors, this is raised when needed.
74
The default method does not raise this when the entropy pool is depleted.
76
Whenever this exception is raised directly, it has a list of error messages
77
from the OpenSSL error queue, where each item is a tuple *(lib, function,
78
reason)*. Here *lib*, *function* and *reason* are all strings, describing
79
where and what the problem is. See :manpage:`err(3)` for more information.