-/* $Id: arc4random.c 26092 2008-09-19 15:13:52Z androsyn $ */
/* $$$: arc4random.c 2005/02/08 robert */
/* $NetBSD: arc4random.c,v 1.5.2.1 2004/03/26 22:52:50 jmc Exp $ */
/* $OpenBSD: arc4random.c,v 1.6 2001/06/05 05:05:38 pvalchev Exp $ */
{
struct timeval tv;
pid_t pid;
- int n;
-#ifdef _WIN32
- HMODULE lib;
-#endif
+ uint8_t rnd[128];
+ int fd, n;
/* XXX this doesn't support egd sources or similiar */
pid = getpid();
memset(&buf, 0, sizeof(buf))}
#endif
-#if !defined(_WIN32)
+ fd = open("/dev/urandom", O_RDONLY);
+ if(fd != -1)
{
- uint8_t rnd[128];
- int fd;
- fd = open("/dev/urandom", O_RDONLY);
- if(fd != -1)
- {
- read(fd, rnd, sizeof(rnd));
- close(fd);
- arc4_addrandom(as, (void *)rnd, sizeof(rnd));
- memset(&rnd, 0, sizeof(rnd));
- }
-
+ read(fd, rnd, sizeof(rnd));
+ close(fd);
+ arc4_addrandom(as, (void *)rnd, sizeof(rnd));
+ memset(&rnd, 0, sizeof(rnd));
}
-#else
- {
- LARGE_INTEGER performanceCount;
- if(QueryPerformanceCounter(&performanceCount))
- {
- arc4_addrandom(as, (void *)&performanceCount, sizeof(performanceCount));
- }
- lib = LoadLibrary("ADVAPI32.DLL");
- if(lib)
- {
- uint8_t rnd[128];
- BOOLEAN(APIENTRY * pfn) (void *, ULONG) =
- (BOOLEAN(APIENTRY *) (void *, ULONG))GetProcAddress(lib,
- "SystemFunction036");
- if(pfn)
- {
- if(pfn(rnd, sizeof(rnd)) == TRUE)
- arc4_addrandom(as, (void *)rnd, sizeof(rnd));
- memset(&rnd, 0, sizeof(rnd));
- }
- }
- }
-#endif
-
/*
* Throw away the first N words of output, as suggested in the