"Fossies" - the Fresh Open Source Software Archive

Member "src/Volume/VolumeLayout.h" (10 Oct 2018, 5077 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 "VolumeLayout.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_Volume_VolumeLayout
   14 #define TC_HEADER_Volume_VolumeLayout
   15 
   16 #include "Platform/Platform.h"
   17 #include "Volume/EncryptionAlgorithm.h"
   18 #include "Volume/EncryptionMode.h"
   19 #include "Volume/Pkcs5Kdf.h"
   20 #include "VolumeHeader.h"
   21 
   22 namespace VeraCrypt
   23 {
   24     class VolumeLayout;
   25     typedef list < shared_ptr <VolumeLayout> > VolumeLayoutList;
   26 
   27     class VolumeLayout
   28     {
   29     public:
   30         virtual ~VolumeLayout ();
   31 
   32         static VolumeLayoutList GetAvailableLayouts (VolumeType::Enum type = VolumeType::Unknown);
   33         virtual int GetBackupHeaderOffset () const { return BackupHeaderOffset; } // Positive value: offset from the start of host, negative: offset from the end
   34         virtual uint64 GetDataOffset (uint64 volumeHostSize) const = 0;
   35         virtual uint64 GetDataSize (uint64 volumeHostSize) const = 0;
   36         virtual shared_ptr <VolumeHeader> GetHeader ();
   37         virtual int GetHeaderOffset () const { return HeaderOffset; } // Positive value: offset from the start of host, negative: offset from the end
   38         virtual uint32 GetHeaderSize () const { return HeaderSize; }
   39         virtual uint64 GetMaxDataSize (uint64 volumeSize) const = 0;
   40         virtual EncryptionAlgorithmList GetSupportedEncryptionAlgorithms () const { return SupportedEncryptionAlgorithms; }
   41         virtual Pkcs5KdfList GetSupportedKeyDerivationFunctions (bool truecryptMode) const { return Pkcs5Kdf::GetAvailableAlgorithms(truecryptMode); }
   42         virtual EncryptionModeList GetSupportedEncryptionModes () const { return SupportedEncryptionModes; }
   43         virtual VolumeType::Enum GetType () const { return Type; }
   44         virtual bool HasBackupHeader () const = 0;
   45         virtual bool HasDriveHeader () const { return false; }
   46         virtual void SetHeader (shared_ptr <VolumeHeader> header) { Header = header; }
   47 
   48     protected:
   49         VolumeLayout ();
   50 
   51         EncryptionAlgorithmList SupportedEncryptionAlgorithms;
   52         EncryptionModeList SupportedEncryptionModes;
   53 
   54         int BackupHeaderOffset;
   55         int HeaderOffset;
   56         uint32 HeaderSize;
   57         VolumeType::Enum Type;
   58 
   59         shared_ptr <VolumeHeader> Header;
   60 
   61     private:
   62         VolumeLayout (const VolumeLayout &);
   63         VolumeLayout &operator= (const VolumeLayout &);
   64     };
   65 
   66 
   67     class VolumeLayoutV1Normal : public VolumeLayout
   68     {
   69     public:
   70         VolumeLayoutV1Normal ();
   71         virtual ~VolumeLayoutV1Normal () { }
   72 
   73         virtual int GetBackupHeaderOffset () const { throw NotApplicable (SRC_POS); }
   74         virtual uint64 GetDataOffset (uint64 volumeHostSize) const;
   75         virtual uint64 GetDataSize (uint64 volumeHostSize) const;
   76         virtual uint64 GetMaxDataSize (uint64 volumeSize) const { throw NotApplicable (SRC_POS); }
   77         virtual bool HasBackupHeader () const { return false; }
   78 
   79     private:
   80         VolumeLayoutV1Normal (const VolumeLayoutV1Normal &);
   81         VolumeLayoutV1Normal &operator= (const VolumeLayoutV1Normal &);
   82     };
   83 
   84 
   85     class VolumeLayoutV2Normal : public VolumeLayout
   86     {
   87     public:
   88         VolumeLayoutV2Normal ();
   89         virtual ~VolumeLayoutV2Normal () { }
   90 
   91         virtual uint64 GetDataOffset (uint64 volumeHostSize) const;
   92         virtual uint64 GetDataSize (uint64 volumeHostSize) const;
   93         virtual uint64 GetMaxDataSize (uint64 volumeSize) const;
   94         virtual bool HasBackupHeader () const { return true; }
   95 
   96     private:
   97         VolumeLayoutV2Normal (const VolumeLayoutV2Normal &);
   98         VolumeLayoutV2Normal &operator= (const VolumeLayoutV2Normal &);
   99     };
  100 
  101 
  102     class VolumeLayoutV2Hidden : public VolumeLayout
  103     {
  104     public:
  105         VolumeLayoutV2Hidden ();
  106         virtual ~VolumeLayoutV2Hidden () { }
  107 
  108         virtual uint64 GetDataOffset (uint64 volumeHostSize) const;
  109         virtual uint64 GetDataSize (uint64 volumeHostSize) const;
  110         virtual uint64 GetMaxDataSize (uint64 volumeSize) const;
  111         virtual bool HasBackupHeader () const { return true; }
  112 
  113     private:
  114         VolumeLayoutV2Hidden (const VolumeLayoutV2Hidden &);
  115         VolumeLayoutV2Hidden &operator= (const VolumeLayoutV2Hidden &);
  116     };
  117 
  118 
  119     class VolumeLayoutSystemEncryption : public VolumeLayout
  120     {
  121     public:
  122         VolumeLayoutSystemEncryption ();
  123         virtual ~VolumeLayoutSystemEncryption () { }
  124 
  125         virtual int GetBackupHeaderOffset () const { throw NotApplicable (SRC_POS); }
  126         virtual uint64 GetDataOffset (uint64 volumeHostSize) const;
  127         virtual uint64 GetDataSize (uint64 volumeHostSize) const;
  128         virtual uint64 GetMaxDataSize (uint64 volumeSize) const { throw NotApplicable (SRC_POS); }
  129         virtual Pkcs5KdfList GetSupportedKeyDerivationFunctions (bool truecryptMode) const;
  130         virtual bool HasBackupHeader () const { return false; }
  131         virtual bool HasDriveHeader () const { return true; }
  132 
  133     private:
  134         VolumeLayoutSystemEncryption (const VolumeLayoutSystemEncryption &);
  135         VolumeLayoutSystemEncryption &operator= (const VolumeLayoutSystemEncryption &);
  136     };
  137 }
  138 
  139 #endif // TC_HEADER_Volume_VolumeLayout