Generating better random numbers in C with the help of /dev/urandom (practical-random) and (s)rand (pseudo-random)

Order of Operations

  • First load in 88-bits worth of /dev/urandom practical-random data into an initial seed buffer variable
  • Next feed in the first 32-bits from the seed variable to the srand() pseudo-random initialization function
  • Then use the rand() pseudo-random function to initially mix in random bytes into throughout the seed buffer
  • When the user calls for a random byte, start with a pseudo-random byte and XOR in every seed practical-random byte
    • In the same loop, XOR in a new pseudo-random bytes into the seed practical-random bytes ready for the next call

[C Snippet]

Source Code: https://github.com/stoops/vpn/blob/main/lib/rnd.c

~

Leave a comment