1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-11 11:08:02 -06:00

Windows: Add colors (Red, Yellow, Green) to the collected randomness indicator depending on how much entropy was gathered. Code re-factoring.

This commit is contained in:
Mounir IDRASSI
2016-02-11 23:54:35 +01:00
parent 89d238bb32
commit d7d4c98775
5 changed files with 53 additions and 63 deletions

View File

@@ -53,6 +53,7 @@
#include "Xml.h" #include "Xml.h"
#include "Xts.h" #include "Xts.h"
#include "Boot/Windows/BootCommon.h" #include "Boot/Windows/BootCommon.h"
#include "Progress.h"
#ifdef TCMOUNT #ifdef TCMOUNT
#include "Mount/Mount.h" #include "Mount/Mount.h"
@@ -5409,6 +5410,7 @@ static BOOL CALLBACK RandomPoolEnrichementDlgProc (HWND hwndDlg, UINT msg, WPARA
hEntropyBar = GetDlgItem (hwndDlg, IDC_ENTROPY_BAR); hEntropyBar = GetDlgItem (hwndDlg, IDC_ENTROPY_BAR);
SendMessage (hEntropyBar, PBM_SETRANGE32, 0, maxEntropyLevel); SendMessage (hEntropyBar, PBM_SETRANGE32, 0, maxEntropyLevel);
SendMessage (hEntropyBar, PBM_SETSTEP, 1, 0); SendMessage (hEntropyBar, PBM_SETSTEP, 1, 0);
SendMessage (hEntropyBar, PBM_SETSTATE, PBST_ERROR, 0);
return 1; return 1;
} }
@@ -5421,27 +5423,7 @@ static BOOL CALLBACK RandomPoolEnrichementDlgProc (HWND hwndDlg, UINT msg, WPARA
RandpeekBytes (hwndDlg, randPool, sizeof (randPool), &mouseEventsCounter); RandpeekBytes (hwndDlg, randPool, sizeof (randPool), &mouseEventsCounter);
/* conservative estimate: 1 mouse move event brings 1 bit of entropy ProcessEntropyEstimate (hEntropyBar, &mouseEventsInitialCount, mouseEventsCounter, maxEntropyLevel, &mouseEntropyGathered);
* https://security.stackexchange.com/questions/32844/for-how-much-time-should-i-randomly-move-the-mouse-for-generating-encryption-key/32848#32848
*/
if (mouseEntropyGathered == 0xFFFFFFFF)
{
mouseEventsInitialCount = mouseEventsCounter;
mouseEntropyGathered = 0;
}
else
{
if ( mouseEntropyGathered < maxEntropyLevel
&& (mouseEventsCounter >= mouseEventsInitialCount)
&& (mouseEventsCounter - mouseEventsInitialCount) <= maxEntropyLevel)
mouseEntropyGathered = mouseEventsCounter - mouseEventsInitialCount;
else
mouseEntropyGathered = maxEntropyLevel;
SendMessage (hEntropyBar, PBM_SETPOS,
(WPARAM) (mouseEntropyGathered),
0);
}
if (memcmp (lastRandPool, randPool, sizeof(lastRandPool)) != 0) if (memcmp (lastRandPool, randPool, sizeof(lastRandPool)) != 0)
{ {
@@ -5618,6 +5600,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
hEntropyBar = GetDlgItem (hwndDlg, IDC_ENTROPY_BAR); hEntropyBar = GetDlgItem (hwndDlg, IDC_ENTROPY_BAR);
SendMessage (hEntropyBar, PBM_SETRANGE32, 0, maxEntropyLevel); SendMessage (hEntropyBar, PBM_SETRANGE32, 0, maxEntropyLevel);
SendMessage (hEntropyBar, PBM_SETSTEP, 1, 0); SendMessage (hEntropyBar, PBM_SETSTEP, 1, 0);
SendMessage (hEntropyBar, PBM_SETSTATE, PBST_ERROR, 0);
#ifndef VOLFORMAT #ifndef VOLFORMAT
if (Randinit ()) if (Randinit ())
@@ -5648,27 +5631,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
RandpeekBytes (hwndDlg, randPool, sizeof (randPool), &mouseEventsCounter); RandpeekBytes (hwndDlg, randPool, sizeof (randPool), &mouseEventsCounter);
/* conservative estimate: 1 mouse move event brings 1 bit of entropy ProcessEntropyEstimate (hEntropyBar, &mouseEventsInitialCount, mouseEventsCounter, maxEntropyLevel, &mouseEntropyGathered);
* https://security.stackexchange.com/questions/32844/for-how-much-time-should-i-randomly-move-the-mouse-for-generating-encryption-key/32848#32848
*/
if (mouseEntropyGathered == 0xFFFFFFFF)
{
mouseEventsInitialCount = mouseEventsCounter;
mouseEntropyGathered = 0;
}
else
{
if ( mouseEntropyGathered < maxEntropyLevel
&& (mouseEventsCounter >= mouseEventsInitialCount)
&& (mouseEventsCounter - mouseEventsInitialCount) <= maxEntropyLevel)
mouseEntropyGathered = mouseEventsCounter - mouseEventsInitialCount;
else
mouseEntropyGathered = maxEntropyLevel;
SendMessage (hEntropyBar, PBM_SETPOS,
(WPARAM) (mouseEntropyGathered),
0);
}
if (memcmp (lastRandPool, randPool, sizeof(lastRandPool)) != 0) if (memcmp (lastRandPool, randPool, sizeof(lastRandPool)) != 0)
{ {
@@ -11508,3 +11471,40 @@ HRESULT VCStrDupW(LPCWSTR psz, LPWSTR *ppwsz)
{ {
return SHStrDupWFn (psz, ppwsz); return SHStrDupWFn (psz, ppwsz);
} }
void ProcessEntropyEstimate (HWND hProgress, DWORD* pdwInitialValue, DWORD dwCounter, DWORD dwMaxLevel, DWORD* pdwEntropy)
{
/* conservative estimate: 1 mouse move event brings 1 bit of entropy
* https://security.stackexchange.com/questions/32844/for-how-much-time-should-i-randomly-move-the-mouse-for-generating-encryption-key/32848#32848
*/
if (*pdwEntropy == 0xFFFFFFFF)
{
*pdwInitialValue = dwCounter;
*pdwEntropy = 0;
}
else
{
if ( *pdwEntropy < dwMaxLevel
&& (dwCounter >= *pdwInitialValue)
&& (dwCounter - *pdwInitialValue) <= dwMaxLevel)
*pdwEntropy = dwCounter - *pdwInitialValue;
else
*pdwEntropy = dwMaxLevel;
if (IsOSAtLeast (WIN_VISTA))
{
int state = PBST_ERROR;
if (*pdwEntropy >= (dwMaxLevel/2))
state = PBST_NORMAL;
else if (*pdwEntropy >= (dwMaxLevel/4))
state = PBST_PAUSED;
SendMessage (hProgress, PBM_SETSTATE, state, 0);
}
SendMessage (hProgress, PBM_SETPOS,
(WPARAM) (*pdwEntropy),
0);
}
}

View File

@@ -498,6 +498,7 @@ LSTATUS DeleteRegistryKey (HKEY, LPCTSTR);
HIMAGELIST CreateImageList(int cx, int cy, UINT flags, int cInitial, int cGrow); HIMAGELIST CreateImageList(int cx, int cy, UINT flags, int cInitial, int cGrow);
int AddBitmapToImageList(HIMAGELIST himl, HBITMAP hbmImage, HBITMAP hbmMask); int AddBitmapToImageList(HIMAGELIST himl, HBITMAP hbmImage, HBITMAP hbmMask);
HRESULT VCStrDupW(LPCWSTR psz, LPWSTR *ppwsz); HRESULT VCStrDupW(LPCWSTR psz, LPWSTR *ppwsz);
void ProcessEntropyEstimate (HWND hProgress, DWORD* pdwInitialValue, DWORD dwCounter, DWORD dwMaxLevel, DWORD* pdwEntropy);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -15,6 +15,15 @@
extern "C" { extern "C" {
#endif #endif
#ifndef PBM_SETSTATE
#define PBM_SETSTATE (WM_USER+16) // wParam = PBST_[State] (NORMAL, ERROR, PAUSED)
#define PBST_NORMAL 0x0001
#define PBST_ERROR 0x0002
#define PBST_PAUSED 0x0003
#endif
void InitProgressBar (__int64 totalBytes, __int64 bytesDone, BOOL bReverse, BOOL bIOThroughput, BOOL bDisplayStatus, BOOL bShowPercent); void InitProgressBar (__int64 totalBytes, __int64 bytesDone, BOOL bReverse, BOOL bIOThroughput, BOOL bDisplayStatus, BOOL bShowPercent);
BOOL UpdateProgressBar (__int64 byteOffset); BOOL UpdateProgressBar (__int64 byteOffset);
BOOL UpdateProgressBarProc (__int64 byteOffset); BOOL UpdateProgressBarProc (__int64 byteOffset);

View File

@@ -346,27 +346,7 @@ BOOL CALLBACK ExpandVolProgressDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, L
RandpeekBytes (hwndDlg, randPool, sizeof (randPool),&mouseEventsCounter); RandpeekBytes (hwndDlg, randPool, sizeof (randPool),&mouseEventsCounter);
/* conservative estimate: 1 mouse move event brings 1 bit of entropy ProcessEntropyEstimate (hEntropyBar, &mouseEventsInitialCount, mouseEventsCounter, maxEntropyLevel, &mouseEntropyGathered);
* https://security.stackexchange.com/questions/32844/for-how-much-time-should-i-randomly-move-the-mouse-for-generating-encryption-key/32848#32848
*/
if (mouseEntropyGathered == 0xFFFFFFFF)
{
mouseEventsInitialCount = mouseEventsCounter;
mouseEntropyGathered = 0;
}
else
{
if ( mouseEntropyGathered < maxEntropyLevel
&& (mouseEventsCounter >= mouseEventsInitialCount)
&& (mouseEventsCounter - mouseEventsInitialCount) <= maxEntropyLevel)
mouseEntropyGathered = mouseEventsCounter - mouseEventsInitialCount;
else
mouseEntropyGathered = maxEntropyLevel;
SendMessage (hEntropyBar, PBM_SETPOS,
(WPARAM) (mouseEntropyGathered),
0);
}
if (showRandPool) if (showRandPool)
StringCbPrintfW (szRndPool, sizeof(szRndPool), L"%08X%08X%08X%08X", StringCbPrintfW (szRndPool, sizeof(szRndPool), L"%08X%08X%08X%08X",

Binary file not shown.