hn.today

AMD's random number generator can't generate a 0?

board.flatassembler.net94 points46 comments
Screenshot of AMD's random number generator can't generate a 0?

A developer reports that AMD CPUs (reported on Zen2-class hardware) appear unable to produce an exact zero when using rdrand/rdseed to request 16-bit random values. He built an assembly test that draws a bar chart of counts for all 16-bit values: the zero bin (first bar) never changes on AMD machines while Intel systems show zeros as expected. The chart colors correspond to rdrand (red), rdseed (blue) and a custom TSC-based generator (green). He confirms that when rdrand/rdseed are used to produce full 32- or 64-bit outputs and then the low 16 bits are taken, zeros do appear, and suggests a practical fix: emit to 32/64-bit registers and truncate to 16 bits for display. The test program and source are provided for others to reproduce the behavior.

Responses on the board debate trust in hardware RNGs and suggest always mixing entropy sources for cryptographic use. The author contacted AMD, received an apparently inadequate reply, and reports the case has been escalated but no definitive resolution yet; two AMD machines he tested produced no zeros over extended runs. He also added benchmarking to the tool and notes wide performance differences: an older Core i5 produced ~12.6M rnd/s, a Core i7-7700 ~750k rnd/s, and a Ryzen 7 ~2.6M rnd/s, with AMD’s generator apparently insensitive to clock changes.

Read on board.flatassembler.net46 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Security

Type Punning in C and C++

Type Punning in C and C++

Type punning involves interpreting memory as different types, which is common in low-level programming but can lead to undefined behavior. In C, unions and memcpy are safe methods, while pointer casts are unsafe and violate strict aliasing rules, especially in C++ where the compiler assumes types do not alias. (blog.pwkf.org)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.