flat assembler
Message board for the users of flat assembler.

Index > Linux > AMD's random number generator can't generate a 0 (+ app)

Author
Thread Post new topic Reply to topic
Jessé



Joined: 03 May 2025
Posts: 101
Location: Brazil
Jessé 11 May 2026, 05:13
Recently, while doing some assembly code to render data intro charts, and using 'rdrand' and 'rdseed' to provide that data to the displayed, I've figured out by accident what appears to be a bug (problem) only with AMD processors (maybe Zen2 only problem): they can't generate a number 0 at a given size! Running the same programs on an Intel processor, and the 0's are there with no problem.

You can help me figure out this by using my application to seek for any 0 number generated, and maybe post your results at this forum thread...

I also must mention that this application is a very deep showcase on how to control and render data to the console screen at arbitrary positions, which I remember someone here was trying to achieve the same under Linux cli, and he asked for help on this subject before.

Attached, I've provided that exact chart test application that showcases the AMD's RNG 0 problem: you'll probably, on an AMD host, never see the first bar change colors from green (which uses a TSC method I've created to generate random numbers), and also never see the base chart scale up from 0. On Intel processor, no problem, and the chart scale its base (minimum) beyond 0. The first bar renders how many zeroes are being generated by rdrand (red), rdseed (blue) and TSC-custom technique (green), as well as other bars render the other 65535 numbers from the 16-bit space.
Note: it requires fastcall_v1 macro kit if anyone wants to compile and test it as is.

Cheers!


Description: Test application. To fix it, change rdrand and rdseed lines to generate either to 32-bit or 64-bit registers, while keeping 16-bit data to be gathered for the graph display (graph is still rendering 16-bit data).
Download
Filename: gtk4-bargraph.tar.gz
Filesize: 7.25 KB
Downloaded: 9 Time(s)


_________________
jesse6
Post 11 May 2026, 05:13
View user's profile Send private message Visit poster's website Reply with quote
Jessé



Joined: 03 May 2025
Posts: 101
Location: Brazil
Jessé 11 May 2026, 05:16
So far, my results...


Description:
Filesize: 23.67 KB
Viewed: 245 Time(s)

AMD_no_0_captura_de_tela_20260511_021302.png


Post 11 May 2026, 05:16
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20976
Location: In your JS exploiting you and your system
revolution 11 May 2026, 05:28
Do the lowest 16-bits ever equal all-zero for 32/64-bit outputs?
Post 11 May 2026, 05:28
View user's profile Send private message Visit poster's website Reply with quote
Jessé



Joined: 03 May 2025
Posts: 101
Location: Brazil
Jessé 11 May 2026, 05:36
Yes, when using either 32-bit or 64-bit number, the lowest portion can output a zero, as I suggested on the attached example file as a modification to fix the problem.
But a true zero (fitting the requested size), on AMD, never happens.
Post 11 May 2026, 05:36
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20976
Location: In your JS exploiting you and your system
revolution 11 May 2026, 05:41
I hope this is not something stupid from AMD that decided zero is not a random number.

Maybe some C?O person executed RDRAND, got zero, declared it was broken and made the engineers "fix" it. Razz
Post 11 May 2026, 05:41
View user's profile Send private message Visit poster's website Reply with quote
Jessé



Joined: 03 May 2025
Posts: 101
Location: Brazil
Jessé 11 May 2026, 06:05
Haha, good point, I was thinking the same when this problem has presented itself to me.
I'll probably will e-mail AMD about this, and if they answered, I'll be back here to share what they said.
Post 11 May 2026, 06:05
View user's profile Send private message Visit poster's website Reply with quote
sylware



Joined: 23 Oct 2020
Posts: 576
Location: Marseille/France
sylware 11 May 2026, 10:22
At the time I was wandering in information system security, there was that rule of thumb: never ever use hardware accelerated crypto...
Post 11 May 2026, 10:22
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20976
Location: In your JS exploiting you and your system
revolution 11 May 2026, 11:36
For trusted hardware: Hardware accelerated crypto is definitely the way to go IMO.

For untrusted hardware: Don't do any crypto with it, software or hardware.

For best security with RDRAND, it might be backdoored, it might not. IDK, but never use it in isolation, always mix it with other sources. It doesn't hurt to add non-random data into an already random seed. It isn't possible to un-random a random value with non-randomness, it just mixes up the random bits a bit more.

If the application isn't for crypto then none of this matters, use RDRAND for anything. Go for it.


Last edited by revolution on 12 May 2026, 11:35; edited 1 time in total
Post 11 May 2026, 11:36
View user's profile Send private message Visit poster's website Reply with quote
sylware



Joined: 23 Oct 2020
Posts: 576
Location: Marseille/France
sylware 11 May 2026, 12:31
'trusted hardware' does not exist, unless it is YOUR hardware, of YOUR design (based on best know how), with tight control of the manufacturing process.
Post 11 May 2026, 12:31
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1217
Location: Russia
macomics 11 May 2026, 15:41
sylware wrote:
'trusted hardware' does not exist, unless it is YOUR hardware, of YOUR design (based on best know how), with tight control of the manufacturing process.
Even in this case, you will simply be mistaken in thinking that the hardware has no vulnerabilities.
Post 11 May 2026, 15:41
View user's profile Send private message Reply with quote
sylware



Joined: 23 Oct 2020
Posts: 576
Location: Marseille/France
sylware 12 May 2026, 11:17
I said 'trusted hardware', not trusted hardware................

We all know "trusted" hardware does not exist, it is a spectrum: "trusted" is actually some amount of "trust" decided based on some contexts and specifics.

At the time, when I was wandering in information system security groups: all this 'security hardware' was rumored to have flaws: entropy/maths/bugs/etc which users cannot cleanly fix, or actually even fix.
Post 12 May 2026, 11:17
View user's profile Send private message Reply with quote
alCoPaUL



Joined: 20 Jun 2023
Posts: 8
Location: NYC
alCoPaUL 13 May 2026, 05:04
maybe because any number multiplied by zero is zero and any number divided by zero is overflow...
Post 13 May 2026, 05:04
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.