"Fossies" - the Fresh Open Source Software Archive

Member "src/Core/Core.h" (10 Oct 2018, 7876 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 "Core.h" 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 #ifndef TC_HEADER_Core_Core
   14 #define TC_HEADER_Core_Core
   15 
   16 #include "CoreBase.h"
   17 
   18 namespace VeraCrypt
   19 {
   20     extern auto_ptr <CoreBase> Core;
   21     extern auto_ptr <CoreBase> CoreDirect;
   22 
   23     class WaitThreadRoutine
   24     {
   25     public:
   26         Exception* m_pException;
   27         WaitThreadRoutine() : m_pException(NULL) {}
   28         virtual ~WaitThreadRoutine() {if (m_pException) delete m_pException;}
   29         bool HasException () { return m_pException != NULL;}
   30         Exception* GetException () const { return m_pException;}
   31         void Execute(void)
   32         {
   33             try
   34             {
   35                 ExecutionCode();
   36             }
   37             catch(Exception& ex)
   38             {
   39                 m_pException = ex.CloneNew();
   40             }
   41             catch(...)
   42             {
   43                 m_pException = new UnknownException (SRC_POS);
   44             }
   45         }
   46         virtual void ExecutionCode(void) = 0;
   47     };
   48 
   49     class MountThreadRoutine : public WaitThreadRoutine
   50     {
   51     public:
   52         MountOptions& m_options;
   53         shared_ptr <VolumeInfo> m_pVolume;
   54         MountThreadRoutine(MountOptions &options) : m_options(options) {}
   55         virtual ~MountThreadRoutine() { }
   56         virtual void ExecutionCode(void) { m_pVolume = Core->MountVolume(m_options); }
   57     };
   58 
   59     class VolumeCreatorThreadRoutine : public WaitThreadRoutine
   60     {
   61     public:
   62         shared_ptr <VolumeCreationOptions> m_options;
   63         shared_ptr <VolumeCreator> m_pCreator;
   64         VolumeCreatorThreadRoutine(shared_ptr <VolumeCreationOptions> options, shared_ptr <VolumeCreator> pCreator)
   65             : m_options(options), m_pCreator(pCreator) {}
   66         virtual ~VolumeCreatorThreadRoutine() { }
   67         virtual void ExecutionCode(void) { m_pCreator->CreateVolume (m_options); }
   68     };
   69 
   70     class ChangePasswordThreadRoutine : public WaitThreadRoutine
   71     {
   72     public:
   73         shared_ptr <VolumePath> m_volumePath;
   74         bool m_preserveTimestamps;
   75         shared_ptr <VolumePassword> m_password;
   76         int m_pim;
   77         shared_ptr <Pkcs5Kdf> m_kdf;
   78         bool m_truecryptMode;
   79         shared_ptr <KeyfileList> m_keyfiles;
   80         shared_ptr <VolumePassword> m_newPassword;
   81         int m_newPim;
   82         shared_ptr <KeyfileList> m_newKeyfiles;
   83         shared_ptr <Pkcs5Kdf> m_newPkcs5Kdf;
   84         int m_wipeCount;
   85         ChangePasswordThreadRoutine(shared_ptr <VolumePath> volumePath, bool preserveTimestamps, shared_ptr <VolumePassword> password, int pim, shared_ptr <Pkcs5Kdf> kdf, bool truecryptMode, shared_ptr <KeyfileList> keyfiles, shared_ptr <VolumePassword> newPassword, int newPim, shared_ptr <KeyfileList> newKeyfiles, shared_ptr <Pkcs5Kdf> 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)  {}
   86         virtual ~ChangePasswordThreadRoutine() { }
   87         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); }
   88     };
   89 
   90     class OpenVolumeThreadRoutine : public WaitThreadRoutine
   91     {
   92     public:
   93         shared_ptr <VolumePath> m_volumePath;
   94         bool m_preserveTimestamps;
   95         shared_ptr <VolumePassword> m_password;
   96         int m_pim;
   97         shared_ptr<Pkcs5Kdf> m_Kdf;
   98         bool m_truecryptMode;
   99         shared_ptr <KeyfileList> m_keyfiles;
  100         VolumeProtection::Enum m_protection;
  101         shared_ptr <VolumePassword> m_protectionPassword;
  102         int m_protectionPim;
  103         shared_ptr<Pkcs5Kdf> m_protectionKdf;
  104         shared_ptr <KeyfileList> m_protectionKeyfiles;
  105         bool m_sharedAccessAllowed;
  106         VolumeType::Enum m_volumeType;
  107         bool m_useBackupHeaders;
  108         bool m_partitionInSystemEncryptionScope;
  109         shared_ptr <Volume> m_pVolume;
  110 
  111         OpenVolumeThreadRoutine(shared_ptr <VolumePath> volumePath, bool preserveTimestamps, shared_ptr <VolumePassword> password, int pim, shared_ptr<Pkcs5Kdf> Kdf, bool truecryptMode, shared_ptr <KeyfileList> keyfiles, VolumeProtection::Enum protection = VolumeProtection::None, shared_ptr <VolumePassword> protectionPassword = shared_ptr <VolumePassword> (), int protectionPim = 0, shared_ptr<Pkcs5Kdf> protectionKdf = shared_ptr<Pkcs5Kdf> (), shared_ptr <KeyfileList> protectionKeyfiles = shared_ptr <KeyfileList> (), bool sharedAccessAllowed = false, VolumeType::Enum volumeType = VolumeType::Unknown, bool useBackupHeaders = false, bool partitionInSystemEncryptionScope = false):
  112         m_volumePath(volumePath), m_preserveTimestamps(preserveTimestamps), m_password(password), m_pim(pim), m_Kdf(Kdf), m_truecryptMode(truecryptMode), m_keyfiles(keyfiles),
  113         m_protection(protection), m_protectionPassword(protectionPassword), m_protectionPim(protectionPim), m_protectionKdf(protectionKdf), m_protectionKeyfiles(protectionKeyfiles), m_sharedAccessAllowed(sharedAccessAllowed), m_volumeType(volumeType),m_useBackupHeaders(useBackupHeaders),
  114         m_partitionInSystemEncryptionScope(partitionInSystemEncryptionScope) {}
  115 
  116         ~OpenVolumeThreadRoutine() {}
  117 
  118         virtual void ExecutionCode(void) { m_pVolume = Core->OpenVolume(m_volumePath,m_preserveTimestamps,m_password,m_pim,m_Kdf,m_truecryptMode,m_keyfiles, m_protection,m_protectionPassword,m_protectionPim,m_protectionKdf, m_protectionKeyfiles,m_sharedAccessAllowed,m_volumeType,m_useBackupHeaders, m_partitionInSystemEncryptionScope); }
  119 
  120     };
  121 
  122     class ReEncryptHeaderThreadRoutine : public WaitThreadRoutine
  123     {
  124     public:
  125         const BufferPtr &m_newHeaderBuffer;
  126         shared_ptr <VolumeHeader> m_header;
  127         shared_ptr <VolumePassword> m_password;
  128         int m_pim;
  129         shared_ptr <KeyfileList> m_keyfiles;
  130         ReEncryptHeaderThreadRoutine(const BufferPtr &newHeaderBuffer, shared_ptr <VolumeHeader> header, shared_ptr <VolumePassword> password, int pim, shared_ptr <KeyfileList> keyfiles)
  131             : m_newHeaderBuffer(newHeaderBuffer), m_header(header), m_password(password), m_pim(pim), m_keyfiles(keyfiles) {}
  132         virtual ~ReEncryptHeaderThreadRoutine() { }
  133         virtual void ExecutionCode(void) { Core->ReEncryptVolumeHeaderWithNewSalt (m_newHeaderBuffer, m_header, m_password, m_pim, m_keyfiles); }
  134     };
  135 
  136     class DecryptThreadRoutine : public WaitThreadRoutine
  137     {
  138     public:
  139         shared_ptr <VolumeHeader> m_pHeader;
  140         const ConstBufferPtr &m_encryptedData;
  141         const VolumePassword &m_password;
  142         int m_pim;
  143         shared_ptr <Pkcs5Kdf> m_kdf;
  144         bool m_truecryptMode;
  145         const Pkcs5KdfList &m_keyDerivationFunctions;
  146         const EncryptionAlgorithmList &m_encryptionAlgorithms;
  147         const EncryptionModeList &m_encryptionModes;
  148         bool m_bResult;
  149         DecryptThreadRoutine(shared_ptr <VolumeHeader> header, const ConstBufferPtr &encryptedData, const VolumePassword &password, int pim, shared_ptr <Pkcs5Kdf> kdf, bool truecryptMode, const Pkcs5KdfList &keyDerivationFunctions, const EncryptionAlgorithmList &encryptionAlgorithms, const EncryptionModeList &encryptionModes)
  150             : m_pHeader(header), m_encryptedData(encryptedData), m_password(password), m_pim(pim), m_kdf(kdf), m_truecryptMode(truecryptMode), m_keyDerivationFunctions(keyDerivationFunctions), m_encryptionAlgorithms(encryptionAlgorithms), m_encryptionModes(encryptionModes), m_bResult(false){}
  151         virtual ~DecryptThreadRoutine() { }
  152         virtual void ExecutionCode(void) { m_bResult = m_pHeader->Decrypt(m_encryptedData, m_password, m_pim, m_kdf, m_truecryptMode, m_keyDerivationFunctions, m_encryptionAlgorithms, m_encryptionModes); }
  153     };
  154 
  155     class WaitThreadUI
  156     {
  157     public:
  158         WaitThreadUI(WaitThreadRoutine* pRoutine): m_pRoutine(pRoutine) {}
  159         virtual ~WaitThreadUI() {}
  160         virtual void Run(void) { m_pRoutine->ExecutionCode();}
  161         WaitThreadRoutine* m_pRoutine;
  162     };
  163 }
  164 
  165 #endif // TC_HEADER_Core_Core