You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB

4 years ago
  1. """
  2. PRNG management routines, thin wrappers.
  3. """
  4. from OpenSSL._util import lib as _lib
  5. def add(buffer, entropy):
  6. """
  7. Mix bytes from *string* into the PRNG state.
  8. The *entropy* argument is (the lower bound of) an estimate of how much
  9. randomness is contained in *string*, measured in bytes.
  10. For more information, see e.g. :rfc:`1750`.
  11. This function is only relevant if you are forking Python processes and
  12. need to reseed the CSPRNG after fork.
  13. :param buffer: Buffer with random data.
  14. :param entropy: The entropy (in bytes) measurement of the buffer.
  15. :return: :obj:`None`
  16. """
  17. if not isinstance(buffer, bytes):
  18. raise TypeError("buffer must be a byte string")
  19. if not isinstance(entropy, int):
  20. raise TypeError("entropy must be an integer")
  21. _lib.RAND_add(buffer, len(buffer), entropy)
  22. def status():
  23. """
  24. Check whether the PRNG has been seeded with enough data.
  25. :return: 1 if the PRNG is seeded enough, 0 otherwise.
  26. """
  27. return _lib.RAND_status()