1997-11-18 15:06:00 +01:00
|
|
|
/* random.c - random number generator
|
1998-02-24 19:50:46 +01:00
|
|
|
* Copyright (C) 1998 Free Software Foundation, Inc.
|
1997-11-18 15:06:00 +01:00
|
|
|
*
|
1998-12-23 13:41:40 +01:00
|
|
|
* This file is part of GnuPG.
|
1997-11-18 15:06:00 +01:00
|
|
|
*
|
1998-12-23 13:41:40 +01:00
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
1997-11-18 15:06:00 +01:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
1998-12-23 13:41:40 +01:00
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
1997-11-18 15:06:00 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
*/
|
|
|
|
|
1998-03-09 22:44:06 +01:00
|
|
|
|
|
|
|
/****************
|
1998-05-13 19:53:36 +02:00
|
|
|
* This random number generator is modelled after the one described
|
|
|
|
* in Peter Gutmann's Paper: "Software Generation of Practically
|
|
|
|
* Strong Random Numbers".
|
1998-03-09 22:44:06 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
1997-11-18 15:06:00 +01:00
|
|
|
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1998-01-02 21:40:10 +01:00
|
|
|
#include <assert.h>
|
1997-11-18 15:06:00 +01:00
|
|
|
#include <errno.h>
|
1998-02-03 13:09:20 +01:00
|
|
|
#include <string.h>
|
1998-12-10 20:20:47 +01:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
1998-12-29 14:47:31 +01:00
|
|
|
#include <unistd.h>
|
1998-12-10 20:20:47 +01:00
|
|
|
#ifdef HAVE_GETHRTIME
|
|
|
|
#include <sys/times.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_GETTIMEOFDAY
|
|
|
|
#include <sys/times.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_GETRUSAGE
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#endif
|
1997-11-18 15:06:00 +01:00
|
|
|
#include "util.h"
|
1998-03-09 22:44:06 +01:00
|
|
|
#include "rmd.h"
|
1998-01-16 22:15:24 +01:00
|
|
|
#include "ttyio.h"
|
1998-01-28 17:09:43 +01:00
|
|
|
#include "i18n.h"
|
1998-11-25 12:52:41 +01:00
|
|
|
#include "random.h"
|
1998-05-13 19:53:36 +02:00
|
|
|
#include "rand-internal.h"
|
1998-11-25 12:52:41 +01:00
|
|
|
#include "dynload.h"
|
1997-11-18 15:06:00 +01:00
|
|
|
|
1998-03-09 22:44:06 +01:00
|
|
|
|
1998-12-29 14:47:31 +01:00
|
|
|
#ifndef RAND_MAX /* for SunOS */
|
|
|
|
#define RAND_MAX 32767
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1998-03-09 22:44:06 +01:00
|
|
|
#if SIZEOF_UNSIGNED_LONG == 8
|
|
|
|
#define ADD_VALUE 0xa5a5a5a5a5a5a5a5
|
|
|
|
#elif SIZEOF_UNSIGNED_LONG == 4
|
|
|
|
#define ADD_VALUE 0xa5a5a5a5
|
|
|
|
#else
|
|
|
|
#error weird size for an unsigned long
|
|
|
|
#endif
|
|
|
|
|
1998-11-25 12:52:41 +01:00
|
|
|
#define BLOCKLEN 64 /* hash this amount of bytes */
|
|
|
|
#define DIGESTLEN 20 /* into a digest of this length (rmd160) */
|
|
|
|
/* poolblocks is the number of digests which make up the pool
|
|
|
|
* and poolsize must be a multiple of the digest length
|
|
|
|
* to make the AND operations faster, the size should also be
|
|
|
|
* a multiple of ulong
|
|
|
|
*/
|
|
|
|
#define POOLBLOCKS 30
|
|
|
|
#define POOLSIZE (POOLBLOCKS*DIGESTLEN)
|
|
|
|
#if (POOLSIZE % SIZEOF_UNSIGNED_LONG)
|
|
|
|
#error Please make sure that poolsize is a multiple of ulong
|
|
|
|
#endif
|
|
|
|
#define POOLWORDS (POOLSIZE / SIZEOF_UNSIGNED_LONG)
|
|
|
|
|
1998-03-09 22:44:06 +01:00
|
|
|
|
|
|
|
static int is_initialized;
|
1997-12-12 13:03:58 +01:00
|
|
|
#define MASK_LEVEL(a) do {if( a > 2 ) a = 2; else if( a < 0 ) a = 0; } while(0)
|
1998-03-09 22:44:06 +01:00
|
|
|
static char *rndpool; /* allocated size is POOLSIZE+BLOCKLEN */
|
|
|
|
static char *keypool; /* allocated size is POOLSIZE+BLOCKLEN */
|
|
|
|
static size_t pool_readpos;
|
|
|
|
static size_t pool_writepos;
|
|
|
|
static int pool_filled;
|
1998-03-19 16:27:29 +01:00
|
|
|
static int pool_balance;
|
1998-03-09 22:44:06 +01:00
|
|
|
static int just_mixed;
|
|
|
|
|
|
|
|
static int secure_alloc;
|
|
|
|
static int quick_test;
|
1998-11-25 12:52:41 +01:00
|
|
|
static int faked_rng;
|
1997-12-12 13:03:58 +01:00
|
|
|
|
|
|
|
|
1998-03-09 22:44:06 +01:00
|
|
|
static void read_pool( byte *buffer, size_t length, int level );
|
1998-11-25 12:52:41 +01:00
|
|
|
static void add_randomness( const void *buffer, size_t length, int source );
|
|
|
|
static void random_poll(void);
|
1998-12-14 21:22:42 +01:00
|
|
|
static void read_random_source( int requester, size_t length, int level);
|
|
|
|
static int gather_faked( void (*add)(const void*, size_t, int), int requester,
|
|
|
|
size_t length, int level );
|
1998-01-16 22:15:24 +01:00
|
|
|
|
|
|
|
|
1998-03-09 22:44:06 +01:00
|
|
|
static void
|
1999-02-16 14:16:33 +01:00
|
|
|
initialize(void)
|
1998-03-09 22:44:06 +01:00
|
|
|
{
|
|
|
|
/* The data buffer is allocated somewhat larger, so that
|
|
|
|
* we can use this extra space (which is allocated in secure memory)
|
|
|
|
* as a temporary hash buffer */
|
|
|
|
rndpool = secure_alloc ? m_alloc_secure_clear(POOLSIZE+BLOCKLEN)
|
|
|
|
: m_alloc_clear(POOLSIZE+BLOCKLEN);
|
|
|
|
keypool = secure_alloc ? m_alloc_secure_clear(POOLSIZE+BLOCKLEN)
|
|
|
|
: m_alloc_clear(POOLSIZE+BLOCKLEN);
|
|
|
|
is_initialized = 1;
|
1999-02-10 17:22:40 +01:00
|
|
|
cipher_modules_constructor();
|
1998-03-09 22:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
secure_random_alloc()
|
|
|
|
{
|
|
|
|
secure_alloc = 1;
|
|
|
|
}
|
|
|
|
|
1998-05-13 19:53:36 +02:00
|
|
|
|
1998-01-16 22:15:24 +01:00
|
|
|
int
|
|
|
|
quick_random_gen( int onoff )
|
|
|
|
{
|
1998-11-25 12:52:41 +01:00
|
|
|
int last;
|
|
|
|
|
1998-12-14 21:22:42 +01:00
|
|
|
read_random_source(0,0,0); /* init */
|
1998-11-25 12:52:41 +01:00
|
|
|
last = quick_test;
|
1998-01-16 22:15:24 +01:00
|
|
|
if( onoff != -1 )
|
|
|
|
quick_test = onoff;
|
1998-11-25 12:52:41 +01:00
|
|
|
return faked_rng? 1 : last;
|
1998-01-16 22:15:24 +01:00
|
|
|
}
|
|
|
|
|
1997-11-18 15:06:00 +01:00
|
|
|
|
|
|
|
/****************
|
1998-04-14 19:51:16 +02:00
|
|
|
* Fill the buffer with LENGTH bytes of cryptographically strong
|
1997-11-18 15:06:00 +01:00
|
|
|
* random bytes. level 0 is not very strong, 1 is strong enough
|
|
|
|
* for most usage, 2 is good for key generation stuff but may be very slow.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
randomize_buffer( byte *buffer, size_t length, int level )
|
|
|
|
{
|
1999-04-18 10:18:52 +02:00
|
|
|
char *p = get_random_bits( length*8, level, 1 );
|
1998-08-07 10:53:38 +02:00
|
|
|
memcpy( buffer, p, length );
|
|
|
|
m_free(p);
|
1997-11-18 15:06:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-01-12 11:20:24 +01:00
|
|
|
int
|
|
|
|
random_is_faked()
|
|
|
|
{
|
|
|
|
if( !is_initialized )
|
|
|
|
initialize();
|
|
|
|
return faked_rng || quick_test;
|
|
|
|
}
|
1998-03-19 16:27:29 +01:00
|
|
|
|
|
|
|
/****************
|
|
|
|
* Return a pointer to a randomized buffer of level 0 and LENGTH bits
|
1998-08-07 10:53:38 +02:00
|
|
|
* caller must free the buffer.
|
|
|
|
* Note: The returned value is rounded up to bytes.
|
1998-03-19 16:27:29 +01:00
|
|
|
*/
|
|
|
|
byte *
|
|
|
|
get_random_bits( size_t nbits, int level, int secure )
|
|
|
|
{
|
1999-04-06 20:04:55 +02:00
|
|
|
byte *buf, *p;
|
1998-03-19 16:27:29 +01:00
|
|
|
size_t nbytes = (nbits+7)/8;
|
|
|
|
|
1998-08-11 19:29:34 +02:00
|
|
|
if( quick_test && level > 1 )
|
|
|
|
level = 1;
|
1998-03-19 16:27:29 +01:00
|
|
|
MASK_LEVEL(level);
|
1998-07-14 19:10:28 +02:00
|
|
|
buf = secure && secure_alloc ? m_alloc_secure( nbytes ) : m_alloc( nbytes );
|
1999-04-06 20:04:55 +02:00
|
|
|
for( p = buf; nbytes > 0; ) {
|
|
|
|
size_t n = nbytes > POOLSIZE? POOLSIZE : nbytes;
|
|
|
|
read_pool( p, n, level );
|
|
|
|
nbytes -= n;
|
|
|
|
p += n;
|
|
|
|
}
|
1998-03-19 16:27:29 +01:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-03-09 22:44:06 +01:00
|
|
|
/****************
|
|
|
|
* Mix the pool
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
mix_pool(byte *pool)
|
|
|
|
{
|
|
|
|
char *hashbuf = pool + POOLSIZE;
|
|
|
|
char *p, *pend;
|
|
|
|
int i, n;
|
|
|
|
RMD160_CONTEXT md;
|
|
|
|
|
|
|
|
rmd160_init( &md );
|
|
|
|
#if DIGESTLEN != 20
|
|
|
|
#error must have a digest length of 20 for ripe-md-160
|
|
|
|
#endif
|
|
|
|
/* loop over the pool */
|
|
|
|
pend = pool + POOLSIZE;
|
|
|
|
memcpy(hashbuf, pend - DIGESTLEN, DIGESTLEN );
|
|
|
|
memcpy(hashbuf+DIGESTLEN, pool, BLOCKLEN-DIGESTLEN);
|
|
|
|
rmd160_mixblock( &md, hashbuf);
|
|
|
|
memcpy(pool, hashbuf, 20 );
|
|
|
|
|
|
|
|
p = pool;
|
|
|
|
for( n=1; n < POOLBLOCKS; n++ ) {
|
|
|
|
memcpy(hashbuf, p, DIGESTLEN );
|
|
|
|
|
|
|
|
p += DIGESTLEN;
|
|
|
|
if( p+DIGESTLEN+BLOCKLEN < pend )
|
|
|
|
memcpy(hashbuf+DIGESTLEN, p+DIGESTLEN, BLOCKLEN-DIGESTLEN);
|
|
|
|
else {
|
|
|
|
char *pp = p+DIGESTLEN;
|
|
|
|
for(i=DIGESTLEN; i < BLOCKLEN; i++ ) {
|
|
|
|
if( pp >= pend )
|
|
|
|
pp = pool;
|
|
|
|
hashbuf[i] = *pp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rmd160_mixblock( &md, hashbuf);
|
|
|
|
memcpy(p, hashbuf, 20 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
read_pool( byte *buffer, size_t length, int level )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
ulong *sp, *dp;
|
|
|
|
|
|
|
|
if( length >= POOLSIZE )
|
|
|
|
BUG(); /* not allowed */
|
|
|
|
|
1998-03-19 16:27:29 +01:00
|
|
|
/* for level 2 make sure that there is enough random in the pool */
|
|
|
|
if( level == 2 && pool_balance < length ) {
|
|
|
|
size_t needed;
|
|
|
|
|
|
|
|
if( pool_balance < 0 )
|
|
|
|
pool_balance = 0;
|
|
|
|
needed = length - pool_balance;
|
|
|
|
if( needed > POOLSIZE )
|
|
|
|
BUG();
|
1998-12-14 21:22:42 +01:00
|
|
|
read_random_source( 3, needed, 2 );
|
1998-03-19 16:27:29 +01:00
|
|
|
pool_balance += needed;
|
|
|
|
}
|
|
|
|
|
1998-03-09 22:44:06 +01:00
|
|
|
/* make sure the pool is filled */
|
|
|
|
while( !pool_filled )
|
|
|
|
random_poll();
|
1998-06-25 12:19:08 +02:00
|
|
|
|
1998-03-09 22:44:06 +01:00
|
|
|
/* do always a fast random poll */
|
|
|
|
fast_random_poll();
|
|
|
|
|
1998-06-25 12:19:08 +02:00
|
|
|
if( !level ) { /* no need for cryptographic strong random */
|
|
|
|
/* create a new pool */
|
|
|
|
for(i=0,dp=(ulong*)keypool, sp=(ulong*)rndpool;
|
|
|
|
i < POOLWORDS; i++, dp++, sp++ )
|
|
|
|
*dp = *sp + ADD_VALUE;
|
|
|
|
/* must mix both pools */
|
1998-03-09 22:44:06 +01:00
|
|
|
mix_pool(rndpool);
|
1998-06-25 12:19:08 +02:00
|
|
|
mix_pool(keypool);
|
|
|
|
memcpy( buffer, keypool, length );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* mix the pool (if add_randomness() didn't it) */
|
|
|
|
if( !just_mixed )
|
|
|
|
mix_pool(rndpool);
|
|
|
|
/* create a new pool */
|
|
|
|
for(i=0,dp=(ulong*)keypool, sp=(ulong*)rndpool;
|
|
|
|
i < POOLWORDS; i++, dp++, sp++ )
|
|
|
|
*dp = *sp + ADD_VALUE;
|
|
|
|
/* and mix both pools */
|
|
|
|
mix_pool(rndpool);
|
|
|
|
mix_pool(keypool);
|
|
|
|
/* read the required data
|
|
|
|
* we use a readpoiter to read from a different postion each
|
|
|
|
* time */
|
|
|
|
while( length-- ) {
|
|
|
|
*buffer++ = keypool[pool_readpos++];
|
|
|
|
if( pool_readpos >= POOLSIZE )
|
|
|
|
pool_readpos = 0;
|
|
|
|
pool_balance--;
|
|
|
|
}
|
|
|
|
if( pool_balance < 0 )
|
|
|
|
pool_balance = 0;
|
|
|
|
/* and clear the keypool */
|
|
|
|
memset( keypool, 0, POOLSIZE );
|
1998-03-09 22:44:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************
|
|
|
|
* Add LENGTH bytes of randomness from buffer to the pool.
|
1998-11-25 12:52:41 +01:00
|
|
|
* source may be used to specify the randomness source.
|
1998-03-09 22:44:06 +01:00
|
|
|
*/
|
1998-11-25 12:52:41 +01:00
|
|
|
static void
|
1998-03-09 22:44:06 +01:00
|
|
|
add_randomness( const void *buffer, size_t length, int source )
|
|
|
|
{
|
1999-05-17 22:03:24 +02:00
|
|
|
const byte *p = buffer;
|
|
|
|
|
1998-03-09 22:44:06 +01:00
|
|
|
if( !is_initialized )
|
|
|
|
initialize();
|
|
|
|
while( length-- ) {
|
1999-05-17 22:03:24 +02:00
|
|
|
rndpool[pool_writepos++] = *p++;
|
1998-03-09 22:44:06 +01:00
|
|
|
if( pool_writepos >= POOLSIZE ) {
|
1998-05-13 19:53:36 +02:00
|
|
|
if( source > 1 )
|
|
|
|
pool_filled = 1;
|
1998-03-09 22:44:06 +01:00
|
|
|
pool_writepos = 0;
|
|
|
|
mix_pool(rndpool);
|
|
|
|
just_mixed = !length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-11-25 12:52:41 +01:00
|
|
|
static void
|
|
|
|
random_poll()
|
|
|
|
{
|
1998-12-14 21:22:42 +01:00
|
|
|
read_random_source( 2, POOLSIZE/5, 1 );
|
1998-11-25 12:52:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
fast_random_poll()
|
|
|
|
{
|
1998-12-14 21:22:42 +01:00
|
|
|
static void (*fnc)( void (*)(const void*, size_t, int), int) = NULL;
|
1998-11-25 12:52:41 +01:00
|
|
|
static int initialized = 0;
|
|
|
|
|
|
|
|
if( !initialized ) {
|
|
|
|
if( !is_initialized )
|
|
|
|
initialize();
|
|
|
|
initialized = 1;
|
|
|
|
fnc = dynload_getfnc_fast_random_poll();
|
|
|
|
}
|
1998-12-10 20:20:47 +01:00
|
|
|
if( fnc ) {
|
1998-12-14 21:22:42 +01:00
|
|
|
(*fnc)( add_randomness, 1 );
|
1998-12-10 20:20:47 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fall back to the generic function */
|
|
|
|
#if HAVE_GETHRTIME
|
|
|
|
{ hrtime_t tv;
|
|
|
|
tv = gethrtime();
|
|
|
|
add_randomness( &tv, sizeof(tv), 1 );
|
|
|
|
}
|
|
|
|
#elif HAVE_GETTIMEOFDAY
|
|
|
|
{ struct timeval tv;
|
|
|
|
if( gettimeofday( &tv, NULL ) )
|
|
|
|
BUG();
|
|
|
|
add_randomness( &tv.tv_sec, sizeof(tv.tv_sec), 1 );
|
|
|
|
add_randomness( &tv.tv_usec, sizeof(tv.tv_usec), 1 );
|
|
|
|
}
|
|
|
|
#else /* use times */
|
|
|
|
{ struct tms buf;
|
|
|
|
times( &buf );
|
|
|
|
add_randomness( &buf, sizeof buf, 1 );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_GETRUSAGE
|
|
|
|
{ struct rusage buf;
|
|
|
|
if( getrusage( RUSAGE_SELF, &buf ) )
|
|
|
|
BUG();
|
|
|
|
add_randomness( &buf, sizeof buf, 1 );
|
|
|
|
memset( &buf, 0, sizeof buf );
|
|
|
|
}
|
|
|
|
#endif
|
1998-11-25 12:52:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
1998-12-14 21:22:42 +01:00
|
|
|
read_random_source( int requester, size_t length, int level )
|
1998-11-25 12:52:41 +01:00
|
|
|
{
|
1998-12-14 21:22:42 +01:00
|
|
|
static int (*fnc)(void (*)(const void*, size_t, int), int,
|
|
|
|
size_t, int) = NULL;
|
1998-11-25 12:52:41 +01:00
|
|
|
if( !fnc ) {
|
|
|
|
if( !is_initialized )
|
|
|
|
initialize();
|
|
|
|
fnc = dynload_getfnc_gather_random();
|
|
|
|
if( !fnc ) {
|
|
|
|
faked_rng = 1;
|
|
|
|
fnc = gather_faked;
|
|
|
|
}
|
1998-12-14 21:22:42 +01:00
|
|
|
if( !requester && !length && !level )
|
|
|
|
return; /* init only */
|
1998-11-25 12:52:41 +01:00
|
|
|
}
|
1998-12-14 21:22:42 +01:00
|
|
|
if( (*fnc)( add_randomness, requester, length, level ) < 0 )
|
|
|
|
log_fatal("No way to gather entropy for the RNG\n");
|
1998-11-25 12:52:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
1998-12-14 21:22:42 +01:00
|
|
|
gather_faked( void (*add)(const void*, size_t, int), int requester,
|
|
|
|
size_t length, int level )
|
1998-11-25 12:52:41 +01:00
|
|
|
{
|
|
|
|
static int initialized=0;
|
1998-12-14 21:22:42 +01:00
|
|
|
size_t n;
|
|
|
|
char *buffer, *p;
|
1998-11-25 12:52:41 +01:00
|
|
|
|
|
|
|
if( !initialized ) {
|
|
|
|
log_info(_("WARNING: using insecure random number generator!!\n"));
|
|
|
|
tty_printf(_("The random number generator is only a kludge to let\n"
|
1998-12-10 20:20:47 +01:00
|
|
|
"it run - it is in no way a strong RNG!\n\n"
|
1998-11-25 12:52:41 +01:00
|
|
|
"DON'T USE ANY DATA GENERATED BY THIS PROGRAM!!\n\n"));
|
|
|
|
initialized=1;
|
|
|
|
#ifdef HAVE_RAND
|
|
|
|
srand(make_timestamp()*getpid());
|
|
|
|
#else
|
|
|
|
srandom(make_timestamp()*getpid());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1998-12-14 21:22:42 +01:00
|
|
|
p = buffer = m_alloc( length );
|
|
|
|
n = length;
|
1998-11-25 12:52:41 +01:00
|
|
|
#ifdef HAVE_RAND
|
1998-12-14 21:22:42 +01:00
|
|
|
while( n-- )
|
|
|
|
*p++ = ((unsigned)(1 + (int) (256.0*rand()/(RAND_MAX+1.0)))-1);
|
1998-11-25 12:52:41 +01:00
|
|
|
#else
|
1998-12-14 21:22:42 +01:00
|
|
|
while( n-- )
|
|
|
|
*p++ = ((unsigned)(1 + (int) (256.0*random()/(RAND_MAX+1.0)))-1);
|
1998-11-25 12:52:41 +01:00
|
|
|
#endif
|
1998-12-14 21:22:42 +01:00
|
|
|
add_randomness( buffer, length, requester );
|
|
|
|
m_free(buffer);
|
|
|
|
return 0; /* okay */
|
1998-11-25 12:52:41 +01:00
|
|
|
}
|
|
|
|
|