diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2016-01-31 20:28:00 +0100 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2016-01-31 23:30:27 +0100 |
commit | 77885de85e577275d2528e738914ba51b5def585 (patch) | |
tree | 7e2db6fc99de60822f5131dc69ce96b17123aa9c /src/Common/Random.c | |
parent | b407512248034dee23186febfc5e6c9597b77912 (diff) | |
download | VeraCrypt-77885de85e577275d2528e738914ba51b5def585.tar.gz VeraCrypt-77885de85e577275d2528e738914ba51b5def585.zip |
Windows: Implement GUI indicator for entropy collected from mouse movements.
Diffstat (limited to 'src/Common/Random.c')
-rw-r--r-- | src/Common/Random.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/Common/Random.c b/src/Common/Random.c index f6820c91..31dea511 100644 --- a/src/Common/Random.c +++ b/src/Common/Random.c @@ -73,8 +73,9 @@ void RandAddInt64 (unsigned __int64 x) #endif
HHOOK hMouse = NULL; /* Mouse hook for the random number generator */
HHOOK hKeyboard = NULL; /* Keyboard hook for the random number generator */
+DWORD ProcessedMouseEventsCounter = 0;
/* Variables for thread control, the thread is used to gather up info about
the system in in the background */
CRITICAL_SECTION critRandProt; /* The critical section */
@@ -102,8 +103,9 @@ int Randinit () InitializeCriticalSection (&critRandProt);
bRandDidInit = TRUE;
CryptoAPILastError = ERROR_SUCCESS;
+ ProcessedMouseEventsCounter = 0;
if (pRandPool == NULL)
{
pRandPool = (unsigned char *) TCalloc (RANDOMPOOL_ALLOCSIZE);
@@ -350,9 +352,9 @@ void RandaddBuf (void *buf, int len) RandaddByte (((unsigned char *) buf)[i]);
}
}
-BOOL RandpeekBytes (void* hwndDlg, unsigned char *buf, int len)
+BOOL RandpeekBytes (void* hwndDlg, unsigned char *buf, int len, DWORD* mouseCounter)
{
if (!bRandDidInit)
return FALSE;
@@ -362,8 +364,9 @@ BOOL RandpeekBytes (void* hwndDlg, unsigned char *buf, int len) len = RNG_POOL_SIZE;
}
EnterCriticalSection (&critRandProt);
+ *mouseCounter = ProcessedMouseEventsCounter;
memcpy (buf, pRandPool, len);
LeaveCriticalSection (&critRandProt);
return TRUE;
@@ -475,8 +478,9 @@ BOOL RandgetBytesFull ( void* hwndDlg, unsigned char *buf , int len, BOOL forceS LRESULT CALLBACK MouseProc (int nCode, WPARAM wParam, LPARAM lParam)
{
static DWORD dwLastTimer;
static unsigned __int32 lastCrc, lastCrc2;
+ static POINT lastPoint;
MOUSEHOOKSTRUCT *lpMouse = (MOUSEHOOKSTRUCT *) lParam;
if (nCode < 0)
return CallNextHookEx (hMouse, nCode, wParam, lParam);
@@ -485,8 +489,9 @@ LRESULT CALLBACK MouseProc (int nCode, WPARAM wParam, LPARAM lParam) DWORD dwTimer = GetTickCount ();
DWORD j = dwLastTimer - dwTimer;
unsigned __int32 crc = 0L;
int i;
+ POINT pt = lpMouse->pt;
dwLastTimer = dwTimer;
for (i = 0; i < sizeof (MOUSEHOOKSTRUCT); i++)
@@ -508,8 +513,15 @@ LRESULT CALLBACK MouseProc (int nCode, WPARAM wParam, LPARAM lParam) timeCrc = UPDC32 (((unsigned char *) &dwTimer)[i], timeCrc);
}
EnterCriticalSection (&critRandProt);
+ /* only count real mouse messages in entropy estimation */
+ if ( (nCode == HC_ACTION) && (wParam == WM_MOUSEMOVE)
+ && ((pt.x != lastPoint.x) || (pt.y != lastPoint.y)))
+ {
+ ProcessedMouseEventsCounter++;
+ lastPoint = pt;
+ }
RandaddInt32 ((unsigned __int32) (crc + timeCrc));
LeaveCriticalSection (&critRandProt);
}
lastCrc2 = lastCrc;
|