VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Format/InPlace.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Format/InPlace.c')
-rw-r--r--src/Format/InPlace.c41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/Format/InPlace.c b/src/Format/InPlace.c
index b2f1b386..7117a8a4 100644
--- a/src/Format/InPlace.c
+++ b/src/Format/InPlace.c
@@ -869,6 +869,13 @@ int EncryptPartitionInPlaceResume (HANDLE dev,
if (nStatus != ERR_SUCCESS)
goto closing_seq;
+#ifdef _WIN64
+ if (IsRamEncryptionEnabled ())
+ {
+ VcProtectKeys (masterCryptoInfo, VcGetEncryptionID (masterCryptoInfo));
+ VcProtectKeys (headerCryptoInfo, VcGetEncryptionID (headerCryptoInfo));
+ }
+#endif
remainingBytes = masterCryptoInfo->VolumeSize.Value - masterCryptoInfo->EncryptedAreaLength.Value;
@@ -1389,6 +1396,13 @@ int DecryptPartitionInPlace (volatile FORMAT_VOL_PARAMETERS *volParams, volatile
if (nStatus != ERR_SUCCESS)
goto closing_seq;
+#ifdef _WIN64
+ if (IsRamEncryptionEnabled ())
+ {
+ VcProtectKeys (masterCryptoInfo, VcGetEncryptionID (masterCryptoInfo));
+ VcProtectKeys (headerCryptoInfo, VcGetEncryptionID (headerCryptoInfo));
+ }
+#endif
if (masterCryptoInfo->LegacyVolume)
{
@@ -1784,6 +1798,7 @@ int FastVolumeHeaderUpdate (HANDLE dev, CRYPTO_INFO *headerCryptoInfo, CRYPTO_IN
DWORD dwError;
uint32 headerCrc32;
byte *fieldPos;
+ PCRYPTO_INFO pCryptoInfo = headerCryptoInfo;
header = (byte *) TCalloc (TC_VOLUME_HEADER_EFFECTIVE_SIZE);
@@ -1804,8 +1819,23 @@ int FastVolumeHeaderUpdate (HANDLE dev, CRYPTO_INFO *headerCryptoInfo, CRYPTO_IN
goto closing_seq;
}
+#ifdef _WIN64
+ if (IsRamEncryptionEnabled())
+ {
+ pCryptoInfo = crypto_open();
+ if (!pCryptoInfo)
+ {
+ nStatus = ERR_OUTOFMEMORY;
+ goto closing_seq;
+ }
+
+ memcpy (pCryptoInfo, headerCryptoInfo, sizeof (CRYPTO_INFO));
+ VcUnprotectKeys (pCryptoInfo, VcGetEncryptionID (headerCryptoInfo));
+ }
+#endif
+
- DecryptBuffer (header + HEADER_ENCRYPTED_DATA_OFFSET, HEADER_ENCRYPTED_DATA_SIZE, headerCryptoInfo);
+ DecryptBuffer (header + HEADER_ENCRYPTED_DATA_OFFSET, HEADER_ENCRYPTED_DATA_SIZE, pCryptoInfo);
if (GetHeaderField32 (header, TC_HEADER_OFFSET_MAGIC) != 0x56455241)
{
@@ -1828,7 +1858,7 @@ int FastVolumeHeaderUpdate (HANDLE dev, CRYPTO_INFO *headerCryptoInfo, CRYPTO_IN
fieldPos = (byte *) header + TC_HEADER_OFFSET_HEADER_CRC;
mputLong (fieldPos, headerCrc32);
- EncryptBuffer (header + HEADER_ENCRYPTED_DATA_OFFSET, HEADER_ENCRYPTED_DATA_SIZE, headerCryptoInfo);
+ EncryptBuffer (header + HEADER_ENCRYPTED_DATA_OFFSET, HEADER_ENCRYPTED_DATA_SIZE, pCryptoInfo);
if (SetFilePointerEx (dev, offset, NULL, FILE_BEGIN) == 0
@@ -1843,6 +1873,13 @@ closing_seq:
dwError = GetLastError();
+#ifdef _WIN64
+ if (IsRamEncryptionEnabled() && pCryptoInfo)
+ {
+ crypto_close(pCryptoInfo);
+ }
+#endif
+
burn (header, TC_VOLUME_HEADER_EFFECTIVE_SIZE);
VirtualUnlock (header, TC_VOLUME_HEADER_EFFECTIVE_SIZE);
TCfree (header);