Hacker News

Top stories

Live mirror
30 storiesupdated just nowView source snapshot
  1. 9 Ads per Minute: FIFA Cup 26 – "the price of the beautiful game"(bristol.ac.uk)
    36comments
  2. AMD's random number generator can't generate a 0?(flatassembler.net)
    35comments
  3. Can gzip be a language model?(nathan.rs)
    72comments
  4. MiMo v2.6(xiaomi.com)
    414comments
  5. Spymarks, Not Watermarks(brand.io)
    120comments
  6. A Tokyo school counts the mornings it can see Mt. Fuji: 22 in 1965, 170 in 2023(jivx.com)
    discuss
  7. Verda (Finland) raises $189M in Series B(verda.com)
    4comments
  8. Transformers Explained Visually(poloclub.github.io)
    67comments
  9. Attention is all you have(alicegg.tech)
    249comments
  10. JavaFX 27 Native Image on a Raspberry Pi 5(ennerf.github.io)
    3comments
  11. MiMo-v2.6-Pro: Intelligence, Performance and Price Analysis(artificialanalysis.ai)
    28comments
  12. What Sun got wrong(dtrace.org)
    348comments
  13. JetBrains Air: A System of Products for Agentic Software Development(jetbrains.com)
    4comments
  14. A font that reads what you wrote(rohanadwankar.github.io)
    12comments
  15. I said no and Apple said yes(dbushell.com)
    183comments
  16. I don't want to read what you didn't write(colinbreck.com)
    297comments
  17. AI coding has made CI a bottleneck, so we reworked ours to keep up(linear.app)
    283comments
  18. Divide by depth for instant 3D(gabrieloc.com)
    30comments
  19. Engineering Memory: On learning to memorize first 100 digits of pi (2024)(gregorygundersen.com)
    11comments
  20. A build graph that rolls dice(fzakaria.com)
    1comments
  21. NASA’s Mars Sample Return mission is dead(science.org)
    334comments
  22. Looking forward to Git 2.56 – and 3.0(lwn.net)
    67comments
  23. World Wide Words(worldwidewords.org)
    2comments
  24. What It's Like to Work in One of America's Data Centers(wsj.com)
    8comments
  25. The Advisory Group on Mathematics and Artificial Intelligence(terrytao.wordpress.com)
    69comments
  26. Claude Status – Elevated errors for multiple models(claude.com)
    88comments
  27. PDF Forgeries Are Surprisingly Rare (2022)(gwern.net)
    38comments
  28. Used ThinkPad Buyer's Guide (2019)(bobble.tech)
    21comments
  29. Python Workers are now generally available(cloudflare.com)
    38comments
  30. HERMES radio enables voice and data communication over vast distances(ieee.org)
    61comments

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

85 pointsby 2h agoboard.flatassembler.net
35 comments
1h agoHN ↗

Embarrassing, but probably little practical impact, since these hardware random numbers are typically not used directly and instead seed a CSPRNG.

1h agoHN ↗

It is just possible they decided crypto code that uses it was safer to skip zeros. (Whist mathematically it should be no more likely; it is vastly more likely someone will actually try that key).

It is also possible that their code was generating too many zeros and the easiest fix was to discard them all.

28m agoHN ↗

Can you clarify what you mean by "it is vastly more likely someone will actually try that key"?

I'm guessing you don't think there are people calling rdrand in a loop and throwing away the output with high probability except when it is 0, but I can't see how else you imagine people would be vastly more likely to use the output when it is 0?

1h agoHN ↗

The probability of generating a zero is incredibly low if you use the normal distribution curve.

So it is not necessarily that it doesn't generate zero, they did not run enough times to increase the probability of actually generating a zero.

39m agoHN ↗

should be a discrete uniform distribution right?

58m agoHN ↗

From what I can see they were trying to generate 16bit integers, so the probability is 1 in 65536 and they were running the test for 11 hours.

You definitely would expect a roughly equal number of 0s as any other of those numbers since it's uniformly distributed. And definitely not 0

54m agoHN ↗

This also seems to happen for 16 and 32 bit numbers, so you should be able to see zeros easily.

They also write:

Running the same programs on an Intel processor, and the 0's are there with no problem.

