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

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 "Bios.h"
                     12: #include "BootConfig.h"
                     13: #include "BootDebug.h"
                     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:        byte sectorBuf[TC_LB_SIZE];
                     22: 
                     23:        while (sectorCount-- > 0)
                     24:        {
                     25:                result = ReadSectors (sectorBuf, drive, sector, 1);
                     26: 
                     27:                if (result != BiosResultSuccess)
                     28:                        return result;
                     29: 
                     30:                if (drive == EncryptedVirtualPartition.Drive && sector >= EncryptedVirtualPartition.StartSector && sector <= EncryptedVirtualPartition.EndSector)
                     31:                {
                     32:                        DecryptDataUnits (sectorBuf, &sector, 1, BootCryptoInfo);
                     33:                }
                     34: 
                     35:                CopyMemory (sectorBuf, destSegment, destOffset, sizeof (sectorBuf));
                     36: 
                     37:                ++sector;
                     38:                destOffset += sizeof (sectorBuf);
                     39:        }
                     40: 
                     41:        return result;
                     42: }
                     43: 
                     44: 
                     45: BiosResult WriteEncryptedSectors (uint16 sourceSegment, uint16 sourceOffset, byte drive, uint64 sector, uint16 sectorCount)
                     46: {
                     47:        BiosResult result;
                     48:        byte sectorBuf[TC_LB_SIZE];
                     49: 
                     50:        while (sectorCount-- > 0)
                     51:        {
                     52:                CopyMemory (sourceSegment, sourceOffset, sectorBuf, sizeof (sectorBuf));
                     53: 
                     54:                if (drive == EncryptedVirtualPartition.Drive && sector >= EncryptedVirtualPartition.StartSector && sector <= EncryptedVirtualPartition.EndSector)
                     55:                {
                     56:                        EncryptDataUnits (sectorBuf, &sector, 1, BootCryptoInfo);
                     57:                }
                     58: 
                     59:                result = WriteSectors (sectorBuf, drive, sector, 1);
                     60: 
                     61:                if (result != BiosResultSuccess)
                     62:                        return result;
                     63: 
                     64:                ++sector;
                     65:                sourceOffset += sizeof (sectorBuf);
                     66:        }
                     67: 
                     68:        return result;
                     69: }

unix.superglobalmegacorp.com

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