Mercurial > trustbridge > nss-cmake-static
comparison nspr/pr/src/md/windows/w32rng.c @ 0:1e5118fa0cb1
This is NSS with a Cmake Buildsyste
To compile a static NSS library for Windows we've used the
Chromium-NSS fork and added a Cmake buildsystem to compile
it statically for Windows. See README.chromium for chromium
changes and README.trustbridge for our modifications.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 28 Jul 2014 10:47:06 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1e5118fa0cb1 |
---|---|
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 |