/* 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. */ #include "Crc32.h" #include "EncryptionModeXTS.h" #include "Pkcs5Kdf.h" #include "Pkcs5Kdf.h" #include "VolumeHeader.h" #include "VolumeException.h" #include "Common/Crypto.h" namespace VeraCrypt { VolumeHeader::VolumeHeader (uint32 size) { Init(); HeaderSize = size; EncryptedHeaderDataSize = size - EncryptedHeaderDataOffset; } VolumeHeader::~VolumeHeader () { Init(); } void VolumeHeader::Init () { VolumeKeyAreaCrc32 = 0; VolumeCreationTime = 0; HeaderCreationTime = 0; mVolumeType = VolumeType::Unknown; HiddenVolumeDataSize = 0; VolumeDataSize = 0; EncryptedAreaStart = 0; EncryptedAreaLength = 0; Flags = 0; SectorSize = 0; } void VolumeHeader::Create (const BufferPtr &headerBuffer, VolumeHeaderCreationOptions &options) { if (options.DataKey.Size() != options.EA->GetKeySize() * 2 || options.Salt.Size() != GetSaltSize()) throw ParameterIncorrect (SRC_POS); headerBuffer.Zero(); HeaderVersion = CurrentHeaderVersion; RequiredMinProgramVersion = CurrentRequiredMinProgramVersion; DataAreaKey.Zero(); DataAreaKey.CopyFrom (options.DataKey); VolumeCreationTime = 0; HiddenVolumeDataSize = (options.Type == VolumeType::Hidden ? options.VolumeDataSize : 0); VolumeDataSize = options.VolumeDataSize; EncryptedAreaStart = options.VolumeDataStart; EncryptedAreaLength = options.VolumeDataSize; SectorSize = options.SectorSize; if (SectorSize < TC_MIN_VOLUME_SECTOR_SIZE || SectorSize > TC_MAX_VOLUME_SECTOR_SIZE || SectorSize % ENCRYPTION_DATA_UNIT_SIZE != 0) { throw ParameterIncorrect (SRC_POS); } EA = options.EA; shared_ptr mode (new EncryptionModeXTS ()); EA->SetMode (mode); EncryptNew (headerBuffer, options.Salt, options.HeaderKey, options.Kdf); } bool VolumeHeader::Decrypt (const ConstBufferPtr &encryptedData, const VolumePassword &password, int pim, shared_ptr kdf, bool truecryptMode, const Pkcs5KdfList &keyDerivationFunctions, const EncryptionAlgorithmList &encryptionAlgorithms, const EncryptionModeList &encryptionModes) { if (password.Size() < 1) throw PasswordEmpty (SRC_POS); ConstBufferPtr salt (encryptedData.GetRange (SaltOffset, SaltSize)); SecureBuffer header (EncryptedHeaderDataSize); SecureBuffer headerKey (GetLargestSerializedKeySize()); foreach (shared_ptr pkcs5, keyDerivationFunctions) { if (kdf && (kdf->GetName() != pkcs5->GetName())) continue; pkcs5->DeriveKey (headerKey, password, pim, salt); foreach (shared_ptr mode, encryptionModes) { if (typeid (*mode) != typeid (EncryptionModeXTS)) mode->SetKey (headerKey.GetRange (0, mode->GetKeySize())); foreach (shared_ptr ea, encryptionAlgorithms) { if (!ea->IsModeSupported (mode)) continue; if (typeid (*mode) == typeid (EncryptionModeXTS)) { ea->SetKey (headerKey.GetRange (0, ea->GetKeySize())); mode = mode->GetNew(); mode->SetKey (headerKey.GetRange (ea->GetKeySize(), ea->GetKeySize())); } else { ea->SetKey (headerKey.GetRange (LegacyEncryptionModeKeyAreaSize, ea->GetKeySize())); } ea->SetMode (mode); header.CopyFrom (encryptedData.GetRange (EncryptedHeaderDataOffset, EncryptedHeaderDataSize)); ea->Decrypt (header); if (Deserialize (header, ea, mode, truecryptMode)) { EA = ea; Pkcs5 = pkcs5; return true; } } } } return false; } bool VolumeHeader::Deserialize (const ConstBufferPtr &header, shared_ptr &ea, shared_ptr &mode, bool truecryptMode) { if (header.Size() != EncryptedHeaderDataSize) throw ParameterIncorrect (SRC_POS); if (truecryptMode && (header[0] != 'T' || header[1] != 'R' || header[2] != 'U' || header[3] != 'E')) return false; if (!truecryptMode && (header[0] != 'V' || header[1] != 'E' || header[2] != 'R' || header[3] != 'A')) return false; size_t offset = 4; HeaderVersion = DeserializeEntry (header, offset); if (HeaderVersion < MinAllowedHeaderVersion) return false; if (HeaderVersion > CurrentHeaderVersion) throw HigherVersionRequired (SRC_POS); if (HeaderVersion >= 4 && Crc32::ProcessBuffer (header.GetRange (0, TC_HEADER_OFFSET_HEADER_CRC - TC_HEADER_OFFSET_MAGIC)) != DeserializeEntryAt (header, TC_HEADER_OFFSET_HEADER_CRC - TC_HEADER_OFFSET_MAGIC)) { return false; } RequiredMinProgramVersion = DeserializeEntry (header, offset); if (!truecryptMode && (RequiredMinProgramVersion > Version::Number())) throw HigherVersionRequired (SRC_POS); if (truecryptMode) { if (RequiredMinProgramVersion
/*
 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.
*/

#ifndef TC_HEADER_Main_Forms_DeviceSelectionDialog
#define TC_HEADER_Main_Forms_DeviceSelectionDialog

#include "Forms.h"
#include "Main/Main.h"

namespace VeraCrypt
{
	class DeviceSelectionDialog : public DeviceSelectionDialogBase
	{
	public:
		DeviceSelectionDialog (wxWindow* parent);

		HostDeviceList DeviceList;
		HostDevice SelectedDevice;

	protected:
		enum
		{
			ColumnDevice = 0,
#ifdef TC_WINDOWS
			ColumnDrive,
#endif
			ColumnSize,
#ifdef TC_WINDOWS
			ColumnName
#else
			ColumnMountPoint
#endif
		};

		void OnListItemActivated (wxListEvent& event);
		void OnListItemDeselected (wxListEvent& event);
		void OnListItemSelected (wxListEvent& event);
	};
}

#endif // TC_HEADER_Main_Forms_DeviceSelectionDialog