Switch random_number() to always use the best entropy source for internal
client purposes. The RANDOM_SOURCE setting now only affects the $rand() scripting function. git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@357 13b04d17-f746-0410-82c6-800466cd88b0
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
[Changes 1.2c01]
|
[Changes 1.2c01]
|
||||||
|
|
||||||
|
* RANDOM_SOURCE now only affects the rand() scripting function. (caf)
|
||||||
|
|
||||||
* Make RANDOM_LOCAL_PORTS actually random. (caf)
|
* Make RANDOM_LOCAL_PORTS actually random. (caf)
|
||||||
|
|
||||||
* Show same message on local terminal as used in emergency exit QUIT. (caf)
|
* Show same message on local terminal as used in emergency exit QUIT. (caf)
|
||||||
|
|||||||
@@ -128,8 +128,10 @@ char * BX_strmpcat (char *, size_t, const char *, ...);
|
|||||||
char * chomp (char *);
|
char * chomp (char *);
|
||||||
size_t BX_ccspan (const char *, int);
|
size_t BX_ccspan (const char *, int);
|
||||||
u_char *BX_strcpy_nocolorcodes (u_char *, const u_char *);
|
u_char *BX_strcpy_nocolorcodes (u_char *, const u_char *);
|
||||||
|
unsigned long randm(unsigned long);
|
||||||
u_long BX_random_number (u_long);
|
unsigned long randt(unsigned long);
|
||||||
|
unsigned long randd(unsigned long);
|
||||||
|
unsigned long BX_random_number(unsigned long);
|
||||||
char * get_userhost (void);
|
char * get_userhost (void);
|
||||||
|
|
||||||
char * urlencode (const char *);
|
char * urlencode (const char *);
|
||||||
|
|||||||
@@ -1348,12 +1348,30 @@ BUILT_IN_FUNCTION(function_mid, word)
|
|||||||
BUILT_IN_FUNCTION(function_rand, word)
|
BUILT_IN_FUNCTION(function_rand, word)
|
||||||
{
|
{
|
||||||
long tempin;
|
long tempin;
|
||||||
|
unsigned long rand_n;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
GET_INT_ARG(tempin, word);
|
GET_INT_ARG(tempin, word);
|
||||||
if (tempin == 0)
|
|
||||||
tempin = (unsigned long) -1; /* This is cheating. :P */
|
switch (get_int_var(RANDOM_SOURCE_VAR))
|
||||||
result = random_number(0L) % tempin;
|
{
|
||||||
|
case 0:
|
||||||
|
default:
|
||||||
|
rand_n = randd(0);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
rand_n = randm(0);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
rand_n = randt(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tempin)
|
||||||
|
result = rand_n % tempin;
|
||||||
|
else
|
||||||
|
result = rand_n;
|
||||||
|
|
||||||
RETURN_INT(result);
|
RETURN_INT(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1365,7 +1383,9 @@ BUILT_IN_FUNCTION(function_rand, word)
|
|||||||
*/
|
*/
|
||||||
BUILT_IN_FUNCTION(function_srand, word)
|
BUILT_IN_FUNCTION(function_srand, word)
|
||||||
{
|
{
|
||||||
random_number((long) now);
|
/* randd() and randt() do not accept seeding */
|
||||||
|
randm((long)now);
|
||||||
|
|
||||||
RETURN_EMPTY;
|
RETURN_EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3132,7 +3132,7 @@ char * get_userhost (void)
|
|||||||
* to call it once to set the seed. Subsequent calls should use 'l'
|
* to call it once to set the seed. Subsequent calls should use 'l'
|
||||||
* as 0, and it will return a value.
|
* as 0, and it will return a value.
|
||||||
*/
|
*/
|
||||||
static unsigned long randm (unsigned long l)
|
unsigned long randm(unsigned long l)
|
||||||
{
|
{
|
||||||
/* patch from Sarayan to make $rand() better */
|
/* patch from Sarayan to make $rand() better */
|
||||||
static const long RAND_A = 16807L;
|
static const long RAND_A = 16807L;
|
||||||
@@ -3178,7 +3178,7 @@ static unsigned long randt_2 (void)
|
|||||||
return (unsigned long) tp1.tv_usec;
|
return (unsigned long) tp1.tv_usec;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned long randt (unsigned long l)
|
unsigned long randt(unsigned long l)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_GETTIMEOFDAY
|
#ifdef HAVE_GETTIMEOFDAY
|
||||||
unsigned long t1, t2, t;
|
unsigned long t1, t2, t;
|
||||||
@@ -3203,7 +3203,7 @@ static unsigned long randt (unsigned long l)
|
|||||||
* substantial unpredictable numbers. At worst, it is mathematical psuedo-
|
* substantial unpredictable numbers. At worst, it is mathematical psuedo-
|
||||||
* random sequence (which randm() is).
|
* random sequence (which randm() is).
|
||||||
*/
|
*/
|
||||||
static unsigned long randd (unsigned long l)
|
unsigned long randd(unsigned long l)
|
||||||
{
|
{
|
||||||
unsigned long value;
|
unsigned long value;
|
||||||
static int random_fd = -1;
|
static int random_fd = -1;
|
||||||
@@ -3227,19 +3227,10 @@ static int random_fd = -1;
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long BX_random_number(unsigned long l)
|
unsigned long BX_random_number(unsigned long l)
|
||||||
{
|
{
|
||||||
switch (get_int_var(RANDOM_SOURCE_VAR))
|
/* Always use the strongest random source for internal client use. */
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
default:
|
|
||||||
return randd(l);
|
return randd(l);
|
||||||
case 1:
|
|
||||||
return randm(l);
|
|
||||||
case 2:
|
|
||||||
return randt(l);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user