mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 19:08:26 -06:00
Normalize all line terminators
This commit is contained in:
@@ -1,344 +1,344 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Boot/Windows/BootDefs.h"
|
||||
#include "Common.h"
|
||||
#include "Crypto.h"
|
||||
#include "Volumes.h"
|
||||
#include "Wipe.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
/* WARNING: Modifying the following values or their meanings can introduce incompatibility with previous versions. */
|
||||
|
||||
#define TC_IOCTL(CODE) (CTL_CODE (FILE_DEVICE_UNKNOWN, 0x800 + (CODE), METHOD_BUFFERED, FILE_ANY_ACCESS))
|
||||
|
||||
#define TC_IOCTL_GET_DRIVER_VERSION TC_IOCTL (1)
|
||||
#define TC_IOCTL_GET_BOOT_LOADER_VERSION TC_IOCTL (2)
|
||||
#define TC_IOCTL_MOUNT_VOLUME TC_IOCTL (3)
|
||||
#define TC_IOCTL_DISMOUNT_VOLUME TC_IOCTL (4)
|
||||
#define TC_IOCTL_DISMOUNT_ALL_VOLUMES TC_IOCTL (5)
|
||||
#define TC_IOCTL_GET_MOUNTED_VOLUMES TC_IOCTL (6)
|
||||
#define TC_IOCTL_GET_VOLUME_PROPERTIES TC_IOCTL (7)
|
||||
#define TC_IOCTL_GET_DEVICE_REFCOUNT TC_IOCTL (8)
|
||||
#define TC_IOCTL_IS_DRIVER_UNLOAD_DISABLED TC_IOCTL (9)
|
||||
#define TC_IOCTL_IS_ANY_VOLUME_MOUNTED TC_IOCTL (10)
|
||||
#define TC_IOCTL_GET_PASSWORD_CACHE_STATUS TC_IOCTL (11)
|
||||
#define TC_IOCTL_WIPE_PASSWORD_CACHE TC_IOCTL (12)
|
||||
#define TC_IOCTL_OPEN_TEST TC_IOCTL (13)
|
||||
#define TC_IOCTL_GET_DRIVE_PARTITION_INFO TC_IOCTL (14)
|
||||
#define TC_IOCTL_GET_DRIVE_GEOMETRY TC_IOCTL (15)
|
||||
#define TC_IOCTL_PROBE_REAL_DRIVE_SIZE TC_IOCTL (16)
|
||||
#define TC_IOCTL_GET_RESOLVED_SYMLINK TC_IOCTL (17)
|
||||
#define TC_IOCTL_GET_BOOT_ENCRYPTION_STATUS TC_IOCTL (18)
|
||||
#define TC_IOCTL_BOOT_ENCRYPTION_SETUP TC_IOCTL (19)
|
||||
#define TC_IOCTL_ABORT_BOOT_ENCRYPTION_SETUP TC_IOCTL (20)
|
||||
#define TC_IOCTL_GET_BOOT_ENCRYPTION_SETUP_RESULT TC_IOCTL (21)
|
||||
#define TC_IOCTL_GET_BOOT_DRIVE_VOLUME_PROPERTIES TC_IOCTL (22)
|
||||
#define TC_IOCTL_REOPEN_BOOT_VOLUME_HEADER TC_IOCTL (23)
|
||||
#define TC_IOCTL_GET_BOOT_ENCRYPTION_ALGORITHM_NAME TC_IOCTL (24)
|
||||
#define TC_IOCTL_GET_PORTABLE_MODE_STATUS TC_IOCTL (25)
|
||||
#define TC_IOCTL_SET_PORTABLE_MODE_STATUS TC_IOCTL (26)
|
||||
#define TC_IOCTL_IS_HIDDEN_SYSTEM_RUNNING TC_IOCTL (27)
|
||||
#define TC_IOCTL_GET_SYSTEM_DRIVE_CONFIG TC_IOCTL (28)
|
||||
#define TC_IOCTL_DISK_IS_WRITABLE TC_IOCTL (29)
|
||||
#define TC_IOCTL_START_DECOY_SYSTEM_WIPE TC_IOCTL (30)
|
||||
#define TC_IOCTL_ABORT_DECOY_SYSTEM_WIPE TC_IOCTL (31)
|
||||
#define TC_IOCTL_GET_DECOY_SYSTEM_WIPE_STATUS TC_IOCTL (32)
|
||||
#define TC_IOCTL_GET_DECOY_SYSTEM_WIPE_RESULT TC_IOCTL (33)
|
||||
#define TC_IOCTL_WRITE_BOOT_DRIVE_SECTOR TC_IOCTL (34)
|
||||
#define TC_IOCTL_GET_WARNING_FLAGS TC_IOCTL (35)
|
||||
#define TC_IOCTL_SET_SYSTEM_FAVORITE_VOLUME_DIRTY TC_IOCTL (36)
|
||||
#define TC_IOCTL_REREAD_DRIVER_CONFIG TC_IOCTL (37)
|
||||
#define TC_IOCTL_GET_SYSTEM_DRIVE_DUMP_CONFIG TC_IOCTL (38)
|
||||
#define VC_IOCTL_GET_BOOT_LOADER_FINGERPRINT TC_IOCTL (39)
|
||||
|
||||
// Legacy IOCTLs used before version 5.0
|
||||
#define TC_IOCTL_LEGACY_GET_DRIVER_VERSION 466968
|
||||
#define TC_IOCTL_LEGACY_GET_MOUNTED_VOLUMES 466948
|
||||
|
||||
|
||||
/* Start of driver interface structures, the size of these structures may
|
||||
change between versions; so make sure you first send DRIVER_VERSION to
|
||||
check that it's the correct device driver */
|
||||
|
||||
#pragma pack (push)
|
||||
#pragma pack(1)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int nReturnCode; /* Return code back from driver */
|
||||
BOOL FilesystemDirty;
|
||||
BOOL VolumeMountedReadOnlyAfterAccessDenied;
|
||||
BOOL VolumeMountedReadOnlyAfterDeviceWriteProtected;
|
||||
|
||||
wchar_t wszVolume[TC_MAX_PATH]; /* Volume to be mounted */
|
||||
Password VolumePassword; /* User password */
|
||||
BOOL bCache; /* Cache passwords in driver */
|
||||
int nDosDriveNo; /* Drive number to mount */
|
||||
uint32 BytesPerSector;
|
||||
BOOL bMountReadOnly; /* Mount volume in read-only mode */
|
||||
BOOL bMountRemovable; /* Mount volume as removable media */
|
||||
BOOL bExclusiveAccess; /* Open host file/device in exclusive access mode */
|
||||
BOOL bMountManager; /* Announce volume to mount manager */
|
||||
BOOL bPreserveTimestamp; /* Preserve file container timestamp */
|
||||
BOOL bPartitionInInactiveSysEncScope; /* If TRUE, we are to attempt to mount a partition located on an encrypted system drive without pre-boot authentication. */
|
||||
int nPartitionInInactiveSysEncScopeDriveNo; /* If bPartitionInInactiveSysEncScope is TRUE, this contains the drive number of the system drive on which the partition is located. */
|
||||
BOOL SystemFavorite;
|
||||
// Hidden volume protection
|
||||
BOOL bProtectHiddenVolume; /* TRUE if the user wants the hidden volume within this volume to be protected against being overwritten (damaged) */
|
||||
Password ProtectedHidVolPassword; /* Password to the hidden volume to be protected against overwriting */
|
||||
BOOL UseBackupHeader;
|
||||
BOOL RecoveryMode;
|
||||
int pkcs5_prf;
|
||||
int ProtectedHidVolPkcs5Prf;
|
||||
BOOL bTrueCryptMode;
|
||||
uint32 BytesPerPhysicalSector;
|
||||
int VolumePim;
|
||||
int ProtectedHidVolPim;
|
||||
wchar_t wszLabel[33]; // maximum label length is 32 for NTFS and 11 for FAT32
|
||||
BOOL bIsNTFS; // output only
|
||||
BOOL bDriverSetLabel;
|
||||
BOOL bCachePim;
|
||||
} MOUNT_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int nDosDriveNo; /* Drive letter to unmount */
|
||||
BOOL ignoreOpenFiles;
|
||||
BOOL HiddenVolumeProtectionTriggered;
|
||||
int nReturnCode; /* Return code back from driver */
|
||||
} UNMOUNT_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned __int32 ulMountedDrives; /* Bitfield of all mounted drive letters */
|
||||
wchar_t wszVolume[26][TC_MAX_PATH]; /* Volume names of mounted volumes */
|
||||
wchar_t wszLabel[26][33]; /* Labels of mounted volumes */
|
||||
wchar_t volumeID[26][VOLUME_ID_SIZE]; /* IDs of mounted volumes */
|
||||
unsigned __int64 diskLength[26];
|
||||
int ea[26];
|
||||
int volumeType[26]; /* Volume type (e.g. PROP_VOL_TYPE_OUTER, PROP_VOL_TYPE_OUTER_VOL_WRITE_PREVENTED, etc.) */
|
||||
BOOL truecryptMode[26];
|
||||
} MOUNT_LIST_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int driveNo;
|
||||
int uniqueId;
|
||||
wchar_t wszVolume[TC_MAX_PATH];
|
||||
unsigned __int64 diskLength;
|
||||
int ea;
|
||||
int mode;
|
||||
int pkcs5;
|
||||
int pkcs5Iterations;
|
||||
BOOL hiddenVolume;
|
||||
BOOL readOnly;
|
||||
BOOL removable;
|
||||
BOOL partitionInInactiveSysEncScope;
|
||||
uint32 volumeHeaderFlags;
|
||||
unsigned __int64 totalBytesRead;
|
||||
unsigned __int64 totalBytesWritten;
|
||||
int hiddenVolProtection; /* Hidden volume protection status (e.g. HIDVOL_PROT_STATUS_NONE, HIDVOL_PROT_STATUS_ACTIVE, etc.) */
|
||||
int volFormatVersion;
|
||||
int volumePim;
|
||||
wchar_t wszLabel[33];
|
||||
BOOL bDriverSetLabel;
|
||||
unsigned char volumeID[VOLUME_ID_SIZE];
|
||||
} VOLUME_PROPERTIES_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
WCHAR symLinkName[TC_MAX_PATH];
|
||||
WCHAR targetName[TC_MAX_PATH];
|
||||
} RESOLVE_SYMLINK_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
WCHAR deviceName[TC_MAX_PATH];
|
||||
PARTITION_INFORMATION partInfo;
|
||||
BOOL IsGPT;
|
||||
BOOL IsDynamic;
|
||||
}
|
||||
DISK_PARTITION_INFO_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
WCHAR deviceName[TC_MAX_PATH];
|
||||
DISK_GEOMETRY diskGeometry;
|
||||
}
|
||||
DISK_GEOMETRY_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
WCHAR DeviceName[TC_MAX_PATH];
|
||||
LARGE_INTEGER RealDriveSize;
|
||||
BOOL TimeOut;
|
||||
} ProbeRealDriveSizeRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
wchar_t wszFileName[TC_MAX_PATH]; // Volume to be "open tested"
|
||||
BOOL bDetectTCBootLoader; // Whether the driver is to determine if the first sector contains a portion of the TrueCrypt Boot Loader
|
||||
BOOL TCBootLoaderDetected;
|
||||
BOOL DetectFilesystem;
|
||||
BOOL FilesystemDetected;
|
||||
BOOL bMatchVolumeID;
|
||||
unsigned char volumeID[VOLUME_ID_SIZE];
|
||||
BOOL VolumeIDMatched;
|
||||
} OPEN_TEST_STRUCT;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SetupNone = 0,
|
||||
SetupEncryption,
|
||||
SetupDecryption
|
||||
} BootEncryptionSetupMode;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// New fields must be added at the end of the structure to maintain compatibility with previous versions
|
||||
BOOL DeviceFilterActive;
|
||||
|
||||
uint16 BootLoaderVersion;
|
||||
|
||||
BOOL DriveMounted;
|
||||
BOOL VolumeHeaderPresent;
|
||||
BOOL DriveEncrypted;
|
||||
|
||||
LARGE_INTEGER BootDriveLength;
|
||||
|
||||
int64 ConfiguredEncryptedAreaStart;
|
||||
int64 ConfiguredEncryptedAreaEnd;
|
||||
int64 EncryptedAreaStart;
|
||||
int64 EncryptedAreaEnd;
|
||||
|
||||
uint32 VolumeHeaderSaltCrc32;
|
||||
|
||||
BOOL SetupInProgress;
|
||||
BootEncryptionSetupMode SetupMode;
|
||||
BOOL TransformWaitingForIdle;
|
||||
|
||||
uint32 HibernationPreventionCount;
|
||||
|
||||
BOOL HiddenSystem;
|
||||
int64 HiddenSystemPartitionStart;
|
||||
|
||||
// Number of times the filter driver answered that an unencrypted volume
|
||||
// is read-only (or mounted an outer/normal TrueCrypt volume as read only)
|
||||
uint32 HiddenSysLeakProtectionCount;
|
||||
|
||||
} BootEncryptionStatus;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BootEncryptionSetupMode SetupMode;
|
||||
WipeAlgorithmId WipeAlgorithm;
|
||||
BOOL ZeroUnreadableSectors;
|
||||
BOOL DiscardUnreadableEncryptedSectors;
|
||||
} BootEncryptionSetupRequest;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Password VolumePassword;
|
||||
int pkcs5_prf;
|
||||
int pim;
|
||||
} ReopenBootVolumeHeaderRequest;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char BootEncryptionAlgorithmName[256];
|
||||
char BootPrfAlgorithmName[256];
|
||||
} GetBootEncryptionAlgorithmNameRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
byte Fingerprint[WHIRLPOOL_DIGESTSIZE + SHA512_DIGESTSIZE];
|
||||
} BootLoaderFingerprintRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
wchar_t DevicePath[TC_MAX_PATH];
|
||||
byte Configuration;
|
||||
BOOL DriveIsDynamic;
|
||||
uint16 BootLoaderVersion;
|
||||
byte UserConfiguration;
|
||||
char CustomUserMessage[TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH + 1];
|
||||
} GetSystemDriveConfigurationRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
WipeAlgorithmId WipeAlgorithm;
|
||||
byte WipeKey[MASTER_KEYDATA_SIZE];
|
||||
} WipeDecoySystemRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BOOL WipeInProgress;
|
||||
WipeAlgorithmId WipeAlgorithm;
|
||||
int64 WipedAreaEnd;
|
||||
} DecoySystemWipeStatus;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
LARGE_INTEGER Offset;
|
||||
byte Data[TC_SECTOR_SIZE_BIOS];
|
||||
} WriteBootDriveSectorRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BOOL PagingFileCreationPrevented;
|
||||
BOOL SystemFavoriteVolumeDirty;
|
||||
} GetWarningFlagsRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struct _DriveFilterExtension *BootDriveFilterExtension;
|
||||
BOOL HwEncryptionEnabled;
|
||||
} GetSystemDriveDumpConfigRequest;
|
||||
|
||||
#pragma pack (pop)
|
||||
|
||||
#define DRIVER_STR WIDE
|
||||
|
||||
#define TC_UNIQUE_ID_PREFIX "VeraCryptVolume"
|
||||
#define TC_MOUNT_PREFIX L"\\Device\\VeraCryptVolume"
|
||||
|
||||
#define NT_MOUNT_PREFIX DRIVER_STR("\\Device\\VeraCryptVolume")
|
||||
#define NT_ROOT_PREFIX DRIVER_STR("\\Device\\VeraCrypt")
|
||||
#define DOS_MOUNT_PREFIX_DEFAULT DRIVER_STR("\\DosDevices\\")
|
||||
#define DOS_MOUNT_PREFIX_GLOBAL DRIVER_STR("\\GLOBAL??\\") // Use Global MS-DOS device names for sanity checks on drive letters
|
||||
#define DOS_ROOT_PREFIX DRIVER_STR("\\DosDevices\\VeraCrypt")
|
||||
#define WIN32_ROOT_PREFIX DRIVER_STR("\\\\.\\VeraCrypt")
|
||||
|
||||
#define TC_DRIVER_CONFIG_REG_VALUE_NAME DRIVER_STR("VeraCryptConfig")
|
||||
#define TC_ENCRYPTION_FREE_CPU_COUNT_REG_VALUE_NAME DRIVER_STR("VeraCryptEncryptionFreeCpuCount")
|
||||
|
||||
// WARNING: Modifying the following values can introduce incompatibility with previous versions.
|
||||
#define TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD 0x1
|
||||
#define TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD_FOR_SYS_FAVORITES 0x2
|
||||
#define TC_DRIVER_CONFIG_DISABLE_NONADMIN_SYS_FAVORITES_ACCESS 0x4
|
||||
#define TC_DRIVER_CONFIG_DISABLE_HARDWARE_ENCRYPTION 0x8
|
||||
#define TC_DRIVER_CONFIG_ENABLE_EXTENDED_IOCTL 0x10
|
||||
#define TC_DRIVER_CONFIG_DISABLE_EVIL_MAID_ATTACK_DETECTION 0x20
|
||||
#define TC_DRIVER_CONFIG_CACHE_BOOT_PIM 0x40
|
||||
|
||||
#endif /* _WIN32 */
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Boot/Windows/BootDefs.h"
|
||||
#include "Common.h"
|
||||
#include "Crypto.h"
|
||||
#include "Volumes.h"
|
||||
#include "Wipe.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
/* WARNING: Modifying the following values or their meanings can introduce incompatibility with previous versions. */
|
||||
|
||||
#define TC_IOCTL(CODE) (CTL_CODE (FILE_DEVICE_UNKNOWN, 0x800 + (CODE), METHOD_BUFFERED, FILE_ANY_ACCESS))
|
||||
|
||||
#define TC_IOCTL_GET_DRIVER_VERSION TC_IOCTL (1)
|
||||
#define TC_IOCTL_GET_BOOT_LOADER_VERSION TC_IOCTL (2)
|
||||
#define TC_IOCTL_MOUNT_VOLUME TC_IOCTL (3)
|
||||
#define TC_IOCTL_DISMOUNT_VOLUME TC_IOCTL (4)
|
||||
#define TC_IOCTL_DISMOUNT_ALL_VOLUMES TC_IOCTL (5)
|
||||
#define TC_IOCTL_GET_MOUNTED_VOLUMES TC_IOCTL (6)
|
||||
#define TC_IOCTL_GET_VOLUME_PROPERTIES TC_IOCTL (7)
|
||||
#define TC_IOCTL_GET_DEVICE_REFCOUNT TC_IOCTL (8)
|
||||
#define TC_IOCTL_IS_DRIVER_UNLOAD_DISABLED TC_IOCTL (9)
|
||||
#define TC_IOCTL_IS_ANY_VOLUME_MOUNTED TC_IOCTL (10)
|
||||
#define TC_IOCTL_GET_PASSWORD_CACHE_STATUS TC_IOCTL (11)
|
||||
#define TC_IOCTL_WIPE_PASSWORD_CACHE TC_IOCTL (12)
|
||||
#define TC_IOCTL_OPEN_TEST TC_IOCTL (13)
|
||||
#define TC_IOCTL_GET_DRIVE_PARTITION_INFO TC_IOCTL (14)
|
||||
#define TC_IOCTL_GET_DRIVE_GEOMETRY TC_IOCTL (15)
|
||||
#define TC_IOCTL_PROBE_REAL_DRIVE_SIZE TC_IOCTL (16)
|
||||
#define TC_IOCTL_GET_RESOLVED_SYMLINK TC_IOCTL (17)
|
||||
#define TC_IOCTL_GET_BOOT_ENCRYPTION_STATUS TC_IOCTL (18)
|
||||
#define TC_IOCTL_BOOT_ENCRYPTION_SETUP TC_IOCTL (19)
|
||||
#define TC_IOCTL_ABORT_BOOT_ENCRYPTION_SETUP TC_IOCTL (20)
|
||||
#define TC_IOCTL_GET_BOOT_ENCRYPTION_SETUP_RESULT TC_IOCTL (21)
|
||||
#define TC_IOCTL_GET_BOOT_DRIVE_VOLUME_PROPERTIES TC_IOCTL (22)
|
||||
#define TC_IOCTL_REOPEN_BOOT_VOLUME_HEADER TC_IOCTL (23)
|
||||
#define TC_IOCTL_GET_BOOT_ENCRYPTION_ALGORITHM_NAME TC_IOCTL (24)
|
||||
#define TC_IOCTL_GET_PORTABLE_MODE_STATUS TC_IOCTL (25)
|
||||
#define TC_IOCTL_SET_PORTABLE_MODE_STATUS TC_IOCTL (26)
|
||||
#define TC_IOCTL_IS_HIDDEN_SYSTEM_RUNNING TC_IOCTL (27)
|
||||
#define TC_IOCTL_GET_SYSTEM_DRIVE_CONFIG TC_IOCTL (28)
|
||||
#define TC_IOCTL_DISK_IS_WRITABLE TC_IOCTL (29)
|
||||
#define TC_IOCTL_START_DECOY_SYSTEM_WIPE TC_IOCTL (30)
|
||||
#define TC_IOCTL_ABORT_DECOY_SYSTEM_WIPE TC_IOCTL (31)
|
||||
#define TC_IOCTL_GET_DECOY_SYSTEM_WIPE_STATUS TC_IOCTL (32)
|
||||
#define TC_IOCTL_GET_DECOY_SYSTEM_WIPE_RESULT TC_IOCTL (33)
|
||||
#define TC_IOCTL_WRITE_BOOT_DRIVE_SECTOR TC_IOCTL (34)
|
||||
#define TC_IOCTL_GET_WARNING_FLAGS TC_IOCTL (35)
|
||||
#define TC_IOCTL_SET_SYSTEM_FAVORITE_VOLUME_DIRTY TC_IOCTL (36)
|
||||
#define TC_IOCTL_REREAD_DRIVER_CONFIG TC_IOCTL (37)
|
||||
#define TC_IOCTL_GET_SYSTEM_DRIVE_DUMP_CONFIG TC_IOCTL (38)
|
||||
#define VC_IOCTL_GET_BOOT_LOADER_FINGERPRINT TC_IOCTL (39)
|
||||
|
||||
// Legacy IOCTLs used before version 5.0
|
||||
#define TC_IOCTL_LEGACY_GET_DRIVER_VERSION 466968
|
||||
#define TC_IOCTL_LEGACY_GET_MOUNTED_VOLUMES 466948
|
||||
|
||||
|
||||
/* Start of driver interface structures, the size of these structures may
|
||||
change between versions; so make sure you first send DRIVER_VERSION to
|
||||
check that it's the correct device driver */
|
||||
|
||||
#pragma pack (push)
|
||||
#pragma pack(1)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int nReturnCode; /* Return code back from driver */
|
||||
BOOL FilesystemDirty;
|
||||
BOOL VolumeMountedReadOnlyAfterAccessDenied;
|
||||
BOOL VolumeMountedReadOnlyAfterDeviceWriteProtected;
|
||||
|
||||
wchar_t wszVolume[TC_MAX_PATH]; /* Volume to be mounted */
|
||||
Password VolumePassword; /* User password */
|
||||
BOOL bCache; /* Cache passwords in driver */
|
||||
int nDosDriveNo; /* Drive number to mount */
|
||||
uint32 BytesPerSector;
|
||||
BOOL bMountReadOnly; /* Mount volume in read-only mode */
|
||||
BOOL bMountRemovable; /* Mount volume as removable media */
|
||||
BOOL bExclusiveAccess; /* Open host file/device in exclusive access mode */
|
||||
BOOL bMountManager; /* Announce volume to mount manager */
|
||||
BOOL bPreserveTimestamp; /* Preserve file container timestamp */
|
||||
BOOL bPartitionInInactiveSysEncScope; /* If TRUE, we are to attempt to mount a partition located on an encrypted system drive without pre-boot authentication. */
|
||||
int nPartitionInInactiveSysEncScopeDriveNo; /* If bPartitionInInactiveSysEncScope is TRUE, this contains the drive number of the system drive on which the partition is located. */
|
||||
BOOL SystemFavorite;
|
||||
// Hidden volume protection
|
||||
BOOL bProtectHiddenVolume; /* TRUE if the user wants the hidden volume within this volume to be protected against being overwritten (damaged) */
|
||||
Password ProtectedHidVolPassword; /* Password to the hidden volume to be protected against overwriting */
|
||||
BOOL UseBackupHeader;
|
||||
BOOL RecoveryMode;
|
||||
int pkcs5_prf;
|
||||
int ProtectedHidVolPkcs5Prf;
|
||||
BOOL bTrueCryptMode;
|
||||
uint32 BytesPerPhysicalSector;
|
||||
int VolumePim;
|
||||
int ProtectedHidVolPim;
|
||||
wchar_t wszLabel[33]; // maximum label length is 32 for NTFS and 11 for FAT32
|
||||
BOOL bIsNTFS; // output only
|
||||
BOOL bDriverSetLabel;
|
||||
BOOL bCachePim;
|
||||
} MOUNT_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int nDosDriveNo; /* Drive letter to unmount */
|
||||
BOOL ignoreOpenFiles;
|
||||
BOOL HiddenVolumeProtectionTriggered;
|
||||
int nReturnCode; /* Return code back from driver */
|
||||
} UNMOUNT_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned __int32 ulMountedDrives; /* Bitfield of all mounted drive letters */
|
||||
wchar_t wszVolume[26][TC_MAX_PATH]; /* Volume names of mounted volumes */
|
||||
wchar_t wszLabel[26][33]; /* Labels of mounted volumes */
|
||||
wchar_t volumeID[26][VOLUME_ID_SIZE]; /* IDs of mounted volumes */
|
||||
unsigned __int64 diskLength[26];
|
||||
int ea[26];
|
||||
int volumeType[26]; /* Volume type (e.g. PROP_VOL_TYPE_OUTER, PROP_VOL_TYPE_OUTER_VOL_WRITE_PREVENTED, etc.) */
|
||||
BOOL truecryptMode[26];
|
||||
} MOUNT_LIST_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int driveNo;
|
||||
int uniqueId;
|
||||
wchar_t wszVolume[TC_MAX_PATH];
|
||||
unsigned __int64 diskLength;
|
||||
int ea;
|
||||
int mode;
|
||||
int pkcs5;
|
||||
int pkcs5Iterations;
|
||||
BOOL hiddenVolume;
|
||||
BOOL readOnly;
|
||||
BOOL removable;
|
||||
BOOL partitionInInactiveSysEncScope;
|
||||
uint32 volumeHeaderFlags;
|
||||
unsigned __int64 totalBytesRead;
|
||||
unsigned __int64 totalBytesWritten;
|
||||
int hiddenVolProtection; /* Hidden volume protection status (e.g. HIDVOL_PROT_STATUS_NONE, HIDVOL_PROT_STATUS_ACTIVE, etc.) */
|
||||
int volFormatVersion;
|
||||
int volumePim;
|
||||
wchar_t wszLabel[33];
|
||||
BOOL bDriverSetLabel;
|
||||
unsigned char volumeID[VOLUME_ID_SIZE];
|
||||
} VOLUME_PROPERTIES_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
WCHAR symLinkName[TC_MAX_PATH];
|
||||
WCHAR targetName[TC_MAX_PATH];
|
||||
} RESOLVE_SYMLINK_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
WCHAR deviceName[TC_MAX_PATH];
|
||||
PARTITION_INFORMATION partInfo;
|
||||
BOOL IsGPT;
|
||||
BOOL IsDynamic;
|
||||
}
|
||||
DISK_PARTITION_INFO_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
WCHAR deviceName[TC_MAX_PATH];
|
||||
DISK_GEOMETRY diskGeometry;
|
||||
}
|
||||
DISK_GEOMETRY_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
WCHAR DeviceName[TC_MAX_PATH];
|
||||
LARGE_INTEGER RealDriveSize;
|
||||
BOOL TimeOut;
|
||||
} ProbeRealDriveSizeRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
wchar_t wszFileName[TC_MAX_PATH]; // Volume to be "open tested"
|
||||
BOOL bDetectTCBootLoader; // Whether the driver is to determine if the first sector contains a portion of the TrueCrypt Boot Loader
|
||||
BOOL TCBootLoaderDetected;
|
||||
BOOL DetectFilesystem;
|
||||
BOOL FilesystemDetected;
|
||||
BOOL bMatchVolumeID;
|
||||
unsigned char volumeID[VOLUME_ID_SIZE];
|
||||
BOOL VolumeIDMatched;
|
||||
} OPEN_TEST_STRUCT;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SetupNone = 0,
|
||||
SetupEncryption,
|
||||
SetupDecryption
|
||||
} BootEncryptionSetupMode;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// New fields must be added at the end of the structure to maintain compatibility with previous versions
|
||||
BOOL DeviceFilterActive;
|
||||
|
||||
uint16 BootLoaderVersion;
|
||||
|
||||
BOOL DriveMounted;
|
||||
BOOL VolumeHeaderPresent;
|
||||
BOOL DriveEncrypted;
|
||||
|
||||
LARGE_INTEGER BootDriveLength;
|
||||
|
||||
int64 ConfiguredEncryptedAreaStart;
|
||||
int64 ConfiguredEncryptedAreaEnd;
|
||||
int64 EncryptedAreaStart;
|
||||
int64 EncryptedAreaEnd;
|
||||
|
||||
uint32 VolumeHeaderSaltCrc32;
|
||||
|
||||
BOOL SetupInProgress;
|
||||
BootEncryptionSetupMode SetupMode;
|
||||
BOOL TransformWaitingForIdle;
|
||||
|
||||
uint32 HibernationPreventionCount;
|
||||
|
||||
BOOL HiddenSystem;
|
||||
int64 HiddenSystemPartitionStart;
|
||||
|
||||
// Number of times the filter driver answered that an unencrypted volume
|
||||
// is read-only (or mounted an outer/normal TrueCrypt volume as read only)
|
||||
uint32 HiddenSysLeakProtectionCount;
|
||||
|
||||
} BootEncryptionStatus;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BootEncryptionSetupMode SetupMode;
|
||||
WipeAlgorithmId WipeAlgorithm;
|
||||
BOOL ZeroUnreadableSectors;
|
||||
BOOL DiscardUnreadableEncryptedSectors;
|
||||
} BootEncryptionSetupRequest;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Password VolumePassword;
|
||||
int pkcs5_prf;
|
||||
int pim;
|
||||
} ReopenBootVolumeHeaderRequest;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char BootEncryptionAlgorithmName[256];
|
||||
char BootPrfAlgorithmName[256];
|
||||
} GetBootEncryptionAlgorithmNameRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
byte Fingerprint[WHIRLPOOL_DIGESTSIZE + SHA512_DIGESTSIZE];
|
||||
} BootLoaderFingerprintRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
wchar_t DevicePath[TC_MAX_PATH];
|
||||
byte Configuration;
|
||||
BOOL DriveIsDynamic;
|
||||
uint16 BootLoaderVersion;
|
||||
byte UserConfiguration;
|
||||
char CustomUserMessage[TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH + 1];
|
||||
} GetSystemDriveConfigurationRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
WipeAlgorithmId WipeAlgorithm;
|
||||
byte WipeKey[MASTER_KEYDATA_SIZE];
|
||||
} WipeDecoySystemRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BOOL WipeInProgress;
|
||||
WipeAlgorithmId WipeAlgorithm;
|
||||
int64 WipedAreaEnd;
|
||||
} DecoySystemWipeStatus;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
LARGE_INTEGER Offset;
|
||||
byte Data[TC_SECTOR_SIZE_BIOS];
|
||||
} WriteBootDriveSectorRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BOOL PagingFileCreationPrevented;
|
||||
BOOL SystemFavoriteVolumeDirty;
|
||||
} GetWarningFlagsRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struct _DriveFilterExtension *BootDriveFilterExtension;
|
||||
BOOL HwEncryptionEnabled;
|
||||
} GetSystemDriveDumpConfigRequest;
|
||||
|
||||
#pragma pack (pop)
|
||||
|
||||
#define DRIVER_STR WIDE
|
||||
|
||||
#define TC_UNIQUE_ID_PREFIX "VeraCryptVolume"
|
||||
#define TC_MOUNT_PREFIX L"\\Device\\VeraCryptVolume"
|
||||
|
||||
#define NT_MOUNT_PREFIX DRIVER_STR("\\Device\\VeraCryptVolume")
|
||||
#define NT_ROOT_PREFIX DRIVER_STR("\\Device\\VeraCrypt")
|
||||
#define DOS_MOUNT_PREFIX_DEFAULT DRIVER_STR("\\DosDevices\\")
|
||||
#define DOS_MOUNT_PREFIX_GLOBAL DRIVER_STR("\\GLOBAL??\\") // Use Global MS-DOS device names for sanity checks on drive letters
|
||||
#define DOS_ROOT_PREFIX DRIVER_STR("\\DosDevices\\VeraCrypt")
|
||||
#define WIN32_ROOT_PREFIX DRIVER_STR("\\\\.\\VeraCrypt")
|
||||
|
||||
#define TC_DRIVER_CONFIG_REG_VALUE_NAME DRIVER_STR("VeraCryptConfig")
|
||||
#define TC_ENCRYPTION_FREE_CPU_COUNT_REG_VALUE_NAME DRIVER_STR("VeraCryptEncryptionFreeCpuCount")
|
||||
|
||||
// WARNING: Modifying the following values can introduce incompatibility with previous versions.
|
||||
#define TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD 0x1
|
||||
#define TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD_FOR_SYS_FAVORITES 0x2
|
||||
#define TC_DRIVER_CONFIG_DISABLE_NONADMIN_SYS_FAVORITES_ACCESS 0x4
|
||||
#define TC_DRIVER_CONFIG_DISABLE_HARDWARE_ENCRYPTION 0x8
|
||||
#define TC_DRIVER_CONFIG_ENABLE_EXTENDED_IOCTL 0x10
|
||||
#define TC_DRIVER_CONFIG_DISABLE_EVIL_MAID_ATTACK_DETECTION 0x20
|
||||
#define TC_DRIVER_CONFIG_CACHE_BOOT_PIM 0x40
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
@@ -1,246 +1,246 @@
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#include <atlcomcli.h>
|
||||
#include <atlconv.h>
|
||||
#include <comutil.h>
|
||||
#include <windows.h>
|
||||
#include "BaseCom.h"
|
||||
#include "BootEncryption.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Registry.h"
|
||||
|
||||
using namespace VeraCrypt;
|
||||
|
||||
HRESULT CreateElevatedComObject (HWND hwnd, REFGUID guid, REFIID iid, void **ppv)
|
||||
{
|
||||
WCHAR monikerName[1024];
|
||||
WCHAR clsid[1024];
|
||||
BIND_OPTS3 bo;
|
||||
|
||||
StringFromGUID2 (guid, clsid, sizeof (clsid) / 2);
|
||||
swprintf_s (monikerName, sizeof (monikerName) / 2, L"Elevation:Administrator!new:%s", clsid);
|
||||
|
||||
memset (&bo, 0, sizeof (bo));
|
||||
bo.cbStruct = sizeof (bo);
|
||||
bo.hwnd = hwnd;
|
||||
bo.dwClassContext = CLSCTX_LOCAL_SERVER;
|
||||
|
||||
// Prevent the GUI from being half-rendered when the UAC prompt "freezes" it
|
||||
ProcessPaintMessages (hwnd, 5000);
|
||||
|
||||
return CoGetObject (monikerName, &bo, iid, ppv);
|
||||
}
|
||||
|
||||
|
||||
BOOL ComGetInstanceBase (HWND hWnd, REFCLSID clsid, REFIID iid, void **tcServer)
|
||||
{
|
||||
BOOL r;
|
||||
|
||||
if (IsUacSupported ())
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
r = CreateElevatedComObject (hWnd, clsid, iid, tcServer) == S_OK;
|
||||
if (r)
|
||||
break;
|
||||
else
|
||||
{
|
||||
if (IDRETRY == ErrorRetryCancel ("UAC_INIT_ERROR", hWnd))
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
r = CoCreateInstance (clsid, NULL, CLSCTX_LOCAL_SERVER, iid, tcServer) == S_OK;
|
||||
if (!r)
|
||||
Error ("UAC_INIT_ERROR", hWnd);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::CallDriver (DWORD ioctl, BSTR input, BSTR *output)
|
||||
{
|
||||
try
|
||||
{
|
||||
BootEncryption bootEnc (NULL);
|
||||
bootEnc.CallDriver (ioctl,
|
||||
(BYTE *) input, !(BYTE *) input ? 0 : ((DWORD *) ((BYTE *) input))[-1],
|
||||
(BYTE *) *output, !(BYTE *) *output ? 0 : ((DWORD *) ((BYTE *) *output))[-1]);
|
||||
}
|
||||
catch (SystemException &)
|
||||
{
|
||||
return GetLastError();
|
||||
}
|
||||
catch (Exception &e)
|
||||
{
|
||||
e.Show (NULL);
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::CopyFile (BSTR sourceFile, BSTR destinationFile)
|
||||
{
|
||||
|
||||
if (!::CopyFileW (sourceFile, destinationFile, FALSE))
|
||||
return GetLastError();
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::DeleteFile (BSTR file)
|
||||
{
|
||||
|
||||
if (!::DeleteFileW (file))
|
||||
return GetLastError();
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
BOOL BaseCom::IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly)
|
||||
{
|
||||
return ::IsPagingFileActive (checkNonWindowsPartitionsOnly);
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *bufferBstr, unsigned __int64 offset, unsigned __int32 size, DWORD *sizeDone)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto_ptr <File> file (device ? new Device (filePath, !write) : new File (filePath, !write));
|
||||
file->CheckOpened (SRC_POS);
|
||||
file->SeekAt (offset);
|
||||
|
||||
if (write)
|
||||
{
|
||||
file->Write ((BYTE *) *bufferBstr, size);
|
||||
*sizeDone = size;
|
||||
}
|
||||
else
|
||||
{
|
||||
*sizeDone = file->Read ((BYTE *) *bufferBstr, size);
|
||||
}
|
||||
}
|
||||
catch (SystemException &)
|
||||
{
|
||||
return GetLastError();
|
||||
}
|
||||
catch (Exception &e)
|
||||
{
|
||||
e.Show (NULL);
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::RegisterFilterDriver (BOOL registerDriver, int filterType)
|
||||
{
|
||||
try
|
||||
{
|
||||
BootEncryption bootEnc (NULL);
|
||||
bootEnc.RegisterFilterDriver (registerDriver ? true : false, (BootEncryption::FilterType) filterType);
|
||||
}
|
||||
catch (SystemException &)
|
||||
{
|
||||
return GetLastError();
|
||||
}
|
||||
catch (Exception &e)
|
||||
{
|
||||
e.Show (NULL);
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::RegisterSystemFavoritesService (BOOL registerService)
|
||||
{
|
||||
try
|
||||
{
|
||||
BootEncryption bootEnc (NULL);
|
||||
bootEnc.RegisterSystemFavoritesService (registerService);
|
||||
}
|
||||
catch (SystemException &)
|
||||
{
|
||||
return GetLastError();
|
||||
}
|
||||
catch (Exception &e)
|
||||
{
|
||||
e.Show (NULL);
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::SetDriverServiceStartType (DWORD startType)
|
||||
{
|
||||
try
|
||||
{
|
||||
BootEncryption bootEnc (NULL);
|
||||
bootEnc.SetDriverServiceStartType (startType);
|
||||
}
|
||||
catch (SystemException &)
|
||||
{
|
||||
return GetLastError();
|
||||
}
|
||||
catch (Exception &e)
|
||||
{
|
||||
e.Show (NULL);
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::WriteLocalMachineRegistryDwordValue (BSTR keyPath, BSTR valueName, DWORD value)
|
||||
{
|
||||
if (!::WriteLocalMachineRegistryDword (keyPath, valueName, value))
|
||||
return GetLastError();
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#include <atlcomcli.h>
|
||||
#include <atlconv.h>
|
||||
#include <comutil.h>
|
||||
#include <windows.h>
|
||||
#include "BaseCom.h"
|
||||
#include "BootEncryption.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Registry.h"
|
||||
|
||||
using namespace VeraCrypt;
|
||||
|
||||
HRESULT CreateElevatedComObject (HWND hwnd, REFGUID guid, REFIID iid, void **ppv)
|
||||
{
|
||||
WCHAR monikerName[1024];
|
||||
WCHAR clsid[1024];
|
||||
BIND_OPTS3 bo;
|
||||
|
||||
StringFromGUID2 (guid, clsid, sizeof (clsid) / 2);
|
||||
swprintf_s (monikerName, sizeof (monikerName) / 2, L"Elevation:Administrator!new:%s", clsid);
|
||||
|
||||
memset (&bo, 0, sizeof (bo));
|
||||
bo.cbStruct = sizeof (bo);
|
||||
bo.hwnd = hwnd;
|
||||
bo.dwClassContext = CLSCTX_LOCAL_SERVER;
|
||||
|
||||
// Prevent the GUI from being half-rendered when the UAC prompt "freezes" it
|
||||
ProcessPaintMessages (hwnd, 5000);
|
||||
|
||||
return CoGetObject (monikerName, &bo, iid, ppv);
|
||||
}
|
||||
|
||||
|
||||
BOOL ComGetInstanceBase (HWND hWnd, REFCLSID clsid, REFIID iid, void **tcServer)
|
||||
{
|
||||
BOOL r;
|
||||
|
||||
if (IsUacSupported ())
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
r = CreateElevatedComObject (hWnd, clsid, iid, tcServer) == S_OK;
|
||||
if (r)
|
||||
break;
|
||||
else
|
||||
{
|
||||
if (IDRETRY == ErrorRetryCancel ("UAC_INIT_ERROR", hWnd))
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
r = CoCreateInstance (clsid, NULL, CLSCTX_LOCAL_SERVER, iid, tcServer) == S_OK;
|
||||
if (!r)
|
||||
Error ("UAC_INIT_ERROR", hWnd);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::CallDriver (DWORD ioctl, BSTR input, BSTR *output)
|
||||
{
|
||||
try
|
||||
{
|
||||
BootEncryption bootEnc (NULL);
|
||||
bootEnc.CallDriver (ioctl,
|
||||
(BYTE *) input, !(BYTE *) input ? 0 : ((DWORD *) ((BYTE *) input))[-1],
|
||||
(BYTE *) *output, !(BYTE *) *output ? 0 : ((DWORD *) ((BYTE *) *output))[-1]);
|
||||
}
|
||||
catch (SystemException &)
|
||||
{
|
||||
return GetLastError();
|
||||
}
|
||||
catch (Exception &e)
|
||||
{
|
||||
e.Show (NULL);
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::CopyFile (BSTR sourceFile, BSTR destinationFile)
|
||||
{
|
||||
|
||||
if (!::CopyFileW (sourceFile, destinationFile, FALSE))
|
||||
return GetLastError();
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::DeleteFile (BSTR file)
|
||||
{
|
||||
|
||||
if (!::DeleteFileW (file))
|
||||
return GetLastError();
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
BOOL BaseCom::IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly)
|
||||
{
|
||||
return ::IsPagingFileActive (checkNonWindowsPartitionsOnly);
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *bufferBstr, unsigned __int64 offset, unsigned __int32 size, DWORD *sizeDone)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto_ptr <File> file (device ? new Device (filePath, !write) : new File (filePath, !write));
|
||||
file->CheckOpened (SRC_POS);
|
||||
file->SeekAt (offset);
|
||||
|
||||
if (write)
|
||||
{
|
||||
file->Write ((BYTE *) *bufferBstr, size);
|
||||
*sizeDone = size;
|
||||
}
|
||||
else
|
||||
{
|
||||
*sizeDone = file->Read ((BYTE *) *bufferBstr, size);
|
||||
}
|
||||
}
|
||||
catch (SystemException &)
|
||||
{
|
||||
return GetLastError();
|
||||
}
|
||||
catch (Exception &e)
|
||||
{
|
||||
e.Show (NULL);
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::RegisterFilterDriver (BOOL registerDriver, int filterType)
|
||||
{
|
||||
try
|
||||
{
|
||||
BootEncryption bootEnc (NULL);
|
||||
bootEnc.RegisterFilterDriver (registerDriver ? true : false, (BootEncryption::FilterType) filterType);
|
||||
}
|
||||
catch (SystemException &)
|
||||
{
|
||||
return GetLastError();
|
||||
}
|
||||
catch (Exception &e)
|
||||
{
|
||||
e.Show (NULL);
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::RegisterSystemFavoritesService (BOOL registerService)
|
||||
{
|
||||
try
|
||||
{
|
||||
BootEncryption bootEnc (NULL);
|
||||
bootEnc.RegisterSystemFavoritesService (registerService);
|
||||
}
|
||||
catch (SystemException &)
|
||||
{
|
||||
return GetLastError();
|
||||
}
|
||||
catch (Exception &e)
|
||||
{
|
||||
e.Show (NULL);
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::SetDriverServiceStartType (DWORD startType)
|
||||
{
|
||||
try
|
||||
{
|
||||
BootEncryption bootEnc (NULL);
|
||||
bootEnc.SetDriverServiceStartType (startType);
|
||||
}
|
||||
catch (SystemException &)
|
||||
{
|
||||
return GetLastError();
|
||||
}
|
||||
catch (Exception &e)
|
||||
{
|
||||
e.Show (NULL);
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::WriteLocalMachineRegistryDwordValue (BSTR keyPath, BSTR valueName, DWORD value)
|
||||
{
|
||||
if (!::WriteLocalMachineRegistryDword (keyPath, valueName, value))
|
||||
return GetLastError();
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,119 +1,119 @@
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_BASE_COM
|
||||
#define TC_HEADER_BASE_COM
|
||||
|
||||
#include <guiddef.h>
|
||||
|
||||
template <class TClass>
|
||||
class TrueCryptFactory : public IClassFactory
|
||||
{
|
||||
|
||||
public:
|
||||
TrueCryptFactory (DWORD messageThreadId) :
|
||||
RefCount (1), ServerLockCount (0), MessageThreadId (messageThreadId) { }
|
||||
|
||||
~TrueCryptFactory () { }
|
||||
|
||||
virtual ULONG STDMETHODCALLTYPE AddRef ()
|
||||
{
|
||||
return InterlockedIncrement (&RefCount) - 1;
|
||||
}
|
||||
|
||||
virtual ULONG STDMETHODCALLTYPE Release ()
|
||||
{
|
||||
ULONG r = InterlockedDecrement (&RefCount) + 1;
|
||||
|
||||
if (r == 0)
|
||||
delete this;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE QueryInterface (REFIID riid, void **ppvObject)
|
||||
{
|
||||
if (riid == IID_IUnknown || riid == IID_IClassFactory)
|
||||
*ppvObject = this;
|
||||
else
|
||||
{
|
||||
*ppvObject = NULL;
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
AddRef ();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE CreateInstance (IUnknown *pUnkOuter, REFIID riid, void **ppvObject)
|
||||
{
|
||||
if (pUnkOuter != NULL)
|
||||
return CLASS_E_NOAGGREGATION;
|
||||
|
||||
TClass *tc = new TClass (MessageThreadId);
|
||||
if (tc == NULL)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
HRESULT hr = tc->QueryInterface (riid, ppvObject);
|
||||
|
||||
if (hr)
|
||||
delete tc;
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE LockServer (BOOL fLock)
|
||||
{
|
||||
if (fLock)
|
||||
{
|
||||
InterlockedIncrement (&ServerLockCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!InterlockedDecrement (&ServerLockCount))
|
||||
PostThreadMessage (MessageThreadId, WM_APP, 0, 0);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
virtual bool IsServerLocked ()
|
||||
{
|
||||
return ServerLockCount > 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
DWORD MessageThreadId;
|
||||
LONG RefCount;
|
||||
LONG ServerLockCount;
|
||||
};
|
||||
|
||||
|
||||
class BaseCom
|
||||
{
|
||||
public:
|
||||
static DWORD CallDriver (DWORD ioctl, BSTR input, BSTR *output);
|
||||
static DWORD CopyFile (BSTR sourceFile, BSTR destinationFile);
|
||||
static DWORD DeleteFile (BSTR file);
|
||||
static BOOL IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly);
|
||||
static DWORD ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *bufferBstr, unsigned __int64 offset, unsigned __int32 size, DWORD *sizeDone);
|
||||
static DWORD RegisterFilterDriver (BOOL registerDriver, int filterType);
|
||||
static DWORD RegisterSystemFavoritesService (BOOL registerService);
|
||||
static DWORD SetDriverServiceStartType (DWORD startType);
|
||||
static DWORD WriteLocalMachineRegistryDwordValue (BSTR keyPath, BSTR valueName, DWORD value);
|
||||
};
|
||||
|
||||
|
||||
BOOL ComGetInstanceBase (HWND hWnd, REFCLSID clsid, REFIID iid, void **tcServer);
|
||||
HRESULT CreateElevatedComObject (HWND hwnd, REFGUID guid, REFIID iid, void **ppv);
|
||||
|
||||
#endif // TC_HEADER_BASE_COM
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_BASE_COM
|
||||
#define TC_HEADER_BASE_COM
|
||||
|
||||
#include <guiddef.h>
|
||||
|
||||
template <class TClass>
|
||||
class TrueCryptFactory : public IClassFactory
|
||||
{
|
||||
|
||||
public:
|
||||
TrueCryptFactory (DWORD messageThreadId) :
|
||||
RefCount (1), ServerLockCount (0), MessageThreadId (messageThreadId) { }
|
||||
|
||||
~TrueCryptFactory () { }
|
||||
|
||||
virtual ULONG STDMETHODCALLTYPE AddRef ()
|
||||
{
|
||||
return InterlockedIncrement (&RefCount) - 1;
|
||||
}
|
||||
|
||||
virtual ULONG STDMETHODCALLTYPE Release ()
|
||||
{
|
||||
ULONG r = InterlockedDecrement (&RefCount) + 1;
|
||||
|
||||
if (r == 0)
|
||||
delete this;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE QueryInterface (REFIID riid, void **ppvObject)
|
||||
{
|
||||
if (riid == IID_IUnknown || riid == IID_IClassFactory)
|
||||
*ppvObject = this;
|
||||
else
|
||||
{
|
||||
*ppvObject = NULL;
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
AddRef ();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE CreateInstance (IUnknown *pUnkOuter, REFIID riid, void **ppvObject)
|
||||
{
|
||||
if (pUnkOuter != NULL)
|
||||
return CLASS_E_NOAGGREGATION;
|
||||
|
||||
TClass *tc = new TClass (MessageThreadId);
|
||||
if (tc == NULL)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
HRESULT hr = tc->QueryInterface (riid, ppvObject);
|
||||
|
||||
if (hr)
|
||||
delete tc;
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE LockServer (BOOL fLock)
|
||||
{
|
||||
if (fLock)
|
||||
{
|
||||
InterlockedIncrement (&ServerLockCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!InterlockedDecrement (&ServerLockCount))
|
||||
PostThreadMessage (MessageThreadId, WM_APP, 0, 0);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
virtual bool IsServerLocked ()
|
||||
{
|
||||
return ServerLockCount > 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
DWORD MessageThreadId;
|
||||
LONG RefCount;
|
||||
LONG ServerLockCount;
|
||||
};
|
||||
|
||||
|
||||
class BaseCom
|
||||
{
|
||||
public:
|
||||
static DWORD CallDriver (DWORD ioctl, BSTR input, BSTR *output);
|
||||
static DWORD CopyFile (BSTR sourceFile, BSTR destinationFile);
|
||||
static DWORD DeleteFile (BSTR file);
|
||||
static BOOL IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly);
|
||||
static DWORD ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *bufferBstr, unsigned __int64 offset, unsigned __int32 size, DWORD *sizeDone);
|
||||
static DWORD RegisterFilterDriver (BOOL registerDriver, int filterType);
|
||||
static DWORD RegisterSystemFavoritesService (BOOL registerService);
|
||||
static DWORD SetDriverServiceStartType (DWORD startType);
|
||||
static DWORD WriteLocalMachineRegistryDwordValue (BSTR keyPath, BSTR valueName, DWORD value);
|
||||
};
|
||||
|
||||
|
||||
BOOL ComGetInstanceBase (HWND hWnd, REFCLSID clsid, REFIID iid, void **tcServer);
|
||||
HRESULT CreateElevatedComObject (HWND hwnd, REFGUID guid, REFIID iid, void **ppv);
|
||||
|
||||
#endif // TC_HEADER_BASE_COM
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,255 +1,255 @@
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Common_BootEncryption
|
||||
#define TC_HEADER_Common_BootEncryption
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Exception.h"
|
||||
#include "Platform/PlatformBase.h"
|
||||
#include "Volumes.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace VeraCrypt
|
||||
{
|
||||
class File
|
||||
{
|
||||
public:
|
||||
File () : Elevated (false), FileOpen (false), FilePointerPosition(0), Handle(INVALID_HANDLE_VALUE), IsDevice(false), LastError(0) { }
|
||||
File (wstring path,bool readOnly = false, bool create = false);
|
||||
virtual ~File () { Close(); }
|
||||
|
||||
void CheckOpened (const char* srcPos) { if (!FileOpen) { SetLastError (LastError); throw SystemException (srcPos);} }
|
||||
void Close ();
|
||||
DWORD Read (byte *buffer, DWORD size);
|
||||
void Write (byte *buffer, DWORD size);
|
||||
void SeekAt (int64 position);
|
||||
|
||||
protected:
|
||||
bool Elevated;
|
||||
bool FileOpen;
|
||||
uint64 FilePointerPosition;
|
||||
HANDLE Handle;
|
||||
bool IsDevice;
|
||||
wstring Path;
|
||||
DWORD LastError;
|
||||
};
|
||||
|
||||
|
||||
class Device : public File
|
||||
{
|
||||
public:
|
||||
Device (wstring path,bool readOnly = false);
|
||||
virtual ~Device () {}
|
||||
};
|
||||
|
||||
|
||||
class Buffer
|
||||
{
|
||||
public:
|
||||
Buffer (size_t size) : DataSize (size)
|
||||
{
|
||||
DataPtr = new byte[size];
|
||||
if (!DataPtr)
|
||||
throw bad_alloc();
|
||||
}
|
||||
|
||||
~Buffer () { delete[] DataPtr; }
|
||||
byte *Ptr () const { return DataPtr; }
|
||||
size_t Size () const { return DataSize; }
|
||||
|
||||
protected:
|
||||
byte *DataPtr;
|
||||
size_t DataSize;
|
||||
};
|
||||
|
||||
|
||||
struct Partition
|
||||
{
|
||||
wstring DevicePath;
|
||||
PARTITION_INFORMATION Info;
|
||||
wstring MountPoint;
|
||||
size_t Number;
|
||||
BOOL IsGPT;
|
||||
wstring VolumeNameId;
|
||||
};
|
||||
|
||||
typedef list <Partition> PartitionList;
|
||||
|
||||
#pragma pack (push)
|
||||
#pragma pack(1)
|
||||
|
||||
struct PartitionEntryMBR
|
||||
{
|
||||
byte BootIndicator;
|
||||
|
||||
byte StartHead;
|
||||
byte StartCylSector;
|
||||
byte StartCylinder;
|
||||
|
||||
byte Type;
|
||||
|
||||
byte EndHead;
|
||||
byte EndSector;
|
||||
byte EndCylinder;
|
||||
|
||||
uint32 StartLBA;
|
||||
uint32 SectorCountLBA;
|
||||
};
|
||||
|
||||
struct MBR
|
||||
{
|
||||
byte Code[446];
|
||||
PartitionEntryMBR Partitions[4];
|
||||
uint16 Signature;
|
||||
};
|
||||
|
||||
#pragma pack (pop)
|
||||
|
||||
struct SystemDriveConfiguration
|
||||
{
|
||||
wstring DeviceKernelPath;
|
||||
wstring DevicePath;
|
||||
int DriveNumber;
|
||||
Partition DrivePartition;
|
||||
bool ExtraBootPartitionPresent;
|
||||
int64 InitialUnallocatedSpace;
|
||||
PartitionList Partitions;
|
||||
Partition SystemPartition;
|
||||
int64 TotalUnallocatedSpace;
|
||||
bool SystemLoaderPresent;
|
||||
};
|
||||
|
||||
class BootEncryption
|
||||
{
|
||||
public:
|
||||
BootEncryption (HWND parent);
|
||||
~BootEncryption ();
|
||||
|
||||
enum FilterType
|
||||
{
|
||||
DriveFilter,
|
||||
VolumeFilter,
|
||||
DumpFilter
|
||||
};
|
||||
|
||||
void SetParentWindow (HWND parent) { ParentWindow = parent; }
|
||||
void AbortDecoyOSWipe ();
|
||||
void AbortSetup ();
|
||||
void AbortSetupWait ();
|
||||
void CallDriver (DWORD ioctl, void *input = nullptr, DWORD inputSize = 0, void *output = nullptr, DWORD outputSize = 0);
|
||||
int ChangePassword (Password *oldPassword, int old_pkcs5, int old_pim, Password *newPassword, int pkcs5, int pim, int wipePassCount, HWND hwndDlg);
|
||||
void CheckDecoyOSWipeResult ();
|
||||
void CheckEncryptionSetupResult ();
|
||||
void CheckRequirements ();
|
||||
void CheckRequirementsHiddenOS ();
|
||||
void CopyFileAdmin (const wstring &sourceFile, const wstring &destinationFile);
|
||||
void CreateRescueIsoImage (bool initialSetup, const wstring &isoImagePath);
|
||||
void Deinstall (bool displayWaitDialog = false);
|
||||
void DeleteFileAdmin (const wstring &file);
|
||||
DecoySystemWipeStatus GetDecoyOSWipeStatus ();
|
||||
DWORD GetDriverServiceStartType ();
|
||||
unsigned int GetHiddenOSCreationPhase ();
|
||||
uint16 GetInstalledBootLoaderVersion ();
|
||||
void GetInstalledBootLoaderFingerprint (byte fingerprint[WHIRLPOOL_DIGESTSIZE + SHA512_DIGESTSIZE]);
|
||||
Partition GetPartitionForHiddenOS ();
|
||||
bool IsBootLoaderOnDrive (wchar_t *devicePath);
|
||||
BootEncryptionStatus GetStatus ();
|
||||
void GetVolumeProperties (VOLUME_PROPERTIES_STRUCT *properties);
|
||||
SystemDriveConfiguration GetSystemDriveConfiguration ();
|
||||
void Install (bool hiddenSystem);
|
||||
void InstallBootLoader (Device& device, bool preserveUserConfig = false, bool hiddenOSCreation = false, int pim = -1);
|
||||
void InstallBootLoader (bool preserveUserConfig = false, bool hiddenOSCreation = false);
|
||||
bool CheckBootloaderFingerprint (bool bSilent = false);
|
||||
void InvalidateCachedSysDriveProperties ();
|
||||
bool IsCDRecorderPresent ();
|
||||
bool IsHiddenSystemRunning ();
|
||||
bool IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly);
|
||||
void PrepareHiddenOSCreation (int ea, int mode, int pkcs5);
|
||||
void PrepareInstallation (bool systemPartitionOnly, Password &password, int ea, int mode, int pkcs5, int pim, const wstring &rescueIsoImagePath);
|
||||
void ProbeRealSystemDriveSize ();
|
||||
void ReadBootSectorConfig (byte *config, size_t bufLength, byte *userConfig = nullptr, string *customUserMessage = nullptr, uint16 *bootLoaderVersion = nullptr);
|
||||
uint32 ReadDriverConfigurationFlags ();
|
||||
void RegisterBootDriver (bool hiddenSystem);
|
||||
void RegisterFilterDriver (bool registerDriver, FilterType filterType);
|
||||
void RegisterSystemFavoritesService (BOOL registerService);
|
||||
void RegisterSystemFavoritesService (BOOL registerService, BOOL noFileHandling);
|
||||
void UpdateSystemFavoritesService ();
|
||||
void RenameDeprecatedSystemLoaderBackup ();
|
||||
bool RestartComputer (void);
|
||||
void InitialSecurityChecksForHiddenOS ();
|
||||
void RestrictPagingFilesToSystemPartition ();
|
||||
void SetDriverConfigurationFlag (uint32 flag, bool state);
|
||||
void SetDriverServiceStartType (DWORD startType);
|
||||
void SetHiddenOSCreationPhase (unsigned int newPhase);
|
||||
void StartDecryption (BOOL discardUnreadableEncryptedSectors);
|
||||
void StartDecoyOSWipe (WipeAlgorithmId wipeAlgorithm);
|
||||
void StartEncryption (WipeAlgorithmId wipeAlgorithm, bool zeroUnreadableSectors);
|
||||
bool SystemDriveContainsPartitionType (byte type);
|
||||
bool SystemDriveContainsExtendedPartition ();
|
||||
bool SystemDriveContainsNonStandardPartitions ();
|
||||
bool SystemPartitionCoversWholeDrive ();
|
||||
bool SystemDriveIsDynamic ();
|
||||
bool VerifyRescueDisk ();
|
||||
bool VerifyRescueDiskIsoImage (const wchar_t* imageFile);
|
||||
void WipeHiddenOSCreationConfig ();
|
||||
void WriteBootDriveSector (uint64 offset, byte *data);
|
||||
void WriteBootSectorConfig (const byte newConfig[]);
|
||||
void WriteBootSectorUserConfig (byte userConfig, const string &customUserMessage, int pim);
|
||||
void WriteLocalMachineRegistryDwordValue (wchar_t *keyPath, wchar_t *valueName, DWORD value);
|
||||
|
||||
protected:
|
||||
static const uint32 RescueIsoImageSize = 1835008; // Size of ISO9660 image with bootable emulated 1.44MB floppy disk image
|
||||
|
||||
void BackupSystemLoader ();
|
||||
void CreateBootLoaderInMemory (byte *buffer, size_t bufferSize, bool rescueDisk, bool hiddenOSCreation = false);
|
||||
void CreateVolumeHeader (uint64 volumeSize, uint64 encryptedAreaStart, Password *password, int ea, int mode, int pkcs5, int pim);
|
||||
wstring GetSystemLoaderBackupPath ();
|
||||
uint32 GetChecksum (byte *data, size_t size);
|
||||
DISK_GEOMETRY GetDriveGeometry (int driveNumber);
|
||||
PartitionList GetDrivePartitions (int driveNumber);
|
||||
wstring GetRemarksOnHiddenOS ();
|
||||
wstring GetWindowsDirectory ();
|
||||
void RegisterFilter (bool registerFilter, FilterType filterType, const GUID *deviceClassGuid = nullptr);
|
||||
void RestoreSystemLoader ();
|
||||
void InstallVolumeHeader ();
|
||||
|
||||
HWND ParentWindow;
|
||||
SystemDriveConfiguration DriveConfig;
|
||||
int SelectedEncryptionAlgorithmId;
|
||||
int SelectedPrfAlgorithmId;
|
||||
Partition HiddenOSCandidatePartition;
|
||||
byte *RescueIsoImage;
|
||||
byte RescueVolumeHeader[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE];
|
||||
byte VolumeHeader[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE];
|
||||
bool DriveConfigValid;
|
||||
bool RealSystemDriveSizeValid;
|
||||
bool RescueVolumeHeaderValid;
|
||||
bool VolumeHeaderValid;
|
||||
};
|
||||
}
|
||||
|
||||
#define TC_ABORT_TRANSFORM_WAIT_INTERVAL 10
|
||||
|
||||
#define MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_NTFS 2.1
|
||||
#define MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_FAT 1.05
|
||||
|
||||
#define TC_SYS_BOOT_LOADER_BACKUP_NAME L"Original System Loader"
|
||||
#define TC_SYS_BOOT_LOADER_BACKUP_NAME_LEGACY L"Original System Loader.bak" // Deprecated to prevent removal by some "cleaners"
|
||||
|
||||
#define TC_SYSTEM_FAVORITES_SERVICE_NAME _T(TC_APP_NAME) L"SystemFavorites"
|
||||
#define TC_SYSTEM_FAVORITES_SERVICE_LOAD_ORDER_GROUP L"Event Log"
|
||||
#define TC_SYSTEM_FAVORITES_SERVICE_CMDLINE_OPTION L"/systemFavoritesService"
|
||||
|
||||
#endif // TC_HEADER_Common_BootEncryption
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Common_BootEncryption
|
||||
#define TC_HEADER_Common_BootEncryption
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Exception.h"
|
||||
#include "Platform/PlatformBase.h"
|
||||
#include "Volumes.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace VeraCrypt
|
||||
{
|
||||
class File
|
||||
{
|
||||
public:
|
||||
File () : Elevated (false), FileOpen (false), FilePointerPosition(0), Handle(INVALID_HANDLE_VALUE), IsDevice(false), LastError(0) { }
|
||||
File (wstring path,bool readOnly = false, bool create = false);
|
||||
virtual ~File () { Close(); }
|
||||
|
||||
void CheckOpened (const char* srcPos) { if (!FileOpen) { SetLastError (LastError); throw SystemException (srcPos);} }
|
||||
void Close ();
|
||||
DWORD Read (byte *buffer, DWORD size);
|
||||
void Write (byte *buffer, DWORD size);
|
||||
void SeekAt (int64 position);
|
||||
|
||||
protected:
|
||||
bool Elevated;
|
||||
bool FileOpen;
|
||||
uint64 FilePointerPosition;
|
||||
HANDLE Handle;
|
||||
bool IsDevice;
|
||||
wstring Path;
|
||||
DWORD LastError;
|
||||
};
|
||||
|
||||
|
||||
class Device : public File
|
||||
{
|
||||
public:
|
||||
Device (wstring path,bool readOnly = false);
|
||||
virtual ~Device () {}
|
||||
};
|
||||
|
||||
|
||||
class Buffer
|
||||
{
|
||||
public:
|
||||
Buffer (size_t size) : DataSize (size)
|
||||
{
|
||||
DataPtr = new byte[size];
|
||||
if (!DataPtr)
|
||||
throw bad_alloc();
|
||||
}
|
||||
|
||||
~Buffer () { delete[] DataPtr; }
|
||||
byte *Ptr () const { return DataPtr; }
|
||||
size_t Size () const { return DataSize; }
|
||||
|
||||
protected:
|
||||
byte *DataPtr;
|
||||
size_t DataSize;
|
||||
};
|
||||
|
||||
|
||||
struct Partition
|
||||
{
|
||||
wstring DevicePath;
|
||||
PARTITION_INFORMATION Info;
|
||||
wstring MountPoint;
|
||||
size_t Number;
|
||||
BOOL IsGPT;
|
||||
wstring VolumeNameId;
|
||||
};
|
||||
|
||||
typedef list <Partition> PartitionList;
|
||||
|
||||
#pragma pack (push)
|
||||
#pragma pack(1)
|
||||
|
||||
struct PartitionEntryMBR
|
||||
{
|
||||
byte BootIndicator;
|
||||
|
||||
byte StartHead;
|
||||
byte StartCylSector;
|
||||
byte StartCylinder;
|
||||
|
||||
byte Type;
|
||||
|
||||
byte EndHead;
|
||||
byte EndSector;
|
||||
byte EndCylinder;
|
||||
|
||||
uint32 StartLBA;
|
||||
uint32 SectorCountLBA;
|
||||
};
|
||||
|
||||
struct MBR
|
||||
{
|
||||
byte Code[446];
|
||||
PartitionEntryMBR Partitions[4];
|
||||
uint16 Signature;
|
||||
};
|
||||
|
||||
#pragma pack (pop)
|
||||
|
||||
struct SystemDriveConfiguration
|
||||
{
|
||||
wstring DeviceKernelPath;
|
||||
wstring DevicePath;
|
||||
int DriveNumber;
|
||||
Partition DrivePartition;
|
||||
bool ExtraBootPartitionPresent;
|
||||
int64 InitialUnallocatedSpace;
|
||||
PartitionList Partitions;
|
||||
Partition SystemPartition;
|
||||
int64 TotalUnallocatedSpace;
|
||||
bool SystemLoaderPresent;
|
||||
};
|
||||
|
||||
class BootEncryption
|
||||
{
|
||||
public:
|
||||
BootEncryption (HWND parent);
|
||||
~BootEncryption ();
|
||||
|
||||
enum FilterType
|
||||
{
|
||||
DriveFilter,
|
||||
VolumeFilter,
|
||||
DumpFilter
|
||||
};
|
||||
|
||||
void SetParentWindow (HWND parent) { ParentWindow = parent; }
|
||||
void AbortDecoyOSWipe ();
|
||||
void AbortSetup ();
|
||||
void AbortSetupWait ();
|
||||
void CallDriver (DWORD ioctl, void *input = nullptr, DWORD inputSize = 0, void *output = nullptr, DWORD outputSize = 0);
|
||||
int ChangePassword (Password *oldPassword, int old_pkcs5, int old_pim, Password *newPassword, int pkcs5, int pim, int wipePassCount, HWND hwndDlg);
|
||||
void CheckDecoyOSWipeResult ();
|
||||
void CheckEncryptionSetupResult ();
|
||||
void CheckRequirements ();
|
||||
void CheckRequirementsHiddenOS ();
|
||||
void CopyFileAdmin (const wstring &sourceFile, const wstring &destinationFile);
|
||||
void CreateRescueIsoImage (bool initialSetup, const wstring &isoImagePath);
|
||||
void Deinstall (bool displayWaitDialog = false);
|
||||
void DeleteFileAdmin (const wstring &file);
|
||||
DecoySystemWipeStatus GetDecoyOSWipeStatus ();
|
||||
DWORD GetDriverServiceStartType ();
|
||||
unsigned int GetHiddenOSCreationPhase ();
|
||||
uint16 GetInstalledBootLoaderVersion ();
|
||||
void GetInstalledBootLoaderFingerprint (byte fingerprint[WHIRLPOOL_DIGESTSIZE + SHA512_DIGESTSIZE]);
|
||||
Partition GetPartitionForHiddenOS ();
|
||||
bool IsBootLoaderOnDrive (wchar_t *devicePath);
|
||||
BootEncryptionStatus GetStatus ();
|
||||
void GetVolumeProperties (VOLUME_PROPERTIES_STRUCT *properties);
|
||||
SystemDriveConfiguration GetSystemDriveConfiguration ();
|
||||
void Install (bool hiddenSystem);
|
||||
void InstallBootLoader (Device& device, bool preserveUserConfig = false, bool hiddenOSCreation = false, int pim = -1);
|
||||
void InstallBootLoader (bool preserveUserConfig = false, bool hiddenOSCreation = false);
|
||||
bool CheckBootloaderFingerprint (bool bSilent = false);
|
||||
void InvalidateCachedSysDriveProperties ();
|
||||
bool IsCDRecorderPresent ();
|
||||
bool IsHiddenSystemRunning ();
|
||||
bool IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly);
|
||||
void PrepareHiddenOSCreation (int ea, int mode, int pkcs5);
|
||||
void PrepareInstallation (bool systemPartitionOnly, Password &password, int ea, int mode, int pkcs5, int pim, const wstring &rescueIsoImagePath);
|
||||
void ProbeRealSystemDriveSize ();
|
||||
void ReadBootSectorConfig (byte *config, size_t bufLength, byte *userConfig = nullptr, string *customUserMessage = nullptr, uint16 *bootLoaderVersion = nullptr);
|
||||
uint32 ReadDriverConfigurationFlags ();
|
||||
void RegisterBootDriver (bool hiddenSystem);
|
||||
void RegisterFilterDriver (bool registerDriver, FilterType filterType);
|
||||
void RegisterSystemFavoritesService (BOOL registerService);
|
||||
void RegisterSystemFavoritesService (BOOL registerService, BOOL noFileHandling);
|
||||
void UpdateSystemFavoritesService ();
|
||||
void RenameDeprecatedSystemLoaderBackup ();
|
||||
bool RestartComputer (void);
|
||||
void InitialSecurityChecksForHiddenOS ();
|
||||
void RestrictPagingFilesToSystemPartition ();
|
||||
void SetDriverConfigurationFlag (uint32 flag, bool state);
|
||||
void SetDriverServiceStartType (DWORD startType);
|
||||
void SetHiddenOSCreationPhase (unsigned int newPhase);
|
||||
void StartDecryption (BOOL discardUnreadableEncryptedSectors);
|
||||
void StartDecoyOSWipe (WipeAlgorithmId wipeAlgorithm);
|
||||
void StartEncryption (WipeAlgorithmId wipeAlgorithm, bool zeroUnreadableSectors);
|
||||
bool SystemDriveContainsPartitionType (byte type);
|
||||
bool SystemDriveContainsExtendedPartition ();
|
||||
bool SystemDriveContainsNonStandardPartitions ();
|
||||
bool SystemPartitionCoversWholeDrive ();
|
||||
bool SystemDriveIsDynamic ();
|
||||
bool VerifyRescueDisk ();
|
||||
bool VerifyRescueDiskIsoImage (const wchar_t* imageFile);
|
||||
void WipeHiddenOSCreationConfig ();
|
||||
void WriteBootDriveSector (uint64 offset, byte *data);
|
||||
void WriteBootSectorConfig (const byte newConfig[]);
|
||||
void WriteBootSectorUserConfig (byte userConfig, const string &customUserMessage, int pim);
|
||||
void WriteLocalMachineRegistryDwordValue (wchar_t *keyPath, wchar_t *valueName, DWORD value);
|
||||
|
||||
protected:
|
||||
static const uint32 RescueIsoImageSize = 1835008; // Size of ISO9660 image with bootable emulated 1.44MB floppy disk image
|
||||
|
||||
void BackupSystemLoader ();
|
||||
void CreateBootLoaderInMemory (byte *buffer, size_t bufferSize, bool rescueDisk, bool hiddenOSCreation = false);
|
||||
void CreateVolumeHeader (uint64 volumeSize, uint64 encryptedAreaStart, Password *password, int ea, int mode, int pkcs5, int pim);
|
||||
wstring GetSystemLoaderBackupPath ();
|
||||
uint32 GetChecksum (byte *data, size_t size);
|
||||
DISK_GEOMETRY GetDriveGeometry (int driveNumber);
|
||||
PartitionList GetDrivePartitions (int driveNumber);
|
||||
wstring GetRemarksOnHiddenOS ();
|
||||
wstring GetWindowsDirectory ();
|
||||
void RegisterFilter (bool registerFilter, FilterType filterType, const GUID *deviceClassGuid = nullptr);
|
||||
void RestoreSystemLoader ();
|
||||
void InstallVolumeHeader ();
|
||||
|
||||
HWND ParentWindow;
|
||||
SystemDriveConfiguration DriveConfig;
|
||||
int SelectedEncryptionAlgorithmId;
|
||||
int SelectedPrfAlgorithmId;
|
||||
Partition HiddenOSCandidatePartition;
|
||||
byte *RescueIsoImage;
|
||||
byte RescueVolumeHeader[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE];
|
||||
byte VolumeHeader[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE];
|
||||
bool DriveConfigValid;
|
||||
bool RealSystemDriveSizeValid;
|
||||
bool RescueVolumeHeaderValid;
|
||||
bool VolumeHeaderValid;
|
||||
};
|
||||
}
|
||||
|
||||
#define TC_ABORT_TRANSFORM_WAIT_INTERVAL 10
|
||||
|
||||
#define MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_NTFS 2.1
|
||||
#define MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_FAT 1.05
|
||||
|
||||
#define TC_SYS_BOOT_LOADER_BACKUP_NAME L"Original System Loader"
|
||||
#define TC_SYS_BOOT_LOADER_BACKUP_NAME_LEGACY L"Original System Loader.bak" // Deprecated to prevent removal by some "cleaners"
|
||||
|
||||
#define TC_SYSTEM_FAVORITES_SERVICE_NAME _T(TC_APP_NAME) L"SystemFavorites"
|
||||
#define TC_SYSTEM_FAVORITES_SERVICE_LOAD_ORDER_GROUP L"Event Log"
|
||||
#define TC_SYSTEM_FAVORITES_SERVICE_CMDLINE_OPTION L"/systemFavoritesService"
|
||||
|
||||
#endif // TC_HEADER_Common_BootEncryption
|
||||
|
||||
@@ -1,115 +1,115 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Crypto.h"
|
||||
#include "Fat.h"
|
||||
#include "Volumes.h"
|
||||
#include "Apidrvr.h"
|
||||
#include "Common.h"
|
||||
#include "Cache.h"
|
||||
|
||||
Password CachedPasswords[CACHE_SIZE];
|
||||
int CachedPim[CACHE_SIZE];
|
||||
int cacheEmpty = 1;
|
||||
static int nPasswordIdx = 0;
|
||||
|
||||
int ReadVolumeHeaderWCache (BOOL bBoot, BOOL bCache, BOOL bCachePim, char *header, Password *password, int pkcs5_prf, int pim, BOOL truecryptMode, PCRYPTO_INFO *retInfo)
|
||||
{
|
||||
int nReturnCode = ERR_PASSWORD_WRONG;
|
||||
int i, effectivePim;
|
||||
|
||||
/* Attempt to recognize volume using mount password */
|
||||
if (password->Length > 0)
|
||||
{
|
||||
nReturnCode = ReadVolumeHeader (bBoot, header, password, pkcs5_prf, pim, truecryptMode, retInfo, NULL);
|
||||
|
||||
/* Save mount passwords back into cache if asked to do so */
|
||||
if (bCache && (nReturnCode == 0 || nReturnCode == ERR_CIPHER_INIT_WEAK_KEY))
|
||||
{
|
||||
for (i = 0; i < CACHE_SIZE; i++)
|
||||
{
|
||||
if (memcmp (&CachedPasswords[i], password, sizeof (Password)) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (i == CACHE_SIZE)
|
||||
{
|
||||
/* Store the password */
|
||||
CachedPasswords[nPasswordIdx] = *password;
|
||||
|
||||
/* Store also PIM if requested, otherwise set to default */
|
||||
if (bCachePim && (pim > 0))
|
||||
CachedPim[nPasswordIdx] = pim;
|
||||
else
|
||||
CachedPim[nPasswordIdx] = 0;
|
||||
|
||||
/* Try another slot */
|
||||
nPasswordIdx = (nPasswordIdx + 1) % CACHE_SIZE;
|
||||
|
||||
cacheEmpty = 0;
|
||||
}
|
||||
else if (bCachePim)
|
||||
{
|
||||
CachedPim[i] = pim > 0? pim : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!cacheEmpty)
|
||||
{
|
||||
/* Attempt to recognize volume using cached passwords */
|
||||
for (i = 0; i < CACHE_SIZE; i++)
|
||||
{
|
||||
if (CachedPasswords[i].Length > 0)
|
||||
{
|
||||
if (truecryptMode)
|
||||
effectivePim = 0;
|
||||
else if (pim == -1)
|
||||
effectivePim = CachedPim[i];
|
||||
else
|
||||
effectivePim = pim;
|
||||
nReturnCode = ReadVolumeHeader (bBoot, header, &CachedPasswords[i], pkcs5_prf, effectivePim, truecryptMode, retInfo, NULL);
|
||||
|
||||
if (nReturnCode != ERR_PASSWORD_WRONG)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nReturnCode;
|
||||
}
|
||||
|
||||
|
||||
void AddPasswordToCache (Password *password, int pim)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < CACHE_SIZE; i++)
|
||||
{
|
||||
if (memcmp (&CachedPasswords[i], password, sizeof (Password)) == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
CachedPasswords[nPasswordIdx] = *password;
|
||||
CachedPim[nPasswordIdx] = pim > 0? pim : 0;
|
||||
nPasswordIdx = (nPasswordIdx + 1) % CACHE_SIZE;
|
||||
cacheEmpty = 0;
|
||||
}
|
||||
|
||||
|
||||
void WipeCache ()
|
||||
{
|
||||
burn (CachedPasswords, sizeof (CachedPasswords));
|
||||
burn (CachedPim, sizeof (CachedPim));
|
||||
nPasswordIdx = 0;
|
||||
cacheEmpty = 1;
|
||||
}
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Crypto.h"
|
||||
#include "Fat.h"
|
||||
#include "Volumes.h"
|
||||
#include "Apidrvr.h"
|
||||
#include "Common.h"
|
||||
#include "Cache.h"
|
||||
|
||||
Password CachedPasswords[CACHE_SIZE];
|
||||
int CachedPim[CACHE_SIZE];
|
||||
int cacheEmpty = 1;
|
||||
static int nPasswordIdx = 0;
|
||||
|
||||
int ReadVolumeHeaderWCache (BOOL bBoot, BOOL bCache, BOOL bCachePim, char *header, Password *password, int pkcs5_prf, int pim, BOOL truecryptMode, PCRYPTO_INFO *retInfo)
|
||||
{
|
||||
int nReturnCode = ERR_PASSWORD_WRONG;
|
||||
int i, effectivePim;
|
||||
|
||||
/* Attempt to recognize volume using mount password */
|
||||
if (password->Length > 0)
|
||||
{
|
||||
nReturnCode = ReadVolumeHeader (bBoot, header, password, pkcs5_prf, pim, truecryptMode, retInfo, NULL);
|
||||
|
||||
/* Save mount passwords back into cache if asked to do so */
|
||||
if (bCache && (nReturnCode == 0 || nReturnCode == ERR_CIPHER_INIT_WEAK_KEY))
|
||||
{
|
||||
for (i = 0; i < CACHE_SIZE; i++)
|
||||
{
|
||||
if (memcmp (&CachedPasswords[i], password, sizeof (Password)) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (i == CACHE_SIZE)
|
||||
{
|
||||
/* Store the password */
|
||||
CachedPasswords[nPasswordIdx] = *password;
|
||||
|
||||
/* Store also PIM if requested, otherwise set to default */
|
||||
if (bCachePim && (pim > 0))
|
||||
CachedPim[nPasswordIdx] = pim;
|
||||
else
|
||||
CachedPim[nPasswordIdx] = 0;
|
||||
|
||||
/* Try another slot */
|
||||
nPasswordIdx = (nPasswordIdx + 1) % CACHE_SIZE;
|
||||
|
||||
cacheEmpty = 0;
|
||||
}
|
||||
else if (bCachePim)
|
||||
{
|
||||
CachedPim[i] = pim > 0? pim : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!cacheEmpty)
|
||||
{
|
||||
/* Attempt to recognize volume using cached passwords */
|
||||
for (i = 0; i < CACHE_SIZE; i++)
|
||||
{
|
||||
if (CachedPasswords[i].Length > 0)
|
||||
{
|
||||
if (truecryptMode)
|
||||
effectivePim = 0;
|
||||
else if (pim == -1)
|
||||
effectivePim = CachedPim[i];
|
||||
else
|
||||
effectivePim = pim;
|
||||
nReturnCode = ReadVolumeHeader (bBoot, header, &CachedPasswords[i], pkcs5_prf, effectivePim, truecryptMode, retInfo, NULL);
|
||||
|
||||
if (nReturnCode != ERR_PASSWORD_WRONG)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nReturnCode;
|
||||
}
|
||||
|
||||
|
||||
void AddPasswordToCache (Password *password, int pim)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < CACHE_SIZE; i++)
|
||||
{
|
||||
if (memcmp (&CachedPasswords[i], password, sizeof (Password)) == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
CachedPasswords[nPasswordIdx] = *password;
|
||||
CachedPim[nPasswordIdx] = pim > 0? pim : 0;
|
||||
nPasswordIdx = (nPasswordIdx + 1) % CACHE_SIZE;
|
||||
cacheEmpty = 0;
|
||||
}
|
||||
|
||||
|
||||
void WipeCache ()
|
||||
{
|
||||
burn (CachedPasswords, sizeof (CachedPasswords));
|
||||
burn (CachedPim, sizeof (CachedPim));
|
||||
nPasswordIdx = 0;
|
||||
cacheEmpty = 1;
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
#ifndef CACHE_SIZE
|
||||
/* WARNING: Changing this value might not be safe (some items may be hard coded for 4)! Inspection necessary. */
|
||||
#define CACHE_SIZE 4
|
||||
#endif
|
||||
|
||||
extern int cacheEmpty;
|
||||
|
||||
void AddPasswordToCache (Password *password, int pim);
|
||||
int ReadVolumeHeaderWCache (BOOL bBoot, BOOL bCache, BOOL bCachePim,char *header, Password *password, int pkcs5_prf, int pim, BOOL truecryptMode, PCRYPTO_INFO *retInfo);
|
||||
void WipeCache (void);
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
#ifndef CACHE_SIZE
|
||||
/* WARNING: Changing this value might not be safe (some items may be hard coded for 4)! Inspection necessary. */
|
||||
#define CACHE_SIZE 4
|
||||
#endif
|
||||
|
||||
extern int cacheEmpty;
|
||||
|
||||
void AddPasswordToCache (Password *password, int pim);
|
||||
int ReadVolumeHeaderWCache (BOOL bBoot, BOOL bCache, BOOL bCachePim,char *header, Password *password, int pkcs5_prf, int pim, BOOL truecryptMode, PCRYPTO_INFO *retInfo);
|
||||
void WipeCache (void);
|
||||
|
||||
@@ -1,184 +1,184 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#include <malloc.h>
|
||||
#include <ctype.h>
|
||||
#include "Cmdline.h"
|
||||
|
||||
#include "Resource.h"
|
||||
#include "Crypto.h"
|
||||
#include "Apidrvr.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Language.h"
|
||||
#include <Strsafe.h>
|
||||
|
||||
#ifndef SRC_POS
|
||||
#define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__))
|
||||
#endif
|
||||
|
||||
/* Except in response to the WM_INITDIALOG message, the dialog box procedure
|
||||
should return nonzero if it processes the message, and zero if it does
|
||||
not. - see DialogProc */
|
||||
BOOL CALLBACK CommandHelpDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
UNREFERENCED_PARAMETER (lParam); /* remove warning */
|
||||
UNREFERENCED_PARAMETER (wParam); /* remove warning */
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
{
|
||||
wchar_t * tmp = err_malloc(8192 * sizeof (wchar_t));
|
||||
wchar_t tmp2[MAX_PATH * 2];
|
||||
argumentspec *as;
|
||||
int i;
|
||||
|
||||
LocalizeDialog (hwndDlg, "IDD_COMMANDHELP_DLG");
|
||||
|
||||
as = (argumentspec*) lParam;
|
||||
|
||||
*tmp = 0;
|
||||
|
||||
StringCchCopyW (tmp, 8192, L"VeraCrypt " _T(VERSION_STRING));
|
||||
#ifdef _WIN64
|
||||
StringCchCatW (tmp, 8192, L" (64-bit)");
|
||||
#else
|
||||
StringCchCatW (tmp, 8192, L" (32-bit)");
|
||||
#endif
|
||||
#if (defined(_DEBUG) || defined(DEBUG))
|
||||
StringCchCatW (tmp, 8192, L" (debug)");
|
||||
#endif
|
||||
|
||||
StringCchCatW (tmp, 8192, L"\n\nCommand line options:\n\n");
|
||||
for (i = 0; i < as->arg_cnt; i ++)
|
||||
{
|
||||
if (!as->args[i].Internal)
|
||||
{
|
||||
StringCchPrintfW(tmp2, MAX_PATH * 2, L"%s\t%s\n", as->args[i].short_name, as->args[i].long_name);
|
||||
StringCchCatW(tmp, 8192, tmp2);
|
||||
}
|
||||
}
|
||||
|
||||
StringCchCatW (tmp, 8192, L"\nExamples:\n\nMount a volume as X:\tveracrypt.exe /q /v volume.hc /l X\nDismount a volume X:\tveracrypt.exe /q /d X");
|
||||
|
||||
SetWindowTextW (GetDlgItem (hwndDlg, IDC_COMMANDHELP_TEXT), tmp);
|
||||
|
||||
TCfree(tmp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
case WM_COMMAND:
|
||||
EndDialog (hwndDlg, IDOK);
|
||||
return 1;
|
||||
case WM_CLOSE:
|
||||
EndDialog (hwndDlg, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Win32CommandLine (wchar_t ***lpszArgs)
|
||||
{
|
||||
int argumentCount;
|
||||
int i;
|
||||
|
||||
LPWSTR *arguments = CommandLineToArgvW (GetCommandLineW(), &argumentCount);
|
||||
if (!arguments)
|
||||
{
|
||||
handleWin32Error (NULL, SRC_POS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
--argumentCount;
|
||||
if (argumentCount < 1)
|
||||
{
|
||||
LocalFree (arguments);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*lpszArgs = malloc (sizeof (wchar_t *) * argumentCount);
|
||||
if (!*lpszArgs)
|
||||
AbortProcess ("OUTOFMEMORY");
|
||||
|
||||
for (i = 0; i < argumentCount; ++i)
|
||||
{
|
||||
wchar_t *arg = _wcsdup (arguments[i + 1]);
|
||||
if (!arg)
|
||||
AbortProcess ("OUTOFMEMORY");
|
||||
|
||||
(*lpszArgs)[i] = arg;
|
||||
}
|
||||
|
||||
LocalFree (arguments);
|
||||
return argumentCount;
|
||||
}
|
||||
|
||||
int GetArgSepPosOffset (wchar_t *lpszArgument)
|
||||
{
|
||||
if (lpszArgument[0] == L'/')
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GetArgumentID (argumentspec *as, wchar_t *lpszArgument)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < as->arg_cnt; i++)
|
||||
{
|
||||
if (_wcsicmp (as->args[i].long_name, lpszArgument) == 0)
|
||||
{
|
||||
return as->args[i].Id;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < as->arg_cnt; i++)
|
||||
{
|
||||
if (as->args[i].short_name[0] == 0)
|
||||
continue;
|
||||
|
||||
if (_wcsicmp (as->args[i].short_name, lpszArgument) == 0)
|
||||
{
|
||||
return as->args[i].Id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int GetArgumentValue (wchar_t **lpszCommandLineArgs, int *nArgIdx,
|
||||
int nNoCommandLineArgs, wchar_t *lpszValue, int nValueSize)
|
||||
{
|
||||
*lpszValue = 0;
|
||||
|
||||
if (*nArgIdx + 1 < nNoCommandLineArgs)
|
||||
{
|
||||
int x = GetArgSepPosOffset (lpszCommandLineArgs[*nArgIdx + 1]);
|
||||
if (x == 0)
|
||||
{
|
||||
/* Handles the case of space between parameter code
|
||||
and value */
|
||||
StringCchCopyW (lpszValue, nValueSize, lpszCommandLineArgs[*nArgIdx + 1]);
|
||||
lpszValue[nValueSize - 1] = 0;
|
||||
(*nArgIdx)++;
|
||||
return HAS_ARGUMENT;
|
||||
}
|
||||
}
|
||||
|
||||
return HAS_NO_ARGUMENT;
|
||||
}
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#include <malloc.h>
|
||||
#include <ctype.h>
|
||||
#include "Cmdline.h"
|
||||
|
||||
#include "Resource.h"
|
||||
#include "Crypto.h"
|
||||
#include "Apidrvr.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Language.h"
|
||||
#include <Strsafe.h>
|
||||
|
||||
#ifndef SRC_POS
|
||||
#define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__))
|
||||
#endif
|
||||
|
||||
/* Except in response to the WM_INITDIALOG message, the dialog box procedure
|
||||
should return nonzero if it processes the message, and zero if it does
|
||||
not. - see DialogProc */
|
||||
BOOL CALLBACK CommandHelpDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
UNREFERENCED_PARAMETER (lParam); /* remove warning */
|
||||
UNREFERENCED_PARAMETER (wParam); /* remove warning */
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
{
|
||||
wchar_t * tmp = err_malloc(8192 * sizeof (wchar_t));
|
||||
wchar_t tmp2[MAX_PATH * 2];
|
||||
argumentspec *as;
|
||||
int i;
|
||||
|
||||
LocalizeDialog (hwndDlg, "IDD_COMMANDHELP_DLG");
|
||||
|
||||
as = (argumentspec*) lParam;
|
||||
|
||||
*tmp = 0;
|
||||
|
||||
StringCchCopyW (tmp, 8192, L"VeraCrypt " _T(VERSION_STRING));
|
||||
#ifdef _WIN64
|
||||
StringCchCatW (tmp, 8192, L" (64-bit)");
|
||||
#else
|
||||
StringCchCatW (tmp, 8192, L" (32-bit)");
|
||||
#endif
|
||||
#if (defined(_DEBUG) || defined(DEBUG))
|
||||
StringCchCatW (tmp, 8192, L" (debug)");
|
||||
#endif
|
||||
|
||||
StringCchCatW (tmp, 8192, L"\n\nCommand line options:\n\n");
|
||||
for (i = 0; i < as->arg_cnt; i ++)
|
||||
{
|
||||
if (!as->args[i].Internal)
|
||||
{
|
||||
StringCchPrintfW(tmp2, MAX_PATH * 2, L"%s\t%s\n", as->args[i].short_name, as->args[i].long_name);
|
||||
StringCchCatW(tmp, 8192, tmp2);
|
||||
}
|
||||
}
|
||||
|
||||
StringCchCatW (tmp, 8192, L"\nExamples:\n\nMount a volume as X:\tveracrypt.exe /q /v volume.hc /l X\nDismount a volume X:\tveracrypt.exe /q /d X");
|
||||
|
||||
SetWindowTextW (GetDlgItem (hwndDlg, IDC_COMMANDHELP_TEXT), tmp);
|
||||
|
||||
TCfree(tmp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
case WM_COMMAND:
|
||||
EndDialog (hwndDlg, IDOK);
|
||||
return 1;
|
||||
case WM_CLOSE:
|
||||
EndDialog (hwndDlg, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Win32CommandLine (wchar_t ***lpszArgs)
|
||||
{
|
||||
int argumentCount;
|
||||
int i;
|
||||
|
||||
LPWSTR *arguments = CommandLineToArgvW (GetCommandLineW(), &argumentCount);
|
||||
if (!arguments)
|
||||
{
|
||||
handleWin32Error (NULL, SRC_POS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
--argumentCount;
|
||||
if (argumentCount < 1)
|
||||
{
|
||||
LocalFree (arguments);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*lpszArgs = malloc (sizeof (wchar_t *) * argumentCount);
|
||||
if (!*lpszArgs)
|
||||
AbortProcess ("OUTOFMEMORY");
|
||||
|
||||
for (i = 0; i < argumentCount; ++i)
|
||||
{
|
||||
wchar_t *arg = _wcsdup (arguments[i + 1]);
|
||||
if (!arg)
|
||||
AbortProcess ("OUTOFMEMORY");
|
||||
|
||||
(*lpszArgs)[i] = arg;
|
||||
}
|
||||
|
||||
LocalFree (arguments);
|
||||
return argumentCount;
|
||||
}
|
||||
|
||||
int GetArgSepPosOffset (wchar_t *lpszArgument)
|
||||
{
|
||||
if (lpszArgument[0] == L'/')
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GetArgumentID (argumentspec *as, wchar_t *lpszArgument)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < as->arg_cnt; i++)
|
||||
{
|
||||
if (_wcsicmp (as->args[i].long_name, lpszArgument) == 0)
|
||||
{
|
||||
return as->args[i].Id;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < as->arg_cnt; i++)
|
||||
{
|
||||
if (as->args[i].short_name[0] == 0)
|
||||
continue;
|
||||
|
||||
if (_wcsicmp (as->args[i].short_name, lpszArgument) == 0)
|
||||
{
|
||||
return as->args[i].Id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int GetArgumentValue (wchar_t **lpszCommandLineArgs, int *nArgIdx,
|
||||
int nNoCommandLineArgs, wchar_t *lpszValue, int nValueSize)
|
||||
{
|
||||
*lpszValue = 0;
|
||||
|
||||
if (*nArgIdx + 1 < nNoCommandLineArgs)
|
||||
{
|
||||
int x = GetArgSepPosOffset (lpszCommandLineArgs[*nArgIdx + 1]);
|
||||
if (x == 0)
|
||||
{
|
||||
/* Handles the case of space between parameter code
|
||||
and value */
|
||||
StringCchCopyW (lpszValue, nValueSize, lpszCommandLineArgs[*nArgIdx + 1]);
|
||||
lpszValue[nValueSize - 1] = 0;
|
||||
(*nArgIdx)++;
|
||||
return HAS_ARGUMENT;
|
||||
}
|
||||
}
|
||||
|
||||
return HAS_NO_ARGUMENT;
|
||||
}
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define HAS_ARGUMENT 1
|
||||
#define HAS_NO_ARGUMENT !HAS_ARGUMENT
|
||||
|
||||
typedef struct argument_t
|
||||
{
|
||||
int Id;
|
||||
wchar_t long_name[32];
|
||||
wchar_t short_name[8];
|
||||
BOOL Internal;
|
||||
} argument;
|
||||
|
||||
typedef struct argumentspec_t
|
||||
{
|
||||
argument *args;
|
||||
int arg_cnt;
|
||||
} argumentspec;
|
||||
|
||||
BOOL CALLBACK CommandHelpDlgProc ( HWND hwndDlg , UINT msg , WPARAM wParam , LPARAM lParam );
|
||||
int Win32CommandLine ( wchar_t ***lpszArgs );
|
||||
int GetArgSepPosOffset ( wchar_t *lpszArgument );
|
||||
int GetArgumentID ( argumentspec *as , wchar_t *lpszArgument );
|
||||
int GetArgumentValue ( wchar_t **lpszCommandLineArgs , int *nArgIdx , int nNoCommandLineArgs , wchar_t *lpszValue , int nValueSize );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define HAS_ARGUMENT 1
|
||||
#define HAS_NO_ARGUMENT !HAS_ARGUMENT
|
||||
|
||||
typedef struct argument_t
|
||||
{
|
||||
int Id;
|
||||
wchar_t long_name[32];
|
||||
wchar_t short_name[8];
|
||||
BOOL Internal;
|
||||
} argument;
|
||||
|
||||
typedef struct argumentspec_t
|
||||
{
|
||||
argument *args;
|
||||
int arg_cnt;
|
||||
} argumentspec;
|
||||
|
||||
BOOL CALLBACK CommandHelpDlgProc ( HWND hwndDlg , UINT msg , WPARAM wParam , LPARAM lParam );
|
||||
int Win32CommandLine ( wchar_t ***lpszArgs );
|
||||
int GetArgSepPosOffset ( wchar_t *lpszArgument );
|
||||
int GetArgumentID ( argumentspec *as , wchar_t *lpszArgument );
|
||||
int GetArgumentValue ( wchar_t **lpszCommandLineArgs , int *nArgIdx , int nNoCommandLineArgs , wchar_t *lpszValue , int nValueSize );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,258 +1,258 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Combo.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Xml.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#define SIZEOF_MRU_LIST 20
|
||||
|
||||
void AddComboItem (HWND hComboBox, const wchar_t *lpszFileName, BOOL saveHistory)
|
||||
{
|
||||
LPARAM nIndex;
|
||||
|
||||
if (!saveHistory)
|
||||
{
|
||||
SendMessage (hComboBox, CB_RESETCONTENT, 0, 0);
|
||||
SetWindowText (hComboBox, lpszFileName);
|
||||
return;
|
||||
}
|
||||
|
||||
nIndex = SendMessage (hComboBox, CB_FINDSTRINGEXACT, (WPARAM) - 1, (LPARAM) & lpszFileName[0]);
|
||||
|
||||
if (nIndex == CB_ERR && *lpszFileName)
|
||||
{
|
||||
time_t lTime = time (NULL);
|
||||
nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) & lpszFileName[0]);
|
||||
if (nIndex != CB_ERR)
|
||||
SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) lTime);
|
||||
}
|
||||
|
||||
if (nIndex != CB_ERR && *lpszFileName)
|
||||
nIndex = SendMessage (hComboBox, CB_SETCURSEL, nIndex, 0);
|
||||
|
||||
if (*lpszFileName == 0)
|
||||
{
|
||||
SendMessage (hComboBox, CB_SETCURSEL, (WPARAM) - 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LPARAM MoveEditToCombo (HWND hComboBox, BOOL saveHistory)
|
||||
{
|
||||
wchar_t szTmp[TC_MAX_PATH] = {0};
|
||||
|
||||
if (!saveHistory)
|
||||
{
|
||||
GetWindowText (hComboBox, szTmp, ARRAYSIZE (szTmp));
|
||||
SendMessage (hComboBox, CB_RESETCONTENT, 0, 0);
|
||||
SetWindowText (hComboBox, szTmp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
GetWindowText (hComboBox, szTmp, ARRAYSIZE (szTmp));
|
||||
|
||||
if (wcslen (szTmp) > 0)
|
||||
{
|
||||
LPARAM nIndex = SendMessage (hComboBox, CB_FINDSTRINGEXACT, (WPARAM) - 1,
|
||||
(LPARAM) & szTmp[0]);
|
||||
if (nIndex == CB_ERR)
|
||||
{
|
||||
time_t lTime = time (NULL);
|
||||
nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) & szTmp[0]);
|
||||
if (nIndex != CB_ERR)
|
||||
SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (DWORD) lTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
time_t lTime = time (NULL);
|
||||
SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (DWORD) lTime);
|
||||
}
|
||||
|
||||
return nIndex;
|
||||
}
|
||||
|
||||
return SendMessage (hComboBox, CB_GETCURSEL, 0, 0);
|
||||
}
|
||||
|
||||
int GetOrderComboIdx (HWND hComboBox, int *nIdxList, int nElems)
|
||||
{
|
||||
int x = (int) SendMessage (hComboBox, CB_GETCOUNT, 0, 0);
|
||||
if (x != CB_ERR)
|
||||
{
|
||||
int i, nHighIdx = CB_ERR;
|
||||
time_t lHighTime = -1;
|
||||
|
||||
for (i = 0; i < x; i++)
|
||||
{
|
||||
time_t lTime = SendMessage (hComboBox, CB_GETITEMDATA, (WPARAM) i, 0);
|
||||
if (lTime > lHighTime)
|
||||
{
|
||||
int n;
|
||||
for (n = 0; n < nElems; n++)
|
||||
if (nIdxList[n] == i)
|
||||
break;
|
||||
if (n == nElems)
|
||||
{
|
||||
lHighTime = lTime;
|
||||
nHighIdx = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nHighIdx;
|
||||
}
|
||||
|
||||
return CB_ERR;
|
||||
}
|
||||
|
||||
LPARAM UpdateComboOrder (HWND hComboBox)
|
||||
{
|
||||
LPARAM nIndex;
|
||||
|
||||
nIndex = SendMessage (hComboBox, CB_GETCURSEL, 0, 0);
|
||||
|
||||
if (nIndex != CB_ERR)
|
||||
{
|
||||
time_t lTime = time (NULL);
|
||||
nIndex = SendMessage (hComboBox, CB_SETITEMDATA, (WPARAM) nIndex,
|
||||
(LPARAM) lTime);
|
||||
}
|
||||
|
||||
return nIndex;
|
||||
}
|
||||
|
||||
void LoadCombo (HWND hComboBox, BOOL bEnabled, BOOL bOnlyCheckModified, BOOL *pbModified)
|
||||
{
|
||||
DWORD size;
|
||||
char *history = LoadFile (GetConfigPath (TC_APPD_FILENAME_HISTORY), &size);
|
||||
char *xml = history;
|
||||
char volume[MAX_PATH];
|
||||
int i, nComboIdx[SIZEOF_MRU_LIST] = {0};
|
||||
int count = SendMessage (hComboBox, CB_GETCOUNT, 0, 0);
|
||||
|
||||
if (xml == NULL)
|
||||
{
|
||||
// No history XML file but history is enabled
|
||||
if (bEnabled && pbModified)
|
||||
*pbModified = TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!bEnabled && bOnlyCheckModified)
|
||||
{
|
||||
// History is disable but there is a history XML file
|
||||
if (pbModified)
|
||||
*pbModified = TRUE;
|
||||
free (history);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* combo list part:- get mru items */
|
||||
for (i = 0; i < SIZEOF_MRU_LIST; i++)
|
||||
nComboIdx[i] = GetOrderComboIdx (hComboBox, &nComboIdx[0], i);
|
||||
|
||||
i = 0;
|
||||
while (xml = XmlFindElement (xml, "volume"))
|
||||
{
|
||||
wchar_t szTmp[MAX_PATH] = { 0 };
|
||||
wchar_t wszVolume[MAX_PATH] = {0};
|
||||
|
||||
if (i < count)
|
||||
{
|
||||
if (SendMessage (hComboBox, CB_GETLBTEXTLEN, nComboIdx[i], 0) < ARRAYSIZE (szTmp))
|
||||
SendMessage (hComboBox, CB_GETLBTEXT, nComboIdx[i], (LPARAM) & szTmp[0]);
|
||||
}
|
||||
|
||||
XmlGetNodeText (xml, volume, sizeof (volume));
|
||||
if (0 == MultiByteToWideChar (CP_UTF8, 0, volume, -1, wszVolume, MAX_PATH))
|
||||
wszVolume [0] = 0;
|
||||
if (!bOnlyCheckModified)
|
||||
AddComboItem (hComboBox, wszVolume, TRUE);
|
||||
|
||||
if (pbModified && wcscmp (wszVolume, szTmp))
|
||||
*pbModified = TRUE;
|
||||
|
||||
xml++;
|
||||
i++;
|
||||
}
|
||||
|
||||
if (pbModified && (i != count))
|
||||
*pbModified = TRUE;
|
||||
|
||||
if (!bOnlyCheckModified)
|
||||
SendMessage (hComboBox, CB_SETCURSEL, 0, 0);
|
||||
|
||||
free (history);
|
||||
}
|
||||
|
||||
void DumpCombo (HWND hComboBox, int bClear)
|
||||
{
|
||||
FILE *f;
|
||||
int i, nComboIdx[SIZEOF_MRU_LIST] = {0};
|
||||
|
||||
if (bClear)
|
||||
{
|
||||
DeleteFile (GetConfigPath (TC_APPD_FILENAME_HISTORY));
|
||||
return;
|
||||
}
|
||||
|
||||
f = _wfopen (GetConfigPath (TC_APPD_FILENAME_HISTORY), L"w,ccs=UTF-8");
|
||||
if (f == NULL) return;
|
||||
|
||||
XmlWriteHeader (f);
|
||||
fputws (L"\n\t<history>", f);
|
||||
|
||||
/* combo list part:- get mru items */
|
||||
for (i = 0; i < SIZEOF_MRU_LIST; i++)
|
||||
nComboIdx[i] = GetOrderComboIdx (hComboBox, &nComboIdx[0], i);
|
||||
|
||||
/* combo list part:- write out mru items */
|
||||
for (i = 0; i < SIZEOF_MRU_LIST; i++)
|
||||
{
|
||||
wchar_t szTmp[MAX_PATH] = { 0 };
|
||||
|
||||
if (SendMessage (hComboBox, CB_GETLBTEXTLEN, nComboIdx[i], 0) < ARRAYSIZE (szTmp))
|
||||
SendMessage (hComboBox, CB_GETLBTEXT, nComboIdx[i], (LPARAM) & szTmp[0]);
|
||||
|
||||
if (szTmp[0] != 0)
|
||||
{
|
||||
wchar_t q[MAX_PATH * 2] = { 0 };
|
||||
XmlQuoteTextW (szTmp, q, ARRAYSIZE (q));
|
||||
|
||||
fwprintf (f, L"\n\t\t<volume>%s</volume>", q);
|
||||
}
|
||||
}
|
||||
|
||||
fputws (L"\n\t</history>", f);
|
||||
XmlWriteFooter (f);
|
||||
fclose (f);
|
||||
}
|
||||
|
||||
void ClearCombo (HWND hComboBox)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < SIZEOF_MRU_LIST; i++)
|
||||
{
|
||||
SendMessage (hComboBox, CB_DELETESTRING, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
int IsComboEmpty (HWND hComboBox)
|
||||
{
|
||||
return SendMessage (hComboBox, CB_GETCOUNT, 0, 0) < 1;
|
||||
}
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Combo.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Xml.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#define SIZEOF_MRU_LIST 20
|
||||
|
||||
void AddComboItem (HWND hComboBox, const wchar_t *lpszFileName, BOOL saveHistory)
|
||||
{
|
||||
LPARAM nIndex;
|
||||
|
||||
if (!saveHistory)
|
||||
{
|
||||
SendMessage (hComboBox, CB_RESETCONTENT, 0, 0);
|
||||
SetWindowText (hComboBox, lpszFileName);
|
||||
return;
|
||||
}
|
||||
|
||||
nIndex = SendMessage (hComboBox, CB_FINDSTRINGEXACT, (WPARAM) - 1, (LPARAM) & lpszFileName[0]);
|
||||
|
||||
if (nIndex == CB_ERR && *lpszFileName)
|
||||
{
|
||||
time_t lTime = time (NULL);
|
||||
nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) & lpszFileName[0]);
|
||||
if (nIndex != CB_ERR)
|
||||
SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) lTime);
|
||||
}
|
||||
|
||||
if (nIndex != CB_ERR && *lpszFileName)
|
||||
nIndex = SendMessage (hComboBox, CB_SETCURSEL, nIndex, 0);
|
||||
|
||||
if (*lpszFileName == 0)
|
||||
{
|
||||
SendMessage (hComboBox, CB_SETCURSEL, (WPARAM) - 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LPARAM MoveEditToCombo (HWND hComboBox, BOOL saveHistory)
|
||||
{
|
||||
wchar_t szTmp[TC_MAX_PATH] = {0};
|
||||
|
||||
if (!saveHistory)
|
||||
{
|
||||
GetWindowText (hComboBox, szTmp, ARRAYSIZE (szTmp));
|
||||
SendMessage (hComboBox, CB_RESETCONTENT, 0, 0);
|
||||
SetWindowText (hComboBox, szTmp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
GetWindowText (hComboBox, szTmp, ARRAYSIZE (szTmp));
|
||||
|
||||
if (wcslen (szTmp) > 0)
|
||||
{
|
||||
LPARAM nIndex = SendMessage (hComboBox, CB_FINDSTRINGEXACT, (WPARAM) - 1,
|
||||
(LPARAM) & szTmp[0]);
|
||||
if (nIndex == CB_ERR)
|
||||
{
|
||||
time_t lTime = time (NULL);
|
||||
nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) & szTmp[0]);
|
||||
if (nIndex != CB_ERR)
|
||||
SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (DWORD) lTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
time_t lTime = time (NULL);
|
||||
SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (DWORD) lTime);
|
||||
}
|
||||
|
||||
return nIndex;
|
||||
}
|
||||
|
||||
return SendMessage (hComboBox, CB_GETCURSEL, 0, 0);
|
||||
}
|
||||
|
||||
int GetOrderComboIdx (HWND hComboBox, int *nIdxList, int nElems)
|
||||
{
|
||||
int x = (int) SendMessage (hComboBox, CB_GETCOUNT, 0, 0);
|
||||
if (x != CB_ERR)
|
||||
{
|
||||
int i, nHighIdx = CB_ERR;
|
||||
time_t lHighTime = -1;
|
||||
|
||||
for (i = 0; i < x; i++)
|
||||
{
|
||||
time_t lTime = SendMessage (hComboBox, CB_GETITEMDATA, (WPARAM) i, 0);
|
||||
if (lTime > lHighTime)
|
||||
{
|
||||
int n;
|
||||
for (n = 0; n < nElems; n++)
|
||||
if (nIdxList[n] == i)
|
||||
break;
|
||||
if (n == nElems)
|
||||
{
|
||||
lHighTime = lTime;
|
||||
nHighIdx = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nHighIdx;
|
||||
}
|
||||
|
||||
return CB_ERR;
|
||||
}
|
||||
|
||||
LPARAM UpdateComboOrder (HWND hComboBox)
|
||||
{
|
||||
LPARAM nIndex;
|
||||
|
||||
nIndex = SendMessage (hComboBox, CB_GETCURSEL, 0, 0);
|
||||
|
||||
if (nIndex != CB_ERR)
|
||||
{
|
||||
time_t lTime = time (NULL);
|
||||
nIndex = SendMessage (hComboBox, CB_SETITEMDATA, (WPARAM) nIndex,
|
||||
(LPARAM) lTime);
|
||||
}
|
||||
|
||||
return nIndex;
|
||||
}
|
||||
|
||||
void LoadCombo (HWND hComboBox, BOOL bEnabled, BOOL bOnlyCheckModified, BOOL *pbModified)
|
||||
{
|
||||
DWORD size;
|
||||
char *history = LoadFile (GetConfigPath (TC_APPD_FILENAME_HISTORY), &size);
|
||||
char *xml = history;
|
||||
char volume[MAX_PATH];
|
||||
int i, nComboIdx[SIZEOF_MRU_LIST] = {0};
|
||||
int count = SendMessage (hComboBox, CB_GETCOUNT, 0, 0);
|
||||
|
||||
if (xml == NULL)
|
||||
{
|
||||
// No history XML file but history is enabled
|
||||
if (bEnabled && pbModified)
|
||||
*pbModified = TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!bEnabled && bOnlyCheckModified)
|
||||
{
|
||||
// History is disable but there is a history XML file
|
||||
if (pbModified)
|
||||
*pbModified = TRUE;
|
||||
free (history);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* combo list part:- get mru items */
|
||||
for (i = 0; i < SIZEOF_MRU_LIST; i++)
|
||||
nComboIdx[i] = GetOrderComboIdx (hComboBox, &nComboIdx[0], i);
|
||||
|
||||
i = 0;
|
||||
while (xml = XmlFindElement (xml, "volume"))
|
||||
{
|
||||
wchar_t szTmp[MAX_PATH] = { 0 };
|
||||
wchar_t wszVolume[MAX_PATH] = {0};
|
||||
|
||||
if (i < count)
|
||||
{
|
||||
if (SendMessage (hComboBox, CB_GETLBTEXTLEN, nComboIdx[i], 0) < ARRAYSIZE (szTmp))
|
||||
SendMessage (hComboBox, CB_GETLBTEXT, nComboIdx[i], (LPARAM) & szTmp[0]);
|
||||
}
|
||||
|
||||
XmlGetNodeText (xml, volume, sizeof (volume));
|
||||
if (0 == MultiByteToWideChar (CP_UTF8, 0, volume, -1, wszVolume, MAX_PATH))
|
||||
wszVolume [0] = 0;
|
||||
if (!bOnlyCheckModified)
|
||||
AddComboItem (hComboBox, wszVolume, TRUE);
|
||||
|
||||
if (pbModified && wcscmp (wszVolume, szTmp))
|
||||
*pbModified = TRUE;
|
||||
|
||||
xml++;
|
||||
i++;
|
||||
}
|
||||
|
||||
if (pbModified && (i != count))
|
||||
*pbModified = TRUE;
|
||||
|
||||
if (!bOnlyCheckModified)
|
||||
SendMessage (hComboBox, CB_SETCURSEL, 0, 0);
|
||||
|
||||
free (history);
|
||||
}
|
||||
|
||||
void DumpCombo (HWND hComboBox, int bClear)
|
||||
{
|
||||
FILE *f;
|
||||
int i, nComboIdx[SIZEOF_MRU_LIST] = {0};
|
||||
|
||||
if (bClear)
|
||||
{
|
||||
DeleteFile (GetConfigPath (TC_APPD_FILENAME_HISTORY));
|
||||
return;
|
||||
}
|
||||
|
||||
f = _wfopen (GetConfigPath (TC_APPD_FILENAME_HISTORY), L"w,ccs=UTF-8");
|
||||
if (f == NULL) return;
|
||||
|
||||
XmlWriteHeader (f);
|
||||
fputws (L"\n\t<history>", f);
|
||||
|
||||
/* combo list part:- get mru items */
|
||||
for (i = 0; i < SIZEOF_MRU_LIST; i++)
|
||||
nComboIdx[i] = GetOrderComboIdx (hComboBox, &nComboIdx[0], i);
|
||||
|
||||
/* combo list part:- write out mru items */
|
||||
for (i = 0; i < SIZEOF_MRU_LIST; i++)
|
||||
{
|
||||
wchar_t szTmp[MAX_PATH] = { 0 };
|
||||
|
||||
if (SendMessage (hComboBox, CB_GETLBTEXTLEN, nComboIdx[i], 0) < ARRAYSIZE (szTmp))
|
||||
SendMessage (hComboBox, CB_GETLBTEXT, nComboIdx[i], (LPARAM) & szTmp[0]);
|
||||
|
||||
if (szTmp[0] != 0)
|
||||
{
|
||||
wchar_t q[MAX_PATH * 2] = { 0 };
|
||||
XmlQuoteTextW (szTmp, q, ARRAYSIZE (q));
|
||||
|
||||
fwprintf (f, L"\n\t\t<volume>%s</volume>", q);
|
||||
}
|
||||
}
|
||||
|
||||
fputws (L"\n\t</history>", f);
|
||||
XmlWriteFooter (f);
|
||||
fclose (f);
|
||||
}
|
||||
|
||||
void ClearCombo (HWND hComboBox)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < SIZEOF_MRU_LIST; i++)
|
||||
{
|
||||
SendMessage (hComboBox, CB_DELETESTRING, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
int IsComboEmpty (HWND hComboBox)
|
||||
{
|
||||
return SendMessage (hComboBox, CB_GETCOUNT, 0, 0) < 1;
|
||||
}
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void AddComboItem (HWND hComboBox, const wchar_t *lpszFileName, BOOL saveHistory);
|
||||
LPARAM MoveEditToCombo (HWND hComboBox, BOOL saveHistory);
|
||||
int GetOrderComboIdx ( HWND hComboBox , int *nIdxList , int nElems );
|
||||
LPARAM UpdateComboOrder ( HWND hComboBox );
|
||||
void LoadCombo (HWND hComboBox, BOOL bEnabled, BOOL bOnlyCheckModified, BOOL *pbModified);
|
||||
void DumpCombo ( HWND hComboBox , int bClear );
|
||||
void ClearCombo (HWND hComboBox);
|
||||
int IsComboEmpty (HWND hComboBox);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void AddComboItem (HWND hComboBox, const wchar_t *lpszFileName, BOOL saveHistory);
|
||||
LPARAM MoveEditToCombo (HWND hComboBox, BOOL saveHistory);
|
||||
int GetOrderComboIdx ( HWND hComboBox , int *nIdxList , int nElems );
|
||||
LPARAM UpdateComboOrder ( HWND hComboBox );
|
||||
void LoadCombo (HWND hComboBox, BOOL bEnabled, BOOL bOnlyCheckModified, BOOL *pbModified);
|
||||
void DumpCombo ( HWND hComboBox , int bClear );
|
||||
void ClearCombo (HWND hComboBox);
|
||||
int IsComboEmpty (HWND hComboBox);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,95 +1,95 @@
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
#include "Crypto.h"
|
||||
|
||||
#define MIN_MOUNTED_VOLUME_DRIVE_NUMBER ('A' - 'A')
|
||||
#define MAX_MOUNTED_VOLUME_DRIVE_NUMBER ('Z' - 'A')
|
||||
|
||||
#define MAX_HOST_DRIVE_NUMBER 64
|
||||
#define MAX_HOST_PARTITION_NUMBER 32
|
||||
|
||||
#define VOLUME_ID_SIZE SHA256_DIGESTSIZE
|
||||
|
||||
typedef enum
|
||||
{
|
||||
// IMPORTANT: If you add a new item here, update IsOSVersionAtLeast().
|
||||
|
||||
WIN_UNKNOWN = 0,
|
||||
WIN_31,
|
||||
WIN_95,
|
||||
WIN_98,
|
||||
WIN_ME,
|
||||
WIN_NT3,
|
||||
WIN_NT4,
|
||||
WIN_2000,
|
||||
WIN_XP,
|
||||
WIN_XP64,
|
||||
WIN_SERVER_2003,
|
||||
WIN_VISTA,
|
||||
WIN_SERVER_2008,
|
||||
WIN_7,
|
||||
WIN_SERVER_2008_R2,
|
||||
WIN_8,
|
||||
WIN_SERVER_2012,
|
||||
WIN_8_1,
|
||||
WIN_SERVER_2012_R2,
|
||||
WIN_10,
|
||||
WIN_SERVER_2016
|
||||
} OSVersionEnum;
|
||||
|
||||
/* Volume types */
|
||||
enum
|
||||
{
|
||||
TC_VOLUME_TYPE_NORMAL = 0,
|
||||
TC_VOLUME_TYPE_HIDDEN,
|
||||
TC_VOLUME_TYPE_COUNT
|
||||
};
|
||||
|
||||
/* Prop volume types */
|
||||
enum
|
||||
{
|
||||
PROP_VOL_TYPE_NORMAL = 0,
|
||||
PROP_VOL_TYPE_HIDDEN,
|
||||
PROP_VOL_TYPE_OUTER, /* Outer/normal (hidden volume protected) */
|
||||
PROP_VOL_TYPE_OUTER_VOL_WRITE_PREVENTED, /* Outer/normal (hidden volume protected AND write already prevented) */
|
||||
PROP_VOL_TYPE_SYSTEM,
|
||||
PROP_NBR_VOLUME_TYPES
|
||||
};
|
||||
|
||||
/* Hidden volume protection status */
|
||||
enum
|
||||
{
|
||||
HIDVOL_PROT_STATUS_NONE = 0,
|
||||
HIDVOL_PROT_STATUS_ACTIVE,
|
||||
HIDVOL_PROT_STATUS_ACTION_TAKEN /* Active + action taken (write operation has already been denied) */
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BOOL ReadOnly;
|
||||
BOOL Removable;
|
||||
BOOL ProtectHiddenVolume;
|
||||
BOOL PreserveTimestamp;
|
||||
BOOL PartitionInInactiveSysEncScope; /* If TRUE, we are to attempt to mount a partition located on an encrypted system drive without pre-boot authentication. */
|
||||
Password ProtectedHidVolPassword; /* Password of hidden volume to protect against overwriting */
|
||||
BOOL UseBackupHeader;
|
||||
BOOL RecoveryMode;
|
||||
int ProtectedHidVolPkcs5Prf;
|
||||
int ProtectedHidVolPim;
|
||||
wchar_t Label[33]; /* maximum label length is 32 for NTFS and 11 for FAT32 */
|
||||
} MountOptions;
|
||||
|
||||
#endif
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
#include "Crypto.h"
|
||||
|
||||
#define MIN_MOUNTED_VOLUME_DRIVE_NUMBER ('A' - 'A')
|
||||
#define MAX_MOUNTED_VOLUME_DRIVE_NUMBER ('Z' - 'A')
|
||||
|
||||
#define MAX_HOST_DRIVE_NUMBER 64
|
||||
#define MAX_HOST_PARTITION_NUMBER 32
|
||||
|
||||
#define VOLUME_ID_SIZE SHA256_DIGESTSIZE
|
||||
|
||||
typedef enum
|
||||
{
|
||||
// IMPORTANT: If you add a new item here, update IsOSVersionAtLeast().
|
||||
|
||||
WIN_UNKNOWN = 0,
|
||||
WIN_31,
|
||||
WIN_95,
|
||||
WIN_98,
|
||||
WIN_ME,
|
||||
WIN_NT3,
|
||||
WIN_NT4,
|
||||
WIN_2000,
|
||||
WIN_XP,
|
||||
WIN_XP64,
|
||||
WIN_SERVER_2003,
|
||||
WIN_VISTA,
|
||||
WIN_SERVER_2008,
|
||||
WIN_7,
|
||||
WIN_SERVER_2008_R2,
|
||||
WIN_8,
|
||||
WIN_SERVER_2012,
|
||||
WIN_8_1,
|
||||
WIN_SERVER_2012_R2,
|
||||
WIN_10,
|
||||
WIN_SERVER_2016
|
||||
} OSVersionEnum;
|
||||
|
||||
/* Volume types */
|
||||
enum
|
||||
{
|
||||
TC_VOLUME_TYPE_NORMAL = 0,
|
||||
TC_VOLUME_TYPE_HIDDEN,
|
||||
TC_VOLUME_TYPE_COUNT
|
||||
};
|
||||
|
||||
/* Prop volume types */
|
||||
enum
|
||||
{
|
||||
PROP_VOL_TYPE_NORMAL = 0,
|
||||
PROP_VOL_TYPE_HIDDEN,
|
||||
PROP_VOL_TYPE_OUTER, /* Outer/normal (hidden volume protected) */
|
||||
PROP_VOL_TYPE_OUTER_VOL_WRITE_PREVENTED, /* Outer/normal (hidden volume protected AND write already prevented) */
|
||||
PROP_VOL_TYPE_SYSTEM,
|
||||
PROP_NBR_VOLUME_TYPES
|
||||
};
|
||||
|
||||
/* Hidden volume protection status */
|
||||
enum
|
||||
{
|
||||
HIDVOL_PROT_STATUS_NONE = 0,
|
||||
HIDVOL_PROT_STATUS_ACTIVE,
|
||||
HIDVOL_PROT_STATUS_ACTION_TAKEN /* Active + action taken (write operation has already been denied) */
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BOOL ReadOnly;
|
||||
BOOL Removable;
|
||||
BOOL ProtectHiddenVolume;
|
||||
BOOL PreserveTimestamp;
|
||||
BOOL PartitionInInactiveSysEncScope; /* If TRUE, we are to attempt to mount a partition located on an encrypted system drive without pre-boot authentication. */
|
||||
Password ProtectedHidVolPassword; /* Password of hidden volume to protect against overwriting */
|
||||
BOOL UseBackupHeader;
|
||||
BOOL RecoveryMode;
|
||||
int ProtectedHidVolPkcs5Prf;
|
||||
int ProtectedHidVolPim;
|
||||
wchar_t Label[33]; /* maximum label length is 32 for NTFS and 11 for FAT32 */
|
||||
} MountOptions;
|
||||
|
||||
#endif
|
||||
|
||||
1206
src/Common/Common.rc
1206
src/Common/Common.rc
File diff suppressed because it is too large
Load Diff
270
src/Common/Crc.c
270
src/Common/Crc.c
@@ -1,135 +1,135 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Crc.h"
|
||||
#include "Common/Endian.h"
|
||||
|
||||
#ifndef TC_MINIMIZE_CODE_SIZE
|
||||
|
||||
/* CRC polynomial 0x04c11db7 */
|
||||
unsigned __int32 crc_32_tab[]=
|
||||
{
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
|
||||
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
|
||||
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
|
||||
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
|
||||
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
|
||||
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
|
||||
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
|
||||
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
|
||||
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
|
||||
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
|
||||
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
|
||||
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
|
||||
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
|
||||
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
|
||||
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
||||
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
|
||||
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
|
||||
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
|
||||
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
|
||||
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
|
||||
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
|
||||
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
|
||||
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
|
||||
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
|
||||
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
|
||||
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
|
||||
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
|
||||
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
|
||||
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
|
||||
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
||||
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
|
||||
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
|
||||
};
|
||||
|
||||
unsigned __int32 GetCrc32 (unsigned char *data, int length)
|
||||
{
|
||||
unsigned __int32 CRC = 0xffffffff;
|
||||
|
||||
while (length--)
|
||||
{
|
||||
CRC = (CRC >> 8) ^ crc_32_tab[ (CRC ^ *data++) & 0xFF ];
|
||||
}
|
||||
|
||||
return CRC ^ 0xffffffff;
|
||||
}
|
||||
|
||||
unsigned __int32 crc32int (unsigned __int32 *data)
|
||||
{
|
||||
unsigned char *d = (unsigned char *) data;
|
||||
unsigned __int32 CRC = 0xffffffff;
|
||||
|
||||
CRC = (CRC >> 8) ^ crc_32_tab[ (CRC ^ *d++) & 0xFF ];
|
||||
CRC = (CRC >> 8) ^ crc_32_tab[ (CRC ^ *d++) & 0xFF ];
|
||||
CRC = (CRC >> 8) ^ crc_32_tab[ (CRC ^ *d++) & 0xFF ];
|
||||
return (CRC >> 8) ^ crc_32_tab[ (CRC ^ *d) & 0xFF ] ^ 0xffffffff;
|
||||
}
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
# define CRC_SELFTEST 0x6fcf9e13
|
||||
#else
|
||||
# define CRC_SELFTEST 0xca87914d
|
||||
#endif
|
||||
|
||||
BOOL crc32_selftests (void)
|
||||
{
|
||||
int i;
|
||||
unsigned __int32 crc = 0xffffffff;
|
||||
BOOL bSuccess = FALSE;
|
||||
|
||||
for (i = 0; i < (int)sizeof(crc_32_tab); i++)
|
||||
crc = UPDC32 (((unsigned char *) crc_32_tab)[i], crc);
|
||||
|
||||
bSuccess = CRC_SELFTEST == (crc ^ 0xffffffff);
|
||||
|
||||
bSuccess &= GetCrc32 ((unsigned char *)crc_32_tab, sizeof crc_32_tab) == CRC_SELFTEST;
|
||||
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
#else // TC_MINIMIZE_CODE_SIZE
|
||||
|
||||
unsigned __int32 GetCrc32 (unsigned char *data, int length)
|
||||
{
|
||||
unsigned __int32 r = 0xFFFFFFFFUL;
|
||||
int i, b;
|
||||
|
||||
for (i = 0; i < length; ++i)
|
||||
{
|
||||
r ^= data[i];
|
||||
for (b = 0; b < 8; ++b)
|
||||
{
|
||||
if ((unsigned __int8) r & 1)
|
||||
r = (r >> 1) ^ 0xEDB88320UL;
|
||||
else
|
||||
r >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
return r ^ 0xFFFFFFFFUL;
|
||||
}
|
||||
|
||||
BOOL crc32_selftests ()
|
||||
{
|
||||
unsigned __int8 testData[32];
|
||||
unsigned __int8 i;
|
||||
|
||||
for (i = 0; i < sizeof (testData); ++i)
|
||||
testData[i] = i;
|
||||
|
||||
return GetCrc32 (testData, sizeof (testData)) == 0x91267E8AUL;
|
||||
}
|
||||
|
||||
#endif // TC_MINIMIZE_CODE_SIZE
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Crc.h"
|
||||
#include "Common/Endian.h"
|
||||
|
||||
#ifndef TC_MINIMIZE_CODE_SIZE
|
||||
|
||||
/* CRC polynomial 0x04c11db7 */
|
||||
unsigned __int32 crc_32_tab[]=
|
||||
{
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
|
||||
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
|
||||
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
|
||||
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
|
||||
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
|
||||
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
|
||||
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
|
||||
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
|
||||
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
|
||||
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
|
||||
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
|
||||
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
|
||||
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
|
||||
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
|
||||
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
||||
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
|
||||
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
|
||||
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
|
||||
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
|
||||
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
|
||||
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
|
||||
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
|
||||
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
|
||||
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
|
||||
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
|
||||
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
|
||||
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
|
||||
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
|
||||
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
|
||||
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
||||
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
|
||||
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
|
||||
};
|
||||
|
||||
unsigned __int32 GetCrc32 (unsigned char *data, int length)
|
||||
{
|
||||
unsigned __int32 CRC = 0xffffffff;
|
||||
|
||||
while (length--)
|
||||
{
|
||||
CRC = (CRC >> 8) ^ crc_32_tab[ (CRC ^ *data++) & 0xFF ];
|
||||
}
|
||||
|
||||
return CRC ^ 0xffffffff;
|
||||
}
|
||||
|
||||
unsigned __int32 crc32int (unsigned __int32 *data)
|
||||
{
|
||||
unsigned char *d = (unsigned char *) data;
|
||||
unsigned __int32 CRC = 0xffffffff;
|
||||
|
||||
CRC = (CRC >> 8) ^ crc_32_tab[ (CRC ^ *d++) & 0xFF ];
|
||||
CRC = (CRC >> 8) ^ crc_32_tab[ (CRC ^ *d++) & 0xFF ];
|
||||
CRC = (CRC >> 8) ^ crc_32_tab[ (CRC ^ *d++) & 0xFF ];
|
||||
return (CRC >> 8) ^ crc_32_tab[ (CRC ^ *d) & 0xFF ] ^ 0xffffffff;
|
||||
}
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
# define CRC_SELFTEST 0x6fcf9e13
|
||||
#else
|
||||
# define CRC_SELFTEST 0xca87914d
|
||||
#endif
|
||||
|
||||
BOOL crc32_selftests (void)
|
||||
{
|
||||
int i;
|
||||
unsigned __int32 crc = 0xffffffff;
|
||||
BOOL bSuccess = FALSE;
|
||||
|
||||
for (i = 0; i < (int)sizeof(crc_32_tab); i++)
|
||||
crc = UPDC32 (((unsigned char *) crc_32_tab)[i], crc);
|
||||
|
||||
bSuccess = CRC_SELFTEST == (crc ^ 0xffffffff);
|
||||
|
||||
bSuccess &= GetCrc32 ((unsigned char *)crc_32_tab, sizeof crc_32_tab) == CRC_SELFTEST;
|
||||
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
#else // TC_MINIMIZE_CODE_SIZE
|
||||
|
||||
unsigned __int32 GetCrc32 (unsigned char *data, int length)
|
||||
{
|
||||
unsigned __int32 r = 0xFFFFFFFFUL;
|
||||
int i, b;
|
||||
|
||||
for (i = 0; i < length; ++i)
|
||||
{
|
||||
r ^= data[i];
|
||||
for (b = 0; b < 8; ++b)
|
||||
{
|
||||
if ((unsigned __int8) r & 1)
|
||||
r = (r >> 1) ^ 0xEDB88320UL;
|
||||
else
|
||||
r >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
return r ^ 0xFFFFFFFFUL;
|
||||
}
|
||||
|
||||
BOOL crc32_selftests ()
|
||||
{
|
||||
unsigned __int8 testData[32];
|
||||
unsigned __int8 i;
|
||||
|
||||
for (i = 0; i < sizeof (testData); ++i)
|
||||
testData[i] = i;
|
||||
|
||||
return GetCrc32 (testData, sizeof (testData)) == 0x91267E8AUL;
|
||||
}
|
||||
|
||||
#endif // TC_MINIMIZE_CODE_SIZE
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#ifndef TC_HEADER_CRC
|
||||
#define TC_HEADER_CRC
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define UPDC32(octet, crc)\
|
||||
(unsigned __int32)((crc_32_tab[(((unsigned __int32)(crc)) ^ ((unsigned char)(octet))) & 0xff] ^ (((unsigned __int32)(crc)) >> 8)))
|
||||
|
||||
unsigned __int32 GetCrc32 (unsigned char *data, int length);
|
||||
unsigned __int32 crc32int (unsigned __int32 *data);
|
||||
BOOL crc32_selftests (void);
|
||||
|
||||
extern unsigned __int32 crc_32_tab[];
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_CRC
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#ifndef TC_HEADER_CRC
|
||||
#define TC_HEADER_CRC
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define UPDC32(octet, crc)\
|
||||
(unsigned __int32)((crc_32_tab[(((unsigned __int32)(crc)) ^ ((unsigned char)(octet))) & 0xff] ^ (((unsigned __int32)(crc)) >> 8)))
|
||||
|
||||
unsigned __int32 GetCrc32 (unsigned char *data, int length);
|
||||
unsigned __int32 crc32int (unsigned __int32 *data);
|
||||
BOOL crc32_selftests (void);
|
||||
|
||||
extern unsigned __int32 crc_32_tab[];
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_CRC
|
||||
|
||||
2116
src/Common/Crypto.c
2116
src/Common/Crypto.c
File diff suppressed because it is too large
Load Diff
@@ -1,363 +1,363 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
/* Update the following when adding a new cipher or EA:
|
||||
|
||||
Crypto.h:
|
||||
ID #define
|
||||
MAX_EXPANDED_KEY #define
|
||||
|
||||
Crypto.c:
|
||||
Ciphers[]
|
||||
EncryptionAlgorithms[]
|
||||
CipherInit()
|
||||
EncipherBlock()
|
||||
DecipherBlock()
|
||||
|
||||
*/
|
||||
|
||||
#ifndef CRYPTO_H
|
||||
#define CRYPTO_H
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Encryption data unit size, which may differ from the sector size and must always be 512
|
||||
#define ENCRYPTION_DATA_UNIT_SIZE 512
|
||||
|
||||
// Size of the salt (in bytes)
|
||||
#define PKCS5_SALT_SIZE 64
|
||||
|
||||
// Size of the volume header area containing concatenated master key(s) and secondary key(s) (XTS mode)
|
||||
#define MASTER_KEYDATA_SIZE 256
|
||||
|
||||
// The first PRF to try when mounting
|
||||
#define FIRST_PRF_ID 1
|
||||
|
||||
// Hash algorithms (pseudorandom functions).
|
||||
enum
|
||||
{
|
||||
SHA512 = FIRST_PRF_ID,
|
||||
WHIRLPOOL,
|
||||
SHA256,
|
||||
RIPEMD160,
|
||||
HASH_ENUM_END_ID
|
||||
};
|
||||
|
||||
// The last PRF to try when mounting and also the number of implemented PRFs
|
||||
#define LAST_PRF_ID (HASH_ENUM_END_ID - 1)
|
||||
|
||||
#define RIPEMD160_BLOCKSIZE 64
|
||||
#define RIPEMD160_DIGESTSIZE 20
|
||||
|
||||
#define SHA256_BLOCKSIZE 64
|
||||
#define SHA256_DIGESTSIZE 32
|
||||
|
||||
#define SHA512_BLOCKSIZE 128
|
||||
#define SHA512_DIGESTSIZE 64
|
||||
|
||||
#define WHIRLPOOL_BLOCKSIZE 64
|
||||
#define WHIRLPOOL_DIGESTSIZE 64
|
||||
|
||||
#define MAX_DIGESTSIZE WHIRLPOOL_DIGESTSIZE
|
||||
|
||||
#define DEFAULT_HASH_ALGORITHM FIRST_PRF_ID
|
||||
#define DEFAULT_HASH_ALGORITHM_BOOT SHA256
|
||||
|
||||
// The mode of operation used for newly created volumes and first to try when mounting
|
||||
#define FIRST_MODE_OF_OPERATION_ID 1
|
||||
|
||||
// Modes of operation
|
||||
enum
|
||||
{
|
||||
/* If you add/remove a mode, update the following: GetMaxPkcs5OutSize(), EAInitMode() */
|
||||
|
||||
XTS = FIRST_MODE_OF_OPERATION_ID,
|
||||
MODE_ENUM_END_ID
|
||||
};
|
||||
|
||||
|
||||
// The last mode of operation to try when mounting and also the number of implemented modes
|
||||
#define LAST_MODE_OF_OPERATION (MODE_ENUM_END_ID - 1)
|
||||
|
||||
// Ciphertext/plaintext block size for XTS mode (in bytes)
|
||||
#define BYTES_PER_XTS_BLOCK 16
|
||||
|
||||
// Number of ciphertext/plaintext blocks per XTS data unit
|
||||
#define BLOCKS_PER_XTS_DATA_UNIT (ENCRYPTION_DATA_UNIT_SIZE / BYTES_PER_XTS_BLOCK)
|
||||
|
||||
|
||||
// Cipher IDs
|
||||
enum
|
||||
{
|
||||
NONE = 0,
|
||||
AES,
|
||||
SERPENT,
|
||||
TWOFISH
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int Id; // Cipher ID
|
||||
#ifdef TC_WINDOWS_BOOT
|
||||
char *Name; // Name
|
||||
#else
|
||||
wchar_t *Name; // Name
|
||||
#endif
|
||||
int BlockSize; // Block size (bytes)
|
||||
int KeySize; // Key size (bytes)
|
||||
int KeyScheduleSize; // Scheduled key size (bytes)
|
||||
} Cipher;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int Ciphers[4]; // Null terminated array of ciphers used by encryption algorithm
|
||||
int Modes[LAST_MODE_OF_OPERATION + 1]; // Null terminated array of modes of operation
|
||||
int FormatEnabled;
|
||||
} EncryptionAlgorithm;
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
typedef struct
|
||||
{
|
||||
int Id; // Hash ID
|
||||
wchar_t *Name; // Name
|
||||
BOOL Deprecated;
|
||||
BOOL SystemEncryption; // Available for system encryption
|
||||
} Hash;
|
||||
#endif
|
||||
|
||||
// Maxium length of scheduled key
|
||||
#if !defined (TC_WINDOWS_BOOT) || defined (TC_WINDOWS_BOOT_AES)
|
||||
# define AES_KS (sizeof(aes_encrypt_ctx) + sizeof(aes_decrypt_ctx))
|
||||
#else
|
||||
# define AES_KS (sizeof(aes_context))
|
||||
#endif
|
||||
#define SERPENT_KS (140 * 4)
|
||||
|
||||
#ifdef TC_WINDOWS_BOOT_SINGLE_CIPHER_MODE
|
||||
|
||||
# ifdef TC_WINDOWS_BOOT_AES
|
||||
# define MAX_EXPANDED_KEY AES_KS
|
||||
# elif defined (TC_WINDOWS_BOOT_SERPENT)
|
||||
# define MAX_EXPANDED_KEY SERPENT_KS
|
||||
# elif defined (TC_WINDOWS_BOOT_TWOFISH)
|
||||
# define MAX_EXPANDED_KEY TWOFISH_KS
|
||||
# endif
|
||||
|
||||
#else
|
||||
|
||||
#define MAX_EXPANDED_KEY (AES_KS + SERPENT_KS + TWOFISH_KS)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
# define PRAND_DISK_WIPE_PASSES 3
|
||||
#else
|
||||
# define PRAND_DISK_WIPE_PASSES 256
|
||||
#endif
|
||||
|
||||
/* specific value for volume header wipe used only when drive is fully wiped. */
|
||||
#define PRAND_HEADER_WIPE_PASSES 3
|
||||
|
||||
#if !defined (TC_WINDOWS_BOOT) || defined (TC_WINDOWS_BOOT_AES)
|
||||
# include "Aes.h"
|
||||
#else
|
||||
# include "AesSmall.h"
|
||||
#endif
|
||||
|
||||
#include "Aes_hw_cpu.h"
|
||||
#include "Serpent.h"
|
||||
#include "Twofish.h"
|
||||
|
||||
#include "Rmd160.h"
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
# include "Sha2.h"
|
||||
# include "Whirlpool.h"
|
||||
#endif
|
||||
|
||||
#include "GfMul.h"
|
||||
#include "Password.h"
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
|
||||
#include "config.h"
|
||||
|
||||
typedef struct keyInfo_t
|
||||
{
|
||||
int noIterations; /* Number of times to iterate (PKCS-5) */
|
||||
int keyLength; /* Length of the key */
|
||||
uint64 dummy; /* Dummy field to ensure 16-byte alignment of this structure */
|
||||
__int8 salt[PKCS5_SALT_SIZE]; /* PKCS-5 salt */
|
||||
__int8 master_keydata[MASTER_KEYDATA_SIZE]; /* Concatenated master primary and secondary key(s) (XTS mode). For LRW (deprecated/legacy), it contains the tweak key before the master key(s). For CBC (deprecated/legacy), it contains the IV seed before the master key(s). */
|
||||
CRYPTOPP_ALIGN_DATA(16) __int8 userKey[MAX_PASSWORD]; /* Password (to which keyfiles may have been applied). WITHOUT +1 for the null terminator. */
|
||||
} KEY_INFO, *PKEY_INFO;
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct CRYPTO_INFO_t
|
||||
{
|
||||
int ea; /* Encryption algorithm ID */
|
||||
int mode; /* Mode of operation (e.g., XTS) */
|
||||
int pkcs5; /* PRF algorithm */
|
||||
|
||||
unsigned __int8 ks[MAX_EXPANDED_KEY]; /* Primary key schedule (if it is a cascade, it conatins multiple concatenated keys) */
|
||||
unsigned __int8 ks2[MAX_EXPANDED_KEY]; /* Secondary key schedule (if cascade, multiple concatenated) for XTS mode. */
|
||||
|
||||
BOOL hiddenVolume; // Indicates whether the volume is mounted/mountable as hidden volume
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
uint16 HeaderVersion;
|
||||
|
||||
GfCtx gf_ctx;
|
||||
|
||||
unsigned __int8 master_keydata[MASTER_KEYDATA_SIZE]; /* This holds the volume header area containing concatenated master key(s) and secondary key(s) (XTS mode). For LRW (deprecated/legacy), it contains the tweak key before the master key(s). For CBC (deprecated/legacy), it contains the IV seed before the master key(s). */
|
||||
unsigned __int8 k2[MASTER_KEYDATA_SIZE]; /* For XTS, this contains the secondary key (if cascade, multiple concatenated). For LRW (deprecated/legacy), it contains the tweak key. For CBC (deprecated/legacy), it contains the IV seed. */
|
||||
unsigned __int8 salt[PKCS5_SALT_SIZE];
|
||||
int noIterations;
|
||||
BOOL bTrueCryptMode;
|
||||
int volumePim;
|
||||
|
||||
uint64 volume_creation_time; // Legacy
|
||||
uint64 header_creation_time; // Legacy
|
||||
|
||||
BOOL bProtectHiddenVolume; // Indicates whether the volume contains a hidden volume to be protected against overwriting
|
||||
BOOL bHiddenVolProtectionAction; // TRUE if a write operation has been denied by the driver in order to prevent the hidden volume from being overwritten (set to FALSE upon volume mount).
|
||||
|
||||
uint64 volDataAreaOffset; // Absolute position, in bytes, of the first data sector of the volume.
|
||||
|
||||
uint64 hiddenVolumeSize; // Size of the hidden volume excluding the header (in bytes). Set to 0 for standard volumes.
|
||||
uint64 hiddenVolumeOffset; // Absolute position, in bytes, of the first hidden volume data sector within the host volume (provided that there is a hidden volume within). This must be set for all hidden volumes; in case of a normal volume, this variable is only used when protecting a hidden volume within it.
|
||||
uint64 hiddenVolumeProtectedSize;
|
||||
|
||||
BOOL bPartitionInInactiveSysEncScope; // If TRUE, the volume is a partition located on an encrypted system drive and mounted without pre-boot authentication.
|
||||
|
||||
UINT64_STRUCT FirstDataUnitNo; // First data unit number of the volume. This is 0 for file-hosted and non-system partition-hosted volumes. For partitions within key scope of system encryption this reflects real physical offset within the device (this is used e.g. when such a partition is mounted as a regular volume without pre-boot authentication).
|
||||
|
||||
uint16 RequiredProgramVersion;
|
||||
BOOL LegacyVolume;
|
||||
|
||||
uint32 SectorSize;
|
||||
|
||||
#endif // !TC_WINDOWS_BOOT
|
||||
|
||||
UINT64_STRUCT VolumeSize;
|
||||
|
||||
UINT64_STRUCT EncryptedAreaStart;
|
||||
UINT64_STRUCT EncryptedAreaLength;
|
||||
|
||||
uint32 HeaderFlags;
|
||||
|
||||
} CRYPTO_INFO, *PCRYPTO_INFO;
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#pragma pack (push)
|
||||
#pragma pack(1)
|
||||
|
||||
typedef struct BOOT_CRYPTO_HEADER_t
|
||||
{
|
||||
__int16 ea; /* Encryption algorithm ID */
|
||||
__int16 mode; /* Mode of operation (e.g., XTS) */
|
||||
__int16 pkcs5; /* PRF algorithm */
|
||||
|
||||
} BOOT_CRYPTO_HEADER, *PBOOT_CRYPTO_HEADER;
|
||||
|
||||
#pragma pack (pop)
|
||||
|
||||
#endif
|
||||
|
||||
PCRYPTO_INFO crypto_open (void);
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
void crypto_loadkey (PKEY_INFO keyInfo, char *lpszUserKey, int nUserKeyLen);
|
||||
#endif
|
||||
void crypto_close (PCRYPTO_INFO cryptoInfo);
|
||||
|
||||
int CipherGetBlockSize (int cipher);
|
||||
int CipherGetKeySize (int cipher);
|
||||
int CipherGetKeyScheduleSize (int cipher);
|
||||
BOOL CipherSupportsIntraDataUnitParallelization (int cipher);
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
const wchar_t * CipherGetName (int cipher);
|
||||
#endif
|
||||
|
||||
int CipherInit (int cipher, unsigned char *key, unsigned char *ks);
|
||||
#ifndef TC_WINDOWS_BOOT_SINGLE_CIPHER_MODE
|
||||
int EAInit (int ea, unsigned char *key, unsigned char *ks);
|
||||
#else
|
||||
int EAInit (unsigned char *key, unsigned char *ks);
|
||||
#endif
|
||||
BOOL EAInitMode (PCRYPTO_INFO ci);
|
||||
void EncipherBlock(int cipher, void *data, void *ks);
|
||||
void DecipherBlock(int cipher, void *data, void *ks);
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
void EncipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount);
|
||||
void DecipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount);
|
||||
#endif
|
||||
|
||||
int EAGetFirst ();
|
||||
int EAGetCount (void);
|
||||
int EAGetNext (int previousEA);
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
wchar_t * EAGetName (wchar_t *buf, int ea, int guiDisplay);
|
||||
int EAGetByName (wchar_t *name);
|
||||
#endif
|
||||
int EAGetKeySize (int ea);
|
||||
int EAGetFirstMode (int ea);
|
||||
int EAGetNextMode (int ea, int previousModeId);
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
wchar_t * EAGetModeName (int ea, int mode, BOOL capitalLetters);
|
||||
#endif
|
||||
int EAGetKeyScheduleSize (int ea);
|
||||
int EAGetLargestKey ();
|
||||
int EAGetLargestKeyForMode (int mode);
|
||||
|
||||
int EAGetCipherCount (int ea);
|
||||
int EAGetFirstCipher (int ea);
|
||||
int EAGetLastCipher (int ea);
|
||||
int EAGetNextCipher (int ea, int previousCipherId);
|
||||
int EAGetPreviousCipher (int ea, int previousCipherId);
|
||||
int EAIsFormatEnabled (int ea);
|
||||
BOOL EAIsModeSupported (int ea, int testedMode);
|
||||
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
const wchar_t *HashGetName (int hash_algo_id);
|
||||
|
||||
Hash *HashGet (int id);
|
||||
void HashGetName2 (wchar_t *buf, int hashId);
|
||||
BOOL HashIsDeprecated (int hashId);
|
||||
BOOL HashForSystemEncryption (int hashId);
|
||||
int GetMaxPkcs5OutSize (void);
|
||||
#endif
|
||||
|
||||
|
||||
void EncryptDataUnits (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, uint32 nbrUnits, PCRYPTO_INFO ci);
|
||||
void EncryptDataUnitsCurrentThread (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, TC_LARGEST_COMPILER_UINT nbrUnits, PCRYPTO_INFO ci);
|
||||
void DecryptDataUnits (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, uint32 nbrUnits, PCRYPTO_INFO ci);
|
||||
void DecryptDataUnitsCurrentThread (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, TC_LARGEST_COMPILER_UINT nbrUnits, PCRYPTO_INFO ci);
|
||||
void EncryptBuffer (unsigned __int8 *buf, TC_LARGEST_COMPILER_UINT len, PCRYPTO_INFO cryptoInfo);
|
||||
void DecryptBuffer (unsigned __int8 *buf, TC_LARGEST_COMPILER_UINT len, PCRYPTO_INFO cryptoInfo);
|
||||
|
||||
BOOL IsAesHwCpuSupported ();
|
||||
void EnableHwEncryption (BOOL enable);
|
||||
BOOL IsHwEncryptionEnabled ();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CRYPTO_H */
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
/* Update the following when adding a new cipher or EA:
|
||||
|
||||
Crypto.h:
|
||||
ID #define
|
||||
MAX_EXPANDED_KEY #define
|
||||
|
||||
Crypto.c:
|
||||
Ciphers[]
|
||||
EncryptionAlgorithms[]
|
||||
CipherInit()
|
||||
EncipherBlock()
|
||||
DecipherBlock()
|
||||
|
||||
*/
|
||||
|
||||
#ifndef CRYPTO_H
|
||||
#define CRYPTO_H
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Encryption data unit size, which may differ from the sector size and must always be 512
|
||||
#define ENCRYPTION_DATA_UNIT_SIZE 512
|
||||
|
||||
// Size of the salt (in bytes)
|
||||
#define PKCS5_SALT_SIZE 64
|
||||
|
||||
// Size of the volume header area containing concatenated master key(s) and secondary key(s) (XTS mode)
|
||||
#define MASTER_KEYDATA_SIZE 256
|
||||
|
||||
// The first PRF to try when mounting
|
||||
#define FIRST_PRF_ID 1
|
||||
|
||||
// Hash algorithms (pseudorandom functions).
|
||||
enum
|
||||
{
|
||||
SHA512 = FIRST_PRF_ID,
|
||||
WHIRLPOOL,
|
||||
SHA256,
|
||||
RIPEMD160,
|
||||
HASH_ENUM_END_ID
|
||||
};
|
||||
|
||||
// The last PRF to try when mounting and also the number of implemented PRFs
|
||||
#define LAST_PRF_ID (HASH_ENUM_END_ID - 1)
|
||||
|
||||
#define RIPEMD160_BLOCKSIZE 64
|
||||
#define RIPEMD160_DIGESTSIZE 20
|
||||
|
||||
#define SHA256_BLOCKSIZE 64
|
||||
#define SHA256_DIGESTSIZE 32
|
||||
|
||||
#define SHA512_BLOCKSIZE 128
|
||||
#define SHA512_DIGESTSIZE 64
|
||||
|
||||
#define WHIRLPOOL_BLOCKSIZE 64
|
||||
#define WHIRLPOOL_DIGESTSIZE 64
|
||||
|
||||
#define MAX_DIGESTSIZE WHIRLPOOL_DIGESTSIZE
|
||||
|
||||
#define DEFAULT_HASH_ALGORITHM FIRST_PRF_ID
|
||||
#define DEFAULT_HASH_ALGORITHM_BOOT SHA256
|
||||
|
||||
// The mode of operation used for newly created volumes and first to try when mounting
|
||||
#define FIRST_MODE_OF_OPERATION_ID 1
|
||||
|
||||
// Modes of operation
|
||||
enum
|
||||
{
|
||||
/* If you add/remove a mode, update the following: GetMaxPkcs5OutSize(), EAInitMode() */
|
||||
|
||||
XTS = FIRST_MODE_OF_OPERATION_ID,
|
||||
MODE_ENUM_END_ID
|
||||
};
|
||||
|
||||
|
||||
// The last mode of operation to try when mounting and also the number of implemented modes
|
||||
#define LAST_MODE_OF_OPERATION (MODE_ENUM_END_ID - 1)
|
||||
|
||||
// Ciphertext/plaintext block size for XTS mode (in bytes)
|
||||
#define BYTES_PER_XTS_BLOCK 16
|
||||
|
||||
// Number of ciphertext/plaintext blocks per XTS data unit
|
||||
#define BLOCKS_PER_XTS_DATA_UNIT (ENCRYPTION_DATA_UNIT_SIZE / BYTES_PER_XTS_BLOCK)
|
||||
|
||||
|
||||
// Cipher IDs
|
||||
enum
|
||||
{
|
||||
NONE = 0,
|
||||
AES,
|
||||
SERPENT,
|
||||
TWOFISH
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int Id; // Cipher ID
|
||||
#ifdef TC_WINDOWS_BOOT
|
||||
char *Name; // Name
|
||||
#else
|
||||
wchar_t *Name; // Name
|
||||
#endif
|
||||
int BlockSize; // Block size (bytes)
|
||||
int KeySize; // Key size (bytes)
|
||||
int KeyScheduleSize; // Scheduled key size (bytes)
|
||||
} Cipher;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int Ciphers[4]; // Null terminated array of ciphers used by encryption algorithm
|
||||
int Modes[LAST_MODE_OF_OPERATION + 1]; // Null terminated array of modes of operation
|
||||
int FormatEnabled;
|
||||
} EncryptionAlgorithm;
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
typedef struct
|
||||
{
|
||||
int Id; // Hash ID
|
||||
wchar_t *Name; // Name
|
||||
BOOL Deprecated;
|
||||
BOOL SystemEncryption; // Available for system encryption
|
||||
} Hash;
|
||||
#endif
|
||||
|
||||
// Maxium length of scheduled key
|
||||
#if !defined (TC_WINDOWS_BOOT) || defined (TC_WINDOWS_BOOT_AES)
|
||||
# define AES_KS (sizeof(aes_encrypt_ctx) + sizeof(aes_decrypt_ctx))
|
||||
#else
|
||||
# define AES_KS (sizeof(aes_context))
|
||||
#endif
|
||||
#define SERPENT_KS (140 * 4)
|
||||
|
||||
#ifdef TC_WINDOWS_BOOT_SINGLE_CIPHER_MODE
|
||||
|
||||
# ifdef TC_WINDOWS_BOOT_AES
|
||||
# define MAX_EXPANDED_KEY AES_KS
|
||||
# elif defined (TC_WINDOWS_BOOT_SERPENT)
|
||||
# define MAX_EXPANDED_KEY SERPENT_KS
|
||||
# elif defined (TC_WINDOWS_BOOT_TWOFISH)
|
||||
# define MAX_EXPANDED_KEY TWOFISH_KS
|
||||
# endif
|
||||
|
||||
#else
|
||||
|
||||
#define MAX_EXPANDED_KEY (AES_KS + SERPENT_KS + TWOFISH_KS)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
# define PRAND_DISK_WIPE_PASSES 3
|
||||
#else
|
||||
# define PRAND_DISK_WIPE_PASSES 256
|
||||
#endif
|
||||
|
||||
/* specific value for volume header wipe used only when drive is fully wiped. */
|
||||
#define PRAND_HEADER_WIPE_PASSES 3
|
||||
|
||||
#if !defined (TC_WINDOWS_BOOT) || defined (TC_WINDOWS_BOOT_AES)
|
||||
# include "Aes.h"
|
||||
#else
|
||||
# include "AesSmall.h"
|
||||
#endif
|
||||
|
||||
#include "Aes_hw_cpu.h"
|
||||
#include "Serpent.h"
|
||||
#include "Twofish.h"
|
||||
|
||||
#include "Rmd160.h"
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
# include "Sha2.h"
|
||||
# include "Whirlpool.h"
|
||||
#endif
|
||||
|
||||
#include "GfMul.h"
|
||||
#include "Password.h"
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
|
||||
#include "config.h"
|
||||
|
||||
typedef struct keyInfo_t
|
||||
{
|
||||
int noIterations; /* Number of times to iterate (PKCS-5) */
|
||||
int keyLength; /* Length of the key */
|
||||
uint64 dummy; /* Dummy field to ensure 16-byte alignment of this structure */
|
||||
__int8 salt[PKCS5_SALT_SIZE]; /* PKCS-5 salt */
|
||||
__int8 master_keydata[MASTER_KEYDATA_SIZE]; /* Concatenated master primary and secondary key(s) (XTS mode). For LRW (deprecated/legacy), it contains the tweak key before the master key(s). For CBC (deprecated/legacy), it contains the IV seed before the master key(s). */
|
||||
CRYPTOPP_ALIGN_DATA(16) __int8 userKey[MAX_PASSWORD]; /* Password (to which keyfiles may have been applied). WITHOUT +1 for the null terminator. */
|
||||
} KEY_INFO, *PKEY_INFO;
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct CRYPTO_INFO_t
|
||||
{
|
||||
int ea; /* Encryption algorithm ID */
|
||||
int mode; /* Mode of operation (e.g., XTS) */
|
||||
int pkcs5; /* PRF algorithm */
|
||||
|
||||
unsigned __int8 ks[MAX_EXPANDED_KEY]; /* Primary key schedule (if it is a cascade, it conatins multiple concatenated keys) */
|
||||
unsigned __int8 ks2[MAX_EXPANDED_KEY]; /* Secondary key schedule (if cascade, multiple concatenated) for XTS mode. */
|
||||
|
||||
BOOL hiddenVolume; // Indicates whether the volume is mounted/mountable as hidden volume
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
uint16 HeaderVersion;
|
||||
|
||||
GfCtx gf_ctx;
|
||||
|
||||
unsigned __int8 master_keydata[MASTER_KEYDATA_SIZE]; /* This holds the volume header area containing concatenated master key(s) and secondary key(s) (XTS mode). For LRW (deprecated/legacy), it contains the tweak key before the master key(s). For CBC (deprecated/legacy), it contains the IV seed before the master key(s). */
|
||||
unsigned __int8 k2[MASTER_KEYDATA_SIZE]; /* For XTS, this contains the secondary key (if cascade, multiple concatenated). For LRW (deprecated/legacy), it contains the tweak key. For CBC (deprecated/legacy), it contains the IV seed. */
|
||||
unsigned __int8 salt[PKCS5_SALT_SIZE];
|
||||
int noIterations;
|
||||
BOOL bTrueCryptMode;
|
||||
int volumePim;
|
||||
|
||||
uint64 volume_creation_time; // Legacy
|
||||
uint64 header_creation_time; // Legacy
|
||||
|
||||
BOOL bProtectHiddenVolume; // Indicates whether the volume contains a hidden volume to be protected against overwriting
|
||||
BOOL bHiddenVolProtectionAction; // TRUE if a write operation has been denied by the driver in order to prevent the hidden volume from being overwritten (set to FALSE upon volume mount).
|
||||
|
||||
uint64 volDataAreaOffset; // Absolute position, in bytes, of the first data sector of the volume.
|
||||
|
||||
uint64 hiddenVolumeSize; // Size of the hidden volume excluding the header (in bytes). Set to 0 for standard volumes.
|
||||
uint64 hiddenVolumeOffset; // Absolute position, in bytes, of the first hidden volume data sector within the host volume (provided that there is a hidden volume within). This must be set for all hidden volumes; in case of a normal volume, this variable is only used when protecting a hidden volume within it.
|
||||
uint64 hiddenVolumeProtectedSize;
|
||||
|
||||
BOOL bPartitionInInactiveSysEncScope; // If TRUE, the volume is a partition located on an encrypted system drive and mounted without pre-boot authentication.
|
||||
|
||||
UINT64_STRUCT FirstDataUnitNo; // First data unit number of the volume. This is 0 for file-hosted and non-system partition-hosted volumes. For partitions within key scope of system encryption this reflects real physical offset within the device (this is used e.g. when such a partition is mounted as a regular volume without pre-boot authentication).
|
||||
|
||||
uint16 RequiredProgramVersion;
|
||||
BOOL LegacyVolume;
|
||||
|
||||
uint32 SectorSize;
|
||||
|
||||
#endif // !TC_WINDOWS_BOOT
|
||||
|
||||
UINT64_STRUCT VolumeSize;
|
||||
|
||||
UINT64_STRUCT EncryptedAreaStart;
|
||||
UINT64_STRUCT EncryptedAreaLength;
|
||||
|
||||
uint32 HeaderFlags;
|
||||
|
||||
} CRYPTO_INFO, *PCRYPTO_INFO;
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#pragma pack (push)
|
||||
#pragma pack(1)
|
||||
|
||||
typedef struct BOOT_CRYPTO_HEADER_t
|
||||
{
|
||||
__int16 ea; /* Encryption algorithm ID */
|
||||
__int16 mode; /* Mode of operation (e.g., XTS) */
|
||||
__int16 pkcs5; /* PRF algorithm */
|
||||
|
||||
} BOOT_CRYPTO_HEADER, *PBOOT_CRYPTO_HEADER;
|
||||
|
||||
#pragma pack (pop)
|
||||
|
||||
#endif
|
||||
|
||||
PCRYPTO_INFO crypto_open (void);
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
void crypto_loadkey (PKEY_INFO keyInfo, char *lpszUserKey, int nUserKeyLen);
|
||||
#endif
|
||||
void crypto_close (PCRYPTO_INFO cryptoInfo);
|
||||
|
||||
int CipherGetBlockSize (int cipher);
|
||||
int CipherGetKeySize (int cipher);
|
||||
int CipherGetKeyScheduleSize (int cipher);
|
||||
BOOL CipherSupportsIntraDataUnitParallelization (int cipher);
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
const wchar_t * CipherGetName (int cipher);
|
||||
#endif
|
||||
|
||||
int CipherInit (int cipher, unsigned char *key, unsigned char *ks);
|
||||
#ifndef TC_WINDOWS_BOOT_SINGLE_CIPHER_MODE
|
||||
int EAInit (int ea, unsigned char *key, unsigned char *ks);
|
||||
#else
|
||||
int EAInit (unsigned char *key, unsigned char *ks);
|
||||
#endif
|
||||
BOOL EAInitMode (PCRYPTO_INFO ci);
|
||||
void EncipherBlock(int cipher, void *data, void *ks);
|
||||
void DecipherBlock(int cipher, void *data, void *ks);
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
void EncipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount);
|
||||
void DecipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount);
|
||||
#endif
|
||||
|
||||
int EAGetFirst ();
|
||||
int EAGetCount (void);
|
||||
int EAGetNext (int previousEA);
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
wchar_t * EAGetName (wchar_t *buf, int ea, int guiDisplay);
|
||||
int EAGetByName (wchar_t *name);
|
||||
#endif
|
||||
int EAGetKeySize (int ea);
|
||||
int EAGetFirstMode (int ea);
|
||||
int EAGetNextMode (int ea, int previousModeId);
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
wchar_t * EAGetModeName (int ea, int mode, BOOL capitalLetters);
|
||||
#endif
|
||||
int EAGetKeyScheduleSize (int ea);
|
||||
int EAGetLargestKey ();
|
||||
int EAGetLargestKeyForMode (int mode);
|
||||
|
||||
int EAGetCipherCount (int ea);
|
||||
int EAGetFirstCipher (int ea);
|
||||
int EAGetLastCipher (int ea);
|
||||
int EAGetNextCipher (int ea, int previousCipherId);
|
||||
int EAGetPreviousCipher (int ea, int previousCipherId);
|
||||
int EAIsFormatEnabled (int ea);
|
||||
BOOL EAIsModeSupported (int ea, int testedMode);
|
||||
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
const wchar_t *HashGetName (int hash_algo_id);
|
||||
|
||||
Hash *HashGet (int id);
|
||||
void HashGetName2 (wchar_t *buf, int hashId);
|
||||
BOOL HashIsDeprecated (int hashId);
|
||||
BOOL HashForSystemEncryption (int hashId);
|
||||
int GetMaxPkcs5OutSize (void);
|
||||
#endif
|
||||
|
||||
|
||||
void EncryptDataUnits (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, uint32 nbrUnits, PCRYPTO_INFO ci);
|
||||
void EncryptDataUnitsCurrentThread (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, TC_LARGEST_COMPILER_UINT nbrUnits, PCRYPTO_INFO ci);
|
||||
void DecryptDataUnits (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, uint32 nbrUnits, PCRYPTO_INFO ci);
|
||||
void DecryptDataUnitsCurrentThread (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, TC_LARGEST_COMPILER_UINT nbrUnits, PCRYPTO_INFO ci);
|
||||
void EncryptBuffer (unsigned __int8 *buf, TC_LARGEST_COMPILER_UINT len, PCRYPTO_INFO cryptoInfo);
|
||||
void DecryptBuffer (unsigned __int8 *buf, TC_LARGEST_COMPILER_UINT len, PCRYPTO_INFO cryptoInfo);
|
||||
|
||||
BOOL IsAesHwCpuSupported ();
|
||||
void EnableHwEncryption (BOOL enable);
|
||||
BOOL IsHwEncryptionEnabled ();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CRYPTO_H */
|
||||
|
||||
@@ -1,88 +1,88 @@
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#include "../Common/Dictionary.h"
|
||||
#include <windows.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
static map <string, void *> StringKeyMap;
|
||||
static map <int, void *> IntKeyMap;
|
||||
|
||||
static void *DataPool = NULL;
|
||||
static size_t DataPoolSize = 0;
|
||||
|
||||
|
||||
void AddDictionaryEntry (char *key, int intKey, void *value)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (key)
|
||||
StringKeyMap[key] = value;
|
||||
|
||||
if (intKey != 0)
|
||||
IntKeyMap[intKey] = value;
|
||||
}
|
||||
catch (exception&) {}
|
||||
}
|
||||
|
||||
|
||||
void *GetDictionaryValue (const char *key)
|
||||
{
|
||||
map <string, void *>::const_iterator i = StringKeyMap.find (key);
|
||||
|
||||
if (i == StringKeyMap.end())
|
||||
return NULL;
|
||||
|
||||
return i->second;
|
||||
}
|
||||
|
||||
|
||||
void *GetDictionaryValueByInt (int intKey)
|
||||
{
|
||||
map <int, void *>::const_iterator i = IntKeyMap.find (intKey);
|
||||
|
||||
if (i == IntKeyMap.end())
|
||||
return NULL;
|
||||
|
||||
return i->second;
|
||||
}
|
||||
|
||||
|
||||
void *AddPoolData (void *data, size_t dataSize)
|
||||
{
|
||||
if (DataPoolSize + dataSize > DATA_POOL_CAPACITY) return NULL;
|
||||
|
||||
if (DataPool == NULL)
|
||||
{
|
||||
DataPool = malloc (DATA_POOL_CAPACITY);
|
||||
if (DataPool == NULL) return NULL;
|
||||
}
|
||||
|
||||
memcpy ((BYTE *)DataPool + DataPoolSize, data, dataSize);
|
||||
|
||||
// Ensure 32-bit alignment for next entries
|
||||
dataSize = (dataSize + 3) & (~(size_t)3);
|
||||
|
||||
DataPoolSize += dataSize;
|
||||
return (BYTE *)DataPool + DataPoolSize - dataSize;
|
||||
}
|
||||
|
||||
|
||||
void ClearDictionaryPool ()
|
||||
{
|
||||
DataPoolSize = 0;
|
||||
StringKeyMap.clear();
|
||||
IntKeyMap.clear();
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#include "../Common/Dictionary.h"
|
||||
#include <windows.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
static map <string, void *> StringKeyMap;
|
||||
static map <int, void *> IntKeyMap;
|
||||
|
||||
static void *DataPool = NULL;
|
||||
static size_t DataPoolSize = 0;
|
||||
|
||||
|
||||
void AddDictionaryEntry (char *key, int intKey, void *value)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (key)
|
||||
StringKeyMap[key] = value;
|
||||
|
||||
if (intKey != 0)
|
||||
IntKeyMap[intKey] = value;
|
||||
}
|
||||
catch (exception&) {}
|
||||
}
|
||||
|
||||
|
||||
void *GetDictionaryValue (const char *key)
|
||||
{
|
||||
map <string, void *>::const_iterator i = StringKeyMap.find (key);
|
||||
|
||||
if (i == StringKeyMap.end())
|
||||
return NULL;
|
||||
|
||||
return i->second;
|
||||
}
|
||||
|
||||
|
||||
void *GetDictionaryValueByInt (int intKey)
|
||||
{
|
||||
map <int, void *>::const_iterator i = IntKeyMap.find (intKey);
|
||||
|
||||
if (i == IntKeyMap.end())
|
||||
return NULL;
|
||||
|
||||
return i->second;
|
||||
}
|
||||
|
||||
|
||||
void *AddPoolData (void *data, size_t dataSize)
|
||||
{
|
||||
if (DataPoolSize + dataSize > DATA_POOL_CAPACITY) return NULL;
|
||||
|
||||
if (DataPool == NULL)
|
||||
{
|
||||
DataPool = malloc (DATA_POOL_CAPACITY);
|
||||
if (DataPool == NULL) return NULL;
|
||||
}
|
||||
|
||||
memcpy ((BYTE *)DataPool + DataPoolSize, data, dataSize);
|
||||
|
||||
// Ensure 32-bit alignment for next entries
|
||||
dataSize = (dataSize + 3) & (~(size_t)3);
|
||||
|
||||
DataPoolSize += dataSize;
|
||||
return (BYTE *)DataPool + DataPoolSize - dataSize;
|
||||
}
|
||||
|
||||
|
||||
void ClearDictionaryPool ()
|
||||
{
|
||||
DataPoolSize = 0;
|
||||
StringKeyMap.clear();
|
||||
IntKeyMap.clear();
|
||||
}
|
||||
@@ -1,34 +1,34 @@
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifndef DICTIONARY_H
|
||||
#define DICTIONARY_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define DATA_POOL_CAPACITY 1000000
|
||||
|
||||
void AddDictionaryEntry (char *key, int intKey, void *value);
|
||||
void *GetDictionaryValue (const char *key);
|
||||
void *GetDictionaryValueByInt (int intKey);
|
||||
void *AddPoolData (void *data, size_t dataSize);
|
||||
void ClearDictionaryPool ();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifndef DICTIONARY_H
|
||||
#define DICTIONARY_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define DATA_POOL_CAPACITY 1000000
|
||||
|
||||
void AddDictionaryEntry (char *key, int intKey, void *value);
|
||||
void *GetDictionaryValue (const char *key);
|
||||
void *GetDictionaryValueByInt (int intKey);
|
||||
void *AddPoolData (void *data, size_t dataSize);
|
||||
void ClearDictionaryPool ();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
23780
src/Common/Dlgcode.c
23780
src/Common/Dlgcode.c
File diff suppressed because it is too large
Load Diff
1186
src/Common/Dlgcode.h
1186
src/Common/Dlgcode.h
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,42 +1,42 @@
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_ENCRYPTION_THREAD_POOL
|
||||
#define TC_HEADER_ENCRYPTION_THREAD_POOL
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Crypto.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
EncryptDataUnitsWork,
|
||||
DecryptDataUnitsWork,
|
||||
DeriveKeyWork
|
||||
} EncryptionThreadPoolWorkType;
|
||||
|
||||
void EncryptionThreadPoolBeginKeyDerivation (TC_EVENT *completionEvent, TC_EVENT *noOutstandingWorkItemEvent, LONG *completionFlag, LONG *outstandingWorkItemCount, int pkcs5Prf, char *password, int passwordLength, char *salt, int iterationCount, char *derivedKey);
|
||||
void EncryptionThreadPoolDoWork (EncryptionThreadPoolWorkType type, byte *data, const UINT64_STRUCT *startUnitNo, uint32 unitCount, PCRYPTO_INFO cryptoInfo);
|
||||
BOOL EncryptionThreadPoolStart (size_t encryptionFreeCpuCount);
|
||||
void EncryptionThreadPoolStop ();
|
||||
size_t GetEncryptionThreadCount ();
|
||||
size_t GetMaxEncryptionThreadCount ();
|
||||
BOOL IsEncryptionThreadPoolRunning ();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_ENCRYPTION_THREAD_POOL
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_ENCRYPTION_THREAD_POOL
|
||||
#define TC_HEADER_ENCRYPTION_THREAD_POOL
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Crypto.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
EncryptDataUnitsWork,
|
||||
DecryptDataUnitsWork,
|
||||
DeriveKeyWork
|
||||
} EncryptionThreadPoolWorkType;
|
||||
|
||||
void EncryptionThreadPoolBeginKeyDerivation (TC_EVENT *completionEvent, TC_EVENT *noOutstandingWorkItemEvent, LONG *completionFlag, LONG *outstandingWorkItemCount, int pkcs5Prf, char *password, int passwordLength, char *salt, int iterationCount, char *derivedKey);
|
||||
void EncryptionThreadPoolDoWork (EncryptionThreadPoolWorkType type, byte *data, const UINT64_STRUCT *startUnitNo, uint32 unitCount, PCRYPTO_INFO cryptoInfo);
|
||||
BOOL EncryptionThreadPoolStart (size_t encryptionFreeCpuCount);
|
||||
void EncryptionThreadPoolStop ();
|
||||
size_t GetEncryptionThreadCount ();
|
||||
size_t GetMaxEncryptionThreadCount ();
|
||||
BOOL IsEncryptionThreadPoolRunning ();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_ENCRYPTION_THREAD_POOL
|
||||
|
||||
@@ -1,59 +1,59 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Common/Endian.h"
|
||||
|
||||
|
||||
unsigned __int16 MirrorBytes16 (unsigned __int16 x)
|
||||
{
|
||||
return (x << 8) | (x >> 8);
|
||||
}
|
||||
|
||||
|
||||
unsigned __int32 MirrorBytes32 (unsigned __int32 x)
|
||||
{
|
||||
unsigned __int32 n = (unsigned __int8) x;
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 8);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 16);
|
||||
return (n << 8) | (unsigned __int8) (x >> 24);
|
||||
}
|
||||
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
uint64 MirrorBytes64 (uint64 x)
|
||||
{
|
||||
uint64 n = (unsigned __int8) x;
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 8);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 16);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 24);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 32);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 40);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 48);
|
||||
return (n << 8) | (unsigned __int8) (x >> 56);
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
LongReverse (unsigned __int32 *buffer, unsigned byteCount)
|
||||
{
|
||||
unsigned __int32 value;
|
||||
|
||||
byteCount /= sizeof (unsigned __int32);
|
||||
while (byteCount--)
|
||||
{
|
||||
value = *buffer;
|
||||
value = ((value & 0xFF00FF00L) >> 8) | \
|
||||
((value & 0x00FF00FFL) << 8);
|
||||
*buffer++ = (value << 16) | (value >> 16);
|
||||
}
|
||||
}
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Common/Endian.h"
|
||||
|
||||
|
||||
unsigned __int16 MirrorBytes16 (unsigned __int16 x)
|
||||
{
|
||||
return (x << 8) | (x >> 8);
|
||||
}
|
||||
|
||||
|
||||
unsigned __int32 MirrorBytes32 (unsigned __int32 x)
|
||||
{
|
||||
unsigned __int32 n = (unsigned __int8) x;
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 8);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 16);
|
||||
return (n << 8) | (unsigned __int8) (x >> 24);
|
||||
}
|
||||
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
uint64 MirrorBytes64 (uint64 x)
|
||||
{
|
||||
uint64 n = (unsigned __int8) x;
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 8);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 16);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 24);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 32);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 40);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 48);
|
||||
return (n << 8) | (unsigned __int8) (x >> 56);
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
LongReverse (unsigned __int32 *buffer, unsigned byteCount)
|
||||
{
|
||||
unsigned __int32 value;
|
||||
|
||||
byteCount /= sizeof (unsigned __int32);
|
||||
while (byteCount--)
|
||||
{
|
||||
value = *buffer;
|
||||
value = ((value & 0xFF00FF00L) >> 8) | \
|
||||
((value & 0x00FF00FFL) << 8);
|
||||
*buffer++ = (value << 16) | (value >> 16);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,149 +1,149 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#ifndef TC_ENDIAN_H
|
||||
#define TC_ENDIAN_H
|
||||
|
||||
#include "Common/Tcdefs.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
# ifndef LITTLE_ENDIAN
|
||||
# define LITTLE_ENDIAN 1234
|
||||
# endif
|
||||
# ifndef BYTE_ORDER
|
||||
# define BYTE_ORDER LITTLE_ENDIAN
|
||||
# endif
|
||||
|
||||
#elif !defined(BYTE_ORDER)
|
||||
|
||||
# ifdef TC_MACOSX
|
||||
# include <machine/endian.h>
|
||||
# elif defined (TC_BSD)
|
||||
# include <sys/endian.h>
|
||||
# elif defined (TC_SOLARIS)
|
||||
# include <sys/types.h>
|
||||
# define LITTLE_ENDIAN 1234
|
||||
# define BIG_ENDIAN 4321
|
||||
# ifdef _BIG_ENDIAN
|
||||
# define BYTE_ORDER BIG_ENDIAN
|
||||
# else
|
||||
# define BYTE_ORDER LITTLE_ENDIAN
|
||||
# endif
|
||||
# else
|
||||
# include <endian.h>
|
||||
# endif
|
||||
|
||||
# ifndef BYTE_ORDER
|
||||
# ifndef __BYTE_ORDER
|
||||
# error Byte order cannot be determined (BYTE_ORDER undefined)
|
||||
# endif
|
||||
|
||||
# define BYTE_ORDER __BYTE_ORDER
|
||||
# endif
|
||||
|
||||
# ifndef LITTLE_ENDIAN
|
||||
# define LITTLE_ENDIAN __LITTLE_ENDIAN
|
||||
# endif
|
||||
|
||||
# ifndef BIG_ENDIAN
|
||||
# define BIG_ENDIAN __BIG_ENDIAN
|
||||
# endif
|
||||
|
||||
#endif // !BYTE_ORDER
|
||||
|
||||
/* Macros to read and write 16, 32, and 64-bit quantities in a portable manner.
|
||||
These functions are implemented as macros rather than true functions as
|
||||
the need to adjust the memory pointers makes them somewhat painful to call
|
||||
in user code */
|
||||
|
||||
#define mputInt64(memPtr,data) \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 56 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 48 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 40 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 32 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 24 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 16 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 8 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( data ) & 0xFF )
|
||||
|
||||
#define mputLong(memPtr,data) \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 24 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 16 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 8 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( data ) & 0xFF )
|
||||
|
||||
#define mputWord(memPtr,data) \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 8 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( data ) & 0xFF )
|
||||
|
||||
#define mputByte(memPtr,data) \
|
||||
*memPtr++ = ( unsigned char ) data
|
||||
|
||||
#define mputBytes(memPtr,data,len) \
|
||||
memcpy (memPtr,data,len); \
|
||||
memPtr += len;
|
||||
|
||||
#define mgetInt64(memPtr) \
|
||||
( memPtr += 8, ( ( unsigned __int64 ) memPtr[ -8 ] << 56 ) | ( ( unsigned __int64 ) memPtr[ -7 ] << 48 ) | \
|
||||
( ( unsigned __int64 ) memPtr[ -6 ] << 40 ) | ( ( unsigned __int64 ) memPtr[ -5 ] << 32 ) | \
|
||||
( ( unsigned __int64 ) memPtr[ -4 ] << 24 ) | ( ( unsigned __int64 ) memPtr[ -3 ] << 16 ) | \
|
||||
( ( unsigned __int64 ) memPtr[ -2 ] << 8 ) | ( unsigned __int64 ) memPtr[ -1 ] )
|
||||
|
||||
#define mgetLong(memPtr) \
|
||||
( memPtr += 4, ( ( unsigned __int32 ) memPtr[ -4 ] << 24 ) | ( ( unsigned __int32 ) memPtr[ -3 ] << 16 ) | \
|
||||
( ( unsigned __int32 ) memPtr[ -2 ] << 8 ) | ( unsigned __int32 ) memPtr[ -1 ] )
|
||||
|
||||
#define mgetWord(memPtr) \
|
||||
( memPtr += 2, ((( unsigned short ) memPtr[ -2 ] << 8 ) | ( ( unsigned short ) memPtr[ -1 ] )) )
|
||||
|
||||
#define mgetByte(memPtr) \
|
||||
( ( unsigned char ) *memPtr++ )
|
||||
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
# define LE16(x) MirrorBytes16(x)
|
||||
# define LE32(x) MirrorBytes32(x)
|
||||
# define LE64(x) MirrorBytes64(x)
|
||||
#else
|
||||
# define LE16(x) (x)
|
||||
# define LE32(x) (x)
|
||||
# define LE64(x) (x)
|
||||
#endif
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
# define BE16(x) MirrorBytes16(x)
|
||||
# define BE32(x) MirrorBytes32(x)
|
||||
# define BE64(x) MirrorBytes64(x)
|
||||
#else
|
||||
# define BE16(x) (x)
|
||||
# define BE32(x) (x)
|
||||
# define BE64(x) (x)
|
||||
#endif
|
||||
|
||||
unsigned __int16 MirrorBytes16 (unsigned __int16 x);
|
||||
unsigned __int32 MirrorBytes32 (unsigned __int32 x);
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
uint64 MirrorBytes64 (uint64 x);
|
||||
#endif
|
||||
void LongReverse ( unsigned __int32 *buffer , unsigned byteCount );
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TC_ENDIAN_H */
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#ifndef TC_ENDIAN_H
|
||||
#define TC_ENDIAN_H
|
||||
|
||||
#include "Common/Tcdefs.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
# ifndef LITTLE_ENDIAN
|
||||
# define LITTLE_ENDIAN 1234
|
||||
# endif
|
||||
# ifndef BYTE_ORDER
|
||||
# define BYTE_ORDER LITTLE_ENDIAN
|
||||
# endif
|
||||
|
||||
#elif !defined(BYTE_ORDER)
|
||||
|
||||
# ifdef TC_MACOSX
|
||||
# include <machine/endian.h>
|
||||
# elif defined (TC_BSD)
|
||||
# include <sys/endian.h>
|
||||
# elif defined (TC_SOLARIS)
|
||||
# include <sys/types.h>
|
||||
# define LITTLE_ENDIAN 1234
|
||||
# define BIG_ENDIAN 4321
|
||||
# ifdef _BIG_ENDIAN
|
||||
# define BYTE_ORDER BIG_ENDIAN
|
||||
# else
|
||||
# define BYTE_ORDER LITTLE_ENDIAN
|
||||
# endif
|
||||
# else
|
||||
# include <endian.h>
|
||||
# endif
|
||||
|
||||
# ifndef BYTE_ORDER
|
||||
# ifndef __BYTE_ORDER
|
||||
# error Byte order cannot be determined (BYTE_ORDER undefined)
|
||||
# endif
|
||||
|
||||
# define BYTE_ORDER __BYTE_ORDER
|
||||
# endif
|
||||
|
||||
# ifndef LITTLE_ENDIAN
|
||||
# define LITTLE_ENDIAN __LITTLE_ENDIAN
|
||||
# endif
|
||||
|
||||
# ifndef BIG_ENDIAN
|
||||
# define BIG_ENDIAN __BIG_ENDIAN
|
||||
# endif
|
||||
|
||||
#endif // !BYTE_ORDER
|
||||
|
||||
/* Macros to read and write 16, 32, and 64-bit quantities in a portable manner.
|
||||
These functions are implemented as macros rather than true functions as
|
||||
the need to adjust the memory pointers makes them somewhat painful to call
|
||||
in user code */
|
||||
|
||||
#define mputInt64(memPtr,data) \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 56 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 48 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 40 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 32 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 24 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 16 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 8 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( data ) & 0xFF )
|
||||
|
||||
#define mputLong(memPtr,data) \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 24 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 16 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 8 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( data ) & 0xFF )
|
||||
|
||||
#define mputWord(memPtr,data) \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 8 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( data ) & 0xFF )
|
||||
|
||||
#define mputByte(memPtr,data) \
|
||||
*memPtr++ = ( unsigned char ) data
|
||||
|
||||
#define mputBytes(memPtr,data,len) \
|
||||
memcpy (memPtr,data,len); \
|
||||
memPtr += len;
|
||||
|
||||
#define mgetInt64(memPtr) \
|
||||
( memPtr += 8, ( ( unsigned __int64 ) memPtr[ -8 ] << 56 ) | ( ( unsigned __int64 ) memPtr[ -7 ] << 48 ) | \
|
||||
( ( unsigned __int64 ) memPtr[ -6 ] << 40 ) | ( ( unsigned __int64 ) memPtr[ -5 ] << 32 ) | \
|
||||
( ( unsigned __int64 ) memPtr[ -4 ] << 24 ) | ( ( unsigned __int64 ) memPtr[ -3 ] << 16 ) | \
|
||||
( ( unsigned __int64 ) memPtr[ -2 ] << 8 ) | ( unsigned __int64 ) memPtr[ -1 ] )
|
||||
|
||||
#define mgetLong(memPtr) \
|
||||
( memPtr += 4, ( ( unsigned __int32 ) memPtr[ -4 ] << 24 ) | ( ( unsigned __int32 ) memPtr[ -3 ] << 16 ) | \
|
||||
( ( unsigned __int32 ) memPtr[ -2 ] << 8 ) | ( unsigned __int32 ) memPtr[ -1 ] )
|
||||
|
||||
#define mgetWord(memPtr) \
|
||||
( memPtr += 2, ((( unsigned short ) memPtr[ -2 ] << 8 ) | ( ( unsigned short ) memPtr[ -1 ] )) )
|
||||
|
||||
#define mgetByte(memPtr) \
|
||||
( ( unsigned char ) *memPtr++ )
|
||||
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
# define LE16(x) MirrorBytes16(x)
|
||||
# define LE32(x) MirrorBytes32(x)
|
||||
# define LE64(x) MirrorBytes64(x)
|
||||
#else
|
||||
# define LE16(x) (x)
|
||||
# define LE32(x) (x)
|
||||
# define LE64(x) (x)
|
||||
#endif
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
# define BE16(x) MirrorBytes16(x)
|
||||
# define BE32(x) MirrorBytes32(x)
|
||||
# define BE64(x) MirrorBytes64(x)
|
||||
#else
|
||||
# define BE16(x) (x)
|
||||
# define BE32(x) (x)
|
||||
# define BE64(x) (x)
|
||||
#endif
|
||||
|
||||
unsigned __int16 MirrorBytes16 (unsigned __int16 x);
|
||||
unsigned __int32 MirrorBytes32 (unsigned __int32 x);
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
uint64 MirrorBytes64 (uint64 x);
|
||||
#endif
|
||||
void LongReverse ( unsigned __int32 *buffer , unsigned byteCount );
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TC_ENDIAN_H */
|
||||
|
||||
@@ -1,123 +1,123 @@
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Common_Exception
|
||||
#define TC_HEADER_Common_Exception
|
||||
|
||||
#include "Platform/PlatformBase.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Language.h"
|
||||
#include <strsafe.h>
|
||||
|
||||
namespace VeraCrypt
|
||||
{
|
||||
struct Exception
|
||||
{
|
||||
virtual void Show (HWND parent) const = 0;
|
||||
};
|
||||
|
||||
struct SystemException : public Exception
|
||||
{
|
||||
SystemException (const char *srcPos) : ErrorCode (GetLastError()), SrcPos (srcPos) { }
|
||||
|
||||
void Show (HWND parent) const
|
||||
{
|
||||
SetLastError (ErrorCode);
|
||||
handleWin32Error (parent, SrcPos);
|
||||
}
|
||||
|
||||
DWORD ErrorCode;
|
||||
const char *SrcPos;
|
||||
};
|
||||
|
||||
struct ErrorException : public Exception
|
||||
{
|
||||
ErrorException (char *langId, const char *srcPos) : SrcPos (srcPos), ErrLangId (langId) { }
|
||||
ErrorException (const wstring &errMsg, const char *srcPos) : SrcPos (srcPos), ErrLangId(NULL), ErrMsg (errMsg) { }
|
||||
|
||||
void Show (HWND parent) const
|
||||
{
|
||||
if (ErrMsg.empty())
|
||||
::ErrorDirect (AppendSrcPos (GetString (ErrLangId? ErrLangId : ""), SrcPos).c_str (), parent);
|
||||
else
|
||||
::ErrorDirect (AppendSrcPos (ErrMsg.c_str(), SrcPos).c_str (), parent);
|
||||
}
|
||||
|
||||
const char *SrcPos;
|
||||
char *ErrLangId;
|
||||
wstring ErrMsg;
|
||||
};
|
||||
|
||||
struct ParameterIncorrect : public Exception
|
||||
{
|
||||
ParameterIncorrect (const char *srcPos) : SrcPos (srcPos) { }
|
||||
|
||||
void Show (HWND parent) const
|
||||
{
|
||||
string msgBody = "Parameter incorrect.\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n" + string (SrcPos) + ")";
|
||||
MessageBoxA (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
|
||||
}
|
||||
|
||||
const char *SrcPos;
|
||||
};
|
||||
|
||||
struct RandInitFailed : public Exception
|
||||
{
|
||||
RandInitFailed (const char *srcPos, DWORD dwLastError) : SrcPos (srcPos), LastError (dwLastError) { }
|
||||
|
||||
void Show (HWND parent) const
|
||||
{
|
||||
char szErrCode[16];
|
||||
StringCchPrintfA (szErrCode, ARRAYSIZE(szErrCode), "0x%.8X", LastError);
|
||||
string msgBody = "The Random Generator initialization failed.\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n" + string (SrcPos) + "\nLast Error = " + string (szErrCode) + ")";
|
||||
MessageBoxA (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
|
||||
}
|
||||
|
||||
const char *SrcPos;
|
||||
DWORD LastError;
|
||||
};
|
||||
|
||||
struct CryptoApiFailed : public Exception
|
||||
{
|
||||
CryptoApiFailed (const char *srcPos, DWORD dwLastError) : SrcPos (srcPos), LastError (dwLastError) { }
|
||||
|
||||
void Show (HWND parent) const
|
||||
{
|
||||
char szErrCode[16];
|
||||
StringCchPrintfA (szErrCode, ARRAYSIZE(szErrCode), "0x%.8X", LastError);
|
||||
string msgBody = "Windows Crypto API failed.\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n" + string (SrcPos) + "\nLast Error = " + string (szErrCode) + ")";
|
||||
MessageBoxA (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
|
||||
}
|
||||
|
||||
const char *SrcPos;
|
||||
DWORD LastError;
|
||||
};
|
||||
|
||||
struct TimeOut : public Exception
|
||||
{
|
||||
TimeOut (const char *srcPos) : SrcPos (srcPos) { }
|
||||
void Show (HWND parent) const { ErrorDirect (AppendSrcPos (L"Timeout", SrcPos).c_str (), parent); }
|
||||
|
||||
const char *SrcPos;
|
||||
};
|
||||
|
||||
struct UserAbort : public Exception
|
||||
{
|
||||
UserAbort (const char *srcPos) { }
|
||||
void Show (HWND parent) const { }
|
||||
};
|
||||
}
|
||||
|
||||
#define throw_sys_if(condition) do { if (condition) throw SystemException( SRC_POS ); } while (false)
|
||||
|
||||
|
||||
#endif // TC_HEADER_Common_Exception
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Common_Exception
|
||||
#define TC_HEADER_Common_Exception
|
||||
|
||||
#include "Platform/PlatformBase.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Language.h"
|
||||
#include <strsafe.h>
|
||||
|
||||
namespace VeraCrypt
|
||||
{
|
||||
struct Exception
|
||||
{
|
||||
virtual void Show (HWND parent) const = 0;
|
||||
};
|
||||
|
||||
struct SystemException : public Exception
|
||||
{
|
||||
SystemException (const char *srcPos) : ErrorCode (GetLastError()), SrcPos (srcPos) { }
|
||||
|
||||
void Show (HWND parent) const
|
||||
{
|
||||
SetLastError (ErrorCode);
|
||||
handleWin32Error (parent, SrcPos);
|
||||
}
|
||||
|
||||
DWORD ErrorCode;
|
||||
const char *SrcPos;
|
||||
};
|
||||
|
||||
struct ErrorException : public Exception
|
||||
{
|
||||
ErrorException (char *langId, const char *srcPos) : SrcPos (srcPos), ErrLangId (langId) { }
|
||||
ErrorException (const wstring &errMsg, const char *srcPos) : SrcPos (srcPos), ErrLangId(NULL), ErrMsg (errMsg) { }
|
||||
|
||||
void Show (HWND parent) const
|
||||
{
|
||||
if (ErrMsg.empty())
|
||||
::ErrorDirect (AppendSrcPos (GetString (ErrLangId? ErrLangId : ""), SrcPos).c_str (), parent);
|
||||
else
|
||||
::ErrorDirect (AppendSrcPos (ErrMsg.c_str(), SrcPos).c_str (), parent);
|
||||
}
|
||||
|
||||
const char *SrcPos;
|
||||
char *ErrLangId;
|
||||
wstring ErrMsg;
|
||||
};
|
||||
|
||||
struct ParameterIncorrect : public Exception
|
||||
{
|
||||
ParameterIncorrect (const char *srcPos) : SrcPos (srcPos) { }
|
||||
|
||||
void Show (HWND parent) const
|
||||
{
|
||||
string msgBody = "Parameter incorrect.\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n" + string (SrcPos) + ")";
|
||||
MessageBoxA (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
|
||||
}
|
||||
|
||||
const char *SrcPos;
|
||||
};
|
||||
|
||||
struct RandInitFailed : public Exception
|
||||
{
|
||||
RandInitFailed (const char *srcPos, DWORD dwLastError) : SrcPos (srcPos), LastError (dwLastError) { }
|
||||
|
||||
void Show (HWND parent) const
|
||||
{
|
||||
char szErrCode[16];
|
||||
StringCchPrintfA (szErrCode, ARRAYSIZE(szErrCode), "0x%.8X", LastError);
|
||||
string msgBody = "The Random Generator initialization failed.\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n" + string (SrcPos) + "\nLast Error = " + string (szErrCode) + ")";
|
||||
MessageBoxA (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
|
||||
}
|
||||
|
||||
const char *SrcPos;
|
||||
DWORD LastError;
|
||||
};
|
||||
|
||||
struct CryptoApiFailed : public Exception
|
||||
{
|
||||
CryptoApiFailed (const char *srcPos, DWORD dwLastError) : SrcPos (srcPos), LastError (dwLastError) { }
|
||||
|
||||
void Show (HWND parent) const
|
||||
{
|
||||
char szErrCode[16];
|
||||
StringCchPrintfA (szErrCode, ARRAYSIZE(szErrCode), "0x%.8X", LastError);
|
||||
string msgBody = "Windows Crypto API failed.\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n" + string (SrcPos) + "\nLast Error = " + string (szErrCode) + ")";
|
||||
MessageBoxA (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
|
||||
}
|
||||
|
||||
const char *SrcPos;
|
||||
DWORD LastError;
|
||||
};
|
||||
|
||||
struct TimeOut : public Exception
|
||||
{
|
||||
TimeOut (const char *srcPos) : SrcPos (srcPos) { }
|
||||
void Show (HWND parent) const { ErrorDirect (AppendSrcPos (L"Timeout", SrcPos).c_str (), parent); }
|
||||
|
||||
const char *SrcPos;
|
||||
};
|
||||
|
||||
struct UserAbort : public Exception
|
||||
{
|
||||
UserAbort (const char *srcPos) { }
|
||||
void Show (HWND parent) const { }
|
||||
};
|
||||
}
|
||||
|
||||
#define throw_sys_if(condition) do { if (condition) throw SystemException( SRC_POS ); } while (false)
|
||||
|
||||
|
||||
#endif // TC_HEADER_Common_Exception
|
||||
|
||||
898
src/Common/Fat.c
898
src/Common/Fat.c
@@ -1,449 +1,449 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#include "Crypto.h"
|
||||
#include "Common/Endian.h"
|
||||
#include "Format.h"
|
||||
#include "Fat.h"
|
||||
#include "Progress.h"
|
||||
#include "Random.h"
|
||||
#include "Volumes.h"
|
||||
|
||||
void
|
||||
GetFatParams (fatparams * ft)
|
||||
{
|
||||
uint64 volumeSize = (uint64) ft->num_sectors * ft->sector_size;
|
||||
unsigned int fatsecs;
|
||||
|
||||
if(ft->cluster_size == 0) // 'Default' cluster size
|
||||
{
|
||||
uint32 clusterSize;
|
||||
|
||||
// Determine optimal cluster size to minimize FAT size (mounting delay), maximize number of files, keep 4 KB alignment, etc.
|
||||
if (volumeSize >= 2 * BYTES_PER_TB)
|
||||
clusterSize = 256 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 512 * BYTES_PER_GB)
|
||||
clusterSize = 128 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 128 * BYTES_PER_GB)
|
||||
clusterSize = 64 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 64 * BYTES_PER_GB)
|
||||
clusterSize = 32 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 32 * BYTES_PER_GB)
|
||||
clusterSize = 16 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 16 * BYTES_PER_GB)
|
||||
clusterSize = 8 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 512 * BYTES_PER_MB)
|
||||
clusterSize = 4 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 256 * BYTES_PER_MB)
|
||||
clusterSize = 2 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 1 * BYTES_PER_MB)
|
||||
clusterSize = 1 * BYTES_PER_KB;
|
||||
else
|
||||
clusterSize = 512;
|
||||
|
||||
ft->cluster_size = clusterSize / ft->sector_size;
|
||||
|
||||
if (ft->cluster_size == 0)
|
||||
ft->cluster_size = 1;
|
||||
|
||||
if (((unsigned __int64) ft->cluster_size * ft->sector_size) > TC_MAX_FAT_CLUSTER_SIZE)
|
||||
ft->cluster_size = TC_MAX_FAT_CLUSTER_SIZE / ft->sector_size;
|
||||
|
||||
if (ft->cluster_size > 128)
|
||||
ft->cluster_size = 128;
|
||||
}
|
||||
|
||||
if (volumeSize <= TC_MAX_FAT_CLUSTER_SIZE * 4)
|
||||
ft->cluster_size = 1;
|
||||
|
||||
// Geometry always set to SECTORS/1/1
|
||||
ft->secs_track = 1;
|
||||
ft->heads = 1;
|
||||
|
||||
ft->dir_entries = 512;
|
||||
ft->fats = 2;
|
||||
ft->media = 0xf8;
|
||||
ft->hidden = 0;
|
||||
|
||||
ft->size_root_dir = ft->dir_entries * 32;
|
||||
|
||||
// FAT12
|
||||
ft->size_fat = 12;
|
||||
ft->reserved = 2;
|
||||
fatsecs = ft->num_sectors - (ft->size_root_dir + ft->sector_size - 1) / ft->sector_size - ft->reserved;
|
||||
ft->cluster_count = (int) (((unsigned __int64) fatsecs * ft->sector_size) / ((unsigned __int64) ft->cluster_size * ft->sector_size));
|
||||
ft->fat_length = (((ft->cluster_count * 3 + 1) >> 1) + ft->sector_size - 1) / ft->sector_size;
|
||||
|
||||
if (ft->cluster_count >= 4085) // FAT16
|
||||
{
|
||||
ft->size_fat = 16;
|
||||
ft->reserved = 2;
|
||||
fatsecs = ft->num_sectors - (ft->size_root_dir + ft->sector_size - 1) / ft->sector_size - ft->reserved;
|
||||
ft->cluster_count = (int) (((__int64) fatsecs * ft->sector_size) / (ft->cluster_size * ft->sector_size));
|
||||
ft->fat_length = (ft->cluster_count * 2 + ft->sector_size - 1) / ft->sector_size;
|
||||
}
|
||||
|
||||
if(ft->cluster_count >= 65525) // FAT32
|
||||
{
|
||||
ft->size_fat = 32;
|
||||
ft->reserved = 32 - 1;
|
||||
|
||||
do
|
||||
{
|
||||
ft->reserved++;
|
||||
|
||||
fatsecs = ft->num_sectors - ft->reserved;
|
||||
ft->size_root_dir = ft->cluster_size * ft->sector_size;
|
||||
ft->cluster_count = (int) (((unsigned __int64) fatsecs * ft->sector_size) / (ft->cluster_size * ft->sector_size));
|
||||
ft->fat_length = (ft->cluster_count * 4 + ft->sector_size - 1) / ft->sector_size;
|
||||
|
||||
// Align data area on TC_MAX_VOLUME_SECTOR_SIZE
|
||||
|
||||
} while (ft->sector_size == TC_SECTOR_SIZE_LEGACY
|
||||
&& (ft->reserved * ft->sector_size + ft->fat_length * ft->fats * ft->sector_size) % TC_MAX_VOLUME_SECTOR_SIZE != 0);
|
||||
}
|
||||
|
||||
ft->cluster_count -= ft->fat_length * ft->fats / ft->cluster_size;
|
||||
|
||||
if (ft->num_sectors >= 65536 || ft->size_fat == 32)
|
||||
{
|
||||
ft->sectors = 0;
|
||||
ft->total_sect = ft->num_sectors;
|
||||
}
|
||||
else
|
||||
{
|
||||
ft->sectors = (uint16) ft->num_sectors;
|
||||
ft->total_sect = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PutBoot (fatparams * ft, unsigned char *boot)
|
||||
{
|
||||
int cnt = 0;
|
||||
|
||||
boot[cnt++] = 0xeb; /* boot jump */
|
||||
boot[cnt++] = 0x3c;
|
||||
boot[cnt++] = 0x90;
|
||||
memcpy (boot + cnt, "MSDOS5.0", 8); /* system id */
|
||||
cnt += 8;
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->sector_size); /* bytes per sector */
|
||||
cnt += 2;
|
||||
boot[cnt++] = (__int8) ft->cluster_size; /* sectors per cluster */
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->reserved); /* reserved sectors */
|
||||
cnt += 2;
|
||||
boot[cnt++] = (__int8) ft->fats; /* 2 fats */
|
||||
|
||||
if(ft->size_fat == 32)
|
||||
{
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x00;
|
||||
}
|
||||
else
|
||||
{
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->dir_entries); /* 512 root entries */
|
||||
cnt += 2;
|
||||
}
|
||||
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->sectors); /* # sectors */
|
||||
cnt += 2;
|
||||
boot[cnt++] = (__int8) ft->media; /* media byte */
|
||||
|
||||
if(ft->size_fat == 32)
|
||||
{
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x00;
|
||||
}
|
||||
else
|
||||
{
|
||||
*(__int16 *)(boot + cnt) = LE16((uint16) ft->fat_length); /* fat size */
|
||||
cnt += 2;
|
||||
}
|
||||
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->secs_track); /* # sectors per track */
|
||||
cnt += 2;
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->heads); /* # heads */
|
||||
cnt += 2;
|
||||
*(__int32 *)(boot + cnt) = LE32(ft->hidden); /* # hidden sectors */
|
||||
cnt += 4;
|
||||
*(__int32 *)(boot + cnt) = LE32(ft->total_sect); /* # huge sectors */
|
||||
cnt += 4;
|
||||
|
||||
if(ft->size_fat == 32)
|
||||
{
|
||||
*(__int32 *)(boot + cnt) = LE32(ft->fat_length); cnt += 4; /* fat size 32 */
|
||||
boot[cnt++] = 0x00; /* ExtFlags */
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x00; /* FSVer */
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x02; /* RootClus */
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x01; /* FSInfo */
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x06; /* BkBootSec */
|
||||
boot[cnt++] = 0x00;
|
||||
memset(boot+cnt, 0, 12); cnt+=12; /* Reserved */
|
||||
}
|
||||
|
||||
boot[cnt++] = 0x00; /* drive number */ // FIXED 80 > 00
|
||||
boot[cnt++] = 0x00; /* reserved */
|
||||
boot[cnt++] = 0x29; /* boot sig */
|
||||
|
||||
memcpy (boot + cnt, ft->volume_id, 4); /* vol id */
|
||||
cnt += 4;
|
||||
|
||||
memcpy (boot + cnt, ft->volume_name, 11); /* vol title */
|
||||
cnt += 11;
|
||||
|
||||
switch(ft->size_fat) /* filesystem type */
|
||||
{
|
||||
case 12: memcpy (boot + cnt, "FAT12 ", 8); break;
|
||||
case 16: memcpy (boot + cnt, "FAT16 ", 8); break;
|
||||
case 32: memcpy (boot + cnt, "FAT32 ", 8); break;
|
||||
}
|
||||
cnt += 8;
|
||||
|
||||
memset (boot + cnt, 0, ft->size_fat==32 ? 420:448); /* boot code */
|
||||
cnt += ft->size_fat==32 ? 420:448;
|
||||
boot[cnt++] = 0x55;
|
||||
boot[cnt++] = 0xaa; /* boot sig */
|
||||
}
|
||||
|
||||
|
||||
/* FAT32 FSInfo */
|
||||
static void PutFSInfo (unsigned char *sector, fatparams *ft)
|
||||
{
|
||||
memset (sector, 0, ft->sector_size);
|
||||
sector[3]=0x41; /* LeadSig */
|
||||
sector[2]=0x61;
|
||||
sector[1]=0x52;
|
||||
sector[0]=0x52;
|
||||
sector[484+3]=0x61; /* StrucSig */
|
||||
sector[484+2]=0x41;
|
||||
sector[484+1]=0x72;
|
||||
sector[484+0]=0x72;
|
||||
|
||||
// Free cluster count
|
||||
*(uint32 *)(sector + 488) = LE32 (ft->cluster_count - ft->size_root_dir / ft->sector_size / ft->cluster_size);
|
||||
|
||||
// Next free cluster
|
||||
*(uint32 *)(sector + 492) = LE32 (2);
|
||||
|
||||
sector[508+3]=0xaa; /* TrailSig */
|
||||
sector[508+2]=0x55;
|
||||
sector[508+1]=0x00;
|
||||
sector[508+0]=0x00;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void * dev, PCRYPTO_INFO cryptoInfo, BOOL quickFormat)
|
||||
{
|
||||
int write_buf_cnt = 0;
|
||||
char sector[TC_MAX_VOLUME_SECTOR_SIZE], *write_buf;
|
||||
unsigned __int64 nSecNo = startSector;
|
||||
int x, n;
|
||||
int retVal;
|
||||
char temporaryKey[MASTER_KEYDATA_SIZE];
|
||||
HWND hwndDlg = (HWND) hwndDlgPtr;
|
||||
|
||||
LARGE_INTEGER startOffset;
|
||||
LARGE_INTEGER newOffset;
|
||||
|
||||
// Seek to start sector
|
||||
startOffset.QuadPart = startSector * ft->sector_size;
|
||||
if (!SetFilePointerEx ((HANDLE) dev, startOffset, &newOffset, FILE_BEGIN)
|
||||
|| newOffset.QuadPart != startOffset.QuadPart)
|
||||
{
|
||||
return ERR_VOL_SEEKING;
|
||||
}
|
||||
|
||||
/* Write the data area */
|
||||
|
||||
write_buf = (char *)TCalloc (FormatWriteBufferSize);
|
||||
if (!write_buf)
|
||||
return ERR_OUTOFMEMORY;
|
||||
|
||||
memset (sector, 0, ft->sector_size);
|
||||
|
||||
if (!RandgetBytes (hwndDlg, ft->volume_id, sizeof (ft->volume_id), FALSE))
|
||||
goto fail;
|
||||
|
||||
PutBoot (ft, (unsigned char *) sector);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
|
||||
/* fat32 boot area */
|
||||
if (ft->size_fat == 32)
|
||||
{
|
||||
/* fsinfo */
|
||||
PutFSInfo((unsigned char *) sector, ft);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
|
||||
/* reserved */
|
||||
while (nSecNo - startSector < 6)
|
||||
{
|
||||
memset (sector, 0, ft->sector_size);
|
||||
sector[508+3]=0xaa; /* TrailSig */
|
||||
sector[508+2]=0x55;
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* bootsector backup */
|
||||
memset (sector, 0, ft->sector_size);
|
||||
PutBoot (ft, (unsigned char *) sector);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
|
||||
PutFSInfo((unsigned char *) sector, ft);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* reserved */
|
||||
while (nSecNo - startSector < (unsigned int)ft->reserved)
|
||||
{
|
||||
memset (sector, 0, ft->sector_size);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* write fat */
|
||||
for (x = 1; x <= ft->fats; x++)
|
||||
{
|
||||
for (n = 0; n < ft->fat_length; n++)
|
||||
{
|
||||
memset (sector, 0, ft->sector_size);
|
||||
|
||||
if (n == 0)
|
||||
{
|
||||
unsigned char fat_sig[12];
|
||||
if (ft->size_fat == 32)
|
||||
{
|
||||
fat_sig[0] = (unsigned char) ft->media;
|
||||
fat_sig[1] = fat_sig[2] = 0xff;
|
||||
fat_sig[3] = 0x0f;
|
||||
fat_sig[4] = fat_sig[5] = fat_sig[6] = 0xff;
|
||||
fat_sig[7] = 0x0f;
|
||||
fat_sig[8] = fat_sig[9] = fat_sig[10] = 0xff;
|
||||
fat_sig[11] = 0x0f;
|
||||
memcpy (sector, fat_sig, 12);
|
||||
}
|
||||
else if (ft->size_fat == 16)
|
||||
{
|
||||
fat_sig[0] = (unsigned char) ft->media;
|
||||
fat_sig[1] = 0xff;
|
||||
fat_sig[2] = 0xff;
|
||||
fat_sig[3] = 0xff;
|
||||
memcpy (sector, fat_sig, 4);
|
||||
}
|
||||
else if (ft->size_fat == 12)
|
||||
{
|
||||
fat_sig[0] = (unsigned char) ft->media;
|
||||
fat_sig[1] = 0xff;
|
||||
fat_sig[2] = 0xff;
|
||||
fat_sig[3] = 0x00;
|
||||
memcpy (sector, fat_sig, 4);
|
||||
}
|
||||
}
|
||||
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* write rootdir */
|
||||
for (x = 0; x < ft->size_root_dir / ft->sector_size; x++)
|
||||
{
|
||||
memset (sector, 0, ft->sector_size);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
|
||||
}
|
||||
|
||||
/* Fill the rest of the data area with random data */
|
||||
|
||||
if(!quickFormat)
|
||||
{
|
||||
if (!FlushFormatWriteBuffer (dev, write_buf, &write_buf_cnt, &nSecNo, cryptoInfo))
|
||||
goto fail;
|
||||
|
||||
/* Generate a random temporary key set to be used for "dummy" encryption that will fill
|
||||
the free disk space (data area) with random data. This is necessary for plausible
|
||||
deniability of hidden volumes (and also reduces the amount of predictable plaintext
|
||||
within the volume). */
|
||||
|
||||
// Temporary master key
|
||||
if (!RandgetBytes (hwndDlg, temporaryKey, EAGetKeySize (cryptoInfo->ea), FALSE))
|
||||
goto fail;
|
||||
|
||||
// Temporary secondary key (XTS mode)
|
||||
if (!RandgetBytes (hwndDlg, cryptoInfo->k2, sizeof cryptoInfo->k2, FALSE))
|
||||
goto fail;
|
||||
|
||||
retVal = EAInit (cryptoInfo->ea, temporaryKey, cryptoInfo->ks);
|
||||
if (retVal != ERR_SUCCESS)
|
||||
{
|
||||
burn (temporaryKey, sizeof(temporaryKey));
|
||||
return retVal;
|
||||
}
|
||||
if (!EAInitMode (cryptoInfo))
|
||||
{
|
||||
burn (temporaryKey, sizeof(temporaryKey));
|
||||
return ERR_MODE_INIT_FAILED;
|
||||
}
|
||||
|
||||
x = ft->num_sectors - ft->reserved - ft->size_root_dir / ft->sector_size - ft->fat_length * 2;
|
||||
while (x--)
|
||||
{
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
UpdateProgressBar (nSecNo * ft->sector_size);
|
||||
}
|
||||
else
|
||||
UpdateProgressBar ((uint64) ft->num_sectors * ft->sector_size);
|
||||
|
||||
if (!FlushFormatWriteBuffer (dev, write_buf, &write_buf_cnt, &nSecNo, cryptoInfo))
|
||||
goto fail;
|
||||
|
||||
TCfree (write_buf);
|
||||
burn (temporaryKey, sizeof(temporaryKey));
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
|
||||
TCfree (write_buf);
|
||||
burn (temporaryKey, sizeof(temporaryKey));
|
||||
return ERR_OS_ERROR;
|
||||
}
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#include "Crypto.h"
|
||||
#include "Common/Endian.h"
|
||||
#include "Format.h"
|
||||
#include "Fat.h"
|
||||
#include "Progress.h"
|
||||
#include "Random.h"
|
||||
#include "Volumes.h"
|
||||
|
||||
void
|
||||
GetFatParams (fatparams * ft)
|
||||
{
|
||||
uint64 volumeSize = (uint64) ft->num_sectors * ft->sector_size;
|
||||
unsigned int fatsecs;
|
||||
|
||||
if(ft->cluster_size == 0) // 'Default' cluster size
|
||||
{
|
||||
uint32 clusterSize;
|
||||
|
||||
// Determine optimal cluster size to minimize FAT size (mounting delay), maximize number of files, keep 4 KB alignment, etc.
|
||||
if (volumeSize >= 2 * BYTES_PER_TB)
|
||||
clusterSize = 256 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 512 * BYTES_PER_GB)
|
||||
clusterSize = 128 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 128 * BYTES_PER_GB)
|
||||
clusterSize = 64 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 64 * BYTES_PER_GB)
|
||||
clusterSize = 32 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 32 * BYTES_PER_GB)
|
||||
clusterSize = 16 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 16 * BYTES_PER_GB)
|
||||
clusterSize = 8 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 512 * BYTES_PER_MB)
|
||||
clusterSize = 4 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 256 * BYTES_PER_MB)
|
||||
clusterSize = 2 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 1 * BYTES_PER_MB)
|
||||
clusterSize = 1 * BYTES_PER_KB;
|
||||
else
|
||||
clusterSize = 512;
|
||||
|
||||
ft->cluster_size = clusterSize / ft->sector_size;
|
||||
|
||||
if (ft->cluster_size == 0)
|
||||
ft->cluster_size = 1;
|
||||
|
||||
if (((unsigned __int64) ft->cluster_size * ft->sector_size) > TC_MAX_FAT_CLUSTER_SIZE)
|
||||
ft->cluster_size = TC_MAX_FAT_CLUSTER_SIZE / ft->sector_size;
|
||||
|
||||
if (ft->cluster_size > 128)
|
||||
ft->cluster_size = 128;
|
||||
}
|
||||
|
||||
if (volumeSize <= TC_MAX_FAT_CLUSTER_SIZE * 4)
|
||||
ft->cluster_size = 1;
|
||||
|
||||
// Geometry always set to SECTORS/1/1
|
||||
ft->secs_track = 1;
|
||||
ft->heads = 1;
|
||||
|
||||
ft->dir_entries = 512;
|
||||
ft->fats = 2;
|
||||
ft->media = 0xf8;
|
||||
ft->hidden = 0;
|
||||
|
||||
ft->size_root_dir = ft->dir_entries * 32;
|
||||
|
||||
// FAT12
|
||||
ft->size_fat = 12;
|
||||
ft->reserved = 2;
|
||||
fatsecs = ft->num_sectors - (ft->size_root_dir + ft->sector_size - 1) / ft->sector_size - ft->reserved;
|
||||
ft->cluster_count = (int) (((unsigned __int64) fatsecs * ft->sector_size) / ((unsigned __int64) ft->cluster_size * ft->sector_size));
|
||||
ft->fat_length = (((ft->cluster_count * 3 + 1) >> 1) + ft->sector_size - 1) / ft->sector_size;
|
||||
|
||||
if (ft->cluster_count >= 4085) // FAT16
|
||||
{
|
||||
ft->size_fat = 16;
|
||||
ft->reserved = 2;
|
||||
fatsecs = ft->num_sectors - (ft->size_root_dir + ft->sector_size - 1) / ft->sector_size - ft->reserved;
|
||||
ft->cluster_count = (int) (((__int64) fatsecs * ft->sector_size) / (ft->cluster_size * ft->sector_size));
|
||||
ft->fat_length = (ft->cluster_count * 2 + ft->sector_size - 1) / ft->sector_size;
|
||||
}
|
||||
|
||||
if(ft->cluster_count >= 65525) // FAT32
|
||||
{
|
||||
ft->size_fat = 32;
|
||||
ft->reserved = 32 - 1;
|
||||
|
||||
do
|
||||
{
|
||||
ft->reserved++;
|
||||
|
||||
fatsecs = ft->num_sectors - ft->reserved;
|
||||
ft->size_root_dir = ft->cluster_size * ft->sector_size;
|
||||
ft->cluster_count = (int) (((unsigned __int64) fatsecs * ft->sector_size) / (ft->cluster_size * ft->sector_size));
|
||||
ft->fat_length = (ft->cluster_count * 4 + ft->sector_size - 1) / ft->sector_size;
|
||||
|
||||
// Align data area on TC_MAX_VOLUME_SECTOR_SIZE
|
||||
|
||||
} while (ft->sector_size == TC_SECTOR_SIZE_LEGACY
|
||||
&& (ft->reserved * ft->sector_size + ft->fat_length * ft->fats * ft->sector_size) % TC_MAX_VOLUME_SECTOR_SIZE != 0);
|
||||
}
|
||||
|
||||
ft->cluster_count -= ft->fat_length * ft->fats / ft->cluster_size;
|
||||
|
||||
if (ft->num_sectors >= 65536 || ft->size_fat == 32)
|
||||
{
|
||||
ft->sectors = 0;
|
||||
ft->total_sect = ft->num_sectors;
|
||||
}
|
||||
else
|
||||
{
|
||||
ft->sectors = (uint16) ft->num_sectors;
|
||||
ft->total_sect = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PutBoot (fatparams * ft, unsigned char *boot)
|
||||
{
|
||||
int cnt = 0;
|
||||
|
||||
boot[cnt++] = 0xeb; /* boot jump */
|
||||
boot[cnt++] = 0x3c;
|
||||
boot[cnt++] = 0x90;
|
||||
memcpy (boot + cnt, "MSDOS5.0", 8); /* system id */
|
||||
cnt += 8;
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->sector_size); /* bytes per sector */
|
||||
cnt += 2;
|
||||
boot[cnt++] = (__int8) ft->cluster_size; /* sectors per cluster */
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->reserved); /* reserved sectors */
|
||||
cnt += 2;
|
||||
boot[cnt++] = (__int8) ft->fats; /* 2 fats */
|
||||
|
||||
if(ft->size_fat == 32)
|
||||
{
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x00;
|
||||
}
|
||||
else
|
||||
{
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->dir_entries); /* 512 root entries */
|
||||
cnt += 2;
|
||||
}
|
||||
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->sectors); /* # sectors */
|
||||
cnt += 2;
|
||||
boot[cnt++] = (__int8) ft->media; /* media byte */
|
||||
|
||||
if(ft->size_fat == 32)
|
||||
{
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x00;
|
||||
}
|
||||
else
|
||||
{
|
||||
*(__int16 *)(boot + cnt) = LE16((uint16) ft->fat_length); /* fat size */
|
||||
cnt += 2;
|
||||
}
|
||||
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->secs_track); /* # sectors per track */
|
||||
cnt += 2;
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->heads); /* # heads */
|
||||
cnt += 2;
|
||||
*(__int32 *)(boot + cnt) = LE32(ft->hidden); /* # hidden sectors */
|
||||
cnt += 4;
|
||||
*(__int32 *)(boot + cnt) = LE32(ft->total_sect); /* # huge sectors */
|
||||
cnt += 4;
|
||||
|
||||
if(ft->size_fat == 32)
|
||||
{
|
||||
*(__int32 *)(boot + cnt) = LE32(ft->fat_length); cnt += 4; /* fat size 32 */
|
||||
boot[cnt++] = 0x00; /* ExtFlags */
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x00; /* FSVer */
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x02; /* RootClus */
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x01; /* FSInfo */
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x06; /* BkBootSec */
|
||||
boot[cnt++] = 0x00;
|
||||
memset(boot+cnt, 0, 12); cnt+=12; /* Reserved */
|
||||
}
|
||||
|
||||
boot[cnt++] = 0x00; /* drive number */ // FIXED 80 > 00
|
||||
boot[cnt++] = 0x00; /* reserved */
|
||||
boot[cnt++] = 0x29; /* boot sig */
|
||||
|
||||
memcpy (boot + cnt, ft->volume_id, 4); /* vol id */
|
||||
cnt += 4;
|
||||
|
||||
memcpy (boot + cnt, ft->volume_name, 11); /* vol title */
|
||||
cnt += 11;
|
||||
|
||||
switch(ft->size_fat) /* filesystem type */
|
||||
{
|
||||
case 12: memcpy (boot + cnt, "FAT12 ", 8); break;
|
||||
case 16: memcpy (boot + cnt, "FAT16 ", 8); break;
|
||||
case 32: memcpy (boot + cnt, "FAT32 ", 8); break;
|
||||
}
|
||||
cnt += 8;
|
||||
|
||||
memset (boot + cnt, 0, ft->size_fat==32 ? 420:448); /* boot code */
|
||||
cnt += ft->size_fat==32 ? 420:448;
|
||||
boot[cnt++] = 0x55;
|
||||
boot[cnt++] = 0xaa; /* boot sig */
|
||||
}
|
||||
|
||||
|
||||
/* FAT32 FSInfo */
|
||||
static void PutFSInfo (unsigned char *sector, fatparams *ft)
|
||||
{
|
||||
memset (sector, 0, ft->sector_size);
|
||||
sector[3]=0x41; /* LeadSig */
|
||||
sector[2]=0x61;
|
||||
sector[1]=0x52;
|
||||
sector[0]=0x52;
|
||||
sector[484+3]=0x61; /* StrucSig */
|
||||
sector[484+2]=0x41;
|
||||
sector[484+1]=0x72;
|
||||
sector[484+0]=0x72;
|
||||
|
||||
// Free cluster count
|
||||
*(uint32 *)(sector + 488) = LE32 (ft->cluster_count - ft->size_root_dir / ft->sector_size / ft->cluster_size);
|
||||
|
||||
// Next free cluster
|
||||
*(uint32 *)(sector + 492) = LE32 (2);
|
||||
|
||||
sector[508+3]=0xaa; /* TrailSig */
|
||||
sector[508+2]=0x55;
|
||||
sector[508+1]=0x00;
|
||||
sector[508+0]=0x00;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void * dev, PCRYPTO_INFO cryptoInfo, BOOL quickFormat)
|
||||
{
|
||||
int write_buf_cnt = 0;
|
||||
char sector[TC_MAX_VOLUME_SECTOR_SIZE], *write_buf;
|
||||
unsigned __int64 nSecNo = startSector;
|
||||
int x, n;
|
||||
int retVal;
|
||||
char temporaryKey[MASTER_KEYDATA_SIZE];
|
||||
HWND hwndDlg = (HWND) hwndDlgPtr;
|
||||
|
||||
LARGE_INTEGER startOffset;
|
||||
LARGE_INTEGER newOffset;
|
||||
|
||||
// Seek to start sector
|
||||
startOffset.QuadPart = startSector * ft->sector_size;
|
||||
if (!SetFilePointerEx ((HANDLE) dev, startOffset, &newOffset, FILE_BEGIN)
|
||||
|| newOffset.QuadPart != startOffset.QuadPart)
|
||||
{
|
||||
return ERR_VOL_SEEKING;
|
||||
}
|
||||
|
||||
/* Write the data area */
|
||||
|
||||
write_buf = (char *)TCalloc (FormatWriteBufferSize);
|
||||
if (!write_buf)
|
||||
return ERR_OUTOFMEMORY;
|
||||
|
||||
memset (sector, 0, ft->sector_size);
|
||||
|
||||
if (!RandgetBytes (hwndDlg, ft->volume_id, sizeof (ft->volume_id), FALSE))
|
||||
goto fail;
|
||||
|
||||
PutBoot (ft, (unsigned char *) sector);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
|
||||
/* fat32 boot area */
|
||||
if (ft->size_fat == 32)
|
||||
{
|
||||
/* fsinfo */
|
||||
PutFSInfo((unsigned char *) sector, ft);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
|
||||
/* reserved */
|
||||
while (nSecNo - startSector < 6)
|
||||
{
|
||||
memset (sector, 0, ft->sector_size);
|
||||
sector[508+3]=0xaa; /* TrailSig */
|
||||
sector[508+2]=0x55;
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* bootsector backup */
|
||||
memset (sector, 0, ft->sector_size);
|
||||
PutBoot (ft, (unsigned char *) sector);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
|
||||
PutFSInfo((unsigned char *) sector, ft);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* reserved */
|
||||
while (nSecNo - startSector < (unsigned int)ft->reserved)
|
||||
{
|
||||
memset (sector, 0, ft->sector_size);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* write fat */
|
||||
for (x = 1; x <= ft->fats; x++)
|
||||
{
|
||||
for (n = 0; n < ft->fat_length; n++)
|
||||
{
|
||||
memset (sector, 0, ft->sector_size);
|
||||
|
||||
if (n == 0)
|
||||
{
|
||||
unsigned char fat_sig[12];
|
||||
if (ft->size_fat == 32)
|
||||
{
|
||||
fat_sig[0] = (unsigned char) ft->media;
|
||||
fat_sig[1] = fat_sig[2] = 0xff;
|
||||
fat_sig[3] = 0x0f;
|
||||
fat_sig[4] = fat_sig[5] = fat_sig[6] = 0xff;
|
||||
fat_sig[7] = 0x0f;
|
||||
fat_sig[8] = fat_sig[9] = fat_sig[10] = 0xff;
|
||||
fat_sig[11] = 0x0f;
|
||||
memcpy (sector, fat_sig, 12);
|
||||
}
|
||||
else if (ft->size_fat == 16)
|
||||
{
|
||||
fat_sig[0] = (unsigned char) ft->media;
|
||||
fat_sig[1] = 0xff;
|
||||
fat_sig[2] = 0xff;
|
||||
fat_sig[3] = 0xff;
|
||||
memcpy (sector, fat_sig, 4);
|
||||
}
|
||||
else if (ft->size_fat == 12)
|
||||
{
|
||||
fat_sig[0] = (unsigned char) ft->media;
|
||||
fat_sig[1] = 0xff;
|
||||
fat_sig[2] = 0xff;
|
||||
fat_sig[3] = 0x00;
|
||||
memcpy (sector, fat_sig, 4);
|
||||
}
|
||||
}
|
||||
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* write rootdir */
|
||||
for (x = 0; x < ft->size_root_dir / ft->sector_size; x++)
|
||||
{
|
||||
memset (sector, 0, ft->sector_size);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
|
||||
}
|
||||
|
||||
/* Fill the rest of the data area with random data */
|
||||
|
||||
if(!quickFormat)
|
||||
{
|
||||
if (!FlushFormatWriteBuffer (dev, write_buf, &write_buf_cnt, &nSecNo, cryptoInfo))
|
||||
goto fail;
|
||||
|
||||
/* Generate a random temporary key set to be used for "dummy" encryption that will fill
|
||||
the free disk space (data area) with random data. This is necessary for plausible
|
||||
deniability of hidden volumes (and also reduces the amount of predictable plaintext
|
||||
within the volume). */
|
||||
|
||||
// Temporary master key
|
||||
if (!RandgetBytes (hwndDlg, temporaryKey, EAGetKeySize (cryptoInfo->ea), FALSE))
|
||||
goto fail;
|
||||
|
||||
// Temporary secondary key (XTS mode)
|
||||
if (!RandgetBytes (hwndDlg, cryptoInfo->k2, sizeof cryptoInfo->k2, FALSE))
|
||||
goto fail;
|
||||
|
||||
retVal = EAInit (cryptoInfo->ea, temporaryKey, cryptoInfo->ks);
|
||||
if (retVal != ERR_SUCCESS)
|
||||
{
|
||||
burn (temporaryKey, sizeof(temporaryKey));
|
||||
return retVal;
|
||||
}
|
||||
if (!EAInitMode (cryptoInfo))
|
||||
{
|
||||
burn (temporaryKey, sizeof(temporaryKey));
|
||||
return ERR_MODE_INIT_FAILED;
|
||||
}
|
||||
|
||||
x = ft->num_sectors - ft->reserved - ft->size_root_dir / ft->sector_size - ft->fat_length * 2;
|
||||
while (x--)
|
||||
{
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
UpdateProgressBar (nSecNo * ft->sector_size);
|
||||
}
|
||||
else
|
||||
UpdateProgressBar ((uint64) ft->num_sectors * ft->sector_size);
|
||||
|
||||
if (!FlushFormatWriteBuffer (dev, write_buf, &write_buf_cnt, &nSecNo, cryptoInfo))
|
||||
goto fail;
|
||||
|
||||
TCfree (write_buf);
|
||||
burn (temporaryKey, sizeof(temporaryKey));
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
|
||||
TCfree (write_buf);
|
||||
burn (temporaryKey, sizeof(temporaryKey));
|
||||
return ERR_OS_ERROR;
|
||||
}
|
||||
|
||||
138
src/Common/Fat.h
138
src/Common/Fat.h
@@ -1,69 +1,69 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
typedef struct fatparams_t
|
||||
{
|
||||
char volume_name[11];
|
||||
byte volume_id[4];
|
||||
unsigned int num_sectors; /* total number of sectors */
|
||||
int cluster_count; /* number of clusters */
|
||||
int size_root_dir; /* size of the root directory in bytes */
|
||||
int size_fat; /* size of FAT */
|
||||
int fats;
|
||||
int media;
|
||||
unsigned int cluster_size;
|
||||
int fat_length;
|
||||
uint16 dir_entries;
|
||||
uint16 sector_size;
|
||||
int hidden;
|
||||
__int16 reserved;
|
||||
uint16 sectors;
|
||||
unsigned int total_sect;
|
||||
|
||||
uint16 heads;
|
||||
uint16 secs_track;
|
||||
|
||||
} fatparams;
|
||||
|
||||
|
||||
struct msdos_boot_sector
|
||||
{
|
||||
unsigned char boot_jump[3]; /* Boot strap short or near jump */
|
||||
char system_id[8]; /* Name - can be used to special case
|
||||
partition manager volumes */
|
||||
unsigned char sector_size[2]; /* bytes per logical sector */
|
||||
unsigned char cluster_size; /* sectors/cluster */
|
||||
unsigned short reserved;/* reserved sectors */
|
||||
unsigned char fats; /* number of FATs */
|
||||
unsigned char dir_entries[2]; /* root directory entries */
|
||||
unsigned char sectors[2]; /* number of sectors */
|
||||
unsigned char media; /* media code */
|
||||
unsigned short fat_length; /* sectors/FAT */
|
||||
unsigned short secs_track; /* sectors per track */
|
||||
unsigned short heads; /* number of heads */
|
||||
unsigned __int32 hidden; /* hidden sectors */
|
||||
unsigned __int32 total_sect; /* number of sectors (if sectors == 0) */
|
||||
unsigned char drive_number; /* BIOS drive number */
|
||||
unsigned char RESERVED; /* Unused */
|
||||
unsigned char ext_boot_sign; /* 0x29 if fields below exist (DOS 3.3+) */
|
||||
unsigned char volume_id[4]; /* Volume ID number */
|
||||
char volume_label[11]; /* Volume label */
|
||||
char fs_type[8]; /* Typically FAT12, FAT16, or FAT32 */
|
||||
unsigned char boot_code[448]; /* Boot code (or message) */
|
||||
unsigned short boot_sign; /* 0xAA55 */
|
||||
};
|
||||
|
||||
|
||||
void GetFatParams ( fatparams *ft );
|
||||
void PutBoot ( fatparams *ft , unsigned char *boot );
|
||||
int FormatFat (void* hwndDlg, unsigned __int64 startSector, fatparams * ft, void * dev, PCRYPTO_INFO cryptoInfo, BOOL quickFormat);
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
typedef struct fatparams_t
|
||||
{
|
||||
char volume_name[11];
|
||||
byte volume_id[4];
|
||||
unsigned int num_sectors; /* total number of sectors */
|
||||
int cluster_count; /* number of clusters */
|
||||
int size_root_dir; /* size of the root directory in bytes */
|
||||
int size_fat; /* size of FAT */
|
||||
int fats;
|
||||
int media;
|
||||
unsigned int cluster_size;
|
||||
int fat_length;
|
||||
uint16 dir_entries;
|
||||
uint16 sector_size;
|
||||
int hidden;
|
||||
__int16 reserved;
|
||||
uint16 sectors;
|
||||
unsigned int total_sect;
|
||||
|
||||
uint16 heads;
|
||||
uint16 secs_track;
|
||||
|
||||
} fatparams;
|
||||
|
||||
|
||||
struct msdos_boot_sector
|
||||
{
|
||||
unsigned char boot_jump[3]; /* Boot strap short or near jump */
|
||||
char system_id[8]; /* Name - can be used to special case
|
||||
partition manager volumes */
|
||||
unsigned char sector_size[2]; /* bytes per logical sector */
|
||||
unsigned char cluster_size; /* sectors/cluster */
|
||||
unsigned short reserved;/* reserved sectors */
|
||||
unsigned char fats; /* number of FATs */
|
||||
unsigned char dir_entries[2]; /* root directory entries */
|
||||
unsigned char sectors[2]; /* number of sectors */
|
||||
unsigned char media; /* media code */
|
||||
unsigned short fat_length; /* sectors/FAT */
|
||||
unsigned short secs_track; /* sectors per track */
|
||||
unsigned short heads; /* number of heads */
|
||||
unsigned __int32 hidden; /* hidden sectors */
|
||||
unsigned __int32 total_sect; /* number of sectors (if sectors == 0) */
|
||||
unsigned char drive_number; /* BIOS drive number */
|
||||
unsigned char RESERVED; /* Unused */
|
||||
unsigned char ext_boot_sign; /* 0x29 if fields below exist (DOS 3.3+) */
|
||||
unsigned char volume_id[4]; /* Volume ID number */
|
||||
char volume_label[11]; /* Volume label */
|
||||
char fs_type[8]; /* Typically FAT12, FAT16, or FAT32 */
|
||||
unsigned char boot_code[448]; /* Boot code (or message) */
|
||||
unsigned short boot_sign; /* 0xAA55 */
|
||||
};
|
||||
|
||||
|
||||
void GetFatParams ( fatparams *ft );
|
||||
void PutBoot ( fatparams *ft , unsigned char *boot );
|
||||
int FormatFat (void* hwndDlg, unsigned __int64 startSector, fatparams * ft, void * dev, PCRYPTO_INFO cryptoInfo, BOOL quickFormat);
|
||||
|
||||
2108
src/Common/Format.c
2108
src/Common/Format.c
File diff suppressed because it is too large
Load Diff
@@ -1,53 +1,53 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#ifndef TC_HEADER_Format
|
||||
#define TC_HEADER_Format
|
||||
|
||||
#include "Password.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// FMIFS
|
||||
typedef BOOLEAN (__stdcall *PFMIFSCALLBACK)( int command, DWORD subCommand, PVOID parameter );
|
||||
typedef VOID (__stdcall *PFORMATEX)( PWCHAR DriveRoot, DWORD MediaFlag, PWCHAR Format, PWCHAR Label, BOOL QuickFormat, DWORD ClusterSize, PFMIFSCALLBACK Callback );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BOOL bDevice;
|
||||
BOOL hiddenVol;
|
||||
wchar_t *volumePath;
|
||||
unsigned __int64 size;
|
||||
unsigned __int64 hiddenVolHostSize;
|
||||
int ea;
|
||||
int pkcs5;
|
||||
uint32 headerFlags;
|
||||
int fileSystem;
|
||||
unsigned int clusterSize;
|
||||
BOOL sparseFileSwitch;
|
||||
BOOL quickFormat;
|
||||
DWORD sectorSize;
|
||||
int *realClusterSize;
|
||||
Password *password;
|
||||
int pim;
|
||||
HWND hwndDlg;
|
||||
BOOL bForceOperation;
|
||||
BOOL bGuiMode;
|
||||
}
|
||||
FORMAT_VOL_PARAMETERS;
|
||||
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#ifndef TC_HEADER_Format
|
||||
#define TC_HEADER_Format
|
||||
|
||||
#include "Password.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// FMIFS
|
||||
typedef BOOLEAN (__stdcall *PFMIFSCALLBACK)( int command, DWORD subCommand, PVOID parameter );
|
||||
typedef VOID (__stdcall *PFORMATEX)( PWCHAR DriveRoot, DWORD MediaFlag, PWCHAR Format, PWCHAR Label, BOOL QuickFormat, DWORD ClusterSize, PFMIFSCALLBACK Callback );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BOOL bDevice;
|
||||
BOOL hiddenVol;
|
||||
wchar_t *volumePath;
|
||||
unsigned __int64 size;
|
||||
unsigned __int64 hiddenVolHostSize;
|
||||
int ea;
|
||||
int pkcs5;
|
||||
uint32 headerFlags;
|
||||
int fileSystem;
|
||||
unsigned int clusterSize;
|
||||
BOOL sparseFileSwitch;
|
||||
BOOL quickFormat;
|
||||
DWORD sectorSize;
|
||||
int *realClusterSize;
|
||||
Password *password;
|
||||
int pim;
|
||||
HWND hwndDlg;
|
||||
BOOL bForceOperation;
|
||||
BOOL bGuiMode;
|
||||
}
|
||||
FORMAT_VOL_PARAMETERS;
|
||||
|
||||
#define FMIFS_PROGRESS 0x00
|
||||
#define FMIFS_DONE_WITH_STRUCTURE 0x01
|
||||
#define FMIFS_INCOMPATIBLE_FILE_SYSTEM 0x03
|
||||
@@ -66,29 +66,29 @@ FORMAT_VOL_PARAMETERS;
|
||||
#define FMIFS_NO_MEDIA_IN_DRIVE 0x14
|
||||
#define FMIFS_DEVICE_NOT_READY 0x18
|
||||
#define FMIFS_CHECKDISK_PROGRESS 0x19
|
||||
#define FMIFS_READ_ONLY_MODE 0x20
|
||||
|
||||
#define FMIFS_HARDDISK 0xC
|
||||
|
||||
extern int FormatWriteBufferSize;
|
||||
|
||||
int TCFormatVolume (volatile FORMAT_VOL_PARAMETERS *volParams);
|
||||
BOOL FormatNtfs (int driveNo, int clusterSize);
|
||||
BOOL FormatFs (int driveNo, int clusterSize, int fsType);
|
||||
uint64 GetVolumeDataAreaSize (BOOL hiddenVolume, uint64 volumeSize);
|
||||
int FormatNoFs (HWND hwndDlg, unsigned __int64 startSector, __int64 num_sectors, void *dev, PCRYPTO_INFO cryptoInfo, BOOL quickFormat);
|
||||
BOOL WriteSector ( void *dev , char *sector , char *write_buf , int *write_buf_cnt , __int64 *nSecNo , PCRYPTO_INFO cryptoInfo );
|
||||
BOOL FlushFormatWriteBuffer (void *dev, char *write_buf, int *write_buf_cnt, __int64 *nSecNo, PCRYPTO_INFO cryptoInfo);
|
||||
static BOOL StartFormatWriteThread ();
|
||||
static void StopFormatWriteThread ();
|
||||
|
||||
#define FILESYS_NONE 0
|
||||
#define FILESYS_FAT 1
|
||||
#define FILESYS_NTFS 2
|
||||
#define FILESYS_EXFAT 3
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_Format
|
||||
#define FMIFS_READ_ONLY_MODE 0x20
|
||||
|
||||
#define FMIFS_HARDDISK 0xC
|
||||
|
||||
extern int FormatWriteBufferSize;
|
||||
|
||||
int TCFormatVolume (volatile FORMAT_VOL_PARAMETERS *volParams);
|
||||
BOOL FormatNtfs (int driveNo, int clusterSize);
|
||||
BOOL FormatFs (int driveNo, int clusterSize, int fsType);
|
||||
uint64 GetVolumeDataAreaSize (BOOL hiddenVolume, uint64 volumeSize);
|
||||
int FormatNoFs (HWND hwndDlg, unsigned __int64 startSector, __int64 num_sectors, void *dev, PCRYPTO_INFO cryptoInfo, BOOL quickFormat);
|
||||
BOOL WriteSector ( void *dev , char *sector , char *write_buf , int *write_buf_cnt , __int64 *nSecNo , PCRYPTO_INFO cryptoInfo );
|
||||
BOOL FlushFormatWriteBuffer (void *dev, char *write_buf, int *write_buf_cnt, __int64 *nSecNo, PCRYPTO_INFO cryptoInfo);
|
||||
static BOOL StartFormatWriteThread ();
|
||||
static void StopFormatWriteThread ();
|
||||
|
||||
#define FILESYS_NONE 0
|
||||
#define FILESYS_FAT 1
|
||||
#define FILESYS_NTFS 2
|
||||
#define FILESYS_EXFAT 3
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_Format
|
||||
|
||||
1536
src/Common/GfMul.c
1536
src/Common/GfMul.c
File diff suppressed because it is too large
Load Diff
@@ -1,74 +1,74 @@
|
||||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved.
|
||||
|
||||
LICENSE TERMS
|
||||
|
||||
The free distribution and use of this software is allowed (with or without
|
||||
changes) provided that:
|
||||
|
||||
1. source code distributions include the above copyright notice, this
|
||||
list of conditions and the following disclaimer;
|
||||
|
||||
2. binary distributions include the above copyright notice, this list
|
||||
of conditions and the following disclaimer in their documentation;
|
||||
|
||||
3. the name of the copyright holder is not used to endorse products
|
||||
built using this software without specific written permission.
|
||||
|
||||
DISCLAIMER
|
||||
|
||||
This software is provided 'as is' with no explicit or implied warranties
|
||||
in respect of its properties, including, but not limited to, correctness
|
||||
and/or fitness for purpose.
|
||||
---------------------------------------------------------------------------
|
||||
Issue Date: 31/01/2004
|
||||
*/
|
||||
|
||||
/* Adapted for TrueCrypt */
|
||||
|
||||
#ifndef _GCM_H
|
||||
#define _GCM_H
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define CBLK_LEN 16 /* encryption block length */
|
||||
#define CBLK_LEN8 8
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned __int32 gf_t8k[CBLK_LEN * 2][16][CBLK_LEN / 4];
|
||||
} GfCtx8k;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned __int32 gf_t4k[CBLK_LEN8 * 2][16][CBLK_LEN / 4];
|
||||
} GfCtx4k64;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* union not used to support faster mounting */
|
||||
unsigned __int32 gf_t128[CBLK_LEN * 2 / 2][16][CBLK_LEN / 4];
|
||||
unsigned __int32 gf_t64[CBLK_LEN8 * 2][16][CBLK_LEN8 / 4];
|
||||
} GfCtx;
|
||||
|
||||
typedef int ret_type;
|
||||
|
||||
void GfMul128 (void *a, const void* b);
|
||||
void GfMul128Tab(unsigned char a[16], GfCtx8k *ctx);
|
||||
int Gf128Tab64Init (unsigned __int8 *a, GfCtx *ctx);
|
||||
void Gf128MulBy64Tab (unsigned __int8 a[8], unsigned __int8 p[16], GfCtx *ctx);
|
||||
void MirrorBits128 (unsigned __int8 *a);
|
||||
void MirrorBits64 (unsigned __int8 *a);
|
||||
BOOL GfMulSelfTest ();
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved.
|
||||
|
||||
LICENSE TERMS
|
||||
|
||||
The free distribution and use of this software is allowed (with or without
|
||||
changes) provided that:
|
||||
|
||||
1. source code distributions include the above copyright notice, this
|
||||
list of conditions and the following disclaimer;
|
||||
|
||||
2. binary distributions include the above copyright notice, this list
|
||||
of conditions and the following disclaimer in their documentation;
|
||||
|
||||
3. the name of the copyright holder is not used to endorse products
|
||||
built using this software without specific written permission.
|
||||
|
||||
DISCLAIMER
|
||||
|
||||
This software is provided 'as is' with no explicit or implied warranties
|
||||
in respect of its properties, including, but not limited to, correctness
|
||||
and/or fitness for purpose.
|
||||
---------------------------------------------------------------------------
|
||||
Issue Date: 31/01/2004
|
||||
*/
|
||||
|
||||
/* Adapted for TrueCrypt */
|
||||
|
||||
#ifndef _GCM_H
|
||||
#define _GCM_H
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define CBLK_LEN 16 /* encryption block length */
|
||||
#define CBLK_LEN8 8
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned __int32 gf_t8k[CBLK_LEN * 2][16][CBLK_LEN / 4];
|
||||
} GfCtx8k;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned __int32 gf_t4k[CBLK_LEN8 * 2][16][CBLK_LEN / 4];
|
||||
} GfCtx4k64;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* union not used to support faster mounting */
|
||||
unsigned __int32 gf_t128[CBLK_LEN * 2 / 2][16][CBLK_LEN / 4];
|
||||
unsigned __int32 gf_t64[CBLK_LEN8 * 2][16][CBLK_LEN8 / 4];
|
||||
} GfCtx;
|
||||
|
||||
typedef int ret_type;
|
||||
|
||||
void GfMul128 (void *a, const void* b);
|
||||
void GfMul128Tab(unsigned char a[16], GfCtx8k *ctx);
|
||||
int Gf128Tab64Init (unsigned __int8 *a, GfCtx *ctx);
|
||||
void Gf128MulBy64Tab (unsigned __int8 a[8], unsigned __int8 p[16], GfCtx *ctx);
|
||||
void MirrorBits128 (unsigned __int8 *a);
|
||||
void MirrorBits64 (unsigned __int8 *a);
|
||||
BOOL GfMulSelfTest ();
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
2642
src/Common/Inflate.c
2642
src/Common/Inflate.c
File diff suppressed because it is too large
Load Diff
@@ -1,51 +1,51 @@
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
|
||||
#define WSIZE 0x8000 // Window size
|
||||
#define ZCONST const
|
||||
#define OF(p) p
|
||||
|
||||
typedef unsigned long ulg;
|
||||
typedef unsigned char uch;
|
||||
typedef unsigned short ush;
|
||||
typedef void zvoid;
|
||||
|
||||
typedef struct huft
|
||||
{
|
||||
uch b, e;
|
||||
union
|
||||
{
|
||||
ush n;
|
||||
struct huft *t;
|
||||
}v;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uch *inptr, *outbufptr;
|
||||
int incnt;
|
||||
int outCounter;
|
||||
|
||||
struct huft *fixed_tl;
|
||||
struct huft *fixed_td;
|
||||
int fixed_bl, fixed_bd;
|
||||
|
||||
unsigned bk, wp;
|
||||
ulg bb;
|
||||
} G_struct;
|
||||
|
||||
#define __GPRO void
|
||||
#define __GPRO__
|
||||
#define __G
|
||||
#define __G__
|
||||
#define __GDEF
|
||||
|
||||
|
||||
#define FLUSH(cnt) { memcpy (G.outbufptr, redirSlide, cnt); G.outbufptr += cnt; G.outCounter += cnt; }
|
||||
#define NEXTBYTE (((G.incnt--) >= 0) ? (*G.inptr++) : EOF)
|
||||
|
||||
|
||||
int huft_free(struct huft *t);
|
||||
int huft_build(__GDEF ZCONST unsigned *b, unsigned n, unsigned s, ZCONST ush *d, ZCONST ush *e, struct huft **t, int *m);
|
||||
|
||||
int DecompressDeflatedData (char *out, char *in, int inLength);
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
|
||||
#define WSIZE 0x8000 // Window size
|
||||
#define ZCONST const
|
||||
#define OF(p) p
|
||||
|
||||
typedef unsigned long ulg;
|
||||
typedef unsigned char uch;
|
||||
typedef unsigned short ush;
|
||||
typedef void zvoid;
|
||||
|
||||
typedef struct huft
|
||||
{
|
||||
uch b, e;
|
||||
union
|
||||
{
|
||||
ush n;
|
||||
struct huft *t;
|
||||
}v;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uch *inptr, *outbufptr;
|
||||
int incnt;
|
||||
int outCounter;
|
||||
|
||||
struct huft *fixed_tl;
|
||||
struct huft *fixed_td;
|
||||
int fixed_bl, fixed_bd;
|
||||
|
||||
unsigned bk, wp;
|
||||
ulg bb;
|
||||
} G_struct;
|
||||
|
||||
#define __GPRO void
|
||||
#define __GPRO__
|
||||
#define __G
|
||||
#define __G__
|
||||
#define __GDEF
|
||||
|
||||
|
||||
#define FLUSH(cnt) { memcpy (G.outbufptr, redirSlide, cnt); G.outbufptr += cnt; G.outCounter += cnt; }
|
||||
#define NEXTBYTE (((G.incnt--) >= 0) ? (*G.inptr++) : EOF)
|
||||
|
||||
|
||||
int huft_free(struct huft *t);
|
||||
int huft_build(__GDEF ZCONST unsigned *b, unsigned n, unsigned s, ZCONST ush *d, ZCONST ush *e, struct huft **t, int *m);
|
||||
|
||||
int DecompressDeflatedData (char *out, char *in, int inLength);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,54 +1,54 @@
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifndef KEYFILES_H
|
||||
#define KEYFILES_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
#define KEYFILE_POOL_SIZE 64
|
||||
#define KEYFILE_MAX_READ_LEN (1024*1024)
|
||||
|
||||
typedef struct KeyFileStruct
|
||||
{
|
||||
wchar_t FileName[MAX_PATH + 1];
|
||||
struct KeyFileStruct *Next;
|
||||
} KeyFile;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
wchar_t VolumeFileName[MAX_PATH + 1];
|
||||
BOOL EnableKeyFiles;
|
||||
KeyFile *FirstKeyFile;
|
||||
} KeyFilesDlgParam;
|
||||
|
||||
KeyFile *KeyFileAdd (KeyFile *firstKeyFile, KeyFile *keyFile);
|
||||
void KeyFileRemoveAll (KeyFile **firstKeyFile);
|
||||
KeyFile *KeyFileClone (KeyFile *keyFile);
|
||||
void KeyFileCloneAll (KeyFile *firstKeyFile, KeyFile **outputKeyFile);
|
||||
BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFilem, const wchar_t* volumeFileName);
|
||||
BOOL KeyFilesApplyWithPin (HWND hwndDlg, Password *password, char* pin, KeyFile *firstKeyFilem, const wchar_t* volumeFileName);
|
||||
|
||||
BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
BOOL KeyfilesPopupMenu (HWND hwndDlg, POINT popupPosition, KeyFilesDlgParam *dialogParam);
|
||||
|
||||
extern BOOL HiddenFilesPresentInKeyfilePath;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* #ifndef KEYFILES_H */
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifndef KEYFILES_H
|
||||
#define KEYFILES_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
#define KEYFILE_POOL_SIZE 64
|
||||
#define KEYFILE_MAX_READ_LEN (1024*1024)
|
||||
|
||||
typedef struct KeyFileStruct
|
||||
{
|
||||
wchar_t FileName[MAX_PATH + 1];
|
||||
struct KeyFileStruct *Next;
|
||||
} KeyFile;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
wchar_t VolumeFileName[MAX_PATH + 1];
|
||||
BOOL EnableKeyFiles;
|
||||
KeyFile *FirstKeyFile;
|
||||
} KeyFilesDlgParam;
|
||||
|
||||
KeyFile *KeyFileAdd (KeyFile *firstKeyFile, KeyFile *keyFile);
|
||||
void KeyFileRemoveAll (KeyFile **firstKeyFile);
|
||||
KeyFile *KeyFileClone (KeyFile *keyFile);
|
||||
void KeyFileCloneAll (KeyFile *firstKeyFile, KeyFile **outputKeyFile);
|
||||
BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFilem, const wchar_t* volumeFileName);
|
||||
BOOL KeyFilesApplyWithPin (HWND hwndDlg, Password *password, char* pin, KeyFile *firstKeyFilem, const wchar_t* volumeFileName);
|
||||
|
||||
BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
BOOL KeyfilesPopupMenu (HWND hwndDlg, POINT popupPosition, KeyFilesDlgParam *dialogParam);
|
||||
|
||||
extern BOOL HiddenFilesPresentInKeyfilePath;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* #ifndef KEYFILES_H */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,43 +1,43 @@
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define UNKNOWN_STRING_ID L"[?]"
|
||||
|
||||
extern BOOL LocalizationActive;
|
||||
extern int LocalizationSerialNo;
|
||||
extern wchar_t UnknownString[1024];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
wchar_t *FaceName;
|
||||
int Size;
|
||||
} Font;
|
||||
|
||||
BOOL CALLBACK LanguageDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
wchar_t *GetString (const char *stringId);
|
||||
Font *GetFont (char *fontType);
|
||||
BOOL LoadLanguageFile ();
|
||||
char *GetPreferredLangId ();
|
||||
void SetPreferredLangId (char *langId);
|
||||
char *GetActiveLangPackVersion ();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define UNKNOWN_STRING_ID L"[?]"
|
||||
|
||||
extern BOOL LocalizationActive;
|
||||
extern int LocalizationSerialNo;
|
||||
extern wchar_t UnknownString[1024];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
wchar_t *FaceName;
|
||||
int Size;
|
||||
} Font;
|
||||
|
||||
BOOL CALLBACK LanguageDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
wchar_t *GetString (const char *stringId);
|
||||
Font *GetFont (char *fontType);
|
||||
BOOL LoadLanguageFile ();
|
||||
char *GetPreferredLangId ();
|
||||
void SetPreferredLangId (char *langId);
|
||||
char *GetActiveLangPackVersion ();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1 +1 @@
|
||||
!INCLUDE $(NTMAKEENV)\makefile.def
|
||||
!INCLUDE $(NTMAKEENV)\makefile.def
|
||||
|
||||
@@ -1,491 +1,491 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#include "Crypto.h"
|
||||
#include "Volumes.h"
|
||||
#include "Password.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Language.h"
|
||||
#include "Pkcs5.h"
|
||||
#include "Endian.h"
|
||||
#include "Random.h"
|
||||
|
||||
#include <io.h>
|
||||
|
||||
#ifndef SRC_POS
|
||||
#define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__))
|
||||
#endif
|
||||
|
||||
void VerifyPasswordAndUpdate (HWND hwndDlg, HWND hButton, HWND hPassword,
|
||||
HWND hVerify, unsigned char *szPassword,
|
||||
char *szVerify,
|
||||
BOOL keyFilesEnabled)
|
||||
{
|
||||
wchar_t szTmp1[MAX_PASSWORD + 1];
|
||||
wchar_t szTmp2[MAX_PASSWORD + 1];
|
||||
char szTmp1Utf8[MAX_PASSWORD + 1];
|
||||
char szTmp2Utf8[MAX_PASSWORD + 1];
|
||||
int k = GetWindowTextLength (hPassword);
|
||||
BOOL bEnable = FALSE;
|
||||
int utf8Len1, utf8Len2;
|
||||
|
||||
UNREFERENCED_PARAMETER (hwndDlg); /* Remove warning */
|
||||
|
||||
GetWindowText (hPassword, szTmp1, ARRAYSIZE (szTmp1));
|
||||
GetWindowText (hVerify, szTmp2, ARRAYSIZE (szTmp2));
|
||||
|
||||
utf8Len1 = WideCharToMultiByte (CP_UTF8, 0, szTmp1, -1, szTmp1Utf8, MAX_PASSWORD + 1, NULL, NULL);
|
||||
utf8Len2 = WideCharToMultiByte (CP_UTF8, 0, szTmp2, -1, szTmp2Utf8, MAX_PASSWORD + 1, NULL, NULL);
|
||||
|
||||
if (wcscmp (szTmp1, szTmp2) != 0)
|
||||
bEnable = FALSE;
|
||||
else if (utf8Len1 <= 0)
|
||||
bEnable = FALSE;
|
||||
else
|
||||
{
|
||||
if (k >= MIN_PASSWORD || keyFilesEnabled)
|
||||
bEnable = TRUE;
|
||||
else
|
||||
bEnable = FALSE;
|
||||
}
|
||||
|
||||
if (szPassword != NULL)
|
||||
{
|
||||
if (utf8Len1 > 0)
|
||||
memcpy (szPassword, szTmp1Utf8, sizeof (szTmp1Utf8));
|
||||
else
|
||||
szPassword [0] = 0;
|
||||
}
|
||||
|
||||
if (szVerify != NULL)
|
||||
{
|
||||
if (utf8Len2 > 0)
|
||||
memcpy (szVerify, szTmp2Utf8, sizeof (szTmp2Utf8));
|
||||
else
|
||||
szVerify [0] = 0;
|
||||
}
|
||||
|
||||
burn (szTmp1, sizeof (szTmp1));
|
||||
burn (szTmp2, sizeof (szTmp2));
|
||||
burn (szTmp1Utf8, sizeof (szTmp1Utf8));
|
||||
burn (szTmp2Utf8, sizeof (szTmp2Utf8));
|
||||
|
||||
EnableWindow (hButton, bEnable);
|
||||
}
|
||||
|
||||
|
||||
BOOL CheckPasswordCharEncoding (HWND hPassword, Password *ptrPw)
|
||||
{
|
||||
int i, len;
|
||||
|
||||
if (hPassword == NULL)
|
||||
{
|
||||
if (ptrPw)
|
||||
{
|
||||
unsigned char *pw;
|
||||
len = ptrPw->Length;
|
||||
pw = (unsigned char *) ptrPw->Text;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (pw[i] >= 0x7f || pw[i] < 0x20) // A non-ASCII or non-printable character?
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t s[MAX_PASSWORD + 1];
|
||||
len = GetWindowTextLength (hPassword);
|
||||
|
||||
if (len > MAX_PASSWORD)
|
||||
return FALSE;
|
||||
|
||||
GetWindowTextW (hPassword, s, sizeof (s) / sizeof (wchar_t));
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (s[i] >= 0x7f || s[i] < 0x20) // A non-ASCII or non-printable character?
|
||||
break;
|
||||
}
|
||||
|
||||
burn (s, sizeof(s));
|
||||
|
||||
if (i < len)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
BOOL CheckPasswordLength (HWND hwndDlg, unsigned __int32 passwordLength, int pim, BOOL bForBoot, BOOL bSkipPasswordWarning, BOOL bSkipPimWarning)
|
||||
{
|
||||
BOOL bCustomPimSmall = ((pim != 0) && (pim < (bForBoot? 98 : 485)))? TRUE : FALSE;
|
||||
if (passwordLength < PASSWORD_LEN_WARNING)
|
||||
{
|
||||
if (bCustomPimSmall)
|
||||
{
|
||||
Error (bForBoot? "BOOT_PIM_REQUIRE_LONG_PASSWORD": "PIM_REQUIRE_LONG_PASSWORD", hwndDlg);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifndef _DEBUG
|
||||
if (!bSkipPasswordWarning && (MessageBoxW (hwndDlg, GetString ("PASSWORD_LENGTH_WARNING"), lpszTitle, MB_YESNO|MB_ICONWARNING|MB_DEFBUTTON2) != IDYES))
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
#ifndef _DEBUG
|
||||
else if (bCustomPimSmall)
|
||||
{
|
||||
if (!bSkipPimWarning && AskWarnNoYes ("PIM_SMALL_WARNING", hwndDlg) != IDYES)
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((pim != 0) && (pim > (bForBoot? 98 : 485)))
|
||||
{
|
||||
// warn that mount/boot will take more time
|
||||
Warning ("PIM_LARGE_WARNING", hwndDlg);
|
||||
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int ChangePwd (const wchar_t *lpszVolume, Password *oldPassword, int old_pkcs5, int old_pim, BOOL truecryptMode, Password *newPassword, int pkcs5, int pim, int wipePassCount, HWND hwndDlg)
|
||||
{
|
||||
int nDosLinkCreated = 1, nStatus = ERR_OS_ERROR;
|
||||
wchar_t szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
|
||||
wchar_t szDosDevice[TC_MAX_PATH];
|
||||
char buffer[TC_VOLUME_HEADER_EFFECTIVE_SIZE];
|
||||
PCRYPTO_INFO cryptoInfo = NULL, ci = NULL;
|
||||
void *dev = INVALID_HANDLE_VALUE;
|
||||
DWORD dwError;
|
||||
DWORD bytesRead;
|
||||
BOOL bDevice;
|
||||
unsigned __int64 hostSize = 0;
|
||||
int volumeType;
|
||||
int wipePass;
|
||||
FILETIME ftCreationTime;
|
||||
FILETIME ftLastWriteTime;
|
||||
FILETIME ftLastAccessTime;
|
||||
BOOL bTimeStampValid = FALSE;
|
||||
LARGE_INTEGER headerOffset;
|
||||
BOOL backupHeader;
|
||||
DISK_GEOMETRY driveInfo;
|
||||
|
||||
if (oldPassword->Length == 0 || newPassword->Length == 0) return -1;
|
||||
|
||||
if ((wipePassCount <= 0) || (truecryptMode && (old_pkcs5 == SHA256)))
|
||||
{
|
||||
nStatus = ERR_PARAMETER_INCORRECT;
|
||||
handleError (hwndDlg, nStatus, SRC_POS);
|
||||
return nStatus;
|
||||
}
|
||||
|
||||
if (!lpszVolume)
|
||||
{
|
||||
nStatus = ERR_OUTOFMEMORY;
|
||||
handleError (hwndDlg, nStatus, SRC_POS);
|
||||
return nStatus;
|
||||
}
|
||||
|
||||
WaitCursor ();
|
||||
|
||||
CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), lpszVolume, &bDevice);
|
||||
|
||||
if (bDevice == FALSE)
|
||||
{
|
||||
wcscpy (szCFDevice, szDiskFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
nDosLinkCreated = FakeDosNameForDevice (szDiskFile, szDosDevice, sizeof(szDosDevice), szCFDevice, sizeof(szCFDevice),FALSE);
|
||||
|
||||
if (nDosLinkCreated != 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
dev = CreateFile (szCFDevice, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
||||
|
||||
if (dev == INVALID_HANDLE_VALUE)
|
||||
goto error;
|
||||
|
||||
if (bDevice)
|
||||
{
|
||||
/* This is necessary to determine the hidden volume header offset */
|
||||
|
||||
if (dev == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
else
|
||||
{
|
||||
PARTITION_INFORMATION diskInfo;
|
||||
DWORD dwResult;
|
||||
BOOL bResult;
|
||||
|
||||
bResult = DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
|
||||
&driveInfo, sizeof (driveInfo), &dwResult, NULL);
|
||||
|
||||
if (!bResult)
|
||||
goto error;
|
||||
|
||||
bResult = GetPartitionInfo (lpszVolume, &diskInfo);
|
||||
|
||||
if (bResult)
|
||||
{
|
||||
hostSize = diskInfo.PartitionLength.QuadPart;
|
||||
}
|
||||
else
|
||||
{
|
||||
hostSize = driveInfo.Cylinders.QuadPart * driveInfo.BytesPerSector *
|
||||
driveInfo.SectorsPerTrack * driveInfo.TracksPerCylinder;
|
||||
}
|
||||
|
||||
if (hostSize == 0)
|
||||
{
|
||||
nStatus = ERR_VOL_SIZE_WRONG;
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LARGE_INTEGER fileSize;
|
||||
if (!GetFileSizeEx (dev, &fileSize))
|
||||
{
|
||||
nStatus = ERR_OS_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
hostSize = fileSize.QuadPart;
|
||||
}
|
||||
|
||||
if (Randinit ())
|
||||
{
|
||||
if (CryptoAPILastError == ERROR_SUCCESS)
|
||||
nStatus = ERR_RAND_INIT_FAILED;
|
||||
else
|
||||
nStatus = ERR_CAPI_INIT_FAILED;
|
||||
goto error;
|
||||
}
|
||||
|
||||
SetRandomPoolEnrichedByUserStatus (FALSE); /* force the display of the random enriching dialog */
|
||||
|
||||
if (!bDevice && bPreserveTimestamp)
|
||||
{
|
||||
if (GetFileTime ((HANDLE) dev, &ftCreationTime, &ftLastAccessTime, &ftLastWriteTime) == 0)
|
||||
bTimeStampValid = FALSE;
|
||||
else
|
||||
bTimeStampValid = TRUE;
|
||||
}
|
||||
|
||||
for (volumeType = TC_VOLUME_TYPE_NORMAL; volumeType < TC_VOLUME_TYPE_COUNT; volumeType++)
|
||||
{
|
||||
// Seek the volume header
|
||||
switch (volumeType)
|
||||
{
|
||||
case TC_VOLUME_TYPE_NORMAL:
|
||||
headerOffset.QuadPart = TC_VOLUME_HEADER_OFFSET;
|
||||
break;
|
||||
|
||||
case TC_VOLUME_TYPE_HIDDEN:
|
||||
if (TC_HIDDEN_VOLUME_HEADER_OFFSET + TC_VOLUME_HEADER_SIZE > hostSize)
|
||||
continue;
|
||||
|
||||
headerOffset.QuadPart = TC_HIDDEN_VOLUME_HEADER_OFFSET;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (!SetFilePointerEx ((HANDLE) dev, headerOffset, NULL, FILE_BEGIN))
|
||||
{
|
||||
nStatus = ERR_OS_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Read in volume header */
|
||||
if (!ReadEffectiveVolumeHeader (bDevice, dev, buffer, &bytesRead))
|
||||
{
|
||||
nStatus = ERR_OS_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (bytesRead != sizeof (buffer))
|
||||
{
|
||||
// Windows may report EOF when reading sectors from the last cluster of a device formatted as NTFS
|
||||
memset (buffer, 0, sizeof (buffer));
|
||||
}
|
||||
|
||||
/* Try to decrypt the header */
|
||||
|
||||
nStatus = ReadVolumeHeader (FALSE, buffer, oldPassword, old_pkcs5, old_pim, truecryptMode, &cryptoInfo, NULL);
|
||||
if (nStatus == ERR_CIPHER_INIT_WEAK_KEY)
|
||||
nStatus = 0; // We can ignore this error here
|
||||
|
||||
if (nStatus == ERR_PASSWORD_WRONG)
|
||||
{
|
||||
continue; // Try next volume type
|
||||
}
|
||||
else if (nStatus != 0)
|
||||
{
|
||||
cryptoInfo = NULL;
|
||||
goto error;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (nStatus != 0)
|
||||
{
|
||||
cryptoInfo = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (cryptoInfo->HeaderFlags & TC_HEADER_FLAG_ENCRYPTED_SYSTEM)
|
||||
{
|
||||
nStatus = ERR_SYS_HIDVOL_HEAD_REENC_MODE_WRONG;
|
||||
goto error;
|
||||
}
|
||||
|
||||
// Change the PKCS-5 PRF if requested by user
|
||||
if (pkcs5 != 0)
|
||||
cryptoInfo->pkcs5 = pkcs5;
|
||||
|
||||
RandSetHashFunction (cryptoInfo->pkcs5);
|
||||
|
||||
NormalCursor();
|
||||
UserEnrichRandomPool (hwndDlg);
|
||||
EnableElevatedCursorChange (hwndDlg);
|
||||
WaitCursor();
|
||||
|
||||
/* Re-encrypt the volume header */
|
||||
backupHeader = FALSE;
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
/* The header will be re-encrypted wipePassCount times to prevent adversaries from using
|
||||
techniques such as magnetic force microscopy or magnetic force scanning tunnelling microscopy
|
||||
to recover the overwritten header. According to Peter Gutmann, data should be overwritten 22
|
||||
times (ideally, 35 times) using non-random patterns and pseudorandom data. However, as users might
|
||||
impatiently interupt the process (etc.) we will not use the Gutmann's patterns but will write the
|
||||
valid re-encrypted header, i.e. pseudorandom data, and there will be many more passes than Guttman
|
||||
recommends. During each pass we will write a valid working header. Each pass will use the same master
|
||||
key, and also the same header key, secondary key (XTS), etc., derived from the new password. The only
|
||||
item that will be different for each pass will be the salt. This is sufficient to cause each "version"
|
||||
of the header to differ substantially and in a random manner from the versions written during the
|
||||
other passes. */
|
||||
|
||||
for (wipePass = 0; wipePass < wipePassCount; wipePass++)
|
||||
{
|
||||
// Prepare new volume header
|
||||
nStatus = CreateVolumeHeaderInMemory (hwndDlg, FALSE,
|
||||
buffer,
|
||||
cryptoInfo->ea,
|
||||
cryptoInfo->mode,
|
||||
newPassword,
|
||||
cryptoInfo->pkcs5,
|
||||
pim,
|
||||
cryptoInfo->master_keydata,
|
||||
&ci,
|
||||
cryptoInfo->VolumeSize.Value,
|
||||
(volumeType == TC_VOLUME_TYPE_HIDDEN) ? cryptoInfo->hiddenVolumeSize : 0,
|
||||
cryptoInfo->EncryptedAreaStart.Value,
|
||||
cryptoInfo->EncryptedAreaLength.Value,
|
||||
truecryptMode? 0 : cryptoInfo->RequiredProgramVersion,
|
||||
cryptoInfo->HeaderFlags,
|
||||
cryptoInfo->SectorSize,
|
||||
wipePass < wipePassCount - 1);
|
||||
|
||||
if (ci != NULL)
|
||||
crypto_close (ci);
|
||||
|
||||
if (nStatus != 0)
|
||||
goto error;
|
||||
|
||||
if (!SetFilePointerEx ((HANDLE) dev, headerOffset, NULL, FILE_BEGIN))
|
||||
{
|
||||
nStatus = ERR_OS_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!WriteEffectiveVolumeHeader (bDevice, dev, buffer))
|
||||
{
|
||||
nStatus = ERR_OS_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (bDevice
|
||||
&& !cryptoInfo->LegacyVolume
|
||||
&& !cryptoInfo->hiddenVolume
|
||||
&& cryptoInfo->HeaderVersion == 4
|
||||
&& (cryptoInfo->HeaderFlags & TC_HEADER_FLAG_NONSYS_INPLACE_ENC) != 0
|
||||
&& (cryptoInfo->HeaderFlags & ~TC_HEADER_FLAG_NONSYS_INPLACE_ENC) == 0)
|
||||
{
|
||||
nStatus = WriteRandomDataToReservedHeaderAreas (hwndDlg, dev, cryptoInfo, cryptoInfo->VolumeSize.Value, !backupHeader, backupHeader);
|
||||
if (nStatus != ERR_SUCCESS)
|
||||
goto error;
|
||||
}
|
||||
|
||||
FlushFileBuffers (dev);
|
||||
}
|
||||
|
||||
if (backupHeader || cryptoInfo->LegacyVolume)
|
||||
break;
|
||||
|
||||
backupHeader = TRUE;
|
||||
headerOffset.QuadPart += hostSize - TC_VOLUME_HEADER_GROUP_SIZE;
|
||||
}
|
||||
|
||||
/* Password successfully changed */
|
||||
nStatus = 0;
|
||||
|
||||
error:
|
||||
dwError = GetLastError ();
|
||||
|
||||
burn (buffer, sizeof (buffer));
|
||||
|
||||
if (cryptoInfo != NULL)
|
||||
crypto_close (cryptoInfo);
|
||||
|
||||
if (bTimeStampValid)
|
||||
SetFileTime (dev, &ftCreationTime, &ftLastAccessTime, &ftLastWriteTime);
|
||||
|
||||
if (dev != INVALID_HANDLE_VALUE)
|
||||
CloseHandle ((HANDLE) dev);
|
||||
|
||||
if (nDosLinkCreated == 0)
|
||||
RemoveFakeDosName (szDiskFile, szDosDevice);
|
||||
|
||||
RandStop (FALSE);
|
||||
NormalCursor ();
|
||||
|
||||
SetLastError (dwError);
|
||||
|
||||
if (nStatus == ERR_OS_ERROR && dwError == ERROR_ACCESS_DENIED
|
||||
&& bDevice
|
||||
&& !UacElevated
|
||||
&& IsUacSupported ())
|
||||
return nStatus;
|
||||
|
||||
if (nStatus != 0)
|
||||
handleError (hwndDlg, nStatus, SRC_POS);
|
||||
|
||||
return nStatus;
|
||||
}
|
||||
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#include "Crypto.h"
|
||||
#include "Volumes.h"
|
||||
#include "Password.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Language.h"
|
||||
#include "Pkcs5.h"
|
||||
#include "Endian.h"
|
||||
#include "Random.h"
|
||||
|
||||
#include <io.h>
|
||||
|
||||
#ifndef SRC_POS
|
||||
#define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__))
|
||||
#endif
|
||||
|
||||
void VerifyPasswordAndUpdate (HWND hwndDlg, HWND hButton, HWND hPassword,
|
||||
HWND hVerify, unsigned char *szPassword,
|
||||
char *szVerify,
|
||||
BOOL keyFilesEnabled)
|
||||
{
|
||||
wchar_t szTmp1[MAX_PASSWORD + 1];
|
||||
wchar_t szTmp2[MAX_PASSWORD + 1];
|
||||
char szTmp1Utf8[MAX_PASSWORD + 1];
|
||||
char szTmp2Utf8[MAX_PASSWORD + 1];
|
||||
int k = GetWindowTextLength (hPassword);
|
||||
BOOL bEnable = FALSE;
|
||||
int utf8Len1, utf8Len2;
|
||||
|
||||
UNREFERENCED_PARAMETER (hwndDlg); /* Remove warning */
|
||||
|
||||
GetWindowText (hPassword, szTmp1, ARRAYSIZE (szTmp1));
|
||||
GetWindowText (hVerify, szTmp2, ARRAYSIZE (szTmp2));
|
||||
|
||||
utf8Len1 = WideCharToMultiByte (CP_UTF8, 0, szTmp1, -1, szTmp1Utf8, MAX_PASSWORD + 1, NULL, NULL);
|
||||
utf8Len2 = WideCharToMultiByte (CP_UTF8, 0, szTmp2, -1, szTmp2Utf8, MAX_PASSWORD + 1, NULL, NULL);
|
||||
|
||||
if (wcscmp (szTmp1, szTmp2) != 0)
|
||||
bEnable = FALSE;
|
||||
else if (utf8Len1 <= 0)
|
||||
bEnable = FALSE;
|
||||
else
|
||||
{
|
||||
if (k >= MIN_PASSWORD || keyFilesEnabled)
|
||||
bEnable = TRUE;
|
||||
else
|
||||
bEnable = FALSE;
|
||||
}
|
||||
|
||||
if (szPassword != NULL)
|
||||
{
|
||||
if (utf8Len1 > 0)
|
||||
memcpy (szPassword, szTmp1Utf8, sizeof (szTmp1Utf8));
|
||||
else
|
||||
szPassword [0] = 0;
|
||||
}
|
||||
|
||||
if (szVerify != NULL)
|
||||
{
|
||||
if (utf8Len2 > 0)
|
||||
memcpy (szVerify, szTmp2Utf8, sizeof (szTmp2Utf8));
|
||||
else
|
||||
szVerify [0] = 0;
|
||||
}
|
||||
|
||||
burn (szTmp1, sizeof (szTmp1));
|
||||
burn (szTmp2, sizeof (szTmp2));
|
||||
burn (szTmp1Utf8, sizeof (szTmp1Utf8));
|
||||
burn (szTmp2Utf8, sizeof (szTmp2Utf8));
|
||||
|
||||
EnableWindow (hButton, bEnable);
|
||||
}
|
||||
|
||||
|
||||
BOOL CheckPasswordCharEncoding (HWND hPassword, Password *ptrPw)
|
||||
{
|
||||
int i, len;
|
||||
|
||||
if (hPassword == NULL)
|
||||
{
|
||||
if (ptrPw)
|
||||
{
|
||||
unsigned char *pw;
|
||||
len = ptrPw->Length;
|
||||
pw = (unsigned char *) ptrPw->Text;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (pw[i] >= 0x7f || pw[i] < 0x20) // A non-ASCII or non-printable character?
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t s[MAX_PASSWORD + 1];
|
||||
len = GetWindowTextLength (hPassword);
|
||||
|
||||
if (len > MAX_PASSWORD)
|
||||
return FALSE;
|
||||
|
||||
GetWindowTextW (hPassword, s, sizeof (s) / sizeof (wchar_t));
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (s[i] >= 0x7f || s[i] < 0x20) // A non-ASCII or non-printable character?
|
||||
break;
|
||||
}
|
||||
|
||||
burn (s, sizeof(s));
|
||||
|
||||
if (i < len)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
BOOL CheckPasswordLength (HWND hwndDlg, unsigned __int32 passwordLength, int pim, BOOL bForBoot, BOOL bSkipPasswordWarning, BOOL bSkipPimWarning)
|
||||
{
|
||||
BOOL bCustomPimSmall = ((pim != 0) && (pim < (bForBoot? 98 : 485)))? TRUE : FALSE;
|
||||
if (passwordLength < PASSWORD_LEN_WARNING)
|
||||
{
|
||||
if (bCustomPimSmall)
|
||||
{
|
||||
Error (bForBoot? "BOOT_PIM_REQUIRE_LONG_PASSWORD": "PIM_REQUIRE_LONG_PASSWORD", hwndDlg);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifndef _DEBUG
|
||||
if (!bSkipPasswordWarning && (MessageBoxW (hwndDlg, GetString ("PASSWORD_LENGTH_WARNING"), lpszTitle, MB_YESNO|MB_ICONWARNING|MB_DEFBUTTON2) != IDYES))
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
#ifndef _DEBUG
|
||||
else if (bCustomPimSmall)
|
||||
{
|
||||
if (!bSkipPimWarning && AskWarnNoYes ("PIM_SMALL_WARNING", hwndDlg) != IDYES)
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((pim != 0) && (pim > (bForBoot? 98 : 485)))
|
||||
{
|
||||
// warn that mount/boot will take more time
|
||||
Warning ("PIM_LARGE_WARNING", hwndDlg);
|
||||
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int ChangePwd (const wchar_t *lpszVolume, Password *oldPassword, int old_pkcs5, int old_pim, BOOL truecryptMode, Password *newPassword, int pkcs5, int pim, int wipePassCount, HWND hwndDlg)
|
||||
{
|
||||
int nDosLinkCreated = 1, nStatus = ERR_OS_ERROR;
|
||||
wchar_t szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
|
||||
wchar_t szDosDevice[TC_MAX_PATH];
|
||||
char buffer[TC_VOLUME_HEADER_EFFECTIVE_SIZE];
|
||||
PCRYPTO_INFO cryptoInfo = NULL, ci = NULL;
|
||||
void *dev = INVALID_HANDLE_VALUE;
|
||||
DWORD dwError;
|
||||
DWORD bytesRead;
|
||||
BOOL bDevice;
|
||||
unsigned __int64 hostSize = 0;
|
||||
int volumeType;
|
||||
int wipePass;
|
||||
FILETIME ftCreationTime;
|
||||
FILETIME ftLastWriteTime;
|
||||
FILETIME ftLastAccessTime;
|
||||
BOOL bTimeStampValid = FALSE;
|
||||
LARGE_INTEGER headerOffset;
|
||||
BOOL backupHeader;
|
||||
DISK_GEOMETRY driveInfo;
|
||||
|
||||
if (oldPassword->Length == 0 || newPassword->Length == 0) return -1;
|
||||
|
||||
if ((wipePassCount <= 0) || (truecryptMode && (old_pkcs5 == SHA256)))
|
||||
{
|
||||
nStatus = ERR_PARAMETER_INCORRECT;
|
||||
handleError (hwndDlg, nStatus, SRC_POS);
|
||||
return nStatus;
|
||||
}
|
||||
|
||||
if (!lpszVolume)
|
||||
{
|
||||
nStatus = ERR_OUTOFMEMORY;
|
||||
handleError (hwndDlg, nStatus, SRC_POS);
|
||||
return nStatus;
|
||||
}
|
||||
|
||||
WaitCursor ();
|
||||
|
||||
CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), lpszVolume, &bDevice);
|
||||
|
||||
if (bDevice == FALSE)
|
||||
{
|
||||
wcscpy (szCFDevice, szDiskFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
nDosLinkCreated = FakeDosNameForDevice (szDiskFile, szDosDevice, sizeof(szDosDevice), szCFDevice, sizeof(szCFDevice),FALSE);
|
||||
|
||||
if (nDosLinkCreated != 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
dev = CreateFile (szCFDevice, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
||||
|
||||
if (dev == INVALID_HANDLE_VALUE)
|
||||
goto error;
|
||||
|
||||
if (bDevice)
|
||||
{
|
||||
/* This is necessary to determine the hidden volume header offset */
|
||||
|
||||
if (dev == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
else
|
||||
{
|
||||
PARTITION_INFORMATION diskInfo;
|
||||
DWORD dwResult;
|
||||
BOOL bResult;
|
||||
|
||||
bResult = DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
|
||||
&driveInfo, sizeof (driveInfo), &dwResult, NULL);
|
||||
|
||||
if (!bResult)
|
||||
goto error;
|
||||
|
||||
bResult = GetPartitionInfo (lpszVolume, &diskInfo);
|
||||
|
||||
if (bResult)
|
||||
{
|
||||
hostSize = diskInfo.PartitionLength.QuadPart;
|
||||
}
|
||||
else
|
||||
{
|
||||
hostSize = driveInfo.Cylinders.QuadPart * driveInfo.BytesPerSector *
|
||||
driveInfo.SectorsPerTrack * driveInfo.TracksPerCylinder;
|
||||
}
|
||||
|
||||
if (hostSize == 0)
|
||||
{
|
||||
nStatus = ERR_VOL_SIZE_WRONG;
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LARGE_INTEGER fileSize;
|
||||
if (!GetFileSizeEx (dev, &fileSize))
|
||||
{
|
||||
nStatus = ERR_OS_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
hostSize = fileSize.QuadPart;
|
||||
}
|
||||
|
||||
if (Randinit ())
|
||||
{
|
||||
if (CryptoAPILastError == ERROR_SUCCESS)
|
||||
nStatus = ERR_RAND_INIT_FAILED;
|
||||
else
|
||||
nStatus = ERR_CAPI_INIT_FAILED;
|
||||
goto error;
|
||||
}
|
||||
|
||||
SetRandomPoolEnrichedByUserStatus (FALSE); /* force the display of the random enriching dialog */
|
||||
|
||||
if (!bDevice && bPreserveTimestamp)
|
||||
{
|
||||
if (GetFileTime ((HANDLE) dev, &ftCreationTime, &ftLastAccessTime, &ftLastWriteTime) == 0)
|
||||
bTimeStampValid = FALSE;
|
||||
else
|
||||
bTimeStampValid = TRUE;
|
||||
}
|
||||
|
||||
for (volumeType = TC_VOLUME_TYPE_NORMAL; volumeType < TC_VOLUME_TYPE_COUNT; volumeType++)
|
||||
{
|
||||
// Seek the volume header
|
||||
switch (volumeType)
|
||||
{
|
||||
case TC_VOLUME_TYPE_NORMAL:
|
||||
headerOffset.QuadPart = TC_VOLUME_HEADER_OFFSET;
|
||||
break;
|
||||
|
||||
case TC_VOLUME_TYPE_HIDDEN:
|
||||
if (TC_HIDDEN_VOLUME_HEADER_OFFSET + TC_VOLUME_HEADER_SIZE > hostSize)
|
||||
continue;
|
||||
|
||||
headerOffset.QuadPart = TC_HIDDEN_VOLUME_HEADER_OFFSET;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (!SetFilePointerEx ((HANDLE) dev, headerOffset, NULL, FILE_BEGIN))
|
||||
{
|
||||
nStatus = ERR_OS_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Read in volume header */
|
||||
if (!ReadEffectiveVolumeHeader (bDevice, dev, buffer, &bytesRead))
|
||||
{
|
||||
nStatus = ERR_OS_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (bytesRead != sizeof (buffer))
|
||||
{
|
||||
// Windows may report EOF when reading sectors from the last cluster of a device formatted as NTFS
|
||||
memset (buffer, 0, sizeof (buffer));
|
||||
}
|
||||
|
||||
/* Try to decrypt the header */
|
||||
|
||||
nStatus = ReadVolumeHeader (FALSE, buffer, oldPassword, old_pkcs5, old_pim, truecryptMode, &cryptoInfo, NULL);
|
||||
if (nStatus == ERR_CIPHER_INIT_WEAK_KEY)
|
||||
nStatus = 0; // We can ignore this error here
|
||||
|
||||
if (nStatus == ERR_PASSWORD_WRONG)
|
||||
{
|
||||
continue; // Try next volume type
|
||||
}
|
||||
else if (nStatus != 0)
|
||||
{
|
||||
cryptoInfo = NULL;
|
||||
goto error;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (nStatus != 0)
|
||||
{
|
||||
cryptoInfo = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (cryptoInfo->HeaderFlags & TC_HEADER_FLAG_ENCRYPTED_SYSTEM)
|
||||
{
|
||||
nStatus = ERR_SYS_HIDVOL_HEAD_REENC_MODE_WRONG;
|
||||
goto error;
|
||||
}
|
||||
|
||||
// Change the PKCS-5 PRF if requested by user
|
||||
if (pkcs5 != 0)
|
||||
cryptoInfo->pkcs5 = pkcs5;
|
||||
|
||||
RandSetHashFunction (cryptoInfo->pkcs5);
|
||||
|
||||
NormalCursor();
|
||||
UserEnrichRandomPool (hwndDlg);
|
||||
EnableElevatedCursorChange (hwndDlg);
|
||||
WaitCursor();
|
||||
|
||||
/* Re-encrypt the volume header */
|
||||
backupHeader = FALSE;
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
/* The header will be re-encrypted wipePassCount times to prevent adversaries from using
|
||||
techniques such as magnetic force microscopy or magnetic force scanning tunnelling microscopy
|
||||
to recover the overwritten header. According to Peter Gutmann, data should be overwritten 22
|
||||
times (ideally, 35 times) using non-random patterns and pseudorandom data. However, as users might
|
||||
impatiently interupt the process (etc.) we will not use the Gutmann's patterns but will write the
|
||||
valid re-encrypted header, i.e. pseudorandom data, and there will be many more passes than Guttman
|
||||
recommends. During each pass we will write a valid working header. Each pass will use the same master
|
||||
key, and also the same header key, secondary key (XTS), etc., derived from the new password. The only
|
||||
item that will be different for each pass will be the salt. This is sufficient to cause each "version"
|
||||
of the header to differ substantially and in a random manner from the versions written during the
|
||||
other passes. */
|
||||
|
||||
for (wipePass = 0; wipePass < wipePassCount; wipePass++)
|
||||
{
|
||||
// Prepare new volume header
|
||||
nStatus = CreateVolumeHeaderInMemory (hwndDlg, FALSE,
|
||||
buffer,
|
||||
cryptoInfo->ea,
|
||||
cryptoInfo->mode,
|
||||
newPassword,
|
||||
cryptoInfo->pkcs5,
|
||||
pim,
|
||||
cryptoInfo->master_keydata,
|
||||
&ci,
|
||||
cryptoInfo->VolumeSize.Value,
|
||||
(volumeType == TC_VOLUME_TYPE_HIDDEN) ? cryptoInfo->hiddenVolumeSize : 0,
|
||||
cryptoInfo->EncryptedAreaStart.Value,
|
||||
cryptoInfo->EncryptedAreaLength.Value,
|
||||
truecryptMode? 0 : cryptoInfo->RequiredProgramVersion,
|
||||
cryptoInfo->HeaderFlags,
|
||||
cryptoInfo->SectorSize,
|
||||
wipePass < wipePassCount - 1);
|
||||
|
||||
if (ci != NULL)
|
||||
crypto_close (ci);
|
||||
|
||||
if (nStatus != 0)
|
||||
goto error;
|
||||
|
||||
if (!SetFilePointerEx ((HANDLE) dev, headerOffset, NULL, FILE_BEGIN))
|
||||
{
|
||||
nStatus = ERR_OS_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!WriteEffectiveVolumeHeader (bDevice, dev, buffer))
|
||||
{
|
||||
nStatus = ERR_OS_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (bDevice
|
||||
&& !cryptoInfo->LegacyVolume
|
||||
&& !cryptoInfo->hiddenVolume
|
||||
&& cryptoInfo->HeaderVersion == 4
|
||||
&& (cryptoInfo->HeaderFlags & TC_HEADER_FLAG_NONSYS_INPLACE_ENC) != 0
|
||||
&& (cryptoInfo->HeaderFlags & ~TC_HEADER_FLAG_NONSYS_INPLACE_ENC) == 0)
|
||||
{
|
||||
nStatus = WriteRandomDataToReservedHeaderAreas (hwndDlg, dev, cryptoInfo, cryptoInfo->VolumeSize.Value, !backupHeader, backupHeader);
|
||||
if (nStatus != ERR_SUCCESS)
|
||||
goto error;
|
||||
}
|
||||
|
||||
FlushFileBuffers (dev);
|
||||
}
|
||||
|
||||
if (backupHeader || cryptoInfo->LegacyVolume)
|
||||
break;
|
||||
|
||||
backupHeader = TRUE;
|
||||
headerOffset.QuadPart += hostSize - TC_VOLUME_HEADER_GROUP_SIZE;
|
||||
}
|
||||
|
||||
/* Password successfully changed */
|
||||
nStatus = 0;
|
||||
|
||||
error:
|
||||
dwError = GetLastError ();
|
||||
|
||||
burn (buffer, sizeof (buffer));
|
||||
|
||||
if (cryptoInfo != NULL)
|
||||
crypto_close (cryptoInfo);
|
||||
|
||||
if (bTimeStampValid)
|
||||
SetFileTime (dev, &ftCreationTime, &ftLastAccessTime, &ftLastWriteTime);
|
||||
|
||||
if (dev != INVALID_HANDLE_VALUE)
|
||||
CloseHandle ((HANDLE) dev);
|
||||
|
||||
if (nDosLinkCreated == 0)
|
||||
RemoveFakeDosName (szDiskFile, szDosDevice);
|
||||
|
||||
RandStop (FALSE);
|
||||
NormalCursor ();
|
||||
|
||||
SetLastError (dwError);
|
||||
|
||||
if (nStatus == ERR_OS_ERROR && dwError == ERROR_ACCESS_DENIED
|
||||
&& bDevice
|
||||
&& !UacElevated
|
||||
&& IsUacSupported ())
|
||||
return nStatus;
|
||||
|
||||
if (nStatus != 0)
|
||||
handleError (hwndDlg, nStatus, SRC_POS);
|
||||
|
||||
return nStatus;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,52 +1,52 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#ifndef PASSWORD_H
|
||||
#define PASSWORD_H
|
||||
|
||||
// User text input limits
|
||||
#define MIN_PASSWORD 1 // Minimum possible password length
|
||||
#define MAX_PASSWORD 64 // Maximum possible password length
|
||||
#define MAX_PIM 7 // Maximum allowed digits in a PIM (enough for maximum value)
|
||||
#define MAX_PIM_VALUE 2147468 // Maximum value to have a positive 32-bit result for formula 15000 + (PIM x 1000)
|
||||
#define MAX_BOOT_PIM 5 // Maximum allowed digits in a PIM for boot (enough for 16-bit value)
|
||||
#define MAX_BOOT_PIM_VALUE 65535
|
||||
|
||||
#define PASSWORD_LEN_WARNING 20 // Display a warning when a password is shorter than this
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// Modifying this structure can introduce incompatibility with previous versions
|
||||
unsigned __int32 Length;
|
||||
unsigned char Text[MAX_PASSWORD + 1];
|
||||
char Pad[3]; // keep 64-bit alignment
|
||||
} Password;
|
||||
|
||||
#if defined(_WIN32) && !defined(TC_WINDOWS_DRIVER)
|
||||
|
||||
void VerifyPasswordAndUpdate ( HWND hwndDlg , HWND hButton , HWND hPassword , HWND hVerify , unsigned char *szPassword , char *szVerify, BOOL keyFilesEnabled );
|
||||
BOOL CheckPasswordLength (HWND hwndDlg, unsigned __int32 passwordLength, int pim, BOOL bForBoot, BOOL bSkipPasswordWarning, BOOL bSkipPimWarning);
|
||||
BOOL CheckPasswordCharEncoding (HWND hPassword, Password *ptrPw);
|
||||
int ChangePwd (const wchar_t *lpszVolume, Password *oldPassword, int old_pkcs5, int old_pim, BOOL truecryptMode, Password *newPassword, int pkcs5, int pim, int wipePassCount, HWND hwndDlg);
|
||||
|
||||
#endif // defined(_WIN32) && !defined(TC_WINDOWS_DRIVER)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // PASSWORD_H
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#ifndef PASSWORD_H
|
||||
#define PASSWORD_H
|
||||
|
||||
// User text input limits
|
||||
#define MIN_PASSWORD 1 // Minimum possible password length
|
||||
#define MAX_PASSWORD 64 // Maximum possible password length
|
||||
#define MAX_PIM 7 // Maximum allowed digits in a PIM (enough for maximum value)
|
||||
#define MAX_PIM_VALUE 2147468 // Maximum value to have a positive 32-bit result for formula 15000 + (PIM x 1000)
|
||||
#define MAX_BOOT_PIM 5 // Maximum allowed digits in a PIM for boot (enough for 16-bit value)
|
||||
#define MAX_BOOT_PIM_VALUE 65535
|
||||
|
||||
#define PASSWORD_LEN_WARNING 20 // Display a warning when a password is shorter than this
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// Modifying this structure can introduce incompatibility with previous versions
|
||||
unsigned __int32 Length;
|
||||
unsigned char Text[MAX_PASSWORD + 1];
|
||||
char Pad[3]; // keep 64-bit alignment
|
||||
} Password;
|
||||
|
||||
#if defined(_WIN32) && !defined(TC_WINDOWS_DRIVER)
|
||||
|
||||
void VerifyPasswordAndUpdate ( HWND hwndDlg , HWND hButton , HWND hPassword , HWND hVerify , unsigned char *szPassword , char *szVerify, BOOL keyFilesEnabled );
|
||||
BOOL CheckPasswordLength (HWND hwndDlg, unsigned __int32 passwordLength, int pim, BOOL bForBoot, BOOL bSkipPasswordWarning, BOOL bSkipPimWarning);
|
||||
BOOL CheckPasswordCharEncoding (HWND hPassword, Password *ptrPw);
|
||||
int ChangePwd (const wchar_t *lpszVolume, Password *oldPassword, int old_pkcs5, int old_pim, BOOL truecryptMode, Password *newPassword, int pkcs5, int pim, int wipePassCount, HWND hwndDlg);
|
||||
|
||||
#endif // defined(_WIN32) && !defined(TC_WINDOWS_DRIVER)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // PASSWORD_H
|
||||
|
||||
1918
src/Common/Pkcs5.c
1918
src/Common/Pkcs5.c
File diff suppressed because it is too large
Load Diff
@@ -1,48 +1,48 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#ifndef TC_HEADER_PKCS5
|
||||
#define TC_HEADER_PKCS5
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
/* output written to input_digest which must be at lease 20 bytes long */
|
||||
void hmac_ripemd160 (char *key, int keylen, char *input_digest, int len);
|
||||
void derive_key_ripemd160 (char *pwd, int pwd_len, char *salt, int salt_len, uint32 iterations, char *dk, int dklen);
|
||||
|
||||
/* output written to d which must be at lease 32 bytes long */
|
||||
void hmac_sha256 (char *k, int lk, char *d, int ld);
|
||||
void derive_key_sha256 (char *pwd, int pwd_len, char *salt, int salt_len, uint32 iterations, char *dk, int dklen);
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
/* output written to d which must be at lease 64 bytes long */
|
||||
void hmac_sha512 (char *k, int lk, char *d, int ld);
|
||||
void derive_key_sha512 (char *pwd, int pwd_len, char *salt, int salt_len, uint32 iterations, char *dk, int dklen);
|
||||
|
||||
/* output written to d which must be at lease 64 bytes long */
|
||||
void hmac_whirlpool (char *k, int lk, char *d, int ld);
|
||||
void derive_key_whirlpool (char *pwd, int pwd_len, char *salt, int salt_len, uint32 iterations, char *dk, int dklen);
|
||||
|
||||
int get_pkcs5_iteration_count (int pkcs5_prf_id, int pim, BOOL truecryptMode, BOOL bBoot);
|
||||
wchar_t *get_pkcs5_prf_name (int pkcs5_prf_id);
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_PKCS5
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#ifndef TC_HEADER_PKCS5
|
||||
#define TC_HEADER_PKCS5
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
/* output written to input_digest which must be at lease 20 bytes long */
|
||||
void hmac_ripemd160 (char *key, int keylen, char *input_digest, int len);
|
||||
void derive_key_ripemd160 (char *pwd, int pwd_len, char *salt, int salt_len, uint32 iterations, char *dk, int dklen);
|
||||
|
||||
/* output written to d which must be at lease 32 bytes long */
|
||||
void hmac_sha256 (char *k, int lk, char *d, int ld);
|
||||
void derive_key_sha256 (char *pwd, int pwd_len, char *salt, int salt_len, uint32 iterations, char *dk, int dklen);
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
/* output written to d which must be at lease 64 bytes long */
|
||||
void hmac_sha512 (char *k, int lk, char *d, int ld);
|
||||
void derive_key_sha512 (char *pwd, int pwd_len, char *salt, int salt_len, uint32 iterations, char *dk, int dklen);
|
||||
|
||||
/* output written to d which must be at lease 64 bytes long */
|
||||
void hmac_whirlpool (char *k, int lk, char *d, int ld);
|
||||
void derive_key_whirlpool (char *pwd, int pwd_len, char *salt, int salt_len, uint32 iterations, char *dk, int dklen);
|
||||
|
||||
int get_pkcs5_iteration_count (int pkcs5_prf_id, int pim, BOOL truecryptMode, BOOL bBoot);
|
||||
wchar_t *get_pkcs5_prf_name (int pkcs5_prf_id);
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_PKCS5
|
||||
|
||||
@@ -1,134 +1,134 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Language.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Progress.h"
|
||||
#include "../Format/Tcformat.h"
|
||||
#include "../Format/FormatCom.h"
|
||||
#include "../Format/resource.h"
|
||||
|
||||
#include <Strsafe.h>
|
||||
|
||||
static ULONG prevTime, startTime;
|
||||
static __int64 TotalSize;
|
||||
static __int64 resumedPointBytesDone;
|
||||
static BOOL bProgressBarReverse = FALSE;
|
||||
static BOOL bRWThroughput = FALSE;
|
||||
static BOOL bShowStatus = FALSE;
|
||||
static BOOL bPercentMode = FALSE;
|
||||
|
||||
static wchar_t *seconds, *minutes, *hours, *days;
|
||||
|
||||
|
||||
// If bIOThroughput is TRUE, the speed reflects the amount of data read AND written per second (rather than
|
||||
// the speed of the "transform cursor").
|
||||
void InitProgressBar (__int64 totalBytes, __int64 bytesDone, BOOL bReverse, BOOL bIOThroughput, BOOL bDisplayStatus, BOOL bShowPercent)
|
||||
{
|
||||
HWND hProgressBar = GetDlgItem (hCurPage, nPbar);
|
||||
SendMessage (hProgressBar, PBM_SETRANGE32, 0, 10000);
|
||||
SendMessage (hProgressBar, PBM_SETSTEP, 1, 0);
|
||||
|
||||
bProgressBarReverse = bReverse;
|
||||
bRWThroughput = bIOThroughput;
|
||||
bShowStatus = bDisplayStatus;
|
||||
bPercentMode = bShowPercent;
|
||||
|
||||
seconds = GetString ("SECONDS");
|
||||
minutes = GetString ("MINUTES");
|
||||
hours = GetString ("HOURS");
|
||||
days = GetString ("DAYS");
|
||||
|
||||
prevTime = startTime = GetTickCount ();
|
||||
TotalSize = totalBytes;
|
||||
resumedPointBytesDone = bytesDone;
|
||||
}
|
||||
|
||||
|
||||
BOOL UpdateProgressBar (__int64 byteOffset)
|
||||
{
|
||||
return UpdateProgressBarProc (byteOffset);
|
||||
}
|
||||
|
||||
|
||||
BOOL UpdateProgressBarProc (__int64 byteOffset)
|
||||
{
|
||||
wchar_t text[100];
|
||||
wchar_t speed[100];
|
||||
HWND hProgressBar = GetDlgItem (hCurPage, nPbar);
|
||||
int time = GetTickCount ();
|
||||
int elapsed = (time - startTime) / 1000;
|
||||
|
||||
uint64 bytesDone = (bProgressBarReverse ? (TotalSize - byteOffset) : byteOffset);
|
||||
uint64 bytesPerSec = (bProgressBarReverse ? (resumedPointBytesDone - byteOffset) : (bytesDone - resumedPointBytesDone)) / (elapsed + 1);
|
||||
|
||||
if (bPercentMode)
|
||||
{
|
||||
double perc = (double) (100.0 * (bProgressBarReverse ? ((double) (TotalSize - byteOffset)) : ((double) byteOffset)) / (TotalSize == 0 ? 0.0001 : ((double) TotalSize)));
|
||||
|
||||
if (perc > 99.999999999)
|
||||
StringCchCopyW (text,ARRAYSIZE(text), GetString ("PROCESSED_PORTION_100_PERCENT"));
|
||||
else
|
||||
StringCchPrintfW (text, ARRAYSIZE (text), GetString ("PROCESSED_PORTION_X_PERCENT"), perc);
|
||||
|
||||
StringCchCatW (text, ARRAYSIZE(text), L" ");
|
||||
}
|
||||
else
|
||||
{
|
||||
GetSizeString (bytesDone, text, sizeof(text));
|
||||
if (bytesDone < (unsigned __int64) BYTES_PER_MB * 1000000)
|
||||
StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_MB, GetString ("MB"));
|
||||
else if (bytesDone < (unsigned __int64) BYTES_PER_GB * 1000000)
|
||||
StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_GB, GetString ("GB"));
|
||||
else if (bytesDone < (unsigned __int64) BYTES_PER_TB * 1000000)
|
||||
StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_TB, GetString ("TB"));
|
||||
else
|
||||
StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_PB, GetString ("PB"));
|
||||
}
|
||||
|
||||
SetWindowTextW (GetDlgItem (hCurPage, IDC_BYTESWRITTEN), text);
|
||||
|
||||
if (!bShowStatus)
|
||||
{
|
||||
GetSpeedString (bRWThroughput ? bytesPerSec*2 : bytesPerSec, speed, sizeof(speed));
|
||||
StringCchCatW (speed, ARRAYSIZE(speed), L" ");
|
||||
SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), speed);
|
||||
}
|
||||
|
||||
if (byteOffset < TotalSize)
|
||||
{
|
||||
int64 sec = (int64) ((bProgressBarReverse ? byteOffset : (TotalSize - byteOffset)) / (bytesPerSec == 0 ? 0.001 : bytesPerSec));
|
||||
|
||||
if (bytesPerSec == 0 || sec > 60 * 60 * 24 * 999)
|
||||
StringCchPrintfW (text, ARRAYSIZE(text), L"%s ", GetString ("NOT_APPLICABLE_OR_NOT_AVAILABLE"));
|
||||
else if (sec >= 60 * 60 * 24 * 2)
|
||||
StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec / (60 * 24 * 60), days);
|
||||
else if (sec >= 120 * 60)
|
||||
StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec / (60 * 60), hours);
|
||||
else if (sec >= 120)
|
||||
StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec / 60, minutes);
|
||||
else
|
||||
StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec, seconds);
|
||||
|
||||
SetWindowTextW (GetDlgItem (hCurPage, IDC_TIMEREMAIN), text);
|
||||
}
|
||||
|
||||
prevTime = time;
|
||||
|
||||
SendMessage (hProgressBar, PBM_SETPOS,
|
||||
(int) (10000.0 * (bProgressBarReverse ? (TotalSize - byteOffset) : byteOffset) / (TotalSize == 0 ? 1 : TotalSize)),
|
||||
0);
|
||||
|
||||
return bVolTransformThreadCancel;
|
||||
}
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Language.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Progress.h"
|
||||
#include "../Format/Tcformat.h"
|
||||
#include "../Format/FormatCom.h"
|
||||
#include "../Format/resource.h"
|
||||
|
||||
#include <Strsafe.h>
|
||||
|
||||
static ULONG prevTime, startTime;
|
||||
static __int64 TotalSize;
|
||||
static __int64 resumedPointBytesDone;
|
||||
static BOOL bProgressBarReverse = FALSE;
|
||||
static BOOL bRWThroughput = FALSE;
|
||||
static BOOL bShowStatus = FALSE;
|
||||
static BOOL bPercentMode = FALSE;
|
||||
|
||||
static wchar_t *seconds, *minutes, *hours, *days;
|
||||
|
||||
|
||||
// If bIOThroughput is TRUE, the speed reflects the amount of data read AND written per second (rather than
|
||||
// the speed of the "transform cursor").
|
||||
void InitProgressBar (__int64 totalBytes, __int64 bytesDone, BOOL bReverse, BOOL bIOThroughput, BOOL bDisplayStatus, BOOL bShowPercent)
|
||||
{
|
||||
HWND hProgressBar = GetDlgItem (hCurPage, nPbar);
|
||||
SendMessage (hProgressBar, PBM_SETRANGE32, 0, 10000);
|
||||
SendMessage (hProgressBar, PBM_SETSTEP, 1, 0);
|
||||
|
||||
bProgressBarReverse = bReverse;
|
||||
bRWThroughput = bIOThroughput;
|
||||
bShowStatus = bDisplayStatus;
|
||||
bPercentMode = bShowPercent;
|
||||
|
||||
seconds = GetString ("SECONDS");
|
||||
minutes = GetString ("MINUTES");
|
||||
hours = GetString ("HOURS");
|
||||
days = GetString ("DAYS");
|
||||
|
||||
prevTime = startTime = GetTickCount ();
|
||||
TotalSize = totalBytes;
|
||||
resumedPointBytesDone = bytesDone;
|
||||
}
|
||||
|
||||
|
||||
BOOL UpdateProgressBar (__int64 byteOffset)
|
||||
{
|
||||
return UpdateProgressBarProc (byteOffset);
|
||||
}
|
||||
|
||||
|
||||
BOOL UpdateProgressBarProc (__int64 byteOffset)
|
||||
{
|
||||
wchar_t text[100];
|
||||
wchar_t speed[100];
|
||||
HWND hProgressBar = GetDlgItem (hCurPage, nPbar);
|
||||
int time = GetTickCount ();
|
||||
int elapsed = (time - startTime) / 1000;
|
||||
|
||||
uint64 bytesDone = (bProgressBarReverse ? (TotalSize - byteOffset) : byteOffset);
|
||||
uint64 bytesPerSec = (bProgressBarReverse ? (resumedPointBytesDone - byteOffset) : (bytesDone - resumedPointBytesDone)) / (elapsed + 1);
|
||||
|
||||
if (bPercentMode)
|
||||
{
|
||||
double perc = (double) (100.0 * (bProgressBarReverse ? ((double) (TotalSize - byteOffset)) : ((double) byteOffset)) / (TotalSize == 0 ? 0.0001 : ((double) TotalSize)));
|
||||
|
||||
if (perc > 99.999999999)
|
||||
StringCchCopyW (text,ARRAYSIZE(text), GetString ("PROCESSED_PORTION_100_PERCENT"));
|
||||
else
|
||||
StringCchPrintfW (text, ARRAYSIZE (text), GetString ("PROCESSED_PORTION_X_PERCENT"), perc);
|
||||
|
||||
StringCchCatW (text, ARRAYSIZE(text), L" ");
|
||||
}
|
||||
else
|
||||
{
|
||||
GetSizeString (bytesDone, text, sizeof(text));
|
||||
if (bytesDone < (unsigned __int64) BYTES_PER_MB * 1000000)
|
||||
StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_MB, GetString ("MB"));
|
||||
else if (bytesDone < (unsigned __int64) BYTES_PER_GB * 1000000)
|
||||
StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_GB, GetString ("GB"));
|
||||
else if (bytesDone < (unsigned __int64) BYTES_PER_TB * 1000000)
|
||||
StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_TB, GetString ("TB"));
|
||||
else
|
||||
StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_PB, GetString ("PB"));
|
||||
}
|
||||
|
||||
SetWindowTextW (GetDlgItem (hCurPage, IDC_BYTESWRITTEN), text);
|
||||
|
||||
if (!bShowStatus)
|
||||
{
|
||||
GetSpeedString (bRWThroughput ? bytesPerSec*2 : bytesPerSec, speed, sizeof(speed));
|
||||
StringCchCatW (speed, ARRAYSIZE(speed), L" ");
|
||||
SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), speed);
|
||||
}
|
||||
|
||||
if (byteOffset < TotalSize)
|
||||
{
|
||||
int64 sec = (int64) ((bProgressBarReverse ? byteOffset : (TotalSize - byteOffset)) / (bytesPerSec == 0 ? 0.001 : bytesPerSec));
|
||||
|
||||
if (bytesPerSec == 0 || sec > 60 * 60 * 24 * 999)
|
||||
StringCchPrintfW (text, ARRAYSIZE(text), L"%s ", GetString ("NOT_APPLICABLE_OR_NOT_AVAILABLE"));
|
||||
else if (sec >= 60 * 60 * 24 * 2)
|
||||
StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec / (60 * 24 * 60), days);
|
||||
else if (sec >= 120 * 60)
|
||||
StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec / (60 * 60), hours);
|
||||
else if (sec >= 120)
|
||||
StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec / 60, minutes);
|
||||
else
|
||||
StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec, seconds);
|
||||
|
||||
SetWindowTextW (GetDlgItem (hCurPage, IDC_TIMEREMAIN), text);
|
||||
}
|
||||
|
||||
prevTime = time;
|
||||
|
||||
SendMessage (hProgressBar, PBM_SETPOS,
|
||||
(int) (10000.0 * (bProgressBarReverse ? (TotalSize - byteOffset) : byteOffset) / (TotalSize == 0 ? 1 : TotalSize)),
|
||||
0);
|
||||
|
||||
return bVolTransformThreadCancel;
|
||||
}
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef PBM_SETSTATE
|
||||
|
||||
#define PBM_SETSTATE (WM_USER+16) // wParam = PBST_[State] (NORMAL, ERROR, PAUSED)
|
||||
#define PBST_NORMAL 0x0001
|
||||
#define PBST_ERROR 0x0002
|
||||
#define PBST_PAUSED 0x0003
|
||||
|
||||
#endif
|
||||
|
||||
void InitProgressBar (__int64 totalBytes, __int64 bytesDone, BOOL bReverse, BOOL bIOThroughput, BOOL bDisplayStatus, BOOL bShowPercent);
|
||||
BOOL UpdateProgressBar (__int64 byteOffset);
|
||||
BOOL UpdateProgressBarProc (__int64 byteOffset);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef PBM_SETSTATE
|
||||
|
||||
#define PBM_SETSTATE (WM_USER+16) // wParam = PBST_[State] (NORMAL, ERROR, PAUSED)
|
||||
#define PBST_NORMAL 0x0001
|
||||
#define PBST_ERROR 0x0002
|
||||
#define PBST_PAUSED 0x0003
|
||||
|
||||
#endif
|
||||
|
||||
void InitProgressBar (__int64 totalBytes, __int64 bytesDone, BOOL bReverse, BOOL bIOThroughput, BOOL bDisplayStatus, BOOL bShowPercent);
|
||||
BOOL UpdateProgressBar (__int64 byteOffset);
|
||||
BOOL UpdateProgressBarProc (__int64 byteOffset);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
1796
src/Common/Random.c
1796
src/Common/Random.c
File diff suppressed because it is too large
Load Diff
@@ -1,76 +1,76 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
|
||||
#include "Crypto.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* RNG defines & pool pointers */
|
||||
#define RNG_POOL_SIZE 320 // Must be divisible by the size of the output of each of the implemented hash functions. (in bytes)
|
||||
|
||||
#if RNG_POOL_SIZE % SHA512_DIGESTSIZE || RNG_POOL_SIZE % WHIRLPOOL_DIGESTSIZE || RNG_POOL_SIZE % RIPEMD160_DIGESTSIZE
|
||||
#error RNG_POOL_SIZE must be divisible by the size of the output of each of the implemented hash functions.
|
||||
#endif
|
||||
|
||||
#define RANDOMPOOL_ALLOCSIZE RNG_POOL_SIZE
|
||||
|
||||
// After every RANDMIX_BYTE_INTERVAL-th byte written to the pool, the pool mixing function is applied to the entire pool
|
||||
#define RANDMIX_BYTE_INTERVAL 16
|
||||
|
||||
// FastPoll interval (in milliseconds)
|
||||
#define FASTPOLL_INTERVAL 500
|
||||
|
||||
void RandAddInt ( unsigned __int32 x );
|
||||
int Randinit ( void );
|
||||
void RandStop (BOOL freePool);
|
||||
BOOL IsRandomNumberGeneratorStarted ();
|
||||
void RandSetHashFunction ( int hash_algo_id );
|
||||
int RandGetHashFunction (void);
|
||||
void SetRandomPoolEnrichedByUserStatus (BOOL enriched);
|
||||
BOOL IsRandomPoolEnrichedByUser ();
|
||||
BOOL Randmix ( void );
|
||||
void RandaddBuf ( void *buf , int len );
|
||||
BOOL FastPoll ( void );
|
||||
BOOL SlowPoll ( void );
|
||||
|
||||
/* Get len random bytes from the pool (max. RNG_POOL_SIZE bytes per a single call) */
|
||||
BOOL RandgetBytes ( void* hwndDlg, unsigned char *buf , int len, BOOL forceSlowPoll );
|
||||
|
||||
/* Get len random bytes from the pool.
|
||||
* If allowAnyLength is FALSE, then len must be less or equal to RNG_POOL_SIZE
|
||||
* If allowAnyLength is TRUE, then len can have any positive value
|
||||
*/
|
||||
BOOL RandgetBytesFull ( void* hwndDlg, unsigned char *buf , int len, BOOL forceSlowPoll , BOOL allowAnyLength);
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
extern BOOL volatile bFastPollEnabled;
|
||||
extern BOOL volatile bRandmixEnabled;
|
||||
extern DWORD CryptoAPILastError;
|
||||
extern DWORD ProcessedMouseEventsCounter;
|
||||
|
||||
BOOL RandpeekBytes ( void* hwndDlg, unsigned char *buf , int len, DWORD* mouseCounter );
|
||||
void RandAddInt64 ( unsigned __int64 x );
|
||||
|
||||
LRESULT CALLBACK MouseProc ( int nCode , WPARAM wParam , LPARAM lParam );
|
||||
LRESULT CALLBACK KeyboardProc ( int nCode , WPARAM wParam , LPARAM lParam );
|
||||
static unsigned __stdcall PeriodicFastPollThreadProc (void *dummy);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
|
||||
#include "Crypto.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* RNG defines & pool pointers */
|
||||
#define RNG_POOL_SIZE 320 // Must be divisible by the size of the output of each of the implemented hash functions. (in bytes)
|
||||
|
||||
#if RNG_POOL_SIZE % SHA512_DIGESTSIZE || RNG_POOL_SIZE % WHIRLPOOL_DIGESTSIZE || RNG_POOL_SIZE % RIPEMD160_DIGESTSIZE
|
||||
#error RNG_POOL_SIZE must be divisible by the size of the output of each of the implemented hash functions.
|
||||
#endif
|
||||
|
||||
#define RANDOMPOOL_ALLOCSIZE RNG_POOL_SIZE
|
||||
|
||||
// After every RANDMIX_BYTE_INTERVAL-th byte written to the pool, the pool mixing function is applied to the entire pool
|
||||
#define RANDMIX_BYTE_INTERVAL 16
|
||||
|
||||
// FastPoll interval (in milliseconds)
|
||||
#define FASTPOLL_INTERVAL 500
|
||||
|
||||
void RandAddInt ( unsigned __int32 x );
|
||||
int Randinit ( void );
|
||||
void RandStop (BOOL freePool);
|
||||
BOOL IsRandomNumberGeneratorStarted ();
|
||||
void RandSetHashFunction ( int hash_algo_id );
|
||||
int RandGetHashFunction (void);
|
||||
void SetRandomPoolEnrichedByUserStatus (BOOL enriched);
|
||||
BOOL IsRandomPoolEnrichedByUser ();
|
||||
BOOL Randmix ( void );
|
||||
void RandaddBuf ( void *buf , int len );
|
||||
BOOL FastPoll ( void );
|
||||
BOOL SlowPoll ( void );
|
||||
|
||||
/* Get len random bytes from the pool (max. RNG_POOL_SIZE bytes per a single call) */
|
||||
BOOL RandgetBytes ( void* hwndDlg, unsigned char *buf , int len, BOOL forceSlowPoll );
|
||||
|
||||
/* Get len random bytes from the pool.
|
||||
* If allowAnyLength is FALSE, then len must be less or equal to RNG_POOL_SIZE
|
||||
* If allowAnyLength is TRUE, then len can have any positive value
|
||||
*/
|
||||
BOOL RandgetBytesFull ( void* hwndDlg, unsigned char *buf , int len, BOOL forceSlowPoll , BOOL allowAnyLength);
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
extern BOOL volatile bFastPollEnabled;
|
||||
extern BOOL volatile bRandmixEnabled;
|
||||
extern DWORD CryptoAPILastError;
|
||||
extern DWORD ProcessedMouseEventsCounter;
|
||||
|
||||
BOOL RandpeekBytes ( void* hwndDlg, unsigned char *buf , int len, DWORD* mouseCounter );
|
||||
void RandAddInt64 ( unsigned __int64 x );
|
||||
|
||||
LRESULT CALLBACK MouseProc ( int nCode , WPARAM wParam , LPARAM lParam );
|
||||
LRESULT CALLBACK KeyboardProc ( int nCode , WPARAM wParam , LPARAM lParam );
|
||||
static unsigned __stdcall PeriodicFastPollThreadProc (void *dummy);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,300 +1,300 @@
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Registry.h"
|
||||
#include <Strsafe.h>
|
||||
|
||||
BOOL ReadLocalMachineRegistryDword (wchar_t *subKey, wchar_t *name, DWORD *value)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD size = sizeof (*value);
|
||||
DWORD type;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
if (RegQueryValueEx (hkey, name, NULL, &type, (BYTE *) value, &size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return type == REG_DWORD;
|
||||
}
|
||||
|
||||
BOOL ReadLocalMachineRegistryMultiString (wchar_t *subKey, wchar_t *name, wchar_t *value, DWORD *size)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD type;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
if (RegQueryValueEx (hkey, name, NULL, &type, (BYTE *) value, size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return type == REG_MULTI_SZ;
|
||||
}
|
||||
|
||||
BOOL ReadLocalMachineRegistryString (const wchar_t *subKey, wchar_t *name, wchar_t *str, DWORD *size)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD type;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
if (RegQueryValueEx (hkey, name, NULL, &type, (BYTE *) str, size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return type == REG_SZ;
|
||||
}
|
||||
|
||||
BOOL ReadLocalMachineRegistryStringNonReflected (const wchar_t *subKey, wchar_t *name, wchar_t *str, DWORD *size, BOOL b32bitApp)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD type;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ | (b32bitApp? KEY_WOW64_32KEY: KEY_WOW64_64KEY), &hkey) != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
if (RegQueryValueEx (hkey, name, NULL, &type, (BYTE *) str, size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return type == REG_SZ;
|
||||
}
|
||||
|
||||
int ReadRegistryInt (wchar_t *subKey, wchar_t *name, int defaultValue)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD value, size = sizeof (DWORD);
|
||||
|
||||
if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey,
|
||||
0, KEY_READ, &hkey) != ERROR_SUCCESS)
|
||||
return defaultValue;
|
||||
|
||||
if (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) &value, &size) != ERROR_SUCCESS)
|
||||
value = defaultValue;
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return value;
|
||||
}
|
||||
|
||||
wchar_t *ReadRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *defaultValue, wchar_t *str, int maxLen)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
wchar_t value[MAX_PATH*4];
|
||||
DWORD size = sizeof (value);
|
||||
|
||||
str[maxLen/2-1] = 0;
|
||||
StringCbCopyW (str, maxLen, defaultValue);
|
||||
|
||||
ZeroMemory (value, sizeof value);
|
||||
if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey,
|
||||
0, KEY_READ, &hkey) == ERROR_SUCCESS)
|
||||
if (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) value, &size) == ERROR_SUCCESS)
|
||||
StringCbCopyW (str, maxLen,value);
|
||||
|
||||
if (hkey)
|
||||
RegCloseKey (hkey);
|
||||
return str;
|
||||
}
|
||||
|
||||
DWORD ReadRegistryBytes (wchar_t *path, wchar_t *name, char *value, int maxLen)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD size = maxLen;
|
||||
BOOL success = FALSE;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_CURRENT_USER, path, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
|
||||
return 0;
|
||||
|
||||
success = (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) value, &size) == ERROR_SUCCESS);
|
||||
RegCloseKey (hkey);
|
||||
|
||||
return success ? size : 0;
|
||||
}
|
||||
|
||||
void WriteRegistryInt (wchar_t *subKey, wchar_t *name, int value)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
|
||||
if (RegCreateKeyEx (HKEY_CURRENT_USER, subKey,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS)
|
||||
return;
|
||||
|
||||
RegSetValueEx (hkey, name, 0, REG_DWORD, (BYTE *) &value, sizeof value);
|
||||
RegCloseKey (hkey);
|
||||
}
|
||||
|
||||
BOOL WriteLocalMachineRegistryDword (wchar_t *subKey, wchar_t *name, DWORD value)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
LONG status;
|
||||
|
||||
if ((status = RegCreateKeyEx (HKEY_LOCAL_MACHINE, subKey,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp)) != ERROR_SUCCESS)
|
||||
{
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((status = RegSetValueEx (hkey, name, 0, REG_DWORD, (BYTE *) &value, sizeof value)) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WriteLocalMachineRegistryMultiString (wchar_t *subKey, wchar_t *name, wchar_t *multiString, DWORD size)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
LONG status;
|
||||
|
||||
if ((status = RegCreateKeyEx (HKEY_LOCAL_MACHINE, subKey,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp)) != ERROR_SUCCESS)
|
||||
{
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((status = RegSetValueEx (hkey, name, 0, REG_MULTI_SZ, (BYTE *) multiString, size)) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WriteLocalMachineRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *str, BOOL expandable)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
LONG status;
|
||||
|
||||
if ((status = RegCreateKeyEx (HKEY_LOCAL_MACHINE, subKey,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp)) != ERROR_SUCCESS)
|
||||
{
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((status = RegSetValueEx (hkey, name, 0, expandable ? REG_EXPAND_SZ : REG_SZ, (BYTE *) str, (DWORD) (wcslen (str) + 1) * sizeof (wchar_t))) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void WriteRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *str)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
|
||||
if (RegCreateKeyEx (HKEY_CURRENT_USER, subKey,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS)
|
||||
return;
|
||||
|
||||
RegSetValueEx (hkey, name, 0, REG_SZ, (BYTE *) str, (DWORD) (wcslen (str) + 1) * sizeof (wchar_t));
|
||||
RegCloseKey (hkey);
|
||||
}
|
||||
|
||||
BOOL WriteRegistryBytes (wchar_t *path, wchar_t *name, char *str, DWORD size)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
BOOL res;
|
||||
|
||||
if (RegCreateKeyEx (HKEY_CURRENT_USER, path,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
res = RegSetValueEx (hkey, name, 0, REG_BINARY, (BYTE *) str, size);
|
||||
RegCloseKey (hkey);
|
||||
return res == ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
BOOL DeleteLocalMachineRegistryKey (wchar_t *parentKey, wchar_t *subKeyToDelete)
|
||||
{
|
||||
LONG status;
|
||||
HKEY hkey = 0;
|
||||
|
||||
if ((status = RegOpenKeyEx (HKEY_LOCAL_MACHINE, parentKey, 0, KEY_WRITE, &hkey)) != ERROR_SUCCESS)
|
||||
{
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((status = RegDeleteKey (hkey, subKeyToDelete)) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void DeleteRegistryValue (wchar_t *subKey, wchar_t *name)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey, 0, KEY_WRITE, &hkey) != ERROR_SUCCESS)
|
||||
return;
|
||||
|
||||
RegDeleteValue (hkey, name);
|
||||
RegCloseKey (hkey);
|
||||
}
|
||||
|
||||
|
||||
void GetStartupRegKeyName (wchar_t *regk, size_t cbRegk)
|
||||
{
|
||||
// The string is split in order to prevent some antivirus packages from falsely reporting
|
||||
// VeraCrypt.exe to contain a possible Trojan horse because of this string (heuristic scan).
|
||||
StringCbPrintfW (regk, cbRegk,L"%s%s", L"Software\\Microsoft\\Windows\\Curren", L"tVersion\\Run");
|
||||
}
|
||||
|
||||
void GetRestorePointRegKeyName (wchar_t *regk, size_t cbRegk)
|
||||
{
|
||||
// The string is split in order to prevent some antivirus packages from falsely reporting
|
||||
// VeraCrypt.exe to contain a possible Trojan horse because of this string (heuristic scan).
|
||||
StringCbPrintfW (regk, cbRegk,L"%s%s%s%s", L"Software\\Microsoft\\Windows", L" NT\\Curren", L"tVersion\\Sy", L"stemRestore");
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Registry.h"
|
||||
#include <Strsafe.h>
|
||||
|
||||
BOOL ReadLocalMachineRegistryDword (wchar_t *subKey, wchar_t *name, DWORD *value)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD size = sizeof (*value);
|
||||
DWORD type;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
if (RegQueryValueEx (hkey, name, NULL, &type, (BYTE *) value, &size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return type == REG_DWORD;
|
||||
}
|
||||
|
||||
BOOL ReadLocalMachineRegistryMultiString (wchar_t *subKey, wchar_t *name, wchar_t *value, DWORD *size)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD type;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
if (RegQueryValueEx (hkey, name, NULL, &type, (BYTE *) value, size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return type == REG_MULTI_SZ;
|
||||
}
|
||||
|
||||
BOOL ReadLocalMachineRegistryString (const wchar_t *subKey, wchar_t *name, wchar_t *str, DWORD *size)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD type;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
if (RegQueryValueEx (hkey, name, NULL, &type, (BYTE *) str, size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return type == REG_SZ;
|
||||
}
|
||||
|
||||
BOOL ReadLocalMachineRegistryStringNonReflected (const wchar_t *subKey, wchar_t *name, wchar_t *str, DWORD *size, BOOL b32bitApp)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD type;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ | (b32bitApp? KEY_WOW64_32KEY: KEY_WOW64_64KEY), &hkey) != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
if (RegQueryValueEx (hkey, name, NULL, &type, (BYTE *) str, size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return type == REG_SZ;
|
||||
}
|
||||
|
||||
int ReadRegistryInt (wchar_t *subKey, wchar_t *name, int defaultValue)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD value, size = sizeof (DWORD);
|
||||
|
||||
if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey,
|
||||
0, KEY_READ, &hkey) != ERROR_SUCCESS)
|
||||
return defaultValue;
|
||||
|
||||
if (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) &value, &size) != ERROR_SUCCESS)
|
||||
value = defaultValue;
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return value;
|
||||
}
|
||||
|
||||
wchar_t *ReadRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *defaultValue, wchar_t *str, int maxLen)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
wchar_t value[MAX_PATH*4];
|
||||
DWORD size = sizeof (value);
|
||||
|
||||
str[maxLen/2-1] = 0;
|
||||
StringCbCopyW (str, maxLen, defaultValue);
|
||||
|
||||
ZeroMemory (value, sizeof value);
|
||||
if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey,
|
||||
0, KEY_READ, &hkey) == ERROR_SUCCESS)
|
||||
if (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) value, &size) == ERROR_SUCCESS)
|
||||
StringCbCopyW (str, maxLen,value);
|
||||
|
||||
if (hkey)
|
||||
RegCloseKey (hkey);
|
||||
return str;
|
||||
}
|
||||
|
||||
DWORD ReadRegistryBytes (wchar_t *path, wchar_t *name, char *value, int maxLen)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD size = maxLen;
|
||||
BOOL success = FALSE;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_CURRENT_USER, path, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
|
||||
return 0;
|
||||
|
||||
success = (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) value, &size) == ERROR_SUCCESS);
|
||||
RegCloseKey (hkey);
|
||||
|
||||
return success ? size : 0;
|
||||
}
|
||||
|
||||
void WriteRegistryInt (wchar_t *subKey, wchar_t *name, int value)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
|
||||
if (RegCreateKeyEx (HKEY_CURRENT_USER, subKey,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS)
|
||||
return;
|
||||
|
||||
RegSetValueEx (hkey, name, 0, REG_DWORD, (BYTE *) &value, sizeof value);
|
||||
RegCloseKey (hkey);
|
||||
}
|
||||
|
||||
BOOL WriteLocalMachineRegistryDword (wchar_t *subKey, wchar_t *name, DWORD value)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
LONG status;
|
||||
|
||||
if ((status = RegCreateKeyEx (HKEY_LOCAL_MACHINE, subKey,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp)) != ERROR_SUCCESS)
|
||||
{
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((status = RegSetValueEx (hkey, name, 0, REG_DWORD, (BYTE *) &value, sizeof value)) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WriteLocalMachineRegistryMultiString (wchar_t *subKey, wchar_t *name, wchar_t *multiString, DWORD size)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
LONG status;
|
||||
|
||||
if ((status = RegCreateKeyEx (HKEY_LOCAL_MACHINE, subKey,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp)) != ERROR_SUCCESS)
|
||||
{
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((status = RegSetValueEx (hkey, name, 0, REG_MULTI_SZ, (BYTE *) multiString, size)) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WriteLocalMachineRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *str, BOOL expandable)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
LONG status;
|
||||
|
||||
if ((status = RegCreateKeyEx (HKEY_LOCAL_MACHINE, subKey,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp)) != ERROR_SUCCESS)
|
||||
{
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((status = RegSetValueEx (hkey, name, 0, expandable ? REG_EXPAND_SZ : REG_SZ, (BYTE *) str, (DWORD) (wcslen (str) + 1) * sizeof (wchar_t))) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void WriteRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *str)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
|
||||
if (RegCreateKeyEx (HKEY_CURRENT_USER, subKey,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS)
|
||||
return;
|
||||
|
||||
RegSetValueEx (hkey, name, 0, REG_SZ, (BYTE *) str, (DWORD) (wcslen (str) + 1) * sizeof (wchar_t));
|
||||
RegCloseKey (hkey);
|
||||
}
|
||||
|
||||
BOOL WriteRegistryBytes (wchar_t *path, wchar_t *name, char *str, DWORD size)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
BOOL res;
|
||||
|
||||
if (RegCreateKeyEx (HKEY_CURRENT_USER, path,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
res = RegSetValueEx (hkey, name, 0, REG_BINARY, (BYTE *) str, size);
|
||||
RegCloseKey (hkey);
|
||||
return res == ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
BOOL DeleteLocalMachineRegistryKey (wchar_t *parentKey, wchar_t *subKeyToDelete)
|
||||
{
|
||||
LONG status;
|
||||
HKEY hkey = 0;
|
||||
|
||||
if ((status = RegOpenKeyEx (HKEY_LOCAL_MACHINE, parentKey, 0, KEY_WRITE, &hkey)) != ERROR_SUCCESS)
|
||||
{
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((status = RegDeleteKey (hkey, subKeyToDelete)) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void DeleteRegistryValue (wchar_t *subKey, wchar_t *name)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey, 0, KEY_WRITE, &hkey) != ERROR_SUCCESS)
|
||||
return;
|
||||
|
||||
RegDeleteValue (hkey, name);
|
||||
RegCloseKey (hkey);
|
||||
}
|
||||
|
||||
|
||||
void GetStartupRegKeyName (wchar_t *regk, size_t cbRegk)
|
||||
{
|
||||
// The string is split in order to prevent some antivirus packages from falsely reporting
|
||||
// VeraCrypt.exe to contain a possible Trojan horse because of this string (heuristic scan).
|
||||
StringCbPrintfW (regk, cbRegk,L"%s%s", L"Software\\Microsoft\\Windows\\Curren", L"tVersion\\Run");
|
||||
}
|
||||
|
||||
void GetRestorePointRegKeyName (wchar_t *regk, size_t cbRegk)
|
||||
{
|
||||
// The string is split in order to prevent some antivirus packages from falsely reporting
|
||||
// VeraCrypt.exe to contain a possible Trojan horse because of this string (heuristic scan).
|
||||
StringCbPrintfW (regk, cbRegk,L"%s%s%s%s", L"Software\\Microsoft\\Windows", L" NT\\Curren", L"tVersion\\Sy", L"stemRestore");
|
||||
}
|
||||
@@ -1,37 +1,37 @@
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
BOOL ReadLocalMachineRegistryDword (wchar_t *subKey, wchar_t *name, DWORD *value);
|
||||
BOOL ReadLocalMachineRegistryMultiString (wchar_t *subKey, wchar_t *name, wchar_t *value, DWORD *size);
|
||||
BOOL ReadLocalMachineRegistryString (const wchar_t *subKey, wchar_t *name, wchar_t *value, DWORD *size);
|
||||
BOOL ReadLocalMachineRegistryStringNonReflected (const wchar_t *subKey, wchar_t *name, wchar_t *str, DWORD *size, BOOL b32bitApp);
|
||||
int ReadRegistryInt (wchar_t *subKey, wchar_t *name, int defaultValue);
|
||||
wchar_t *ReadRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *defaultValue, wchar_t *str, int maxLen);
|
||||
DWORD ReadRegistryBytes (wchar_t *path, wchar_t *name, char *value, int maxLen);
|
||||
void WriteRegistryInt (wchar_t *subKey, wchar_t *name, int value);
|
||||
BOOL WriteLocalMachineRegistryDword (wchar_t *subKey, wchar_t *name, DWORD value);
|
||||
BOOL WriteLocalMachineRegistryMultiString (wchar_t *subKey, wchar_t *name, wchar_t *multiString, DWORD size);
|
||||
BOOL WriteLocalMachineRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *str, BOOL expandable);
|
||||
void WriteRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *str);
|
||||
BOOL WriteRegistryBytes (wchar_t *path, wchar_t *name, char *str, DWORD size);
|
||||
BOOL DeleteLocalMachineRegistryKey (wchar_t *parentKey, wchar_t *subKeyToDelete);
|
||||
void DeleteRegistryValue (wchar_t *subKey, wchar_t *name);
|
||||
void GetStartupRegKeyName (wchar_t *regk, size_t cbRegk);
|
||||
void GetRestorePointRegKeyName (wchar_t *regk, size_t cbRegk);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
BOOL ReadLocalMachineRegistryDword (wchar_t *subKey, wchar_t *name, DWORD *value);
|
||||
BOOL ReadLocalMachineRegistryMultiString (wchar_t *subKey, wchar_t *name, wchar_t *value, DWORD *size);
|
||||
BOOL ReadLocalMachineRegistryString (const wchar_t *subKey, wchar_t *name, wchar_t *value, DWORD *size);
|
||||
BOOL ReadLocalMachineRegistryStringNonReflected (const wchar_t *subKey, wchar_t *name, wchar_t *str, DWORD *size, BOOL b32bitApp);
|
||||
int ReadRegistryInt (wchar_t *subKey, wchar_t *name, int defaultValue);
|
||||
wchar_t *ReadRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *defaultValue, wchar_t *str, int maxLen);
|
||||
DWORD ReadRegistryBytes (wchar_t *path, wchar_t *name, char *value, int maxLen);
|
||||
void WriteRegistryInt (wchar_t *subKey, wchar_t *name, int value);
|
||||
BOOL WriteLocalMachineRegistryDword (wchar_t *subKey, wchar_t *name, DWORD value);
|
||||
BOOL WriteLocalMachineRegistryMultiString (wchar_t *subKey, wchar_t *name, wchar_t *multiString, DWORD size);
|
||||
BOOL WriteLocalMachineRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *str, BOOL expandable);
|
||||
void WriteRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *str);
|
||||
BOOL WriteRegistryBytes (wchar_t *path, wchar_t *name, char *str, DWORD size);
|
||||
BOOL DeleteLocalMachineRegistryKey (wchar_t *parentKey, wchar_t *subKeyToDelete);
|
||||
void DeleteRegistryValue (wchar_t *subKey, wchar_t *name);
|
||||
void GetStartupRegKeyName (wchar_t *regk, size_t cbRegk);
|
||||
void GetRestorePointRegKeyName (wchar_t *regk, size_t cbRegk);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,211 +1,211 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by Common.rc
|
||||
//
|
||||
#define IDI_TRUECRYPT_ICON 501
|
||||
#define IDI_TRUECRYPT_VOL_ICON 502
|
||||
#define IDD_BENCHMARK_DLG 503
|
||||
#define IDD_MOUNT_OPTIONS 504
|
||||
#define IDD_KEYFILES 505
|
||||
#define IDR_LANGUAGE 506
|
||||
#define IDI_TRUECRYPT 507
|
||||
#define IDD_ABOUT_DLG 508
|
||||
#define IDD_COMMANDHELP_DLG 509
|
||||
#define IDD_RAWDEVICES_DLG 510
|
||||
#define IDC_HOMEPAGE 511
|
||||
#define IDR_COMMON_RSRC_HEADER 512
|
||||
#define IDD_LANGUAGE 513
|
||||
#define IDD_CIPHER_TEST_DLG 514
|
||||
#define IDR_LICENSE 515
|
||||
#define IDD_AUXILIARY_DLG 516
|
||||
#define IDB_TEXTUAL_LOGO_BKG 517
|
||||
#define IDB_TEXTUAL_LOGO_96DPI 518
|
||||
#define IDB_TEXTUAL_LOGO_288DPI 519
|
||||
#define IDR_BOOT_SECTOR 520
|
||||
#define IDR_BOOT_SECTOR_AES 521
|
||||
#define IDR_BOOT_SECTOR_SERPENT 522
|
||||
#define IDR_BOOT_SECTOR_TWOFISH 523
|
||||
#define IDR_BOOT_LOADER_DECOMPRESSOR 524
|
||||
#define IDR_BOOT_LOADER 525
|
||||
#define IDR_BOOT_LOADER_AES 526
|
||||
#define IDR_BOOT_LOADER_SERPENT 527
|
||||
#define IDR_BOOT_LOADER_TWOFISH 528
|
||||
#define IDR_RESCUE_BOOT_SECTOR 529
|
||||
#define IDR_RESCUE_BOOT_SECTOR_AES 530
|
||||
#define IDR_RESCUE_BOOT_SECTOR_SERPENT 531
|
||||
#define IDR_RESCUE_BOOT_SECTOR_TWOFISH 532
|
||||
#define IDR_RESCUE_LOADER 533
|
||||
#define IDR_RESCUE_LOADER_AES 534
|
||||
#define IDR_RESCUE_LOADER_SERPENT 535
|
||||
#define IDR_RESCUE_LOADER_TWOFISH 536
|
||||
#define IDD_TOKEN_PASSWORD 537
|
||||
#define IDD_TOKEN_KEYFILES 538
|
||||
#define IDD_NEW_TOKEN_KEYFILE 539
|
||||
#define IDD_RANDOM_POOL_ENRICHMENT 540
|
||||
#define IDI_TRUECRYPT_MOUNTED_ICON 541
|
||||
#define IDR_BOOT_SECTOR_SHA2 542
|
||||
#define IDR_BOOT_SECTOR_AES_SHA2 543
|
||||
#define IDR_BOOT_SECTOR_SERPENT_SHA2 544
|
||||
#define IDR_BOOT_SECTOR_TWOFISH_SHA2 545
|
||||
#define IDR_BOOT_LOADER_SHA2 546
|
||||
#define IDR_BOOT_LOADER_AES_SHA2 547
|
||||
#define IDR_BOOT_LOADER_SERPENT_SHA2 548
|
||||
#define IDR_BOOT_LOADER_TWOFISH_SHA2 549
|
||||
#define IDR_RESCUE_BOOT_SECTOR_SHA2 550
|
||||
#define IDR_RESCUE_BOOT_SECTOR_AES_SHA2 551
|
||||
#define IDR_RESCUE_BOOT_SECTOR_SERPENT_SHA2 552
|
||||
#define IDR_RESCUE_BOOT_SECTOR_TWOFISH_SHA2 553
|
||||
#define IDR_RESCUE_LOADER_SHA2 554
|
||||
#define IDR_RESCUE_LOADER_AES_SHA2 555
|
||||
#define IDR_RESCUE_LOADER_SERPENT_SHA2 556
|
||||
#define IDR_RESCUE_LOADER_TWOFISH_SHA2 557
|
||||
#define IDC_HW_AES_LABEL_LINK 5000
|
||||
#define IDC_HW_AES 5001
|
||||
#define IDC_PARALLELIZATION_LABEL_LINK 5002
|
||||
#define IDC_PARALLELIZATION 5003
|
||||
#define IDT_TOKEN_PASSWORD 5004
|
||||
#define IDC_PRINT 5005
|
||||
#define IDC_KEY 5006
|
||||
#define IDC_PLAINTEXT 5007
|
||||
#define IDC_CIPHERTEXT 5008
|
||||
#define IDC_INFO_BOX_TEXT 5009
|
||||
#define IDC_SECONDARY_KEY 5010
|
||||
#define IDD_TEXT_INFO_DIALOG_BOX_DLG 5011
|
||||
#define IDC_TEST_DATA_UNIT_NUMBER 5012
|
||||
#define IDD_KEYFILE_GENERATOR 5013
|
||||
#define IDC_CIPHER 5014
|
||||
#define IDD_MULTI_CHOICE_DLG 5015
|
||||
#define IDC_TEST_BLOCK_NUMBER 5016
|
||||
#define IDD_STATIC_MODELESS_WAIT_DLG 5017
|
||||
#define IDC_POOL_CONTENTS 5018
|
||||
#define IDC_PRF_ID 5019
|
||||
#define IDC_KEY_SIZE 5020
|
||||
#define IDC_PLAINTEXT_SIZE 5021
|
||||
#define IDC_REDTICK 5022
|
||||
#define IDC_TESTS_MESSAGE 5023
|
||||
#define IDC_RESET 5024
|
||||
#define IDC_AUTO 5025
|
||||
#define IDC_DECRYPT 5026
|
||||
#define IDT_TEST_KEY 5027
|
||||
#define IDT_TEST_PLAINTEXT 5028
|
||||
#define IDT_PRF 5029
|
||||
#define IDT_XTS_MODE 5030
|
||||
#define IDT_TEST_CIPHERTEXT 5031
|
||||
#define IDT_KEY 5032
|
||||
#define IDT_PLAINTEXT 5033
|
||||
#define IDC_ENCRYPT 5034
|
||||
#define IDT_KEY_UNIT 5035
|
||||
#define IDT_CIPHER 5036
|
||||
#define IDT_PLAINTEXT_SIZE_UNIT 5037
|
||||
#define IDC_DEVICELIST 5038
|
||||
#define IDT_TEST_BLOCK_NUMBER 5039
|
||||
#define IDT_SECONDARY_KEY 5040
|
||||
#define IDC_PERFORM_BENCHMARK 5041
|
||||
#define IDT_TEST_DATA_UNIT_NUMBER 5042
|
||||
#define IDC_KEYFILES_HIDVOL_PROT 5043
|
||||
#define IDC_KEYLIST 5044
|
||||
#define IDC_ABOUT_BKG 5045
|
||||
#define IDT_ABOUT_VERSION 5046
|
||||
#define IDT_BOX_BENCHMARK_INFO 5047
|
||||
#define IDC_ABOUT_CREDITS 5048
|
||||
#define IDT_SORT_METHOD 5049
|
||||
#define IDC_MOUNT_READONLY 5050
|
||||
#define IDC_MOUNT_REMOVABLE 5051
|
||||
#define IDC_PROTECT_HIDDEN_VOL 5052
|
||||
#define IDC_COMMANDHELP_TEXT 5053
|
||||
#define IDC_USE_EMBEDDED_HEADER_BAK 5054
|
||||
#define IDC_MOUNT_SYSENC_PART_WITHOUT_PBA 5055
|
||||
#define IDT_HIDDEN_PROT_PASSWD 5056
|
||||
#define IDC_RESULTS 5057
|
||||
#define IDC_KEYADD 5058
|
||||
#define IDC_KEYREMOVE 5059
|
||||
#define IDC_KEYREMOVEALL 5060
|
||||
#define IDC_KEYFILES_ENABLE 5061
|
||||
#define IDT_HIDDEN_VOL_PROTECTION 5062
|
||||
#define IDC_ADD_KEYFILE_PATH 5063
|
||||
#define IDC_BENCHMARK_BUFFER_SIZE 5064
|
||||
#define IDC_SHOW_PASSWORD_MO 5065
|
||||
#define IDC_GENERATE_KEYFILE 5066
|
||||
#define IDC_BENCHMARK_SORT_METHOD 5067
|
||||
#define IDC_PASSWORD_PROT_HIDVOL 5068
|
||||
#define IDT_BUFFER_SIZE 5069
|
||||
#define IDC_LANGLIST 5070
|
||||
#define IDC_KEYFILES_ENABLE_HIDVOL_PROT 5071
|
||||
#define IDT_KEYFILES_NOTE 5072
|
||||
#define IDT_KEYFILE_WARNING 5073
|
||||
#define IDT_KEYFILE_GENERATOR_NOTE 5074
|
||||
#define IDC_GENERATE_AND_SAVE_KEYFILE 5075
|
||||
#define IDT_POOL_CONTENTS 5076
|
||||
#define IDC_GET_LANG_PACKS 5077
|
||||
#define IDT_LANGPACK_AUTHORS 5078
|
||||
#define IDC_LANGPACK_CREDITS 5079
|
||||
#define IDC_LANGPACK_VERSION 5080
|
||||
#define IDT_ACTIVE_LANG_PACK 5081
|
||||
#define IDC_DISPLAY_POOL_CONTENTS 5082
|
||||
#define IDC_XTS_MODE_ENABLED 5083
|
||||
#define IDC_MULTI_CHOICE_MSG 5084
|
||||
#define IDC_CHOICE1 5085
|
||||
#define IDC_CHOICE5 5086
|
||||
#define IDC_CHOICE2 5087
|
||||
#define IDC_CHOICE3 5088
|
||||
#define IDC_CHOICE4 5089
|
||||
#define IDC_CHOICE6 5090
|
||||
#define IDC_CHOICE7 5091
|
||||
#define IDC_CHOICE8 5092
|
||||
#define IDC_CHOICE9 5093
|
||||
#define IDC_CHOICE10 5094
|
||||
#define IDC_MC_DLG_HR1 5095
|
||||
#define IDC_MC_DLG_HR2 5096
|
||||
#define IDC_LINK_HIDVOL_PROTECTION_INFO 5097
|
||||
#define IDC_LINK_KEYFILES_INFO 5098
|
||||
#define IDC_TEXTUAL_LOGO_IMG 5099
|
||||
#define IDC_ASPECT_RATIO_CALIBRATION_BOX 5100
|
||||
#define IDC_ABOUT_LOGO_AREA 5101
|
||||
#define IDC_TOKEN_PASSWORD 5102
|
||||
#define IDC_TOKEN_FILE_LIST 5103
|
||||
#define IDC_TOKEN_FILES_ADD 5104
|
||||
#define IDC_EXPORT 5105
|
||||
#define IDC_DELETE 5106
|
||||
#define IDC_IMPORT_KEYFILE 5107
|
||||
#define IDC_SELECTED_TOKEN 5108
|
||||
#define IDT_SECURITY_TOKEN 5109
|
||||
#define IDT_TOKEN_KEYFILE_NAME 5110
|
||||
#define IDC_TOKEN_KEYFILE_NAME 5111
|
||||
#define IDT_TOKEN_PASSWORD_INFO 5112
|
||||
#define IDT_RANDOM_POOL_ENRICHMENT_NOTE 5113
|
||||
#define IDC_CONTINUE 5114
|
||||
#define IDT_ABOUT_RELEASE 5115
|
||||
#define IDT_STATIC_MODELESS_WAIT_DLG_INFO 5116
|
||||
#define IDT_NUMBER_KEYFILES 5117
|
||||
#define IDC_NUMBER_KEYFILES 5118
|
||||
#define IDT_KEYFILES_BASE_NAME 5119
|
||||
#define IDC_KEYFILES_BASE_NAME 5120
|
||||
#define IDC_KEYFILES_SIZE 5121
|
||||
#define IDC_KEYFILES_RANDOM_SIZE 5122
|
||||
#define IDT_KEYFILES_SIZE 5123
|
||||
#define IDD_STATIC_MODAL_WAIT_DLG 5124
|
||||
#define IDT_STATIC_MODAL_WAIT_DLG_INFO 5125
|
||||
#define IDC_WAIT_PROGRESS_BAR 5126
|
||||
#define IDC_PKCS5_PRF_ID 5127
|
||||
#define IDT_PKCS5_PRF 5128
|
||||
#define IDT_PIM 5129
|
||||
#define IDC_PIM 5130
|
||||
#define IDC_PIM_HELP 5131
|
||||
#define IDC_PIM_ENABLE 5132
|
||||
#define IDC_VOLUME_LABEL 5133
|
||||
#define IDT_VOLUME_LABEL 5134
|
||||
#define IDC_KEYFILES_TRY_EMPTY_PASSWORD 5135
|
||||
#define IDC_ENTROPY_BAR 5136
|
||||
#define IDT_ENTROPY_BAR 5137
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NO_MFC 1
|
||||
#define _APS_NEXT_RESOURCE_VALUE 558
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 5138
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by Common.rc
|
||||
//
|
||||
#define IDI_TRUECRYPT_ICON 501
|
||||
#define IDI_TRUECRYPT_VOL_ICON 502
|
||||
#define IDD_BENCHMARK_DLG 503
|
||||
#define IDD_MOUNT_OPTIONS 504
|
||||
#define IDD_KEYFILES 505
|
||||
#define IDR_LANGUAGE 506
|
||||
#define IDI_TRUECRYPT 507
|
||||
#define IDD_ABOUT_DLG 508
|
||||
#define IDD_COMMANDHELP_DLG 509
|
||||
#define IDD_RAWDEVICES_DLG 510
|
||||
#define IDC_HOMEPAGE 511
|
||||
#define IDR_COMMON_RSRC_HEADER 512
|
||||
#define IDD_LANGUAGE 513
|
||||
#define IDD_CIPHER_TEST_DLG 514
|
||||
#define IDR_LICENSE 515
|
||||
#define IDD_AUXILIARY_DLG 516
|
||||
#define IDB_TEXTUAL_LOGO_BKG 517
|
||||
#define IDB_TEXTUAL_LOGO_96DPI 518
|
||||
#define IDB_TEXTUAL_LOGO_288DPI 519
|
||||
#define IDR_BOOT_SECTOR 520
|
||||
#define IDR_BOOT_SECTOR_AES 521
|
||||
#define IDR_BOOT_SECTOR_SERPENT 522
|
||||
#define IDR_BOOT_SECTOR_TWOFISH 523
|
||||
#define IDR_BOOT_LOADER_DECOMPRESSOR 524
|
||||
#define IDR_BOOT_LOADER 525
|
||||
#define IDR_BOOT_LOADER_AES 526
|
||||
#define IDR_BOOT_LOADER_SERPENT 527
|
||||
#define IDR_BOOT_LOADER_TWOFISH 528
|
||||
#define IDR_RESCUE_BOOT_SECTOR 529
|
||||
#define IDR_RESCUE_BOOT_SECTOR_AES 530
|
||||
#define IDR_RESCUE_BOOT_SECTOR_SERPENT 531
|
||||
#define IDR_RESCUE_BOOT_SECTOR_TWOFISH 532
|
||||
#define IDR_RESCUE_LOADER 533
|
||||
#define IDR_RESCUE_LOADER_AES 534
|
||||
#define IDR_RESCUE_LOADER_SERPENT 535
|
||||
#define IDR_RESCUE_LOADER_TWOFISH 536
|
||||
#define IDD_TOKEN_PASSWORD 537
|
||||
#define IDD_TOKEN_KEYFILES 538
|
||||
#define IDD_NEW_TOKEN_KEYFILE 539
|
||||
#define IDD_RANDOM_POOL_ENRICHMENT 540
|
||||
#define IDI_TRUECRYPT_MOUNTED_ICON 541
|
||||
#define IDR_BOOT_SECTOR_SHA2 542
|
||||
#define IDR_BOOT_SECTOR_AES_SHA2 543
|
||||
#define IDR_BOOT_SECTOR_SERPENT_SHA2 544
|
||||
#define IDR_BOOT_SECTOR_TWOFISH_SHA2 545
|
||||
#define IDR_BOOT_LOADER_SHA2 546
|
||||
#define IDR_BOOT_LOADER_AES_SHA2 547
|
||||
#define IDR_BOOT_LOADER_SERPENT_SHA2 548
|
||||
#define IDR_BOOT_LOADER_TWOFISH_SHA2 549
|
||||
#define IDR_RESCUE_BOOT_SECTOR_SHA2 550
|
||||
#define IDR_RESCUE_BOOT_SECTOR_AES_SHA2 551
|
||||
#define IDR_RESCUE_BOOT_SECTOR_SERPENT_SHA2 552
|
||||
#define IDR_RESCUE_BOOT_SECTOR_TWOFISH_SHA2 553
|
||||
#define IDR_RESCUE_LOADER_SHA2 554
|
||||
#define IDR_RESCUE_LOADER_AES_SHA2 555
|
||||
#define IDR_RESCUE_LOADER_SERPENT_SHA2 556
|
||||
#define IDR_RESCUE_LOADER_TWOFISH_SHA2 557
|
||||
#define IDC_HW_AES_LABEL_LINK 5000
|
||||
#define IDC_HW_AES 5001
|
||||
#define IDC_PARALLELIZATION_LABEL_LINK 5002
|
||||
#define IDC_PARALLELIZATION 5003
|
||||
#define IDT_TOKEN_PASSWORD 5004
|
||||
#define IDC_PRINT 5005
|
||||
#define IDC_KEY 5006
|
||||
#define IDC_PLAINTEXT 5007
|
||||
#define IDC_CIPHERTEXT 5008
|
||||
#define IDC_INFO_BOX_TEXT 5009
|
||||
#define IDC_SECONDARY_KEY 5010
|
||||
#define IDD_TEXT_INFO_DIALOG_BOX_DLG 5011
|
||||
#define IDC_TEST_DATA_UNIT_NUMBER 5012
|
||||
#define IDD_KEYFILE_GENERATOR 5013
|
||||
#define IDC_CIPHER 5014
|
||||
#define IDD_MULTI_CHOICE_DLG 5015
|
||||
#define IDC_TEST_BLOCK_NUMBER 5016
|
||||
#define IDD_STATIC_MODELESS_WAIT_DLG 5017
|
||||
#define IDC_POOL_CONTENTS 5018
|
||||
#define IDC_PRF_ID 5019
|
||||
#define IDC_KEY_SIZE 5020
|
||||
#define IDC_PLAINTEXT_SIZE 5021
|
||||
#define IDC_REDTICK 5022
|
||||
#define IDC_TESTS_MESSAGE 5023
|
||||
#define IDC_RESET 5024
|
||||
#define IDC_AUTO 5025
|
||||
#define IDC_DECRYPT 5026
|
||||
#define IDT_TEST_KEY 5027
|
||||
#define IDT_TEST_PLAINTEXT 5028
|
||||
#define IDT_PRF 5029
|
||||
#define IDT_XTS_MODE 5030
|
||||
#define IDT_TEST_CIPHERTEXT 5031
|
||||
#define IDT_KEY 5032
|
||||
#define IDT_PLAINTEXT 5033
|
||||
#define IDC_ENCRYPT 5034
|
||||
#define IDT_KEY_UNIT 5035
|
||||
#define IDT_CIPHER 5036
|
||||
#define IDT_PLAINTEXT_SIZE_UNIT 5037
|
||||
#define IDC_DEVICELIST 5038
|
||||
#define IDT_TEST_BLOCK_NUMBER 5039
|
||||
#define IDT_SECONDARY_KEY 5040
|
||||
#define IDC_PERFORM_BENCHMARK 5041
|
||||
#define IDT_TEST_DATA_UNIT_NUMBER 5042
|
||||
#define IDC_KEYFILES_HIDVOL_PROT 5043
|
||||
#define IDC_KEYLIST 5044
|
||||
#define IDC_ABOUT_BKG 5045
|
||||
#define IDT_ABOUT_VERSION 5046
|
||||
#define IDT_BOX_BENCHMARK_INFO 5047
|
||||
#define IDC_ABOUT_CREDITS 5048
|
||||
#define IDT_SORT_METHOD 5049
|
||||
#define IDC_MOUNT_READONLY 5050
|
||||
#define IDC_MOUNT_REMOVABLE 5051
|
||||
#define IDC_PROTECT_HIDDEN_VOL 5052
|
||||
#define IDC_COMMANDHELP_TEXT 5053
|
||||
#define IDC_USE_EMBEDDED_HEADER_BAK 5054
|
||||
#define IDC_MOUNT_SYSENC_PART_WITHOUT_PBA 5055
|
||||
#define IDT_HIDDEN_PROT_PASSWD 5056
|
||||
#define IDC_RESULTS 5057
|
||||
#define IDC_KEYADD 5058
|
||||
#define IDC_KEYREMOVE 5059
|
||||
#define IDC_KEYREMOVEALL 5060
|
||||
#define IDC_KEYFILES_ENABLE 5061
|
||||
#define IDT_HIDDEN_VOL_PROTECTION 5062
|
||||
#define IDC_ADD_KEYFILE_PATH 5063
|
||||
#define IDC_BENCHMARK_BUFFER_SIZE 5064
|
||||
#define IDC_SHOW_PASSWORD_MO 5065
|
||||
#define IDC_GENERATE_KEYFILE 5066
|
||||
#define IDC_BENCHMARK_SORT_METHOD 5067
|
||||
#define IDC_PASSWORD_PROT_HIDVOL 5068
|
||||
#define IDT_BUFFER_SIZE 5069
|
||||
#define IDC_LANGLIST 5070
|
||||
#define IDC_KEYFILES_ENABLE_HIDVOL_PROT 5071
|
||||
#define IDT_KEYFILES_NOTE 5072
|
||||
#define IDT_KEYFILE_WARNING 5073
|
||||
#define IDT_KEYFILE_GENERATOR_NOTE 5074
|
||||
#define IDC_GENERATE_AND_SAVE_KEYFILE 5075
|
||||
#define IDT_POOL_CONTENTS 5076
|
||||
#define IDC_GET_LANG_PACKS 5077
|
||||
#define IDT_LANGPACK_AUTHORS 5078
|
||||
#define IDC_LANGPACK_CREDITS 5079
|
||||
#define IDC_LANGPACK_VERSION 5080
|
||||
#define IDT_ACTIVE_LANG_PACK 5081
|
||||
#define IDC_DISPLAY_POOL_CONTENTS 5082
|
||||
#define IDC_XTS_MODE_ENABLED 5083
|
||||
#define IDC_MULTI_CHOICE_MSG 5084
|
||||
#define IDC_CHOICE1 5085
|
||||
#define IDC_CHOICE5 5086
|
||||
#define IDC_CHOICE2 5087
|
||||
#define IDC_CHOICE3 5088
|
||||
#define IDC_CHOICE4 5089
|
||||
#define IDC_CHOICE6 5090
|
||||
#define IDC_CHOICE7 5091
|
||||
#define IDC_CHOICE8 5092
|
||||
#define IDC_CHOICE9 5093
|
||||
#define IDC_CHOICE10 5094
|
||||
#define IDC_MC_DLG_HR1 5095
|
||||
#define IDC_MC_DLG_HR2 5096
|
||||
#define IDC_LINK_HIDVOL_PROTECTION_INFO 5097
|
||||
#define IDC_LINK_KEYFILES_INFO 5098
|
||||
#define IDC_TEXTUAL_LOGO_IMG 5099
|
||||
#define IDC_ASPECT_RATIO_CALIBRATION_BOX 5100
|
||||
#define IDC_ABOUT_LOGO_AREA 5101
|
||||
#define IDC_TOKEN_PASSWORD 5102
|
||||
#define IDC_TOKEN_FILE_LIST 5103
|
||||
#define IDC_TOKEN_FILES_ADD 5104
|
||||
#define IDC_EXPORT 5105
|
||||
#define IDC_DELETE 5106
|
||||
#define IDC_IMPORT_KEYFILE 5107
|
||||
#define IDC_SELECTED_TOKEN 5108
|
||||
#define IDT_SECURITY_TOKEN 5109
|
||||
#define IDT_TOKEN_KEYFILE_NAME 5110
|
||||
#define IDC_TOKEN_KEYFILE_NAME 5111
|
||||
#define IDT_TOKEN_PASSWORD_INFO 5112
|
||||
#define IDT_RANDOM_POOL_ENRICHMENT_NOTE 5113
|
||||
#define IDC_CONTINUE 5114
|
||||
#define IDT_ABOUT_RELEASE 5115
|
||||
#define IDT_STATIC_MODELESS_WAIT_DLG_INFO 5116
|
||||
#define IDT_NUMBER_KEYFILES 5117
|
||||
#define IDC_NUMBER_KEYFILES 5118
|
||||
#define IDT_KEYFILES_BASE_NAME 5119
|
||||
#define IDC_KEYFILES_BASE_NAME 5120
|
||||
#define IDC_KEYFILES_SIZE 5121
|
||||
#define IDC_KEYFILES_RANDOM_SIZE 5122
|
||||
#define IDT_KEYFILES_SIZE 5123
|
||||
#define IDD_STATIC_MODAL_WAIT_DLG 5124
|
||||
#define IDT_STATIC_MODAL_WAIT_DLG_INFO 5125
|
||||
#define IDC_WAIT_PROGRESS_BAR 5126
|
||||
#define IDC_PKCS5_PRF_ID 5127
|
||||
#define IDT_PKCS5_PRF 5128
|
||||
#define IDT_PIM 5129
|
||||
#define IDC_PIM 5130
|
||||
#define IDC_PIM_HELP 5131
|
||||
#define IDC_PIM_ENABLE 5132
|
||||
#define IDC_VOLUME_LABEL 5133
|
||||
#define IDT_VOLUME_LABEL 5134
|
||||
#define IDC_KEYFILES_TRY_EMPTY_PASSWORD 5135
|
||||
#define IDC_ENTROPY_BAR 5136
|
||||
#define IDT_ENTROPY_BAR 5137
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NO_MFC 1
|
||||
#define _APS_NEXT_RESOURCE_VALUE 558
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 5138
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,226 +1,226 @@
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Common_SecurityToken
|
||||
#define TC_HEADER_Common_SecurityToken
|
||||
|
||||
#include "Platform/PlatformBase.h"
|
||||
#if defined (TC_WINDOWS) && !defined (TC_PROTOTYPE)
|
||||
# include "Exception.h"
|
||||
#else
|
||||
# include "Platform/Exception.h"
|
||||
#endif
|
||||
|
||||
#ifndef NULL_PTR
|
||||
# define NULL_PTR 0
|
||||
#endif
|
||||
#define CK_PTR *
|
||||
#define CK_CALLBACK_FUNCTION(RET_TYPE, NAME) RET_TYPE (* NAME)
|
||||
|
||||
#ifdef TC_WINDOWS
|
||||
|
||||
# include <windows.h>
|
||||
|
||||
# define CK_DEFINE_FUNCTION(RET_TYPE, NAME) RET_TYPE __declspec(dllexport) NAME
|
||||
# define CK_DECLARE_FUNCTION(RET_TYPE, NAME) RET_TYPE __declspec(dllimport) NAME
|
||||
# define CK_DECLARE_FUNCTION_POINTER(RET_TYPE, NAME) RET_TYPE __declspec(dllimport) (* NAME)
|
||||
|
||||
# pragma pack(push, cryptoki, 1)
|
||||
# include <pkcs11.h>
|
||||
# pragma pack(pop, cryptoki)
|
||||
|
||||
#else // !TC_WINDOWS
|
||||
|
||||
# define CK_DEFINE_FUNCTION(RET_TYPE, NAME) RET_TYPE NAME
|
||||
# define CK_DECLARE_FUNCTION(RET_TYPE, NAME) RET_TYPE NAME
|
||||
# define CK_DECLARE_FUNCTION_POINTER(RET_TYPE, NAME) RET_TYPE (* NAME)
|
||||
|
||||
# include <pkcs11.h>
|
||||
|
||||
#endif // !TC_WINDOWS
|
||||
|
||||
|
||||
#define TC_SECURITY_TOKEN_KEYFILE_URL_PREFIX L"token://"
|
||||
#define TC_SECURITY_TOKEN_KEYFILE_URL_SLOT L"slot"
|
||||
#define TC_SECURITY_TOKEN_KEYFILE_URL_FILE L"file"
|
||||
|
||||
namespace VeraCrypt
|
||||
{
|
||||
struct SecurityTokenInfo
|
||||
{
|
||||
CK_SLOT_ID SlotId;
|
||||
CK_FLAGS Flags;
|
||||
wstring Label;
|
||||
string LabelUtf8;
|
||||
};
|
||||
|
||||
struct SecurityTokenKeyfilePath
|
||||
{
|
||||
SecurityTokenKeyfilePath () { }
|
||||
SecurityTokenKeyfilePath (const wstring &path) : Path (path) { }
|
||||
operator wstring () const { return Path; }
|
||||
wstring Path;
|
||||
};
|
||||
|
||||
struct SecurityTokenKeyfile
|
||||
{
|
||||
SecurityTokenKeyfile () : Handle(CK_INVALID_HANDLE), SlotId(CK_UNAVAILABLE_INFORMATION) { Token.SlotId = CK_UNAVAILABLE_INFORMATION; Token.Flags = 0; }
|
||||
SecurityTokenKeyfile (const SecurityTokenKeyfilePath &path, char* pin = nullptr);
|
||||
|
||||
operator SecurityTokenKeyfilePath () const;
|
||||
|
||||
CK_OBJECT_HANDLE Handle;
|
||||
wstring Id;
|
||||
string IdUtf8;
|
||||
CK_SLOT_ID SlotId;
|
||||
SecurityTokenInfo Token;
|
||||
};
|
||||
|
||||
struct Pkcs11Exception : public Exception
|
||||
{
|
||||
Pkcs11Exception (CK_RV errorCode = (CK_RV) -1)
|
||||
: ErrorCode (errorCode),
|
||||
SubjectErrorCodeValid (false),
|
||||
SubjectErrorCode( (uint64) -1)
|
||||
{
|
||||
}
|
||||
|
||||
Pkcs11Exception (CK_RV errorCode, uint64 subjectErrorCode)
|
||||
: ErrorCode (errorCode),
|
||||
SubjectErrorCodeValid (true),
|
||||
SubjectErrorCode (subjectErrorCode)
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef TC_HEADER_Platform_Exception
|
||||
virtual ~Pkcs11Exception () throw () { }
|
||||
TC_SERIALIZABLE_EXCEPTION (Pkcs11Exception);
|
||||
#else
|
||||
void Show (HWND parent) const;
|
||||
#endif
|
||||
operator string () const;
|
||||
CK_RV GetErrorCode () const { return ErrorCode; }
|
||||
|
||||
protected:
|
||||
CK_RV ErrorCode;
|
||||
bool SubjectErrorCodeValid;
|
||||
uint64 SubjectErrorCode;
|
||||
};
|
||||
|
||||
|
||||
#ifdef TC_HEADER_Platform_Exception
|
||||
|
||||
#define TC_EXCEPTION(NAME) TC_EXCEPTION_DECL(NAME,Exception)
|
||||
|
||||
#undef TC_EXCEPTION_SET
|
||||
#define TC_EXCEPTION_SET \
|
||||
TC_EXCEPTION_NODECL (Pkcs11Exception); \
|
||||
TC_EXCEPTION (InvalidSecurityTokenKeyfilePath); \
|
||||
TC_EXCEPTION (SecurityTokenLibraryNotInitialized); \
|
||||
TC_EXCEPTION (SecurityTokenKeyfileAlreadyExists); \
|
||||
TC_EXCEPTION (SecurityTokenKeyfileNotFound);
|
||||
|
||||
TC_EXCEPTION_SET;
|
||||
|
||||
#undef TC_EXCEPTION
|
||||
|
||||
#else // !TC_HEADER_Platform_Exception
|
||||
|
||||
struct SecurityTokenLibraryNotInitialized : public Exception
|
||||
{
|
||||
void Show (HWND parent) const { Error (SecurityTokenLibraryPath[0] == 0 ? "NO_PKCS11_MODULE_SPECIFIED" : "PKCS11_MODULE_INIT_FAILED", parent); }
|
||||
};
|
||||
|
||||
struct InvalidSecurityTokenKeyfilePath : public Exception
|
||||
{
|
||||
void Show (HWND parent) const { Error ("INVALID_TOKEN_KEYFILE_PATH", parent); }
|
||||
};
|
||||
|
||||
struct SecurityTokenKeyfileAlreadyExists : public Exception
|
||||
{
|
||||
void Show (HWND parent) const { Error ("TOKEN_KEYFILE_ALREADY_EXISTS", parent); }
|
||||
};
|
||||
|
||||
struct SecurityTokenKeyfileNotFound : public Exception
|
||||
{
|
||||
void Show (HWND parent) const { Error ("TOKEN_KEYFILE_NOT_FOUND", parent); }
|
||||
};
|
||||
|
||||
#endif // !TC_HEADER_Platform_Exception
|
||||
|
||||
|
||||
struct Pkcs11Session
|
||||
{
|
||||
Pkcs11Session () : Handle (CK_UNAVAILABLE_INFORMATION), UserLoggedIn (false) { }
|
||||
|
||||
CK_SESSION_HANDLE Handle;
|
||||
bool UserLoggedIn;
|
||||
};
|
||||
|
||||
struct GetPinFunctor
|
||||
{
|
||||
virtual ~GetPinFunctor () { }
|
||||
virtual void operator() (string &str) = 0;
|
||||
};
|
||||
|
||||
struct SendExceptionFunctor
|
||||
{
|
||||
virtual ~SendExceptionFunctor () { }
|
||||
virtual void operator() (const Exception &e) = 0;
|
||||
};
|
||||
|
||||
class SecurityToken
|
||||
{
|
||||
public:
|
||||
static void CloseAllSessions () throw ();
|
||||
static void CloseLibrary ();
|
||||
static void CreateKeyfile (CK_SLOT_ID slotId, vector <byte> &keyfileData, const string &name);
|
||||
static void DeleteKeyfile (const SecurityTokenKeyfile &keyfile);
|
||||
static vector <SecurityTokenKeyfile> GetAvailableKeyfiles (CK_SLOT_ID *slotIdFilter = nullptr, const wstring keyfileIdFilter = wstring(), char* pin = nullptr);
|
||||
static void GetKeyfileData (const SecurityTokenKeyfile &keyfile, vector <byte> &keyfileData);
|
||||
static void GetKeyfileData (const SecurityTokenKeyfile &keyfile, char* pin, vector <byte> &keyfileData);
|
||||
static list <SecurityTokenInfo> GetAvailableTokens ();
|
||||
static SecurityTokenInfo GetTokenInfo (CK_SLOT_ID slotId);
|
||||
#ifdef TC_WINDOWS
|
||||
static void InitLibrary (const wstring &pkcs11LibraryPath, auto_ptr <GetPinFunctor> pinCallback, auto_ptr <SendExceptionFunctor> warningCallback);
|
||||
#else
|
||||
static void InitLibrary (const string &pkcs11LibraryPath, auto_ptr <GetPinFunctor> pinCallback, auto_ptr <SendExceptionFunctor> warningCallback);
|
||||
#endif
|
||||
static bool IsInitialized () { return Initialized; }
|
||||
static bool IsKeyfilePathValid (const wstring &securityTokenKeyfilePath);
|
||||
|
||||
static const size_t MaxPasswordLength = 128;
|
||||
|
||||
protected:
|
||||
static void CloseSession (CK_SLOT_ID slotId);
|
||||
static vector <CK_OBJECT_HANDLE> GetObjects (CK_SLOT_ID slotId, CK_ATTRIBUTE_TYPE objectClass);
|
||||
static void GetObjectAttribute (CK_SLOT_ID slotId, CK_OBJECT_HANDLE tokenObject, CK_ATTRIBUTE_TYPE attributeType, vector <byte> &attributeValue);
|
||||
static list <CK_SLOT_ID> GetTokenSlots ();
|
||||
static void Login (CK_SLOT_ID slotId, const char* pin);
|
||||
static void LoginUserIfRequired (CK_SLOT_ID slotId, char* cmdPin = nullptr);
|
||||
static void OpenSession (CK_SLOT_ID slotId);
|
||||
static void CheckLibraryStatus ();
|
||||
|
||||
static bool Initialized;
|
||||
static auto_ptr <GetPinFunctor> PinCallback;
|
||||
static CK_FUNCTION_LIST_PTR Pkcs11Functions;
|
||||
#ifdef TC_WINDOWS
|
||||
static HMODULE Pkcs11LibraryHandle;
|
||||
#else
|
||||
static void *Pkcs11LibraryHandle;
|
||||
#endif
|
||||
static map <CK_SLOT_ID, Pkcs11Session> Sessions;
|
||||
static auto_ptr <SendExceptionFunctor> WarningCallback;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // TC_HEADER_Common_SecurityToken
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Common_SecurityToken
|
||||
#define TC_HEADER_Common_SecurityToken
|
||||
|
||||
#include "Platform/PlatformBase.h"
|
||||
#if defined (TC_WINDOWS) && !defined (TC_PROTOTYPE)
|
||||
# include "Exception.h"
|
||||
#else
|
||||
# include "Platform/Exception.h"
|
||||
#endif
|
||||
|
||||
#ifndef NULL_PTR
|
||||
# define NULL_PTR 0
|
||||
#endif
|
||||
#define CK_PTR *
|
||||
#define CK_CALLBACK_FUNCTION(RET_TYPE, NAME) RET_TYPE (* NAME)
|
||||
|
||||
#ifdef TC_WINDOWS
|
||||
|
||||
# include <windows.h>
|
||||
|
||||
# define CK_DEFINE_FUNCTION(RET_TYPE, NAME) RET_TYPE __declspec(dllexport) NAME
|
||||
# define CK_DECLARE_FUNCTION(RET_TYPE, NAME) RET_TYPE __declspec(dllimport) NAME
|
||||
# define CK_DECLARE_FUNCTION_POINTER(RET_TYPE, NAME) RET_TYPE __declspec(dllimport) (* NAME)
|
||||
|
||||
# pragma pack(push, cryptoki, 1)
|
||||
# include <pkcs11.h>
|
||||
# pragma pack(pop, cryptoki)
|
||||
|
||||
#else // !TC_WINDOWS
|
||||
|
||||
# define CK_DEFINE_FUNCTION(RET_TYPE, NAME) RET_TYPE NAME
|
||||
# define CK_DECLARE_FUNCTION(RET_TYPE, NAME) RET_TYPE NAME
|
||||
# define CK_DECLARE_FUNCTION_POINTER(RET_TYPE, NAME) RET_TYPE (* NAME)
|
||||
|
||||
# include <pkcs11.h>
|
||||
|
||||
#endif // !TC_WINDOWS
|
||||
|
||||
|
||||
#define TC_SECURITY_TOKEN_KEYFILE_URL_PREFIX L"token://"
|
||||
#define TC_SECURITY_TOKEN_KEYFILE_URL_SLOT L"slot"
|
||||
#define TC_SECURITY_TOKEN_KEYFILE_URL_FILE L"file"
|
||||
|
||||
namespace VeraCrypt
|
||||
{
|
||||
struct SecurityTokenInfo
|
||||
{
|
||||
CK_SLOT_ID SlotId;
|
||||
CK_FLAGS Flags;
|
||||
wstring Label;
|
||||
string LabelUtf8;
|
||||
};
|
||||
|
||||
struct SecurityTokenKeyfilePath
|
||||
{
|
||||
SecurityTokenKeyfilePath () { }
|
||||
SecurityTokenKeyfilePath (const wstring &path) : Path (path) { }
|
||||
operator wstring () const { return Path; }
|
||||
wstring Path;
|
||||
};
|
||||
|
||||
struct SecurityTokenKeyfile
|
||||
{
|
||||
SecurityTokenKeyfile () : Handle(CK_INVALID_HANDLE), SlotId(CK_UNAVAILABLE_INFORMATION) { Token.SlotId = CK_UNAVAILABLE_INFORMATION; Token.Flags = 0; }
|
||||
SecurityTokenKeyfile (const SecurityTokenKeyfilePath &path, char* pin = nullptr);
|
||||
|
||||
operator SecurityTokenKeyfilePath () const;
|
||||
|
||||
CK_OBJECT_HANDLE Handle;
|
||||
wstring Id;
|
||||
string IdUtf8;
|
||||
CK_SLOT_ID SlotId;
|
||||
SecurityTokenInfo Token;
|
||||
};
|
||||
|
||||
struct Pkcs11Exception : public Exception
|
||||
{
|
||||
Pkcs11Exception (CK_RV errorCode = (CK_RV) -1)
|
||||
: ErrorCode (errorCode),
|
||||
SubjectErrorCodeValid (false),
|
||||
SubjectErrorCode( (uint64) -1)
|
||||
{
|
||||
}
|
||||
|
||||
Pkcs11Exception (CK_RV errorCode, uint64 subjectErrorCode)
|
||||
: ErrorCode (errorCode),
|
||||
SubjectErrorCodeValid (true),
|
||||
SubjectErrorCode (subjectErrorCode)
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef TC_HEADER_Platform_Exception
|
||||
virtual ~Pkcs11Exception () throw () { }
|
||||
TC_SERIALIZABLE_EXCEPTION (Pkcs11Exception);
|
||||
#else
|
||||
void Show (HWND parent) const;
|
||||
#endif
|
||||
operator string () const;
|
||||
CK_RV GetErrorCode () const { return ErrorCode; }
|
||||
|
||||
protected:
|
||||
CK_RV ErrorCode;
|
||||
bool SubjectErrorCodeValid;
|
||||
uint64 SubjectErrorCode;
|
||||
};
|
||||
|
||||
|
||||
#ifdef TC_HEADER_Platform_Exception
|
||||
|
||||
#define TC_EXCEPTION(NAME) TC_EXCEPTION_DECL(NAME,Exception)
|
||||
|
||||
#undef TC_EXCEPTION_SET
|
||||
#define TC_EXCEPTION_SET \
|
||||
TC_EXCEPTION_NODECL (Pkcs11Exception); \
|
||||
TC_EXCEPTION (InvalidSecurityTokenKeyfilePath); \
|
||||
TC_EXCEPTION (SecurityTokenLibraryNotInitialized); \
|
||||
TC_EXCEPTION (SecurityTokenKeyfileAlreadyExists); \
|
||||
TC_EXCEPTION (SecurityTokenKeyfileNotFound);
|
||||
|
||||
TC_EXCEPTION_SET;
|
||||
|
||||
#undef TC_EXCEPTION
|
||||
|
||||
#else // !TC_HEADER_Platform_Exception
|
||||
|
||||
struct SecurityTokenLibraryNotInitialized : public Exception
|
||||
{
|
||||
void Show (HWND parent) const { Error (SecurityTokenLibraryPath[0] == 0 ? "NO_PKCS11_MODULE_SPECIFIED" : "PKCS11_MODULE_INIT_FAILED", parent); }
|
||||
};
|
||||
|
||||
struct InvalidSecurityTokenKeyfilePath : public Exception
|
||||
{
|
||||
void Show (HWND parent) const { Error ("INVALID_TOKEN_KEYFILE_PATH", parent); }
|
||||
};
|
||||
|
||||
struct SecurityTokenKeyfileAlreadyExists : public Exception
|
||||
{
|
||||
void Show (HWND parent) const { Error ("TOKEN_KEYFILE_ALREADY_EXISTS", parent); }
|
||||
};
|
||||
|
||||
struct SecurityTokenKeyfileNotFound : public Exception
|
||||
{
|
||||
void Show (HWND parent) const { Error ("TOKEN_KEYFILE_NOT_FOUND", parent); }
|
||||
};
|
||||
|
||||
#endif // !TC_HEADER_Platform_Exception
|
||||
|
||||
|
||||
struct Pkcs11Session
|
||||
{
|
||||
Pkcs11Session () : Handle (CK_UNAVAILABLE_INFORMATION), UserLoggedIn (false) { }
|
||||
|
||||
CK_SESSION_HANDLE Handle;
|
||||
bool UserLoggedIn;
|
||||
};
|
||||
|
||||
struct GetPinFunctor
|
||||
{
|
||||
virtual ~GetPinFunctor () { }
|
||||
virtual void operator() (string &str) = 0;
|
||||
};
|
||||
|
||||
struct SendExceptionFunctor
|
||||
{
|
||||
virtual ~SendExceptionFunctor () { }
|
||||
virtual void operator() (const Exception &e) = 0;
|
||||
};
|
||||
|
||||
class SecurityToken
|
||||
{
|
||||
public:
|
||||
static void CloseAllSessions () throw ();
|
||||
static void CloseLibrary ();
|
||||
static void CreateKeyfile (CK_SLOT_ID slotId, vector <byte> &keyfileData, const string &name);
|
||||
static void DeleteKeyfile (const SecurityTokenKeyfile &keyfile);
|
||||
static vector <SecurityTokenKeyfile> GetAvailableKeyfiles (CK_SLOT_ID *slotIdFilter = nullptr, const wstring keyfileIdFilter = wstring(), char* pin = nullptr);
|
||||
static void GetKeyfileData (const SecurityTokenKeyfile &keyfile, vector <byte> &keyfileData);
|
||||
static void GetKeyfileData (const SecurityTokenKeyfile &keyfile, char* pin, vector <byte> &keyfileData);
|
||||
static list <SecurityTokenInfo> GetAvailableTokens ();
|
||||
static SecurityTokenInfo GetTokenInfo (CK_SLOT_ID slotId);
|
||||
#ifdef TC_WINDOWS
|
||||
static void InitLibrary (const wstring &pkcs11LibraryPath, auto_ptr <GetPinFunctor> pinCallback, auto_ptr <SendExceptionFunctor> warningCallback);
|
||||
#else
|
||||
static void InitLibrary (const string &pkcs11LibraryPath, auto_ptr <GetPinFunctor> pinCallback, auto_ptr <SendExceptionFunctor> warningCallback);
|
||||
#endif
|
||||
static bool IsInitialized () { return Initialized; }
|
||||
static bool IsKeyfilePathValid (const wstring &securityTokenKeyfilePath);
|
||||
|
||||
static const size_t MaxPasswordLength = 128;
|
||||
|
||||
protected:
|
||||
static void CloseSession (CK_SLOT_ID slotId);
|
||||
static vector <CK_OBJECT_HANDLE> GetObjects (CK_SLOT_ID slotId, CK_ATTRIBUTE_TYPE objectClass);
|
||||
static void GetObjectAttribute (CK_SLOT_ID slotId, CK_OBJECT_HANDLE tokenObject, CK_ATTRIBUTE_TYPE attributeType, vector <byte> &attributeValue);
|
||||
static list <CK_SLOT_ID> GetTokenSlots ();
|
||||
static void Login (CK_SLOT_ID slotId, const char* pin);
|
||||
static void LoginUserIfRequired (CK_SLOT_ID slotId, char* cmdPin = nullptr);
|
||||
static void OpenSession (CK_SLOT_ID slotId);
|
||||
static void CheckLibraryStatus ();
|
||||
|
||||
static bool Initialized;
|
||||
static auto_ptr <GetPinFunctor> PinCallback;
|
||||
static CK_FUNCTION_LIST_PTR Pkcs11Functions;
|
||||
#ifdef TC_WINDOWS
|
||||
static HMODULE Pkcs11LibraryHandle;
|
||||
#else
|
||||
static void *Pkcs11LibraryHandle;
|
||||
#endif
|
||||
static map <CK_SLOT_ID, Pkcs11Session> Sessions;
|
||||
static auto_ptr <SendExceptionFunctor> WarningCallback;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // TC_HEADER_Common_SecurityToken
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
TARGETNAME=Common
|
||||
TARGETTYPE=DRIVER_LIBRARY
|
||||
|
||||
INCLUDES = ..;../Crypto
|
||||
|
||||
SOURCES = \
|
||||
Cache.c \
|
||||
Crc.c \
|
||||
Crypto.c \
|
||||
EncryptionThreadPool.c \
|
||||
Endian.c \
|
||||
GfMul.c \
|
||||
Pkcs5.c \
|
||||
Volumes.c \
|
||||
Xts.c \
|
||||
Tests.c \
|
||||
Wipe.c
|
||||
TARGETNAME=Common
|
||||
TARGETTYPE=DRIVER_LIBRARY
|
||||
|
||||
INCLUDES = ..;../Crypto
|
||||
|
||||
SOURCES = \
|
||||
Cache.c \
|
||||
Crc.c \
|
||||
Crypto.c \
|
||||
EncryptionThreadPool.c \
|
||||
Endian.c \
|
||||
GfMul.c \
|
||||
Pkcs5.c \
|
||||
Volumes.c \
|
||||
Xts.c \
|
||||
Tests.c \
|
||||
Wipe.c
|
||||
|
||||
@@ -1,323 +1,323 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#ifndef TCDEFS_H
|
||||
#define TCDEFS_H
|
||||
|
||||
#define TC_APP_NAME "VeraCrypt"
|
||||
|
||||
// Version displayed to user
|
||||
#define VERSION_STRING "1.17"
|
||||
|
||||
// Version number to compare against driver
|
||||
#define VERSION_NUM 0x0117
|
||||
|
||||
// Release date
|
||||
#define TC_STR_RELEASE_DATE L"February 13th, 2016"
|
||||
#define TC_RELEASE_DATE_YEAR 2016
|
||||
#define TC_RELEASE_DATE_MONTH 2
|
||||
|
||||
#define BYTES_PER_KB 1024LL
|
||||
#define BYTES_PER_MB 1048576LL
|
||||
#define BYTES_PER_GB 1073741824LL
|
||||
#define BYTES_PER_TB 1099511627776LL
|
||||
#define BYTES_PER_PB 1125899906842624LL
|
||||
|
||||
/* GUI/driver errors */
|
||||
|
||||
#define WIDE(x) (LPWSTR)L##x
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
typedef __int8 int8;
|
||||
typedef __int16 int16;
|
||||
typedef __int32 int32;
|
||||
typedef unsigned __int8 byte;
|
||||
typedef unsigned __int16 uint16;
|
||||
typedef unsigned __int32 uint32;
|
||||
|
||||
#ifdef TC_NO_COMPILER_INT64
|
||||
typedef unsigned __int32 TC_LARGEST_COMPILER_UINT;
|
||||
#else
|
||||
typedef unsigned __int64 TC_LARGEST_COMPILER_UINT;
|
||||
typedef __int64 int64;
|
||||
typedef unsigned __int64 uint64;
|
||||
#define LL(x) x##ui64
|
||||
#endif
|
||||
|
||||
#else // !_MSC_VER
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
|
||||
typedef int8_t int8;
|
||||
typedef int16_t int16;
|
||||
typedef int32_t int32;
|
||||
typedef int64_t int64;
|
||||
typedef uint8_t byte;
|
||||
typedef uint16_t uint16;
|
||||
typedef uint32_t uint32;
|
||||
typedef uint64_t uint64;
|
||||
|
||||
#define LL(x) x##ULL
|
||||
|
||||
#if UCHAR_MAX != 0xffU
|
||||
#error UCHAR_MAX != 0xff
|
||||
#endif
|
||||
#define __int8 char
|
||||
|
||||
#if USHRT_MAX != 0xffffU
|
||||
#error USHRT_MAX != 0xffff
|
||||
#endif
|
||||
#define __int16 short
|
||||
|
||||
#if UINT_MAX != 0xffffffffU
|
||||
#error UINT_MAX != 0xffffffff
|
||||
#endif
|
||||
#define __int32 int
|
||||
|
||||
typedef uint64 TC_LARGEST_COMPILER_UINT;
|
||||
|
||||
#define BOOL int
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#endif // !_MSC_VER
|
||||
|
||||
#define TC_INT_TYPES_DEFINED
|
||||
|
||||
// Integer types required by Cryptolib
|
||||
typedef unsigned __int8 uint_8t;
|
||||
typedef unsigned __int16 uint_16t;
|
||||
typedef unsigned __int32 uint_32t;
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
typedef uint64 uint_64t;
|
||||
#endif
|
||||
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
unsigned __int32 LowPart;
|
||||
unsigned __int32 HighPart;
|
||||
};
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
uint64 Value;
|
||||
#endif
|
||||
|
||||
} UINT64_STRUCT;
|
||||
|
||||
#ifndef __has_builtin // Optional of course
|
||||
#define __has_builtin(x) 0 // Compatibility with non-clang compilers
|
||||
#endif
|
||||
|
||||
#ifdef TC_WINDOWS_BOOT
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C"
|
||||
# endif
|
||||
void ThrowFatalException (int line);
|
||||
|
||||
# define TC_THROW_FATAL_EXCEPTION ThrowFatalException (__LINE__)
|
||||
#elif defined (TC_WINDOWS_DRIVER)
|
||||
# define TC_THROW_FATAL_EXCEPTION KeBugCheckEx (SECURITY_SYSTEM, __LINE__, 0, 0, 'VC')
|
||||
#elif (defined(__clang__) && __has_builtin(__builtin_trap)) \
|
||||
|| (defined(__GNUC__ ) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))) \
|
||||
|| (__has_builtin(__builtin_trap))
|
||||
# define TC_THROW_FATAL_EXCEPTION __builtin_trap()
|
||||
#else
|
||||
# define TC_THROW_FATAL_EXCEPTION *(char *) 0 = 0
|
||||
#endif
|
||||
|
||||
#ifdef __COVERITY__
|
||||
#undef TC_THROW_FATAL_EXCEPTION
|
||||
#define TC_THROW_FATAL_EXCEPTION __coverity_panic__()
|
||||
#endif
|
||||
|
||||
#ifdef TC_WINDOWS_DRIVER
|
||||
|
||||
#include <ntifs.h>
|
||||
#include <ntddk.h> /* Standard header file for nt drivers */
|
||||
#include <ntdddisk.h> /* Standard I/O control codes */
|
||||
|
||||
#define TCalloc(size) ((void *) ExAllocatePoolWithTag( NonPagedPool, size, 'MMCV' ))
|
||||
#define TCfree(memblock) ExFreePoolWithTag( memblock, 'MMCV' )
|
||||
|
||||
#define DEVICE_DRIVER
|
||||
|
||||
#ifndef BOOL
|
||||
typedef int BOOL;
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE !TRUE
|
||||
#endif
|
||||
|
||||
#else /* !TC_WINDOWS_DRIVER */
|
||||
|
||||
#define TCalloc malloc
|
||||
#define TCfree free
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#ifndef TC_LOCAL_WIN32_WINNT_OVERRIDE
|
||||
# undef _WIN32_WINNT
|
||||
# define _WIN32_WINNT 0x0501 /* Does not apply to the driver */
|
||||
#endif
|
||||
|
||||
#include <windows.h> /* Windows header */
|
||||
#include <commctrl.h> /* The common controls */
|
||||
#include <process.h> /* Process control */
|
||||
#include <winioctl.h>
|
||||
#include <stdio.h> /* For sprintf */
|
||||
#include <tchar.h>
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#endif /* !TC_WINDOWS_DRIVER */
|
||||
|
||||
#ifndef TC_TO_STRING
|
||||
# define TC_TO_STRING2(n) #n
|
||||
# define TC_TO_STRING(n) TC_TO_STRING2(n)
|
||||
#endif
|
||||
|
||||
#ifdef DEVICE_DRIVER
|
||||
# if defined (DEBUG) || 0
|
||||
# if 1 // DbgPrintEx is not available on Windows 2000
|
||||
# define Dump DbgPrint
|
||||
# else
|
||||
# define Dump(...) DbgPrintEx (DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, __VA_ARGS__)
|
||||
# endif
|
||||
# define DumpMem(...) DumpMemory (__VA_ARGS__)
|
||||
# else
|
||||
# define Dump(...)
|
||||
# define DumpMem(...)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined (trace_msg) && !defined (TC_WINDOWS_BOOT)
|
||||
# ifdef DEBUG
|
||||
# ifdef DEVICE_DRIVER
|
||||
# define trace_msg Dump
|
||||
# elif defined (_WIN32)
|
||||
# define trace_msg(...) do { char msg[2048]; StringCbPrintfA (msg, sizeof (msg), __VA_ARGS__); OutputDebugString (msg); } while (0)
|
||||
# endif
|
||||
# define trace_point trace_msg (__FUNCTION__ ":" TC_TO_STRING(__LINE__) "\n")
|
||||
# else
|
||||
# define trace_msg(...)
|
||||
# define trace_point
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef DEVICE_DRIVER
|
||||
# define TC_EVENT KEVENT
|
||||
# define TC_WAIT_EVENT(EVENT) KeWaitForSingleObject (&EVENT, Executive, KernelMode, FALSE, NULL)
|
||||
#elif defined (_WIN32)
|
||||
# define TC_EVENT HANDLE
|
||||
# define TC_WAIT_EVENT(EVENT) WaitForSingleObject (EVENT, INFINITE)
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define burn(mem,size) do { volatile char *burnm = (volatile char *)(mem); size_t burnc = size; RtlSecureZeroMemory (mem, size); while (burnc--) *burnm++ = 0; } while (0)
|
||||
#else
|
||||
#define burn(mem,size) do { volatile char *burnm = (volatile char *)(mem); int burnc = size; while (burnc--) *burnm++ = 0; } while (0)
|
||||
#endif
|
||||
|
||||
// The size of the memory area to wipe is in bytes amd it must be a multiple of 8.
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
# define FAST_ERASE64(mem,size) do { volatile uint64 *burnm = (volatile uint64 *)(mem); int burnc = size >> 3; while (burnc--) *burnm++ = 0; } while (0)
|
||||
#else
|
||||
# define FAST_ERASE64(mem,size) do { volatile unsigned __int32 *burnm = (volatile unsigned __int32 *)(mem); int burnc = size >> 2; while (burnc--) *burnm++ = 0; } while (0)
|
||||
#endif
|
||||
|
||||
#ifdef TC_WINDOWS_BOOT
|
||||
# ifndef max
|
||||
# define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
# endif
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C"
|
||||
# endif
|
||||
void EraseMemory (void *memory, int size);
|
||||
|
||||
# undef burn
|
||||
# define burn EraseMemory
|
||||
#endif
|
||||
|
||||
#ifdef MAX_PATH
|
||||
#define TC_MAX_PATH MAX_PATH
|
||||
#else
|
||||
#define TC_MAX_PATH 260 /* Includes the null terminator */
|
||||
#endif
|
||||
|
||||
#define TC_STR_RELEASED_BY L"Released by IDRIX on " TC_STR_RELEASE_DATE
|
||||
|
||||
#define MAX_URL_LENGTH 2084 /* Internet Explorer limit. Includes the terminating null character. */
|
||||
|
||||
#define TC_HOMEPAGE "http://www.idrix.fr/"
|
||||
#define TC_APPLINK "https://veracrypt.codeplex.com"
|
||||
#define TC_APPLINK_SECURE "https://veracrypt.codeplex.com"
|
||||
|
||||
enum
|
||||
{
|
||||
/* WARNING: ADD ANY NEW CODES AT THE END (DO NOT INSERT THEM BETWEEN EXISTING). DO *NOT* DELETE ANY
|
||||
EXISTING CODES! Changing these values or their meanings may cause incompatibility with other versions
|
||||
(for example, if a new version of the TrueCrypt installer receives an error code from an installed
|
||||
driver whose version is lower, it will report and interpret the error incorrectly). */
|
||||
|
||||
ERR_SUCCESS = 0,
|
||||
ERR_OS_ERROR = 1,
|
||||
ERR_OUTOFMEMORY = 2,
|
||||
ERR_PASSWORD_WRONG = 3,
|
||||
ERR_VOL_FORMAT_BAD = 4,
|
||||
ERR_DRIVE_NOT_FOUND = 5,
|
||||
ERR_FILES_OPEN = 6,
|
||||
ERR_VOL_SIZE_WRONG = 7,
|
||||
ERR_COMPRESSION_NOT_SUPPORTED = 8,
|
||||
ERR_PASSWORD_CHANGE_VOL_TYPE = 9,
|
||||
ERR_PASSWORD_CHANGE_VOL_VERSION = 10,
|
||||
ERR_VOL_SEEKING = 11,
|
||||
ERR_VOL_WRITING = 12,
|
||||
ERR_FILES_OPEN_LOCK = 13,
|
||||
ERR_VOL_READING = 14,
|
||||
ERR_DRIVER_VERSION = 15,
|
||||
ERR_NEW_VERSION_REQUIRED = 16,
|
||||
ERR_CIPHER_INIT_FAILURE = 17,
|
||||
ERR_CIPHER_INIT_WEAK_KEY = 18,
|
||||
ERR_SELF_TESTS_FAILED = 19,
|
||||
ERR_SECTOR_SIZE_INCOMPATIBLE = 20,
|
||||
ERR_VOL_ALREADY_MOUNTED = 21,
|
||||
ERR_NO_FREE_DRIVES = 22,
|
||||
ERR_FILE_OPEN_FAILED = 23,
|
||||
ERR_VOL_MOUNT_FAILED = 24,
|
||||
DEPRECATED_ERR_INVALID_DEVICE = 25,
|
||||
ERR_ACCESS_DENIED = 26,
|
||||
ERR_MODE_INIT_FAILED = 27,
|
||||
ERR_DONT_REPORT = 28,
|
||||
ERR_ENCRYPTION_NOT_COMPLETED = 29,
|
||||
ERR_PARAMETER_INCORRECT = 30,
|
||||
ERR_SYS_HIDVOL_HEAD_REENC_MODE_WRONG = 31,
|
||||
ERR_NONSYS_INPLACE_ENC_INCOMPLETE = 32,
|
||||
ERR_USER_ABORT = 33,
|
||||
ERR_UNSUPPORTED_TRUECRYPT_FORMAT = 34,
|
||||
ERR_RAND_INIT_FAILED = 35,
|
||||
ERR_CAPI_INIT_FAILED = 36
|
||||
};
|
||||
|
||||
#endif // #ifndef TCDEFS_H
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#ifndef TCDEFS_H
|
||||
#define TCDEFS_H
|
||||
|
||||
#define TC_APP_NAME "VeraCrypt"
|
||||
|
||||
// Version displayed to user
|
||||
#define VERSION_STRING "1.17"
|
||||
|
||||
// Version number to compare against driver
|
||||
#define VERSION_NUM 0x0117
|
||||
|
||||
// Release date
|
||||
#define TC_STR_RELEASE_DATE L"February 13th, 2016"
|
||||
#define TC_RELEASE_DATE_YEAR 2016
|
||||
#define TC_RELEASE_DATE_MONTH 2
|
||||
|
||||
#define BYTES_PER_KB 1024LL
|
||||
#define BYTES_PER_MB 1048576LL
|
||||
#define BYTES_PER_GB 1073741824LL
|
||||
#define BYTES_PER_TB 1099511627776LL
|
||||
#define BYTES_PER_PB 1125899906842624LL
|
||||
|
||||
/* GUI/driver errors */
|
||||
|
||||
#define WIDE(x) (LPWSTR)L##x
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
typedef __int8 int8;
|
||||
typedef __int16 int16;
|
||||
typedef __int32 int32;
|
||||
typedef unsigned __int8 byte;
|
||||
typedef unsigned __int16 uint16;
|
||||
typedef unsigned __int32 uint32;
|
||||
|
||||
#ifdef TC_NO_COMPILER_INT64
|
||||
typedef unsigned __int32 TC_LARGEST_COMPILER_UINT;
|
||||
#else
|
||||
typedef unsigned __int64 TC_LARGEST_COMPILER_UINT;
|
||||
typedef __int64 int64;
|
||||
typedef unsigned __int64 uint64;
|
||||
#define LL(x) x##ui64
|
||||
#endif
|
||||
|
||||
#else // !_MSC_VER
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
|
||||
typedef int8_t int8;
|
||||
typedef int16_t int16;
|
||||
typedef int32_t int32;
|
||||
typedef int64_t int64;
|
||||
typedef uint8_t byte;
|
||||
typedef uint16_t uint16;
|
||||
typedef uint32_t uint32;
|
||||
typedef uint64_t uint64;
|
||||
|
||||
#define LL(x) x##ULL
|
||||
|
||||
#if UCHAR_MAX != 0xffU
|
||||
#error UCHAR_MAX != 0xff
|
||||
#endif
|
||||
#define __int8 char
|
||||
|
||||
#if USHRT_MAX != 0xffffU
|
||||
#error USHRT_MAX != 0xffff
|
||||
#endif
|
||||
#define __int16 short
|
||||
|
||||
#if UINT_MAX != 0xffffffffU
|
||||
#error UINT_MAX != 0xffffffff
|
||||
#endif
|
||||
#define __int32 int
|
||||
|
||||
typedef uint64 TC_LARGEST_COMPILER_UINT;
|
||||
|
||||
#define BOOL int
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#endif // !_MSC_VER
|
||||
|
||||
#define TC_INT_TYPES_DEFINED
|
||||
|
||||
// Integer types required by Cryptolib
|
||||
typedef unsigned __int8 uint_8t;
|
||||
typedef unsigned __int16 uint_16t;
|
||||
typedef unsigned __int32 uint_32t;
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
typedef uint64 uint_64t;
|
||||
#endif
|
||||
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
unsigned __int32 LowPart;
|
||||
unsigned __int32 HighPart;
|
||||
};
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
uint64 Value;
|
||||
#endif
|
||||
|
||||
} UINT64_STRUCT;
|
||||
|
||||
#ifndef __has_builtin // Optional of course
|
||||
#define __has_builtin(x) 0 // Compatibility with non-clang compilers
|
||||
#endif
|
||||
|
||||
#ifdef TC_WINDOWS_BOOT
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C"
|
||||
# endif
|
||||
void ThrowFatalException (int line);
|
||||
|
||||
# define TC_THROW_FATAL_EXCEPTION ThrowFatalException (__LINE__)
|
||||
#elif defined (TC_WINDOWS_DRIVER)
|
||||
# define TC_THROW_FATAL_EXCEPTION KeBugCheckEx (SECURITY_SYSTEM, __LINE__, 0, 0, 'VC')
|
||||
#elif (defined(__clang__) && __has_builtin(__builtin_trap)) \
|
||||
|| (defined(__GNUC__ ) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))) \
|
||||
|| (__has_builtin(__builtin_trap))
|
||||
# define TC_THROW_FATAL_EXCEPTION __builtin_trap()
|
||||
#else
|
||||
# define TC_THROW_FATAL_EXCEPTION *(char *) 0 = 0
|
||||
#endif
|
||||
|
||||
#ifdef __COVERITY__
|
||||
#undef TC_THROW_FATAL_EXCEPTION
|
||||
#define TC_THROW_FATAL_EXCEPTION __coverity_panic__()
|
||||
#endif
|
||||
|
||||
#ifdef TC_WINDOWS_DRIVER
|
||||
|
||||
#include <ntifs.h>
|
||||
#include <ntddk.h> /* Standard header file for nt drivers */
|
||||
#include <ntdddisk.h> /* Standard I/O control codes */
|
||||
|
||||
#define TCalloc(size) ((void *) ExAllocatePoolWithTag( NonPagedPool, size, 'MMCV' ))
|
||||
#define TCfree(memblock) ExFreePoolWithTag( memblock, 'MMCV' )
|
||||
|
||||
#define DEVICE_DRIVER
|
||||
|
||||
#ifndef BOOL
|
||||
typedef int BOOL;
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE !TRUE
|
||||
#endif
|
||||
|
||||
#else /* !TC_WINDOWS_DRIVER */
|
||||
|
||||
#define TCalloc malloc
|
||||
#define TCfree free
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#ifndef TC_LOCAL_WIN32_WINNT_OVERRIDE
|
||||
# undef _WIN32_WINNT
|
||||
# define _WIN32_WINNT 0x0501 /* Does not apply to the driver */
|
||||
#endif
|
||||
|
||||
#include <windows.h> /* Windows header */
|
||||
#include <commctrl.h> /* The common controls */
|
||||
#include <process.h> /* Process control */
|
||||
#include <winioctl.h>
|
||||
#include <stdio.h> /* For sprintf */
|
||||
#include <tchar.h>
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#endif /* !TC_WINDOWS_DRIVER */
|
||||
|
||||
#ifndef TC_TO_STRING
|
||||
# define TC_TO_STRING2(n) #n
|
||||
# define TC_TO_STRING(n) TC_TO_STRING2(n)
|
||||
#endif
|
||||
|
||||
#ifdef DEVICE_DRIVER
|
||||
# if defined (DEBUG) || 0
|
||||
# if 1 // DbgPrintEx is not available on Windows 2000
|
||||
# define Dump DbgPrint
|
||||
# else
|
||||
# define Dump(...) DbgPrintEx (DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, __VA_ARGS__)
|
||||
# endif
|
||||
# define DumpMem(...) DumpMemory (__VA_ARGS__)
|
||||
# else
|
||||
# define Dump(...)
|
||||
# define DumpMem(...)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined (trace_msg) && !defined (TC_WINDOWS_BOOT)
|
||||
# ifdef DEBUG
|
||||
# ifdef DEVICE_DRIVER
|
||||
# define trace_msg Dump
|
||||
# elif defined (_WIN32)
|
||||
# define trace_msg(...) do { char msg[2048]; StringCbPrintfA (msg, sizeof (msg), __VA_ARGS__); OutputDebugString (msg); } while (0)
|
||||
# endif
|
||||
# define trace_point trace_msg (__FUNCTION__ ":" TC_TO_STRING(__LINE__) "\n")
|
||||
# else
|
||||
# define trace_msg(...)
|
||||
# define trace_point
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef DEVICE_DRIVER
|
||||
# define TC_EVENT KEVENT
|
||||
# define TC_WAIT_EVENT(EVENT) KeWaitForSingleObject (&EVENT, Executive, KernelMode, FALSE, NULL)
|
||||
#elif defined (_WIN32)
|
||||
# define TC_EVENT HANDLE
|
||||
# define TC_WAIT_EVENT(EVENT) WaitForSingleObject (EVENT, INFINITE)
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define burn(mem,size) do { volatile char *burnm = (volatile char *)(mem); size_t burnc = size; RtlSecureZeroMemory (mem, size); while (burnc--) *burnm++ = 0; } while (0)
|
||||
#else
|
||||
#define burn(mem,size) do { volatile char *burnm = (volatile char *)(mem); int burnc = size; while (burnc--) *burnm++ = 0; } while (0)
|
||||
#endif
|
||||
|
||||
// The size of the memory area to wipe is in bytes amd it must be a multiple of 8.
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
# define FAST_ERASE64(mem,size) do { volatile uint64 *burnm = (volatile uint64 *)(mem); int burnc = size >> 3; while (burnc--) *burnm++ = 0; } while (0)
|
||||
#else
|
||||
# define FAST_ERASE64(mem,size) do { volatile unsigned __int32 *burnm = (volatile unsigned __int32 *)(mem); int burnc = size >> 2; while (burnc--) *burnm++ = 0; } while (0)
|
||||
#endif
|
||||
|
||||
#ifdef TC_WINDOWS_BOOT
|
||||
# ifndef max
|
||||
# define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
# endif
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C"
|
||||
# endif
|
||||
void EraseMemory (void *memory, int size);
|
||||
|
||||
# undef burn
|
||||
# define burn EraseMemory
|
||||
#endif
|
||||
|
||||
#ifdef MAX_PATH
|
||||
#define TC_MAX_PATH MAX_PATH
|
||||
#else
|
||||
#define TC_MAX_PATH 260 /* Includes the null terminator */
|
||||
#endif
|
||||
|
||||
#define TC_STR_RELEASED_BY L"Released by IDRIX on " TC_STR_RELEASE_DATE
|
||||
|
||||
#define MAX_URL_LENGTH 2084 /* Internet Explorer limit. Includes the terminating null character. */
|
||||
|
||||
#define TC_HOMEPAGE "http://www.idrix.fr/"
|
||||
#define TC_APPLINK "https://veracrypt.codeplex.com"
|
||||
#define TC_APPLINK_SECURE "https://veracrypt.codeplex.com"
|
||||
|
||||
enum
|
||||
{
|
||||
/* WARNING: ADD ANY NEW CODES AT THE END (DO NOT INSERT THEM BETWEEN EXISTING). DO *NOT* DELETE ANY
|
||||
EXISTING CODES! Changing these values or their meanings may cause incompatibility with other versions
|
||||
(for example, if a new version of the TrueCrypt installer receives an error code from an installed
|
||||
driver whose version is lower, it will report and interpret the error incorrectly). */
|
||||
|
||||
ERR_SUCCESS = 0,
|
||||
ERR_OS_ERROR = 1,
|
||||
ERR_OUTOFMEMORY = 2,
|
||||
ERR_PASSWORD_WRONG = 3,
|
||||
ERR_VOL_FORMAT_BAD = 4,
|
||||
ERR_DRIVE_NOT_FOUND = 5,
|
||||
ERR_FILES_OPEN = 6,
|
||||
ERR_VOL_SIZE_WRONG = 7,
|
||||
ERR_COMPRESSION_NOT_SUPPORTED = 8,
|
||||
ERR_PASSWORD_CHANGE_VOL_TYPE = 9,
|
||||
ERR_PASSWORD_CHANGE_VOL_VERSION = 10,
|
||||
ERR_VOL_SEEKING = 11,
|
||||
ERR_VOL_WRITING = 12,
|
||||
ERR_FILES_OPEN_LOCK = 13,
|
||||
ERR_VOL_READING = 14,
|
||||
ERR_DRIVER_VERSION = 15,
|
||||
ERR_NEW_VERSION_REQUIRED = 16,
|
||||
ERR_CIPHER_INIT_FAILURE = 17,
|
||||
ERR_CIPHER_INIT_WEAK_KEY = 18,
|
||||
ERR_SELF_TESTS_FAILED = 19,
|
||||
ERR_SECTOR_SIZE_INCOMPATIBLE = 20,
|
||||
ERR_VOL_ALREADY_MOUNTED = 21,
|
||||
ERR_NO_FREE_DRIVES = 22,
|
||||
ERR_FILE_OPEN_FAILED = 23,
|
||||
ERR_VOL_MOUNT_FAILED = 24,
|
||||
DEPRECATED_ERR_INVALID_DEVICE = 25,
|
||||
ERR_ACCESS_DENIED = 26,
|
||||
ERR_MODE_INIT_FAILED = 27,
|
||||
ERR_DONT_REPORT = 28,
|
||||
ERR_ENCRYPTION_NOT_COMPLETED = 29,
|
||||
ERR_PARAMETER_INCORRECT = 30,
|
||||
ERR_SYS_HIDVOL_HEAD_REENC_MODE_WRONG = 31,
|
||||
ERR_NONSYS_INPLACE_ENC_INCOMPLETE = 32,
|
||||
ERR_USER_ABORT = 33,
|
||||
ERR_UNSUPPORTED_TRUECRYPT_FORMAT = 34,
|
||||
ERR_RAND_INIT_FAILED = 35,
|
||||
ERR_CAPI_INIT_FAILED = 36
|
||||
};
|
||||
|
||||
#endif // #ifndef TCDEFS_H
|
||||
|
||||
2310
src/Common/Tests.c
2310
src/Common/Tests.c
File diff suppressed because it is too large
Load Diff
@@ -1,31 +1,31 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern unsigned char ks_tmp[MAX_EXPANDED_KEY];
|
||||
|
||||
void CipherInit2(int cipher, void* key, void* ks, int key_len);
|
||||
BOOL test_hmac_sha512 (void);
|
||||
BOOL test_hmac_ripemd160 (void);
|
||||
BOOL test_hmac_whirlpool (void);
|
||||
BOOL test_pkcs5 (void);
|
||||
BOOL TestSectorBufEncryption ();
|
||||
BOOL TestLegacySectorBufEncryption ();
|
||||
BOOL AutoTestAlgorithms (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern unsigned char ks_tmp[MAX_EXPANDED_KEY];
|
||||
|
||||
void CipherInit2(int cipher, void* key, void* ks, int key_len);
|
||||
BOOL test_hmac_sha512 (void);
|
||||
BOOL test_hmac_ripemd160 (void);
|
||||
BOOL test_hmac_whirlpool (void);
|
||||
BOOL test_pkcs5 (void);
|
||||
BOOL TestSectorBufEncryption ();
|
||||
BOOL TestLegacySectorBufEncryption ();
|
||||
BOOL AutoTestAlgorithms (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
2540
src/Common/Volumes.c
2540
src/Common/Volumes.c
File diff suppressed because it is too large
Load Diff
@@ -1,155 +1,155 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#ifndef TC_HEADER_Common_Volumes
|
||||
#define TC_HEADER_Common_Volumes
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Volume header version
|
||||
#define VOLUME_HEADER_VERSION 0x0005
|
||||
|
||||
// Version number written to volume header during format;
|
||||
// specifies the minimum program version required to mount the volume
|
||||
#define TC_VOLUME_MIN_REQUIRED_PROGRAM_VERSION 0x010b
|
||||
|
||||
// Version number written (encrypted) to the key data area of an encrypted system partition/drive;
|
||||
// specifies the minimum program version required to decrypt the system partition/drive
|
||||
#define TC_SYSENC_KEYSCOPE_MIN_REQ_PROG_VERSION 0x010b
|
||||
|
||||
// Current volume format version (created by TrueCrypt 6.0+)
|
||||
#define TC_VOLUME_FORMAT_VERSION 2
|
||||
|
||||
// Version number of volume format created by TrueCrypt 1.0-5.1a
|
||||
#define TC_VOLUME_FORMAT_VERSION_PRE_6_0 1
|
||||
|
||||
// Volume header sizes
|
||||
#define TC_VOLUME_HEADER_SIZE (64 * 1024L)
|
||||
#define TC_VOLUME_HEADER_EFFECTIVE_SIZE 512
|
||||
#define TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE 512
|
||||
#define TC_VOLUME_HEADER_SIZE_LEGACY 512
|
||||
|
||||
#define TC_VOLUME_HEADER_GROUP_SIZE (2 * TC_VOLUME_HEADER_SIZE)
|
||||
#define TC_TOTAL_VOLUME_HEADERS_SIZE (4 * TC_VOLUME_HEADER_SIZE)
|
||||
|
||||
// Volume offsets
|
||||
#define TC_VOLUME_HEADER_OFFSET 0
|
||||
#define TC_HIDDEN_VOLUME_HEADER_OFFSET TC_VOLUME_HEADER_SIZE
|
||||
|
||||
// Sector sizes
|
||||
#define TC_MIN_VOLUME_SECTOR_SIZE 512
|
||||
#define TC_MAX_VOLUME_SECTOR_SIZE 4096
|
||||
#define TC_SECTOR_SIZE_FILE_HOSTED_VOLUME 512
|
||||
#define TC_SECTOR_SIZE_LEGACY 512
|
||||
|
||||
// Sector size which can be safely assumed to be supported by all BIOSes
|
||||
#define TC_SECTOR_SIZE_BIOS 512
|
||||
|
||||
#define TC_VOLUME_SMALL_SIZE_THRESHOLD (2 * BYTES_PER_MB) // Volume sizes below this threshold are considered small
|
||||
|
||||
#define TC_HIDDEN_VOLUME_HOST_FS_RESERVED_END_AREA_SIZE TC_MAX_VOLUME_SECTOR_SIZE // FAT file system fills the last sector with zeroes (marked as free; observed when quick format was performed using the OS format tool).
|
||||
#define TC_HIDDEN_VOLUME_HOST_FS_RESERVED_END_AREA_SIZE_HIGH TC_VOLUME_HEADER_GROUP_SIZE // Reserved area size used for hidden volumes larger than TC_VOLUME_SMALL_SIZE_THRESHOLD
|
||||
|
||||
#define TC_VOLUME_DATA_OFFSET TC_VOLUME_HEADER_GROUP_SIZE
|
||||
|
||||
// The offset, in bytes, of the legacy hidden volume header position from the end of the file (a positive value).
|
||||
#define TC_HIDDEN_VOLUME_HEADER_OFFSET_LEGACY (TC_VOLUME_HEADER_SIZE_LEGACY + TC_SECTOR_SIZE_LEGACY * 2)
|
||||
|
||||
#define TC_MAX_128BIT_BLOCK_VOLUME_SIZE BYTES_PER_PB // Security bound (128-bit block XTS mode)
|
||||
|
||||
// Filesystem size limits
|
||||
#define TC_MIN_FAT_FS_SIZE (9 * TC_MAX_VOLUME_SECTOR_SIZE)
|
||||
#define TC_MAX_FAT_SECTOR_COUNT 0x100000000ULL
|
||||
#define TC_MIN_NTFS_FS_SIZE (884 * TC_MAX_VOLUME_SECTOR_SIZE)
|
||||
#define TC_MAX_NTFS_FS_SIZE (128LL * BYTES_PER_TB) // NTFS volume can theoretically be up to 16 exabytes, but Windows XP and 2003 limit the size to that addressable with 32-bit clusters, i.e. max size is 128 TB (if 64-KB clusters are used).
|
||||
#define TC_MAX_FAT_CLUSTER_SIZE (256 * BYTES_PER_KB) // Windows XP/Vista may crash when writing to a filesystem using clusters larger than 256 KB
|
||||
#define TC_MIN_EXFAT_FS_SIZE (42 * TC_MAX_VOLUME_SECTOR_SIZE)
|
||||
#define TC_MAX_EXFAT_FS_SIZE (128LL * BYTES_PER_PB)
|
||||
|
||||
// Volume size limits
|
||||
#define TC_MIN_VOLUME_SIZE (TC_TOTAL_VOLUME_HEADERS_SIZE + TC_MIN_FAT_FS_SIZE)
|
||||
#define TC_MIN_VOLUME_SIZE_LEGACY (37 * TC_SECTOR_SIZE_LEGACY)
|
||||
#define TC_MAX_VOLUME_SIZE_GENERAL 0x7fffFFFFffffFFFFLL // Signed 64-bit integer file offset values
|
||||
#define TC_MAX_VOLUME_SIZE TC_MAX_128BIT_BLOCK_VOLUME_SIZE
|
||||
|
||||
#define TC_MIN_HIDDEN_VOLUME_SIZE (TC_MIN_FAT_FS_SIZE + TC_HIDDEN_VOLUME_HOST_FS_RESERVED_END_AREA_SIZE)
|
||||
|
||||
#define TC_MIN_HIDDEN_VOLUME_HOST_SIZE (TC_MIN_VOLUME_SIZE + TC_MIN_HIDDEN_VOLUME_SIZE + 2 * TC_MAX_VOLUME_SECTOR_SIZE)
|
||||
#define TC_MAX_HIDDEN_VOLUME_HOST_SIZE (TC_MAX_NTFS_FS_SIZE - TC_TOTAL_VOLUME_HEADERS_SIZE)
|
||||
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
# if TC_MAX_VOLUME_SIZE > TC_MAX_VOLUME_SIZE_GENERAL
|
||||
# error TC_MAX_VOLUME_SIZE > TC_MAX_VOLUME_SIZE_GENERAL
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define HEADER_ENCRYPTED_DATA_SIZE (TC_VOLUME_HEADER_EFFECTIVE_SIZE - HEADER_ENCRYPTED_DATA_OFFSET)
|
||||
|
||||
// Volume header field offsets
|
||||
#define HEADER_SALT_OFFSET 0
|
||||
#define HEADER_ENCRYPTED_DATA_OFFSET PKCS5_SALT_SIZE
|
||||
#define HEADER_MASTER_KEYDATA_OFFSET 256
|
||||
|
||||
#define TC_HEADER_OFFSET_MAGIC 64
|
||||
#define TC_HEADER_OFFSET_VERSION 68
|
||||
#define TC_HEADER_OFFSET_REQUIRED_VERSION 70
|
||||
#define TC_HEADER_OFFSET_KEY_AREA_CRC 72
|
||||
#define TC_HEADER_OFFSET_VOLUME_CREATION_TIME 76
|
||||
#define TC_HEADER_OFFSET_MODIFICATION_TIME 84
|
||||
#define TC_HEADER_OFFSET_HIDDEN_VOLUME_SIZE 92
|
||||
#define TC_HEADER_OFFSET_VOLUME_SIZE 100
|
||||
#define TC_HEADER_OFFSET_ENCRYPTED_AREA_START 108
|
||||
#define TC_HEADER_OFFSET_ENCRYPTED_AREA_LENGTH 116
|
||||
#define TC_HEADER_OFFSET_FLAGS 124
|
||||
#define TC_HEADER_OFFSET_SECTOR_SIZE 128
|
||||
#define TC_HEADER_OFFSET_HEADER_CRC 252
|
||||
|
||||
// Volume header flags
|
||||
#define TC_HEADER_FLAG_ENCRYPTED_SYSTEM 0x1
|
||||
#define TC_HEADER_FLAG_NONSYS_INPLACE_ENC 0x2 // The volume has been created (or is being encrypted/decrypted) using non-system in-place encryption
|
||||
|
||||
|
||||
#ifndef TC_HEADER_Volume_VolumeHeader
|
||||
|
||||
#include "Password.h"
|
||||
|
||||
extern BOOL ReadVolumeHeaderRecoveryMode;
|
||||
|
||||
uint16 GetHeaderField16 (byte *header, int offset);
|
||||
uint32 GetHeaderField32 (byte *header, int offset);
|
||||
UINT64_STRUCT GetHeaderField64 (byte *header, int offset);
|
||||
#ifdef TC_WINDOWS_BOOT
|
||||
int ReadVolumeHeader (BOOL bBoot, char *encryptedHeader, Password *password, int pim, PCRYPTO_INFO *retInfo, CRYPTO_INFO *retHeaderCryptoInfo);
|
||||
#else
|
||||
int ReadVolumeHeader (BOOL bBoot, char *encryptedHeader, Password *password, int pkcs5_prf, int pim, BOOL truecryptMode, PCRYPTO_INFO *retInfo, CRYPTO_INFO *retHeaderCryptoInfo);
|
||||
#ifdef _WIN32
|
||||
void ComputeBootloaderFingerprint (byte *bootLoaderBuf, unsigned int bootLoaderSize, byte* fingerprint);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined (DEVICE_DRIVER) && !defined (TC_WINDOWS_BOOT)
|
||||
int CreateVolumeHeaderInMemory (HWND hwndDlg, BOOL bBoot, char *encryptedHeader, int ea, int mode, Password *password, int pkcs5_prf, int pim, char *masterKeydata, PCRYPTO_INFO *retInfo, unsigned __int64 volumeSize, unsigned __int64 hiddenVolumeSize, unsigned __int64 encryptedAreaStart, unsigned __int64 encryptedAreaLength, uint16 requiredProgramVersion, uint32 headerFlags, uint32 sectorSize, BOOL bWipeMode);
|
||||
BOOL ReadEffectiveVolumeHeader (BOOL device, HANDLE fileHandle, byte *header, DWORD *bytesRead);
|
||||
BOOL WriteEffectiveVolumeHeader (BOOL device, HANDLE fileHandle, byte *header);
|
||||
int WriteRandomDataToReservedHeaderAreas (HWND hwndDlg, HANDLE dev, CRYPTO_INFO *cryptoInfo, uint64 dataAreaSize, BOOL bPrimaryOnly, BOOL bBackupOnly);
|
||||
#endif
|
||||
|
||||
#endif // !TC_HEADER_Volume_VolumeHeader
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_Common_Volumes
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages. */
|
||||
|
||||
#ifndef TC_HEADER_Common_Volumes
|
||||
#define TC_HEADER_Common_Volumes
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Volume header version
|
||||
#define VOLUME_HEADER_VERSION 0x0005
|
||||
|
||||
// Version number written to volume header during format;
|
||||
// specifies the minimum program version required to mount the volume
|
||||
#define TC_VOLUME_MIN_REQUIRED_PROGRAM_VERSION 0x010b
|
||||
|
||||
// Version number written (encrypted) to the key data area of an encrypted system partition/drive;
|
||||
// specifies the minimum program version required to decrypt the system partition/drive
|
||||
#define TC_SYSENC_KEYSCOPE_MIN_REQ_PROG_VERSION 0x010b
|
||||
|
||||
// Current volume format version (created by TrueCrypt 6.0+)
|
||||
#define TC_VOLUME_FORMAT_VERSION 2
|
||||
|
||||
// Version number of volume format created by TrueCrypt 1.0-5.1a
|
||||
#define TC_VOLUME_FORMAT_VERSION_PRE_6_0 1
|
||||
|
||||
// Volume header sizes
|
||||
#define TC_VOLUME_HEADER_SIZE (64 * 1024L)
|
||||
#define TC_VOLUME_HEADER_EFFECTIVE_SIZE 512
|
||||
#define TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE 512
|
||||
#define TC_VOLUME_HEADER_SIZE_LEGACY 512
|
||||
|
||||
#define TC_VOLUME_HEADER_GROUP_SIZE (2 * TC_VOLUME_HEADER_SIZE)
|
||||
#define TC_TOTAL_VOLUME_HEADERS_SIZE (4 * TC_VOLUME_HEADER_SIZE)
|
||||
|
||||
// Volume offsets
|
||||
#define TC_VOLUME_HEADER_OFFSET 0
|
||||
#define TC_HIDDEN_VOLUME_HEADER_OFFSET TC_VOLUME_HEADER_SIZE
|
||||
|
||||
// Sector sizes
|
||||
#define TC_MIN_VOLUME_SECTOR_SIZE 512
|
||||
#define TC_MAX_VOLUME_SECTOR_SIZE 4096
|
||||
#define TC_SECTOR_SIZE_FILE_HOSTED_VOLUME 512
|
||||
#define TC_SECTOR_SIZE_LEGACY 512
|
||||
|
||||
// Sector size which can be safely assumed to be supported by all BIOSes
|
||||
#define TC_SECTOR_SIZE_BIOS 512
|
||||
|
||||
#define TC_VOLUME_SMALL_SIZE_THRESHOLD (2 * BYTES_PER_MB) // Volume sizes below this threshold are considered small
|
||||
|
||||
#define TC_HIDDEN_VOLUME_HOST_FS_RESERVED_END_AREA_SIZE TC_MAX_VOLUME_SECTOR_SIZE // FAT file system fills the last sector with zeroes (marked as free; observed when quick format was performed using the OS format tool).
|
||||
#define TC_HIDDEN_VOLUME_HOST_FS_RESERVED_END_AREA_SIZE_HIGH TC_VOLUME_HEADER_GROUP_SIZE // Reserved area size used for hidden volumes larger than TC_VOLUME_SMALL_SIZE_THRESHOLD
|
||||
|
||||
#define TC_VOLUME_DATA_OFFSET TC_VOLUME_HEADER_GROUP_SIZE
|
||||
|
||||
// The offset, in bytes, of the legacy hidden volume header position from the end of the file (a positive value).
|
||||
#define TC_HIDDEN_VOLUME_HEADER_OFFSET_LEGACY (TC_VOLUME_HEADER_SIZE_LEGACY + TC_SECTOR_SIZE_LEGACY * 2)
|
||||
|
||||
#define TC_MAX_128BIT_BLOCK_VOLUME_SIZE BYTES_PER_PB // Security bound (128-bit block XTS mode)
|
||||
|
||||
// Filesystem size limits
|
||||
#define TC_MIN_FAT_FS_SIZE (9 * TC_MAX_VOLUME_SECTOR_SIZE)
|
||||
#define TC_MAX_FAT_SECTOR_COUNT 0x100000000ULL
|
||||
#define TC_MIN_NTFS_FS_SIZE (884 * TC_MAX_VOLUME_SECTOR_SIZE)
|
||||
#define TC_MAX_NTFS_FS_SIZE (128LL * BYTES_PER_TB) // NTFS volume can theoretically be up to 16 exabytes, but Windows XP and 2003 limit the size to that addressable with 32-bit clusters, i.e. max size is 128 TB (if 64-KB clusters are used).
|
||||
#define TC_MAX_FAT_CLUSTER_SIZE (256 * BYTES_PER_KB) // Windows XP/Vista may crash when writing to a filesystem using clusters larger than 256 KB
|
||||
#define TC_MIN_EXFAT_FS_SIZE (42 * TC_MAX_VOLUME_SECTOR_SIZE)
|
||||
#define TC_MAX_EXFAT_FS_SIZE (128LL * BYTES_PER_PB)
|
||||
|
||||
// Volume size limits
|
||||
#define TC_MIN_VOLUME_SIZE (TC_TOTAL_VOLUME_HEADERS_SIZE + TC_MIN_FAT_FS_SIZE)
|
||||
#define TC_MIN_VOLUME_SIZE_LEGACY (37 * TC_SECTOR_SIZE_LEGACY)
|
||||
#define TC_MAX_VOLUME_SIZE_GENERAL 0x7fffFFFFffffFFFFLL // Signed 64-bit integer file offset values
|
||||
#define TC_MAX_VOLUME_SIZE TC_MAX_128BIT_BLOCK_VOLUME_SIZE
|
||||
|
||||
#define TC_MIN_HIDDEN_VOLUME_SIZE (TC_MIN_FAT_FS_SIZE + TC_HIDDEN_VOLUME_HOST_FS_RESERVED_END_AREA_SIZE)
|
||||
|
||||
#define TC_MIN_HIDDEN_VOLUME_HOST_SIZE (TC_MIN_VOLUME_SIZE + TC_MIN_HIDDEN_VOLUME_SIZE + 2 * TC_MAX_VOLUME_SECTOR_SIZE)
|
||||
#define TC_MAX_HIDDEN_VOLUME_HOST_SIZE (TC_MAX_NTFS_FS_SIZE - TC_TOTAL_VOLUME_HEADERS_SIZE)
|
||||
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
# if TC_MAX_VOLUME_SIZE > TC_MAX_VOLUME_SIZE_GENERAL
|
||||
# error TC_MAX_VOLUME_SIZE > TC_MAX_VOLUME_SIZE_GENERAL
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define HEADER_ENCRYPTED_DATA_SIZE (TC_VOLUME_HEADER_EFFECTIVE_SIZE - HEADER_ENCRYPTED_DATA_OFFSET)
|
||||
|
||||
// Volume header field offsets
|
||||
#define HEADER_SALT_OFFSET 0
|
||||
#define HEADER_ENCRYPTED_DATA_OFFSET PKCS5_SALT_SIZE
|
||||
#define HEADER_MASTER_KEYDATA_OFFSET 256
|
||||
|
||||
#define TC_HEADER_OFFSET_MAGIC 64
|
||||
#define TC_HEADER_OFFSET_VERSION 68
|
||||
#define TC_HEADER_OFFSET_REQUIRED_VERSION 70
|
||||
#define TC_HEADER_OFFSET_KEY_AREA_CRC 72
|
||||
#define TC_HEADER_OFFSET_VOLUME_CREATION_TIME 76
|
||||
#define TC_HEADER_OFFSET_MODIFICATION_TIME 84
|
||||
#define TC_HEADER_OFFSET_HIDDEN_VOLUME_SIZE 92
|
||||
#define TC_HEADER_OFFSET_VOLUME_SIZE 100
|
||||
#define TC_HEADER_OFFSET_ENCRYPTED_AREA_START 108
|
||||
#define TC_HEADER_OFFSET_ENCRYPTED_AREA_LENGTH 116
|
||||
#define TC_HEADER_OFFSET_FLAGS 124
|
||||
#define TC_HEADER_OFFSET_SECTOR_SIZE 128
|
||||
#define TC_HEADER_OFFSET_HEADER_CRC 252
|
||||
|
||||
// Volume header flags
|
||||
#define TC_HEADER_FLAG_ENCRYPTED_SYSTEM 0x1
|
||||
#define TC_HEADER_FLAG_NONSYS_INPLACE_ENC 0x2 // The volume has been created (or is being encrypted/decrypted) using non-system in-place encryption
|
||||
|
||||
|
||||
#ifndef TC_HEADER_Volume_VolumeHeader
|
||||
|
||||
#include "Password.h"
|
||||
|
||||
extern BOOL ReadVolumeHeaderRecoveryMode;
|
||||
|
||||
uint16 GetHeaderField16 (byte *header, int offset);
|
||||
uint32 GetHeaderField32 (byte *header, int offset);
|
||||
UINT64_STRUCT GetHeaderField64 (byte *header, int offset);
|
||||
#ifdef TC_WINDOWS_BOOT
|
||||
int ReadVolumeHeader (BOOL bBoot, char *encryptedHeader, Password *password, int pim, PCRYPTO_INFO *retInfo, CRYPTO_INFO *retHeaderCryptoInfo);
|
||||
#else
|
||||
int ReadVolumeHeader (BOOL bBoot, char *encryptedHeader, Password *password, int pkcs5_prf, int pim, BOOL truecryptMode, PCRYPTO_INFO *retInfo, CRYPTO_INFO *retHeaderCryptoInfo);
|
||||
#ifdef _WIN32
|
||||
void ComputeBootloaderFingerprint (byte *bootLoaderBuf, unsigned int bootLoaderSize, byte* fingerprint);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined (DEVICE_DRIVER) && !defined (TC_WINDOWS_BOOT)
|
||||
int CreateVolumeHeaderInMemory (HWND hwndDlg, BOOL bBoot, char *encryptedHeader, int ea, int mode, Password *password, int pkcs5_prf, int pim, char *masterKeydata, PCRYPTO_INFO *retInfo, unsigned __int64 volumeSize, unsigned __int64 hiddenVolumeSize, unsigned __int64 encryptedAreaStart, unsigned __int64 encryptedAreaLength, uint16 requiredProgramVersion, uint32 headerFlags, uint32 sectorSize, BOOL bWipeMode);
|
||||
BOOL ReadEffectiveVolumeHeader (BOOL device, HANDLE fileHandle, byte *header, DWORD *bytesRead);
|
||||
BOOL WriteEffectiveVolumeHeader (BOOL device, HANDLE fileHandle, byte *header);
|
||||
int WriteRandomDataToReservedHeaderAreas (HWND hwndDlg, HANDLE dev, CRYPTO_INFO *cryptoInfo, uint64 dataAreaSize, BOOL bPrimaryOnly, BOOL bBackupOnly);
|
||||
#endif
|
||||
|
||||
#endif // !TC_HEADER_Volume_VolumeHeader
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_Common_Volumes
|
||||
|
||||
@@ -1,198 +1,198 @@
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Wipe.h"
|
||||
|
||||
|
||||
static BOOL Wipe1PseudoRandom (int pass, byte *buffer, size_t size)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
// Fill buffer with wipe patterns defined in "National Industrial Security Program Operating Manual", US DoD 5220.22-M.
|
||||
// Return: FALSE = buffer must be filled with random data
|
||||
|
||||
static BOOL Wipe3Dod5220 (int pass, byte *buffer, size_t size)
|
||||
{
|
||||
byte wipeChar;
|
||||
|
||||
switch (pass)
|
||||
{
|
||||
case 1:
|
||||
wipeChar = 0;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
wipeChar = 0xff;
|
||||
break;
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
memset (buffer, wipeChar, size);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static BOOL Wipe7Dod5220 (int pass, byte randChars[TC_WIPE_RAND_CHAR_COUNT], byte *buffer, size_t size)
|
||||
{
|
||||
byte wipeChar;
|
||||
|
||||
switch (pass)
|
||||
{
|
||||
case 1:
|
||||
wipeChar = randChars[0];
|
||||
break;
|
||||
|
||||
case 2:
|
||||
wipeChar = ~randChars[0];
|
||||
break;
|
||||
|
||||
case 4:
|
||||
wipeChar = randChars[1];
|
||||
break;
|
||||
|
||||
case 5:
|
||||
wipeChar = randChars[2];
|
||||
break;
|
||||
|
||||
case 6:
|
||||
wipeChar = ~randChars[2];
|
||||
break;
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
memset (buffer, wipeChar, size);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
// Fill the buffer with wipe patterns defined in the paper "Secure Deletion of Data from Magnetic and Solid-State Memory" by Peter Gutmann.
|
||||
// Return: FALSE = buffer must be filled with random data
|
||||
|
||||
static BOOL Wipe35Gutmann (int pass, byte *buffer, size_t size)
|
||||
{
|
||||
byte wipePat3[] = { 0x92, 0x49, 0x24 };
|
||||
int wipePat3Pos;
|
||||
size_t i;
|
||||
|
||||
switch (pass)
|
||||
{
|
||||
case 5:
|
||||
memset (buffer, 0x55, size);
|
||||
break;
|
||||
|
||||
case 6:
|
||||
memset (buffer, 0xaa, size);
|
||||
break;
|
||||
|
||||
case 7:
|
||||
case 26:
|
||||
case 29:
|
||||
wipePat3Pos = 0;
|
||||
goto wipe3;
|
||||
|
||||
case 8:
|
||||
case 27:
|
||||
case 30:
|
||||
wipePat3Pos = 1;
|
||||
goto wipe3;
|
||||
|
||||
case 9:
|
||||
case 28:
|
||||
case 31:
|
||||
wipePat3Pos = 2;
|
||||
goto wipe3;
|
||||
|
||||
wipe3:
|
||||
if (pass >= 29)
|
||||
{
|
||||
wipePat3[0] = ~wipePat3[0];
|
||||
wipePat3[1] = ~wipePat3[1];
|
||||
wipePat3[2] = ~wipePat3[2];
|
||||
}
|
||||
|
||||
for (i = 0; i < size; ++i)
|
||||
{
|
||||
buffer[i] = wipePat3[wipePat3Pos++ % 3];
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (pass >= 10 && pass <= 25)
|
||||
memset (buffer, (pass - 10) * 0x11, size);
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
int GetWipePassCount (WipeAlgorithmId algorithm)
|
||||
{
|
||||
switch (algorithm)
|
||||
{
|
||||
case TC_WIPE_1_RAND:
|
||||
return 1;
|
||||
|
||||
case TC_WIPE_3_DOD_5220:
|
||||
return 3;
|
||||
|
||||
case TC_WIPE_7_DOD_5220:
|
||||
return 7;
|
||||
|
||||
case TC_WIPE_35_GUTMANN:
|
||||
return 35;
|
||||
|
||||
case TC_WIPE_256:
|
||||
return 256;
|
||||
}
|
||||
|
||||
return -1; // Prevent compiler warnings
|
||||
}
|
||||
|
||||
|
||||
BOOL WipeBuffer (WipeAlgorithmId algorithm, byte randChars[TC_WIPE_RAND_CHAR_COUNT], int pass, byte *buffer, size_t size)
|
||||
{
|
||||
switch (algorithm)
|
||||
{
|
||||
case TC_WIPE_1_RAND:
|
||||
case TC_WIPE_256:
|
||||
return Wipe1PseudoRandom (pass, buffer, size);
|
||||
|
||||
case TC_WIPE_3_DOD_5220:
|
||||
return Wipe3Dod5220 (pass, buffer, size);
|
||||
|
||||
case TC_WIPE_7_DOD_5220:
|
||||
return Wipe7Dod5220 (pass, randChars, buffer, size);
|
||||
|
||||
case TC_WIPE_35_GUTMANN:
|
||||
return Wipe35Gutmann (pass, buffer, size);
|
||||
|
||||
/* we will never reach here because all calls to WipeBuffer are preceeded
|
||||
* by a call to GetWipePassCount that already checks the same algorithm
|
||||
* parameters and in case of unsupported value an error is returned before
|
||||
* calling WipeBuffer
|
||||
*/
|
||||
/*
|
||||
default:
|
||||
TC_THROW_FATAL_EXCEPTION;*/
|
||||
}
|
||||
|
||||
return FALSE; // Prevent compiler warnings
|
||||
}
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Wipe.h"
|
||||
|
||||
|
||||
static BOOL Wipe1PseudoRandom (int pass, byte *buffer, size_t size)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
// Fill buffer with wipe patterns defined in "National Industrial Security Program Operating Manual", US DoD 5220.22-M.
|
||||
// Return: FALSE = buffer must be filled with random data
|
||||
|
||||
static BOOL Wipe3Dod5220 (int pass, byte *buffer, size_t size)
|
||||
{
|
||||
byte wipeChar;
|
||||
|
||||
switch (pass)
|
||||
{
|
||||
case 1:
|
||||
wipeChar = 0;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
wipeChar = 0xff;
|
||||
break;
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
memset (buffer, wipeChar, size);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static BOOL Wipe7Dod5220 (int pass, byte randChars[TC_WIPE_RAND_CHAR_COUNT], byte *buffer, size_t size)
|
||||
{
|
||||
byte wipeChar;
|
||||
|
||||
switch (pass)
|
||||
{
|
||||
case 1:
|
||||
wipeChar = randChars[0];
|
||||
break;
|
||||
|
||||
case 2:
|
||||
wipeChar = ~randChars[0];
|
||||
break;
|
||||
|
||||
case 4:
|
||||
wipeChar = randChars[1];
|
||||
break;
|
||||
|
||||
case 5:
|
||||
wipeChar = randChars[2];
|
||||
break;
|
||||
|
||||
case 6:
|
||||
wipeChar = ~randChars[2];
|
||||
break;
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
memset (buffer, wipeChar, size);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
// Fill the buffer with wipe patterns defined in the paper "Secure Deletion of Data from Magnetic and Solid-State Memory" by Peter Gutmann.
|
||||
// Return: FALSE = buffer must be filled with random data
|
||||
|
||||
static BOOL Wipe35Gutmann (int pass, byte *buffer, size_t size)
|
||||
{
|
||||
byte wipePat3[] = { 0x92, 0x49, 0x24 };
|
||||
int wipePat3Pos;
|
||||
size_t i;
|
||||
|
||||
switch (pass)
|
||||
{
|
||||
case 5:
|
||||
memset (buffer, 0x55, size);
|
||||
break;
|
||||
|
||||
case 6:
|
||||
memset (buffer, 0xaa, size);
|
||||
break;
|
||||
|
||||
case 7:
|
||||
case 26:
|
||||
case 29:
|
||||
wipePat3Pos = 0;
|
||||
goto wipe3;
|
||||
|
||||
case 8:
|
||||
case 27:
|
||||
case 30:
|
||||
wipePat3Pos = 1;
|
||||
goto wipe3;
|
||||
|
||||
case 9:
|
||||
case 28:
|
||||
case 31:
|
||||
wipePat3Pos = 2;
|
||||
goto wipe3;
|
||||
|
||||
wipe3:
|
||||
if (pass >= 29)
|
||||
{
|
||||
wipePat3[0] = ~wipePat3[0];
|
||||
wipePat3[1] = ~wipePat3[1];
|
||||
wipePat3[2] = ~wipePat3[2];
|
||||
}
|
||||
|
||||
for (i = 0; i < size; ++i)
|
||||
{
|
||||
buffer[i] = wipePat3[wipePat3Pos++ % 3];
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (pass >= 10 && pass <= 25)
|
||||
memset (buffer, (pass - 10) * 0x11, size);
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
int GetWipePassCount (WipeAlgorithmId algorithm)
|
||||
{
|
||||
switch (algorithm)
|
||||
{
|
||||
case TC_WIPE_1_RAND:
|
||||
return 1;
|
||||
|
||||
case TC_WIPE_3_DOD_5220:
|
||||
return 3;
|
||||
|
||||
case TC_WIPE_7_DOD_5220:
|
||||
return 7;
|
||||
|
||||
case TC_WIPE_35_GUTMANN:
|
||||
return 35;
|
||||
|
||||
case TC_WIPE_256:
|
||||
return 256;
|
||||
}
|
||||
|
||||
return -1; // Prevent compiler warnings
|
||||
}
|
||||
|
||||
|
||||
BOOL WipeBuffer (WipeAlgorithmId algorithm, byte randChars[TC_WIPE_RAND_CHAR_COUNT], int pass, byte *buffer, size_t size)
|
||||
{
|
||||
switch (algorithm)
|
||||
{
|
||||
case TC_WIPE_1_RAND:
|
||||
case TC_WIPE_256:
|
||||
return Wipe1PseudoRandom (pass, buffer, size);
|
||||
|
||||
case TC_WIPE_3_DOD_5220:
|
||||
return Wipe3Dod5220 (pass, buffer, size);
|
||||
|
||||
case TC_WIPE_7_DOD_5220:
|
||||
return Wipe7Dod5220 (pass, randChars, buffer, size);
|
||||
|
||||
case TC_WIPE_35_GUTMANN:
|
||||
return Wipe35Gutmann (pass, buffer, size);
|
||||
|
||||
/* we will never reach here because all calls to WipeBuffer are preceeded
|
||||
* by a call to GetWipePassCount that already checks the same algorithm
|
||||
* parameters and in case of unsupported value an error is returned before
|
||||
* calling WipeBuffer
|
||||
*/
|
||||
/*
|
||||
default:
|
||||
TC_THROW_FATAL_EXCEPTION;*/
|
||||
}
|
||||
|
||||
return FALSE; // Prevent compiler warnings
|
||||
}
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Common_Wipe
|
||||
#define TC_HEADER_Common_Wipe
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
/* WARNING: As these values are written to config files, if they or their meanings
|
||||
are changed, incompatiblity with other versions may arise (upgrade, downgrade, etc.).
|
||||
When adding a new constant, verify that the value is unique within this block. */
|
||||
TC_WIPE_NONE = 0,
|
||||
TC_WIPE_1_RAND = 100,
|
||||
TC_WIPE_3_DOD_5220 = 300,
|
||||
TC_WIPE_7_DOD_5220 = 700,
|
||||
TC_WIPE_35_GUTMANN = 3500,
|
||||
TC_WIPE_256 = 25600
|
||||
|
||||
} WipeAlgorithmId;
|
||||
|
||||
#define TC_WIPE_RAND_CHAR_COUNT 3
|
||||
|
||||
int GetWipePassCount (WipeAlgorithmId algorithm);
|
||||
BOOL WipeBuffer (WipeAlgorithmId algorithm, byte randChars[TC_WIPE_RAND_CHAR_COUNT], int pass, byte *buffer, size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_Common_Wipe
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Common_Wipe
|
||||
#define TC_HEADER_Common_Wipe
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
/* WARNING: As these values are written to config files, if they or their meanings
|
||||
are changed, incompatiblity with other versions may arise (upgrade, downgrade, etc.).
|
||||
When adding a new constant, verify that the value is unique within this block. */
|
||||
TC_WIPE_NONE = 0,
|
||||
TC_WIPE_1_RAND = 100,
|
||||
TC_WIPE_3_DOD_5220 = 300,
|
||||
TC_WIPE_7_DOD_5220 = 700,
|
||||
TC_WIPE_35_GUTMANN = 3500,
|
||||
TC_WIPE_256 = 25600
|
||||
|
||||
} WipeAlgorithmId;
|
||||
|
||||
#define TC_WIPE_RAND_CHAR_COUNT 3
|
||||
|
||||
int GetWipePassCount (WipeAlgorithmId algorithm);
|
||||
BOOL WipeBuffer (WipeAlgorithmId algorithm, byte randChars[TC_WIPE_RAND_CHAR_COUNT], int pass, byte *buffer, size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_Common_Wipe
|
||||
|
||||
536
src/Common/Xml.c
536
src/Common/Xml.c
@@ -1,268 +1,268 @@
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include "Xml.h"
|
||||
|
||||
|
||||
static BOOL BeginsWith (char *string, char *subString)
|
||||
{
|
||||
while (*string++ == *subString++)
|
||||
{
|
||||
if (*subString == 0) return TRUE;
|
||||
if (*string == 0) return FALSE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
char *XmlNextNode (char *xmlNode)
|
||||
{
|
||||
char *t = xmlNode + 1;
|
||||
while ((t = strchr (t, '<')) != NULL)
|
||||
{
|
||||
if (t[1] != '/')
|
||||
return t;
|
||||
|
||||
t++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char *XmlFindElement (char *xmlNode, char *nodeName)
|
||||
{
|
||||
char *t = xmlNode;
|
||||
size_t nameLen = strlen (nodeName);
|
||||
|
||||
do
|
||||
{
|
||||
if (BeginsWith (t + 1, nodeName)
|
||||
&& (t[nameLen + 1] == '>'
|
||||
|| t[nameLen + 1] == ' ')) return t;
|
||||
|
||||
} while (t = XmlNextNode (t));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char *XmlFindElementByAttributeValue (char *xml, char *nodeName, char *attrName, char *attrValue)
|
||||
{
|
||||
char attr[2048];
|
||||
|
||||
while (xml = XmlFindElement (xml, nodeName))
|
||||
{
|
||||
XmlGetAttributeText (xml, attrName, attr, sizeof (attr));
|
||||
if (strcmp (attr, attrValue) == 0)
|
||||
return xml;
|
||||
|
||||
xml++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char *XmlGetAttributeText (char *xmlNode, char *xmlAttrName, char *xmlAttrValue, int xmlAttrValueSize)
|
||||
{
|
||||
char *t = xmlNode;
|
||||
char *e = xmlNode;
|
||||
int l = 0;
|
||||
|
||||
xmlAttrValue[0] = 0;
|
||||
if (t[0] != '<') return NULL;
|
||||
|
||||
e = strchr (e, '>');
|
||||
if (e == NULL) return NULL;
|
||||
|
||||
while ((t = strstr (t, xmlAttrName)) && t < e)
|
||||
{
|
||||
char *o = t + strlen (xmlAttrName);
|
||||
if (t[-1] == ' '
|
||||
&&
|
||||
(BeginsWith (o, "=\"")
|
||||
|| BeginsWith (o, "= \"")
|
||||
|| BeginsWith (o, " =\"")
|
||||
|| BeginsWith (o, " = \""))
|
||||
)
|
||||
break;
|
||||
|
||||
t++;
|
||||
}
|
||||
|
||||
if (t == NULL || t > e) return NULL;
|
||||
|
||||
t = strchr (t, '"') + 1;
|
||||
e = strchr (t, '"');
|
||||
l = (int)(e - t);
|
||||
if (e == NULL || l > xmlAttrValueSize) return NULL;
|
||||
|
||||
memcpy (xmlAttrValue, t, l);
|
||||
xmlAttrValue[l] = 0;
|
||||
|
||||
return xmlAttrValue;
|
||||
}
|
||||
|
||||
|
||||
char *XmlGetNodeText (char *xmlNode, char *xmlText, int xmlTextSize)
|
||||
{
|
||||
char *t = xmlNode;
|
||||
char *e = xmlNode + 1;
|
||||
int l = 0, i = 0, j = 0;
|
||||
|
||||
xmlText[0] = 0;
|
||||
|
||||
if (t[0] != '<')
|
||||
return NULL;
|
||||
|
||||
t = strchr (t, '>') + 1;
|
||||
if (t == (char *)1) return NULL;
|
||||
|
||||
e = strchr (e, '<');
|
||||
if (e == NULL) return NULL;
|
||||
|
||||
l = (int)(e - t);
|
||||
if (e == NULL || l > xmlTextSize) return NULL;
|
||||
|
||||
while (i < l)
|
||||
{
|
||||
if (BeginsWith (&t[i], "<"))
|
||||
{
|
||||
xmlText[j++] = '<';
|
||||
i += 4;
|
||||
continue;
|
||||
}
|
||||
if (BeginsWith (&t[i], ">"))
|
||||
{
|
||||
xmlText[j++] = '>';
|
||||
i += 4;
|
||||
continue;
|
||||
}
|
||||
if (BeginsWith (&t[i], "&"))
|
||||
{
|
||||
xmlText[j++] = '&';
|
||||
i += 5;
|
||||
continue;
|
||||
}
|
||||
xmlText[j++] = t[i++];
|
||||
}
|
||||
xmlText[j] = 0;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
char *XmlQuoteText (const char *textSrc, char *textDst, int textDstMaxSize)
|
||||
{
|
||||
char *textDstLast = textDst + textDstMaxSize - 1;
|
||||
|
||||
if (textDstMaxSize == 0)
|
||||
return NULL;
|
||||
|
||||
while (*textSrc != 0 && textDst <= textDstLast)
|
||||
{
|
||||
char c = *textSrc++;
|
||||
switch (c)
|
||||
{
|
||||
case '&':
|
||||
if (textDst + 6 > textDstLast)
|
||||
return NULL;
|
||||
strcpy (textDst, "&");
|
||||
textDst += 5;
|
||||
continue;
|
||||
|
||||
case '>':
|
||||
if (textDst + 5 > textDstLast)
|
||||
return NULL;
|
||||
strcpy (textDst, ">");
|
||||
textDst += 4;
|
||||
continue;
|
||||
|
||||
case '<':
|
||||
if (textDst + 5 > textDstLast)
|
||||
return NULL;
|
||||
strcpy (textDst, "<");
|
||||
textDst += 4;
|
||||
continue;
|
||||
|
||||
default:
|
||||
*textDst++ = c;
|
||||
}
|
||||
}
|
||||
|
||||
if (textDst > textDstLast)
|
||||
return NULL;
|
||||
|
||||
*textDst = 0;
|
||||
return textDst;
|
||||
}
|
||||
|
||||
wchar_t *XmlQuoteTextW (const wchar_t *textSrc, wchar_t *textDst, int textDstMaxSize)
|
||||
{
|
||||
wchar_t *textDstLast = textDst + textDstMaxSize - 1;
|
||||
|
||||
if (textDstMaxSize == 0)
|
||||
return NULL;
|
||||
|
||||
while (*textSrc != 0 && textDst <= textDstLast)
|
||||
{
|
||||
wchar_t c = *textSrc++;
|
||||
switch (c)
|
||||
{
|
||||
case L'&':
|
||||
if (textDst + 6 > textDstLast)
|
||||
return NULL;
|
||||
wcscpy (textDst, L"&");
|
||||
textDst += 5;
|
||||
continue;
|
||||
|
||||
case L'>':
|
||||
if (textDst + 5 > textDstLast)
|
||||
return NULL;
|
||||
wcscpy (textDst, L">");
|
||||
textDst += 4;
|
||||
continue;
|
||||
|
||||
case L'<':
|
||||
if (textDst + 5 > textDstLast)
|
||||
return NULL;
|
||||
wcscpy (textDst, L"<");
|
||||
textDst += 4;
|
||||
continue;
|
||||
|
||||
default:
|
||||
*textDst++ = c;
|
||||
}
|
||||
}
|
||||
|
||||
if (textDst > textDstLast)
|
||||
return NULL;
|
||||
|
||||
*textDst = 0;
|
||||
return textDst;
|
||||
}
|
||||
|
||||
|
||||
int XmlWriteHeader (FILE *file)
|
||||
{
|
||||
return fputws (L"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<VeraCrypt>", file);
|
||||
}
|
||||
|
||||
|
||||
int XmlWriteFooter (FILE *file)
|
||||
{
|
||||
return fputws (L"\n</VeraCrypt>", file);
|
||||
}
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include "Xml.h"
|
||||
|
||||
|
||||
static BOOL BeginsWith (char *string, char *subString)
|
||||
{
|
||||
while (*string++ == *subString++)
|
||||
{
|
||||
if (*subString == 0) return TRUE;
|
||||
if (*string == 0) return FALSE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
char *XmlNextNode (char *xmlNode)
|
||||
{
|
||||
char *t = xmlNode + 1;
|
||||
while ((t = strchr (t, '<')) != NULL)
|
||||
{
|
||||
if (t[1] != '/')
|
||||
return t;
|
||||
|
||||
t++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char *XmlFindElement (char *xmlNode, char *nodeName)
|
||||
{
|
||||
char *t = xmlNode;
|
||||
size_t nameLen = strlen (nodeName);
|
||||
|
||||
do
|
||||
{
|
||||
if (BeginsWith (t + 1, nodeName)
|
||||
&& (t[nameLen + 1] == '>'
|
||||
|| t[nameLen + 1] == ' ')) return t;
|
||||
|
||||
} while (t = XmlNextNode (t));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char *XmlFindElementByAttributeValue (char *xml, char *nodeName, char *attrName, char *attrValue)
|
||||
{
|
||||
char attr[2048];
|
||||
|
||||
while (xml = XmlFindElement (xml, nodeName))
|
||||
{
|
||||
XmlGetAttributeText (xml, attrName, attr, sizeof (attr));
|
||||
if (strcmp (attr, attrValue) == 0)
|
||||
return xml;
|
||||
|
||||
xml++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char *XmlGetAttributeText (char *xmlNode, char *xmlAttrName, char *xmlAttrValue, int xmlAttrValueSize)
|
||||
{
|
||||
char *t = xmlNode;
|
||||
char *e = xmlNode;
|
||||
int l = 0;
|
||||
|
||||
xmlAttrValue[0] = 0;
|
||||
if (t[0] != '<') return NULL;
|
||||
|
||||
e = strchr (e, '>');
|
||||
if (e == NULL) return NULL;
|
||||
|
||||
while ((t = strstr (t, xmlAttrName)) && t < e)
|
||||
{
|
||||
char *o = t + strlen (xmlAttrName);
|
||||
if (t[-1] == ' '
|
||||
&&
|
||||
(BeginsWith (o, "=\"")
|
||||
|| BeginsWith (o, "= \"")
|
||||
|| BeginsWith (o, " =\"")
|
||||
|| BeginsWith (o, " = \""))
|
||||
)
|
||||
break;
|
||||
|
||||
t++;
|
||||
}
|
||||
|
||||
if (t == NULL || t > e) return NULL;
|
||||
|
||||
t = strchr (t, '"') + 1;
|
||||
e = strchr (t, '"');
|
||||
l = (int)(e - t);
|
||||
if (e == NULL || l > xmlAttrValueSize) return NULL;
|
||||
|
||||
memcpy (xmlAttrValue, t, l);
|
||||
xmlAttrValue[l] = 0;
|
||||
|
||||
return xmlAttrValue;
|
||||
}
|
||||
|
||||
|
||||
char *XmlGetNodeText (char *xmlNode, char *xmlText, int xmlTextSize)
|
||||
{
|
||||
char *t = xmlNode;
|
||||
char *e = xmlNode + 1;
|
||||
int l = 0, i = 0, j = 0;
|
||||
|
||||
xmlText[0] = 0;
|
||||
|
||||
if (t[0] != '<')
|
||||
return NULL;
|
||||
|
||||
t = strchr (t, '>') + 1;
|
||||
if (t == (char *)1) return NULL;
|
||||
|
||||
e = strchr (e, '<');
|
||||
if (e == NULL) return NULL;
|
||||
|
||||
l = (int)(e - t);
|
||||
if (e == NULL || l > xmlTextSize) return NULL;
|
||||
|
||||
while (i < l)
|
||||
{
|
||||
if (BeginsWith (&t[i], "<"))
|
||||
{
|
||||
xmlText[j++] = '<';
|
||||
i += 4;
|
||||
continue;
|
||||
}
|
||||
if (BeginsWith (&t[i], ">"))
|
||||
{
|
||||
xmlText[j++] = '>';
|
||||
i += 4;
|
||||
continue;
|
||||
}
|
||||
if (BeginsWith (&t[i], "&"))
|
||||
{
|
||||
xmlText[j++] = '&';
|
||||
i += 5;
|
||||
continue;
|
||||
}
|
||||
xmlText[j++] = t[i++];
|
||||
}
|
||||
xmlText[j] = 0;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
char *XmlQuoteText (const char *textSrc, char *textDst, int textDstMaxSize)
|
||||
{
|
||||
char *textDstLast = textDst + textDstMaxSize - 1;
|
||||
|
||||
if (textDstMaxSize == 0)
|
||||
return NULL;
|
||||
|
||||
while (*textSrc != 0 && textDst <= textDstLast)
|
||||
{
|
||||
char c = *textSrc++;
|
||||
switch (c)
|
||||
{
|
||||
case '&':
|
||||
if (textDst + 6 > textDstLast)
|
||||
return NULL;
|
||||
strcpy (textDst, "&");
|
||||
textDst += 5;
|
||||
continue;
|
||||
|
||||
case '>':
|
||||
if (textDst + 5 > textDstLast)
|
||||
return NULL;
|
||||
strcpy (textDst, ">");
|
||||
textDst += 4;
|
||||
continue;
|
||||
|
||||
case '<':
|
||||
if (textDst + 5 > textDstLast)
|
||||
return NULL;
|
||||
strcpy (textDst, "<");
|
||||
textDst += 4;
|
||||
continue;
|
||||
|
||||
default:
|
||||
*textDst++ = c;
|
||||
}
|
||||
}
|
||||
|
||||
if (textDst > textDstLast)
|
||||
return NULL;
|
||||
|
||||
*textDst = 0;
|
||||
return textDst;
|
||||
}
|
||||
|
||||
wchar_t *XmlQuoteTextW (const wchar_t *textSrc, wchar_t *textDst, int textDstMaxSize)
|
||||
{
|
||||
wchar_t *textDstLast = textDst + textDstMaxSize - 1;
|
||||
|
||||
if (textDstMaxSize == 0)
|
||||
return NULL;
|
||||
|
||||
while (*textSrc != 0 && textDst <= textDstLast)
|
||||
{
|
||||
wchar_t c = *textSrc++;
|
||||
switch (c)
|
||||
{
|
||||
case L'&':
|
||||
if (textDst + 6 > textDstLast)
|
||||
return NULL;
|
||||
wcscpy (textDst, L"&");
|
||||
textDst += 5;
|
||||
continue;
|
||||
|
||||
case L'>':
|
||||
if (textDst + 5 > textDstLast)
|
||||
return NULL;
|
||||
wcscpy (textDst, L">");
|
||||
textDst += 4;
|
||||
continue;
|
||||
|
||||
case L'<':
|
||||
if (textDst + 5 > textDstLast)
|
||||
return NULL;
|
||||
wcscpy (textDst, L"<");
|
||||
textDst += 4;
|
||||
continue;
|
||||
|
||||
default:
|
||||
*textDst++ = c;
|
||||
}
|
||||
}
|
||||
|
||||
if (textDst > textDstLast)
|
||||
return NULL;
|
||||
|
||||
*textDst = 0;
|
||||
return textDst;
|
||||
}
|
||||
|
||||
|
||||
int XmlWriteHeader (FILE *file)
|
||||
{
|
||||
return fputws (L"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<VeraCrypt>", file);
|
||||
}
|
||||
|
||||
|
||||
int XmlWriteFooter (FILE *file)
|
||||
{
|
||||
return fputws (L"\n</VeraCrypt>", file);
|
||||
}
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
char *XmlNextNode (char *xmlNode);
|
||||
char *XmlFindElement (char *xmlNode, char *nodeName);
|
||||
char *XmlGetAttributeText (char *xmlNode, char *xmlAttrName, char *xmlAttrValue, int xmlAttrValueSize);
|
||||
char *XmlGetNodeText (char *xmlNode, char *xmlText, int xmlTextSize);
|
||||
int XmlWriteHeader (FILE *file);
|
||||
int XmlWriteFooter (FILE *file);
|
||||
char *XmlFindElementByAttributeValue (char *xml, char *nodeName, char *attrName, char *attrValue);
|
||||
char *XmlQuoteText (const char *textSrc, char *textDst, int textDstMaxSize);
|
||||
wchar_t *XmlQuoteTextW (const wchar_t *textSrc, wchar_t *textDst, int textDstMaxSize);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
char *XmlNextNode (char *xmlNode);
|
||||
char *XmlFindElement (char *xmlNode, char *nodeName);
|
||||
char *XmlGetAttributeText (char *xmlNode, char *xmlAttrName, char *xmlAttrValue, int xmlAttrValueSize);
|
||||
char *XmlGetNodeText (char *xmlNode, char *xmlText, int xmlTextSize);
|
||||
int XmlWriteHeader (FILE *file);
|
||||
int XmlWriteFooter (FILE *file);
|
||||
char *XmlFindElementByAttributeValue (char *xml, char *nodeName, char *attrName, char *attrValue);
|
||||
char *XmlQuoteText (const char *textSrc, char *textDst, int textDstMaxSize);
|
||||
wchar_t *XmlQuoteTextW (const wchar_t *textSrc, wchar_t *textDst, int textDstMaxSize);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
1500
src/Common/Xts.c
1500
src/Common/Xts.c
File diff suppressed because it is too large
Load Diff
168
src/Common/Xts.h
168
src/Common/Xts.h
@@ -1,84 +1,84 @@
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifndef XTS_H
|
||||
#define XTS_H
|
||||
|
||||
// Header files (optional)
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Common/Endian.h"
|
||||
#include "Crypto.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Macros
|
||||
|
||||
#ifndef LITTLE_ENDIAN
|
||||
# define LITTLE_ENDIAN 1
|
||||
#endif
|
||||
|
||||
#ifndef BIG_ENDIAN
|
||||
# define BIG_ENDIAN 2
|
||||
#endif
|
||||
|
||||
#ifndef BYTE_ORDER
|
||||
# define BYTE_ORDER LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
#ifndef LE64
|
||||
# if BYTE_ORDER == LITTLE_ENDIAN
|
||||
# define LE64(x) (x)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// Custom data types
|
||||
|
||||
#ifndef TC_LARGEST_COMPILER_UINT
|
||||
# ifdef TC_NO_COMPILER_INT64
|
||||
typedef unsigned __int32 TC_LARGEST_COMPILER_UINT;
|
||||
# else
|
||||
typedef unsigned __int64 TC_LARGEST_COMPILER_UINT;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef TCDEFS_H
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
unsigned __int32 LowPart;
|
||||
unsigned __int32 HighPart;
|
||||
};
|
||||
# ifndef TC_NO_COMPILER_INT64
|
||||
unsigned __int64 Value;
|
||||
# endif
|
||||
|
||||
} UINT64_STRUCT;
|
||||
#endif
|
||||
|
||||
// Public function prototypes
|
||||
|
||||
void EncryptBufferXTS (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
static void EncryptBufferXTSParallel (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
static void EncryptBufferXTSNonParallel (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
void DecryptBufferXTS (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
static void DecryptBufferXTSParallel (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
static void DecryptBufferXTSNonParallel (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // #ifndef XTS_H
|
||||
/*
|
||||
Derived from source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
|
||||
by the TrueCrypt License 3.0.
|
||||
|
||||
Modifications and additions to the original source code (contained in this file)
|
||||
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
|
||||
and are governed by the Apache License 2.0 the full text of which is
|
||||
contained in the file License.txt included in VeraCrypt binary and source
|
||||
code distribution packages.
|
||||
*/
|
||||
|
||||
#ifndef XTS_H
|
||||
#define XTS_H
|
||||
|
||||
// Header files (optional)
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Common/Endian.h"
|
||||
#include "Crypto.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Macros
|
||||
|
||||
#ifndef LITTLE_ENDIAN
|
||||
# define LITTLE_ENDIAN 1
|
||||
#endif
|
||||
|
||||
#ifndef BIG_ENDIAN
|
||||
# define BIG_ENDIAN 2
|
||||
#endif
|
||||
|
||||
#ifndef BYTE_ORDER
|
||||
# define BYTE_ORDER LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
#ifndef LE64
|
||||
# if BYTE_ORDER == LITTLE_ENDIAN
|
||||
# define LE64(x) (x)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// Custom data types
|
||||
|
||||
#ifndef TC_LARGEST_COMPILER_UINT
|
||||
# ifdef TC_NO_COMPILER_INT64
|
||||
typedef unsigned __int32 TC_LARGEST_COMPILER_UINT;
|
||||
# else
|
||||
typedef unsigned __int64 TC_LARGEST_COMPILER_UINT;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef TCDEFS_H
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
unsigned __int32 LowPart;
|
||||
unsigned __int32 HighPart;
|
||||
};
|
||||
# ifndef TC_NO_COMPILER_INT64
|
||||
unsigned __int64 Value;
|
||||
# endif
|
||||
|
||||
} UINT64_STRUCT;
|
||||
#endif
|
||||
|
||||
// Public function prototypes
|
||||
|
||||
void EncryptBufferXTS (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
static void EncryptBufferXTSParallel (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
static void EncryptBufferXTSNonParallel (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
void DecryptBufferXTS (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
static void DecryptBufferXTSParallel (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
static void DecryptBufferXTSNonParallel (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // #ifndef XTS_H
|
||||
|
||||
Reference in New Issue
Block a user