@staticmethod def random_bytes(length: int) -> bytes: """Return `length` cryptographically random bytes.""" return os.urandom(length)

@staticmethod def from_password(password: str, salt: bytes, length: int = 32) -> bytes: """ Derive a key from a password using PBKDF2-HMAC-SHA256. For new systems, prefer Argon2id via `argon2-cffi`. """ kdf = PBKDF2HMAC( algorithm=hashes.SHA256(), length=length, salt=salt, iterations=600000, # OWASP recommended (2023) ) return kdf.derive(password.encode('utf-8'))

@staticmethod def chacha20_key() -> bytes: """ChaCha20 uses exactly 256-bit keys.""" return os.urandom(32)

/// Generate a 256-bit AES key. pub fn aes_key_256() -> [u8; 32] let mut key = [0u8; 32]; OsRng.fill_bytes(&mut key); key