Top
Best
New

Posted by BruceEel 7 hours ago

AMD's random number generator can't generate a 0?(board.flatassembler.net)
168 points | 127 commentspage 2
Plainharbor21 5 hours ago||
[dead]
Ledgermellow 4 hours ago||
[dead]
deadbabe 4 hours ago||
I would be very concerned if an RNG simply produced a natural 0.
flexagoon 41 minutes ago||
Why would that be any more concerning than the RNG producing any other number?
flippingheck 3 hours ago||
I would be very concerned if an RNG simply produced a natural 1.
dmurray 3 hours ago||
I would be very concerned if an RNG simply produced a natural 0xf379aa46d1086bca.
throwawayffffas 5 hours ago||
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?
gnfargbl 4 hours ago||
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.

brookst 4 hours ago|||
This is the “what’s the big deal if I lost $100k in a casino, it’s really the same thing as if I had lost $5” argument.

I don’t think you can rebut “you only lose one of many values” with “it’s the same as only having one left”.

gnfargbl 4 hours ago||
We're talking about whether a modification of the expected probabilities changes the dynamics of the game. The example I gave was deliberately extreme, because that makes it easier to reason about.

If you want a casino example, then consider a roulette wheel that always lands on 36 but still pays out as usual. I think you'd want to play on it. Now consider one that always lands somewhere between 30 and 36. Still worth it, right? With careful bets and a good starting float you're still coming away from the table up (with a very high probability).

In fact for a roulette wheel you only need two dead pockets for the player to get an edge. Bias is exploitable.

brookst 2 hours ago||
Sure, but you’re pressing on the truth that a small modification taken to an extreme is a large modification.

When the original point was that a tiny fractional loss in an RNG is not going to make a practical difference. Which I believe is also true. And it is also true that a large loss in an RNG is catastrophic.

They can both be true.

And roulette is 2 out of 38, 5.2%. That’s 17 times more than the 1/256 here, which was already a simplification of the (I think) 1/65536 in question.

gnfargbl 47 minutes ago||
With respect, I think you're still missing my point, which is simply that bias introduces vulnerability. Without a real scenario to analyze, the scale doesn't really factor into the argument. A vulnerability is a vulnerability until proven mitigated.

> a tiny fractional loss in an RNG is not going to make a practical difference

I'm not so sure this is true. I don't think either of us is in a place to say whether this vulnerability has practical applications or not. A 1/65536 bias might seem like nothing important to you. It seems very far from nothing to me, in a world where an attacker can potentially generate terabytes of data.

BigTTYGothGF 2 hours ago||||
> So, it must follow

It certainly does not.

A never-zero RNG is something one should know about, so that it can be mitigated if necessary, but it's not inherently a dealbreaker.

throwawayffffas 4 hours ago|||
The value space goes from 2^16, 2^32, 2^64 to 2^16 - 1, 2^32 - 1, and 2^64 - 1 respectively.

The bug has zero practical impact.

gnfargbl 4 hours ago||
It is absolutely untrue that a biased RNG has "zero practical impact." Modern cryptography has plenty of examples of relatively small biases leading to breaks. Check out Bleichenbacher's attack, for instance.

You could be correct that the very small bias here is not enough to be exploitable. But, given the history around this, it would be wrong to handwave it away as trivial.

kqp 2 hours ago|||
“Pick all the numbers in the range with exactly the same probability” is a very important property of RNGs. Yes, skipping 16542 would be equally bad.

You can frame it around being “non predictable”, but then you need to define those words. It’s not, for example, a poker game where it’s trying to bluff you, right? It’s also not about just making predictions < 100% reliable and declaring victory. It must specifically make all predictions no better than random guessing, and that entails picking any number in range with equal probability, otherwise predictions like “it will be {hot spot}” or “it won’t be {cold spot}” do better than random chance. In this case, specifically, I can predict with 100% accuracy that the result won’t be 0, and that’s a flaw in its unpredictability. I can also predict a bunch of other things with slightly higher accuracy than random guessing, like that it will be odd or greater than max ÷ 2.

antiloper 4 hours ago|||
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".

IAmBroom 3 hours ago|||
"Random" is used by most people to mean "random with an even distribution".

A weighted die is still random, but with an uneven distribution. This is effectively a 2^16-sided, weighted die.

