"Fossies" - the Fresh Open Source Software Archive

Member "src/Boot/Windows/BootCommon.h" (10 Oct 2018, 7579 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 "BootCommon.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_Boot_BootCommon
   14 #define TC_HEADER_Boot_BootCommon
   15 
   16 #include "Common/Password.h"
   17 #include "BootDefs.h"
   18 
   19 // The user will be advised to upgrade the rescue disk if upgrading from the following or any previous version
   20 #define TC_RESCUE_DISK_UPGRADE_NOTICE_MAX_VERSION 0x0122
   21 
   22 #define TC_BOOT_LOADER_AREA_SIZE (TC_BOOT_LOADER_AREA_SECTOR_COUNT * TC_SECTOR_SIZE_BIOS)
   23 
   24 #define TC_BOOT_VOLUME_HEADER_SECTOR (TC_BOOT_LOADER_AREA_SECTOR_COUNT - 1)
   25 #define TC_BOOT_VOLUME_HEADER_SECTOR_OFFSET (TC_BOOT_VOLUME_HEADER_SECTOR * TC_SECTOR_SIZE_BIOS)
   26 
   27 #define TC_CD_BOOTSECTOR_OFFSET 0xd000
   28 #define TC_CD_BOOT_LOADER_SECTOR 26
   29 
   30 #define TC_ORIG_BOOT_LOADER_BACKUP_SECTOR TC_BOOT_LOADER_AREA_SECTOR_COUNT
   31 #define TC_ORIG_BOOT_LOADER_BACKUP_SECTOR_OFFSET (TC_ORIG_BOOT_LOADER_BACKUP_SECTOR * TC_SECTOR_SIZE_BIOS)
   32 
   33 #define TC_BOOT_LOADER_BACKUP_RESCUE_DISK_SECTOR (TC_ORIG_BOOT_LOADER_BACKUP_SECTOR + TC_BOOT_LOADER_AREA_SECTOR_COUNT)
   34 #define TC_BOOT_LOADER_BACKUP_RESCUE_DISK_SECTOR_OFFSET (TC_BOOT_LOADER_BACKUP_RESCUE_DISK_SECTOR * TC_SECTOR_SIZE_BIOS)
   35 
   36 #define TC_MBR_SECTOR 0
   37 #define TC_MAX_MBR_BOOT_CODE_SIZE 440
   38 
   39 #define TC_MAX_EXTRA_BOOT_PARTITION_SIZE (512UL * 1024UL * 1024UL)
   40 
   41 
   42 #pragma pack (1)
   43 
   44 typedef struct
   45 {
   46     byte Flags;
   47 } BootSectorConfiguration;
   48 
   49 
   50 // Modifying this value can introduce incompatibility with previous versions
   51 #define TC_BOOT_LOADER_ARGS_OFFSET 0x10
   52 
   53 typedef struct
   54 {
   55     // Modifying this structure can introduce incompatibility with previous versions
   56     char Signature[8];
   57     uint16 BootLoaderVersion;
   58     uint16 CryptoInfoOffset;
   59     uint16 CryptoInfoLength;
   60     uint32 HeaderSaltCrc32;
   61     Password BootPassword;
   62     uint64 HiddenSystemPartitionStart;
   63     uint64 DecoySystemPartitionStart;
   64     uint32 Flags;
   65     uint32 BootDriveSignature;
   66 
   67     uint32 BootArgumentsCrc32;
   68 
   69 } BootArguments;
   70 
   71 // Modifying these values can introduce incompatibility with previous versions
   72 #define TC_BOOT_ARGS_FLAG_EXTRA_BOOT_PARTITION              0x1
   73 
   74 #pragma pack ()
   75 
   76 // Boot arguments signature should not be defined as a static string
   77 // Modifying these values can introduce incompatibility with previous versions
   78 #define TC_SET_BOOT_ARGUMENTS_SIGNATURE(SG) do { SG[0]  = 'T';   SG[1]  = 'R';   SG[2]  = 'U';   SG[3]  = 'E';   SG[4]  = 0x11;   SG[5]  = 0x23;   SG[6]  = 0x45;   SG[7]  = 0x66; } while (FALSE)
   79 #define TC_IS_BOOT_ARGUMENTS_SIGNATURE(SG)      (SG[0] == 'T' && SG[1] == 'R' && SG[2] == 'U' && SG[3] == 'E' && SG[4] == 0x11 && SG[5] == 0x23 && SG[6] == 0x45 && SG[7] == 0x66)
   80 
   81 #if defined(_MSC_VER) && !defined(TC_WINDOWS_BOOT)
   82 
   83 #define DCS_DISK_ENTRY_LIST_HEADER_SIGN      SIGNATURE_64 ('D','C','S','D','E','L','S','T')
   84 
   85 #ifndef CSTATIC_ASSERT
   86 #define CSTATIC_ASSERT(b, name) typedef int StaticAssertFailed##name[b ? 1 : -1];
   87 #endif
   88 
   89 #define DE_IDX_CRYPTOHEADER  0
   90 #define DE_IDX_LIST          1
   91 #define DE_IDX_DISKID        2
   92 #define DE_IDX_MAINGPTHDR    3
   93 #define DE_IDX_MAINGPTENTRYS 4
   94 #define DE_IDX_ALTGPTHDR     5
   95 #define DE_IDX_ALTGPTENTRYS  6
   96 #define DE_IDX_EXEC          7
   97 #define DE_IDX_PWDCACHE      8
   98 #define DE_IDX_RND           9
   99 #define DE_IDX_TOTAL         10
  100 CSTATIC_ASSERT(DE_IDX_TOTAL <= 15, DE_IDX_TOTAL_too_big);
  101 
  102 enum DcsDiskEntryTypes {
  103     DE_Unused = 0,
  104     DE_Sectors,
  105     DE_List,
  106     DE_DISKID,
  107     DE_ExecParams,
  108     DE_PwdCache,
  109     DE_Rnd
  110 };
  111 
  112 #pragma pack(1)
  113 typedef struct _SECREGION_BOOT_PARAMS {
  114     uint64               Ptr;
  115     uint32               Size;
  116     uint32               Crc;
  117 } SECREGION_BOOT_PARAMS;
  118 
  119 typedef struct {
  120     uint32  Data1;
  121     uint16  Data2;
  122     uint16  Data3;
  123     byte    Data4[8];
  124 } DCS_GUID;
  125 
  126 // DE types
  127 typedef struct _DCS_DISK_ENTRY_SECTORS {
  128     uint32      Type;
  129     uint32      Offset; // Offset in memory
  130     uint64      Reserved;
  131     uint64      Start;  // Start on disk (byte)
  132     uint64      Length; // length on disk (byte)
  133 } DCS_DISK_ENTRY_SECTORS;
  134 CSTATIC_ASSERT(sizeof(DCS_DISK_ENTRY_SECTORS) ==    32, Wrong_size_DCS_DISK_ENTRY_SECTORS);
  135 
  136 typedef struct _DCS_DISK_ENTRY_PARAMS {
  137     uint32      Type;
  138     uint32      Offset;
  139     uint64      Reserved[2];
  140     uint64      Length;           // size of data
  141 } DCS_DISK_ENTRY_PARAMS;
  142 CSTATIC_ASSERT(sizeof(DCS_DISK_ENTRY_PARAMS) == 32, Wrong_size_DCS_DISK_ENTRY_PARAMS);
  143 
  144 typedef struct _DCS_DISK_ENTRY_DISKID {
  145     uint32      Type;
  146     uint32      MbrID;
  147     uint64      ReservedDiskId;
  148     DCS_GUID    GptID;
  149 } DCS_DISK_ENTRY_DISKID;
  150 CSTATIC_ASSERT(sizeof(DCS_DISK_ENTRY_DISKID) == 32, Wrong_size_DCS_DISK_ENTRY_DISKID);
  151 
  152 #pragma warning(disable:4201)
  153 typedef struct _DCS_DISK_ENTRY {
  154     union {
  155         struct {
  156             uint32      Type;
  157             uint32      Offset;
  158             byte        reserved[16];
  159             uint64      Length;           // size of structure at Offset
  160         };
  161         DCS_DISK_ENTRY_SECTORS Sectors;
  162         DCS_DISK_ENTRY_DISKID  DiskId;
  163         DCS_DISK_ENTRY_PARAMS  Prm;
  164     };
  165 } DCS_DISK_ENTRY;
  166 #pragma warning(default:4201)
  167 CSTATIC_ASSERT(sizeof(DCS_DISK_ENTRY) == 32, Wrong_size_DCS_DISK_ENTRY);
  168 
  169 // Static compile time checks field offsets
  170 #ifndef FIELD_OFFSET
  171 #define FIELD_OFFSET(t, f) ((UINTN)(&((t*)0)->f))
  172 #endif
  173 CSTATIC_ASSERT(FIELD_OFFSET(DCS_DISK_ENTRY, Type)   == FIELD_OFFSET(DCS_DISK_ENTRY_SECTORS, Type),   Wrong_Type_offset);
  174 CSTATIC_ASSERT(FIELD_OFFSET(DCS_DISK_ENTRY, Type)   == FIELD_OFFSET(DCS_DISK_ENTRY_DISKID,  Type),   Wrong_Type_offset);
  175 CSTATIC_ASSERT(FIELD_OFFSET(DCS_DISK_ENTRY, Type)   == FIELD_OFFSET(DCS_DISK_ENTRY_PARAMS,  Type),   Wrong_Type_offset);
  176 CSTATIC_ASSERT(FIELD_OFFSET(DCS_DISK_ENTRY, Length) == FIELD_OFFSET(DCS_DISK_ENTRY_SECTORS, Length), Wrong_Length_offset);
  177 CSTATIC_ASSERT(FIELD_OFFSET(DCS_DISK_ENTRY, Length) == FIELD_OFFSET(DCS_DISK_ENTRY_PARAMS,  Length), Wrong_Length_offset);
  178 CSTATIC_ASSERT(FIELD_OFFSET(DCS_DISK_ENTRY, Offset) == FIELD_OFFSET(DCS_DISK_ENTRY_SECTORS, Offset), Wrong_Offset_offset);
  179 CSTATIC_ASSERT(FIELD_OFFSET(DCS_DISK_ENTRY, Offset) == FIELD_OFFSET(DCS_DISK_ENTRY_PARAMS,  Offset), Wrong_Offset_offset);
  180 
  181 // DE type specific data 
  182 // DE List
  183 typedef struct _DCS_DISK_ENTRY_LIST {
  184     //  EFI_TABLE_HEADER
  185     uint64  Signature;
  186     uint32  Revision;
  187     uint32  HeaderSize; //< The size, in bytes, of the entire table including the EFI_TABLE_HEADER.
  188     uint32  CRC32;       //< The 32-bit CRC for the entire table. This value is computed by setting this field to 0, and computing the 32-bit CRC for HeaderSize bytes.
  189     uint32  Reserved;   //< Reserved field that must be set to 0.
  190                                 //
  191     uint32  Count;
  192     uint32  DataSize;
  193     //
  194     DCS_DISK_ENTRY  DE[15];
  195 } DCS_DISK_ENTRY_LIST;
  196 CSTATIC_ASSERT(sizeof(DCS_DISK_ENTRY_LIST) == 512, Wrong_size_DCS_DISK_ENTRY_LIST);
  197 
  198 typedef struct _DCS_DEP_EXEC {
  199     DCS_GUID     ExecPartGuid;
  200     uint16       ExecCmd[248];
  201 } DCS_DEP_EXEC;
  202 CSTATIC_ASSERT(sizeof(DCS_DEP_EXEC) == 512, Wrong_size_DCS_DEP_EXEC);
  203 
  204 #define DCS_DEP_PWD_CACHE_SIGN      SIGNATURE_64 ('P','W','D','C','A','C','H','E')
  205 typedef struct _DCS_DEP_PWD_CACHE {
  206     uint64       Sign;
  207     uint32       CRC;
  208     uint32       Count;
  209     Password     Pwd[4];
  210     int32        Pim[4];
  211     byte         pad[512 - 8 - 4 - 4 - (sizeof(Password) + 4) * 4];
  212 } DCS_DEP_PWD_CACHE;
  213 CSTATIC_ASSERT(sizeof(DCS_DEP_PWD_CACHE) == 512, Wrong_size_DCS_DEP_PWD_CACHE);
  214 #pragma pack()
  215 
  216 #endif // #if !defined(TC_WINDOWS_BOOT)
  217 
  218 #endif // TC_HEADER_Boot_BootCommon