"Fossies" - the Fresh Open Source Software Archive

Member "src/Common/Apidrvr.h" (10 Oct 2018, 13355 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 "Apidrvr.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  Legal Notice: Some portions of the source code contained in this file were
    3  derived from the source code of TrueCrypt 7.1a, which is
    4  Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
    5  governed by the TrueCrypt License 3.0, also from the source code of
    6  Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
    7  and which is governed by the 'License Agreement for Encryption for the Masses'
    8  Modifications and additions to the original source code (contained in this file)
    9  and all other portions of this file are Copyright (c) 2013-2017 IDRIX
   10  and are governed by the Apache License 2.0 the full text of which is
   11  contained in the file License.txt included in VeraCrypt binary and source
   12  code distribution packages. */
   13 
   14 #pragma once
   15 
   16 #include "Tcdefs.h"
   17 #include "Boot/Windows/BootDefs.h"
   18 #include "Common.h"
   19 #include "Crypto.h"
   20 #include "Volumes.h"
   21 #include "Wipe.h"
   22 
   23 #ifdef _WIN32
   24 
   25 /* WARNING: Modifying the following values or their meanings can introduce incompatibility with previous versions. */
   26 
   27 #define TC_IOCTL(CODE) (CTL_CODE (FILE_DEVICE_UNKNOWN, 0x800 + (CODE), METHOD_BUFFERED, FILE_ANY_ACCESS))
   28 
   29 // IOCTL interface to \\device\veracrypt
   30 
   31 // Gets version of driver
   32 // OUT struct - LONG
   33 #define TC_IOCTL_GET_DRIVER_VERSION                     TC_IOCTL (1)
   34 
   35 // Gets boot loader version
   36 // OUT struct - int16
   37 #define TC_IOCTL_GET_BOOT_LOADER_VERSION                TC_IOCTL (2)
   38 
   39 // Mount volume to \\Device\VeraCryptVolume"X"
   40 // IN OUT - MOUNT_STRUCT
   41 #define TC_IOCTL_MOUNT_VOLUME                           TC_IOCTL (3)
   42 
   43 // Dismount volume
   44 // IN OUT - UNMOUNT_STRUCT
   45 #define TC_IOCTL_DISMOUNT_VOLUME                        TC_IOCTL (4)
   46 
   47 // Dismount all volumes
   48 // IN OUT - UNMOUNT_STRUCT
   49 #define TC_IOCTL_DISMOUNT_ALL_VOLUMES                   TC_IOCTL (5)
   50 
   51 // Get list of all mounted volumes
   52 // IN OUT - MOUNT_LIST_STRUCT (only 26 volumes possible)
   53 #define TC_IOCTL_GET_MOUNTED_VOLUMES                    TC_IOCTL (6)
   54 
   55 // Get properties of the volume selected by driveNo
   56 // In OUT - VOLUME_PROPERTIES_STRUCT
   57 #define TC_IOCTL_GET_VOLUME_PROPERTIES                  TC_IOCTL (7)
   58 
   59 // Get reference count to main device object
   60 // OUT - int
   61 #define TC_IOCTL_GET_DEVICE_REFCOUNT                    TC_IOCTL (8)
   62 
   63 // Is it possible to unload driver 
   64 // It check file system cache of mounted drives via unmount IOCTL.
   65 // OUT - int
   66 #define TC_IOCTL_IS_DRIVER_UNLOAD_DISABLED              TC_IOCTL (9)
   67 
   68 // Is there any mounted device
   69 // OUT - int
   70 #define TC_IOCTL_IS_ANY_VOLUME_MOUNTED                  TC_IOCTL (10)
   71 
   72 // Check password cache
   73 // Result in IOCTL result TRUE if there is chached passwords
   74 #define TC_IOCTL_GET_PASSWORD_CACHE_STATUS              TC_IOCTL (11)
   75 
   76 // Clean password cache
   77 #define TC_IOCTL_WIPE_PASSWORD_CACHE                    TC_IOCTL (12)
   78 
   79 // Check file/drive container
   80 // IN OUT - OPEN_TEST_STRUCT
   81 #define TC_IOCTL_OPEN_TEST                              TC_IOCTL (13)
   82 
   83 // result of IOCTL_DISK_GET_PARTITION_INFO
   84 // IN OUT - DISK_PARTITION_INFO_STRUCT
   85 // TODO: need IOCTL_DISK_GET_PARTITION_INFO_EX to support GPT
   86 #define TC_IOCTL_GET_DRIVE_PARTITION_INFO               TC_IOCTL (14)
   87 
   88 // result IOCTL_DISK_GET_DRIVE_GEOMETRY
   89 // IN OUT - DISK_GEOMETRY_STRUCT
   90 #define TC_IOCTL_GET_DRIVE_GEOMETRY                     TC_IOCTL (15)
   91 
   92 // result IOCTL_DISK_GET_LENGTH_INFO
   93 // IN OUT - ProbeRealDriveSizeRequest
   94 #define TC_IOCTL_PROBE_REAL_DRIVE_SIZE                  TC_IOCTL (16)
   95 
   96 // result of ZwQuerySymbolicLinkObject
   97 // IN OUT RESOLVE_SYMLINK_STRUCT
   98 #define TC_IOCTL_GET_RESOLVED_SYMLINK                   TC_IOCTL (17)
   99 
  100 #define TC_IOCTL_GET_BOOT_ENCRYPTION_STATUS             TC_IOCTL (18)
  101 #define TC_IOCTL_BOOT_ENCRYPTION_SETUP                  TC_IOCTL (19)
  102 #define TC_IOCTL_ABORT_BOOT_ENCRYPTION_SETUP            TC_IOCTL (20)
  103 #define TC_IOCTL_GET_BOOT_ENCRYPTION_SETUP_RESULT       TC_IOCTL (21)
  104 #define TC_IOCTL_GET_BOOT_DRIVE_VOLUME_PROPERTIES       TC_IOCTL (22)
  105 #define TC_IOCTL_REOPEN_BOOT_VOLUME_HEADER              TC_IOCTL (23)
  106 #define TC_IOCTL_GET_BOOT_ENCRYPTION_ALGORITHM_NAME     TC_IOCTL (24)
  107 #define TC_IOCTL_GET_PORTABLE_MODE_STATUS               TC_IOCTL (25)
  108 #define TC_IOCTL_SET_PORTABLE_MODE_STATUS               TC_IOCTL (26)
  109 #define TC_IOCTL_IS_HIDDEN_SYSTEM_RUNNING               TC_IOCTL (27)
  110 #define TC_IOCTL_GET_SYSTEM_DRIVE_CONFIG                TC_IOCTL (28)
  111 #define TC_IOCTL_DISK_IS_WRITABLE                       TC_IOCTL (29)
  112 #define TC_IOCTL_START_DECOY_SYSTEM_WIPE                TC_IOCTL (30)
  113 #define TC_IOCTL_ABORT_DECOY_SYSTEM_WIPE                TC_IOCTL (31)
  114 #define TC_IOCTL_GET_DECOY_SYSTEM_WIPE_STATUS           TC_IOCTL (32)
  115 #define TC_IOCTL_GET_DECOY_SYSTEM_WIPE_RESULT           TC_IOCTL (33)
  116 #define TC_IOCTL_WRITE_BOOT_DRIVE_SECTOR                TC_IOCTL (34)
  117 #define TC_IOCTL_GET_WARNING_FLAGS                      TC_IOCTL (35)
  118 #define TC_IOCTL_SET_SYSTEM_FAVORITE_VOLUME_DIRTY       TC_IOCTL (36)
  119 #define TC_IOCTL_REREAD_DRIVER_CONFIG                   TC_IOCTL (37)
  120 #define TC_IOCTL_GET_SYSTEM_DRIVE_DUMP_CONFIG           TC_IOCTL (38)
  121 #define VC_IOCTL_GET_BOOT_LOADER_FINGERPRINT            TC_IOCTL (39)
  122 // result IOCTL_DISK_GET_DRIVE_GEOMETRY_EX
  123 // IN OUT - DISK_GEOMETRY_EX_STRUCT
  124 #define VC_IOCTL_GET_DRIVE_GEOMETRY_EX                  TC_IOCTL (40)
  125 
  126 // Legacy IOCTLs used before version 5.0
  127 #define TC_IOCTL_LEGACY_GET_DRIVER_VERSION      466968
  128 #define TC_IOCTL_LEGACY_GET_MOUNTED_VOLUMES     466948
  129 
  130 // Undocumented IOCTL sent by Windows 10 when handling EFS data on volumes
  131 #define IOCTL_UNKNOWN_WINDOWS10_EFS_ACCESS              0x455610D8
  132 
  133 /* Start of driver interface structures, the size of these structures may
  134    change between versions; so make sure you first send DRIVER_VERSION to
  135    check that it's the correct device driver */
  136 
  137 #pragma pack (push)
  138 #pragma pack(1)
  139 
  140 typedef struct
  141 {
  142     int nReturnCode;                    /* Return code back from driver */
  143     BOOL FilesystemDirty;
  144     BOOL VolumeMountedReadOnlyAfterAccessDenied;
  145     BOOL VolumeMountedReadOnlyAfterDeviceWriteProtected;
  146 
  147     wchar_t wszVolume[TC_MAX_PATH];     /* Volume to be mounted */
  148     Password VolumePassword;            /* User password */
  149     BOOL bCache;                        /* Cache passwords in driver */
  150     int nDosDriveNo;                    /* Drive number to mount */
  151     uint32 BytesPerSector;
  152     BOOL bMountReadOnly;                /* Mount volume in read-only mode */
  153     BOOL bMountRemovable;               /* Mount volume as removable media */
  154     BOOL bExclusiveAccess;              /* Open host file/device in exclusive access mode */
  155     BOOL bMountManager;                 /* Announce volume to mount manager */
  156     BOOL bPreserveTimestamp;            /* Preserve file container timestamp */
  157     BOOL bPartitionInInactiveSysEncScope;       /* If TRUE, we are to attempt to mount a partition located on an encrypted system drive without pre-boot authentication. */
  158     int nPartitionInInactiveSysEncScopeDriveNo; /* If bPartitionInInactiveSysEncScope is TRUE, this contains the drive number of the system drive on which the partition is located. */
  159     BOOL SystemFavorite;
  160     // Hidden volume protection
  161     BOOL bProtectHiddenVolume;          /* TRUE if the user wants the hidden volume within this volume to be protected against being overwritten (damaged) */
  162     Password ProtectedHidVolPassword;   /* Password to the hidden volume to be protected against overwriting */
  163     BOOL UseBackupHeader;
  164     BOOL RecoveryMode;
  165     int pkcs5_prf;
  166     int ProtectedHidVolPkcs5Prf;
  167     BOOL bTrueCryptMode;
  168     uint32 BytesPerPhysicalSector;
  169     int VolumePim;
  170     int ProtectedHidVolPim;
  171     wchar_t wszLabel[33]; // maximum label length is 32 for NTFS and 11 for FAT32
  172     BOOL bIsNTFS; // output only
  173     BOOL bDriverSetLabel;
  174     BOOL bCachePim;
  175     ULONG MaximumTransferLength;
  176     ULONG MaximumPhysicalPages;
  177     ULONG AlignmentMask;
  178 } MOUNT_STRUCT;
  179 
  180 typedef struct
  181 {
  182     int nDosDriveNo;    /* Drive letter to unmount */
  183     BOOL ignoreOpenFiles;
  184     BOOL HiddenVolumeProtectionTriggered;
  185     int nReturnCode;    /* Return code back from driver */
  186 } UNMOUNT_STRUCT;
  187 
  188 typedef struct
  189 {
  190     unsigned __int32 ulMountedDrives;   /* Bitfield of all mounted drive letters */
  191     wchar_t wszVolume[26][TC_MAX_PATH]; /* Volume names of mounted volumes */
  192     wchar_t wszLabel[26][33];   /* Labels of mounted volumes */
  193     wchar_t volumeID[26][VOLUME_ID_SIZE];   /* IDs of mounted volumes */
  194     unsigned __int64 diskLength[26];
  195     int ea[26];
  196     int volumeType[26]; /* Volume type (e.g. PROP_VOL_TYPE_OUTER, PROP_VOL_TYPE_OUTER_VOL_WRITE_PREVENTED, etc.) */
  197     BOOL truecryptMode[26];
  198 } MOUNT_LIST_STRUCT;
  199 
  200 typedef struct
  201 {
  202     int driveNo;
  203     int uniqueId;
  204     wchar_t wszVolume[TC_MAX_PATH];
  205     unsigned __int64 diskLength;
  206     int ea;
  207     int mode;
  208     int pkcs5;
  209     int pkcs5Iterations;
  210     BOOL hiddenVolume;
  211     BOOL readOnly;
  212     BOOL removable;
  213     BOOL partitionInInactiveSysEncScope;
  214     uint32 volumeHeaderFlags;
  215     unsigned __int64 totalBytesRead;
  216     unsigned __int64 totalBytesWritten;
  217     int hiddenVolProtection;    /* Hidden volume protection status (e.g. HIDVOL_PROT_STATUS_NONE, HIDVOL_PROT_STATUS_ACTIVE, etc.) */
  218     int volFormatVersion;
  219     int volumePim;
  220     wchar_t wszLabel[33];
  221     BOOL bDriverSetLabel;
  222     unsigned char volumeID[VOLUME_ID_SIZE];
  223 } VOLUME_PROPERTIES_STRUCT;
  224 
  225 typedef struct
  226 {
  227     WCHAR symLinkName[TC_MAX_PATH];
  228     WCHAR targetName[TC_MAX_PATH];
  229 } RESOLVE_SYMLINK_STRUCT;
  230 
  231 typedef struct
  232 {
  233     WCHAR deviceName[TC_MAX_PATH];
  234     PARTITION_INFORMATION partInfo;
  235     BOOL IsGPT;
  236     BOOL IsDynamic;
  237 }
  238 DISK_PARTITION_INFO_STRUCT;
  239 
  240 typedef struct
  241 {
  242     WCHAR deviceName[TC_MAX_PATH];
  243     DISK_GEOMETRY diskGeometry;
  244 }
  245 DISK_GEOMETRY_STRUCT;
  246 
  247 typedef struct
  248 {
  249     WCHAR deviceName[TC_MAX_PATH];
  250     DISK_GEOMETRY diskGeometry;
  251     LARGE_INTEGER DiskSize;
  252 }
  253 DISK_GEOMETRY_EX_STRUCT;
  254 
  255 typedef struct
  256 {
  257     WCHAR DeviceName[TC_MAX_PATH];
  258     LARGE_INTEGER RealDriveSize;
  259     BOOL TimeOut;
  260 } ProbeRealDriveSizeRequest;
  261 
  262 typedef struct
  263 {
  264     wchar_t wszFileName[TC_MAX_PATH];       // Volume to be "open tested"
  265     BOOL bDetectTCBootLoader;           // Whether the driver is to determine if the first sector contains a portion of the TrueCrypt Boot Loader
  266     BOOL TCBootLoaderDetected;
  267     BOOL DetectFilesystem;
  268     BOOL FilesystemDetected;
  269     BOOL bComputeVolumeIDs;
  270     unsigned char volumeIDs[TC_VOLUME_TYPE_COUNT][VOLUME_ID_SIZE];
  271     BOOL VolumeIDComputed[TC_VOLUME_TYPE_COUNT];
  272 } OPEN_TEST_STRUCT;
  273 
  274 
  275 typedef enum
  276 {
  277     SetupNone = 0,
  278     SetupEncryption,
  279     SetupDecryption
  280 } BootEncryptionSetupMode;
  281 
  282 
  283 typedef struct
  284 {
  285     // New fields must be added at the end of the structure to maintain compatibility with previous versions
  286     BOOL DeviceFilterActive;
  287 
  288     uint16 BootLoaderVersion;
  289 
  290     BOOL DriveMounted;
  291     BOOL VolumeHeaderPresent;
  292     BOOL DriveEncrypted;
  293 
  294     LARGE_INTEGER BootDriveLength;
  295 
  296     int64 ConfiguredEncryptedAreaStart;
  297     int64 ConfiguredEncryptedAreaEnd;
  298     int64 EncryptedAreaStart;
  299     int64 EncryptedAreaEnd;
  300 
  301     uint32 VolumeHeaderSaltCrc32;
  302 
  303     BOOL SetupInProgress;
  304     BootEncryptionSetupMode SetupMode;
  305     BOOL TransformWaitingForIdle;
  306 
  307     uint32 HibernationPreventionCount;
  308 
  309     BOOL HiddenSystem;
  310     int64 HiddenSystemPartitionStart;
  311 
  312     // Number of times the filter driver answered that an unencrypted volume
  313     // is read-only (or mounted an outer/normal TrueCrypt volume as read only)
  314     uint32 HiddenSysLeakProtectionCount;
  315 
  316 } BootEncryptionStatus;
  317 
  318 
  319 typedef struct
  320 {
  321     BootEncryptionSetupMode SetupMode;
  322     WipeAlgorithmId WipeAlgorithm;
  323     BOOL ZeroUnreadableSectors;
  324     BOOL DiscardUnreadableEncryptedSectors;
  325 } BootEncryptionSetupRequest;
  326 
  327 
  328 typedef struct
  329 {
  330     Password VolumePassword;
  331     int pkcs5_prf;
  332     int pim;
  333 } ReopenBootVolumeHeaderRequest;
  334 
  335 
  336 typedef struct
  337 {
  338     char BootEncryptionAlgorithmName[256];
  339     char BootPrfAlgorithmName[256];
  340 } GetBootEncryptionAlgorithmNameRequest;
  341 
  342 typedef struct
  343 {
  344     byte Fingerprint[WHIRLPOOL_DIGESTSIZE + SHA512_DIGESTSIZE];
  345 } BootLoaderFingerprintRequest;
  346 
  347 typedef struct
  348 {
  349     wchar_t DevicePath[TC_MAX_PATH];
  350     byte Configuration;
  351     BOOL DriveIsDynamic;
  352     uint16 BootLoaderVersion;
  353     byte UserConfiguration;
  354     char CustomUserMessage[TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH + 1];
  355 } GetSystemDriveConfigurationRequest;
  356 
  357 typedef struct
  358 {
  359     WipeAlgorithmId WipeAlgorithm;
  360     CRYPTOPP_ALIGN_DATA(16) byte WipeKey[MASTER_KEYDATA_SIZE];
  361 } WipeDecoySystemRequest;
  362 
  363 typedef struct
  364 {
  365     BOOL WipeInProgress;
  366     WipeAlgorithmId WipeAlgorithm;
  367     int64 WipedAreaEnd;
  368 } DecoySystemWipeStatus;
  369 
  370 typedef struct
  371 {
  372     LARGE_INTEGER Offset;
  373     byte Data[TC_SECTOR_SIZE_BIOS];
  374 } WriteBootDriveSectorRequest;
  375 
  376 typedef struct
  377 {
  378     BOOL PagingFileCreationPrevented;
  379     BOOL SystemFavoriteVolumeDirty;
  380 } GetWarningFlagsRequest;
  381 
  382 typedef struct
  383 {
  384     struct _DriveFilterExtension *BootDriveFilterExtension;
  385     BOOL HwEncryptionEnabled;
  386 } GetSystemDriveDumpConfigRequest;
  387 
  388 #pragma pack (pop)
  389 
  390 #define DRIVER_STR WIDE
  391 
  392 #define TC_UNIQUE_ID_PREFIX "VeraCryptVolume"
  393 #define TC_MOUNT_PREFIX L"\\Device\\VeraCryptVolume"
  394 
  395 #define NT_MOUNT_PREFIX DRIVER_STR("\\Device\\VeraCryptVolume")
  396 #define NT_ROOT_PREFIX DRIVER_STR("\\Device\\VeraCrypt")
  397 #define DOS_MOUNT_PREFIX_DEFAULT DRIVER_STR("\\DosDevices\\")
  398 #define DOS_MOUNT_PREFIX_GLOBAL DRIVER_STR("\\GLOBAL??\\") // Use Global MS-DOS device names for sanity checks on drive letters
  399 #define DOS_ROOT_PREFIX DRIVER_STR("\\DosDevices\\VeraCrypt")
  400 #define WIN32_ROOT_PREFIX DRIVER_STR("\\\\.\\VeraCrypt")
  401 
  402 #define TC_DRIVER_CONFIG_REG_VALUE_NAME DRIVER_STR("VeraCryptConfig")
  403 #define TC_ENCRYPTION_FREE_CPU_COUNT_REG_VALUE_NAME DRIVER_STR("VeraCryptEncryptionFreeCpuCount")
  404 
  405 // WARNING: Modifying the following values can introduce incompatibility with previous versions.
  406 #define TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD                        0x1
  407 #define TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD_FOR_SYS_FAVORITES      0x2
  408 #define TC_DRIVER_CONFIG_DISABLE_NONADMIN_SYS_FAVORITES_ACCESS      0x4
  409 #define TC_DRIVER_CONFIG_DISABLE_HARDWARE_ENCRYPTION                0x8
  410 #define TC_DRIVER_CONFIG_ENABLE_EXTENDED_IOCTL                      0x10
  411 #define TC_DRIVER_CONFIG_DISABLE_EVIL_MAID_ATTACK_DETECTION         0x20
  412 #define TC_DRIVER_CONFIG_CACHE_BOOT_PIM                             0x40
  413 #define VC_DRIVER_CONFIG_ALLOW_NONSYS_TRIM                          0x80
  414 #define VC_DRIVER_CONFIG_BLOCK_SYS_TRIM                             0x100
  415 #define VC_DRIVER_CONFIG_ALLOW_WINDOWS_DEFRAG                       0x200
  416 
  417 #endif      /* _WIN32 */