Skip to content

Commit

Permalink
Windows: Remove support for 32-bit driver code. Set build target as W…
Browse files Browse the repository at this point in the history
…indows 10. Simplify code and fix all warnings in driver.
  • Loading branch information
idrassi committed Nov 13, 2024
1 parent ec4b44c commit cb97351
Show file tree
Hide file tree
Showing 31 changed files with 512 additions and 777 deletions.
2 changes: 1 addition & 1 deletion src/Boot/Windows/BootCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ typedef struct
uint16 CryptoInfoOffset;
uint16 CryptoInfoLength;
uint32 HeaderSaltCrc32;
PasswordLegacy BootPassword;
__declspec(align(8)) PasswordLegacy BootPassword;
uint64 HiddenSystemPartitionStart;
uint64 DecoySystemPartitionStart;
uint32 Flags;
Expand Down
8 changes: 4 additions & 4 deletions src/Common/BootEncryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4382,14 +4382,14 @@ namespace VeraCrypt
if (!IsRandomNumberGeneratorStarted())
throw ParameterIncorrect (SRC_POS);

throw_sys_if (CreateVolumeHeaderInMemory (ParentWindow, TRUE, (char *) VolumeHeader, ea, mode, password, pkcs5, pim, NULL, &cryptoInfo,
throw_sys_if (CreateVolumeHeaderInMemory (ParentWindow, TRUE, VolumeHeader, ea, mode, password, pkcs5, pim, NULL, &cryptoInfo,
volumeSize, 0, encryptedAreaStart, 0, TC_SYSENC_KEYSCOPE_MIN_REQ_PROG_VERSION, TC_HEADER_FLAG_ENCRYPTED_SYSTEM, TC_SECTOR_SIZE_BIOS, FALSE) != 0);

finally_do_arg (PCRYPTO_INFO*, &cryptoInfo, { crypto_close (*finally_arg); });

// Initial rescue disk assumes encryption of the drive has been completed (EncryptedAreaLength == volumeSize)
memcpy (RescueVolumeHeader, VolumeHeader, sizeof (RescueVolumeHeader));
if (0 != ReadVolumeHeader (TRUE, (char *) RescueVolumeHeader, password, pkcs5, pim, NULL, cryptoInfo))
if (0 != ReadVolumeHeader (TRUE, RescueVolumeHeader, password, pkcs5, pim, NULL, cryptoInfo))
throw ParameterIncorrect (SRC_POS);

DecryptBuffer (RescueVolumeHeader + HEADER_ENCRYPTED_DATA_OFFSET, HEADER_ENCRYPTED_DATA_SIZE, cryptoInfo);
Expand Down Expand Up @@ -5391,7 +5391,7 @@ namespace VeraCrypt

SystemDriveConfiguration config = GetSystemDriveConfiguration ();

char header[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE];
unsigned char header[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE];
Device device (config.DevicePath);
device.CheckOpened (SRC_POS);

Expand Down Expand Up @@ -5421,7 +5421,7 @@ namespace VeraCrypt
}

device.SeekAt (headerOffset);
device.Read ((uint8 *) header, sizeof (header));
device.Read (header, sizeof (header));

PCRYPTO_INFO cryptoInfo = NULL;

Expand Down
2 changes: 1 addition & 1 deletion src/Common/Cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void VcUnprotectPassword (Password* pPassword, uint64 encID)

#endif

int ReadVolumeHeaderWCache (BOOL bBoot, BOOL bCache, BOOL bCachePim, char *header, Password *password, int pkcs5_prf, int pim, PCRYPTO_INFO *retInfo)
int ReadVolumeHeaderWCache (BOOL bBoot, BOOL bCache, BOOL bCachePim, unsigned char *header, Password *password, int pkcs5_prf, int pim, PCRYPTO_INFO *retInfo)
{
int nReturnCode = ERR_PASSWORD_WRONG;
int i, effectivePim;
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ extern int cacheEmpty;

void AddPasswordToCache (Password *password, int pim, BOOL bCachePim);
void AddLegacyPasswordToCache (PasswordLegacy *password, int pim);
int ReadVolumeHeaderWCache (BOOL bBoot, BOOL bCache, BOOL bCachePim,char *header, Password *password, int pkcs5_prf, int pim, PCRYPTO_INFO *retInfo);
int ReadVolumeHeaderWCache (BOOL bBoot, BOOL bCache, BOOL bCachePim, unsigned char *header, Password *password, int pkcs5_prf, int pim, PCRYPTO_INFO *retInfo);
void WipeCache (void);
12 changes: 7 additions & 5 deletions src/Common/Crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,8 @@ int EAGetNextMode (int ea, int previousModeId)
return 0;
}

// Returns the name of the mode of operation of the whole EA
wchar_t *EAGetModeName (int ea, int mode, BOOL capitalLetters)
// Returns the name of the mode of operation
const wchar_t *EAGetModeName (int mode)
{
switch (mode)
{
Expand All @@ -669,7 +669,7 @@ wchar_t *EAGetModeName (int ea, int mode, BOOL capitalLetters)
return L"XTS";

}
return L"[unknown]";
return L"[UNKNOWN]";
}

#endif // TC_WINDOWS_BOOT
Expand Down Expand Up @@ -891,7 +891,7 @@ PCRYPTO_INFO crypto_open ()
}

