Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #define INCL_DOS
8 #define INCL_DOSERRORS
9 #include <os2.h>
10 #include <stdlib.h>
11 #include <time.h>
12 #include "primpl.h"
14 static BOOL clockTickTime(unsigned long *phigh, unsigned long *plow)
15 {
16 APIRET rc = NO_ERROR;
17 QWORD qword = {0,0};
19 rc = DosTmrQueryTime(&qword);
20 if (rc != NO_ERROR)
21 return FALSE;
23 *phigh = qword.ulHi;
24 *plow = qword.ulLo;
26 return TRUE;
27 }
29 extern PRSize _PR_MD_GetRandomNoise(void *buf, PRSize size )
30 {
31 unsigned long high = 0;
32 unsigned long low = 0;
33 clock_t val = 0;
34 int n = 0;
35 int nBytes = 0;
36 time_t sTime;
38 if (size <= 0)
39 return 0;
41 clockTickTime(&high, &low);
43 /* get the maximally changing bits first */
44 nBytes = sizeof(low) > size ? size : sizeof(low);
45 memcpy(buf, &low, nBytes);
46 n += nBytes;
47 size -= nBytes;
49 if (size <= 0)
50 return n;
52 nBytes = sizeof(high) > size ? size : sizeof(high);
53 memcpy(((char *)buf) + n, &high, nBytes);
54 n += nBytes;
55 size -= nBytes;
57 if (size <= 0)
58 return n;
60 /* get the number of milliseconds that have elapsed since application started */
61 val = clock();
63 nBytes = sizeof(val) > size ? size : sizeof(val);
64 memcpy(((char *)buf) + n, &val, nBytes);
65 n += nBytes;
66 size -= nBytes;
68 if (size <= 0)
69 return n;
71 /* get the time in seconds since midnight Jan 1, 1970 */
72 time(&sTime);
73 nBytes = sizeof(sTime) > size ? size : sizeof(sTime);
74 memcpy(((char *)buf) + n, &sTime, nBytes);
75 n += nBytes;
77 return n;
78 }