Skip to content

Commit

Permalink
TrueCrypt Source Version 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Truecrypt Foundation authored and FreeApophis committed May 29, 2014
1 parent ea0cb8c commit edcab0c
Show file tree
Hide file tree
Showing 129 changed files with 8,110 additions and 1,587 deletions.
4 changes: 1 addition & 3 deletions Boot/Windows/Bios.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "Platform.h"

#define TC_LB_SIZE 512
#define TC_LB_SIZE_BIT_SHIFT_DIVISOR 9

#define TC_FIRST_BIOS_DRIVE 0x80
Expand All @@ -20,8 +19,7 @@
enum
{
BiosResultSuccess = 0x00,
BiosResultInvalidFunction = 0x01,
BiosResultEccCorrected = 0x11
BiosResultInvalidFunction = 0x01
};

typedef byte BiosResult;
Expand Down
18 changes: 13 additions & 5 deletions Boot/Windows/Boot.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
BuildCommandLine="md Debug 2>NUL:
nmake.exe /nologo DEBUG=1"
ReBuildCommandLine="md Debug 2>NUL:
nmake.exe /nologo DEBUG=1 clean
nmake.exe /nologo DEBUG=1"
CleanCommandLine="nmake.exe /nologo DEBUG=1 clean"
Output="Debug\Boot.exe"
Output="Debug\BootLoader.exe"
PreprocessorDefinitions="WIN32;_DEBUG"
IncludeSearchPath=""$(SolutionDir)";"$(SolutionDir)\Common";"$(SolutionDir)\Crypto";"$(MSVC16_ROOT)\Include""
ForcedIncludes=""
Expand All @@ -43,10 +43,10 @@
>
<Tool
Name="VCNMakeTool"
BuildCommandLine="md Release 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1"
ReBuildCommandLine="md Release 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 clean&#x0D;&#x0A;nmake.exe /nologo RELEASE=1"
CleanCommandLine="nmake.exe /nologo RELEASE=1 clean"
Output="Release\Boot.com"
BuildCommandLine="md Release 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1&#x0D;&#x0A;&#x0D;&#x0A;md Release_AES 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES&#x0D;&#x0A;&#x0D;&#x0A;md Release_Serpent 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT&#x0D;&#x0A;&#x0D;&#x0A;md Release_Twofish 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH&#x0D;&#x0A;"
ReBuildCommandLine="del /q /s Release &gt;NUL:&#x0D;&#x0A;md Release 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_AES &gt;NUL:&#x0D;&#x0A;md Release_AES 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_Serpent &gt;NUL:&#x0D;&#x0A;md Release_Serpent 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_Twofish &gt;NUL:&#x0D;&#x0A;md Release_Twofish 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH&#x0D;&#x0A;"
CleanCommandLine="del /q /s Release Release_AES Release_Serpent Release_Twofish &gt;NUL:"
Output="Release\BootLoader.com"
PreprocessorDefinitions="WIN32;NDEBUG"
IncludeSearchPath="&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)\Common&quot;;&quot;$(SolutionDir)\Crypto&quot;;&quot;$(MSVC16_ROOT)\Include&quot;"
ForcedIncludes=""
Expand Down Expand Up @@ -100,6 +100,10 @@
RelativePath=".\BootSector.asm"
>
</File>
<File
RelativePath=".\Decompressor.c"
>
</File>
<File
RelativePath=".\IntFilter.cpp"
>
Expand Down Expand Up @@ -143,6 +147,10 @@
RelativePath="..\..\Crypto\AesSmall.c"
>
</File>
<File
RelativePath="..\..\Crypto\AesSmall_x86.asm"
>
</File>
<File
RelativePath="..\..\Crypto\Rmd160.c"
>
Expand Down
2 changes: 0 additions & 2 deletions Boot/Windows/BootCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#define TC_MBR_SECTOR 0
#define TC_MAX_MBR_BOOT_CODE_SIZE 440

#define TC_BOOT_CFG_FLAG_RESCUE_DISK 0x10
#define TC_BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER 0x20

#pragma pack (1)

Expand Down
2 changes: 1 addition & 1 deletion Boot/Windows/BootConsoleIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void EnableScreenOutput ()

void PrintChar (char c)
{
#ifdef TC_TRACING_ENABLED
#ifdef TC_BOOT_TRACING_ENABLED
WriteDebugPort (c);
#endif

Expand Down
5 changes: 2 additions & 3 deletions Boot/Windows/BootCrt.asm
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ INCLUDE BootDefs.i
EXTERNDEF main:NEAR

_TEXT SEGMENT
ORG TC_BOOT_LOADER_OFFSET
ORG TC_COM_EXECUTABLE_OFFSET

start:
call main
jmp $
jmp main

_TEXT ENDS
END start
64 changes: 50 additions & 14 deletions Boot/Windows/BootDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
#include "Platform.h"
#include "Bios.h"
#include "BootConsoleIo.h"
#include "BootDefs.h"
#include "BootDiskIo.h"
#include "BootDebug.h"


#ifdef TC_BOOT_TRACING_ENABLED

void InitDebugPort ()
{
__asm
Expand All @@ -38,6 +41,10 @@ void WriteDebugPort (byte dataByte)
}
}

