"Fossies" - the Fresh Open Source Software Archive

Member "src/Volume/VolumeHeader.h" (10 Oct 2018, 4590 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 "VolumeHeader.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_VolumeHeader
   14 #define TC_HEADER_Volume_VolumeHeader
   15 
   16 #include "Common/Tcdefs.h"
   17 #include "Common/Volumes.h"
   18 #include "Platform/Platform.h"
   19 #include "Volume/EncryptionAlgorithm.h"
   20 #include "Volume/EncryptionMode.h"
   21 #include "Volume/Keyfile.h"
   22 #include "Volume/VolumePassword.h"
   23 #include "Volume/Pkcs5Kdf.h"
   24 #include "Version.h"
   25 
   26 
   27 // For specifications of the volume header see Common/Volumes.c
   28 
   29 namespace VeraCrypt
   30 {
   31     typedef uint64 VolumeTime;
   32 
   33     struct VolumeType
   34     {
   35         enum Enum
   36         {
   37             Unknown,
   38             Normal,
   39             Hidden
   40         };
   41     };
   42 
   43     struct VolumeHeaderCreationOptions
   44     {
   45         ConstBufferPtr DataKey;
   46         shared_ptr <EncryptionAlgorithm> EA;
   47         shared_ptr <Pkcs5Kdf> Kdf;
   48         ConstBufferPtr HeaderKey;
   49         ConstBufferPtr Salt;
   50         uint32 SectorSize;
   51         uint64 VolumeDataSize;
   52         uint64 VolumeDataStart;
   53         VolumeType::Enum Type;
   54     };
   55 
   56     class VolumeHeader
   57     {
   58     public:
   59         VolumeHeader (uint32 HeaderSize);
   60         virtual ~VolumeHeader ();
   61 
   62         void Create (const BufferPtr &headerBuffer, VolumeHeaderCreationOptions &options);
   63         bool Decrypt (const ConstBufferPtr &encryptedData, const VolumePassword &password, int pim, shared_ptr <Pkcs5Kdf> kdf, bool truecryptMode, const Pkcs5KdfList &keyDerivationFunctions, const EncryptionAlgorithmList &encryptionAlgorithms, const EncryptionModeList &encryptionModes);
   64         void EncryptNew (const BufferPtr &newHeaderBuffer, const ConstBufferPtr &newSalt, const ConstBufferPtr &newHeaderKey, shared_ptr <Pkcs5Kdf> newPkcs5Kdf);
   65         uint64 GetEncryptedAreaStart () const { return EncryptedAreaStart; }
   66         uint64 GetEncryptedAreaLength () const { return EncryptedAreaLength; }
   67         shared_ptr <EncryptionAlgorithm> GetEncryptionAlgorithm () const { return EA; }
   68         uint32 GetFlags () const { return Flags; }
   69         VolumeTime GetHeaderCreationTime () const { return HeaderCreationTime; }
   70         uint64 GetHiddenVolumeDataSize () const { return HiddenVolumeDataSize; }
   71         static size_t GetLargestSerializedKeySize ();
   72         shared_ptr <Pkcs5Kdf> GetPkcs5Kdf () const { return Pkcs5; }
   73         uint16 GetRequiredMinProgramVersion () const { return RequiredMinProgramVersion; }
   74         size_t GetSectorSize () const { return SectorSize; }
   75         static uint32 GetSaltSize () { return SaltSize; }
   76         uint64 GetVolumeDataSize () const { return VolumeDataSize; }
   77         VolumeTime GetVolumeCreationTime () const { return VolumeCreationTime; }
   78         void SetSize (uint32 headerSize);
   79 
   80     protected:
   81         bool Deserialize (const ConstBufferPtr &header, shared_ptr <EncryptionAlgorithm> &ea, shared_ptr <EncryptionMode> &mode, bool truecryptMode);
   82         template <typename T> T DeserializeEntry (const ConstBufferPtr &header, size_t &offset) const;
   83         template <typename T> T DeserializeEntryAt (const ConstBufferPtr &header, const size_t &offset) const;
   84         void Init ();
   85         void Serialize (const BufferPtr &header) const;
   86         template <typename T> void SerializeEntry (const T &entry, const BufferPtr &header, size_t &offset) const;
   87 
   88         uint32 HeaderSize;
   89 
   90         static const uint16 CurrentHeaderVersion = VOLUME_HEADER_VERSION;
   91         static const uint16 CurrentRequiredMinProgramVersion = TC_VOLUME_MIN_REQUIRED_PROGRAM_VERSION;
   92         static const uint16 MinAllowedHeaderVersion = 1;
   93 
   94         static const int SaltOffset = 0;
   95         static const uint32 SaltSize = 64;
   96 
   97         static const int EncryptedHeaderDataOffset = SaltOffset + SaltSize;
   98         uint32 EncryptedHeaderDataSize;
   99 
  100         static const uint32 LegacyEncryptionModeKeyAreaSize = 32;
  101         static const int DataKeyAreaMaxSize = 256;
  102         static const uint32 DataAreaKeyOffset = DataKeyAreaMaxSize - EncryptedHeaderDataOffset;
  103 
  104         shared_ptr <EncryptionAlgorithm> EA;
  105         shared_ptr <Pkcs5Kdf> Pkcs5;
  106 
  107         uint16 HeaderVersion;
  108         uint16 RequiredMinProgramVersion;
  109         uint32 VolumeKeyAreaCrc32;
  110 
  111         VolumeTime VolumeCreationTime;
  112         VolumeTime HeaderCreationTime;
  113 
  114         VolumeType::Enum mVolumeType;
  115         uint64 HiddenVolumeDataSize;
  116         uint64 VolumeDataSize;
  117         uint64 EncryptedAreaStart;
  118         uint64 EncryptedAreaLength;
  119         uint32 Flags;
  120         uint32 SectorSize;
  121 
  122         SecureBuffer DataAreaKey;
  123 
  124     private:
  125         VolumeHeader (const VolumeHeader &);
  126         VolumeHeader &operator= (const VolumeHeader &);
  127     };
  128 }
  129 
  130 #endif // TC_HEADER_Volume_VolumeHeader