Python wrapper module around the OpenSSL library providing cryptographic functionality and TLS/SSL capabilities
—
Random number generation utilities for cryptographic operations. Note: These functions are deprecated and provided for backward compatibility only.
Functions for seeding the OpenSSL random number generator. These are deprecated as modern OpenSSL versions handle random seeding automatically.
@deprecated
def add(buffer: bytes, entropy: int) -> None:
"""
Add random bytes to OpenSSL's entropy pool.
Parameters:
- buffer: Random bytes to add to entropy pool
- entropy: Estimate of entropy in buffer (in bytes)
Note: This function is deprecated. Modern OpenSSL versions
automatically seed the random number generator.
"""
@deprecated
def status() -> int:
"""
Check if random number generator has been seeded.
Returns:
1 if PRNG has been seeded with enough data, 0 otherwise
Note: This function is deprecated and may not provide
meaningful results on modern systems.
"""from OpenSSL import rand
import warnings
# Note: These functions are deprecated
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
# Check if random generator is seeded
if rand.status():
print("Random generator is seeded")
else:
print("Random generator needs seeding")
# Add some entropy (deprecated approach)
import os
random_bytes = os.urandom(32)
rand.add(random_bytes, 32)
print(f"Random generator status: {rand.status()}")# Instead of using OpenSSL.rand, use Python's secure random functions
import secrets
import os
# Generate cryptographically secure random bytes
secure_random = secrets.token_bytes(32)
print(f"Generated {len(secure_random)} secure random bytes")
# Or use os.urandom for system randomness
system_random = os.urandom(32)
print(f"Generated {len(system_random)} system random bytes")
# Modern OpenSSL automatically handles seeding, so manual
# seeding with OpenSSL.rand is not necessaryThe OpenSSL.rand module is deprecated because:
secrets and os.urandom provide better interfaces for secure randomnessFor new code, use Python's built-in secure random functions instead of this module.
Install with Tessl CLI
npx tessl i tessl/pypi-pyopenssl