VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Platform/Platform.h
blob: 314111692a60bf53859e81f1b9d41da512dc129e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 Derived from source code of TrueCrypt 7.1a, which is
 Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
 by the TrueCrypt License 3.0.

 Modifications and additions to the original source code (contained in this file) 
 and all other portions of this file are Copyright (c) 2013-2015 IDRIX
 and are governed by the Apache License 2.0 the full text of which is
 contained in the file License.txt included in VeraCrypt binary and source
 code distribution packages.
*/

#ifndef TC_HEADER_Platform
#define TC_HEADER_Platform

#include "PlatformBase.h"
#include "Buffer.h"
#include "Exception.h"
#include "Directory.h"
#include "Event.h"
#include "File.h"
#include "FilesystemPath.h"
#include "Finally.h"
#include "ForEach.h"
#include "Functor.h"
#include "Memory.h"
#include "Mutex.h"
#include "SharedPtr.h"
#include "SystemException.h"
#include "Thread.h"

#endif // TC_HEADER_Platform
teral.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*
 Copyright (c) 2008 TrueCrypt Developers Association. All rights reserved.

 Governed by the TrueCrypt License 3.0 the full text of which is contained in
 the file License.txt included in TrueCrypt binary and source code distribution
 packages.
*/

#include "System.h"
#include "Volume/EncryptionTest.h"
#include "Volume/Hash.h"
#include "Main/GraphicUserInterface.h"
#include "BenchmarkDialog.h"
#include "EncryptionOptionsWizardPage.h"
#include "EncryptionTestDialog.h"

namespace VeraCrypt
{
	EncryptionOptionsWizardPage::EncryptionOptionsWizardPage (wxPanel* parent)
		: EncryptionOptionsWizardPageBase (parent)
	{

		EncryptionAlgorithms = EncryptionAlgorithm::GetAvailableAlgorithms();
		foreach (shared_ptr <EncryptionAlgorithm> ea, EncryptionAlgorithms)
		{
			if (!ea->IsDeprecated())
				EncryptionAlgorithmChoice->Append (ea->GetName(), ea.get());
		}

		EncryptionAlgorithmChoice->Select (0);
		
		Hashes = Hash::GetAvailableAlgorithms();
		foreach (shared_ptr <Hash> hash, Hashes)
		{
			if (!hash->IsDeprecated())
				HashChoice->Append (hash->GetName(), hash.get());
		}

		HashChoice->Select (0);
		OnEncryptionAlgorithmSelected();

	}

	shared_ptr <EncryptionAlgorithm> EncryptionOptionsWizardPage::GetEncryptionAlgorithm () const
	{
		return Gui->GetSelectedData <EncryptionAlgorithm> (EncryptionAlgorithmChoice)->GetNew();
	}

	shared_ptr <Hash> EncryptionOptionsWizardPage::GetHash () const
	{
		return Gui->GetSelectedData <Hash> (HashChoice)->GetNew();
	}

	void EncryptionOptionsWizardPage::OnBenchmarkButtonClick (wxCommandEvent& event)
	{
		BenchmarkDialog dialog (this);
		dialog.ShowModal();
	}

	void EncryptionOptionsWizardPage::OnEncryptionAlgorithmSelected ()
	{
		FreezeScope freeze (this);

		shared_ptr <EncryptionAlgorithm> ea = GetEncryptionAlgorithm();
		CipherList ciphers = ea->GetCiphers();

		if (ciphers.size() == 1)
		{
			EncryptionAlgorithmHyperlink->SetLabel (StringFormatter (LangString["MORE_INFO_ABOUT"], ea->GetName()));

			if (typeid (*ea) == typeid (AES))
				EncryptionAlgorithmStaticText->SetLabel (LangString["AES_HELP"]);
			else if (typeid (*ea) == typeid (Serpent))
				EncryptionAlgorithmStaticText->SetLabel (LangString["SERPENT_HELP"]);
			else if (typeid (*ea) == typeid (Twofish))
				EncryptionAlgorithmStaticText->SetLabel (LangString["TWOFISH_HELP"]);
			else
				EncryptionAlgorithmStaticText->SetLabel (L"");
		}
		else
		{
			if (ciphers.size() == 2)
			{
				EncryptionAlgorithmStaticText->SetLabel (StringFormatter (LangString["TWO_LAYER_CASCADE_HELP"],
					ciphers[0]->GetName(), (int) ciphers[0]->GetKeySize() * 8,
					ciphers[1]->GetName(), (int) ciphers[1]->GetKeySize() * 8));
			}
			else if (ciphers.size() == 3)
			{
				EncryptionAlgorithmStaticText->SetLabel (StringFormatter (LangString["THREE_LAYER_CASCADE_HELP"],
					ciphers[0]->GetName(), (int) ciphers[0]->GetKeySize() * 8,
					ciphers[1]->GetName(), (int) ciphers[1]->GetKeySize() * 8,
					ciphers[2]->GetName(), (int) ciphers[2]->GetKeySize() * 8));
			}
			else
				EncryptionAlgorithmStaticText->SetLabel (L"");

			EncryptionAlgorithmHyperlink->SetLabel (_("More information"));
		}

		Layout();
	}

	void EncryptionOptionsWizardPage::OnEncryptionAlgorithmHyperlinkClick (wxHyperlinkEvent& event)
	{
		if (GetEncryptionAlgorithm()->GetCiphers().size() == 1)
			Gui->OpenHomepageLink (this, wxString (GetEncryptionAlgorithm()->GetName()).Lower());
		else
			Gui->OpenHomepageLink (this, L"cascades");
	}

	void EncryptionOptionsWizardPage::OnHashHyperlinkClick (wxHyperlinkEvent& event)
	{
		Gui->OpenHomepageLink (this, L"hashalgorithms");
	}
	
	void EncryptionOptionsWizardPage::OnTestButtonClick (wxCommandEvent& event)
	{
		EncryptionTestDialog dialog (this);
		dialog.ShowModal();
	}

	void EncryptionOptionsWizardPage::SetEncryptionAlgorithm (shared_ptr <EncryptionAlgorithm> algorithm)
	{
		if (algorithm)
		{
			EncryptionAlgorithmChoice->SetStringSelection (algorithm->GetName());
			OnEncryptionAlgorithmSelected ();
		}
	}

	void EncryptionOptionsWizardPage::SetHash (shared_ptr <Hash> hash)
	{
		if (hash)
			HashChoice->SetStringSelection (hash->GetName());
	}
}