/* 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-2017 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_Core_Core #define TC_HEADER_Core_Core #include "CoreBase.h" namespace VeraCrypt { extern auto_ptr Core; extern auto_ptr CoreDirect; class WaitThreadRoutine { public: Exception* m_pException; WaitThreadRoutine() : m_pException(NULL) {} virtual ~WaitThreadRoutine() {if (m_pException) delete m_pException;} bool HasException () { return m_pException != NULL;} Exception* GetException () const { return m_pException;} void Execute(void) { try { ExecutionCode(); } catch(Exception& ex) { m_pException = ex.CloneNew(); } catch(...) { m_pException = new UnknownException (SRC_POS); } } virtual void ExecutionCode(void) = 0; }; class MountThreadRoutine : public WaitThreadRoutine { public: MountOptions& m_options; shared_ptr m_pVolume; MountThreadRoutine(MountOptions &options) : m_options(options) {} virtual ~MountThreadRoutine() { } virtual void ExecutionCode(void) { m_pVolume = Core->MountVolume(m_options); } }; class VolumeCreatorThreadRoutine : public WaitThreadRoutine { public: shared_ptr m_options; shared_ptr m_pCreator; VolumeCreatorThreadRoutine(shared_ptr options, shared_ptr pCreator) : m_options(options), m_pCreator(pCreator) {} virtual ~VolumeCreatorThreadRoutine() { } virtual void ExecutionCode(void) { m_pCreator->CreateVolume (m_options); } }; class ChangePasswordThreadRoutine : public WaitThreadRoutine { public: shared_ptr m_volumePath; bool m_preserveTimestamps; shared_ptr m_password; int m_pim; shared_ptr m_kdf; bool m_truecryptMode; shared_ptr m_keyfiles; shared_ptr m_newPassword; int m_newPim; shared_ptr m_newKeyfiles; shared_ptr m_newPkcs5Kdf; int m_wipeCount; ChangePasswordThreadRoutine(shared_ptr volumePath, bool preserveTimestamps, shared_ptr password, int pim, shared_ptr kdf, bool truecryptMode, shared_ptr keyfiles, shared_ptr newPassword, int newPim, shared_ptr newKeyfiles, shared_ptr newPkcs5Kdf, int wipeCount) : m_volumePath(volumePath), m_preserveTimestamps(preserveTimestamps), m_password(password), m_pim(pim), m_kdf(kdf), m_truecryptMode(truecryptMode), m_keyfiles(keyfiles), m_newPassword(newPassword), m_newPim(newPim), m_newKeyfiles(newKeyfiles), m_newPkcs5Kdf(newPkcs5Kdf), m_wipeCount(wipeCount) {} virtual ~ChangePasswordThreadRoutine() { } virtual void ExecutionCode(void) { Core->ChangePassword(m_volumePath, m_preserveTimestamps, m_password, m_pim, m_kdf, m_truecryptMode, m_keyfiles, m_newPassword, m_newPim, m_newKeyfiles, m_newPkcs5Kdf, m_wipeCount); } }; class OpenVolumeThreadRoutine : public WaitThreadRoutine { public: shared_ptr m_volumePath; bool m_preserveTimestamps; shared_ptr m_password; int m_pim; shared_ptr m_Kdf; bool m_truecryptMode; shared_ptr m_keyfiles; VolumeProtection::Enum m_protection; shared_ptr m_protectionPassword; int m_protectionPim; shared_ptr m_protectionKdf; shared_ptr m_protectionKeyfiles; bool m_sharedAccessAllowed; VolumeType::Enum m_volumeType; bool m_useBackupHeaders; bool m_partitionInSystemEncryptionScope; shared_ptr m_pVolume; OpenVolumeThreadRoutine(shared_ptr volumePath, bool preserveTimestamps, shared_ptr password, int pim, shared_ptr Kdf, bool truecryptMode, shared_ptr keyfiles, VolumeProtection::Enum protection = VolumeProtection::None, shared_ptr protectionPassword = shared_ptr (), int protectionPim = 0, shared_ptr protectionKdf = shared_ptr (), shared_ptr protectionKeyfiles = shared_ptr (), bool sharedAccessAllowed = false, VolumeType::Enum volumeType = VolumeType::Unknown, bool useBackupHeaders = false, bool partitionInSystemEncryptionScope = false): m_volumePath(volumePath), m_preserveTimestamps(preserveTimestamps), m_password(password), m_pim(pim), m_Kdf(Kdf), m_truecryptMode(truecryptMode), m_keyfiles(keyfiles), m_protection(protection), m_protectionPassword(protectionPassword), m_protectionPim
/*
 Copyright (c) 2008-2010 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.
*/

#ifndef TC_HEADER_ENCRYPTION_THREAD_POOL
#define TC_HEADER_ENCRYPTION_THREAD_POOL

#include "Tcdefs.h"
#include "Crypto.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum
{
	EncryptDataUnitsWork,
	DecryptDataUnitsWork,
	DeriveKeyWork
} EncryptionThreadPoolWorkType;

void EncryptionThreadPoolBeginKeyDerivation (TC_EVENT *completionEvent, TC_EVENT *noOutstandingWorkItemEvent, LONG *completionFlag, LONG *outstandingWorkItemCount, int pkcs5Prf, char *password, int passwordLength, char *salt, int iterationCount, char *derivedKey);
void EncryptionThreadPoolDoWork (EncryptionThreadPoolWorkType type, byte *data, const UINT64_STRUCT *startUnitNo, uint32 unitCount, PCRYPTO_INFO cryptoInfo);
BOOL EncryptionThreadPoolStart (size_t encryptionFreeCpuCount);
void EncryptionThreadPoolStop ();
size_t GetEncryptionThreadCount ();
size_t GetMaxEncryptionThreadCount ();
BOOL IsEncryptionThreadPoolRunning ();

#ifdef __cplusplus
}
#endif

#endif // TC_HEADER_ENCRYPTION_THREAD_POOL