openmedialibrary_platform_w.../Lib/site-packages/OpenSSL/rand.py

41 lines
1 KiB
Python
Raw Normal View History

2016-01-31 14:44:46 +00:00
"""
PRNG management routines, thin wrappers.
"""
2019-01-20 10:35:31 +00:00
from OpenSSL._util import lib as _lib
2016-01-31 14:44:46 +00:00
2019-01-20 10:35:31 +00:00
def add(buffer, entropy):
2016-01-31 14:44:46 +00:00
"""
2019-01-20 10:35:31 +00:00
Mix bytes from *string* into the PRNG state.
2016-01-31 14:44:46 +00:00
2019-01-20 10:35:31 +00:00
The *entropy* argument is (the lower bound of) an estimate of how much
randomness is contained in *string*, measured in bytes.
2016-01-31 14:44:46 +00:00
2019-01-20 10:35:31 +00:00
For more information, see e.g. :rfc:`1750`.
2016-01-31 14:44:46 +00:00
2019-01-20 10:35:31 +00:00
This function is only relevant if you are forking Python processes and
need to reseed the CSPRNG after fork.
2016-01-31 14:44:46 +00:00
2019-01-20 10:35:31 +00:00
:param buffer: Buffer with random data.
:param entropy: The entropy (in bytes) measurement of the buffer.
2016-01-31 14:44:46 +00:00
2019-01-20 10:35:31 +00:00
:return: :obj:`None`
2016-01-31 14:44:46 +00:00
"""
2019-01-20 10:35:31 +00:00
if not isinstance(buffer, bytes):
2016-01-31 14:44:46 +00:00
raise TypeError("buffer must be a byte string")
if not isinstance(entropy, int):
raise TypeError("entropy must be an integer")
_lib.RAND_add(buffer, len(buffer), entropy)
def status():
"""
2019-01-20 10:35:31 +00:00
Check whether the PRNG has been seeded with enough data.
2016-01-31 14:44:46 +00:00
2019-01-20 10:35:31 +00:00
:return: 1 if the PRNG is seeded enough, 0 otherwise.
2016-01-31 14:44:46 +00:00
"""
return _lib.RAND_status()