Keyboard shortcuts

Press ← or → to navigate between chapters

Press ? to show this help

Press Esc to hide this help

The roles of SHA-256, HMAC, and random bit generation

Key generation needs unpredictable random bytes. The Rust crate quantaegis-drbg exposes SHA-256, HMAC-SHA-256, and HMAC_DRBG, a deterministic random bit generator that uses HMAC-SHA-256 internally. When the tutorials generate keys through the SDK, the SDK uses the operating system’s randomness source.

How it works · SHA-256 block processing · The two hashes in HMAC-SHA-256 · HMAC_DRBG generation and reseeding

TypeInputsOutput
Sha256Up to 2⁶¹ − 1 bytes of dataA 32-byte digest computed with SHA-256, a separate hash function from SHA-3
HmacSha256A shared key and dataAn authentication code that another holder of the shared key can verify
HmacDrbgSha256Entropy and other initialization inputsA sequence of pseudorandom bytes generated while updating a secret internal state

With HMAC, anyone holding the same secret key can generate and verify tags. To let third parties verify something you distribute with a public key, use digital signatures. The unpredictability of HMAC_DRBG output depends on the entropy supplied at initialization and reseeding. The Rust API documents initialization requirements, output limits, and reseed conditions. Digital signatures · Random bit generator crate API · NIST SP 800-90A Rev. 1

When using Sha256 or HmacSha256 incrementally, check the Result returned by try_update and try_finalize_into for state or input errors. HmacSha256::verify returns a Choice. Use .into_bool() when you need to act on a verification result that may be made public.

To pass HmacDrbgSha256 to a primitive as its CryptoRng, use an adapter. The adapter handles DrbgReseedRequired and supplies fresh entropy when a reseed is required, for example when cumulative output reaches the 16 KiB threshold.