michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: #define INCL_DOS michael@0: #define INCL_DOSERRORS michael@0: #include michael@0: #include michael@0: #include michael@0: #include "primpl.h" michael@0: michael@0: static BOOL clockTickTime(unsigned long *phigh, unsigned long *plow) michael@0: { michael@0: APIRET rc = NO_ERROR; michael@0: QWORD qword = {0,0}; michael@0: michael@0: rc = DosTmrQueryTime(&qword); michael@0: if (rc != NO_ERROR) michael@0: return FALSE; michael@0: michael@0: *phigh = qword.ulHi; michael@0: *plow = qword.ulLo; michael@0: michael@0: return TRUE; michael@0: } michael@0: michael@0: extern PRSize _PR_MD_GetRandomNoise(void *buf, PRSize size ) michael@0: { michael@0: unsigned long high = 0; michael@0: unsigned long low = 0; michael@0: clock_t val = 0; michael@0: int n = 0; michael@0: int nBytes = 0; michael@0: time_t sTime; michael@0: michael@0: if (size <= 0) michael@0: return 0; michael@0: michael@0: clockTickTime(&high, &low); michael@0: michael@0: /* get the maximally changing bits first */ michael@0: nBytes = sizeof(low) > size ? size : sizeof(low); michael@0: memcpy(buf, &low, nBytes); michael@0: n += nBytes; michael@0: size -= nBytes; michael@0: michael@0: if (size <= 0) michael@0: return n; michael@0: michael@0: nBytes = sizeof(high) > size ? size : sizeof(high); michael@0: memcpy(((char *)buf) + n, &high, nBytes); michael@0: n += nBytes; michael@0: size -= nBytes; michael@0: michael@0: if (size <= 0) michael@0: return n; michael@0: michael@0: /* get the number of milliseconds that have elapsed since application started */ michael@0: val = clock(); michael@0: michael@0: nBytes = sizeof(val) > size ? size : sizeof(val); michael@0: memcpy(((char *)buf) + n, &val, nBytes); michael@0: n += nBytes; michael@0: size -= nBytes; michael@0: michael@0: if (size <= 0) michael@0: return n; michael@0: michael@0: /* get the time in seconds since midnight Jan 1, 1970 */ michael@0: time(&sTime); michael@0: nBytes = sizeof(sTime) > size ? size : sizeof(sTime); michael@0: memcpy(((char *)buf) + n, &sTime, nBytes); michael@0: n += nBytes; michael@0: michael@0: return n; michael@0: }