#endif // TC_BOOT_TRACING_ENABLED


#ifdef TC_BOOT_DEBUG_ENABLED

extern "C" void PrintDebug (uint32 debugVal)
{
Expand All @@ -46,20 +53,6 @@ extern "C" void PrintDebug (uint32 debugVal)
}


void PrintAddress (void *addr)
{
uint16 segment = uint16 (uint32 (addr) >> 16);
uint16 offset = uint16 (addr);

PrintHex (segment);
PrintChar (':');
PrintHex (offset);
Print (" (");
PrintHex (GetLinearAddress (segment, offset));
Print (")");
}


void PrintVal (const char *message, const uint32 value, bool newLine, bool hex)
{
Print (message);
Expand Down Expand Up @@ -139,3 +132,46 @@ void PrintHexDump (uint16 memSegment, uint16 memOffset, size_t size)
{
PrintHexDump ((byte *) memOffset, size, &memSegment);
}

#endif // TC_BOOT_DEBUG_ENABLED


#ifdef TC_BOOT_STACK_CHECKING_ENABLED

extern "C" char end[];

static void PrintStackInfo ()
{
uint16 spReg;
__asm mov spReg, sp

Print ("Stack: "); Print (TC_BOOT_LOADER_STACK_TOP - spReg);
Print ("/"); Print (TC_BOOT_LOADER_STACK_TOP - (uint16) end);
}


void CheckStack ()
{
uint16 spReg;
__asm mov spReg, sp

if (*(uint32 *) end != 0x12345678UL || spReg < (uint16) end)
{
__asm cli
__asm mov sp, TC_BOOT_LOADER_STACK_TOP

PrintError ("Stack overflow");
TC_THROW_FATAL_EXCEPTION;
}
}


void InitStackChecker ()
{
*(uint32 *) end = 0x12345678UL;

PrintStackInfo();
PrintEndl();
}

#endif // TC_BOOT_STACK_CHECKING_ENABLED
20 changes: 12 additions & 8 deletions Boot/Windows/BootDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@
#include "Platform.h"
#include "BootConsoleIo.h"

#if 0
# define TC_BOOT_DEBUG_ENABLED
#endif

#ifndef DEBUG
# if 0
# define TC_TRACING_ENABLED
# endif
#if 0 || defined (TC_BOOT_DEBUG_ENABLED)
# define TC_BOOT_STACK_CHECKING_ENABLED
extern "C" void CheckStack ();
#else
# define CheckStack()
#endif

#ifdef TC_TRACING_ENABLED
#if 0
# define TC_BOOT_TRACING_ENABLED
# if 1
# define TC_TRACE_INT13
# endif
Expand All @@ -34,13 +39,12 @@
#define trace_hex(VAL) do { Print (#VAL), PrintChar (':'); PrintHex (VAL); PrintEndl(); } while (false)
#define assert(COND) do { if (!(COND)) { trace_point; __asm jmp $ } } while (false)


void InitDebugPort ();
void InitStackChecker ();
void WriteDebugPort (byte dataByte);
void PrintAddress (void *addr);
void PrintHexDump (byte *mem, size_t size, uint16 *memSegment = nullptr);
void PrintHexDump (uint16 memSegment, uint16 memOffset, size_t size);
void PrintVal (const char *message, const uint32 value, bool newLine = true, bool hex = false);
void PrintVal (const char *message, const uint64 &value, bool newLine = true, bool hex = false);

#endif TC_HEADER_Boot_BootDebug
#endif // TC_HEADER_Boot_BootDebug
91 changes: 84 additions & 7 deletions Boot/Windows/BootDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,121 @@
distribution packages.
*/

#ifndef TC_HEADER_Boot_BootDefs
#define TC_HEADER_Boot_BootDefs

// Total memory required (CODE + DATA + BSS + STACK + 0x100) in KBytes - determined from linker map.
#define TC__BOOT_MEMORY_REQUIRED 42

#ifdef TC_WINDOWS_BOOT_SINGLE_CIPHER_MODE
# undef TC__BOOT_MEMORY_REQUIRED

# ifdef TC_WINDOWS_BOOT_AES
# define TC__BOOT_MEMORY_REQUIRED 27
# elif defined (TC_WINDOWS_BOOT_SERPENT)
# define TC__BOOT_MEMORY_REQUIRED 32
# elif defined (TC_WINDOWS_BOOT_TWOFISH)
# define TC__BOOT_MEMORY_REQUIRED 40
# endif

#endif

// Windows Vista boot loader uses memory up to 8000:FFFF, disregarding the BIOS memory map and the amount
// of available memory at 0:0413. Therefore, the code has to be loaded at or above 9000:0000.
// of available memory at 40:0013. Therefore, the code has to be loaded at or above 9000:0000.

// Modifying this value can introduce incompatibility with previous versions
#define TC__BOOT_LOADER_SEGMENT TC_HEX (9000)
#define TC__BOOT_LOADER_OFFSET TC_HEX (100) // COM executable offset
#define TC__BOOT_LOADER_SEGMENT TC_HEX (9000)
#define TC__COM_EXECUTABLE_OFFSET TC_HEX (100)

#define TC__BOOT_LOADER_LOWMEM_SEGMENT TC_HEX (2000)
#define TC__BOOT_LOADER_BUFFER_SEGMENT TC_HEX (5000)

#define TC__BOOT_LOADER_LOWMEM_SEGMENT TC_HEX (2000)
#define TC__BOOT_LOADER_BUFFER_SEGMENT TC_HEX (5000)
#define TC__BOOT_LOADER_STACK_TOP (TC_BOOT_MEMORY_REQUIRED * TC_UNSIGNED (1024) - 4)

#define TC__LB_SIZE 512
#define TC__BOOT_LOADER_AREA_SECTOR_COUNT 63

#define TC__BOOT_SECTOR_LOADER_LENGTH_OFFSET 432
#define TC__BOOT_SECTOR_LOADER_CHECKSUM_OFFSET 434
#define TC__BOOT_SECTOR_CONFIG_OFFSET 439 // Last byte reserved for boot loader

#define TC__BOOT_LOADER_DECOMPRESSOR_START_SECTOR 2
#define TC__BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT 4
#define TC__BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE 32768
#define TC__BOOT_LOADER_COMPRESSED_BUFFER_OFFSET (TC_COM_EXECUTABLE_OFFSET + 3072)

#define TC__BOOT_LOADER_START_SECTOR (TC_BOOT_LOADER_DECOMPRESSOR_START_SECTOR + TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT)
#define TC__MAX_BOOT_LOADER_SECTOR_COUNT (TC_BOOT_LOADER_AREA_SECTOR_COUNT - TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT - 2)
#define TC__MAX_BOOT_LOADER_DECOMPRESSED_SIZE ((TC_BOOT_LOADER_AREA_SECTOR_COUNT - 2) * TC_LB_SIZE)

#define TC__BOOT_LOADER_BACKUP_SECTOR_COUNT 30

#define TC__GZIP_HEADER_SIZE 10

#define TC__BOOT_CFG_FLAG_BACKUP_LOADER_AVAILABLE TC_HEX (02)
#define TC__BOOT_CFG_FLAG_WINDOWS_VISTA_OR_LATER TC_HEX (04)
#define TC__BOOT_CFG_FLAG_RESCUE_DISK TC_HEX (10)
#define TC__BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER TC_HEX (20)


#ifdef TC_ASM_PREPROCESS

#define TC_HEX(N) 0##N##h
#define TC_UNSIGNED(N) N

TC_BOOT_MEMORY_REQUIRED = TC__BOOT_MEMORY_REQUIRED
TC_BOOT_LOADER_SEGMENT = TC__BOOT_LOADER_SEGMENT
TC_BOOT_LOADER_OFFSET = TC__BOOT_LOADER_OFFSET
TC_COM_EXECUTABLE_OFFSET = TC__COM_EXECUTABLE_OFFSET
TC_BOOT_LOADER_LOWMEM_SEGMENT = TC__BOOT_LOADER_LOWMEM_SEGMENT
TC_BOOT_LOADER_BUFFER_SEGMENT = TC__BOOT_LOADER_BUFFER_SEGMENT
TC_BOOT_LOADER_STACK_TOP = TC__BOOT_LOADER_STACK_TOP
TC_LB_SIZE = TC__LB_SIZE
TC_BOOT_LOADER_AREA_SECTOR_COUNT = TC__BOOT_LOADER_AREA_SECTOR_COUNT
TC_BOOT_SECTOR_LOADER_LENGTH_OFFSET = TC__BOOT_SECTOR_LOADER_LENGTH_OFFSET
TC_BOOT_SECTOR_LOADER_CHECKSUM_OFFSET = TC__BOOT_SECTOR_LOADER_CHECKSUM_OFFSET
TC_BOOT_SECTOR_CONFIG_OFFSET = TC__BOOT_SECTOR_CONFIG_OFFSET
TC_BOOT_LOADER_DECOMPRESSOR_START_SECTOR = TC__BOOT_LOADER_DECOMPRESSOR_START_SECTOR
TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT = TC__BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT
TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE = TC__BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE
TC_BOOT_LOADER_COMPRESSED_BUFFER_OFFSET = TC__BOOT_LOADER_COMPRESSED_BUFFER_OFFSET
TC_BOOT_LOADER_START_SECTOR = TC__BOOT_LOADER_START_SECTOR
TC_MAX_BOOT_LOADER_SECTOR_COUNT = TC__MAX_BOOT_LOADER_SECTOR_COUNT
TC_MAX_BOOT_LOADER_DECOMPRESSED_SIZE = TC__MAX_BOOT_LOADER_DECOMPRESSED_SIZE
TC_BOOT_LOADER_BACKUP_SECTOR_COUNT = TC__BOOT_LOADER_BACKUP_SECTOR_COUNT
TC_GZIP_HEADER_SIZE = TC__GZIP_HEADER_SIZE
TC_BOOT_CFG_FLAG_BACKUP_LOADER_AVAILABLE = TC__BOOT_CFG_FLAG_BACKUP_LOADER_AVAILABLE
TC_BOOT_CFG_FLAG_WINDOWS_VISTA_OR_LATER = TC__BOOT_CFG_FLAG_WINDOWS_VISTA_OR_LATER
TC_BOOT_CFG_FLAG_RESCUE_DISK = TC__BOOT_CFG_FLAG_RESCUE_DISK
TC_BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER = TC__BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER

#else

#define TC_HEX(N) 0x##N
#define TC_UNSIGNED(N) N##U

#define TC_BOOT_MEMORY_REQUIRED TC__BOOT_MEMORY_REQUIRED
#define TC_BOOT_LOADER_SEGMENT TC__BOOT_LOADER_SEGMENT
#define TC_BOOT_LOADER_OFFSET TC__BOOT_LOADER_OFFSET
#define TC_COM_EXECUTABLE_OFFSET TC__COM_EXECUTABLE_OFFSET
#define TC_BOOT_LOADER_LOWMEM_SEGMENT TC__BOOT_LOADER_LOWMEM_SEGMENT
#define TC_BOOT_LOADER_BUFFER_SEGMENT TC__BOOT_LOADER_BUFFER_SEGMENT
#define TC_BOOT_LOADER_STACK_TOP (TC__BOOT_LOADER_STACK_TOP)
#define TC_BOOT_LOADER_AREA_SECTOR_COUNT TC__BOOT_LOADER_AREA_SECTOR_COUNT
#define TC_BOOT_SECTOR_LOADER_LENGTH_OFFSET TC__BOOT_SECTOR_LOADER_LENGTH_OFFSET
#define TC_BOOT_SECTOR_LOADER_CHECKSUM_OFFSET TC__BOOT_SECTOR_LOADER_CHECKSUM_OFFSET
#define TC_BOOT_LOADER_DECOMPRESSOR_START_SECTOR TC__BOOT_LOADER_DECOMPRESSOR_START_SECTOR
#define TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT TC__BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT
#define TC_BOOT_SECTOR_CONFIG_OFFSET TC__BOOT_SECTOR_CONFIG_OFFSET
#define TC_BOOT_LOADER_START_SECTOR TC__BOOT_LOADER_START_SECTOR
#define TC_LB_SIZE TC__LB_SIZE
#define TC_MAX_BOOT_LOADER_SECTOR_COUNT TC__MAX_BOOT_LOADER_SECTOR_COUNT
#define TC_MAX_BOOT_LOADER_DECOMPRESSED_SIZE TC__MAX_BOOT_LOADER_DECOMPRESSED_SIZE
#define TC_BOOT_LOADER_BACKUP_SECTOR_COUNT TC__BOOT_LOADER_BACKUP_SECTOR_COUNT
#define TC_GZIP_HEADER_SIZE TC__GZIP_HEADER_SIZE
#define TC_BOOT_CFG_FLAG_BACKUP_LOADER_AVAILABLE TC__BOOT_CFG_FLAG_BACKUP_LOADER_AVAILABLE
#define TC_BOOT_CFG_FLAG_WINDOWS_VISTA_OR_LATER TC__BOOT_CFG_FLAG_WINDOWS_VISTA_OR_LATER
#define TC_BOOT_CFG_FLAG_RESCUE_DISK TC__BOOT_CFG_FLAG_RESCUE_DISK
#define TC_BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER TC__BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER

#endif

#endif // TC_HEADER_Boot_BootDefs
Loading

0 comments on commit edcab0c

Please sign in to comment.