#!/usr/bin/env python3 """Regenerate the TrueEntropy PractRand hybrid test stream. Construction (as used for the April 2026 run): seed = raw_full.bin (10,485,760 bytes of IBM Quantum output, ibm_fez) key = seed[0:32] IV = seed[32:44] || 00 00 00 00 (16 bytes, OpenSSL / cryptography layout) i.e. RFC 8439 block counter = seed[32:36] read as a little-endian uint32, RFC 8439 nonce = seed[36:44] || 00 00 00 00 stream = seed || ChaCha20 keystream length = 2**35 bytes (32 GiB) unless --bytes is given The stream is written to stdout, so it can be piped straight into PractRand: python3 gen_hybrid_stream.py | ./RNG_test stdin8 -tlmax 32G Requires: pip install cryptography """ import argparse import hashlib import sys from cryptography.hazmat.primitives.ciphers import Cipher, algorithms SEED_SIZE = 10_485_760 SEED_SHA256 = "b0940f079dc5236b287033df4aed6d32f1ba306e34c6a60531f055f33b42b31b" DEFAULT_BYTES = 2**35 CHUNK = 16 * 1024 * 1024 def main() -> int: ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) ap.add_argument("--seed", default="raw_full.bin", help="path to the quantum seed file") ap.add_argument("--bytes", type=int, default=DEFAULT_BYTES, help="total stream length (default 2^35)") args = ap.parse_args() with open(args.seed, "rb") as f: seed = f.read() if len(seed) != SEED_SIZE or hashlib.sha256(seed).hexdigest() != SEED_SHA256: sys.exit(f"seed mismatch: expected {SEED_SIZE} bytes with SHA-256 {SEED_SHA256}") key, iv = seed[0:32], seed[32:44] + b"\x00\x00\x00\x00" counter = int.from_bytes(iv[0:4], "little") # keep within the 32-bit block counter so the stream is plain RFC 8439 ChaCha20 with no carry if args.bytes > len(seed) + (2**32 - counter) * 64: sys.exit("requested length exceeds the 32-bit ChaCha20 block counter range") enc = Cipher(algorithms.ChaCha20(key, iv), mode=None).encryptor() out = sys.stdout.buffer remaining = args.bytes try: head = seed[:remaining] out.write(head) remaining -= len(head) zeros = bytes(CHUNK) while remaining > 0: n = min(CHUNK, remaining) out.write(enc.update(zeros[:n])) remaining -= n out.flush() except BrokenPipeError: # PractRand closes stdin once it reaches -tlmax pass return 0 if __name__ == "__main__": sys.exit(main())