/* 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 "Volume/EncryptionMode.h" #include "Volume/EncryptionModeCBC.h" #include "Volume/EncryptionModeLRW.h" #include "Volume/EncryptionModeXTS.h" #include "VolumeLayout.h" #include "Boot/Windows/BootCommon.h" namespace VeraCrypt { VolumeLayout::VolumeLayout () { } VolumeLayout::~VolumeLayout () { } VolumeLayoutList VolumeLayout::GetAvailableLayouts (VolumeType::Enum type) { VolumeLayoutList layouts; layouts.push_back (shared_ptr (new VolumeLayoutV2Normal ())); layouts.push_back (shared_ptr (new VolumeLayoutV1Normal ())); layouts.push_back (shared_ptr (new VolumeLayoutV2Hidden ())); layouts.push_back (shared_ptr (new VolumeLayoutV1Hidden ())); layouts.push_back (shared_ptr (new VolumeLayoutSystemEncryption ())); if (type != VolumeType::Unknown) { VolumeLayoutList l; foreach (shared_ptr vl, layouts) { if (vl->GetType() == type) l.push_back (vl); } layouts = l; } return layouts; } shared_ptr VolumeLayout::GetHeader () { if (Header.get() == nullptr) Header.reset (new VolumeHeader (GetHeaderSize())); return Header; } VolumeLayoutV1Normal::VolumeLayoutV1Normal () { Type = VolumeType::Normal; HeaderOffset = TC_VOLUME_HEADER_OFFSET; HeaderSize = TC_VOLUME_HEADER_SIZE_LEGACY; SupportedEncryptionAlgorithms.push_back (shared_ptr (new AES ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new Serpent ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new Twofish ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new AESTwofish ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new AESTwofishSerpent ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new SerpentAES ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new SerpentTwofishAES ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new TwofishSerpent ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new AESBlowfish ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new AESBlowfishSerpent ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new Blowfish ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new Cast5 ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new TripleDES ())); SupportedEncryptionModes.push_back (shared_ptr (new EncryptionModeXTS ())); SupportedEncryptionModes.push_back (shared_ptr (new EncryptionModeLRW ())); SupportedEncryptionModes.push_back (shared_ptr (new EncryptionModeCBC ())); } uint64 VolumeLayoutV1Normal::GetDataOffset (uint64 volumeHostSize) const { return HeaderSize; } uint64 VolumeLayoutV1Normal::GetDataSize (uint64 volumeHostSize) const { return volumeHostSize - GetHeaderSize(); } VolumeLayoutV1Hidden::VolumeLayoutV1Hidden () { Type = VolumeType::Hidden; HeaderOffset = -TC_HIDDEN_VOLUME_HEADER_OFFSET_LEGACY; HeaderSize = TC_VOLUME_HEADER_SIZE_LEGACY; SupportedEncryptionAlgorithms.push_back (shared_ptr (new AES ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new Serpent ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new Twofish ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new AESTwofish ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new AESTwofishSerpent ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new SerpentAES ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new SerpentTwofishAES ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new TwofishSerpent ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new AESBlowfish ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new AESBlowfishSerpent ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new Blowfish ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new Cast5 ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new TripleDES ())); SupportedEncryptionModes.push_back (shared_ptr (new EncryptionModeXTS ())); SupportedEncryptionModes.push_back (shared_ptr (new EncryptionModeLRW ())); SupportedEncryptionModes.push_back (shared_ptr (new EncryptionModeCBC ())); } uint64 VolumeLayoutV1Hidden::GetDataOffset (uint64 volumeHostSize) const { return volumeHostSize - GetDataSize (volumeHostSize) + HeaderOffset; } uint64 VolumeLayoutV1Hidden::GetDataSize (uint64 volumeHostSize) const { return Header->GetHiddenVolumeDataSize (); } VolumeLayoutV2Normal::VolumeLayoutV2Normal () { Type = VolumeType::Normal; HeaderOffset = TC_VOLUME_HEADER_OFFSET; HeaderSize = TC_VOLUME_HEADER_SIZE; BackupHeaderOffset = -TC_VOLUME_HEADER_GROUP_SIZE; SupportedEncryptionAlgorithms.push_back (shared_ptr (new AES ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new Serpent ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new Twofish ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new AESTwofish ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new AESTwofishSerpent ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new SerpentAES ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new SerpentTwofishAES ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new TwofishSerpent ())); SupportedEncryptionModes.push_back (shared_ptr (new EncryptionModeXTS ())); } uint64 VolumeLayoutV2Normal::GetDataOffset (uint64 volumeHostSize) const { return Header->GetEncryptedAreaStart(); } uint64 VolumeLayoutV2Normal::GetDataSize (uint64 volumeHostSize) const { return Header->GetVolumeDataSize(); } uint64 VolumeLayoutV2Normal::GetMaxDataSize (uint64 volumeSize) const { if (volumeSize < TC_TOTAL_VOLUME_HEADERS_SIZE) return 0; return volumeSize - TC_TOTAL_VOLUME_HEADERS_SIZE; } VolumeLayoutV2Hidden::VolumeLayoutV2Hidden () { Type = VolumeType::Hidden; HeaderOffset = TC_HIDDEN_VOLUME_HEADER_OFFSET; HeaderSize = TC_VOLUME_HEADER_SIZE; BackupHeaderOffset = -TC_HIDDEN_VOLUME_HEADER_OFFSET; SupportedEncryptionAlgorithms.push_back (shared_ptr (new AES ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new Serpent ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new Twofish ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new AESTwofish ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new AESTwofishSerpent ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new SerpentAES ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new SerpentTwofishAES ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new TwofishSerpent ())); SupportedEncryptionModes.push_back (shared_ptr (new EncryptionModeXTS ())); } uint64 VolumeLayoutV2Hidden::GetDataOffset (uint64 volumeHostSize) const { return Header->GetEncryptedAreaStart(); } uint64 VolumeLayoutV2Hidden::GetDataSize (uint64 volumeHostSize) const { return Header->GetVolumeDataSize(); } uint64 VolumeLayoutV2Hidden::GetMaxDataSize (uint64 volumeSize) const { // Reserve free space at the end of the host f
/*
 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-2016 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.
*/

#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(true), 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 if (typeid (*ea) == typeid (Camellia))
				EncryptionAlgorithmStaticText->SetLabel (LangString["CAMELLIA_HELP"]);
			else if (typeid (*ea) == typeid (Kuznyechik))
				EncryptionAlgorithmStaticText->SetLabel (LangString["KUZNYECHIK_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(true));
			OnEncryptionAlgorithmSelected ();
		}
	}

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