🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: sci.crypt
Article #2719

PGP 2.1 uses a constant "random" prefix

#2719
From: Juha Sarlin
Date: Mon, 04 Jan 1993 15:42
88 lines
3190 bytes
The first block in the IDEA-encrypted part of a message is supposed to
contain random data.  In most cases PGP 2.1 uses the very non-random
pseudorand() function to generate this data.  For example, encryption
with the command "pgp -e foo prz" always gives this data in the first
block: DC 19 22 C7 98 E5 BE F3.  One way to improve the randomness
would be to initialize the randseed variable with something more
unpredictable than the currently used constant.  Unfortunately this
would still give only 256 different values, because the least
significant byte from pseudorand() has a cycle length of 256.

The patch below replaces the pseudorand() function with a little
better one.  It might be even better to use something like the
idearand() function instead.

*** 1.1	1992/12/27 15:28:45
--- random.c	1993/01/04 14:04:43
***************
*** 43,44 ****
--- 43,85 ----
  */
+ #define MINIMAL_STANDARD_PSEUDORANDOM
+ #ifdef MINIMAL_STANDARD_PSEUDORANDOM
+ /**
+  ** Minimal Standard Pseudo-Random Number Generator
+  **
+  ** Author: Fuat C. Baran, Columbia University, 1988
+  **
+  ** Based on code in "Random Number Generators: Good Ones are Hard to Find",
+  ** by Stephen K. Park and Keith W. Miller in Communications of the ACM,
+  ** 31, 10 (Oct. 1988) pp. 1192-1201.
+  **
+  ** Requirements: maxint must be 2^31 -1 or larger.
+  **/
+ 
+ /* some constants we need */
+ #define A 16807
+ #define M 2147483647			/* Mersenne prime 2^31 -1 */
+ #define Q 127773			/* M div A (M / A) */
+ #define R 2836				/* M mod A (M % A) */
+ 
+ int pseudorand(void)
+ {
+ 	long hi, lo;
+ #ifdef DEBUG
+ 	static int seed = 1;
+ #else
+ 	static int seed = 0;
+ 	if (!seed) {
+ 		seed = clock();
+ #ifdef UNIX
+ 		seed += getpid();
+ #endif
+ 	}
+ #endif
+ 	hi = seed / Q;
+ 	lo = seed % Q;
+ 	if ((seed = A * lo - R * hi) <= 0)
+ 		seed += M;
+ 	return seed;
+ }
+ #else
  static int randseed=0; /* used only by pseudorand() function. */
***************
*** 49,50 ****
--- 90,92 ----
  }	/* pseudorand */
+ #endif
  
*** 1.1	1992/12/27 15:10:44
--- system.c	1993/01/04 13:25:41
***************
*** 336,337 ****
--- 336,338 ----
  	struct rusage ru;
+ 	struct timeval t;
  
***************
*** 338,340 ****
  	getrusage(RUSAGE_SELF, &ru);
! 	return ru.ru_utime.tv_sec + ru.ru_utime.tv_usec +
  		ru.ru_stime.tv_sec + ru.ru_stime.tv_usec +
--- 339,342 ----
  	getrusage(RUSAGE_SELF, &ru);
! 	gettimeofday(&t, NULL);
! 	return t.tv_usec + ru.ru_utime.tv_sec + ru.ru_utime.tv_usec +
  		ru.ru_stime.tv_sec + ru.ru_stime.tv_usec +
--
Juha Sarlin   juha@elixir.e.kth.se or juha@tds.kth.se
Technical Details
Message-ID: <JUHA.93Jan4164258@elixir.elixir.e.kth.se>
Path: arc1-ca.pugleaf.net!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

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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
From: juha@elixir.elixir.e.kth.se (Juha Sarlin)
Newsgroups: sci.crypt,alt.security.pgp
Subject: PGP 2.1 uses a constant "random" prefix
Message-ID: <JUHA.93Jan4164258@elixir.elixir.e.kth.se>
Date: 4 Jan 93 15:42:58 GMT
Sender: usenet@kth.se (Usenet)
Organization: School of EE, Royal Institute of Technology, Sweden
Lines: 88
Nntp-Posting-Host: elixir.e.kth.se