#ifndef TC_WINDOWS_BOOT
void crypto_loadkey (PKEY_INFO keyInfo, char *lpszUserKey, int nUserKeyLen)
void crypto_loadkey (PKEY_INFO keyInfo, unsigned char *lpszUserKey, int nUserKeyLen)
{
keyInfo->keyLength = nUserKeyLen;
burn (keyInfo->userKey, sizeof (keyInfo->userKey));
Expand Down Expand Up @@ -1239,9 +1239,11 @@ static BOOL RamEncryptionEnabled = FALSE;

BOOL IsCpuRngSupported ()
{
#ifndef _M_ARM64
if (HasRDSEED() || HasRDRAND())
return TRUE;
else
#endif
return FALSE;
}

Expand Down Expand Up @@ -1313,7 +1315,7 @@ uint8 GetRandomIndex (ChaCha20RngCtx* pCtx, uint8 elementsCount)
return index;
}

#if defined(_WIN64) && !defined (_UEFI)
#if !defined (_UEFI)
/* declaration of variables and functions used for RAM encryption on 64-bit build */
static uint8* pbKeyDerivationArea = NULL;
static ULONG cbKeyDerivationArea = 0;
Expand Down
10 changes: 5 additions & 5 deletions src/Common/Crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ 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 */
CRYPTOPP_ALIGN_DATA(16) __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. */
unsigned __int8 salt[PKCS5_SALT_SIZE]; /* PKCS-5 salt */
CRYPTOPP_ALIGN_DATA(16) unsigned __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) unsigned __int8 userKey[MAX_PASSWORD]; /* Password (to which keyfiles may have been applied). WITHOUT +1 for the null terminator. */
} KEY_INFO, *PKEY_INFO;

#endif
Expand Down Expand Up @@ -309,7 +309,7 @@ typedef struct BOOT_CRYPTO_HEADER_t

PCRYPTO_INFO crypto_open (void);
#ifndef TC_WINDOWS_BOOT
void crypto_loadkey (PKEY_INFO keyInfo, char *lpszUserKey, int nUserKeyLen);
void crypto_loadkey (PKEY_INFO keyInfo, unsigned char *lpszUserKey, int nUserKeyLen);
void crypto_eraseKeys (PCRYPTO_INFO cryptoInfo);
#endif
void crypto_close (PCRYPTO_INFO cryptoInfo);
Expand Down Expand Up @@ -348,7 +348,7 @@ 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);
const wchar_t * EAGetModeName (int mode);
#endif
int EAGetKeyScheduleSize (int ea);
int EAGetLargestKey ();
Expand Down
29 changes: 12 additions & 17 deletions src/Common/Dlgcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,11 +859,6 @@ BOOL VerifyModuleSignature (const wchar_t* path)
WINTRUST_DATA WVTData = {0};
wchar_t filePath [TC_MAX_PATH + 1024];

// we check our own authenticode signature only starting from Windows 10 since this is
// the minimal supported OS apart from XP where we can't verify SHA256 signatures
if (!IsOSAtLeast (WIN_10))
return TRUE;

// Strip quotation marks (if any)
if (path [0] == L'"')
{
Expand Down Expand Up @@ -3603,10 +3598,10 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine)

InitOSVersionInfo();

if (!IsOSAtLeast (WIN_7))
if (!IsOSAtLeast (WIN_10))
{
// abort using a message that says that VeraCrypt can run only on Windows 7 and later and that it is officially supported only on Windows 10 and later
AbortProcessDirect(L"VeraCrypt requires at least Windows 7 to run.");
// abort using a message that says that VeraCrypt can run only on Windows 10 and later
AbortProcessDirect(L"VeraCrypt requires at least Windows 10 to run.");
}

