Skip to content
DevMeme
2989 of 7590
Security Post #3301 · source on Telegram

When the PRNG is not CSPRNG

Description

A classic rage comic meme expressing horror at a fundamental security mistake. The image features a crudely drawn, black-and-white stick figure character with bulging, bloodshot eyes, screaming with hands on its face in a gesture of pure shock and disbelief. Above the character, white text with a black outline reads, 'OH MY GOOOOD!'. Below, the text continues, 'THAT'S NOT HOW YOU RANDOM!'. The original post caption provides the context: 'When someone suggests using a PRNG to generate a public/private keypair'. For senior developers, this is a relatable moment of witnessing a junior or uninformed colleague propose a catastrophic security flaw. Using a standard Pseudorandom Number Generator (PRNG), which can be predictable, for cryptographic key generation is a cardinal sin. Cryptography requires a Cryptographically Secure PRNG (CSPRNG) that provides sufficient entropy and unpredictability to ensure keys cannot be guessed or reverse-engineered

Comments

19
Anonymous ★ Top Pick Suggesting a standard PRNG for key generation is the fastest way to get your pull request comments to look like a CVE report
  1. Anonymous ★ Top Pick

    Suggesting a standard PRNG for key generation is the fastest way to get your pull request comments to look like a CVE report

  2. Anonymous

    Sure, seed rand() with time(NULL) and loop until you’ve built a 2048-bit RSA key - because 86 400 possible outcomes per day totally counts as entropy, right?

  3. Anonymous

    After 15 years in the industry, you've seen developers seed Math.random() with the current timestamp, use it for cryptographic keys, and my personal favorite - calling it in a loop expecting different results without understanding the underlying PRNG state. The real horror is when they defend it in the PR comments with 'but it works on my machine!'

  4. Anonymous

    Every senior engineer has witnessed the horror: a junior dev using `new Random(DateTime.Now.Ticks)` inside a loop, or seeding with `time(NULL)` in a tight iteration, generating the same 'random' number thousands of times per second. Even worse is seeing `Math.random()` used for security tokens or session IDs. The real nightmare? Finding out your production system's 'shuffle' algorithm has been deterministically returning the same sequence for three years because someone thought `Random(42)` made for 'reproducible randomness' in prod. Cryptographically secure randomness isn't just pedantry - it's the difference between a secure system and a $4.2M breach settlement

  5. Anonymous

    srand(time(NULL)) in prod: 86,400 'unique' seeds a day, zero surprises

  6. Anonymous

    If your “random” is sort(() => Math.random() - 0.5), the distribution is just “who gets paged”; use Fisher - Yates with a CSPRNG

  7. Anonymous

    rand()%N + time-based reseeding: the only algorithm that guarantees both non-uniform distribution and reproducible breaches

  8. @sylfn 5y

    int rand() { return 4; // chosen by a fair dice roll }

    1. Deleted Account 5y

      i see ps3 security right here

      1. @ZgGPuo8dZef58K6hxxGVj3Z2 5y

        That was my tought too but is this really from the PS3? Or is that just a meme?

        1. @sylfn 5y

          took from xkcd

          1. @ZgGPuo8dZef58K6hxxGVj3Z2 5y

            I see thanks

        2. Deleted Account 5y

          on some talk explaining how someone broke into ps3, there was a slide with exactly this code

        3. dev_meme 5y

          Just a meme

          1. @ZgGPuo8dZef58K6hxxGVj3Z2 5y

            What I tought 😂

      2. dev_meme 5y

        But this have almost nothing to do with ps3! Except the fact the signature scheme were hacked thanks to breaking underlaying alghotithm which were providing random numbers for signatures

        1. Deleted Account 5y

          well, yeah

        2. dev_meme 5y

          That's why we have Ed25519 scheme now and we are not using EdDSA anymore

          1. @chupasaurus 5y

            I think you've meant DSA/ECDSA as Ed25519 is an implementation of EdDSA

Use J and K for navigation