‹ BackHN Continuity

Thread

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

288 points · 220 comments · BruceEel

  1. strenholme · · focus · HN ↗
    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.

    1. stingraycharles · · focus · HN ↗
      Isn’t this effectively what systems like /dev/(u)rand do? Pool multiple random sources together to hedge against these things?

      I fail to see why one should either rely on a single random source nor roll their own.

      1. strenholme · · focus · HN ↗
        Yes, /dev/(u)random is supposed to do that, but what if there’s a bug in a kernel (e.g. some embedded system which may not even be running Linux) which causes /dev/(u)ramdom to be less than secure? There’s also issues where, for example, it may no longer be possible to read /dev/(u)random after putting the process in a chroot() sandbox (chroot() isn’t defined in POSIX so its behavior is not guaranteed to be consistent across multiple operating systems).

        getrandom() is often times suggested, but alas isn’t a standardized function, i.e. it’s not part of the POSIX specification. Considering how the C23 changes to the C specification caused a lot of perfectly good C code to no longer compile, I’m very anal about sticking to specs; I use '-std=C99' for my code these days (even though it can compile as C23 code) and stick to POSIX functions (except chroot() and setgroups(), but both of those predate POSIX, and even here I have a compile-time option to compile my code without those non-POSIX syscalls).

        The code using a secure XOF (the algorithm was developed by the same team which later on made SHA-3, and includes people who helped make AES) has been around for nearly two decades (the code where I roll my own RNG to make secure random numbers has been around for over 25 years, but used AES before XOFs existed) and not one security problem has found with the RNG code has ever been found. [1] “Don’t roll your own RNG” is a suggestion, but it is possible to do so securely if one knows what they are doing (i.e. they have read Applied Cryptography and keep current with cryptographic developments).

        For anything vibe coded (my code is 100% human written, for the record), rolling one’s own RNG is a really bad idea.

        [1] There was a theoretical issue with cache timing attacks over two decades ago, so I put mitigations in place, and then chose to use an XOF for newer code.

        [2] There was an issue where a separate implementation I made of this XOF would generate incorrect test vectors in clang, but only at some optimization levels. I now test the XOF in both GCC and clang at multiple optimization levels to make sure it acts correctly.

        1. boltzmann64 · · focus · HN ↗
          i remember some linux kernel dev got ousted by the community because he/she wanted to not implement a backdoor that would compromise the results of /dev/urandom.
          1. akerl_ · · focus · HN ↗
            Who?
            1. Vvector · · focus · HN ↗
              I have no idea about the claim of a backdoor. But here is the source:

              Matt Mackall: "It's worth noting that the maintainer of record (me) for the Linux RNG quit the project about two years ago precisely because Linus decided to include a patch from Intel to allow their unauditable RdRand to bypass the entropy pool over my strenuous objections. "

              <a href="https:&#x2F;&#x2F;cryptome.wikileaks.org&#x2F;2013&#x2F;07&#x2F;intel-bed-nsa.htm?utm_source=chatgpt.com" rel="nofollow">https:&#x2F;&#x2F;cryptome.wikileaks.org&#x2F;2013&#x2F;07&#x2F;intel-bed-nsa.htm?utm...

              1. matja · · focus · HN ↗
                The fact that Intel Bull Mountain (code name for Secure Key Technology), and NSA&#x27;s BULLRUN program share the name &quot;bull&quot; is a complete coincidence. I&#x27;m sure.
                1. tptacek · · focus · HN ↗
                  You know there are people who actually reason this way.
                  1. Joel_Mckay · · focus · HN ↗
                    On many systems like Raspberry Pi the &lt;v5.6 kernel &#x2F;dev&#x2F;random or &#x2F;dev&#x2F;urandom lacked sufficient entropy to properly deploy wifi hostapd WPA2&#x2F;WPA3 services.

                    Instead, people used haveged to workaround the issue. Not a conspiracy by some dude, but rather just more budget hardware limitations.

                    Don&#x27;t worry about it, there are lots of real dubious things people do already. =3

                    1. akerl_ · · focus · HN ↗
                      Did you mean to comment this somewhere else? It doesn&#x27;t really seem connected to this comment branch.
                      1. Joel_Mckay · · focus · HN ↗
                        No, the recollection of &#x2F;dev&#x2F;random having an issue was correct, but attributing it the some malicious dude is wrong.

                        I don&#x27;t like piling on people that engage in good faith. Best regards =3

                        1. akerl_ · · focus · HN ↗
                          Nobody in this thread has attributed anything to &quot;some malicious dude&quot;.
                          1. Joel_Mckay · · focus · HN ↗
                            You don&#x27;t recall asking boltzmann64 for any details akerl_ ?

                            Perhaps it is time to get outside for a walk to lower stress levels. =3

                            1. akerl_ · · focus · HN ↗
                              I think you&#x27;ve pretty significantly misread the thread.
                              1. didiexjeifjj · · focus · HN ↗
                                You forgot: =3
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.