size_t RNG_GetNoise(void *buf, size_t maxbuf) { DWORD dwHigh, dwLow, dwVal; int n = 0; int nBytes; if (maxbuf <= 0) return 0; CurrentClockTickTime(&dwHigh, &dwLow); // get the maximally changing bits first nBytes = sizeof(dwLow) > maxbuf ? maxbuf : sizeof(dwLow); memcpy((char *)buf, &dwLow, nBytes); n += nBytes; maxbuf -= nBytes; if (maxbuf <= 0) return n; nBytes = sizeof(dwHigh) > maxbuf ? maxbuf : sizeof(dwHigh); memcpy(((char *)buf) + n, &dwHigh, nBytes); n += nBytes; maxbuf -= nBytes; if (maxbuf <= 0) return n; // get the number of milliseconds that have elapsed since Windows started dwVal = GetTickCount(); nBytes = sizeof(dwVal) > maxbuf ? maxbuf : sizeof(dwVal); memcpy(((char *)buf) + n, &dwVal, nBytes); n += nBytes; maxbuf -= nBytes; if (maxbuf <= 0) return n; { #if defined(_WIN32_WCE) // get the number of milliseconds elapsed since Windows CE was started. FILETIME sTime; SYSTEMTIME st; GetSystemTime(&st); SystemTimeToFileTime(&st,&sTime); #else time_t sTime; // get the time in seconds since midnight Jan 1, 1970 time(&sTime); #endif nBytes = sizeof(sTime) > maxbuf ? maxbuf : sizeof(sTime); memcpy(((char *)buf) + n, &sTime, nBytes); n += nBytes; } return n; }
extern PRSize _PR_MD_GetRandomNoise( void *buf, PRSize size ) { DWORD dwHigh, dwLow, dwVal; size_t n = 0; size_t nBytes; time_t sTime; if (size <= 0) return 0; CurrentClockTickTime(&dwHigh, &dwLow); // get the maximally changing bits first nBytes = sizeof(dwLow) > size ? size : sizeof(dwLow); memcpy((char *)buf, &dwLow, nBytes); n += nBytes; size -= nBytes; if (size <= 0) return n; nBytes = sizeof(dwHigh) > size ? size : sizeof(dwHigh); memcpy(((char *)buf) + n, &dwHigh, nBytes); n += nBytes; size -= nBytes; if (size <= 0) return n; // get the number of milliseconds that have elapsed since Windows started dwVal = GetTickCount(); nBytes = sizeof(dwVal) > size ? size : sizeof(dwVal); memcpy(((char *)buf) + n, &dwVal, nBytes); n += nBytes; size -= nBytes; if (size <= 0) return n; // get the time in seconds since midnight Jan 1, 1970 time(&sTime); nBytes = sizeof(sTime) > size ? size : sizeof(sTime); memcpy(((char *)buf) + n, &sTime, nBytes); n += nBytes; return n; }
size_t RNG_GetNoise(void *buf, size_t maxbuf) { DWORD dwHigh, dwLow, dwVal; int n = 0; int nBytes; time_t sTime; if (maxbuf <= 0) return 0; CurrentClockTickTime(&dwHigh, &dwLow); // get the maximally changing bits first nBytes = sizeof(dwLow) > maxbuf ? maxbuf : sizeof(dwLow); memcpy((char *)buf, &dwLow, nBytes); n += nBytes; maxbuf -= nBytes; if (maxbuf <= 0) return n; nBytes = sizeof(dwHigh) > maxbuf ? maxbuf : sizeof(dwHigh); memcpy(((char *)buf) + n, &dwHigh, nBytes); n += nBytes; maxbuf -= nBytes; if (maxbuf <= 0) return n; // get the number of milliseconds that have elapsed since Windows started dwVal = GetTickCount(); nBytes = sizeof(dwVal) > maxbuf ? maxbuf : sizeof(dwVal); memcpy(((char *)buf) + n, &dwVal, nBytes); n += nBytes; maxbuf -= nBytes; if (maxbuf <= 0) return n; // get the time in seconds since midnight Jan 1, 1970 time(&sTime); nBytes = sizeof(sTime) > maxbuf ? maxbuf : sizeof(sTime); memcpy(((char *)buf) + n, &sTime, nBytes); n += nBytes; return n; }