diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2016-05-10 22:34:27 +0200 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2016-05-10 22:34:27 +0200 |
commit | 268ef2d8e904db5068dbdc0fdc7ce3940d6452ea (patch) | |
tree | b1afa687c97fbf5e1ba2c92c5a10479ae5f832f5 /src/Boot/Windows/BootEncryptedIo.cpp | |
parent | 6d61f06a5348aebe7dbc0bf44d3e2729c20f7fd0 (diff) | |
parent | 5f47d8b6f11cdb3c4c2f43e04e5acfc6ffcb3035 (diff) | |
download | VeraCrypt-268ef2d8e904db5068dbdc0fdc7ce3940d6452ea.tar.gz VeraCrypt-268ef2d8e904db5068dbdc0fdc7ce3940d6452ea.zip |
Merge pull request #61 from davidfoerster/normalize-line-terminators
Normalize line terminators
Diffstat (limited to 'src/Boot/Windows/BootEncryptedIo.cpp')
-rw-r--r-- | src/Boot/Windows/BootEncryptedIo.cpp | 264 |
1 files changed, 132 insertions, 132 deletions
diff --git a/src/Boot/Windows/BootEncryptedIo.cpp b/src/Boot/Windows/BootEncryptedIo.cpp index d130534f..63fd0f47 100644 --- a/src/Boot/Windows/BootEncryptedIo.cpp +++ b/src/Boot/Windows/BootEncryptedIo.cpp @@ -1,132 +1,132 @@ -/*
- 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 "Crypto.h"
-#include "Platform.h"
-#include "BootConfig.h"
-#include "BootDebug.h"
-#include "BootDefs.h"
-#include "BootDiskIo.h"
-#include "BootEncryptedIo.h"
-
-
-BiosResult ReadEncryptedSectors (uint16 destSegment, uint16 destOffset, byte drive, uint64 sector, uint16 sectorCount)
-{
- BiosResult result;
- bool decrypt = true;
-
- if (BootCryptoInfo->hiddenVolume)
- {
- if (ReadWritePartiallyCoversEncryptedArea (sector, sectorCount))
- return BiosResultInvalidFunction;
-
- if (sector >= EncryptedVirtualPartition.StartSector && sector <= EncryptedVirtualPartition.EndSector)
- {
- // Remap the request to the hidden volume
- sector -= EncryptedVirtualPartition.StartSector;
- sector += HiddenVolumeStartSector;
- }
- else
- decrypt = false;
- }
-
- result = ReadSectors (destSegment, destOffset, drive, sector, sectorCount);
-
- if (result != BiosResultSuccess || !decrypt)
- return result;
-
- if (BootCryptoInfo->hiddenVolume)
- {
- // Convert sector number to data unit number of the hidden volume
- sector -= HiddenVolumeStartSector;
- sector += PimValueOrHiddenVolumeStartUnitNo;
- }
-
- if (drive == EncryptedVirtualPartition.Drive)
- {
- while (sectorCount-- > 0)
- {
- if (BootCryptoInfo->hiddenVolume
- || (sector >= EncryptedVirtualPartition.StartSector && sector <= EncryptedVirtualPartition.EndSector))
- {
- AcquireSectorBuffer();
- CopyMemory (destSegment, destOffset, SectorBuffer, TC_LB_SIZE);
-
- DecryptDataUnits (SectorBuffer, §or, 1, BootCryptoInfo);
-
- CopyMemory (SectorBuffer, destSegment, destOffset, TC_LB_SIZE);
- ReleaseSectorBuffer();
- }
-
- ++sector;
- destOffset += TC_LB_SIZE;
- }
- }
-
- return result;
-}
-
-
-BiosResult WriteEncryptedSectors (uint16 sourceSegment, uint16 sourceOffset, byte drive, uint64 sector, uint16 sectorCount)
-{
- BiosResult result = BiosResultSuccess;
- AcquireSectorBuffer();
- uint64 dataUnitNo;
- uint64 writeOffset;
-
- dataUnitNo = sector;
- writeOffset.HighPart = 0;
- writeOffset.LowPart = 0;
-
- if (BootCryptoInfo->hiddenVolume)
- {
- if (ReadWritePartiallyCoversEncryptedArea (sector, sectorCount))
- return BiosResultInvalidFunction;
-
- // Remap the request to the hidden volume
- writeOffset = HiddenVolumeStartSector;
- writeOffset -= EncryptedVirtualPartition.StartSector;
- dataUnitNo -= EncryptedVirtualPartition.StartSector;
- dataUnitNo += PimValueOrHiddenVolumeStartUnitNo;
- }
-
- while (sectorCount-- > 0)
- {
- CopyMemory (sourceSegment, sourceOffset, SectorBuffer, TC_LB_SIZE);
-
- if (drive == EncryptedVirtualPartition.Drive && sector >= EncryptedVirtualPartition.StartSector && sector <= EncryptedVirtualPartition.EndSector)
- {
- EncryptDataUnits (SectorBuffer, &dataUnitNo, 1, BootCryptoInfo);
- }
-
- result = WriteSectors (SectorBuffer, drive, sector + writeOffset, 1);
-
- if (result != BiosResultSuccess)
- break;
-
- ++sector;
- ++dataUnitNo;
- sourceOffset += TC_LB_SIZE;
- }
-
- ReleaseSectorBuffer();
- return result;
-}
-
-
-static bool ReadWritePartiallyCoversEncryptedArea (const uint64 §or, uint16 sectorCount)
-{
- uint64 readWriteEnd = sector + --sectorCount;
-
- return ((sector < EncryptedVirtualPartition.StartSector && readWriteEnd >= EncryptedVirtualPartition.StartSector)
- || (sector >= EncryptedVirtualPartition.StartSector && readWriteEnd > EncryptedVirtualPartition.EndSector));
-}
+/* + 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 "Crypto.h" +#include "Platform.h" +#include "BootConfig.h" +#include "BootDebug.h" +#include "BootDefs.h" +#include "BootDiskIo.h" +#include "BootEncryptedIo.h" + + +BiosResult ReadEncryptedSectors (uint16 destSegment, uint16 destOffset, byte drive, uint64 sector, uint16 sectorCount) +{ + BiosResult result; + bool decrypt = true; + + if (BootCryptoInfo->hiddenVolume) + { + if (ReadWritePartiallyCoversEncryptedArea (sector, sectorCount)) + return BiosResultInvalidFunction; + + if (sector >= EncryptedVirtualPartition.StartSector && sector <= EncryptedVirtualPartition.EndSector) + { + // Remap the request to the hidden volume + sector -= EncryptedVirtualPartition.StartSector; + sector += HiddenVolumeStartSector; + } + else + decrypt = false; + } + + result = ReadSectors (destSegment, destOffset, drive, sector, sectorCount); + + if (result != BiosResultSuccess || !decrypt) + return result; + + if (BootCryptoInfo->hiddenVolume) + { + // Convert sector number to data unit number of the hidden volume + sector -= HiddenVolumeStartSector; + sector += PimValueOrHiddenVolumeStartUnitNo; + } + + if (drive == EncryptedVirtualPartition.Drive) + { + while (sectorCount-- > 0) + { + if (BootCryptoInfo->hiddenVolume + || (sector >= EncryptedVirtualPartition.StartSector && sector <= EncryptedVirtualPartition.EndSector)) + { + AcquireSectorBuffer(); + CopyMemory (destSegment, destOffset, SectorBuffer, TC_LB_SIZE); + + DecryptDataUnits (SectorBuffer, §or, 1, BootCryptoInfo); + + CopyMemory (SectorBuffer, destSegment, destOffset, TC_LB_SIZE); + ReleaseSectorBuffer(); + } + + ++sector; + destOffset += TC_LB_SIZE; + } + } + + return result; +} + + +BiosResult WriteEncryptedSectors (uint16 sourceSegment, uint16 sourceOffset, byte drive, uint64 sector, uint16 sectorCount) +{ + BiosResult result = BiosResultSuccess; + AcquireSectorBuffer(); + uint64 dataUnitNo; + uint64 writeOffset; + + dataUnitNo = sector; + writeOffset.HighPart = 0; + writeOffset.LowPart = 0; + + if (BootCryptoInfo->hiddenVolume) + { + if (ReadWritePartiallyCoversEncryptedArea (sector, sectorCount)) + return BiosResultInvalidFunction; + + // Remap the request to the hidden volume + writeOffset = HiddenVolumeStartSector; + writeOffset -= EncryptedVirtualPartition.StartSector; + dataUnitNo -= EncryptedVirtualPartition.StartSector; + dataUnitNo += PimValueOrHiddenVolumeStartUnitNo; + } + + while (sectorCount-- > 0) + { + CopyMemory (sourceSegment, sourceOffset, SectorBuffer, TC_LB_SIZE); + + if (drive == EncryptedVirtualPartition.Drive && sector >= EncryptedVirtualPartition.StartSector && sector <= EncryptedVirtualPartition.EndSector) + { + EncryptDataUnits (SectorBuffer, &dataUnitNo, 1, BootCryptoInfo); + } + + result = WriteSectors (SectorBuffer, drive, sector + writeOffset, 1); + + if (result != BiosResultSuccess) + break; + + ++sector; + ++dataUnitNo; + sourceOffset += TC_LB_SIZE; + } + + ReleaseSectorBuffer(); + return result; +} + + +static bool ReadWritePartiallyCoversEncryptedArea (const uint64 §or, uint16 sectorCount) +{ + uint64 readWriteEnd = sector + --sectorCount; + + return ((sector < EncryptedVirtualPartition.StartSector && readWriteEnd >= EncryptedVirtualPartition.StartSector) + || (sector >= EncryptedVirtualPartition.StartSector && readWriteEnd > EncryptedVirtualPartition.EndSector)); +} |