Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: nspr/pr/src/md/windows/w32rng.c

Issue 2078763002: Delete bundled copy of NSS and replace with README. (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/nss@master
Patch Set: Delete bundled copy of NSS and replace with README. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « nspr/pr/src/md/windows/w32poll.c ('k') | nspr/pr/src/md/windows/w32shm.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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/. */
5
6 #include <windows.h>
7 #include <time.h>
8 #include <io.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <stdio.h>
12 #include <primpl.h>
13
14 static BOOL
15 CurrentClockTickTime(LPDWORD lpdwHigh, LPDWORD lpdwLow)
16 {
17 LARGE_INTEGER liCount;
18
19 if (!QueryPerformanceCounter(&liCount))
20 return FALSE;
21
22 *lpdwHigh = liCount.u.HighPart;
23 *lpdwLow = liCount.u.LowPart;
24 return TRUE;
25 }
26
27 extern PRSize _PR_MD_GetRandomNoise( void *buf, PRSize size )
28 {
29 DWORD dwHigh, dwLow, dwVal;
30 size_t n = 0;
31 size_t nBytes;
32 time_t sTime;
33
34 if (size <= 0)
35 return 0;
36
37 CurrentClockTickTime(&dwHigh, &dwLow);
38
39 // get the maximally changing bits first
40 nBytes = sizeof(dwLow) > size ? size : sizeof(dwLow);
41 memcpy((char *)buf, &dwLow, nBytes);
42 n += nBytes;
43 size -= nBytes;
44
45 if (size <= 0)
46 return n;
47
48 nBytes = sizeof(dwHigh) > size ? size : sizeof(dwHigh);
49 memcpy(((char *)buf) + n, &dwHigh, nBytes);
50 n += nBytes;
51 size -= nBytes;
52
53 if (size <= 0)
54 return n;
55
56 // get the number of milliseconds that have elapsed since Windows started
57 dwVal = GetTickCount();
58
59 nBytes = sizeof(dwVal) > size ? size : sizeof(dwVal);
60 memcpy(((char *)buf) + n, &dwVal, nBytes);
61 n += nBytes;
62 size -= nBytes;
63
64 if (size <= 0)
65 return n;
66
67 // get the time in seconds since midnight Jan 1, 1970
68 time(&sTime);
69 nBytes = sizeof(sTime) > size ? size : sizeof(sTime);
70 memcpy(((char *)buf) + n, &sTime, nBytes);
71 n += nBytes;
72
73 return n;
74 }
75
OLDNEW
« no previous file with comments | « nspr/pr/src/md/windows/w32poll.c ('k') | nspr/pr/src/md/windows/w32shm.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698