File: //usr/lib64/python3.6/site-packages/M2Crypto/__pycache__/Rand.cpython-36.pyc
3
���[x � @ s� d Z ddlmZ ddlmZmZmZ er8ddlmZm Z ddddd d
ddgZ
G d
d� de�Zej
e� dd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd � Zdd
� ZdS )z�M2Crypto wrapper for OpenSSL PRNG. Requires OpenSSL 0.9.5 and above.
Copyright (c) 1999-2003 Ng Pheng Siong. All rights reserved.
Copyright (c) 2014-2017 Matej Cepl. All rights reserved.
See LICENCE for the license information.
� )�absolute_import)�m2�py27plus�six)�AnyStr�Tuple� rand_seed�rand_add� load_file� save_file�
rand_bytes�rand_pseudo_bytes�rand_file_name�rand_statusc @ s e Zd ZdS )� RandErrorN)�__name__�
__module__�__qualname__� r r �/usr/lib64/python3.6/Rand.pyr s r c C s t j| |� dS )aW
Mixes blob into the PRNG state.
:param blob: added data
:param entropy: (the lower bound of) an estimate of how much randomness
is contained in blob, measured in bytes.
Thus, if the data at buf are unpredictable to an adversary, this
increases the uncertainty about the state and makes the PRNG output less
predictable. Suitable input comes from user interaction (random key
presses, mouse movements) and certain hardware events.
Details about sources of randomness and how to estimate their entropy
can be found in the literature, e.g. RFC 1750.
N)r r )ZblobZentropyr r r r s c C s t j| � dS )zx
Equivalent to rand_add() when len(seed) == entropy.
:param seed: added data (see description at rand_add)
N)r r )Zseedr r r r - s c C s t j� S )z�
Check whether there is enough entropy in PRNG.
:return: 1 if the PRNG has been seeded with enough
data, 0 otherwise.
)r r r r r r r 7 s c C s t jtj� �S )z�
Generate a default path for the random seed file.
:return: string with the filename.
The seed file is $RANDFILE if that environment variable
is set, $HOME/.rnd otherwise. If $HOME is not set either,
an error occurs.
)r Zensure_textr r r r r r r B s
c C s t jtj| �|�S )a1
Read a number of bytes from file filename and adds them to the PRNG.
If max_bytes is non-negative, up to to max_bytes are read; starting with
OpenSSL 0.9.5, if max_bytes is -1, the complete file is read.
:param filename:
:param max_bytes:
:return: the number of bytes read.
)r Zrand_load_filer Z
ensure_str)�filenameZ max_bytesr r r r
O s c C s
t j| �S )a=
Write a number of random bytes (currently 1024) to file.
The file then can be used to initialize the PRNG by calling load_file() in
a later session.
:param filename:
:return: returns the number of bytes written, and -1 if the bytes
written were generated without appropriate seed.
)r Zrand_save_file)r r r r r ^ s c C s
t j| �S )a
Return n cryptographically strong pseudo-random bytes.
An error occurs if the PRNG has not been seeded with enough randomness
to ensure an unpredictable byte sequence.
:param num: number of bytes to be returned
:return: random bytes
)r r )�numr r r r m s c C s( ddl }tjdkr|jdt� tj| �S )aH
Return num pseudo-random bytes into buf.
Pseudo-random byte sequences generated by this method will be unique
if they are of sufficient length, but are not necessarily
unpredictable. They can be used for non-cryptographic purposes and for
certain purposes in cryptographic protocols, but usually not for key
generation etc.
Output of the function is mixed into the entropy pool before
retrieving the new pseudo-random bytes unless disabled at compile
time (see FAQ).
:param num: number of bytes to be returned
:return: random bytes
r Ni z'The underlying OpenSSL method has been z(deprecated. Use Rand.rand_bytes instead.zOThe underlying OpenSSL method has been deprecated. Use Rand.rand_bytes instead.)�warningsr ZOPENSSL_VERSION_NUMBER�warn�DeprecationWarningr
)r r r r r r
{ s
N)�__doc__Z
__future__r ZM2Cryptor r r Ztypingr r �__all__�
ValueErrorr Z rand_initr r r r r
r r r
r r r r �<module> s