diff options
author | Adam <Adam@anope.org> | 2012-02-13 00:10:45 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2012-02-13 00:10:45 -0500 |
commit | 086790d6331357022f4da17c76b26b9fc6e2ad90 (patch) | |
tree | e82d9e0b67cfc5ad0251d8bdcd2490207a875fc6 /src/misc.cpp | |
parent | 1bc8e2ab82db9ce00faaa44887338873a2cd9210 (diff) |
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.
Diffstat (limited to 'src/misc.cpp')
-rw-r--r-- | src/misc.cpp | 143 |
1 files changed, 0 insertions, 143 deletions
diff --git a/src/misc.cpp b/src/misc.cpp index 02b886d75..524095d88 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -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 @@ -520,142 +513,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 * @param dilim Dilimiter |