AMD's random number generator can't generate a 0?
summary
Certain AMD processors, specifically those using the RDRAND and RDSEED instructions, appear unable to generate a value of zero when the requested output size is small, such as 16-bit. This behavior is not observed on Intel processors, suggesting a hardware or firmware limitation specific to AMD. The author demonstrates this through a test application and suggests that generating larger bit-widths and then masking the data can bypass the issue.
key points
- AMD's hardware random number generators fail to produce a zero value at specific sizes, whereas Intel's generators function normally.
- The issue can be mitigated by requesting 32-bit or 64-bit random numbers and then extracting the necessary lower bits.
- Users and developers discuss the security implications, noting that hardware RNGs should be mixed with other entropy sources to avoid potential backdoors or flaws.
who should read it
Low-level programmers and electronics engineers interested in CPU architecture and hardware-based random number generation.
discussion skeptical
consensus
Users agree that AMD Zen 2 processors exhibit a bug where the rdrand16 instruction fails to generate all-zero results, incorrectly setting the carry flag (CF=0) to signal a retry. This behavior is viewed as a recurring quality control issue for AMD, with some noting similar RNG failures in Zen 5 errata. Most commenters conclude that while this specific bug is problematic, it is generally harmless if the system utilizes multiple entropy sources, as a single biased source typically cannot poison a well-implemented kernel entropy pool.
top insight
A detailed technical analysis reveals that rdrand16 does actually produce zeros, but it erroneously marks them as failures (CF=0), causing programs that implement the recommended retry logic to skip those values entirely. This distinction is critical because it means the RNG is not fundamentally incapable of generating zero, but rather the interface for reporting success is broken, effectively filtering out zeros from the user's perspective.
Generated by an LLM from the article and thread. Check the sources before relying on it.