SetDefaultDllDirectoriesFn = (SetDefaultDllDirectoriesPtr) GetProcAddress (GetModuleHandle(L"kernel32.dll"), "SetDefaultDllDirectories");
Expand Down Expand Up @@ -6266,7 +6261,7 @@ static BOOL PerformBenchmark(HWND hBenchDlg, HWND hwndDlg)
*/
{
int thid, i;
char dk[MASTER_KEYDATA_SIZE];
unsigned char dk[MASTER_KEYDATA_SIZE];
char *tmp_salt = {"\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF\x01\x23\x45\x67\x89\xAB\xCD\xEF\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF\x01\x23\x45\x67\x89\xAB\xCD\xEF\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF"};

for (thid = FIRST_PRF_ID; thid <= LAST_PRF_ID; thid++)
Expand All @@ -6284,27 +6279,27 @@ static BOOL PerformBenchmark(HWND hBenchDlg, HWND hwndDlg)

case SHA512:
/* PKCS-5 test with HMAC-SHA-512 used as the PRF */
derive_key_sha512 ("passphrase-1234567890", 21, tmp_salt, 64, get_pkcs5_iteration_count(thid, benchmarkPim, benchmarkPreBoot), dk, MASTER_KEYDATA_SIZE);
derive_key_sha512 ((unsigned char*) "passphrase-1234567890", 21, (unsigned char*) tmp_salt, 64, get_pkcs5_iteration_count(thid, benchmarkPim, benchmarkPreBoot), dk, MASTER_KEYDATA_SIZE);
break;

case SHA256:
/* PKCS-5 test with HMAC-SHA-256 used as the PRF */
derive_key_sha256 ("passphrase-1234567890", 21, tmp_salt, 64, get_pkcs5_iteration_count(thid, benchmarkPim, benchmarkPreBoot), dk, MASTER_KEYDATA_SIZE);
derive_key_sha256 ((unsigned char*)"passphrase-1234567890", 21, (unsigned char*) tmp_salt, 64, get_pkcs5_iteration_count(thid, benchmarkPim, benchmarkPreBoot), dk, MASTER_KEYDATA_SIZE);
break;
#ifndef WOLFCRYPT_BACKEND
case BLAKE2S:
/* PKCS-5 test with HMAC-BLAKE2s used as the PRF */
derive_key_blake2s ("passphrase-1234567890", 21, tmp_salt, 64, get_pkcs5_iteration_count(thid, benchmarkPim, benchmarkPreBoot), dk, MASTER_KEYDATA_SIZE);
derive_key_blake2s ((unsigned char*)"passphrase-1234567890", 21, (unsigned char*) tmp_salt, 64, get_pkcs5_iteration_count(thid, benchmarkPim, benchmarkPreBoot), dk, MASTER_KEYDATA_SIZE);
break;

case WHIRLPOOL:
/* PKCS-5 test with HMAC-Whirlpool used as the PRF */
derive_key_whirlpool ("passphrase-1234567890", 21, tmp_salt, 64, get_pkcs5_iteration_count(thid, benchmarkPim, benchmarkPreBoot), dk, MASTER_KEYDATA_SIZE);
derive_key_whirlpool ((unsigned char*)"passphrase-1234567890", 21, (unsigned char*) tmp_salt, 64, get_pkcs5_iteration_count(thid, benchmarkPim, benchmarkPreBoot), dk, MASTER_KEYDATA_SIZE);
break;

case STREEBOG:
/* PKCS-5 test with HMAC-STREEBOG used as the PRF */
derive_key_streebog("passphrase-1234567890", 21, tmp_salt, 64, get_pkcs5_iteration_count(thid, benchmarkPim, benchmarkPreBoot), dk, MASTER_KEYDATA_SIZE);
derive_key_streebog((unsigned char*)"passphrase-1234567890", 21, (unsigned char*) tmp_salt, 64, get_pkcs5_iteration_count(thid, benchmarkPim, benchmarkPreBoot), dk, MASTER_KEYDATA_SIZE);
break;
}
#endif
Expand Down Expand Up @@ -7639,7 +7634,7 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
else
{

CipherInit2(idTestCipher, key, ks_tmp, ks);
CipherInit2(idTestCipher, key, ks_tmp);

if (bEncrypt)
{
Expand Down Expand Up @@ -11480,7 +11475,7 @@ int OpenVolume (OpenVolumeContext *context, const wchar_t *volumePath, Password
int volumeType;
wchar_t szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
wchar_t szDosDevice[TC_MAX_PATH];
char buffer[TC_VOLUME_HEADER_EFFECTIVE_SIZE];
unsigned char buffer[TC_VOLUME_HEADER_EFFECTIVE_SIZE];
LARGE_INTEGER headerOffset;
DWORD dwResult;
DISK_GEOMETRY_EX deviceGeometry;
Expand Down Expand Up @@ -11694,7 +11689,7 @@ void CloseVolume (OpenVolumeContext *context)
}


int ReEncryptVolumeHeader (HWND hwndDlg, char *buffer, BOOL bBoot, CRYPTO_INFO *cryptoInfo, Password *password, int pim, BOOL wipeMode)
int ReEncryptVolumeHeader (HWND hwndDlg, unsigned char *buffer, BOOL bBoot, CRYPTO_INFO *cryptoInfo, Password *password, int pim, BOOL wipeMode)
{
CRYPTO_INFO *newCryptoInfo = NULL;

Expand Down
2 changes: 1 addition & 1 deletion src/Common/Dlgcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ BOOL GetSysDevicePaths (HWND hwndDlg);
BOOL DoDriverInstall (HWND hwndDlg);
int OpenVolume (OpenVolumeContext *context, const wchar_t *volumePath, Password *password, int pkcs5_prf, int pim, BOOL write, BOOL preserveTimestamps, BOOL useBackupHeader);
void CloseVolume (OpenVolumeContext *context);
int ReEncryptVolumeHeader (HWND hwndDlg, char *buffer, BOOL bBoot, CRYPTO_INFO *cryptoInfo, Password *password, int pim, BOOL wipeMode);
int ReEncryptVolumeHeader (HWND hwndDlg, unsigned char *buffer, BOOL bBoot, CRYPTO_INFO *cryptoInfo, Password *password, int pim, BOOL wipeMode);
BOOL IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly);
BOOL IsPagingFileWildcardActive ();
BOOL DisablePagingFile ();
Expand Down
8 changes: 4 additions & 4 deletions src/Common/EncryptionThreadPool.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ typedef struct EncryptionThreadPoolWorkItemStruct
{
TC_EVENT *CompletionEvent;
LONG *CompletionFlag;
char *DerivedKey;
unsigned char *DerivedKey;
int IterationCount;
TC_EVENT *NoOutstandingWorkItemEvent;
LONG *OutstandingWorkItemCount;
char *Password;
unsigned char *Password;
int PasswordLength;
int Pkcs5Prf;
char *Salt;
unsigned char *Salt;

} KeyDerivation;

Expand Down Expand Up @@ -533,7 +533,7 @@ void EncryptionThreadPoolStop ()
}


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 EncryptionThreadPoolBeginKeyDerivation (TC_EVENT *completionEvent, TC_EVENT *noOutstandingWorkItemEvent, LONG *completionFlag, LONG *outstandingWorkItemCount, int pkcs5Prf, unsigned char *password, int passwordLength, unsigned char *salt, int iterationCount, unsigned char *derivedKey)
{
EncryptionThreadPoolWorkItem *workItem;

Expand Down
2 changes: 1 addition & 1 deletion src/Common/EncryptionThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ typedef enum
size_t GetCpuCount (WORD* pGroupCount);
#endif

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 EncryptionThreadPoolBeginKeyDerivation (TC_EVENT *completionEvent, TC_EVENT *noOutstandingWorkItemEvent, LONG *completionFlag, LONG *outstandingWorkItemCount, int pkcs5Prf, unsigned char *password, int passwordLength, unsigned char *salt, int iterationCount, unsigned char *derivedKey);
void EncryptionThreadPoolBeginReadVolumeHeaderFinalization (TC_EVENT *keyDerivationCompletedEvent, TC_EVENT *noOutstandingWorkItemEvent, LONG* outstandingWorkItemCount, void* keyInfoBuffer, int keyInfoBufferSize, void* keyDerivationWorkItems, int keyDerivationWorkItemsSize);
void EncryptionThreadPoolDoWork (EncryptionThreadPoolWorkType type, uint8 *data, const UINT64_STRUCT *startUnitNo, uint32 unitCount, PCRYPTO_INFO cryptoInfo);
BOOL EncryptionThreadPoolStart (size_t encryptionFreeCpuCount);
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Format.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int TCFormatVolume (volatile FORMAT_VOL_PARAMETERS *volParams)
PCRYPTO_INFO cryptoInfo = NULL;
HANDLE dev = INVALID_HANDLE_VALUE;
DWORD dwError;
char header[TC_VOLUME_HEADER_EFFECTIVE_SIZE];
unsigned char header[TC_VOLUME_HEADER_EFFECTIVE_SIZE];
unsigned __int64 num_sectors, startSector;
fatparams ft;
FILETIME ftCreationTime;
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Password.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ int ChangePwd (const wchar_t *lpszVolume, Password *oldPassword, int old_pkcs5,
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];
unsigned char buffer[TC_VOLUME_HEADER_EFFECTIVE_SIZE];
PCRYPTO_INFO cryptoInfo = NULL, ci = NULL;
void *dev = INVALID_HANDLE_VALUE;
DWORD dwError;
Expand Down
Loading

0 comments on commit cb97351

Please sign in to comment.