HmacDrbg
Source: hash.ts:153
HMAC-SHA256 Deterministic Random Bit Generator. Implements the formal NIST SP 800-90A Rev.1 HMAC_DRBG specification.
Properties:
- Cryptographically secure (HMAC-SHA256 as PRF)
- Domain-separated via the context string (prevents cross-use of the same seed for different purposes, e.g. "earnmore:pan" vs "earnmore:expiry")
- Rejection-sampled outputs eliminate modular bias (FIPS 186-5 §B.4.2)
- See:
- - NIST SP 800-90A Rev.1 — HMAC_DRBG (formal standard) - FIPS 186-5 §B.4.2 — Rejection sampling for unbiased output
Constructors
new HmacDrbg(seed: Buffer, context: string): HmacDrbg
Parameters
seed(Buffer) — 32-byte Buffer from which all randomness is derived. Must originate from a CSPRNG (e.g. crypto.randomBytes).context(string, default: "\"\"") — Domain-separation string. Used aspersonalization_string.
Returns
HmacDrbg
Methods
nextByte(): number
Returns the next byte from the DRBG output stream
Returns
nextInt(max: number): number
Returns an unbiased random integer in [0, max) using rejection sampling. Rejects bytes that would introduce modular bias (FIPS 186-5 §B.4.2).
Parameters
max(number) — Upper bound (exclusive). Must be in [2, 256].
Returns