home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / sci / crypt / 7065 < prev    next >
Encoding:
Internet Message Format  |  1993-01-21  |  3.6 KB

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!sdd.hp.com!hp-cv!ogicse!verdix!islabs!fasttech!zeke
  2. From: zeke@fasttech.com (Bohdan Tashchuk)
  3. Newsgroups: sci.crypt
  4. Subject: Re: Getting random numbers from timing events?
  5. Message-ID: <1993Jan21.094510.2963@fasttech.com>
  6. Date: 21 Jan 93 09:45:10 GMT
  7. Article-I.D.: fasttech.1993Jan21.094510.2963
  8. References: <1993Jan17.160641.10711@ulysses.att.com> <1993Jan19.205254.12451dave@tygra.Michigan.COM> <1993Jan20.181024.26975@ulysses.att.com> <1jk77nINNeh3@darkstar.UCSC.EDU>
  9. Organization: Fast Technology   Beaverton, OR
  10. Lines: 62
  11.  
  12. In <1jk77nINNeh3@darkstar.UCSC.EDU> speth@cats.ucsc.edu (James Gustave) writes:
  13.  
  14. >  I need a source for truly random numbers for an encryption program I'm
  15. >working on.  I was thinking of using PGP's approach and time keyboard input
  16. >with a fast timer, then use the low-order 8-bits as a random number.  I'm
  17. >working on a Mac, so I'd like to use key and mouse events.  How can I tell
  18. >if the numbers I'm getting are good enough to be considered cryptographically
  19. >random?
  20.  
  21. When I wanted some random hex digits I wrote myself a similar little program
  22. that ran under dos. It's a little easier for me to understand than pgp's,
  23. because it doesn't have so many #ifdefs (ie, not as portable). Fortunately
  24. TurboC has calls that allow a spin variable to be incremented between key
  25. presses. Here is the inner loop:
  26.  
  27.     for (;;) {
  28.         for (spins = 0; bioskey(1) == 0; spins++)
  29.         ;
  30.         if (spins > 10000)
  31.         printf("%X %c", (spins & 0xf), (count++ % 16) ? ' ' : '\n');
  32.         else
  33.         printf("\a");
  34.         bioskey(0);
  35.     }
  36.  
  37. This code tests for > 10000 spins of the wait loop. If the key is pressed
  38. before then, the digit is invalid. Someone more pedantic than I will
  39. probably be concerned about the inherent bias, since I use the low 4 bits
  40. of the number of spins, and 10000 isn't divided evenly by 16.
  41.  
  42. The important thing to me is that value of 10000. On my machine it works out
  43. to about 1 second of real time per random digit. I don't know how much lower
  44. this value could go before I was uncomfortable with the non-randomness.
  45. I'd be worried with values less than about 1000. I haven't studied pgp
  46. carefully enough to figure out the threshold below which it discards values
  47. with the similar method it uses.
  48.  
  49. But the real reason I'm writing this is to basically agree with you about
  50. the mouse and key events. You should hook in some sort of similar routine
  51. in your Mac, and discard input events that occur too close together. The
  52. result should be quite random. You need to make sure that Multifinder
  53. and init's don't switch away control at inappropriate times and somehow
  54. bias this method.
  55.  
  56. Since I read netnews so much each day, the ideal for me would be to hack
  57. something like this into nn. Each time I hit a key I generate a few more
  58. random bits.
  59.  
  60. I too would like to hear comments about this. Specifically, given a method
  61. like this, how long of a delay is "long enough" for very good randomness?
  62. I realize there are specific tests that can be run on the resulting numbers,
  63. but I'd like to hear people's intuition about it.
  64.  
  65. Another idea would be to take all the Usenet traffic that comes into my
  66. machine and continuously xor it into a file that's about 1 MB in size.
  67. Things would be pretty random after a few weeks of news. You would need
  68. to correct for various biases. For example, almost all traffic is ascii,
  69. so that means that hi bits won't be set and control characters will be
  70. pretty much non-existent. But the end result should still be pretty
  71. darned random. The purists won't like this method since it should
  72. theoretically be possible for someone monitoring my uucp line to figure
  73. out the result file.
  74.