|
|
1.1 ! root 1: /* ! 2: Copyright (c) 2008 TrueCrypt Foundation. All rights reserved. ! 3: ! 4: Governed by the TrueCrypt License 2.4 the full text of which is contained ! 5: in the file License.txt included in TrueCrypt binary and source code ! 6: distribution packages. ! 7: */ ! 8: ! 9: #ifndef TC_HEADER_Volume_VolumeHeader ! 10: #define TC_HEADER_Volume_VolumeHeader ! 11: ! 12: #include "Common/Tcdefs.h" ! 13: #include "Platform/Platform.h" ! 14: #include "Volume/EncryptionAlgorithm.h" ! 15: #include "Volume/EncryptionMode.h" ! 16: #include "Volume/Keyfile.h" ! 17: #include "Volume/VolumePassword.h" ! 18: #include "Volume/Pkcs5Kdf.h" ! 19: #include "Version.h" ! 20: ! 21: /* Volume header v3 structure: */ ! 22: // ! 23: // Offset Length Description ! 24: // ------------------------------------------ ! 25: // Unencrypted: ! 26: // 0 64 Salt ! 27: // Encrypted: ! 28: // 64 4 ASCII string 'TRUE' ! 29: // 68 2 Header version ! 30: // 70 2 Required program version ! 31: // 72 4 CRC-32 checksum of the (decrypted) bytes 256-511 ! 32: // 76 8 Volume creation time ! 33: // 84 8 Header creation time ! 34: // 92 8 Size of hidden volume in bytes (0 = normal volume) ! 35: // 100 8 Size of the volume in bytes (identical with field 92 for hidden volumes) ! 36: // 108 8 Start byte offset of the encrypted area of the volume ! 37: // 116 8 Size of the encrypted area of the volume in bytes ! 38: // 124 132 Reserved (set to zero) ! 39: // 256 256 Concatenated primary master key(s) and secondary master key(s) (XTS mode) ! 40: ! 41: ! 42: /* Deprecated/legacy volume header v2 structure (used before TrueCrypt 5.0): */ ! 43: // ! 44: // Offset Length Description ! 45: // ------------------------------------------ ! 46: // Unencrypted: ! 47: // 0 64 Salt ! 48: // Encrypted: ! 49: // 64 4 ASCII string 'TRUE' ! 50: // 68 2 Header version ! 51: // 70 2 Required program version ! 52: // 72 4 CRC-32 checksum of the (decrypted) bytes 256-511 ! 53: // 76 8 Volume creation time ! 54: // 84 8 Header creation time ! 55: // 92 8 Size of hidden volume in bytes (0 = normal volume) ! 56: // 100 156 Reserved (set to zero) ! 57: // 256 32 For LRW (deprecated/legacy), secondary key ! 58: // For CBC (deprecated/legacy), data used to generate IV and whitening values ! 59: // 288 224 Master key(s) ! 60: ! 61: namespace TrueCrypt ! 62: { ! 63: typedef uint64 VolumeTime; ! 64: ! 65: struct VolumeType ! 66: { ! 67: enum Enum ! 68: { ! 69: Unknown, ! 70: Normal, ! 71: Hidden ! 72: }; ! 73: }; ! 74: ! 75: struct VolumeHeaderCreationOptions ! 76: { ! 77: ConstBufferPtr DataKey; ! 78: shared_ptr <EncryptionAlgorithm> EA; ! 79: shared_ptr <Pkcs5Kdf> Kdf; ! 80: ConstBufferPtr HeaderKey; ! 81: ConstBufferPtr Salt; ! 82: uint64 VolumeSize; ! 83: VolumeType::Enum Type; ! 84: }; ! 85: ! 86: class VolumeHeader ! 87: { ! 88: public: ! 89: VolumeHeader (uint32 HeaderSize); ! 90: virtual ~VolumeHeader (); ! 91: ! 92: void Create (const BufferPtr &headerBuffer, VolumeHeaderCreationOptions &options); ! 93: bool Decrypt (const ConstBufferPtr &encryptedData, const VolumePassword &password, const EncryptionAlgorithmList &encryptionAlgorithms, const EncryptionModeList &encryptionModes); ! 94: void EncryptNew (const BufferPtr &newHeaderBuffer, const ConstBufferPtr &newSalt, const ConstBufferPtr &newHeaderKey, shared_ptr <Pkcs5Kdf> newPkcs5Kdf); ! 95: shared_ptr <EncryptionAlgorithm> GetEncryptionAlgorithm () const { return EA; } ! 96: VolumeTime GetHeaderCreationTime () const { return HeaderCreationTime; } ! 97: uint64 GetHiddenVolumeDataSize () const { return HiddenVolumeDataSize; } ! 98: static size_t GetLargestSerializedKeySize (); ! 99: shared_ptr <Pkcs5Kdf> GetPkcs5Kdf () const { return Pkcs5; } ! 100: size_t GetSectorSize () const { return 512; } ! 101: static uint32 GetSaltSize () { return SaltSize; } ! 102: uint64 GetVolumeDataSize () const { return VolumeDataSize; } ! 103: VolumeTime GetVolumeCreationTime () const { return VolumeCreationTime; } ! 104: ! 105: protected: ! 106: bool Deserialize (const ConstBufferPtr &header, shared_ptr <EncryptionAlgorithm> &ea, shared_ptr <EncryptionMode> &mode); ! 107: template <typename T> T DeserializeEntry (const ConstBufferPtr &header, size_t &offset) const; ! 108: void Serialize (const BufferPtr &header) const; ! 109: template <typename T> void SerializeEntry (const T &entry, const BufferPtr &header, size_t &offset) const; ! 110: ! 111: uint32 HeaderSize; ! 112: ! 113: static const uint16 CurrentHeaderVersion = VOLUME_HEADER_VERSION; ! 114: static const uint16 CurrentRequiredMinProgramVersion = VOL_REQ_PROG_VERSION; ! 115: static const uint16 MinAllowedHeaderVersion = 1; ! 116: ! 117: static const int SaltOffset = 0; ! 118: static const uint32 SaltSize = 64; ! 119: ! 120: static const int EncryptedHeaderDataOffset = SaltOffset + SaltSize; ! 121: uint32 EncryptedHeaderDataSize; ! 122: ! 123: static const uint32 LegacyEncryptionModeKeyAreaSize = 32; ! 124: static const int DataKeyAreaMaxSize = 256; ! 125: static const uint32 DataAreaKeyOffset = DataKeyAreaMaxSize - EncryptedHeaderDataOffset; ! 126: ! 127: shared_ptr <EncryptionAlgorithm> EA; ! 128: shared_ptr <Pkcs5Kdf> Pkcs5; ! 129: ! 130: uint16 HeaderVersion; ! 131: uint16 RequiredMinProgramVersion; ! 132: uint32 VolumeKeyAreaCrc32; ! 133: ! 134: VolumeTime VolumeCreationTime; ! 135: VolumeTime HeaderCreationTime; ! 136: ! 137: VolumeType::Enum mVolumeType; ! 138: uint64 HiddenVolumeDataSize; ! 139: uint64 VolumeDataSize; ! 140: uint64 EncryptedAreaStart; ! 141: uint64 EncryptedAreaLength; ! 142: ! 143: SecureBuffer DataAreaKey; ! 144: ! 145: private: ! 146: VolumeHeader (const VolumeHeader &); ! 147: VolumeHeader &operator= (const VolumeHeader &); ! 148: }; ! 149: } ! 150: ! 151: #endif // TC_HEADER_Volume_VolumeHeader
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.