Hardware Random Number Generator
Posted: Mon Aug 25, 2008 8:52 am
I have been attempting to create a random number generator for the past few days using clock drift between the system time ticks (accurate to 1 millisecond in the language I'm writing in ((QBASIC)) ), and the CPU clock cycles available to the application I wrote per second.
While I was able to obtain reasonably good results (see my website at http://www.markfh11q.net/generate.php?id=0&file=math ), I'm thinking I need to go in another direction. Here are the reasons.
1.) The cycles/second don't vary as much as I like. While I am using the modulus 26 to generate numbers 0-25, there is a fair amount of bias that must be corrected (using the Von Neumann method).
2.) When the application is run under Windows, the CPU cycles tend to level out at a constant, halting the output of the program (because of the bias control method).
So, I figured: why not try the same thing with a 556 timer chip?
Basically, I would connect the two outputs to two individual port addresses on the computer. Then, QBASIC would read off the binary from their ouput (0 for 0V and 1 for the voltage allowed that port).
One half of the timer will run fairly slow, but not slow enough to make generation of the random numbers too slow. The other half would run extremely fast, so that small variations are more detectable. Variations, I think, are inevitable, due to noise and variations of the chips. The two independent circuits could also be separated physically to different areas of the CPU case to produce more variation.
The program starts a loop on a tick (bit 1) of the slow timer. During this loop, it counts the ticks on the fast timer. When the loop is finished, it takes this count MOD 2 and assigns that to a binary output in a pair. The process is repeated to obtain the second bit in the pair. If the bits are equal, the pair is discarded. If they differ, the first bit in the pair is stored in the final binary sequence.
This continues until a certain number of bits is received, preferably user-defined. The bits are then translated into a long integer which is then fed as a seed to QBASICS random number generator, which is used to generate two large blum primes.
The process repeats until another binary number of the specified length is reached. This number is fed as the seed value into the Blum Blum Shub pseudorandom-number generator, which then outputs the final values.
All of this counts on the two 556 timers being able to generate enough randomness for the process. Does anybody see any problems with this? I was going to use crystals for the oscillation, but they seemed too precise to work well.
That's it. Comments? Suggestions? Thanks for reading. All of this is going to be used for a small cryptography suite I'm building, which handles plaintext messages using a onetime-pad cipher.
While I was able to obtain reasonably good results (see my website at http://www.markfh11q.net/generate.php?id=0&file=math ), I'm thinking I need to go in another direction. Here are the reasons.
1.) The cycles/second don't vary as much as I like. While I am using the modulus 26 to generate numbers 0-25, there is a fair amount of bias that must be corrected (using the Von Neumann method).
2.) When the application is run under Windows, the CPU cycles tend to level out at a constant, halting the output of the program (because of the bias control method).
So, I figured: why not try the same thing with a 556 timer chip?
Basically, I would connect the two outputs to two individual port addresses on the computer. Then, QBASIC would read off the binary from their ouput (0 for 0V and 1 for the voltage allowed that port).
One half of the timer will run fairly slow, but not slow enough to make generation of the random numbers too slow. The other half would run extremely fast, so that small variations are more detectable. Variations, I think, are inevitable, due to noise and variations of the chips. The two independent circuits could also be separated physically to different areas of the CPU case to produce more variation.
The program starts a loop on a tick (bit 1) of the slow timer. During this loop, it counts the ticks on the fast timer. When the loop is finished, it takes this count MOD 2 and assigns that to a binary output in a pair. The process is repeated to obtain the second bit in the pair. If the bits are equal, the pair is discarded. If they differ, the first bit in the pair is stored in the final binary sequence.
This continues until a certain number of bits is received, preferably user-defined. The bits are then translated into a long integer which is then fed as a seed to QBASICS random number generator, which is used to generate two large blum primes.
The process repeats until another binary number of the specified length is reached. This number is fed as the seed value into the Blum Blum Shub pseudorandom-number generator, which then outputs the final values.
All of this counts on the two 556 timers being able to generate enough randomness for the process. Does anybody see any problems with this? I was going to use crystals for the oscillation, but they seemed too precise to work well.
That's it. Comments? Suggestions? Thanks for reading. All of this is going to be used for a small cryptography suite I'm building, which handles plaintext messages using a onetime-pad cipher.