CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pyopenssl

Python wrapper module around the OpenSSL library providing cryptographic functionality and TLS/SSL capabilities

Pending
Overview
Eval results
Files

rand-module.mddocs/

Random Number Generation

Random number generation utilities for cryptographic operations. Note: These functions are deprecated and provided for backward compatibility only.

Capabilities

Random Number Seeding (Deprecated)

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.
    """

Usage Examples

Basic Random Seeding (Deprecated)

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()}")

Modern Approach (Recommended)

# 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 necessary

Deprecation Notice

The OpenSSL.rand module is deprecated because:

  1. Modern OpenSSL versions automatically seed the random number generator
  2. The system provides sufficient entropy sources
  3. Python's secrets and os.urandom provide better interfaces for secure randomness
  4. Manual entropy seeding is rarely needed in modern applications

For new code, use Python's built-in secure random functions instead of this module.

Install with Tessl CLI

npx tessl i tessl/pypi-pyopenssl

docs

certificate-management.md

certificate-verification.md

cryptographic-keys.md

index.md

rand-module.md

ssl-connections.md

tile.json