flat assembler - AMD's random number generator can't generate a 0 (+ app) (templates/phpVB2/phpVB2.css) flat assembler Message board for the users of flat assembler. (https://board.flatassembler.net/index.php) Home (https://board.flatassembler.net/search.php) Search (https://board.flatassembler.net/profile.php?mode=register) Register (https://board.flatassembler.net/privmsg.php?folder=inbox) Log in to check your private messages (https://board.flatassembler.net/login.php) Log in () (https://board.flatassembler.net/index.php) Index > (https://board.flatassembler.net/forum.php?f=4) Linux > AMD's random number generator can't generate a 0 (+ app) Goto page 1 , (https://board.flatassembler.net/topic.php?t=24261&postdays=0&postorder=asc&start=20) 2 (https://board.flatassembler.net/topic.php?t=24261&postdays=0&postorder=asc&start=20) Next Author Thread (https://board.flatassembler.net/post.php?mode=newtopic&f=4) (Post new topic) (https://board.flatassembler.net/post.php?mode=reply&t=24261) (Reply to topic) Jessé Joined: 03 May 2025Posts: 151Location: Brazil Jessé 11 May 2026, 05:13 (AMD's random number generator can't generate a 0 (+ app)) 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 (https://github.com/Jesse-6/random-fryer) 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 (https://github.com/Jesse-6/fastcall_v1) 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). () (https://board.flatassembler.net/download.php?id=9865) Download Filename: gtk4-bargraph.tar.gz Filesize: 7.25 KB Downloaded: 161 Time(s) _________________ (https://github.com/Jesse-6) jesse6 (https://board.flatassembler.net/topic.php?p=248263#248263) (Post) (Post) 11 May 2026, 05:13 (https://board.flatassembler.net/profile.php?mode=viewprofile&u=8211) (View user's profile) (View user's profile) (https://board.flatassembler.net/privmsg.php?mode=post&u=8211) (Send private message) (Send private message) (https://github.com/Jesse-6) (Visit poster's website) (Visit poster's website) (https://board.flatassembler.net/post.php?mode=quote&p=248263) (Reply with quote) (Reply with quote) Jessé Joined: 03 May 2025Posts: 151Location: Brazil Jessé 11 May 2026, 05:16 () So far, my results... Description: Filesize: 23.67 KB Viewed: 47638 Time(s) (AMD_no_0_captura_de_tela_20260511_021302.png) (https://board.flatassembler.net/topic.php?p=248264#248264) (Post) (Post) 11 May 2026, 05:16 (https://board.flatassembler.net/profile.php?mode=viewprofile&u=8211) (View user's profile) (View user's profile) (https://board.flatassembler.net/privmsg.php?mode=post&u=8211) (Send private message) (Send private message) (https://github.com/Jesse-6) (Visit poster's website) (Visit poster's website) (https://board.flatassembler.net/post.php?mode=quote&p=248264) (Reply with quote) (Reply with quote) revolution When all else fails, read the sourceJoined: 24 Aug 2004Posts: 21119Location: 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? (https://board.flatassembler.net/topic.php?p=248265#248265) (Post) (Post) 11 May 2026, 05:28 (https://board.flatassembler.net/profile.php?mode=viewprofile&u=908) (View user's profile) (View user's profile) (https://board.flatassembler.net/privmsg.php?mode=post&u=908) (Send private message) (Send private message) (https://html.duckduckgo.com/) (Visit poster's website) (Visit poster's website) (https://board.flatassembler.net/post.php?mode=quote&p=248265) (Reply with quote) (Reply with quote) Jessé Joined: 03 May 2025Posts: 151Location: 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. (https://board.flatassembler.net/topic.php?p=248266#248266) (Post) (Post) 11 May 2026, 05:36 (https://board.flatassembler.net/profile.php?mode=viewprofile&u=8211) (View user's profile) (View user's profile) (https://board.flatassembler.net/privmsg.php?mode=post&u=8211) (Send private message) (Send private message) (https://github.com/Jesse-6) (Visit poster's website) (Visit poster's website) (https://board.flatassembler.net/post.php?mode=quote&p=248266) (Reply with quote) (Reply with quote) revolution When all else fails, read the sourceJoined: 24 Aug 2004Posts: 21119Location: 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) (https://board.flatassembler.net/topic.php?p=248267#248267) (Post) (Post) 11 May 2026, 05:41 (https://board.flatassembler.net/profile.php?mode=viewprofile&u=908) (View user's profile) (View user's profile) (https://board.flatassembler.net/privmsg.php?mode=post&u=908) (Send private message) (Send private message) (https://html.duckduckgo.com/) (Visit poster's website) (Visit poster's website) (https://board.flatassembler.net/post.php?mode=quote&p=248267) (Reply with quote) (Reply with quote) Jessé Joined: 03 May 2025Posts: 151Location: 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. (https://board.flatassembler.net/topic.php?p=248268#248268) (Post) (Post) 11 May 2026, 06:05 (https://board.flatassembler.net/profile.php?mode=viewprofile&u=8211) (View user's profile) (View user's profile) (https://board.flatassembler.net/privmsg.php?mode=post&u=8211) (Send private message) (Send private message) (https://github.com/Jesse-6) (Visit poster's website) (Visit poster's website) (https://board.flatassembler.net/post.php?mode=quote&p=248268) (Reply with quote) (Reply with quote) sylware Joined: 23 Oct 2020Posts: 656Location: 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... (https://board.flatassembler.net/topic.php?p=248272#248272) (Post) (Post) 11 May 2026, 10:22 (https://board.flatassembler.net/profile.php?mode=viewprofile&u=7666) (View user's profile) (View user's profile) (https://board.flatassembler.net/privmsg.php?mode=post&u=7666) (Send private message) (Send private message) (https://board.flatassembler.net/post.php?mode=quote&p=248272) (Reply with quote) (Reply with quote) revolution When all else fails, read the sourceJoined: 24 Aug 2004Posts: 21119Location: 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 (https://board.flatassembler.net/topic.php?p=248276#248276) (Post) (Post) 11 May 2026, 11:36 (https://board.flatassembler.net/profile.php?mode=viewprofile&u=908) (View user's profile) (View user's profile) (https://board.flatassembler.net/privmsg.php?mode=post&u=908) (Send private message) (Send private message) (https://html.duckduckgo.com/) (Visit poster's website) (Visit poster's website) (https://board.flatassembler.net/post.php?mode=quote&p=248276) (Reply with quote) (Reply with quote) sylware Joined: 23 Oct 2020Posts: 656Location: 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. (https://board.flatassembler.net/topic.php?p=248278#248278) (Post) (Post) 11 May 2026, 12:31 (https://board.flatassembler.net/profile.php?mode=viewprofile&u=7666) (View user's profile) (View user's profile) (https://board.flatassembler.net/privmsg.php?mode=post&u=7666) (Send private message) (Send private message) (https://board.flatassembler.net/post.php?mode=quote&p=248278) (Reply with quote) (Reply with quote) macomics Joined: 26 Jan 2021Posts: 1237Location: 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. (https://board.flatassembler.net/topic.php?p=248282#248282) (Post) (Post) 11 May 2026, 15:41 (https://board.flatassembler.net/profile.php?mode=viewprofile&u=7708) (View user's profile) (View user's profile) (https://board.flatassembler.net/privmsg.php?mode=post&u=7708) (Send private message) (Send private message) (https://board.flatassembler.net/post.php?mode=quote&p=248282) (Reply with quote) (Reply with quote) sylware Joined: 23 Oct 2020Posts: 656Location: 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. (https://board.flatassembler.net/topic.php?p=248298#248298) (Post) (Post) 12 May 2026, 11:17 (https://board.flatassembler.net/profile.php?mode=viewprofile&u=7666) (View user's profile) (View user's profile) (https://board.flatassembler.net/privmsg.php?mode=post&u=7666) (Send private message) (Send private message) (https://board.flatassembler.net/post.php?mode=quote&p=248298) (Reply with quote) (Reply with quote) alCoPaUL Joined: 20 Jun 2023Posts: 22Location: NYC alCoPaUL 13 May 2026, 05:04 () maybe because any number multiplied by zero is zero and any number divided by zero is overflow... (https://board.flatassembler.net/topic.php?p=248313#248313) (Post) (Post) 13 May 2026, 05:04 (https://board.flatassembler.net/profile.php?mode=viewprofile&u=7956) (View user's profile) (View user's profile) (https://board.flatassembler.net/privmsg.php?mode=post&u=7956) (Send private message) (Send private message) (http://www.perrun.su) (Visit poster's website) (Visit poster's website) (https://board.flatassembler.net/post.php?mode=quote&p=248313) (Reply with quote) (Reply with quote) Jessé Joined: 03 May 2025Posts: 151Location: Brazil Jessé 15 May 2026, 10:38 () alCoPaUL wrote: maybe because any number multiplied by zero is zero and any number divided by zero is overflow... How about Intel results, which seems normal (0s being generated at requested sizes)? _________________ (https://github.com/Jesse-6) jesse6 Last edited by Jessé on 15 May 2026, 11:00; edited 1 time in total (https://board.flatassembler.net/topic.php?p=248348#248348) (Post) (Post) 15 May 2026, 10:38 (https://board.flatassembler.net/profile.php?mode=viewprofile&u=8211) (View user's profile) (View user's profile) (https://board.flatassembler.net/privmsg.php?mode=post&u=8211) (Send private message) (Send private message) (https://github.com/Jesse-6) (Visit poster's website) (Visit poster's website) (https://board.flatassembler.net/post.php?mode=quote&p=248348) (Reply with quote) (Reply with quote) Jessé Joined: 03 May 2025Posts: 151Location: Brazil Jessé 15 May 2026, 11:00 () Just to update you about this situation, AMD has replied me, but it seems that the guy from their team misread my results entirely, or used AI to formulate that reply (because his answer seems too similar to the one I got from ChatGPT when I checked if someone had previously figured this out before me). So I reply again with a mode detailed reply, and also a snippet of the code that rises the problem. (https://board.flatassembler.net/topic.php?p=248349#248349) (Post) (Post) 15 May 2026, 11:00 (https://board.flatassembler.net/profile.php?mode=viewprofile&u=8211) (View user's profile) (View user's profile) (https://board.flatassembler.net/privmsg.php?mode=post&u=8211) (Send private message) (Send private message) (https://github.com/Jesse-6) (Visit poster's website) (Visit poster's website) (https://board.flatassembler.net/post.php?mode=quote&p=248349) (Reply with quote) (Reply with quote) alCoPaUL Joined: 20 Jun 2023Posts: 22Location: NYC alCoPaUL 15 May 2026, 14:21 () maybe amd thought of the eventual use of their rng, which is not just spewing any number directly from a routine but a part of a formula or something like that.. moreover, amd invented x86_64.. _________________ Assembly Language Quines (https://bitbucket.org/alcopavl/ia-64_quine/src/main/) https://bitbucket.org/alcopavl/ia-64_quine/src/main/ (https://bitbucket.org/alcopavl/x86x64/src/main/) https://bitbucket.org/alcopavl/x86x64/src/main/ (https://github.com/alcopaul/beth_GviLLErMo_GIMO) https://github.com/alcopaul/beth_GviLLErMo_GIMO (https://board.flatassembler.net/topic.php?p=248351#248351) (Post) (Post) 15 May 2026, 14:21 (https://board.flatassembler.net/profile.php?mode=viewprofile&u=7956) (View user's profile) (View user's profile) (https://board.flatassembler.net/privmsg.php?mode=post&u=7956) (Send private message) (Send private message) (http://www.perrun.su) (Visit poster's website) (Visit poster's website) (https://board.flatassembler.net/post.php?mode=quote&p=248351) (Reply with quote) (Reply with quote) AsmGuru62 Joined: 28 Jan 2004Posts: 1824Location: Toronto, Canada AsmGuru62 15 May 2026, 15:39 () I am curious about the quality of random numbers generated by such CPU opcodes. Anyone did any testing? Like the famous "Big Crush" battery of tests? (https://board.flatassembler.net/topic.php?p=248353#248353) (Post) (Post) 15 May 2026, 15:39 (https://board.flatassembler.net/profile.php?mode=viewprofile&u=430) (View user's profile) (View user's profile) (https://board.flatassembler.net/privmsg.php?mode=post&u=430) (Send private message) (Send private message) (mailto:asmguru62@hotmail.com) (Send e-mail) (Send e-mail) (https://board.flatassembler.net/post.php?mode=quote&p=248353) (Reply with quote) (Reply with quote) sylware Joined: 23 Oct 2020Posts: 656Location: Marseille/France sylware 16 May 2026, 11:15 () I don't talk for recent hardware, but at the time, anything generated from those had entropy flaws which could be propagated to brute force algorithms and then reduced dramatically the breaking time, namely, to something reasonable on a big computer. Heard about prime numbers farming too (mostly via crypto currency). But I only did scratch the surface here, maybe a fluke. (https://board.flatassembler.net/topic.php?p=248362#248362) (Post) (Post) 16 May 2026, 11:15 (https://board.flatassembler.net/profile.php?mode=viewprofile&u=7666) (View user's profile) (View user's profile) (https://board.flatassembler.net/privmsg.php?mode=post&u=7666) (Send private message) (Send private message) (https://board.flatassembler.net/post.php?mode=quote&p=248362) (Reply with quote) (Reply with quote) Jessé Joined: 03 May 2025Posts: 151Location: Brazil Jessé 23 May 2026, 17:43 () In addition to being an assembly language programmer, I am also an electronics engineer/technician (with probably "similar level of experience", or even more), and therefore, with knowledge of both areas, I can think of hundreds of different ways of being able to build something that generates random numbers, and of high quality (for example, based on white noise generators, which are the thermal noise of semiconductors, try to predict this with supercomputers). Therefore, I don't think this is by far the most difficult part to do on an x86-64 processor, for the Engineering elite, present in the Intel and AMD teams, for example. Furthermore, I must say that I have not yet received any further feedback from AMD regarding the case. But they have already escalated my case internally with them, so I am still here waiting for a precise update from them, to share it here. And, since 9 days before posting here, until the present moment, not a single 0 came out of the 2 AMDs that I had access to! With the new update I made to my (https://github.com/Jesse-6/random-fryer) application to test this, it is now also possible to benchmark the random number generator, and it is also now possible to run the test on processors that do not have the 'rdseed' instruction. As for the benchmark, it is surprising how different the results are between different processors (e.g.: a Core i5 from 2012 generates 12.6 M numbers per second, while a Core i7 7700 from 2017 generates "only" 750 k numbers per second, and my AMD Ryzen 7 around 2.6 M numbers per second, and the AMD generator being completely inert to clock variation, and the Core i5 from 2012 100% dependent on the clock, as it seemed to me in the tests I did). Which leads me to realize that the random number generator circuit must have large differences, and probably completely different versions/revisions, even for models from the same manufacturer. So far, I also have not found decent information on how their RNG unit works. (https://board.flatassembler.net/topic.php?p=248475#248475) (Post) (Post) 23 May 2026, 17:43 (https://board.flatassembler.net/profile.php?mode=viewprofile&u=8211) (View user's profile) (View user's profile) (https://board.flatassembler.net/privmsg.php?mode=post&u=8211) (Send private message) (Send private message) (https://github.com/Jesse-6) (Visit poster's website) (Visit poster's website) (https://board.flatassembler.net/post.php?mode=quote&p=248475) (Reply with quote) (Reply with quote) revolution When all else fails, read the sourceJoined: 24 Aug 2004Posts: 21119Location: In your JS exploiting you and your system revolution 24 May 2026, 00:56 () Jessé wrote: So far, I also have not found decent information on how their RNG unit works. When the RDRAND instruction was first introduced I saw some Intel literature about the internal construction. It had an astable noise generator (a single bit), feeding into a clocked sampler, then a de-bias circuit, into a serial shifter. That created an internal 128-bit seed. From the seed there was a high speed AES CSPRNG in counter mode that output the bits for RDRAND, and got reseeded periodically by the internal seed when it had enough bits accumulated. The RDSEED instruction would output some raw bits from the internal seed directly. The circuits may have changed since then, so maybe today they are totally different. Back then RDRAND could generate output at the full CPU clock rate, RDSEED was slower. There was discussion at the time about it not being "properly" random because of the PRNG in the pipeline, but no one could show any measurable problem. There are lots of places to hide a backdoor in there, and it would be extremely hard to detect without reverse engineering the silicon. (https://board.flatassembler.net/topic.php?p=248478#248478) (Post) (Post) 24 May 2026, 00:56 (https://board.flatassembler.net/profile.php?mode=viewprofile&u=908) (View user's profile) (View user's profile) (https://board.flatassembler.net/privmsg.php?mode=post&u=908) (Send private message) (Send private message) (https://html.duckduckgo.com/) (Visit poster's website) (Visit poster's website) (https://board.flatassembler.net/post.php?mode=quote&p=248478) (Reply with quote) (Reply with quote) ttd3v Joined: 17 Sep 2026Posts: 16 ttd3v 19 Sep 2026, 00:37 () As far as I know, rdrand is supposed to be used as an entropy source of the kernel, so although the choice of AMD to set zero as invalid is very weird, I guess it's not supposed to be used as the main cryptographic RNG either way. I mean, if you need it for cryptographic purposes, the OS's cryptographic RNG might be more coherent. Also, if you need it for non-cryptographic purposes I guess that thing is negligible. (https://board.flatassembler.net/topic.php?p=249635#249635) (Post) (Post) 19 Sep 2026, 00:37 (https://board.flatassembler.net/profile.php?mode=viewprofile&u=8351) (View user's profile) (View user's profile) (https://board.flatassembler.net/privmsg.php?mode=post&u=8351) (Send private message) (Send private message) (https://codeberg.org/ttd3v) (Visit poster's website) (Visit poster's website) (https://board.flatassembler.net/post.php?mode=quote&p=249635) (Reply with quote) (Reply with quote) Display posts from previous: (0) All Posts (1) 1 Day (7) 7 Days (14) 2 Weeks (30) 1 Month (90) 3 Months (180) 6 Months (364) 1 Year (asc) Oldest First (desc) Newest First (https://board.flatassembler.net/post.php?mode=newtopic&f=4) (Post new topic) (https://board.flatassembler.net/post.php?mode=reply&t=24261) (Reply to topic) (topic.php@t=24261.html) Jump to: (-1) Select a forum (-1) (-1) Official (-1) ---------------- (27) Assembly (28) Peripheria (-1) (-1) General (-1) ---------------- (13) Main (23) Tutorials and Examples (2) DOS (3) Windows (4) Linux (17) Unix (12) MenuetOS (-1) (-1) Specific (-1) ---------------- (14) Macroinstructions (11) OS Construction (15) IDE Development (21) Projects and Ideas (22) Non-x86 architectures (19) High Level Languages (26) Programming Language Design (9) Compiler Internals (-1) (-1) Other (-1) ---------------- (7) Feedback (8) Heap (10) Test Area () Goto page 1 , (https://board.flatassembler.net/topic.php?t=24261&postdays=0&postorder=asc&start=20) 2 (https://board.flatassembler.net/topic.php?t=24261&postdays=0&postorder=asc&start=20) Next <(https://board.flatassembler.net/topic.php?t=24261&view=previous) Last Thread | (https://board.flatassembler.net/topic.php?t=24261&view=next) 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 (http://flatassembler.net/index.php) Main index (http://flatassembler.net/download.php) Download (http://flatassembler.net/docs.php) Documentation (http://flatassembler.net/examples.php) Examples (http://board.flatassembler.net/) Message board Copyright © 1999-2026, (mailto:tgrysztar@flatassembler.net) Tomasz Grysztar . Also on (https://github.com/tgrysztar) GitHub , (http://www.youtube.com/c/flatassembler) YouTube . Website powered by (https://2ton.com.au/rwasa/) (rwasa web server) rwasa .