Annotation of truecrypt/boot/windows/bootencryptedio.cpp, revision 1.1.1.2

1.1       root        1: /*
                      2:  Copyright (c) 2008 TrueCrypt Foundation. All rights reserved.
                      3: 
                      4:  Governed by the TrueCrypt License 2.4 the full text of which is contained
                      5:  in the file License.txt included in TrueCrypt binary and source code
                      6:  distribution packages.
                      7: */
                      8: 
                      9: #include "Crypto.h"
                     10: #include "Platform.h"
                     11: #include "BootConfig.h"
                     12: #include "BootDebug.h"
1.1.1.2 ! root       13: #include "BootDefs.h"
1.1       root       14: #include "BootDiskIo.h"
                     15: #include "BootEncryptedIo.h"
                     16: 
                     17: 
                     18: BiosResult ReadEncryptedSectors (uint16 destSegment, uint16 destOffset, byte drive, uint64 sector, uint16 sectorCount)
                     19: {
                     20:        BiosResult result;
                     21: 
1.1.1.2 ! root       22:        result = ReadSectors (destSegment, destOffset, drive, sector, sectorCount);
1.1       root       23: 
1.1.1.2 ! root       24:        if (result != BiosResultSuccess)
        !            25:                return result;
1.1       root       26: 
1.1.1.2 ! root       27:        if (drive == EncryptedVirtualPartition.Drive)
        !            28:        {
        !            29:                while (sectorCount-- > 0)
1.1       root       30:                {
1.1.1.2 ! root       31:                        if (sector >= EncryptedVirtualPartition.StartSector && sector <= EncryptedVirtualPartition.EndSector)
        !            32:                        {
        !            33:                                AcquireSectorBuffer();
        !            34:                                CopyMemory (destSegment, destOffset, SectorBuffer, TC_LB_SIZE);
        !            35: 
        !            36:                                DecryptDataUnits (SectorBuffer, &sector, 1, BootCryptoInfo);
        !            37: 
        !            38:                                CopyMemory (SectorBuffer, destSegment, destOffset, TC_LB_SIZE);
        !            39:                                ReleaseSectorBuffer();
        !            40:                        }
1.1       root       41: 
1.1.1.2 ! root       42:                        ++sector;
        !            43:                        destOffset += TC_LB_SIZE;
        !            44:                }
1.1       root       45:        }
                     46: 
                     47:        return result;
                     48: }
                     49: 
                     50: 
                     51: BiosResult WriteEncryptedSectors (uint16 sourceSegment, uint16 sourceOffset, byte drive, uint64 sector, uint16 sectorCount)
                     52: {
                     53:        BiosResult result;
1.1.1.2 ! root       54:        AcquireSectorBuffer();
1.1       root       55: 
                     56:        while (sectorCount-- > 0)
                     57:        {
1.1.1.2 ! root       58:                CopyMemory (sourceSegment, sourceOffset, SectorBuffer, TC_LB_SIZE);
1.1       root       59: 
                     60:                if (drive == EncryptedVirtualPartition.Drive && sector >= EncryptedVirtualPartition.StartSector && sector <= EncryptedVirtualPartition.EndSector)
                     61:                {
1.1.1.2 ! root       62:                        EncryptDataUnits (SectorBuffer, &sector, 1, BootCryptoInfo);
1.1       root       63:                }
                     64: 
1.1.1.2 ! root       65:                result = WriteSectors (SectorBuffer, drive, sector, 1);
1.1       root       66: 
                     67:                if (result != BiosResultSuccess)
1.1.1.2 ! root       68:                        break;
1.1       root       69: 
                     70:                ++sector;
1.1.1.2 ! root       71:                sourceOffset += TC_LB_SIZE;
1.1       root       72:        }
                     73: 
1.1.1.2 ! root       74:        ReleaseSectorBuffer();
1.1       root       75:        return result;
                     76: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.