1h agoHN ↗

I'm getting 16-bit zeros on my Zen 3 chip (+1:3821, 0:3893, -1:3895), I will wait to get some statistically significant samples for the 32-bit values and update the forum thread. Maybe it was fixed after Zen 2?

57m agoHN ↗

This is not the first RNG bug on Zen 2, I recall after I first got mine that some application or other would quit immediately at startup because rdrand always returned -1, i.e. all 1s. It was fixed with a microcode update.

Do we now learn that they fixed "always generate all 1s" with "never generate all 0s"??

EDIT: I've been unable to reproduce the problem on my CPU, FWIW. It's a Ryzen 5 3600.

EDIT2: OK, update, I can reproduce it with rdrand16, rdrand32 is fine but rdrand16 can never generate all 0s. So my CPU does have this problem!

37m agoHN ↗

And for the full fail story behind it, fail0verflow hacking the PS3 presentation is great and covers the bug: https://youtu.be/DUGGJpn2_zY

Most of the console hacking talks are great, both informative and entertaining.

6m agoHN ↗

I think that one is referencing a run of six 9's in the digits of pi, which occur much earlier than one would "expect" them to show up in a truly uniform distribution.

6m agoHN ↗

CVE-2008-0166 (Debian OpenSSL Predictable PRNG Vulnerability) inspired xkcd/221 but this sort of thing happens a lot :)

27m agoHN ↗

Does rdrand32 and then taking the lowest 16 bits of its result yield any zeroes?

Basically I'm wondering if it's a bug in the version of the instruction that writes to a 16-bit reg, or a bug in the underlying RNG

26m agoHN ↗

Yes it does. rdrand32()%65535 was my first attempt, and generated zeroes at about the expected rate, that's why I initially erroneously thought my CPU did not have this problem.

25m agoHN ↗

How about* rdrand32()%65536? Taking the remainder by 65535 doesn't take the lowest 16 bits after all

*: missed a word the first time around

22m agoHN ↗

You should be using &0xFFFF for masking. Your mod is off by 1 too.

56m agoHN ↗

Usually you do "rdrand % <some-number>" anyways, and in that case you will still get zeroes. True, your result might be skewed by 1/(maxint/some-number) but I guess that's not a big problem in practice

33m agoHN ↗

I always wonder how hardware bugs like this happen with the sheer amount of hardware validation that's done. It'd be fascinating to know how it slipped through the cracks, though I know almost nothing about this side of the industry sadly

31m agoHN ↗

So what? The point is to be non predictable not to pick all the numbers in the range with exactly the same probability. Would it be a problem if it never generated 16542?

22m agoHN ↗

What are you talking about? The point is in fact to pick all the numbers in the range with exactly the same probability.

See section 7.3.17 of the Intel SDM, and how NIST SP800-90A (which the SDM refers to) defines "random number".

15m agoHN ↗

Consider an 8-bit RNG.

By your argument, it would not be a problem if the RNG never generated 0. So, it must follow that it would also not be a problem if it never generated {1, 2, 3, ..., 253}.

That means that our RNG now only generates the values 254 and 255. Which of the values is generated is unpredictable on any given call. However, 7 of the 8 output bits are now always fixed and so completely predictable. Can you imagine how an attacker could exploit that?

Failing to generate only the number 0 is a weaker version of the same class of flaw.

15m agoHN ↗

The OP says they discovered this on a Zen 2, which is not covered by that bulletin (?)

16m agoHN ↗

Chased a similar bug in a KDF once and only caught it by histogramming the 16 bit draws, statistical suites never flagged it.

5m agoHN ↗

This is why I use, in security critical contents of my software (where the numbers have to be computationally infeasible to produce), a type of random number generator called an XOF (extendable-output function).

It takes entropy from multiple different sources, makes it all input to the XOF, then the XOF uses cryptography to output a stream that has as much entropy as the combined entropy of all of its sources of randomness. So if an XOF, for example, takes 100 runs of rdrand16, along with the system time in microseconds and the number of milliseconds between receiving 100 packets over the network, the XOF will output a completely random stream without artifacts like never returning 0x0000, even if rdrand16 never outputs 0x0000.