From c44c1ac9ce7148c2830191e373ad41a2feeff046 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Thu, 21 May 2015 23:18:35 +0200 Subject: Windows: make random generator function compatible with 64-bit execution environment --- src/Common/Random.c | 49 ++++++++++++++++++++++++++++++++++--------------- src/Common/Random.h | 2 ++ 2 files changed, 36 insertions(+), 15 deletions(-) (limited to 'src/Common') diff --git a/src/Common/Random.c b/src/Common/Random.c index ae91f2da..c1479340 100644 --- a/src/Common/Random.c +++ b/src/Common/Random.c @@ -36,6 +36,12 @@ static HANDLE PeriodicFastPollThreadHandle = NULL; /* Macro to add four bytes to the pool */ #define RandaddInt32(x) RandAddInt((unsigned __int32)x); +#ifdef _WIN64 +#define RandaddIntPtr(x) RandAddInt64((unsigned __int64)x); +#else +#define RandaddIntPtr(x) RandAddInt((unsigned __int32)x); +#endif + void RandAddInt (unsigned __int32 x) { RandaddByte(x); @@ -44,6 +50,19 @@ void RandAddInt (unsigned __int32 x) RandaddByte((x >> 24)); } +void RandAddInt64 (unsigned __int64 x) +{ + RandaddByte(x); + RandaddByte((x >> 8)); + RandaddByte((x >> 16)); + RandaddByte((x >> 24)); + + RandaddByte((x >> 32)); + RandaddByte((x >> 40)); + RandaddByte((x >> 48)); + RandaddByte((x >> 56)); +} + #include #include "Dlgcode.h" @@ -539,7 +558,7 @@ LRESULT CALLBACK KeyboardProc (int nCode, WPARAM wParam, LPARAM lParam) } EnterCriticalSection (&critRandProt); - RandaddInt32 ((unsigned __int32) (crc32int(&lParam) + timeCrc)); + RandaddInt32 ((unsigned __int32) (GetCrc32((unsigned char*) &lParam, sizeof(lParam)) + timeCrc)); LeaveCriticalSection (&critRandProt); } @@ -734,36 +753,36 @@ BOOL FastPoll (void) int nOriginalRandIndex = nRandIndex; static BOOL addedFixedItems = FALSE; FILETIME creationTime, exitTime, kernelTime, userTime; - DWORD minimumWorkingSetSize, maximumWorkingSetSize; + SIZE_T minimumWorkingSetSize, maximumWorkingSetSize; LARGE_INTEGER performanceCount; MEMORYSTATUS memoryStatus; HANDLE handle; POINT point; /* Get various basic pieces of system information */ - RandaddInt32 (GetActiveWindow ()); /* Handle of active window */ - RandaddInt32 (GetCapture ()); /* Handle of window with mouse + RandaddIntPtr (GetActiveWindow ()); /* Handle of active window */ + RandaddIntPtr (GetCapture ()); /* Handle of window with mouse capture */ - RandaddInt32 (GetClipboardOwner ()); /* Handle of clipboard owner */ - RandaddInt32 (GetClipboardViewer ()); /* Handle of start of + RandaddIntPtr (GetClipboardOwner ()); /* Handle of clipboard owner */ + RandaddIntPtr (GetClipboardViewer ()); /* Handle of start of clpbd.viewer list */ - RandaddInt32 (GetCurrentProcess ()); /* Pseudohandle of current + RandaddIntPtr (GetCurrentProcess ()); /* Pseudohandle of current process */ RandaddInt32 (GetCurrentProcessId ()); /* Current process ID */ - RandaddInt32 (GetCurrentThread ()); /* Pseudohandle of current + RandaddIntPtr (GetCurrentThread ()); /* Pseudohandle of current thread */ RandaddInt32 (GetCurrentThreadId ()); /* Current thread ID */ RandaddInt32 (GetCurrentTime ()); /* Milliseconds since Windows started */ - RandaddInt32 (GetDesktopWindow ()); /* Handle of desktop window */ - RandaddInt32 (GetFocus ()); /* Handle of window with kb.focus */ + RandaddIntPtr (GetDesktopWindow ()); /* Handle of desktop window */ + RandaddIntPtr (GetFocus ()); /* Handle of window with kb.focus */ RandaddInt32 (GetInputState ()); /* Whether sys.queue has any events */ RandaddInt32 (GetMessagePos ()); /* Cursor pos.for last message */ RandaddInt32 (GetMessageTime ()); /* 1 ms time for last message */ - RandaddInt32 (GetOpenClipboardWindow ()); /* Handle of window with + RandaddIntPtr (GetOpenClipboardWindow ()); /* Handle of window with clpbd.open */ - RandaddInt32 (GetProcessHeap ()); /* Handle of process heap */ - RandaddInt32 (GetProcessWindowStation ()); /* Handle of procs + RandaddIntPtr (GetProcessHeap ()); /* Handle of process heap */ + RandaddIntPtr (GetProcessWindowStation ()); /* Handle of procs window station */ RandaddInt32 (GetQueueStatus (QS_ALLEVENTS)); /* Types of events in input queue */ @@ -800,8 +819,8 @@ BOOL FastPoll (void) process */ GetProcessWorkingSetSize (handle, &minimumWorkingSetSize, &maximumWorkingSetSize); - RandaddInt32 (minimumWorkingSetSize); - RandaddInt32 (maximumWorkingSetSize); + RandaddIntPtr (minimumWorkingSetSize); + RandaddIntPtr (maximumWorkingSetSize); /* The following are fixed for the lifetime of the process so we only add them once */ diff --git a/src/Common/Random.h b/src/Common/Random.h index 65e793fa..ba946541 100644 --- a/src/Common/Random.h +++ b/src/Common/Random.h @@ -60,6 +60,8 @@ extern BOOL volatile bFastPollEnabled; extern BOOL volatile bRandmixEnabled; extern DWORD CryptoAPILastError; +void RandAddInt64 ( unsigned __int64 x ); + LRESULT CALLBACK MouseProc ( int nCode , WPARAM wParam , LPARAM lParam ); LRESULT CALLBACK KeyboardProc ( int nCode , WPARAM wParam , LPARAM lParam ); static unsigned __stdcall PeriodicFastPollThreadProc (void *dummy); -- cgit v1.2.3