home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / sci / crypt / 6351 < prev    next >
Encoding:
Internet Message Format  |  1993-01-04  |  3.1 KB

  1. Xref: sparky sci.crypt:6351 alt.security.pgp:451
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!spool.mu.edu!enterpoop.mit.edu!eru.mt.luth.se!kth.se!news.kth.se!juha
  3. From: juha@elixir.elixir.e.kth.se (Juha Sarlin)
  4. Newsgroups: sci.crypt,alt.security.pgp
  5. Subject: PGP 2.1 uses a constant "random" prefix
  6. Message-ID: <JUHA.93Jan4164258@elixir.elixir.e.kth.se>
  7. Date: 4 Jan 93 15:42:58 GMT
  8. Sender: usenet@kth.se (Usenet)
  9. Organization: School of EE, Royal Institute of Technology, Sweden
  10. Lines: 88
  11. Nntp-Posting-Host: elixir.e.kth.se
  12.  
  13. The first block in the IDEA-encrypted part of a message is supposed to
  14. contain random data.  In most cases PGP 2.1 uses the very non-random
  15. pseudorand() function to generate this data.  For example, encryption
  16. with the command "pgp -e foo prz" always gives this data in the first
  17. block: DC 19 22 C7 98 E5 BE F3.  One way to improve the randomness
  18. would be to initialize the randseed variable with something more
  19. unpredictable than the currently used constant.  Unfortunately this
  20. would still give only 256 different values, because the least
  21. significant byte from pseudorand() has a cycle length of 256.
  22.  
  23. The patch below replaces the pseudorand() function with a little
  24. better one.  It might be even better to use something like the
  25. idearand() function instead.
  26.  
  27. *** 1.1    1992/12/27 15:28:45
  28. --- random.c    1993/01/04 14:04:43
  29. ***************
  30. *** 43,44 ****
  31. --- 43,85 ----
  32.   */
  33. + #define MINIMAL_STANDARD_PSEUDORANDOM
  34. + #ifdef MINIMAL_STANDARD_PSEUDORANDOM
  35. + /**
  36. +  ** Minimal Standard Pseudo-Random Number Generator
  37. +  **
  38. +  ** Author: Fuat C. Baran, Columbia University, 1988
  39. +  **
  40. +  ** Based on code in "Random Number Generators: Good Ones are Hard to Find",
  41. +  ** by Stephen K. Park and Keith W. Miller in Communications of the ACM,
  42. +  ** 31, 10 (Oct. 1988) pp. 1192-1201.
  43. +  **
  44. +  ** Requirements: maxint must be 2^31 -1 or larger.
  45. +  **/
  46. + /* some constants we need */
  47. + #define A 16807
  48. + #define M 2147483647            /* Mersenne prime 2^31 -1 */
  49. + #define Q 127773            /* M div A (M / A) */
  50. + #define R 2836                /* M mod A (M % A) */
  51. + int pseudorand(void)
  52. + {
  53. +     long hi, lo;
  54. + #ifdef DEBUG
  55. +     static int seed = 1;
  56. + #else
  57. +     static int seed = 0;
  58. +     if (!seed) {
  59. +         seed = clock();
  60. + #ifdef UNIX
  61. +         seed += getpid();
  62. + #endif
  63. +     }
  64. + #endif
  65. +     hi = seed / Q;
  66. +     lo = seed % Q;
  67. +     if ((seed = A * lo - R * hi) <= 0)
  68. +         seed += M;
  69. +     return seed;
  70. + }
  71. + #else
  72.   static int randseed=0; /* used only by pseudorand() function. */
  73. ***************
  74. *** 49,50 ****
  75. --- 90,92 ----
  76.   }    /* pseudorand */
  77. + #endif
  78.   
  79. *** 1.1    1992/12/27 15:10:44
  80. --- system.c    1993/01/04 13:25:41
  81. ***************
  82. *** 336,337 ****
  83. --- 336,338 ----
  84.       struct rusage ru;
  85. +     struct timeval t;
  86.   
  87. ***************
  88. *** 338,340 ****
  89.       getrusage(RUSAGE_SELF, &ru);
  90. !     return ru.ru_utime.tv_sec + ru.ru_utime.tv_usec +
  91.           ru.ru_stime.tv_sec + ru.ru_stime.tv_usec +
  92. --- 339,342 ----
  93.       getrusage(RUSAGE_SELF, &ru);
  94. !     gettimeofday(&t, NULL);
  95. !     return t.tv_usec + ru.ru_utime.tv_sec + ru.ru_utime.tv_usec +
  96.           ru.ru_stime.tv_sec + ru.ru_stime.tv_usec +
  97. --
  98. Juha Sarlin   juha@elixir.e.kth.se or juha@tds.kth.se
  99.