1
0
mirror of https://github.com/anope/anope.git synced 2026-06-28 02:16:37 +02:00

Removed our RNG and just use the systems, it's not very widely used. Also made DNS query ids not random as they don't need to be.

This commit is contained in:
Adam
2012-02-13 00:10:45 -05:00
parent 1bc8e2ab82
commit 086790d633
14 changed files with 17 additions and 191 deletions
-143
View File
@@ -27,13 +27,6 @@ void ExtensibleItem::OnDelete()
delete this;
}
struct arc4_stream
{
uint8_t i;
uint8_t j;
uint8_t s[256];
} rs;
/*************************************************************************/
/** Check if a file exists
@@ -519,142 +512,6 @@ bool nickIsServices(const Anope::string &tempnick, bool bot)
/*************************************************************************/
/**
* arc4 init
* @return void
*/
static void arc4_init()
{
for (int n = 0; n < 256; ++n)
rs.s[n] = n;
rs.i = 0;
rs.j = 0;
}
/*************************************************************************/
/**
* arc4 addrandom
* @param data
* @param dalen Data Length
* @return void
*/
static void arc4_addrandom(void *dat, int datlen)
{
--rs.i;
for (int n = 0; n < 256; ++n)
{
++rs.i;
uint8_t si = rs.s[rs.i];
rs.j = rs.j + si + (static_cast<unsigned char *>(dat))[n % datlen];
rs.s[rs.i] = rs.s[rs.j];
rs.s[rs.j] = si;
}
}
/*************************************************************************/
/**
* random init
* @return void
*/
void rand_init()
{
struct
{
#ifndef _WIN32
struct timeval nowt; /* time */
char rnd[32]; /* /dev/urandom */
#else
MEMORYSTATUS mstat; /* memory status */
struct _timeb nowt; /* time */
#endif
} rdat;
arc4_init();
/* Grab OS specific "random" data */
#ifndef _WIN32
/* unix/bsd: time */
gettimeofday(&rdat.nowt, NULL);
/* unix/bsd: /dev/urandom */
int fd = open("/dev/urandom", O_RDONLY);
if (fd)
{
read(fd, &rdat.rnd, sizeof(rdat.rnd));
close(fd);
}
#else
/* win32: time */
_ftime(&rdat.nowt);
/* win32: memory status */
GlobalMemoryStatus(&rdat.mstat);
#endif
arc4_addrandom(&rdat, sizeof(rdat));
}
/*************************************************************************/
/**
* Setup the random numbers
* @return void
*/
void add_entropy_userkeys()
{
arc4_addrandom(&Config->UserKey1, sizeof(Config->UserKey1));
arc4_addrandom(&Config->UserKey2, sizeof(Config->UserKey2));
arc4_addrandom(&Config->UserKey3, sizeof(Config->UserKey3));
/* UserKey3 is also used in mysql_rand() */
}
/*************************************************************************/
/**
* Get the random numbers 8 byte deep
* @return char
*/
unsigned char getrandom8()
{
++rs.i;
unsigned char si = rs.s[rs.i];
rs.j += si;
unsigned char sj = rs.s[rs.j];
rs.s[rs.i] = sj;
rs.s[rs.j] = si;
return rs.s[(si + sj) & 0xff];
}
/*************************************************************************/
/**
* Get the random numbers 16 byte deep
* @return char
*/
uint16_t getrandom16()
{
uint16_t val = getrandom8() << 8;
val |= getrandom8();
return val;
}
/*************************************************************************/
/**
* Get the random numbers 32 byte deep
* @return char
*/
uint32_t getrandom32()
{
uint32_t val = getrandom8() << 24;
val |= getrandom8() << 16;
val |= getrandom8() << 8;
val |= getrandom8();
return val;
}
/*************************************************************************/
/**
* Number of tokens in a string
* @param str String