throwawayffffas 2 hours ago||
My argument to follow your analogy is.

It's not a 2^16-sided weighted die. But a 2^16 - 1 sided fair die.

I am not saying there is no bug. I am saying the bug has no practical impact.

Sure if you are that one guy that is getting these values raw from the instruction and comparing to zero for some purpose then you are in trouble. But I am pretty sure no one is doing that, especially given that the bug surfaced after 6 years of millions of users.

necovek 1 hour ago||
I can imagine someone doing a

  pick = rnrand16() - 0x7fff
  if pick > 0...
where these are not equally likely anymore (I may have an off-by-one anyway ;)).
swader999 4 hours ago|||
Betty from accounting will have words.
throwawayffffas 4 hours ago||
What does Betty from accounting care about RNGs?
swader999 3 hours ago||
There's an edge case somewhere that will affect a real user when you can't get a zero. Forecasting simulations perhaps?
Hugsbox 4 hours ago|||
That may well be a problem, yes.
wat10000 3 hours ago||
“Predictable” and “not pick all numbers in range with exactly the same probability” are synonyms here.
dark-star 5 hours ago||
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
adrian_b 3 hours ago|
If you want uniformly-distributed random numbers, computing the remainder works only when the modulus is a power of two.

Otherwise, a slightly more complicated algorithm is necessary, where you reject a range of numbers either before computing the remainder (to make the set of possible values a multiple of the modulus) or after computing the value modulo some power of two (to reject values greater than your target).

Besides these 2 variants based on the remainder of division of integers, there are also 2 corresponding algorithms using multiplication of the input interpreted as a fraction, followed by taking the integer part of the result.

ExoticPearTree 5 hours ago||
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.

blensor 5 hours ago||
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

ExoticPearTree 3 hours ago||
> You definitely would expect a roughly equal number of 0s as any other of those numbers since it's uniformly distributed.

How would random numbers be uniformly distributed?

Hugsbox 3 hours ago|||
Because each number is equally as likely as every other number. If you know you're more likely to get certain numbers, or in this case have no chance of getting certain other numbers, it is by definition _less random_.
IAmBroom 20 minutes ago||
No, that has nothing to do with randomness. It is however a different distribution than expected.

Think about the odds of a uranium atom decaying in a given second. Certainly a random event, yet for most seconds, the value is False, not True.

thinkingQueen 3 hours ago||||
So you think a weighted die is more random than a fair die? A uniform distribution means each outcome has equal probability; it doesn’t mean the outcome is predictable.
necovek 1 hour ago||||
With enough repetitions.

With a few (say 10, so 655360 runs), you will not get a uniform distribution, and some numbers (like 0) might not appear.

account42 3 hours ago||||
https://en.wikipedia.org/wiki/Discrete_uniform_distribution
zygentoma 5 hours ago|||
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.

matja 5 hours ago|||
Why would it be a normal distribution?
throawayonthe 5 hours ago||
should be a discrete uniform distribution right?
m_antis89 4 hours ago||
0 is not a number, it's undefined
flexagoon 36 minutes ago||
Are you a time traveler from the 5th century?
HackerThemAll 3 hours ago||
the what?
BigTTYGothGF 2 hours ago||
That's a thing some people used to believe, I guess some of them still do.
ZiiS 5 hours ago|
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.

jstanley 5 hours ago||
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?

ZiiS 4 hours ago||
In lots of scenarios I know the software used to generate the key; the only unknown is the random numbers used. If I am searching for weaknesses it is highly likely I would try keys with different seeds; zero, one, are going to me much more likely choices here then hoping I can guess the right values.
necovek 1 hour ago|||
If someone was using RDRAND16 to seed a PRNG, choosing to omit one single value (a zero) from the return value would not significantly improve the generated values, if at all.
ZiiS 1 hour ago||
Looked at another way; leaving out the zero also dosn't significantly hurt. If the is any risk if it breaking the PRNG why take the risk.
jstanley 2 hours ago|||
If the keys are selected uniformly at random why are 0 and 1 more likely than other values?
ZiiS 1 hour ago||
Because I don't want my test keys to be random/none reproducable, instead I will just used fixed seeds to see if any timing etc leeks.
jstanley 1 hour ago||
So what has that got to do with rdrand? I literally don't understand what you would get from preventing 0 as output?
dark-star 5 hours ago||
this is not how crypto works