Skip to content

Instantly share code, notes, and snippets.

@defuse
Created March 20, 2017 23:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save defuse/49883a55e70e6927d3327d5da42e1c7c to your computer and use it in GitHub Desktop.
Save defuse/49883a55e70e6927d3327d5da42e1c7c to your computer and use it in GitHub Desktop.
Test OpenSSL RSA Random Number Generator
#!/bin/bash
# primes.sh -- @DefuseSec
echo -n >/tmp/primes.txt
# Generate 1000 primes.
for i in {1..500}; do
# Use 192-bit keys for speed (could potentially mask RNG bugs that only affect bigger keys)
openssl genrsa 192 2>/dev/null | \
openssl rsa -text 2>/dev/null |\
sed 'N;s/:\n//g' | sed 'N;s/:\n//g'| sed 'N;s/:\n//g' | sed 'N;s/:\n//g' | sed 'N;s/:\n//g' |\
grep prime | sed 's/prime[12]//g' | sed 's/[ :]//g' >> /tmp/primes.txt
done
sort /tmp/primes.txt | uniq -c | sort -snr | head -n 10
echo "..."
@defuse
Copy link
Author

defuse commented Mar 21, 2017

I ran it for 100,000 total primes on up-to-date Debian and Arch and there were no duplicates found. I'll run it for 1,000,000 total primes just to see.

The slide that inspired me to write this seemed to need 10s of millions of primes to see a collision though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment