aboutsummaryrefslogtreecommitdiffstats
path: root/cipher/random.c
diff options
context:
space:
mode:
Diffstat (limited to 'cipher/random.c')
-rw-r--r--cipher/random.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/cipher/random.c b/cipher/random.c
index f865693b4..a95e7e50d 100644
--- a/cipher/random.c
+++ b/cipher/random.c
@@ -40,7 +40,6 @@ static struct cache cache[3];
#define MASK_LEVEL(a) do {if( a > 2 ) a = 2; else if( a < 0 ) a = 0; } while(0)
-static int open_device( const char *name, int minor );
static void fill_buffer( byte *buffer, size_t length, int level );
/****************
@@ -70,6 +69,7 @@ get_random_byte( int level )
+#ifdef HAVE_DEV_RANDOM
static int
open_device( const char *name, int minor )
@@ -149,3 +149,26 @@ the OS a chance to collect more entropy! (Need %d more bytes)\n", length );
} while( length );
}
+#else /* not HAVE_DEV_RANDOM */
+
+
+static void
+fill_buffer( byte *buffer, size_t length, int level )
+{
+ static int initialized=0;
+
+ if( !initialized ) {
+ log_info("warning: using insecure random number generator!!\n");
+ tty_printf("The random number generator is only a kludge to let\n"
+ "it compile - it is in no way a strong RNG!\n\n"
+ "DON'T USE ANY DATA GENERATED BY THIS PROGRAM!!\n\n");
+ initialized=1;
+ srand(make_timestamp()*getpid());
+ }
+
+ while( length-- )
+ *buffer++ = ((unsigned)(1 + (int) (256.0*rand()/(RAND_MAX+1.0)))-1);
+}
+
+#endif
+