--- truecrypt/common/tcdefs.h 2018/04/24 16:40:43 1.1.1.5 +++ truecrypt/common/tcdefs.h 2018/04/24 16:53:40 1.1.1.18 @@ -1,66 +1,87 @@ -/* The source code contained in this file has been derived from the source code - of Encryption for the Masses 2.02a by Paul Le Roux. Modifications and - additions to that source code contained in this file are Copyright (c) 2004 - TrueCrypt Team and Copyright (c) 2004 TrueCrypt Foundation. Unmodified - parts are Copyright (c) 1998-99 Paul Le Roux. This is a TrueCrypt Foundation - release. Please see the file license.txt for full license details. */ +/* + Legal Notice: Some portions of the source code contained in this file were + derived 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) 2003-2008 TrueCrypt Foundation and are governed + by the TrueCrypt License 2.5 the full text of which is contained in the + file License.txt included in TrueCrypt binary and source code distribution + packages. */ + +#ifndef TCDEFS_H +#define TCDEFS_H + +#define TC_APP_NAME "TrueCrypt" // Version displayed to user -#define VERSION_STRING "2.1a" +#define VERSION_STRING "6.0" // Version number to compare against driver -#define VERSION_NUM 0x0210 +#define VERSION_NUM 0x0600 -// Version number written to volume header during format, -// specifies the minimum program version required to mount the volume -#define VOLUME_VERSION_NUM 0x0100 +// Sector size of encrypted filesystem, which may differ from sector size +// of host filesystem/device (this is fully supported since v4.3). +#define SECTOR_SIZE 512 + +// "Second generation standard" sector size +#define SECTOR_SIZE_GEN2_STANDARD 4096 + +#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 -#define TC_MAX_PATH 260 /* Includes the null terminator */ -#define SECTOR_SIZE 512 /* sector size */ +/* GUI/driver errors */ -#define BYTES_PER_KB 1024 -#define BYTES_PER_MB 1048576 +#define WIDE(x) (LPWSTR)L##x -/* GUI/driver errors */ +typedef __int8 int8; +typedef __int16 int16; +typedef __int32 int32; +typedef unsigned __int8 byte; +typedef unsigned __int16 uint16; +typedef unsigned __int32 uint32; -#define ERR_OS_ERROR 1 -#define ERR_OUTOFMEMORY 2 -#define ERR_PASSWORD_WRONG 3 -#define ERR_VOL_FORMAT_BAD 4 -#define ERR_BAD_DRIVE_LETTER 5 -#define ERR_DRIVE_NOT_FOUND 6 -#define ERR_FILES_OPEN 7 -#define ERR_VOL_SIZE_WRONG 8 -#define ERR_COMPRESSION_NOT_SUPPORTED 9 -#define ERR_PASSWORD_CHANGE_VOL_TYPE 10 -#define ERR_PASSWORD_CHANGE_VOL_VERSION 11 -#define ERR_VOL_SEEKING 12 -#define ERR_VOL_WRITING 13 -#define ERR_FILES_OPEN_LOCK 14 -#define ERR_VOL_READING 15 -#define ERR_DRIVER_VERSION 16 -#define ERR_NEW_VERSION_REQUIRED 17 - -#define ERR_VOL_ALREADY_MOUNTED 32 -#define ERR_NO_FREE_SLOTS 33 -#define ERR_NO_FREE_DRIVES 34 -#define ERR_FILE_OPEN_FAILED 35 -#define ERR_VOL_MOUNT_FAILED 36 -#define ERR_INVALID_DEVICE 37 -#define ERR_ACCESS_DENIED 38 - -#define MIN_VOLUME_SIZE 19456 -#define MAX_VOLUME_SIZE 0x7fffFFFFffffFFFFI64 - -#define burn(mem,size) \ - memset(mem,0xff,size); \ - memset(mem,0,size); +#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; +#endif -#define WIDE(x) (LPWSTR)L##x +#define TC_INT_TYPES_DEFINED -#include +// 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 unsigned __int64 uint_64t; +#endif + +typedef union +{ + struct + { + unsigned __int32 LowPart; + unsigned __int32 HighPart; + }; +#ifndef TC_NO_COMPILER_INT64 + unsigned __int64 Value; +#endif -#pragma intrinsic(memcmp, memcpy, memset, strcat, strcmp, strcpy, strlen) +} UINT64_STRUCT; + +#ifdef TC_WINDOWS_BOOT +# define TC_THROW_FATAL_EXCEPTION ThrowFatalException (__LINE__) +#elif defined (NT4_DRIVER) +# define TC_THROW_FATAL_EXCEPTION KeBugCheckEx (SECURITY_SYSTEM, __LINE__, 0, 0, 'TC') +#else +# define TC_THROW_FATAL_EXCEPTION *(char *) 0 = 0 +#endif #ifdef NT4_DRIVER @@ -75,7 +96,9 @@ #pragma warning( disable : 4127 ) +#include #include /* Standard header file for nt drivers */ + #undef _WIN32_WINNT #define _WIN32_WINNT 0x0501 #include /* Standard I/O control codes */ @@ -97,45 +120,6 @@ #define DEVICE_DRIVER -#endif /* NT4_DRIVER */ - - -#ifdef WIN9X_DRIVER - -#pragma warning( disable : 4047 ) - -#include "iosdcls.inc" /* VMM and IOS headers */ - -#pragma warning( default : 4047 ) - -#include -#include -#undef WANTVDXWRAPS -#pragma warning( disable : 4229 ) -#include -#pragma warning( default : 4229 ) -#pragma hdrstop -#include -#include -#include "ifs.h" -#include -#define MBYTE16 3967 -#define UWORD unsigned short -#define UBYTE unsigned char - -#define MBYTE16 3967 - -#define TCalloc(size) _PageAllocate(size % 4096 ? (size/4096)+1 : size/4096,\ - PG_SYS,0,0,0,MBYTE16,NULL,PAGEZEROINIT|PAGEFIXED|PAGECONTIG|PAGEUSEALIGN); - -#define TCfree(memblock) _PageFree(memblock,0) - -#define DEVICE_DRIVER - -#endif /* WIN9X_DRIVER */ - -#ifdef DEVICE_DRIVER - #ifndef BOOL typedef int BOOL; #endif @@ -151,7 +135,7 @@ typedef int BOOL; /* Define dummies for the drivers */ typedef int HFILE; typedef unsigned int WPARAM; -typedef unsigned long LPARAM; +typedef unsigned __int32 LPARAM; #define CALLBACK #ifndef UINT @@ -159,14 +143,17 @@ typedef unsigned int UINT; #endif #ifndef LRESULT -typedef unsigned long LRESULT; +typedef unsigned __int32 LRESULT; #endif +/* NT4_DRIVER */ #else #define TCalloc malloc #define TCfree free +#ifdef _WIN32 + #pragma warning( disable : 4201 ) #pragma warning( disable : 4214 ) #pragma warning( disable : 4115 ) @@ -187,11 +174,125 @@ typedef unsigned long LRESULT; /* #pragma warning( default : 4514 ) this warning remains disabled */ /* This is needed to fix a bug with VC 5, the TCHAR macro _ttoi64 maps - incorrectly to atoi64 when it should be _atoi64 */ + incorrectly to atoLL when it should be _atoi64 */ #define atoi64 _atoi64 -#endif /* DEVICE_DRIVER */ +#endif /* _WIN32 */ + +#endif /* NT4_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(...) ((void) 0) +# define DumpMem(...) ((void) 0) +# 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]; _snprintf (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); int 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 unsigned __int64 *burnm = (volatile unsigned __int64 *)(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 +# 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 MAX_URL_LENGTH 2084 /* Internet Explorer limit. Includes the terminating null character. */ + +#define TC_APPLINK "http://www.truecrypt.org/applink.php?version=" VERSION_STRING +#define TC_APPLINK_SECURE "https://www.truecrypt.org/applink.php?version=" VERSION_STRING -typedef UINT (_stdcall * diskio_f) (int, void *, UINT); +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, + 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 +}; -#pragma hdrstop +#endif // #ifndef TCDEFS_H