"Fossies" - the Fresh Open Source Software Archive

Member "src/Volume/Volume.h" (10 Oct 2018, 6300 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 "Volume.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.22_Source_vs_1.23_Source.

    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_Volume_Volume
   14 #define TC_HEADER_Volume_Volume
   15 
   16 #include "Platform/Platform.h"
   17 #include "Platform/StringConverter.h"
   18 #include "EncryptionAlgorithm.h"
   19 #include "EncryptionMode.h"
   20 #include "Keyfile.h"
   21 #include "VolumePassword.h"
   22 #include "VolumeException.h"
   23 #include "VolumeLayout.h"
   24 
   25 namespace VeraCrypt
   26 {
   27     class VolumePath
   28     {
   29     public:
   30         VolumePath () { }
   31         VolumePath (const wstring &path) { Data = path; }
   32         VolumePath (const FilesystemPath &path) { Data = path; }
   33 
   34         bool operator== (const VolumePath &other) const { return Data == other.Data; }
   35         bool operator!= (const VolumePath &other) const { return Data != other.Data; }
   36         operator FilesystemPath () const { return FilesystemPath (Data); }
   37         operator string () const { return StringConverter::ToSingle (Data); }
   38         operator wstring () const { return Data; }
   39 
   40         bool IsDevice () const { return FilesystemPath (Data).IsBlockDevice() || FilesystemPath (Data).IsCharacterDevice(); }
   41         bool IsEmpty () const { return Data.empty(); }
   42         
   43         wstring GetExtension () const
   44         {
   45             if (Data.empty() || (Data.size() == 1))
   46                 return L"";
   47             else
   48             {
   49                 size_t pos = Data.find_last_of (L'.');
   50                 if (pos == string::npos)
   51                     return L"";
   52                 return Data.substr (pos + 1);
   53             }
   54         }
   55         
   56         bool HasTrueCryptExtension () const
   57         {
   58             wstring sExt = GetExtension ();
   59             if ((sExt.size () == 2) 
   60                 && (sExt[0] == L't' || sExt[0] == L'T')
   61                 && (sExt[1] == L'c' || sExt[1] == L'C')
   62                 )
   63             {
   64                 return true;
   65             }
   66             else
   67                 return false;
   68         }
   69 
   70     protected:
   71         wstring Data;
   72     };
   73 
   74     typedef list <VolumePath> VolumePathList;
   75 
   76     struct VolumeHostType
   77     {
   78         enum Enum
   79         {
   80             Unknown,
   81             File,
   82             Device
   83         };
   84     };
   85 
   86     struct VolumeProtection
   87     {
   88         enum Enum
   89         {
   90             None,
   91             ReadOnly,
   92             HiddenVolumeReadOnly
   93         };
   94     };
   95 
   96     class Volume
   97     {
   98     public:
   99         Volume ();
  100         virtual ~Volume ();
  101 
  102         void Close ();
  103         shared_ptr <EncryptionAlgorithm> GetEncryptionAlgorithm () const;
  104         shared_ptr <EncryptionMode> GetEncryptionMode () const;
  105         shared_ptr <File> GetFile () const { return VolumeFile; }
  106         shared_ptr <VolumeHeader> GetHeader () const { return Header; }
  107         uint64 GetHeaderCreationTime () const { return Header->GetHeaderCreationTime(); }
  108         uint64 GetHostSize () const { return VolumeHostSize; }
  109         shared_ptr <VolumeLayout> GetLayout () const { return Layout; }
  110         VolumePath GetPath () const { return VolumeFile->GetPath(); }
  111         VolumeProtection::Enum GetProtectionType () const { return Protection; }
  112         shared_ptr <Pkcs5Kdf> GetPkcs5Kdf () const { return Header->GetPkcs5Kdf(); }
  113         uint32 GetSaltSize () const { return Header->GetSaltSize(); }
  114         size_t GetSectorSize () const { return SectorSize; }
  115         uint64 GetSize () const { return VolumeDataSize; }
  116         uint64 GetEncryptedSize () const { return EncryptedDataSize; }
  117         uint64 GetTopWriteOffset () const { return TopWriteOffset; }
  118         uint64 GetTotalDataRead () const { return TotalDataRead; }
  119         uint64 GetTotalDataWritten () const { return TotalDataWritten; }
  120         VolumeType::Enum GetType () const { return Type; }
  121         bool GetTrueCryptMode() const { return TrueCryptMode; }
  122         int GetPim() const { return Pim;}
  123         uint64 GetVolumeCreationTime () const { return Header->GetVolumeCreationTime(); }
  124         bool IsHiddenVolumeProtectionTriggered () const { return HiddenVolumeProtectionTriggered; }
  125         bool IsInSystemEncryptionScope () const { return SystemEncryption; }
  126         void Open (const 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);
  127         void Open (shared_ptr <File> volumeFile, 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> (), VolumeType::Enum volumeType = VolumeType::Unknown, bool useBackupHeaders = false, bool partitionInSystemEncryptionScope = false);
  128         void ReadSectors (const BufferPtr &buffer, uint64 byteOffset);
  129         void ReEncryptHeader (bool backupHeader, const ConstBufferPtr &newSalt, const ConstBufferPtr &newHeaderKey, shared_ptr <Pkcs5Kdf> newPkcs5Kdf);
  130         void WriteSectors (const ConstBufferPtr &buffer, uint64 byteOffset);
  131         bool IsEncryptionNotCompleted () const { return EncryptionNotCompleted; }
  132 
  133     protected:
  134         void CheckProtectedRange (uint64 writeHostOffset, uint64 writeLength);
  135         void ValidateState () const;
  136 
  137         shared_ptr <EncryptionAlgorithm> EA;
  138         shared_ptr <VolumeHeader> Header;
  139         bool HiddenVolumeProtectionTriggered;
  140         shared_ptr <VolumeLayout> Layout;
  141         uint64 ProtectedRangeStart;
  142         uint64 ProtectedRangeEnd;
  143         VolumeProtection::Enum Protection;
  144         size_t SectorSize;
  145         bool SystemEncryption;
  146         VolumeType::Enum Type;
  147         shared_ptr <File> VolumeFile;
  148         uint64 VolumeHostSize;
  149         uint64 VolumeDataOffset;
  150         uint64 VolumeDataSize;
  151         uint64 EncryptedDataSize;
  152         uint64 TopWriteOffset;
  153         uint64 TotalDataRead;
  154         uint64 TotalDataWritten;
  155         bool TrueCryptMode;
  156         int Pim;
  157         bool EncryptionNotCompleted;
  158 
  159     private:
  160         Volume (const Volume &);
  161         Volume &operator= (const Volume &);
  162     };
  163 }
  164 
  165 #endif // TC_HEADER_Volume_Volume