fill_random
def fill_random(mut buf: List[UInt8]) Overwrite every byte of buf with CSPRNG output.
- Args
buf: Buffer to fill. Its length is unchanged.
Raises Error: If the kernel cannot supply entropy. There is no fallback source.
flare_mlake · API · crypto
flare.crypto.randomflare.crypto.random -- bytes from the operating system's CSPRNG.
Every unpredictable byte flare needs comes from here: WebSocket
masking keys and handshake nonces, QUIC connection IDs, stateless
reset and Retry keys, session identifiers. Before this module each
of those read /dev/urandom itself, and three of them fell back to
a clock-derived or constant value when the open failed. Opening a
file fails under fd exhaustion, which a remote peer can cause, so
the fallback was reachable on demand.
This module calls getentropy(3) instead. It is in macOS libc and
in glibc since 2.25, needs no file descriptor, and blocks only until
the kernel pool is first seeded at boot. There is no fallback: if
the kernel cannot supply entropy the call raises, and the caller
fails closed.
from flare.crypto.random import random_bytes, fill_random
random_bytes(n) raises -> List[UInt8] -- n fresh bytes.fill_random(mut buf) raises -- overwrite every byte of an
existing buffer.fill_randomdef fill_random(mut buf: List[UInt8]) Overwrite every byte of buf with CSPRNG output.
buf: Buffer to fill. Its length is unchanged.Raises Error: If the kernel cannot supply entropy. There is no fallback source.
random_bytesdef random_bytes(n: Int) -> List[UInt8] Return n bytes of CSPRNG output.
n: Number of bytes. Zero returns an empty list.Raises Error: If n is negative, or the kernel cannot supply
entropy.