1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-11 19:08:26 -06:00

Windows: Fix regression in Expander and Format when RAM encryption is enable that was causing volume headers to be corrupted.

This commit is contained in:
Mounir IDRASSI
2020-01-22 11:46:37 +01:00
parent 56775af8d7
commit be1aee0034
5 changed files with 217 additions and 2 deletions

View File

@@ -1097,6 +1097,19 @@ inplace_enc_read:
{
PCRYPTO_INFO dummyInfo = NULL;
#ifdef _WIN64
CRYPTO_INFO tmpCI;
PCRYPTO_INFO cryptoInfoBackup = NULL;
if (IsRamEncryptionEnabled ())
{
VirtualLock (&tmpCI, sizeof(tmpCI));
memcpy (&tmpCI, masterCryptoInfo, sizeof (CRYPTO_INFO));
VcUnprotectKeys (&tmpCI, VcGetEncryptionID (masterCryptoInfo));
cryptoInfoBackup = masterCryptoInfo;
masterCryptoInfo = &tmpCI;
}
#endif
nStatus = CreateVolumeHeaderInMemory (hwndDlg, FALSE,
header,
headerCryptoInfo->ea,
@@ -1115,6 +1128,15 @@ inplace_enc_read:
masterCryptoInfo->SectorSize,
wipeAlgorithm == TC_WIPE_NONE ? FALSE : (wipePass < PRAND_HEADER_WIPE_PASSES - 1));
#ifdef _WIN64
if (IsRamEncryptionEnabled ())
{
masterCryptoInfo = cryptoInfoBackup;
burn (&tmpCI, sizeof (CRYPTO_INFO));
VirtualUnlock (&tmpCI, sizeof(tmpCI));
}
#endif
if (nStatus != ERR_SUCCESS)
goto closing_seq;
@@ -1128,9 +1150,28 @@ inplace_enc_read:
goto closing_seq;
}
#ifdef _WIN64
if (IsRamEncryptionEnabled ())
{
VirtualLock (&tmpCI, sizeof(tmpCI));
memcpy (&tmpCI, headerCryptoInfo, sizeof (CRYPTO_INFO));
VcUnprotectKeys (&tmpCI, VcGetEncryptionID (headerCryptoInfo));
cryptoInfoBackup = headerCryptoInfo;
headerCryptoInfo = &tmpCI;
}
#endif
// Fill the reserved sectors of the header area with random data
nStatus = WriteRandomDataToReservedHeaderAreas (hwndDlg, dev, headerCryptoInfo, masterCryptoInfo->VolumeSize.Value, TRUE, FALSE);
#ifdef _WIN64
if (IsRamEncryptionEnabled ())
{
headerCryptoInfo = cryptoInfoBackup;
burn (&tmpCI, sizeof (CRYPTO_INFO));
VirtualUnlock (&tmpCI, sizeof(tmpCI));
}
#endif
if (nStatus != ERR_SUCCESS)
goto closing_seq;