From 39fb2edc25f2703744932f25d956bf7af604fc5f Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Tue, 9 Feb 2016 00:49:04 +0100 Subject: Linux/MacOSX: add progress bar for mouse collected entropy in GUI of volume creation wizard. Add mutex protection in event handler for shared counter variable --- src/Main/Forms/Forms.cpp | 18 ++-- src/Main/Forms/Forms.h | 1 + src/Main/Forms/KeyfileGeneratorDialog.cpp | 5 +- src/Main/Forms/KeyfileGeneratorDialog.h | 1 + src/Main/Forms/RandomPoolEnrichmentDialog.cpp | 5 +- src/Main/Forms/RandomPoolEnrichmentDialog.h | 1 + src/Main/Forms/TrueCrypt.fbp | 113 +++++++++++++++++++-- .../Forms/VolumeCreationProgressWizardPage.cpp | 12 ++- src/Main/Forms/VolumeCreationProgressWizardPage.h | 3 + src/Main/Forms/VolumeCreationWizard.cpp | 8 +- 10 files changed, 146 insertions(+), 21 deletions(-) (limited to 'src/Main/Forms') diff --git a/src/Main/Forms/Forms.cpp b/src/Main/Forms/Forms.cpp index da2a30ba..5fa70e5f 100644 --- a/src/Main/Forms/Forms.cpp +++ b/src/Main/Forms/Forms.cpp @@ -1436,7 +1436,7 @@ KeyfileGeneratorDialogBase::KeyfileGeneratorDialogBase( wxWindow* parent, wxWind bSizer162->Add( fgSizer8, 1, wxEXPAND, 5 ); - bSizer144->Add( bSizer162, 1, wxALL|wxEXPAND, 5 ); + bSizer144->Add( bSizer162, 0, wxALL|wxEXPAND, 5 ); wxBoxSizer* bSizer146; bSizer146 = new wxBoxSizer( wxHORIZONTAL ); @@ -2885,7 +2885,6 @@ VolumeCreationProgressWizardPageBase::VolumeCreationProgressWizardPageBase( wxWi bSizer126->Add( RandomPoolSampleStaticText, 0, wxEXPAND|wxTOP|wxRIGHT|wxALIGN_BOTTOM, 7 ); DisplayKeysCheckBox = new wxCheckBox( this, wxID_ANY, _("Show"), wxDefaultPosition, wxDefaultSize, 0 ); - DisplayKeysCheckBox->SetValue(true); bSizer126->Add( DisplayKeysCheckBox, 0, wxEXPAND|wxRIGHT, 5 ); @@ -2919,6 +2918,16 @@ VolumeCreationProgressWizardPageBase::VolumeCreationProgressWizardPageBase( wxWi bSizer105->Add( sbSizer31, 0, wxALL|wxEXPAND, 5 ); + wxStaticBoxSizer* sbSizer45; + sbSizer45 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Randomness Collected From Mouse Movements") ), wxVERTICAL ); + + CollectedEntropy = new wxGauge( this, wxID_ANY, 2560, wxDefaultPosition, wxDefaultSize, wxGA_HORIZONTAL|wxGA_SMOOTH ); + CollectedEntropy->SetValue( 0 ); + sbSizer45->Add( CollectedEntropy, 0, wxALL|wxEXPAND, 5 ); + + + bSizer105->Add( sbSizer45, 0, wxEXPAND|wxLEFT|wxRIGHT, 5 ); + wxStaticBoxSizer* sbSizer32; sbSizer32 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, wxEmptyString ), wxVERTICAL ); @@ -3015,12 +3024,9 @@ VolumeCreationProgressWizardPageBase::VolumeCreationProgressWizardPageBase( wxWi bSizer105->Add( sbSizer32, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - - bSizer105->Add( 0, 0, 0, wxTOP|wxBOTTOM, 5 ); - InfoStaticText = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); InfoStaticText->Wrap( -1 ); - bSizer105->Add( InfoStaticText, 0, wxALL, 5 ); + bSizer105->Add( InfoStaticText, 0, wxBOTTOM|wxLEFT|wxRIGHT, 5 ); bSizer104->Add( bSizer105, 1, wxEXPAND, 5 ); diff --git a/src/Main/Forms/Forms.h b/src/Main/Forms/Forms.h index fc3f62d3..5a3e8646 100644 --- a/src/Main/Forms/Forms.h +++ b/src/Main/Forms/Forms.h @@ -871,6 +871,7 @@ namespace VeraCrypt wxCheckBox* DisplayKeysCheckBox; wxStaticText* HeaderKeySampleStaticText; wxStaticText* MasterKeySampleStaticText; + wxGauge* CollectedEntropy; wxGauge* ProgressGauge; wxButton* AbortButton; wxStaticText* m_staticText31; diff --git a/src/Main/Forms/KeyfileGeneratorDialog.cpp b/src/Main/Forms/KeyfileGeneratorDialog.cpp index 157f74e5..61f16287 100644 --- a/src/Main/Forms/KeyfileGeneratorDialog.cpp +++ b/src/Main/Forms/KeyfileGeneratorDialog.cpp @@ -33,6 +33,8 @@ namespace VeraCrypt HideBytes (RandomPoolStaticText, 24); MouseStaticText->Wrap (Gui->GetCharWidth (MouseStaticText) * 70); + + CollectedEntropy->SetRange (RNG_POOL_SIZE * 8); MainSizer->SetMinSize (wxSize (-1, Gui->GetCharHeight (this) * 24)); @@ -177,7 +179,8 @@ namespace VeraCrypt /* 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 (MouseEventsCounter < 2560) + ScopeLock lock (AccessMutex); + if (MouseEventsCounter < (RNG_POOL_SIZE * 8)) CollectedEntropy->SetValue (++MouseEventsCounter); } diff --git a/src/Main/Forms/KeyfileGeneratorDialog.h b/src/Main/Forms/KeyfileGeneratorDialog.h index 23c66f08..e4fd3633 100644 --- a/src/Main/Forms/KeyfileGeneratorDialog.h +++ b/src/Main/Forms/KeyfileGeneratorDialog.h @@ -35,6 +35,7 @@ namespace VeraCrypt HashList Hashes; int MouseEventsCounter; + Mutex AccessMutex; }; } diff --git a/src/Main/Forms/RandomPoolEnrichmentDialog.cpp b/src/Main/Forms/RandomPoolEnrichmentDialog.cpp index f8b04d24..ecbfe7ac 100644 --- a/src/Main/Forms/RandomPoolEnrichmentDialog.cpp +++ b/src/Main/Forms/RandomPoolEnrichmentDialog.cpp @@ -35,6 +35,8 @@ namespace VeraCrypt HideBytes (RandomPoolStaticText, 24); MouseStaticText->Wrap (Gui->GetCharWidth (MouseStaticText) * 70); + + CollectedEntropy->SetRange (RNG_POOL_SIZE * 8); MainSizer->SetMinSize (wxSize (-1, Gui->GetCharHeight (this) * 24)); @@ -76,7 +78,8 @@ namespace VeraCrypt /* 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 (MouseEventsCounter < 2560) + ScopeLock lock (AccessMutex); + if (MouseEventsCounter < (RNG_POOL_SIZE * 8)) CollectedEntropy->SetValue (++MouseEventsCounter); } diff --git a/src/Main/Forms/RandomPoolEnrichmentDialog.h b/src/Main/Forms/RandomPoolEnrichmentDialog.h index 6e113cbe..4135ff28 100644 --- a/src/Main/Forms/RandomPoolEnrichmentDialog.h +++ b/src/Main/Forms/RandomPoolEnrichmentDialog.h @@ -33,6 +33,7 @@ namespace VeraCrypt HashList Hashes; int MouseEventsCounter; + Mutex AccessMutex; }; } diff --git a/src/Main/Forms/TrueCrypt.fbp b/src/Main/Forms/TrueCrypt.fbp index a993f39f..d9b1b1f1 100644 --- a/src/Main/Forms/TrueCrypt.fbp +++ b/src/Main/Forms/TrueCrypt.fbp @@ -23462,6 +23462,107 @@ + + 5 + wxEXPAND|wxLEFT|wxRIGHT + 0 + + wxID_ANY + Randomness Collected From Mouse Movements + + sbSizer45 + wxVERTICAL + none + + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + CollectedEntropy + 1 + + + protected + 1 + + 2560 + Resizable + 1 + + wxGA_HORIZONTAL|wxGA_SMOOTH + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT @@ -24467,17 +24568,7 @@ 5 - wxTOP|wxBOTTOM - 0 - - 0 - protected - 0 - - - - 5 - wxALL + wxBOTTOM|wxLEFT|wxRIGHT 0 1 diff --git a/src/Main/Forms/VolumeCreationProgressWizardPage.cpp b/src/Main/Forms/VolumeCreationProgressWizardPage.cpp index a1964958..08986f5e 100644 --- a/src/Main/Forms/VolumeCreationProgressWizardPage.cpp +++ b/src/Main/Forms/VolumeCreationProgressWizardPage.cpp @@ -21,7 +21,8 @@ namespace VeraCrypt PreviousGaugeValue (0), ProgressBarRange (1), RealProgressBarRange (1), - VolumeCreatorRunning (false) + VolumeCreatorRunning (false), + MouseEventsCounter (0) { DisplayKeysCheckBox->SetValue (displayKeyInfo); #ifdef TC_WINDOWS @@ -35,6 +36,8 @@ namespace VeraCrypt ProgressGauge->SetMinSize (wxSize (-1, Gui->GetCharHeight (this) * 2)); #endif + CollectedEntropy->SetRange (RNG_POOL_SIZE * 8); + if (DisplayKeysCheckBox->IsChecked()) ShowBytes (RandomPoolSampleStaticText, RandomNumberGenerator::PeekPool(), true); else @@ -184,4 +187,11 @@ namespace VeraCrypt RealProgressBarRange = ProgressGauge->GetSize().GetWidth(); ProgressGauge->SetRange (RealProgressBarRange); } + + void VolumeCreationProgressWizardPage::IncrementEntropyProgress () + { + ScopeLock lock (AccessMutex); + if (MouseEventsCounter < (RNG_POOL_SIZE * 8)) + CollectedEntropy->SetValue (++MouseEventsCounter); + } } diff --git a/src/Main/Forms/VolumeCreationProgressWizardPage.h b/src/Main/Forms/VolumeCreationProgressWizardPage.h index 63bd7fa8..417766e4 100644 --- a/src/Main/Forms/VolumeCreationProgressWizardPage.h +++ b/src/Main/Forms/VolumeCreationProgressWizardPage.h @@ -34,6 +34,7 @@ namespace VeraCrypt void SetProgressRange (uint64 progressBarRange); void SetProgressValue (uint64 value); void SetProgressState (bool volumeCreatorRunning); + void IncrementEntropyProgress (); Event AbortEvent; @@ -51,6 +52,8 @@ namespace VeraCrypt int RealProgressBarRange; wxLongLong StartTime; bool VolumeCreatorRunning; + int MouseEventsCounter; + Mutex AccessMutex; }; } diff --git a/src/Main/Forms/VolumeCreationWizard.cpp b/src/Main/Forms/VolumeCreationWizard.cpp index 1e4c2513..e9ceb3a3 100755 --- a/src/Main/Forms/VolumeCreationWizard.cpp +++ b/src/Main/Forms/VolumeCreationWizard.cpp @@ -39,7 +39,7 @@ namespace VeraCrypt VolumeCreationWizard::VolumeCreationWizard (wxWindow* parent) : WizardFrame (parent), CrossPlatformSupport (true), - DisplayKeyInfo (true), + DisplayKeyInfo (false), LargeFilesSupport (false), QuickFormatEnabled (false), SelectedFilesystemClusterSize (0), @@ -378,6 +378,12 @@ namespace VeraCrypt RandomNumberGenerator::AddToPool (ConstBufferPtr (reinterpret_cast (&coord), sizeof (coord))); coord = event.GetY(); RandomNumberGenerator::AddToPool (ConstBufferPtr (reinterpret_cast (&coord), sizeof (coord))); + + VolumeCreationProgressWizardPage *page = dynamic_cast (GetCurrentPage()); + if (page) + { + page->IncrementEntropyProgress (); + } } } -- cgit v1.2.3