"Fossies" - the Fresh Open Source Software Archive

Member "src/Main/Forms/RandomPoolEnrichmentDialog.cpp" (10 Oct 2018, 3529 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "RandomPoolEnrichmentDialog.cpp" see the Fossies "Dox" file reference documentation.

    1 /*
    2  Derived from source code of TrueCrypt 7.1a, which is
    3  Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
    4  by the TrueCrypt License 3.0.
    5 
    6  Modifications and additions to the original source code (contained in this file)
    7  and all other portions of this file are Copyright (c) 2013-2017 IDRIX
    8  and are governed by the Apache License 2.0 the full text of which is
    9  contained in the file License.txt included in VeraCrypt binary and source
   10  code distribution packages.
   11 */
   12 
   13 #include "System.h"
   14 #include "Main/GraphicUserInterface.h"
   15 #include "Volume/Hash.h"
   16 #include "RandomPoolEnrichmentDialog.h"
   17 
   18 namespace VeraCrypt
   19 {
   20     RandomPoolEnrichmentDialog::RandomPoolEnrichmentDialog (wxWindow* parent) : RandomPoolEnrichmentDialogBase (parent)
   21     {
   22         RandomNumberGenerator::Start();
   23 
   24         Hashes = Hash::GetAvailableAlgorithms();
   25         foreach (shared_ptr <Hash> hash, Hashes)
   26         {
   27             if (!hash->IsDeprecated())
   28             {
   29                 HashChoice->Append (hash->GetName(), hash.get());
   30 
   31                 if (typeid (*hash) == typeid (*RandomNumberGenerator::GetHash()))
   32                     HashChoice->Select (HashChoice->GetCount() - 1);
   33             }
   34         }
   35 
   36         HideBytes (RandomPoolStaticText, 24);
   37         MouseStaticText->Wrap (Gui->GetCharWidth (MouseStaticText) * 70);
   38 
   39         CollectedEntropy->SetRange (RNG_POOL_SIZE * 8);
   40 
   41         MainSizer->SetMinSize (wxSize (-1, Gui->GetCharHeight (this) * 24));
   42 
   43         Layout();
   44         Fit();
   45         Center();
   46 
   47         MouseEventsCounter = 0;
   48 
   49         foreach (wxWindow *c, this->GetChildren())
   50             c->Connect (wxEVT_MOTION, wxMouseEventHandler (RandomPoolEnrichmentDialog::OnMouseMotion), nullptr, this);
   51     }
   52 
   53     RandomPoolEnrichmentDialog::~RandomPoolEnrichmentDialog ()
   54     {
   55     }
   56 
   57     void RandomPoolEnrichmentDialog::OnHashSelected (wxCommandEvent& event)
   58     {
   59         RandomNumberGenerator::SetHash (Gui->GetSelectedData <Hash> (HashChoice)->GetNew());
   60     }
   61 
   62     void RandomPoolEnrichmentDialog::OnMouseMotion (wxMouseEvent& event)
   63     {
   64         event.Skip();
   65 
   66         RandomNumberGenerator::AddToPool (ConstBufferPtr (reinterpret_cast <byte *> (&event), sizeof (event)));
   67 
   68         long coord = event.GetX();
   69         RandomNumberGenerator::AddToPool (ConstBufferPtr (reinterpret_cast <byte *> (&coord), sizeof (coord)));
   70         coord = event.GetY();
   71         RandomNumberGenerator::AddToPool (ConstBufferPtr (reinterpret_cast <byte *> (&coord), sizeof (coord)));
   72 
   73         if (ShowRandomPoolCheckBox->IsChecked())
   74             ShowBytes (RandomPoolStaticText, RandomNumberGenerator::PeekPool().GetRange (0, 24));
   75         else
   76             HideBytes (RandomPoolStaticText, 24);
   77 
   78         /* conservative estimate: 1 mouse move event brings 1 bit of entropy
   79          * https://security.stackexchange.com/questions/32844/for-how-much-time-should-i-randomly-move-the-mouse-for-generating-encryption-key/32848#32848
   80          */
   81         ScopeLock lock (AccessMutex);
   82         if (MouseEventsCounter < (RNG_POOL_SIZE * 8))
   83             CollectedEntropy->SetValue (++MouseEventsCounter);
   84     }
   85 
   86     void RandomPoolEnrichmentDialog::OnShowRandomPoolCheckBoxClicked (wxCommandEvent& event)
   87     {
   88         if (!event.IsChecked())
   89             HideBytes (RandomPoolStaticText, 24);
   90     }
   91 
   92     void RandomPoolEnrichmentDialog::ShowBytes (wxStaticText *textCtrl, const ConstBufferPtr &buffer)
   93     {
   94         wxString str;
   95 
   96         for (size_t i = 0; i < buffer.Size(); ++i)
   97         {
   98             str += wxString::Format (L"%02X", buffer[i]);
   99         }
  100 
  101         str += L"..";
  102 
  103         textCtrl->SetLabel (str.c_str());
  104 
  105         for (size_t i = 0; i < str.size(); ++i)
  106         {
  107             str[i] = L'X';
  108         }
  109     }
  110 
  111     void RandomPoolEnrichmentDialog::HideBytes (wxStaticText *textCtrl, size_t len)
  112     {
  113         wxString str;
  114 
  115         for (size_t i = 0; i < len + 1; ++i)
  116         {
  117             str += L"**";
  118         }
  119 
  120         textCtrl->SetLabel (str.c_str());
  121     }
  122 }