VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/Dlgcode.c
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2016-02-11 23:54:35 +0100
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2016-02-12 00:04:31 +0100
commitd7d4c98775e34c7cb723ca813e8a76fe83610013 (patch)
tree262b84c9543995c64a2c93296f3dfebd4e27d3f3 /src/Common/Dlgcode.c
parent89d238bb3241fe8c285e9b748c0d99fa10b6a590 (diff)
downloadVeraCrypt-d7d4c98775e34c7cb723ca813e8a76fe83610013.tar.gz
VeraCrypt-d7d4c98775e34c7cb723ca813e8a76fe83610013.zip
Windows: Add colors (Red, Yellow, Green) to the collected randomness indicator depending on how much entropy was gathered. Code re-factoring.
Diffstat (limited to 'src/Common/Dlgcode.c')
-rw-r--r--src/Common/Dlgcode.c84
1 files changed, 42 insertions, 42 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index 4ffae65c..e3e70985 100644
--- a/src/Common/Dlgcode.c
+++ b/src/Common/Dlgcode.c
@@ -53,6 +53,7 @@
#include "Xml.h"
#include "Xts.h"
#include "Boot/Windows/BootCommon.h"
+#include "Progress.h"
#ifdef TCMOUNT
#include "Mount/Mount.h"
@@ -5409,6 +5410,7 @@ static BOOL CALLBACK RandomPoolEnrichementDlgProc (HWND hwndDlg, UINT msg, WPARA
hEntropyBar = GetDlgItem (hwndDlg, IDC_ENTROPY_BAR);
SendMessage (hEntropyBar, PBM_SETRANGE32, 0, maxEntropyLevel);
SendMessage (hEntropyBar, PBM_SETSTEP, 1, 0);
+ SendMessage (hEntropyBar, PBM_SETSTATE, PBST_ERROR, 0);
return 1;
}
@@ -5421,27 +5423,7 @@ static BOOL CALLBACK RandomPoolEnrichementDlgProc (HWND hwndDlg, UINT msg, WPARA
RandpeekBytes (hwndDlg, randPool, sizeof (randPool), &mouseEventsCounter);
- /* 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 (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);
- }
+ ProcessEntropyEstimate (hEntropyBar, &mouseEventsInitialCount, mouseEventsCounter, maxEntropyLevel, &mouseEntropyGathered);
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);
SendMessage (hEntropyBar, PBM_SETRANGE32, 0, maxEntropyLevel);
SendMessage (hEntropyBar, PBM_SETSTEP, 1, 0);
+ SendMessage (hEntropyBar, PBM_SETSTATE, PBST_ERROR, 0);
#ifndef VOLFORMAT
if (Randinit ())
@@ -5648,27 +5631,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
RandpeekBytes (hwndDlg, randPool, sizeof (randPool), &mouseEventsCounter);
- /* 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 (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);
- }
+ ProcessEntropyEstimate (hEntropyBar, &mouseEventsInitialCount, mouseEventsCounter, maxEntropyLevel, &mouseEntropyGathered);
if (memcmp (lastRandPool, randPool, sizeof(lastRandPool)) != 0)
{
@@ -11508,3 +11471,40 @@ HRESULT VCStrDupW(LPCWSTR psz, LPWSTR *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);
+ }
+}