mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 11:08:02 -06:00
Normalize all line terminators
This commit is contained in:
@@ -1,32 +1,32 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Boot_Bios
|
||||
#define TC_HEADER_Boot_Bios
|
||||
|
||||
#include "Platform.h"
|
||||
|
||||
#define TC_LB_SIZE_BIT_SHIFT_DIVISOR 9
|
||||
|
||||
#define TC_FIRST_BIOS_DRIVE 0x80
|
||||
#define TC_LAST_BIOS_DRIVE 0x8f
|
||||
#define TC_INVALID_BIOS_DRIVE (TC_FIRST_BIOS_DRIVE - 1)
|
||||
|
||||
enum
|
||||
{
|
||||
BiosResultSuccess = 0x00,
|
||||
BiosResultInvalidFunction = 0x01
|
||||
};
|
||||
|
||||
typedef byte BiosResult;
|
||||
|
||||
#endif // TC_HEADER_Boot_Bios
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Boot_Bios
|
||||
#define TC_HEADER_Boot_Bios
|
||||
|
||||
#include "Platform.h"
|
||||
|
||||
#define TC_LB_SIZE_BIT_SHIFT_DIVISOR 9
|
||||
|
||||
#define TC_FIRST_BIOS_DRIVE 0x80
|
||||
#define TC_LAST_BIOS_DRIVE 0x8f
|
||||
#define TC_INVALID_BIOS_DRIVE (TC_FIRST_BIOS_DRIVE - 1)
|
||||
|
||||
enum
|
||||
{
|
||||
BiosResultSuccess = 0x00,
|
||||
BiosResultInvalidFunction = 0x01
|
||||
};
|
||||
|
||||
typedef byte BiosResult;
|
||||
|
||||
#endif // TC_HEADER_Boot_Bios
|
||||
|
||||
@@ -1,246 +1,246 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Name="Boot"
|
||||
ProjectGUID="{8B7F059F-E4C7-4E11-88F5-EE8B8433072E}"
|
||||
RootNamespace="Boot"
|
||||
Keyword="MakeFileProj"
|
||||
TargetFrameworkVersion="131072"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="0"
|
||||
>
|
||||
<Tool
|
||||
Name="VCNMakeTool"
|
||||
BuildCommandLine="md Release 2>NUL:
nmake.exe /nologo RELEASE=1

md Release_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_PRF=SHA2

md Release_AES 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES

md Release_AES_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES SINGLE_PRF=SHA2

md Release_Serpent 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT

md Release_Serpent_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT SINGLE_PRF=SHA2

md Release_Twofish 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH

md Release_Twofish_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH SINGLE_PRF=SHA2

md Rescue 2>NUL:
nmake.exe /nologo RELEASE=1 RESCUE_DISK=1

md Rescue_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 RESCUE_DISK=1 SINGLE_PRF=SHA2

md Rescue_AES 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES RESCUE_DISK=1

md Rescue_AES_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES RESCUE_DISK=1 SINGLE_PRF=SHA2

md Rescue_Serpent 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT RESCUE_DISK=1

md Rescue_Serpent_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT RESCUE_DISK=1 SINGLE_PRF=SHA2

md Rescue_Twofish 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH RESCUE_DISK=1

md Rescue_Twofish_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH RESCUE_DISK=1 SINGLE_PRF=SHA2"
|
||||
ReBuildCommandLine="del /q /s Release >NUL:
md Release 2>NUL:
nmake.exe /nologo RELEASE=1

del /q /s Release_SHA2 >NUL:
md Release_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_PRF=SHA2

del /q /s Release_AES >NUL:
md Release_AES 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES

del /q /s Release_AES_SHA2 >NUL:
md Release_AES_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES SINGLE_PRF=SHA2

del /q /s Release_Serpent >NUL:
md Release_Serpent 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT

del /q /s Release_Serpent_SHA2 >NUL:
md Release_Serpent_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT SINGLE_PRF=SHA2

del /q /s Release_Twofish >NUL:
md Release_Twofish 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH

del /q /s Release_Twofish_SHA2 >NUL:
md Release_Twofish_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH SINGLE_PRF=SHA2

del /q /s Rescue >NUL:
md Rescue 2>NUL:
nmake.exe /nologo RELEASE=1 RESCUE_DISK=1

del /q /s Rescue_SHA2 >NUL:
md Rescue_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 RESCUE_DISK=1 SINGLE_PRF=SHA2

del /q /s Rescue_AES >NUL:
md Rescue_AES 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES RESCUE_DISK=1

del /q /s Rescue_AES_SHA2 >NUL:
md Rescue_AES_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES RESCUE_DISK=1 SINGLE_PRF=SHA2

del /q /s Rescue_Serpent >NUL:
md Rescue_Serpent 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT RESCUE_DISK=1

del /q /s Rescue_Serpent_SHA2 >NUL:
md Rescue_Serpent_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT RESCUE_DISK=1 SINGLE_PRF=SHA2

del /q /s Rescue_Twofish >NUL:
md Rescue_Twofish 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH RESCUE_DISK=1

del /q /s Rescue_Twofish_SHA2 >NUL:
md Rescue_Twofish_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH RESCUE_DISK=1 SINGLE_PRF=SHA2"
|
||||
CleanCommandLine="del /q /s Release Release_AES Release_Serpent Release_Twofish Rescue Rescue_AES Rescue_Serpent Rescue_Twofish >NUL:
del /q /s Release_SHA2 Release_AES_SHA2 Release_Serpent_SHA2 Release_Twofish_SHA2 Rescue_SHA2 Rescue_AES_SHA2 Rescue_Serpent_SHA2 Rescue_Twofish_SHA2 >NUL:
"
|
||||
Output="Release\BootLoader.com"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG"
|
||||
IncludeSearchPath=""$(SolutionDir)";"$(SolutionDir)\Common";"$(SolutionDir)\Crypto";"$(MSVC16_ROOT)\Include""
|
||||
ForcedIncludes=""
|
||||
AssemblySearchPath=""
|
||||
ForcedUsingAssemblies=""
|
||||
CompileAsManaged=""
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release Loader|Win32"
|
||||
OutputDirectory="$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="0"
|
||||
>
|
||||
<Tool
|
||||
Name="VCNMakeTool"
|
||||
BuildCommandLine="md Release 2>NUL:
nmake.exe /nologo RELEASE=1

md Release_AES 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES

md Release_Serpent 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT

md Release_Twofish 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH"
|
||||
ReBuildCommandLine="del /q /s Release >NUL:
md Release 2>NUL:
nmake.exe /nologo RELEASE=1

del /q /s Release_AES >NUL:
md Release_AES 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES

del /q /s Release_Serpent >NUL:
md Release_Serpent 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT

del /q /s Release_Twofish >NUL:
md Release_Twofish 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH"
|
||||
CleanCommandLine="del /q /s Release Release_AES Release_Serpent Release_Twofish >NUL:"
|
||||
Output="Release\BootLoader.com"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG"
|
||||
IncludeSearchPath=""$(SolutionDir)";"$(SolutionDir)\Common";"$(SolutionDir)\Crypto";"$(MSVC16_ROOT)\Include""
|
||||
ForcedIncludes=""
|
||||
AssemblySearchPath=""
|
||||
ForcedUsingAssemblies=""
|
||||
CompileAsManaged=""
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\BootConfig.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootConsoleIo.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootCrt.asm"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootDebug.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootDiskIo.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootEncryptedIo.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootMain.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootMemory.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootSector.asm"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Decompressor.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\IntFilter.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Platform.cpp"
|
||||
>
|
||||
</File>
|
||||
<Filter
|
||||
Name="Common"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\Common\Crc.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Common\Crypto.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Common\Endian.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Common\Pkcs5.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Common\Volumes.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Common\Xts.c"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Crypto"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\Crypto\Aes_hw_cpu.asm"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Crypto\AesSmall.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Crypto\AesSmall_x86.asm"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Crypto\Rmd160.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Crypto\Serpent.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Crypto\Sha2Small.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Crypto\Twofish.c"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Bios.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootCommon.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootConfig.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootConsoleIo.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootDebug.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootDefs.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootDiskIo.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootEncryptedIo.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootMain.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootMemory.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootStrings.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\IntFilter.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Platform.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Build Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Makefile"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Name="Boot"
|
||||
ProjectGUID="{8B7F059F-E4C7-4E11-88F5-EE8B8433072E}"
|
||||
RootNamespace="Boot"
|
||||
Keyword="MakeFileProj"
|
||||
TargetFrameworkVersion="131072"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="0"
|
||||
>
|
||||
<Tool
|
||||
Name="VCNMakeTool"
|
||||
BuildCommandLine="md Release 2>NUL:
nmake.exe /nologo RELEASE=1

md Release_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_PRF=SHA2

md Release_AES 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES

md Release_AES_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES SINGLE_PRF=SHA2

md Release_Serpent 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT

md Release_Serpent_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT SINGLE_PRF=SHA2

md Release_Twofish 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH

md Release_Twofish_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH SINGLE_PRF=SHA2

md Rescue 2>NUL:
nmake.exe /nologo RELEASE=1 RESCUE_DISK=1

md Rescue_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 RESCUE_DISK=1 SINGLE_PRF=SHA2

md Rescue_AES 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES RESCUE_DISK=1

md Rescue_AES_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES RESCUE_DISK=1 SINGLE_PRF=SHA2

md Rescue_Serpent 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT RESCUE_DISK=1

md Rescue_Serpent_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT RESCUE_DISK=1 SINGLE_PRF=SHA2

md Rescue_Twofish 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH RESCUE_DISK=1

md Rescue_Twofish_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH RESCUE_DISK=1 SINGLE_PRF=SHA2"
|
||||
ReBuildCommandLine="del /q /s Release >NUL:
md Release 2>NUL:
nmake.exe /nologo RELEASE=1

del /q /s Release_SHA2 >NUL:
md Release_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_PRF=SHA2

del /q /s Release_AES >NUL:
md Release_AES 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES

del /q /s Release_AES_SHA2 >NUL:
md Release_AES_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES SINGLE_PRF=SHA2

del /q /s Release_Serpent >NUL:
md Release_Serpent 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT

del /q /s Release_Serpent_SHA2 >NUL:
md Release_Serpent_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT SINGLE_PRF=SHA2

del /q /s Release_Twofish >NUL:
md Release_Twofish 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH

del /q /s Release_Twofish_SHA2 >NUL:
md Release_Twofish_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH SINGLE_PRF=SHA2

del /q /s Rescue >NUL:
md Rescue 2>NUL:
nmake.exe /nologo RELEASE=1 RESCUE_DISK=1

del /q /s Rescue_SHA2 >NUL:
md Rescue_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 RESCUE_DISK=1 SINGLE_PRF=SHA2

del /q /s Rescue_AES >NUL:
md Rescue_AES 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES RESCUE_DISK=1

del /q /s Rescue_AES_SHA2 >NUL:
md Rescue_AES_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES RESCUE_DISK=1 SINGLE_PRF=SHA2

del /q /s Rescue_Serpent >NUL:
md Rescue_Serpent 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT RESCUE_DISK=1

del /q /s Rescue_Serpent_SHA2 >NUL:
md Rescue_Serpent_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT RESCUE_DISK=1 SINGLE_PRF=SHA2

del /q /s Rescue_Twofish >NUL:
md Rescue_Twofish 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH RESCUE_DISK=1

del /q /s Rescue_Twofish_SHA2 >NUL:
md Rescue_Twofish_SHA2 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH RESCUE_DISK=1 SINGLE_PRF=SHA2"
|
||||
CleanCommandLine="del /q /s Release Release_AES Release_Serpent Release_Twofish Rescue Rescue_AES Rescue_Serpent Rescue_Twofish >NUL:
del /q /s Release_SHA2 Release_AES_SHA2 Release_Serpent_SHA2 Release_Twofish_SHA2 Rescue_SHA2 Rescue_AES_SHA2 Rescue_Serpent_SHA2 Rescue_Twofish_SHA2 >NUL:
"
|
||||
Output="Release\BootLoader.com"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG"
|
||||
IncludeSearchPath=""$(SolutionDir)";"$(SolutionDir)\Common";"$(SolutionDir)\Crypto";"$(MSVC16_ROOT)\Include""
|
||||
ForcedIncludes=""
|
||||
AssemblySearchPath=""
|
||||
ForcedUsingAssemblies=""
|
||||
CompileAsManaged=""
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release Loader|Win32"
|
||||
OutputDirectory="$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="0"
|
||||
>
|
||||
<Tool
|
||||
Name="VCNMakeTool"
|
||||
BuildCommandLine="md Release 2>NUL:
nmake.exe /nologo RELEASE=1

md Release_AES 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES

md Release_Serpent 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT

md Release_Twofish 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH"
|
||||
ReBuildCommandLine="del /q /s Release >NUL:
md Release 2>NUL:
nmake.exe /nologo RELEASE=1

del /q /s Release_AES >NUL:
md Release_AES 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES

del /q /s Release_Serpent >NUL:
md Release_Serpent 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT

del /q /s Release_Twofish >NUL:
md Release_Twofish 2>NUL:
nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH"
|
||||
CleanCommandLine="del /q /s Release Release_AES Release_Serpent Release_Twofish >NUL:"
|
||||
Output="Release\BootLoader.com"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG"
|
||||
IncludeSearchPath=""$(SolutionDir)";"$(SolutionDir)\Common";"$(SolutionDir)\Crypto";"$(MSVC16_ROOT)\Include""
|
||||
ForcedIncludes=""
|
||||
AssemblySearchPath=""
|
||||
ForcedUsingAssemblies=""
|
||||
CompileAsManaged=""
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\BootConfig.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootConsoleIo.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootCrt.asm"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootDebug.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootDiskIo.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootEncryptedIo.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootMain.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootMemory.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootSector.asm"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Decompressor.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\IntFilter.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Platform.cpp"
|
||||
>
|
||||
</File>
|
||||
<Filter
|
||||
Name="Common"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\Common\Crc.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Common\Crypto.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Common\Endian.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Common\Pkcs5.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Common\Volumes.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Common\Xts.c"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Crypto"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\Crypto\Aes_hw_cpu.asm"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Crypto\AesSmall.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Crypto\AesSmall_x86.asm"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Crypto\Rmd160.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Crypto\Serpent.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Crypto\Sha2Small.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Crypto\Twofish.c"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Bios.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootCommon.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootConfig.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootConsoleIo.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootDebug.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootDefs.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootDiskIo.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootEncryptedIo.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootMain.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootMemory.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\BootStrings.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\IntFilter.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Platform.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Build Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Makefile"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
|
||||
@@ -1,82 +1,82 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Boot_BootCommon
|
||||
#define TC_HEADER_Boot_BootCommon
|
||||
|
||||
#include "Common/Password.h"
|
||||
#include "BootDefs.h"
|
||||
|
||||
// The user will be advised to upgrade the rescue disk if upgrading from the following or any previous version
|
||||
#define TC_RESCUE_DISK_UPGRADE_NOTICE_MAX_VERSION 0x0117
|
||||
|
||||
#define TC_BOOT_LOADER_AREA_SIZE (TC_BOOT_LOADER_AREA_SECTOR_COUNT * TC_SECTOR_SIZE_BIOS)
|
||||
|
||||
#define TC_BOOT_VOLUME_HEADER_SECTOR (TC_BOOT_LOADER_AREA_SECTOR_COUNT - 1)
|
||||
#define TC_BOOT_VOLUME_HEADER_SECTOR_OFFSET (TC_BOOT_VOLUME_HEADER_SECTOR * TC_SECTOR_SIZE_BIOS)
|
||||
|
||||
#define TC_CD_BOOTSECTOR_OFFSET 0xd000
|
||||
#define TC_CD_BOOT_LOADER_SECTOR 26
|
||||
|
||||
#define TC_ORIG_BOOT_LOADER_BACKUP_SECTOR TC_BOOT_LOADER_AREA_SECTOR_COUNT
|
||||
#define TC_ORIG_BOOT_LOADER_BACKUP_SECTOR_OFFSET (TC_ORIG_BOOT_LOADER_BACKUP_SECTOR * TC_SECTOR_SIZE_BIOS)
|
||||
|
||||
#define TC_BOOT_LOADER_BACKUP_RESCUE_DISK_SECTOR (TC_ORIG_BOOT_LOADER_BACKUP_SECTOR + TC_BOOT_LOADER_AREA_SECTOR_COUNT)
|
||||
#define TC_BOOT_LOADER_BACKUP_RESCUE_DISK_SECTOR_OFFSET (TC_BOOT_LOADER_BACKUP_RESCUE_DISK_SECTOR * TC_SECTOR_SIZE_BIOS)
|
||||
|
||||
#define TC_MBR_SECTOR 0
|
||||
#define TC_MAX_MBR_BOOT_CODE_SIZE 440
|
||||
|
||||
#define TC_MAX_EXTRA_BOOT_PARTITION_SIZE (512UL * 1024UL * 1024UL)
|
||||
|
||||
|
||||
#pragma pack (1)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
byte Flags;
|
||||
} BootSectorConfiguration;
|
||||
|
||||
|
||||
// Modifying this value can introduce incompatibility with previous versions
|
||||
#define TC_BOOT_LOADER_ARGS_OFFSET 0x10
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// Modifying this structure can introduce incompatibility with previous versions
|
||||
char Signature[8];
|
||||
uint16 BootLoaderVersion;
|
||||
uint16 CryptoInfoOffset;
|
||||
uint16 CryptoInfoLength;
|
||||
uint32 HeaderSaltCrc32;
|
||||
Password BootPassword;
|
||||
uint64 HiddenSystemPartitionStart;
|
||||
uint64 DecoySystemPartitionStart;
|
||||
uint32 Flags;
|
||||
uint32 BootDriveSignature;
|
||||
|
||||
uint32 BootArgumentsCrc32;
|
||||
|
||||
} BootArguments;
|
||||
|
||||
// Modifying these values can introduce incompatibility with previous versions
|
||||
#define TC_BOOT_ARGS_FLAG_EXTRA_BOOT_PARTITION 0x1
|
||||
|
||||
#pragma pack ()
|
||||
|
||||
// Boot arguments signature should not be defined as a static string
|
||||
// Modifying these values can introduce incompatibility with previous versions
|
||||
#define TC_SET_BOOT_ARGUMENTS_SIGNATURE(SG) do { SG[0] = 'T'; SG[1] = 'R'; SG[2] = 'U'; SG[3] = 'E'; SG[4] = 0x11; SG[5] = 0x23; SG[6] = 0x45; SG[7] = 0x66; } while (FALSE)
|
||||
#define TC_IS_BOOT_ARGUMENTS_SIGNATURE(SG) (SG[0] == 'T' && SG[1] == 'R' && SG[2] == 'U' && SG[3] == 'E' && SG[4] == 0x11 && SG[5] == 0x23 && SG[6] == 0x45 && SG[7] == 0x66)
|
||||
|
||||
|
||||
#endif // TC_HEADER_Boot_BootCommon
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Boot_BootCommon
|
||||
#define TC_HEADER_Boot_BootCommon
|
||||
|
||||
#include "Common/Password.h"
|
||||
#include "BootDefs.h"
|
||||
|
||||
// The user will be advised to upgrade the rescue disk if upgrading from the following or any previous version
|
||||
#define TC_RESCUE_DISK_UPGRADE_NOTICE_MAX_VERSION 0x0117
|
||||
|
||||
#define TC_BOOT_LOADER_AREA_SIZE (TC_BOOT_LOADER_AREA_SECTOR_COUNT * TC_SECTOR_SIZE_BIOS)
|
||||
|
||||
#define TC_BOOT_VOLUME_HEADER_SECTOR (TC_BOOT_LOADER_AREA_SECTOR_COUNT - 1)
|
||||
#define TC_BOOT_VOLUME_HEADER_SECTOR_OFFSET (TC_BOOT_VOLUME_HEADER_SECTOR * TC_SECTOR_SIZE_BIOS)
|
||||
|
||||
#define TC_CD_BOOTSECTOR_OFFSET 0xd000
|
||||
#define TC_CD_BOOT_LOADER_SECTOR 26
|
||||
|
||||
#define TC_ORIG_BOOT_LOADER_BACKUP_SECTOR TC_BOOT_LOADER_AREA_SECTOR_COUNT
|
||||
#define TC_ORIG_BOOT_LOADER_BACKUP_SECTOR_OFFSET (TC_ORIG_BOOT_LOADER_BACKUP_SECTOR * TC_SECTOR_SIZE_BIOS)
|
||||
|
||||
#define TC_BOOT_LOADER_BACKUP_RESCUE_DISK_SECTOR (TC_ORIG_BOOT_LOADER_BACKUP_SECTOR + TC_BOOT_LOADER_AREA_SECTOR_COUNT)
|
||||
#define TC_BOOT_LOADER_BACKUP_RESCUE_DISK_SECTOR_OFFSET (TC_BOOT_LOADER_BACKUP_RESCUE_DISK_SECTOR * TC_SECTOR_SIZE_BIOS)
|
||||
|
||||
#define TC_MBR_SECTOR 0
|
||||
#define TC_MAX_MBR_BOOT_CODE_SIZE 440
|
||||
|
||||
#define TC_MAX_EXTRA_BOOT_PARTITION_SIZE (512UL * 1024UL * 1024UL)
|
||||
|
||||
|
||||
#pragma pack (1)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
byte Flags;
|
||||
} BootSectorConfiguration;
|
||||
|
||||
|
||||
// Modifying this value can introduce incompatibility with previous versions
|
||||
#define TC_BOOT_LOADER_ARGS_OFFSET 0x10
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// Modifying this structure can introduce incompatibility with previous versions
|
||||
char Signature[8];
|
||||
uint16 BootLoaderVersion;
|
||||
uint16 CryptoInfoOffset;
|
||||
uint16 CryptoInfoLength;
|
||||
uint32 HeaderSaltCrc32;
|
||||
Password BootPassword;
|
||||
uint64 HiddenSystemPartitionStart;
|
||||
uint64 DecoySystemPartitionStart;
|
||||
uint32 Flags;
|
||||
uint32 BootDriveSignature;
|
||||
|
||||
uint32 BootArgumentsCrc32;
|
||||
|
||||
} BootArguments;
|
||||
|
||||
// Modifying these values can introduce incompatibility with previous versions
|
||||
#define TC_BOOT_ARGS_FLAG_EXTRA_BOOT_PARTITION 0x1
|
||||
|
||||
#pragma pack ()
|
||||
|
||||
// Boot arguments signature should not be defined as a static string
|
||||
// Modifying these values can introduce incompatibility with previous versions
|
||||
#define TC_SET_BOOT_ARGUMENTS_SIGNATURE(SG) do { SG[0] = 'T'; SG[1] = 'R'; SG[2] = 'U'; SG[3] = 'E'; SG[4] = 0x11; SG[5] = 0x23; SG[6] = 0x45; SG[7] = 0x66; } while (FALSE)
|
||||
#define TC_IS_BOOT_ARGUMENTS_SIGNATURE(SG) (SG[0] == 'T' && SG[1] == 'R' && SG[2] == 'U' && SG[3] == 'E' && SG[4] == 0x11 && SG[5] == 0x23 && SG[6] == 0x45 && SG[7] == 0x66)
|
||||
|
||||
|
||||
#endif // TC_HEADER_Boot_BootCommon
|
||||
|
||||
@@ -1,102 +1,102 @@
|
||||
/*
|
||||
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 "BootConfig.h"
|
||||
|
||||
byte BootSectorFlags;
|
||||
|
||||
byte BootLoaderDrive;
|
||||
byte BootDrive;
|
||||
bool BootDriveGeometryValid = false;
|
||||
bool PreventNormalSystemBoot = false;
|
||||
bool PreventBootMenu = false;
|
||||
char CustomUserMessage[TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH + 1];
|
||||
uint32 OuterVolumeBackupHeaderCrc;
|
||||
|
||||
bool BootStarted = false;
|
||||
|
||||
DriveGeometry BootDriveGeometry;
|
||||
|
||||
CRYPTO_INFO *BootCryptoInfo;
|
||||
Partition EncryptedVirtualPartition;
|
||||
|
||||
Partition ActivePartition;
|
||||
Partition PartitionFollowingActive;
|
||||
bool ExtraBootPartitionPresent = false;
|
||||
uint64 PimValueOrHiddenVolumeStartUnitNo; // reuse this variable for stored PIM value to reduce memory usage
|
||||
uint64 HiddenVolumeStartSector;
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT_RESCUE_DISK_MODE
|
||||
|
||||
void ReadBootSectorUserConfiguration ()
|
||||
{
|
||||
byte userConfig;
|
||||
|
||||
AcquireSectorBuffer();
|
||||
|
||||
if (ReadWriteMBR (false, BootLoaderDrive, true) != BiosResultSuccess)
|
||||
goto ret;
|
||||
|
||||
userConfig = SectorBuffer[TC_BOOT_SECTOR_USER_CONFIG_OFFSET];
|
||||
|
||||
#ifdef TC_WINDOWS_BOOT_AES
|
||||
EnableHwEncryption (!(userConfig & TC_BOOT_USER_CFG_FLAG_DISABLE_HW_ENCRYPTION));
|
||||
#endif
|
||||
|
||||
PreventBootMenu = (userConfig & TC_BOOT_USER_CFG_FLAG_DISABLE_ESC);
|
||||
|
||||
memcpy (CustomUserMessage, SectorBuffer + TC_BOOT_SECTOR_USER_MESSAGE_OFFSET, TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH);
|
||||
CustomUserMessage[TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH] = 0;
|
||||
|
||||
if (userConfig & TC_BOOT_USER_CFG_FLAG_SILENT_MODE)
|
||||
{
|
||||
if (CustomUserMessage[0])
|
||||
{
|
||||
InitVideoMode();
|
||||
Print (CustomUserMessage);
|
||||
}
|
||||
|
||||
DisableScreenOutput();
|
||||
}
|
||||
|
||||
if (userConfig & TC_BOOT_USER_CFG_FLAG_DISABLE_PIM)
|
||||
{
|
||||
PimValueOrHiddenVolumeStartUnitNo.LowPart = 0;
|
||||
memcpy (&PimValueOrHiddenVolumeStartUnitNo.LowPart, SectorBuffer + TC_BOOT_SECTOR_PIM_VALUE_OFFSET, TC_BOOT_SECTOR_PIM_VALUE_SIZE);
|
||||
}
|
||||
else
|
||||
PimValueOrHiddenVolumeStartUnitNo.LowPart = -1;
|
||||
|
||||
OuterVolumeBackupHeaderCrc = *(uint32 *) (SectorBuffer + TC_BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_OFFSET);
|
||||
|
||||
ret:
|
||||
ReleaseSectorBuffer();
|
||||
}
|
||||
|
||||
|
||||
BiosResult UpdateBootSectorConfiguration (byte drive)
|
||||
{
|
||||
AcquireSectorBuffer();
|
||||
|
||||
BiosResult result = ReadWriteMBR (false, drive);
|
||||
if (result != BiosResultSuccess)
|
||||
goto ret;
|
||||
|
||||
SectorBuffer[TC_BOOT_SECTOR_CONFIG_OFFSET] = BootSectorFlags;
|
||||
result = ReadWriteMBR (true, drive);
|
||||
|
||||
ret:
|
||||
ReleaseSectorBuffer();
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif // !TC_WINDOWS_BOOT_RESCUE_DISK_MODE
|
||||
/*
|
||||
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 "BootConfig.h"
|
||||
|
||||
byte BootSectorFlags;
|
||||
|
||||
byte BootLoaderDrive;
|
||||
byte BootDrive;
|
||||
bool BootDriveGeometryValid = false;
|
||||
bool PreventNormalSystemBoot = false;
|
||||
bool PreventBootMenu = false;
|
||||
char CustomUserMessage[TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH + 1];
|
||||
uint32 OuterVolumeBackupHeaderCrc;
|
||||
|
||||
bool BootStarted = false;
|
||||
|
||||
DriveGeometry BootDriveGeometry;
|
||||
|
||||
CRYPTO_INFO *BootCryptoInfo;
|
||||
Partition EncryptedVirtualPartition;
|
||||
|
||||
Partition ActivePartition;
|
||||
Partition PartitionFollowingActive;
|
||||
bool ExtraBootPartitionPresent = false;
|
||||
uint64 PimValueOrHiddenVolumeStartUnitNo; // reuse this variable for stored PIM value to reduce memory usage
|
||||
uint64 HiddenVolumeStartSector;
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT_RESCUE_DISK_MODE
|
||||
|
||||
void ReadBootSectorUserConfiguration ()
|
||||
{
|
||||
byte userConfig;
|
||||
|
||||
AcquireSectorBuffer();
|
||||
|
||||
if (ReadWriteMBR (false, BootLoaderDrive, true) != BiosResultSuccess)
|
||||
goto ret;
|
||||
|
||||
userConfig = SectorBuffer[TC_BOOT_SECTOR_USER_CONFIG_OFFSET];
|
||||
|
||||
#ifdef TC_WINDOWS_BOOT_AES
|
||||
EnableHwEncryption (!(userConfig & TC_BOOT_USER_CFG_FLAG_DISABLE_HW_ENCRYPTION));
|
||||
#endif
|
||||
|
||||
PreventBootMenu = (userConfig & TC_BOOT_USER_CFG_FLAG_DISABLE_ESC);
|
||||
|
||||
memcpy (CustomUserMessage, SectorBuffer + TC_BOOT_SECTOR_USER_MESSAGE_OFFSET, TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH);
|
||||
CustomUserMessage[TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH] = 0;
|
||||
|
||||
if (userConfig & TC_BOOT_USER_CFG_FLAG_SILENT_MODE)
|
||||
{
|
||||
if (CustomUserMessage[0])
|
||||
{
|
||||
InitVideoMode();
|
||||
Print (CustomUserMessage);
|
||||
}
|
||||
|
||||
DisableScreenOutput();
|
||||
}
|
||||
|
||||
if (userConfig & TC_BOOT_USER_CFG_FLAG_DISABLE_PIM)
|
||||
{
|
||||
PimValueOrHiddenVolumeStartUnitNo.LowPart = 0;
|
||||
memcpy (&PimValueOrHiddenVolumeStartUnitNo.LowPart, SectorBuffer + TC_BOOT_SECTOR_PIM_VALUE_OFFSET, TC_BOOT_SECTOR_PIM_VALUE_SIZE);
|
||||
}
|
||||
else
|
||||
PimValueOrHiddenVolumeStartUnitNo.LowPart = -1;
|
||||
|
||||
OuterVolumeBackupHeaderCrc = *(uint32 *) (SectorBuffer + TC_BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_OFFSET);
|
||||
|
||||
ret:
|
||||
ReleaseSectorBuffer();
|
||||
}
|
||||
|
||||
|
||||
BiosResult UpdateBootSectorConfiguration (byte drive)
|
||||
{
|
||||
AcquireSectorBuffer();
|
||||
|
||||
BiosResult result = ReadWriteMBR (false, drive);
|
||||
if (result != BiosResultSuccess)
|
||||
goto ret;
|
||||
|
||||
SectorBuffer[TC_BOOT_SECTOR_CONFIG_OFFSET] = BootSectorFlags;
|
||||
result = ReadWriteMBR (true, drive);
|
||||
|
||||
ret:
|
||||
ReleaseSectorBuffer();
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif // !TC_WINDOWS_BOOT_RESCUE_DISK_MODE
|
||||
|
||||
@@ -1,46 +1,46 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Boot_BootConfig
|
||||
#define TC_HEADER_Boot_BootConfig
|
||||
|
||||
#include "Crypto.h"
|
||||
#include "Platform.h"
|
||||
#include "BootDiskIo.h"
|
||||
|
||||
extern byte BootSectorFlags;
|
||||
|
||||
extern byte BootLoaderDrive;
|
||||
extern byte BootDrive;
|
||||
extern bool BootDriveGeometryValid;
|
||||
extern DriveGeometry BootDriveGeometry;
|
||||
extern bool PreventNormalSystemBoot;
|
||||
extern bool PreventBootMenu;
|
||||
extern char CustomUserMessage[TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH + 1];
|
||||
extern uint32 OuterVolumeBackupHeaderCrc;
|
||||
|
||||
extern bool BootStarted;
|
||||
|
||||
extern CRYPTO_INFO *BootCryptoInfo;
|
||||
extern Partition EncryptedVirtualPartition;
|
||||
|
||||
extern Partition ActivePartition;
|
||||
extern Partition PartitionFollowingActive;
|
||||
extern bool ExtraBootPartitionPresent;
|
||||
extern uint64 PimValueOrHiddenVolumeStartUnitNo; // reuse this variable for stored PIM value to reduce memory usage
|
||||
extern uint64 HiddenVolumeStartSector;
|
||||
|
||||
|
||||
void ReadBootSectorUserConfiguration ();
|
||||
BiosResult UpdateBootSectorConfiguration (byte drive);
|
||||
|
||||
#endif // TC_HEADER_Boot_BootConfig
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Boot_BootConfig
|
||||
#define TC_HEADER_Boot_BootConfig
|
||||
|
||||
#include "Crypto.h"
|
||||
#include "Platform.h"
|
||||
#include "BootDiskIo.h"
|
||||
|
||||
extern byte BootSectorFlags;
|
||||
|
||||
extern byte BootLoaderDrive;
|
||||
extern byte BootDrive;
|
||||
extern bool BootDriveGeometryValid;
|
||||
extern DriveGeometry BootDriveGeometry;
|
||||
extern bool PreventNormalSystemBoot;
|
||||
extern bool PreventBootMenu;
|
||||
extern char CustomUserMessage[TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH + 1];
|
||||
extern uint32 OuterVolumeBackupHeaderCrc;
|
||||
|
||||
extern bool BootStarted;
|
||||
|
||||
extern CRYPTO_INFO *BootCryptoInfo;
|
||||
extern Partition EncryptedVirtualPartition;
|
||||
|
||||
extern Partition ActivePartition;
|
||||
extern Partition PartitionFollowingActive;
|
||||
extern bool ExtraBootPartitionPresent;
|
||||
extern uint64 PimValueOrHiddenVolumeStartUnitNo; // reuse this variable for stored PIM value to reduce memory usage
|
||||
extern uint64 HiddenVolumeStartSector;
|
||||
|
||||
|
||||
void ReadBootSectorUserConfiguration ();
|
||||
BiosResult UpdateBootSectorConfiguration (byte drive);
|
||||
|
||||
#endif // TC_HEADER_Boot_BootConfig
|
||||
|
||||
@@ -1,339 +1,339 @@
|
||||
/*
|
||||
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 "Platform.h"
|
||||
#include "Bios.h"
|
||||
#include "BootConsoleIo.h"
|
||||
#include "BootDebug.h"
|
||||
#include "BootStrings.h"
|
||||
|
||||
|
||||
static int ScreenOutputDisabled = 0;
|
||||
|
||||
void DisableScreenOutput ()
|
||||
{
|
||||
++ScreenOutputDisabled;
|
||||
}
|
||||
|
||||
|
||||
void EnableScreenOutput ()
|
||||
{
|
||||
--ScreenOutputDisabled;
|
||||
}
|
||||
|
||||
|
||||
void PrintChar (char c)
|
||||
{
|
||||
#ifdef TC_BOOT_TRACING_ENABLED
|
||||
WriteDebugPort (c);
|
||||
#endif
|
||||
|
||||
if (ScreenOutputDisabled)
|
||||
return;
|
||||
|
||||
__asm
|
||||
{
|
||||
mov bx, 7
|
||||
mov al, c
|
||||
mov ah, 0xe
|
||||
int 0x10
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PrintCharAtCursor (char c)
|
||||
{
|
||||
if (ScreenOutputDisabled)
|
||||
return;
|
||||
|
||||
__asm
|
||||
{
|
||||
mov bx, 7
|
||||
mov al, c
|
||||
mov cx, 1
|
||||
mov ah, 0xa
|
||||
int 0x10
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Print (const char *str)
|
||||
{
|
||||
char c;
|
||||
while (c = *str++)
|
||||
PrintChar (c);
|
||||
}
|
||||
|
||||
|
||||
void Print (uint32 number)
|
||||
{
|
||||
char str[12];
|
||||
int pos = 0;
|
||||
while (number >= 10)
|
||||
{
|
||||
str[pos++] = (char) (number % 10) + '0';
|
||||
number /= 10;
|
||||
}
|
||||
str[pos] = (char) (number % 10) + '0';
|
||||
|
||||
while (pos >= 0)
|
||||
PrintChar (str[pos--]);
|
||||
}
|
||||
|
||||
|
||||
void Print (const uint64 &number)
|
||||
{
|
||||
if (number.HighPart == 0)
|
||||
Print (number.LowPart);
|
||||
else
|
||||
PrintHex (number);
|
||||
}
|
||||
|
||||
|
||||
void PrintHex (byte b)
|
||||
{
|
||||
PrintChar (((b >> 4) >= 0xA ? 'A' - 0xA : '0') + (b >> 4));
|
||||
PrintChar (((b & 0xF) >= 0xA ? 'A' - 0xA : '0') + (b & 0xF));
|
||||
}
|
||||
|
||||
|
||||
void PrintHex (uint16 data)
|
||||
{
|
||||
PrintHex (byte (data >> 8));
|
||||
PrintHex (byte (data));
|
||||
}
|
||||
|
||||
|
||||
void PrintHex (uint32 data)
|
||||
{
|
||||
PrintHex (uint16 (data >> 16));
|
||||
PrintHex (uint16 (data));
|
||||
}
|
||||
|
||||
|
||||
void PrintHex (const uint64 &data)
|
||||
{
|
||||
PrintHex (data.HighPart);
|
||||
PrintHex (data.LowPart);
|
||||
}
|
||||
|
||||
void PrintRepeatedChar (char c, int n)
|
||||
{
|
||||
while (n-- > 0)
|
||||
PrintChar (c);
|
||||
}
|
||||
|
||||
|
||||
void PrintEndl ()
|
||||
{
|
||||
Print ("\r\n");
|
||||
}
|
||||
|
||||
|
||||
void PrintEndl (int cnt)
|
||||
{
|
||||
while (cnt-- > 0)
|
||||
PrintEndl ();
|
||||
}
|
||||
|
||||
|
||||
void Beep ()
|
||||
{
|
||||
PrintChar (7);
|
||||
}
|
||||
|
||||
|
||||
void InitVideoMode ()
|
||||
{
|
||||
if (ScreenOutputDisabled)
|
||||
return;
|
||||
|
||||
__asm
|
||||
{
|
||||
// Text mode 80x25
|
||||
mov ax, 3
|
||||
int 0x10
|
||||
|
||||
// Page 0
|
||||
mov ax, 0x500
|
||||
int 0x10
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ClearScreen ()
|
||||
{
|
||||
if (ScreenOutputDisabled)
|
||||
return;
|
||||
|
||||
__asm
|
||||
{
|
||||
// White text on black
|
||||
mov bh, 7
|
||||
xor cx, cx
|
||||
mov dx, 0x184f
|
||||
mov ax, 0x600
|
||||
int 0x10
|
||||
|
||||
// Cursor at 0,0
|
||||
xor bh, bh
|
||||
xor dx, dx
|
||||
mov ah, 2
|
||||
int 0x10
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PrintBackspace ()
|
||||
{
|
||||
PrintChar (TC_BIOS_CHAR_BACKSPACE);
|
||||
PrintCharAtCursor (' ');
|
||||
}
|
||||
|
||||
|
||||
void PrintError (const char *message)
|
||||
{
|
||||
Print (TC_BOOT_STR_ERROR);
|
||||
Print (message);
|
||||
PrintEndl();
|
||||
Beep();
|
||||
}
|
||||
|
||||
|
||||
void PrintErrorNoEndl (const char *message)
|
||||
{
|
||||
Print (TC_BOOT_STR_ERROR);
|
||||
Print (message);
|
||||
Beep();
|
||||
}
|
||||
|
||||
|
||||
byte GetShiftFlags ()
|
||||
{
|
||||
byte flags;
|
||||
__asm
|
||||
{
|
||||
mov ah, 2
|
||||
int 0x16
|
||||
mov flags, al
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
|
||||
byte GetKeyboardChar ()
|
||||
{
|
||||
return GetKeyboardChar (nullptr);
|
||||
}
|
||||
|
||||
|
||||
byte GetKeyboardChar (byte *scanCode)
|
||||
{
|
||||
// Work around potential BIOS bugs (Windows boot manager polls the keystroke buffer)
|
||||
while (!IsKeyboardCharAvailable());
|
||||
|
||||
byte asciiCode;
|
||||
byte scan;
|
||||
__asm
|
||||
{
|
||||
mov ah, 0
|
||||
int 0x16
|
||||
mov asciiCode, al
|
||||
mov scan, ah
|
||||
}
|
||||
|
||||
if (scanCode)
|
||||
*scanCode = scan;
|
||||
|
||||
return asciiCode;
|
||||
}
|
||||
|
||||
|
||||
bool IsKeyboardCharAvailable ()
|
||||
{
|
||||
bool available = false;
|
||||
__asm
|
||||
{
|
||||
mov ah, 1
|
||||
int 0x16
|
||||
jz not_avail
|
||||
mov available, true
|
||||
not_avail:
|
||||
}
|
||||
|
||||
return available;
|
||||
}
|
||||
|
||||
|
||||
bool EscKeyPressed ()
|
||||
{
|
||||
if (IsKeyboardCharAvailable ())
|
||||
{
|
||||
byte keyScanCode;
|
||||
GetKeyboardChar (&keyScanCode);
|
||||
return keyScanCode == TC_BIOS_KEY_ESC;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void ClearBiosKeystrokeBuffer ()
|
||||
{
|
||||
__asm
|
||||
{
|
||||
push es
|
||||
xor ax, ax
|
||||
mov es, ax
|
||||
mov di, 0x41e
|
||||
mov cx, 32
|
||||
cld
|
||||
rep stosb
|
||||
pop es
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool IsPrintable (char c)
|
||||
{
|
||||
return c >= ' ' && c <= '~';
|
||||
}
|
||||
|
||||
bool IsDigit (char c)
|
||||
{
|
||||
return c >= '0' && c <= '9';
|
||||
}
|
||||
|
||||
|
||||
int GetString (char *buffer, size_t bufferSize)
|
||||
{
|
||||
byte c;
|
||||
byte scanCode;
|
||||
size_t pos = 0;
|
||||
|
||||
while (pos < bufferSize)
|
||||
{
|
||||
c = GetKeyboardChar (&scanCode);
|
||||
|
||||
if (scanCode == TC_BIOS_KEY_ENTER)
|
||||
break;
|
||||
|
||||
if (scanCode == TC_BIOS_KEY_ESC)
|
||||
return 0;
|
||||
|
||||
buffer[pos++] = c;
|
||||
PrintChar (IsPrintable (c) ? c : ' ');
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
/*
|
||||
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 "Platform.h"
|
||||
#include "Bios.h"
|
||||
#include "BootConsoleIo.h"
|
||||
#include "BootDebug.h"
|
||||
#include "BootStrings.h"
|
||||
|
||||
|
||||
static int ScreenOutputDisabled = 0;
|
||||
|
||||
void DisableScreenOutput ()
|
||||
{
|
||||
++ScreenOutputDisabled;
|
||||
}
|
||||
|
||||
|
||||
void EnableScreenOutput ()
|
||||
{
|
||||
--ScreenOutputDisabled;
|
||||
}
|
||||
|
||||
|
||||
void PrintChar (char c)
|
||||
{
|
||||
#ifdef TC_BOOT_TRACING_ENABLED
|
||||
WriteDebugPort (c);
|
||||
#endif
|
||||
|
||||
if (ScreenOutputDisabled)
|
||||
return;
|
||||
|
||||
__asm
|
||||
{
|
||||
mov bx, 7
|
||||
mov al, c
|
||||
mov ah, 0xe
|
||||
int 0x10
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PrintCharAtCursor (char c)
|
||||
{
|
||||
if (ScreenOutputDisabled)
|
||||
return;
|
||||
|
||||
__asm
|
||||
{
|
||||
mov bx, 7
|
||||
mov al, c
|
||||
mov cx, 1
|
||||
mov ah, 0xa
|
||||
int 0x10
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Print (const char *str)
|
||||
{
|
||||
char c;
|
||||
while (c = *str++)
|
||||
PrintChar (c);
|
||||
}
|
||||
|
||||
|
||||
void Print (uint32 number)
|
||||
{
|
||||
char str[12];
|
||||
int pos = 0;
|
||||
while (number >= 10)
|
||||
{
|
||||
str[pos++] = (char) (number % 10) + '0';
|
||||
number /= 10;
|
||||
}
|
||||
str[pos] = (char) (number % 10) + '0';
|
||||
|
||||
while (pos >= 0)
|
||||
PrintChar (str[pos--]);
|
||||
}
|
||||
|
||||
|
||||
void Print (const uint64 &number)
|
||||
{
|
||||
if (number.HighPart == 0)
|
||||
Print (number.LowPart);
|
||||
else
|
||||
PrintHex (number);
|
||||
}
|
||||
|
||||
|
||||
void PrintHex (byte b)
|
||||
{
|
||||
PrintChar (((b >> 4) >= 0xA ? 'A' - 0xA : '0') + (b >> 4));
|
||||
PrintChar (((b & 0xF) >= 0xA ? 'A' - 0xA : '0') + (b & 0xF));
|
||||
}
|
||||
|
||||
|
||||
void PrintHex (uint16 data)
|
||||
{
|
||||
PrintHex (byte (data >> 8));
|
||||
PrintHex (byte (data));
|
||||
}
|
||||
|
||||
|
||||
void PrintHex (uint32 data)
|
||||
{
|
||||
PrintHex (uint16 (data >> 16));
|
||||
PrintHex (uint16 (data));
|
||||
}
|
||||
|
||||
|
||||
void PrintHex (const uint64 &data)
|
||||
{
|
||||
PrintHex (data.HighPart);
|
||||
PrintHex (data.LowPart);
|
||||
}
|
||||
|
||||
void PrintRepeatedChar (char c, int n)
|
||||
{
|
||||
while (n-- > 0)
|
||||
PrintChar (c);
|
||||
}
|
||||
|
||||
|
||||
void PrintEndl ()
|
||||
{
|
||||
Print ("\r\n");
|
||||
}
|
||||
|
||||
|
||||
void PrintEndl (int cnt)
|
||||
{
|
||||
while (cnt-- > 0)
|
||||
PrintEndl ();
|
||||
}
|
||||
|
||||
|
||||
void Beep ()
|
||||
{
|
||||
PrintChar (7);
|
||||
}
|
||||
|
||||
|
||||
void InitVideoMode ()
|
||||
{
|
||||
if (ScreenOutputDisabled)
|
||||
return;
|
||||
|
||||
__asm
|
||||
{
|
||||
// Text mode 80x25
|
||||
mov ax, 3
|
||||
int 0x10
|
||||
|
||||
// Page 0
|
||||
mov ax, 0x500
|
||||
int 0x10
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ClearScreen ()
|
||||
{
|
||||
if (ScreenOutputDisabled)
|
||||
return;
|
||||
|
||||
__asm
|
||||
{
|
||||
// White text on black
|
||||
mov bh, 7
|
||||
xor cx, cx
|
||||
mov dx, 0x184f
|
||||
mov ax, 0x600
|
||||
int 0x10
|
||||
|
||||
// Cursor at 0,0
|
||||
xor bh, bh
|
||||
xor dx, dx
|
||||
mov ah, 2
|
||||
int 0x10
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PrintBackspace ()
|
||||
{
|
||||
PrintChar (TC_BIOS_CHAR_BACKSPACE);
|
||||
PrintCharAtCursor (' ');
|
||||
}
|
||||
|
||||
|
||||
void PrintError (const char *message)
|
||||
{
|
||||
Print (TC_BOOT_STR_ERROR);
|
||||
Print (message);
|
||||
PrintEndl();
|
||||
Beep();
|
||||
}
|
||||
|
||||
|
||||
void PrintErrorNoEndl (const char *message)
|
||||
{
|
||||
Print (TC_BOOT_STR_ERROR);
|
||||
Print (message);
|
||||
Beep();
|
||||
}
|
||||
|
||||
|
||||
byte GetShiftFlags ()
|
||||
{
|
||||
byte flags;
|
||||
__asm
|
||||
{
|
||||
mov ah, 2
|
||||
int 0x16
|
||||
mov flags, al
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
|
||||
byte GetKeyboardChar ()
|
||||
{
|
||||
return GetKeyboardChar (nullptr);
|
||||
}
|
||||
|
||||
|
||||
byte GetKeyboardChar (byte *scanCode)
|
||||
{
|
||||
// Work around potential BIOS bugs (Windows boot manager polls the keystroke buffer)
|
||||
while (!IsKeyboardCharAvailable());
|
||||
|
||||
byte asciiCode;
|
||||
byte scan;
|
||||
__asm
|
||||
{
|
||||
mov ah, 0
|
||||
int 0x16
|
||||
mov asciiCode, al
|
||||
mov scan, ah
|
||||
}
|
||||
|
||||
if (scanCode)
|
||||
*scanCode = scan;
|
||||
|
||||
return asciiCode;
|
||||
}
|
||||
|
||||
|
||||
bool IsKeyboardCharAvailable ()
|
||||
{
|
||||
bool available = false;
|
||||
__asm
|
||||
{
|
||||
mov ah, 1
|
||||
int 0x16
|
||||
jz not_avail
|
||||
mov available, true
|
||||
not_avail:
|
||||
}
|
||||
|
||||
return available;
|
||||
}
|
||||
|
||||
|
||||
bool EscKeyPressed ()
|
||||
{
|
||||
if (IsKeyboardCharAvailable ())
|
||||
{
|
||||
byte keyScanCode;
|
||||
GetKeyboardChar (&keyScanCode);
|
||||
return keyScanCode == TC_BIOS_KEY_ESC;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void ClearBiosKeystrokeBuffer ()
|
||||
{
|
||||
__asm
|
||||
{
|
||||
push es
|
||||
xor ax, ax
|
||||
mov es, ax
|
||||
mov di, 0x41e
|
||||
mov cx, 32
|
||||
cld
|
||||
rep stosb
|
||||
pop es
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool IsPrintable (char c)
|
||||
{
|
||||
return c >= ' ' && c <= '~';
|
||||
}
|
||||
|
||||
bool IsDigit (char c)
|
||||
{
|
||||
return c >= '0' && c <= '9';
|
||||
}
|
||||
|
||||
|
||||
int GetString (char *buffer, size_t bufferSize)
|
||||
{
|
||||
byte c;
|
||||
byte scanCode;
|
||||
size_t pos = 0;
|
||||
|
||||
while (pos < bufferSize)
|
||||
{
|
||||
c = GetKeyboardChar (&scanCode);
|
||||
|
||||
if (scanCode == TC_BIOS_KEY_ENTER)
|
||||
break;
|
||||
|
||||
if (scanCode == TC_BIOS_KEY_ESC)
|
||||
return 0;
|
||||
|
||||
buffer[pos++] = c;
|
||||
PrintChar (IsPrintable (c) ? c : ' ');
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
@@ -1,72 +1,72 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Boot_BootConsoleIo
|
||||
#define TC_HEADER_Boot_BootConsoleIo
|
||||
|
||||
#include "Platform.h"
|
||||
|
||||
#define TC_DEBUG_PORT 0
|
||||
|
||||
#define TC_BIOS_KEY_ESC 1
|
||||
#define TC_BIOS_KEY_BACKSPACE 14
|
||||
#define TC_BIOS_KEY_ENTER 28
|
||||
#define TC_BIOS_KEY_F1 0x3b
|
||||
#define TC_BIOS_KEY_F2 0x3c
|
||||
#define TC_BIOS_KEY_F3 0x3d
|
||||
#define TC_BIOS_KEY_F4 0x3e
|
||||
#define TC_BIOS_KEY_F5 0x3f
|
||||
#define TC_BIOS_KEY_F6 0x40
|
||||
#define TC_BIOS_KEY_F7 0x41
|
||||
#define TC_BIOS_KEY_F8 0x42
|
||||
#define TC_BIOS_KEY_F9 0x43
|
||||
#define TC_BIOS_KEY_F10 0x44
|
||||
|
||||
#define TC_BIOS_SHIFTMASK_CAPSLOCK (1 << 6)
|
||||
#define TC_BIOS_SHIFTMASK_LSHIFT (1 << 1)
|
||||
#define TC_BIOS_SHIFTMASK_RSHIFT (1 << 0)
|
||||
|
||||
#define TC_BIOS_CHAR_BACKSPACE 8
|
||||
|
||||
#define TC_BIOS_MAX_CHARS_PER_LINE 80
|
||||
|
||||
void Beep ();
|
||||
void ClearBiosKeystrokeBuffer ();
|
||||
void ClearScreen ();
|
||||
void DisableScreenOutput ();
|
||||
void EnableScreenOutput ();
|
||||
bool EscKeyPressed ();
|
||||
byte GetKeyboardChar ();
|
||||
byte GetKeyboardChar (byte *scanCode);
|
||||
byte GetShiftFlags ();
|
||||
int GetString (char *buffer, size_t bufferSize);
|
||||
void InitVideoMode ();
|
||||
bool IsKeyboardCharAvailable ();
|
||||
bool IsPrintable (char c);
|
||||
bool IsDigit (char c);
|
||||
void Print (const char *str);
|
||||
void Print (uint32 number);
|
||||
void Print (const uint64 &number);
|
||||
void PrintBackspace ();
|
||||
void PrintChar (char c);
|
||||
void PrintCharAtCursor (char c);
|
||||
void PrintEndl ();
|
||||
void PrintEndl (int cnt);
|
||||
void PrintRepeatedChar (char c, int n);
|
||||
void PrintError (const char *message);
|
||||
void PrintErrorNoEndl (const char *message);
|
||||
void PrintHex (byte b);
|
||||
void PrintHex (uint16 data);
|
||||
void PrintHex (uint32 data);
|
||||
void PrintHex (const uint64 &data);
|
||||
|
||||
#endif // TC_HEADER_Boot_BootConsoleIo
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Boot_BootConsoleIo
|
||||
#define TC_HEADER_Boot_BootConsoleIo
|
||||
|
||||
#include "Platform.h"
|
||||
|
||||
#define TC_DEBUG_PORT 0
|
||||
|
||||
#define TC_BIOS_KEY_ESC 1
|
||||
#define TC_BIOS_KEY_BACKSPACE 14
|
||||
#define TC_BIOS_KEY_ENTER 28
|
||||
#define TC_BIOS_KEY_F1 0x3b
|
||||
#define TC_BIOS_KEY_F2 0x3c
|
||||
#define TC_BIOS_KEY_F3 0x3d
|
||||
#define TC_BIOS_KEY_F4 0x3e
|
||||
#define TC_BIOS_KEY_F5 0x3f
|
||||
#define TC_BIOS_KEY_F6 0x40
|
||||
#define TC_BIOS_KEY_F7 0x41
|
||||
#define TC_BIOS_KEY_F8 0x42
|
||||
#define TC_BIOS_KEY_F9 0x43
|
||||
#define TC_BIOS_KEY_F10 0x44
|
||||
|
||||
#define TC_BIOS_SHIFTMASK_CAPSLOCK (1 << 6)
|
||||
#define TC_BIOS_SHIFTMASK_LSHIFT (1 << 1)
|
||||
#define TC_BIOS_SHIFTMASK_RSHIFT (1 << 0)
|
||||
|
||||
#define TC_BIOS_CHAR_BACKSPACE 8
|
||||
|
||||
#define TC_BIOS_MAX_CHARS_PER_LINE 80
|
||||
|
||||
void Beep ();
|
||||
void ClearBiosKeystrokeBuffer ();
|
||||
void ClearScreen ();
|
||||
void DisableScreenOutput ();
|
||||
void EnableScreenOutput ();
|
||||
bool EscKeyPressed ();
|
||||
byte GetKeyboardChar ();
|
||||
byte GetKeyboardChar (byte *scanCode);
|
||||
byte GetShiftFlags ();
|
||||
int GetString (char *buffer, size_t bufferSize);
|
||||
void InitVideoMode ();
|
||||
bool IsKeyboardCharAvailable ();
|
||||
bool IsPrintable (char c);
|
||||
bool IsDigit (char c);
|
||||
void Print (const char *str);
|
||||
void Print (uint32 number);
|
||||
void Print (const uint64 &number);
|
||||
void PrintBackspace ();
|
||||
void PrintChar (char c);
|
||||
void PrintCharAtCursor (char c);
|
||||
void PrintEndl ();
|
||||
void PrintEndl (int cnt);
|
||||
void PrintRepeatedChar (char c, int n);
|
||||
void PrintError (const char *message);
|
||||
void PrintErrorNoEndl (const char *message);
|
||||
void PrintHex (byte b);
|
||||
void PrintHex (uint16 data);
|
||||
void PrintHex (uint32 data);
|
||||
void PrintHex (const uint64 &data);
|
||||
|
||||
#endif // TC_HEADER_Boot_BootConsoleIo
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
;
|
||||
; 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.
|
||||
;
|
||||
|
||||
.MODEL tiny, C
|
||||
.386
|
||||
|
||||
INCLUDE BootDefs.i
|
||||
|
||||
EXTERNDEF main:NEAR
|
||||
|
||||
_TEXT SEGMENT
|
||||
ORG TC_COM_EXECUTABLE_OFFSET
|
||||
|
||||
start:
|
||||
jmp main
|
||||
|
||||
_TEXT ENDS
|
||||
END start
|
||||
;
|
||||
; 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.
|
||||
;
|
||||
|
||||
.MODEL tiny, C
|
||||
.386
|
||||
|
||||
INCLUDE BootDefs.i
|
||||
|
||||
EXTERNDEF main:NEAR
|
||||
|
||||
_TEXT SEGMENT
|
||||
ORG TC_COM_EXECUTABLE_OFFSET
|
||||
|
||||
start:
|
||||
jmp main
|
||||
|
||||
_TEXT ENDS
|
||||
END start
|
||||
|
||||
@@ -1,181 +1,181 @@
|
||||
/*
|
||||
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 "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
|
||||
{
|
||||
mov dx, TC_DEBUG_PORT
|
||||
mov ah, 1
|
||||
int 0x17
|
||||
mov dx, TC_DEBUG_PORT
|
||||
mov ah, 0xe2
|
||||
int 0x17
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void WriteDebugPort (byte dataByte)
|
||||
{
|
||||
__asm
|
||||
{
|
||||
mov al, dataByte
|
||||
mov dx, TC_DEBUG_PORT
|
||||
mov ah, 0
|
||||
int 0x17
|
||||
}
|
||||
}
|
||||
|
||||
#endif // TC_BOOT_TRACING_ENABLED
|
||||
|
||||
|
||||
#ifdef TC_BOOT_DEBUG_ENABLED
|
||||
|
||||
extern "C" void PrintDebug (uint32 debugVal)
|
||||
{
|
||||
Print (debugVal);
|
||||
PrintEndl();
|
||||
}
|
||||
|
||||
|
||||
void PrintVal (const char *message, const uint32 value, bool newLine, bool hex)
|
||||
{
|
||||
Print (message);
|
||||
Print (": ");
|
||||
|
||||
if (hex)
|
||||
PrintHex (value);
|
||||
else
|
||||
Print (value);
|
||||
|
||||
if (newLine)
|
||||
PrintEndl();
|
||||
}
|
||||
|
||||
|
||||
void PrintVal (const char *message, const uint64 &value, bool newLine, bool hex)
|
||||
{
|
||||
Print (message);
|
||||
Print (": ");
|
||||
PrintHex (value);
|
||||
if (newLine)
|
||||
PrintEndl();
|
||||
}
|
||||
|
||||
|
||||
void PrintHexDump (byte *mem, size_t size, uint16 *memSegment)
|
||||
{
|
||||
const size_t width = 16;
|
||||
for (size_t pos = 0; pos < size; )
|
||||
{
|
||||
for (int pass = 1; pass <= 2; ++pass)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < width && pos < size; ++i)
|
||||
{
|
||||
byte dataByte;
|
||||
if (memSegment)
|
||||
{
|
||||
__asm
|
||||
{
|
||||
push es
|
||||
mov si, ss:memSegment
|
||||
mov es, ss:[si]
|
||||
mov si, ss:mem
|
||||
add si, pos
|
||||
mov al, es:[si]
|
||||
mov dataByte, al
|
||||
pop es
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
else
|
||||
dataByte = mem[pos++];
|
||||
|
||||
if (pass == 1)
|
||||
{
|
||||
PrintHex (dataByte);
|
||||
PrintChar (' ');
|
||||
}
|
||||
else
|
||||
PrintChar (IsPrintable (dataByte) ? dataByte : '.');
|
||||
}
|
||||
|
||||
if (pass == 1)
|
||||
{
|
||||
pos -= i;
|
||||
PrintChar (' ');
|
||||
}
|
||||
}
|
||||
|
||||
PrintEndl ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
/*
|
||||
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 "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
|
||||
{
|
||||
mov dx, TC_DEBUG_PORT
|
||||
mov ah, 1
|
||||
int 0x17
|
||||
mov dx, TC_DEBUG_PORT
|
||||
mov ah, 0xe2
|
||||
int 0x17
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void WriteDebugPort (byte dataByte)
|
||||
{
|
||||
__asm
|
||||
{
|
||||
mov al, dataByte
|
||||
mov dx, TC_DEBUG_PORT
|
||||
mov ah, 0
|
||||
int 0x17
|
||||
}
|
||||
}
|
||||
|
||||
#endif // TC_BOOT_TRACING_ENABLED
|
||||
|
||||
|
||||
#ifdef TC_BOOT_DEBUG_ENABLED
|
||||
|
||||
extern "C" void PrintDebug (uint32 debugVal)
|
||||
{
|
||||
Print (debugVal);
|
||||
PrintEndl();
|
||||
}
|
||||
|
||||
|
||||
void PrintVal (const char *message, const uint32 value, bool newLine, bool hex)
|
||||
{
|
||||
Print (message);
|
||||
Print (": ");
|
||||
|
||||
if (hex)
|
||||
PrintHex (value);
|
||||
else
|
||||
Print (value);
|
||||
|
||||
if (newLine)
|
||||
PrintEndl();
|
||||
}
|
||||
|
||||
|
||||
void PrintVal (const char *message, const uint64 &value, bool newLine, bool hex)
|
||||
{
|
||||
Print (message);
|
||||
Print (": ");
|
||||
PrintHex (value);
|
||||
if (newLine)
|
||||
PrintEndl();
|
||||
}
|
||||
|
||||
|
||||
void PrintHexDump (byte *mem, size_t size, uint16 *memSegment)
|
||||
{
|
||||
const size_t width = 16;
|
||||
for (size_t pos = 0; pos < size; )
|
||||
{
|
||||
for (int pass = 1; pass <= 2; ++pass)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < width && pos < size; ++i)
|
||||
{
|
||||
byte dataByte;
|
||||
if (memSegment)
|
||||
{
|
||||
__asm
|
||||
{
|
||||
push es
|
||||
mov si, ss:memSegment
|
||||
mov es, ss:[si]
|
||||
mov si, ss:mem
|
||||
add si, pos
|
||||
mov al, es:[si]
|
||||
mov dataByte, al
|
||||
pop es
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
else
|
||||
dataByte = mem[pos++];
|
||||
|
||||
if (pass == 1)
|
||||
{
|
||||
PrintHex (dataByte);
|
||||
PrintChar (' ');
|
||||
}
|
||||
else
|
||||
PrintChar (IsPrintable (dataByte) ? dataByte : '.');
|
||||
}
|
||||
|
||||
if (pass == 1)
|
||||
{
|
||||
pos -= i;
|
||||
PrintChar (' ');
|
||||
}
|
||||
}
|
||||
|
||||
PrintEndl ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -1,60 +1,60 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Boot_BootDebug
|
||||
#define TC_HEADER_Boot_BootDebug
|
||||
|
||||
#include "Platform.h"
|
||||
#include "BootConsoleIo.h"
|
||||
|
||||
#if 0
|
||||
# define TC_BOOT_DEBUG_ENABLED
|
||||
#endif
|
||||
|
||||
#if 0 || defined (TC_BOOT_DEBUG_ENABLED)
|
||||
# define TC_BOOT_STACK_CHECKING_ENABLED
|
||||
extern "C" void CheckStack ();
|
||||
#else
|
||||
# define CheckStack()
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
# define TC_BOOT_TRACING_ENABLED
|
||||
# if 1
|
||||
# define TC_TRACE_INT13
|
||||
# endif
|
||||
# if 0
|
||||
# define TC_TRACE_INT15
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef TC_BOOT_DEBUG_ENABLED
|
||||
# define trace_point do { Print(__FILE__); PrintChar (':'); Print (TC_TO_STRING (__LINE__)); PrintEndl(); } while (false)
|
||||
# define trace_val(VAL) PrintVal (#VAL, VAL);
|
||||
# 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)
|
||||
#else
|
||||
# define trace_point
|
||||
# define trace_val(VAL)
|
||||
# define trace_hex(VAL)
|
||||
# define assert(COND)
|
||||
#endif
|
||||
|
||||
void InitDebugPort ();
|
||||
void InitStackChecker ();
|
||||
void WriteDebugPort (byte dataByte);
|
||||
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
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Boot_BootDebug
|
||||
#define TC_HEADER_Boot_BootDebug
|
||||
|
||||
#include "Platform.h"
|
||||
#include "BootConsoleIo.h"
|
||||
|
||||
#if 0
|
||||
# define TC_BOOT_DEBUG_ENABLED
|
||||
#endif
|
||||
|
||||
#if 0 || defined (TC_BOOT_DEBUG_ENABLED)
|
||||
# define TC_BOOT_STACK_CHECKING_ENABLED
|
||||
extern "C" void CheckStack ();
|
||||
#else
|
||||
# define CheckStack()
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
# define TC_BOOT_TRACING_ENABLED
|
||||
# if 1
|
||||
# define TC_TRACE_INT13
|
||||
# endif
|
||||
# if 0
|
||||
# define TC_TRACE_INT15
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef TC_BOOT_DEBUG_ENABLED
|
||||
# define trace_point do { Print(__FILE__); PrintChar (':'); Print (TC_TO_STRING (__LINE__)); PrintEndl(); } while (false)
|
||||
# define trace_val(VAL) PrintVal (#VAL, VAL);
|
||||
# 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)
|
||||
#else
|
||||
# define trace_point
|
||||
# define trace_val(VAL)
|
||||
# define trace_hex(VAL)
|
||||
# define assert(COND)
|
||||
#endif
|
||||
|
||||
void InitDebugPort ();
|
||||
void InitStackChecker ();
|
||||
void WriteDebugPort (byte dataByte);
|
||||
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
|
||||
|
||||
@@ -1,199 +1,199 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#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 43
|
||||
|
||||
#ifdef TC_WINDOWS_BOOT_SINGLE_CIPHER_MODE
|
||||
# undef TC__BOOT_MEMORY_REQUIRED
|
||||
|
||||
# ifdef TC_WINDOWS_BOOT_AES
|
||||
# ifdef TC_WINDOWS_BOOT_RESCUE_DISK_MODE
|
||||
# define TC__BOOT_MEMORY_REQUIRED 31
|
||||
# else
|
||||
# define TC__BOOT_MEMORY_REQUIRED 29
|
||||
# endif
|
||||
# elif defined (TC_WINDOWS_BOOT_SERPENT)
|
||||
# define TC__BOOT_MEMORY_REQUIRED 33
|
||||
# elif defined (TC_WINDOWS_BOOT_TWOFISH)
|
||||
# define TC__BOOT_MEMORY_REQUIRED 41
|
||||
# endif
|
||||
|
||||
#if 0
|
||||
# undef TC__BOOT_MEMORY_REQUIRED
|
||||
# define TC__BOOT_MEMORY_REQUIRED 60
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// Modifying this value can introduce incompatibility with previous versions
|
||||
#define TC__BOOT_LOADER_SEGMENT TC_HEX (9000) // Some buggy BIOS routines fail if CS bits 0-10 are not zero
|
||||
|
||||
#if TC__BOOT_MEMORY_REQUIRED <= 32
|
||||
# define TC__BOOT_LOADER_SEGMENT_LOW (TC__BOOT_LOADER_SEGMENT - 32 * 1024 / 16)
|
||||
#else
|
||||
# define TC__BOOT_LOADER_SEGMENT_LOW (TC__BOOT_LOADER_SEGMENT - 64 * 1024 / 16)
|
||||
#endif
|
||||
|
||||
#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 (4000)
|
||||
#define TC__BOOT_LOADER_ALT_SEGMENT TC_HEX (6000)
|
||||
|
||||
#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_VERSION_OFFSET 430
|
||||
#define TC__BOOT_SECTOR_LOADER_LENGTH_OFFSET 432
|
||||
#define TC__BOOT_SECTOR_LOADER_CHECKSUM_OFFSET 434
|
||||
#define TC__BOOT_SECTOR_USER_CONFIG_OFFSET 438
|
||||
#define TC__BOOT_SECTOR_CONFIG_OFFSET 439 // The last byte that is reserved for the boot loader
|
||||
|
||||
#define TC__BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH 24
|
||||
#define TC__BOOT_SECTOR_USER_MESSAGE_OFFSET (TC__BOOT_SECTOR_VERSION_OFFSET - TC__BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH)
|
||||
|
||||
#define TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_SIZE 4
|
||||
#define TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_OFFSET (TC__BOOT_SECTOR_USER_MESSAGE_OFFSET - TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_SIZE)
|
||||
|
||||
#define TC__BOOT_SECTOR_PIM_VALUE_SIZE 2
|
||||
#define TC__BOOT_SECTOR_PIM_VALUE_OFFSET (TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_OFFSET - TC__BOOT_SECTOR_PIM_VALUE_SIZE)
|
||||
|
||||
#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_AREA_SIZE 1 // In bytes
|
||||
|
||||
// If you add more flags, revise TC__BOOT_CFG_FLAG_AREA_SIZE
|
||||
#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_DISABLE_HW_ENCRYPTION TC_HEX (10)
|
||||
#define TC__BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER TC_HEX (20)
|
||||
#define TC__BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE (TC_HEX (40) + TC_HEX (80))
|
||||
|
||||
// Modifying the following values can introduce incompatibility with previous versions
|
||||
#define TC__BOOT_USER_CFG_FLAG_SILENT_MODE TC_HEX (01)
|
||||
#define TC__BOOT_USER_CFG_FLAG_DISABLE_ESC TC_HEX (02)
|
||||
#define TC__BOOT_USER_CFG_FLAG_DISABLE_HW_ENCRYPTION TC_HEX (04)
|
||||
#define TC__BOOT_USER_CFG_FLAG_DISABLE_PIM TC_HEX (08)
|
||||
|
||||
// The following items are treated as a 2-bit value (apply TC_BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE to obtain the value)
|
||||
#define TC__HIDDEN_OS_CREATION_PHASE_NONE 0
|
||||
#define TC__HIDDEN_OS_CREATION_PHASE_CLONING TC_HEX (40) // The boot loader is to copy the content of the system partition to the hidden volume
|
||||
#define TC__HIDDEN_OS_CREATION_PHASE_WIPING TC_HEX (80) // The boot loader has successfully copied the content of the system partition to the hidden volume. The original OS is to be wiped now.
|
||||
#define TC__HIDDEN_OS_CREATION_PHASE_WIPED (TC_HEX (40) + TC_HEX (80)) // The original OS has been wiped. The user is required to install a new OS (decoy OS) on the system partition now.
|
||||
|
||||
|
||||
#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_SEGMENT_LOW = TC__BOOT_LOADER_SEGMENT_LOW
|
||||
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_ALT_SEGMENT = TC__BOOT_LOADER_ALT_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_SECTOR_USER_CONFIG_OFFSET = TC__BOOT_SECTOR_USER_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_AREA_SIZE = TC__BOOT_CFG_FLAG_AREA_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_ORIG_SYS_LOADER = TC__BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER
|
||||
TC_BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE = TC__BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE
|
||||
TC_BOOT_USER_CFG_FLAG_SILENT_MODE = TC__BOOT_USER_CFG_FLAG_SILENT_MODE
|
||||
TC_HIDDEN_OS_CREATION_PHASE_NONE = TC__HIDDEN_OS_CREATION_PHASE_NONE
|
||||
TC_HIDDEN_OS_CREATION_PHASE_CLONING = TC__HIDDEN_OS_CREATION_PHASE_CLONING
|
||||
TC_HIDDEN_OS_CREATION_PHASE_WIPING = TC__HIDDEN_OS_CREATION_PHASE_WIPING
|
||||
TC_HIDDEN_OS_CREATION_PHASE_WIPED = TC__HIDDEN_OS_CREATION_PHASE_WIPED
|
||||
|
||||
#else // TC_ASM_PREPROCESS
|
||||
|
||||
#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_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_ALT_SEGMENT TC__BOOT_LOADER_ALT_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_USER_MESSAGE_OFFSET TC__BOOT_SECTOR_USER_MESSAGE_OFFSET
|
||||
#define TC_BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_SIZE TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_SIZE
|
||||
#define TC_BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_OFFSET TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_OFFSET
|
||||
#define TC_BOOT_SECTOR_PIM_VALUE_SIZE TC__BOOT_SECTOR_PIM_VALUE_SIZE
|
||||
#define TC_BOOT_SECTOR_PIM_VALUE_OFFSET TC__BOOT_SECTOR_PIM_VALUE_OFFSET
|
||||
#define TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH TC__BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH
|
||||
#define TC_BOOT_SECTOR_VERSION_OFFSET TC__BOOT_SECTOR_VERSION_OFFSET
|
||||
#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_SECTOR_USER_CONFIG_OFFSET TC__BOOT_SECTOR_USER_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_AREA_SIZE TC__BOOT_CFG_FLAG_AREA_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_ORIG_SYS_LOADER TC__BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER
|
||||
#define TC_BOOT_CFG_FLAG_RESCUE_DISABLE_HW_ENCRYPTION TC__BOOT_CFG_FLAG_RESCUE_DISABLE_HW_ENCRYPTION
|
||||
#define TC_BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE TC__BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE
|
||||
#define TC_BOOT_USER_CFG_FLAG_SILENT_MODE TC__BOOT_USER_CFG_FLAG_SILENT_MODE
|
||||
#define TC_BOOT_USER_CFG_FLAG_DISABLE_ESC TC__BOOT_USER_CFG_FLAG_DISABLE_ESC
|
||||
#define TC_BOOT_USER_CFG_FLAG_DISABLE_HW_ENCRYPTION TC__BOOT_USER_CFG_FLAG_DISABLE_HW_ENCRYPTION
|
||||
#define TC_BOOT_USER_CFG_FLAG_DISABLE_PIM TC__BOOT_USER_CFG_FLAG_DISABLE_PIM
|
||||
#define TC_HIDDEN_OS_CREATION_PHASE_NONE TC__HIDDEN_OS_CREATION_PHASE_NONE
|
||||
#define TC_HIDDEN_OS_CREATION_PHASE_CLONING TC__HIDDEN_OS_CREATION_PHASE_CLONING
|
||||
#define TC_HIDDEN_OS_CREATION_PHASE_WIPING TC__HIDDEN_OS_CREATION_PHASE_WIPING
|
||||
#define TC_HIDDEN_OS_CREATION_PHASE_WIPED TC__HIDDEN_OS_CREATION_PHASE_WIPED
|
||||
|
||||
#endif // TC_ASM_PREPROCESS
|
||||
|
||||
#endif // TC_HEADER_Boot_BootDefs
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#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 43
|
||||
|
||||
#ifdef TC_WINDOWS_BOOT_SINGLE_CIPHER_MODE
|
||||
# undef TC__BOOT_MEMORY_REQUIRED
|
||||
|
||||
# ifdef TC_WINDOWS_BOOT_AES
|
||||
# ifdef TC_WINDOWS_BOOT_RESCUE_DISK_MODE
|
||||
# define TC__BOOT_MEMORY_REQUIRED 31
|
||||
# else
|
||||
# define TC__BOOT_MEMORY_REQUIRED 29
|
||||
# endif
|
||||
# elif defined (TC_WINDOWS_BOOT_SERPENT)
|
||||
# define TC__BOOT_MEMORY_REQUIRED 33
|
||||
# elif defined (TC_WINDOWS_BOOT_TWOFISH)
|
||||
# define TC__BOOT_MEMORY_REQUIRED 41
|
||||
# endif
|
||||
|
||||
#if 0
|
||||
# undef TC__BOOT_MEMORY_REQUIRED
|
||||
# define TC__BOOT_MEMORY_REQUIRED 60
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// Modifying this value can introduce incompatibility with previous versions
|
||||
#define TC__BOOT_LOADER_SEGMENT TC_HEX (9000) // Some buggy BIOS routines fail if CS bits 0-10 are not zero
|
||||
|
||||
#if TC__BOOT_MEMORY_REQUIRED <= 32
|
||||
# define TC__BOOT_LOADER_SEGMENT_LOW (TC__BOOT_LOADER_SEGMENT - 32 * 1024 / 16)
|
||||
#else
|
||||
# define TC__BOOT_LOADER_SEGMENT_LOW (TC__BOOT_LOADER_SEGMENT - 64 * 1024 / 16)
|
||||
#endif
|
||||
|
||||
#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 (4000)
|
||||
#define TC__BOOT_LOADER_ALT_SEGMENT TC_HEX (6000)
|
||||
|
||||
#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_VERSION_OFFSET 430
|
||||
#define TC__BOOT_SECTOR_LOADER_LENGTH_OFFSET 432
|
||||
#define TC__BOOT_SECTOR_LOADER_CHECKSUM_OFFSET 434
|
||||
#define TC__BOOT_SECTOR_USER_CONFIG_OFFSET 438
|
||||
#define TC__BOOT_SECTOR_CONFIG_OFFSET 439 // The last byte that is reserved for the boot loader
|
||||
|
||||
#define TC__BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH 24
|
||||
#define TC__BOOT_SECTOR_USER_MESSAGE_OFFSET (TC__BOOT_SECTOR_VERSION_OFFSET - TC__BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH)
|
||||
|
||||
#define TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_SIZE 4
|
||||
#define TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_OFFSET (TC__BOOT_SECTOR_USER_MESSAGE_OFFSET - TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_SIZE)
|
||||
|
||||
#define TC__BOOT_SECTOR_PIM_VALUE_SIZE 2
|
||||
#define TC__BOOT_SECTOR_PIM_VALUE_OFFSET (TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_OFFSET - TC__BOOT_SECTOR_PIM_VALUE_SIZE)
|
||||
|
||||
#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_AREA_SIZE 1 // In bytes
|
||||
|
||||
// If you add more flags, revise TC__BOOT_CFG_FLAG_AREA_SIZE
|
||||
#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_DISABLE_HW_ENCRYPTION TC_HEX (10)
|
||||
#define TC__BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER TC_HEX (20)
|
||||
#define TC__BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE (TC_HEX (40) + TC_HEX (80))
|
||||
|
||||
// Modifying the following values can introduce incompatibility with previous versions
|
||||
#define TC__BOOT_USER_CFG_FLAG_SILENT_MODE TC_HEX (01)
|
||||
#define TC__BOOT_USER_CFG_FLAG_DISABLE_ESC TC_HEX (02)
|
||||
#define TC__BOOT_USER_CFG_FLAG_DISABLE_HW_ENCRYPTION TC_HEX (04)
|
||||
#define TC__BOOT_USER_CFG_FLAG_DISABLE_PIM TC_HEX (08)
|
||||
|
||||
// The following items are treated as a 2-bit value (apply TC_BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE to obtain the value)
|
||||
#define TC__HIDDEN_OS_CREATION_PHASE_NONE 0
|
||||
#define TC__HIDDEN_OS_CREATION_PHASE_CLONING TC_HEX (40) // The boot loader is to copy the content of the system partition to the hidden volume
|
||||
#define TC__HIDDEN_OS_CREATION_PHASE_WIPING TC_HEX (80) // The boot loader has successfully copied the content of the system partition to the hidden volume. The original OS is to be wiped now.
|
||||
#define TC__HIDDEN_OS_CREATION_PHASE_WIPED (TC_HEX (40) + TC_HEX (80)) // The original OS has been wiped. The user is required to install a new OS (decoy OS) on the system partition now.
|
||||
|
||||
|
||||
#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_SEGMENT_LOW = TC__BOOT_LOADER_SEGMENT_LOW
|
||||
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_ALT_SEGMENT = TC__BOOT_LOADER_ALT_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_SECTOR_USER_CONFIG_OFFSET = TC__BOOT_SECTOR_USER_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_AREA_SIZE = TC__BOOT_CFG_FLAG_AREA_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_ORIG_SYS_LOADER = TC__BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER
|
||||
TC_BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE = TC__BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE
|
||||
TC_BOOT_USER_CFG_FLAG_SILENT_MODE = TC__BOOT_USER_CFG_FLAG_SILENT_MODE
|
||||
TC_HIDDEN_OS_CREATION_PHASE_NONE = TC__HIDDEN_OS_CREATION_PHASE_NONE
|
||||
TC_HIDDEN_OS_CREATION_PHASE_CLONING = TC__HIDDEN_OS_CREATION_PHASE_CLONING
|
||||
TC_HIDDEN_OS_CREATION_PHASE_WIPING = TC__HIDDEN_OS_CREATION_PHASE_WIPING
|
||||
TC_HIDDEN_OS_CREATION_PHASE_WIPED = TC__HIDDEN_OS_CREATION_PHASE_WIPED
|
||||
|
||||
#else // TC_ASM_PREPROCESS
|
||||
|
||||
#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_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_ALT_SEGMENT TC__BOOT_LOADER_ALT_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_USER_MESSAGE_OFFSET TC__BOOT_SECTOR_USER_MESSAGE_OFFSET
|
||||
#define TC_BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_SIZE TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_SIZE
|
||||
#define TC_BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_OFFSET TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_OFFSET
|
||||
#define TC_BOOT_SECTOR_PIM_VALUE_SIZE TC__BOOT_SECTOR_PIM_VALUE_SIZE
|
||||
#define TC_BOOT_SECTOR_PIM_VALUE_OFFSET TC__BOOT_SECTOR_PIM_VALUE_OFFSET
|
||||
#define TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH TC__BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH
|
||||
#define TC_BOOT_SECTOR_VERSION_OFFSET TC__BOOT_SECTOR_VERSION_OFFSET
|
||||
#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_SECTOR_USER_CONFIG_OFFSET TC__BOOT_SECTOR_USER_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_AREA_SIZE TC__BOOT_CFG_FLAG_AREA_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_ORIG_SYS_LOADER TC__BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER
|
||||
#define TC_BOOT_CFG_FLAG_RESCUE_DISABLE_HW_ENCRYPTION TC__BOOT_CFG_FLAG_RESCUE_DISABLE_HW_ENCRYPTION
|
||||
#define TC_BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE TC__BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE
|
||||
#define TC_BOOT_USER_CFG_FLAG_SILENT_MODE TC__BOOT_USER_CFG_FLAG_SILENT_MODE
|
||||
#define TC_BOOT_USER_CFG_FLAG_DISABLE_ESC TC__BOOT_USER_CFG_FLAG_DISABLE_ESC
|
||||
#define TC_BOOT_USER_CFG_FLAG_DISABLE_HW_ENCRYPTION TC__BOOT_USER_CFG_FLAG_DISABLE_HW_ENCRYPTION
|
||||
#define TC_BOOT_USER_CFG_FLAG_DISABLE_PIM TC__BOOT_USER_CFG_FLAG_DISABLE_PIM
|
||||
#define TC_HIDDEN_OS_CREATION_PHASE_NONE TC__HIDDEN_OS_CREATION_PHASE_NONE
|
||||
#define TC_HIDDEN_OS_CREATION_PHASE_CLONING TC__HIDDEN_OS_CREATION_PHASE_CLONING
|
||||
#define TC_HIDDEN_OS_CREATION_PHASE_WIPING TC__HIDDEN_OS_CREATION_PHASE_WIPING
|
||||
#define TC_HIDDEN_OS_CREATION_PHASE_WIPED TC__HIDDEN_OS_CREATION_PHASE_WIPED
|
||||
|
||||
#endif // TC_ASM_PREPROCESS
|
||||
|
||||
#endif // TC_HEADER_Boot_BootDefs
|
||||
|
||||
@@ -1,491 +1,491 @@
|
||||
/*
|
||||
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 "Bios.h"
|
||||
#include "BootConsoleIo.h"
|
||||
#include "BootConfig.h"
|
||||
#include "BootDebug.h"
|
||||
#include "BootDefs.h"
|
||||
#include "BootDiskIo.h"
|
||||
#include "BootStrings.h"
|
||||
|
||||
|
||||
byte SectorBuffer[TC_LB_SIZE];
|
||||
|
||||
#ifdef TC_BOOT_DEBUG_ENABLED
|
||||
static bool SectorBufferInUse = false;
|
||||
|
||||
void AcquireSectorBuffer ()
|
||||
{
|
||||
if (SectorBufferInUse)
|
||||
TC_THROW_FATAL_EXCEPTION;
|
||||
|
||||
SectorBufferInUse = true;
|
||||
}
|
||||
|
||||
|
||||
void ReleaseSectorBuffer ()
|
||||
{
|
||||
SectorBufferInUse = false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
bool IsLbaSupported (byte drive)
|
||||
{
|
||||
static byte CachedDrive = TC_INVALID_BIOS_DRIVE;
|
||||
static bool CachedStatus;
|
||||
uint16 result = 0;
|
||||
|
||||
if (CachedDrive == drive)
|
||||
goto ret;
|
||||
|
||||
__asm
|
||||
{
|
||||
mov bx, 0x55aa
|
||||
mov dl, drive
|
||||
mov ah, 0x41
|
||||
int 0x13
|
||||
jc err
|
||||
mov result, bx
|
||||
err:
|
||||
}
|
||||
|
||||
CachedDrive = drive;
|
||||
CachedStatus = (result == 0xaa55);
|
||||
ret:
|
||||
return CachedStatus;
|
||||
}
|
||||
|
||||
|
||||
void PrintDiskError (BiosResult error, bool write, byte drive, const uint64 *sector, const ChsAddress *chs)
|
||||
{
|
||||
PrintEndl();
|
||||
Print (write ? "Write" : "Read"); Print (" error:");
|
||||
Print (error);
|
||||
Print (" Drive:");
|
||||
Print (drive ^ 0x80);
|
||||
|
||||
if (sector)
|
||||
{
|
||||
Print (" Sector:");
|
||||
Print (*sector);
|
||||
}
|
||||
|
||||
if (chs)
|
||||
{
|
||||
Print (" CHS:");
|
||||
Print (*chs);
|
||||
}
|
||||
|
||||
PrintEndl();
|
||||
Beep();
|
||||
}
|
||||
|
||||
|
||||
void Print (const ChsAddress &chs)
|
||||
{
|
||||
Print (chs.Cylinder);
|
||||
PrintChar ('/');
|
||||
Print (chs.Head);
|
||||
PrintChar ('/');
|
||||
Print (chs.Sector);
|
||||
}
|
||||
|
||||
|
||||
void PrintSectorCountInMB (const uint64 §orCount)
|
||||
{
|
||||
Print (sectorCount >> (TC_LB_SIZE_BIT_SHIFT_DIVISOR + 2)); Print (" MB ");
|
||||
}
|
||||
|
||||
|
||||
BiosResult ReadWriteSectors (bool write, uint16 bufferSegment, uint16 bufferOffset, byte drive, const ChsAddress &chs, byte sectorCount, bool silent)
|
||||
{
|
||||
CheckStack();
|
||||
|
||||
byte cylinderLow = (byte) chs.Cylinder;
|
||||
byte sector = chs.Sector;
|
||||
sector |= byte (chs.Cylinder >> 2) & 0xc0;
|
||||
byte function = write ? 0x03 : 0x02;
|
||||
|
||||
BiosResult result;
|
||||
byte tryCount = TC_MAX_BIOS_DISK_IO_RETRIES;
|
||||
|
||||
do
|
||||
{
|
||||
result = BiosResultSuccess;
|
||||
|
||||
__asm
|
||||
{
|
||||
push es
|
||||
mov ax, bufferSegment
|
||||
mov es, ax
|
||||
mov bx, bufferOffset
|
||||
mov dl, drive
|
||||
mov ch, cylinderLow
|
||||
mov si, chs
|
||||
mov dh, [si].Head
|
||||
mov cl, sector
|
||||
mov al, sectorCount
|
||||
mov ah, function
|
||||
int 0x13
|
||||
jnc ok // If CF=0, ignore AH to prevent issues caused by potential bugs in BIOSes
|
||||
mov result, ah
|
||||
ok:
|
||||
pop es
|
||||
}
|
||||
|
||||
if (result == BiosResultEccCorrected)
|
||||
result = BiosResultSuccess;
|
||||
|
||||
// Some BIOSes report I/O errors prematurely in some cases
|
||||
} while (result != BiosResultSuccess && --tryCount != 0);
|
||||
|
||||
if (!silent && result != BiosResultSuccess)
|
||||
PrintDiskError (result, write, drive, nullptr, &chs);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
BiosResult ReadWriteSectors (bool write, byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent)
|
||||
{
|
||||
uint16 codeSeg;
|
||||
__asm mov codeSeg, cs
|
||||
return ReadWriteSectors (write, codeSeg, (uint16) buffer, drive, chs, sectorCount, silent);
|
||||
}
|
||||
|
||||
|
||||
BiosResult ReadSectors (byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent)
|
||||
{
|
||||
return ReadWriteSectors (false, buffer, drive, chs, sectorCount, silent);
|
||||
}
|
||||
|
||||
|
||||
BiosResult WriteSectors (byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent)
|
||||
{
|
||||
return ReadWriteSectors (true, buffer, drive, chs, sectorCount, silent);
|
||||
}
|
||||
|
||||
|
||||
static BiosResult ReadWriteSectors (bool write, BiosLbaPacket &dapPacket, byte drive, const uint64 §or, uint16 sectorCount, bool silent)
|
||||
{
|
||||
CheckStack();
|
||||
|
||||
if (!IsLbaSupported (drive))
|
||||
{
|
||||
DriveGeometry geometry;
|
||||
|
||||
BiosResult result = GetDriveGeometry (drive, geometry, silent);
|
||||
if (result != BiosResultSuccess)
|
||||
return result;
|
||||
|
||||
ChsAddress chs;
|
||||
LbaToChs (geometry, sector, chs);
|
||||
return ReadWriteSectors (write, (uint16) (dapPacket.Buffer >> 16), (uint16) dapPacket.Buffer, drive, chs, sectorCount, silent);
|
||||
}
|
||||
|
||||
dapPacket.Size = sizeof (dapPacket);
|
||||
dapPacket.Reserved = 0;
|
||||
dapPacket.SectorCount = sectorCount;
|
||||
dapPacket.Sector = sector;
|
||||
|
||||
byte function = write ? 0x43 : 0x42;
|
||||
|
||||
BiosResult result;
|
||||
byte tryCount = TC_MAX_BIOS_DISK_IO_RETRIES;
|
||||
|
||||
do
|
||||
{
|
||||
result = BiosResultSuccess;
|
||||
|
||||
__asm
|
||||
{
|
||||
mov bx, 0x55aa
|
||||
mov dl, drive
|
||||
mov si, [dapPacket]
|
||||
mov ah, function
|
||||
xor al, al
|
||||
int 0x13
|
||||
jnc ok // If CF=0, ignore AH to prevent issues caused by potential bugs in BIOSes
|
||||
mov result, ah
|
||||
ok:
|
||||
}
|
||||
|
||||
if (result == BiosResultEccCorrected)
|
||||
result = BiosResultSuccess;
|
||||
|
||||
// Some BIOSes report I/O errors prematurely in some cases
|
||||
} while (result != BiosResultSuccess && --tryCount != 0);
|
||||
|
||||
if (!silent && result != BiosResultSuccess)
|
||||
PrintDiskError (result, write, drive, §or);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static BiosResult ReadWriteSectors (bool write, byte *buffer, byte drive, const uint64 §or, uint16 sectorCount, bool silent)
|
||||
{
|
||||
BiosLbaPacket dapPacket;
|
||||
dapPacket.Buffer = (uint32) buffer;
|
||||
return ReadWriteSectors (write, dapPacket, drive, sector, sectorCount, silent);
|
||||
}
|
||||
|
||||
|
||||
BiosResult ReadWriteSectors (bool write, uint16 bufferSegment, uint16 bufferOffset, byte drive, const uint64 §or, uint16 sectorCount, bool silent)
|
||||
{
|
||||
BiosLbaPacket dapPacket;
|
||||
dapPacket.Buffer = ((uint32) bufferSegment << 16) | bufferOffset;
|
||||
return ReadWriteSectors (write, dapPacket, drive, sector, sectorCount, silent);
|
||||
}
|
||||
|
||||
BiosResult ReadSectors (uint16 bufferSegment, uint16 bufferOffset, byte drive, const uint64 §or, uint16 sectorCount, bool silent)
|
||||
{
|
||||
return ReadWriteSectors (false, bufferSegment, bufferOffset, drive, sector, sectorCount, silent);
|
||||
}
|
||||
|
||||
|
||||
BiosResult ReadSectors (byte *buffer, byte drive, const uint64 §or, uint16 sectorCount, bool silent)
|
||||
{
|
||||
BiosResult result;
|
||||
uint16 codeSeg;
|
||||
__asm mov codeSeg, cs
|
||||
|
||||
result = ReadSectors (BootStarted ? codeSeg : TC_BOOT_LOADER_ALT_SEGMENT, (uint16) buffer, drive, sector, sectorCount, silent);
|
||||
|
||||
// Alternative segment is used to prevent memory corruption caused by buggy BIOSes
|
||||
if (!BootStarted)
|
||||
CopyMemory (TC_BOOT_LOADER_ALT_SEGMENT, (uint16) buffer, buffer, sectorCount * TC_LB_SIZE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
BiosResult WriteSectors (byte *buffer, byte drive, const uint64 §or, uint16 sectorCount, bool silent)
|
||||
{
|
||||
return ReadWriteSectors (true, buffer, drive, sector, sectorCount, silent);
|
||||
}
|
||||
|
||||
|
||||
BiosResult GetDriveGeometry (byte drive, DriveGeometry &geometry, bool silent)
|
||||
{
|
||||
CheckStack();
|
||||
|
||||
byte maxCylinderLow, maxHead, maxSector;
|
||||
BiosResult result;
|
||||
__asm
|
||||
{
|
||||
push es
|
||||
mov dl, drive
|
||||
mov ah, 0x08
|
||||
int 0x13
|
||||
|
||||
mov result, ah
|
||||
mov maxCylinderLow, ch
|
||||
mov maxSector, cl
|
||||
mov maxHead, dh
|
||||
pop es
|
||||
}
|
||||
|
||||
if (result == BiosResultSuccess)
|
||||
{
|
||||
geometry.Cylinders = (maxCylinderLow | (uint16 (maxSector & 0xc0) << 2)) + 1;
|
||||
geometry.Heads = maxHead + 1;
|
||||
geometry.Sectors = maxSector & ~0xc0;
|
||||
}
|
||||
else if (!silent)
|
||||
{
|
||||
Print ("Drive ");
|
||||
Print (drive ^ 0x80);
|
||||
Print (" not found: ");
|
||||
PrintErrorNoEndl ("");
|
||||
Print (result);
|
||||
PrintEndl();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void ChsToLba (const DriveGeometry &geometry, const ChsAddress &chs, uint64 &lba)
|
||||
{
|
||||
lba.HighPart = 0;
|
||||
lba.LowPart = (uint32 (chs.Cylinder) * geometry.Heads + chs.Head) * geometry.Sectors + chs.Sector - 1;
|
||||
}
|
||||
|
||||
|
||||
void LbaToChs (const DriveGeometry &geometry, const uint64 &lba, ChsAddress &chs)
|
||||
{
|
||||
chs.Sector = (byte) ((lba.LowPart % geometry.Sectors) + 1);
|
||||
uint32 ch = lba.LowPart / geometry.Sectors;
|
||||
chs.Head = (byte) (ch % geometry.Heads);
|
||||
chs.Cylinder = (uint16) (ch / geometry.Heads);
|
||||
}
|
||||
|
||||
|
||||
void PartitionEntryMBRToPartition (const PartitionEntryMBR &partEntry, Partition &partition)
|
||||
{
|
||||
partition.Active = partEntry.BootIndicator == 0x80;
|
||||
partition.EndSector.HighPart = 0;
|
||||
partition.EndSector.LowPart = partEntry.StartLBA + partEntry.SectorCountLBA - 1;
|
||||
partition.SectorCount.HighPart = 0;
|
||||
partition.SectorCount.LowPart = partEntry.SectorCountLBA;
|
||||
partition.StartSector.HighPart = 0;
|
||||
partition.StartSector.LowPart = partEntry.StartLBA;
|
||||
partition.Type = partEntry.Type;
|
||||
}
|
||||
|
||||
|
||||
BiosResult ReadWriteMBR (bool write, byte drive, bool silent)
|
||||
{
|
||||
uint64 mbrSector;
|
||||
mbrSector.HighPart = 0;
|
||||
mbrSector.LowPart = 0;
|
||||
|
||||
if (write)
|
||||
return WriteSectors (SectorBuffer, drive, mbrSector, 1, silent);
|
||||
|
||||
return ReadSectors (SectorBuffer, drive, mbrSector, 1, silent); // Uses alternative segment
|
||||
}
|
||||
|
||||
|
||||
BiosResult GetDrivePartitions (byte drive, Partition *partitionArray, size_t partitionArrayCapacity, size_t &partitionCount, bool activeOnly, Partition *findPartitionFollowingThis, bool silent)
|
||||
{
|
||||
Partition *followingPartition;
|
||||
Partition tmpPartition;
|
||||
|
||||
if (findPartitionFollowingThis)
|
||||
{
|
||||
assert (partitionArrayCapacity == 1);
|
||||
partitionArrayCapacity = 0xff;
|
||||
followingPartition = partitionArray;
|
||||
partitionArray = &tmpPartition;
|
||||
|
||||
followingPartition->Drive = TC_INVALID_BIOS_DRIVE;
|
||||
followingPartition->StartSector.LowPart = 0xFFFFffffUL;
|
||||
}
|
||||
|
||||
AcquireSectorBuffer();
|
||||
BiosResult result = ReadWriteMBR (false, drive, silent);
|
||||
ReleaseSectorBuffer();
|
||||
|
||||
partitionCount = 0;
|
||||
|
||||
MBR *mbr = (MBR *) SectorBuffer;
|
||||
if (result != BiosResultSuccess || mbr->Signature != 0xaa55)
|
||||
return result;
|
||||
|
||||
PartitionEntryMBR mbrPartitions[4];
|
||||
memcpy (mbrPartitions, mbr->Partitions, sizeof (mbrPartitions));
|
||||
size_t partitionArrayPos = 0, partitionNumber;
|
||||
|
||||
for (partitionNumber = 0;
|
||||
partitionNumber < array_capacity (mbrPartitions) && partitionArrayPos < partitionArrayCapacity;
|
||||
++partitionNumber)
|
||||
{
|
||||
const PartitionEntryMBR &partEntry = mbrPartitions[partitionNumber];
|
||||
|
||||
if (partEntry.SectorCountLBA > 0)
|
||||
{
|
||||
Partition &partition = partitionArray[partitionArrayPos];
|
||||
PartitionEntryMBRToPartition (partEntry, partition);
|
||||
|
||||
if (activeOnly && !partition.Active)
|
||||
continue;
|
||||
|
||||
partition.Drive = drive;
|
||||
partition.Number = partitionArrayPos;
|
||||
|
||||
if (partEntry.Type == 0x5 || partEntry.Type == 0xf) // Extended partition
|
||||
{
|
||||
if (IsLbaSupported (drive))
|
||||
{
|
||||
// Find all extended partitions
|
||||
uint64 firstExtStartLBA = partition.StartSector;
|
||||
uint64 extStartLBA = partition.StartSector;
|
||||
MBR *extMbr = (MBR *) SectorBuffer;
|
||||
|
||||
while (partitionArrayPos < partitionArrayCapacity &&
|
||||
(result = ReadSectors ((byte *) extMbr, drive, extStartLBA, 1, silent)) == BiosResultSuccess
|
||||
&& extMbr->Signature == 0xaa55)
|
||||
{
|
||||
if (extMbr->Partitions[0].SectorCountLBA > 0)
|
||||
{
|
||||
Partition &logPart = partitionArray[partitionArrayPos];
|
||||
PartitionEntryMBRToPartition (extMbr->Partitions[0], logPart);
|
||||
logPart.Drive = drive;
|
||||
|
||||
logPart.Number = partitionArrayPos;
|
||||
logPart.Primary = false;
|
||||
|
||||
logPart.StartSector.LowPart += extStartLBA.LowPart;
|
||||
logPart.EndSector.LowPart += extStartLBA.LowPart;
|
||||
|
||||
if (findPartitionFollowingThis)
|
||||
{
|
||||
if (logPart.StartSector.LowPart > findPartitionFollowingThis->EndSector.LowPart
|
||||
&& logPart.StartSector.LowPart < followingPartition->StartSector.LowPart)
|
||||
{
|
||||
*followingPartition = logPart;
|
||||
}
|
||||
}
|
||||
else
|
||||
++partitionArrayPos;
|
||||
}
|
||||
|
||||
// Secondary extended
|
||||
if (extMbr->Partitions[1].Type != 0x5 && extMbr->Partitions[1].Type == 0xf
|
||||
|| extMbr->Partitions[1].SectorCountLBA == 0)
|
||||
break;
|
||||
|
||||
extStartLBA.LowPart = extMbr->Partitions[1].StartLBA + firstExtStartLBA.LowPart;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
partition.Primary = true;
|
||||
|
||||
if (findPartitionFollowingThis)
|
||||
{
|
||||
if (partition.StartSector.LowPart > findPartitionFollowingThis->EndSector.LowPart
|
||||
&& partition.StartSector.LowPart < followingPartition->StartSector.LowPart)
|
||||
{
|
||||
*followingPartition = partition;
|
||||
}
|
||||
}
|
||||
else
|
||||
++partitionArrayPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
partitionCount = partitionArrayPos;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool GetActivePartition (byte drive)
|
||||
{
|
||||
size_t partCount;
|
||||
|
||||
if (GetDrivePartitions (drive, &ActivePartition, 1, partCount, true) != BiosResultSuccess || partCount < 1)
|
||||
{
|
||||
ActivePartition.Drive = TC_INVALID_BIOS_DRIVE;
|
||||
PrintError (TC_BOOT_STR_NO_BOOT_PARTITION);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
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 "Bios.h"
|
||||
#include "BootConsoleIo.h"
|
||||
#include "BootConfig.h"
|
||||
#include "BootDebug.h"
|
||||
#include "BootDefs.h"
|
||||
#include "BootDiskIo.h"
|
||||
#include "BootStrings.h"
|
||||
|
||||
|
||||
byte SectorBuffer[TC_LB_SIZE];
|
||||
|
||||
#ifdef TC_BOOT_DEBUG_ENABLED
|
||||
static bool SectorBufferInUse = false;
|
||||
|
||||
void AcquireSectorBuffer ()
|
||||
{
|
||||
if (SectorBufferInUse)
|
||||
TC_THROW_FATAL_EXCEPTION;
|
||||
|
||||
SectorBufferInUse = true;
|
||||
}
|
||||
|
||||
|
||||
void ReleaseSectorBuffer ()
|
||||
{
|
||||
SectorBufferInUse = false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
bool IsLbaSupported (byte drive)
|
||||
{
|
||||
static byte CachedDrive = TC_INVALID_BIOS_DRIVE;
|
||||
static bool CachedStatus;
|
||||
uint16 result = 0;
|
||||
|
||||
if (CachedDrive == drive)
|
||||
goto ret;
|
||||
|
||||
__asm
|
||||
{
|
||||
mov bx, 0x55aa
|
||||
mov dl, drive
|
||||
mov ah, 0x41
|
||||
int 0x13
|
||||
jc err
|
||||
mov result, bx
|
||||
err:
|
||||
}
|
||||
|
||||
CachedDrive = drive;
|
||||
CachedStatus = (result == 0xaa55);
|
||||
ret:
|
||||
return CachedStatus;
|
||||
}
|
||||
|
||||
|
||||
void PrintDiskError (BiosResult error, bool write, byte drive, const uint64 *sector, const ChsAddress *chs)
|
||||
{
|
||||
PrintEndl();
|
||||
Print (write ? "Write" : "Read"); Print (" error:");
|
||||
Print (error);
|
||||
Print (" Drive:");
|
||||
Print (drive ^ 0x80);
|
||||
|
||||
if (sector)
|
||||
{
|
||||
Print (" Sector:");
|
||||
Print (*sector);
|
||||
}
|
||||
|
||||
if (chs)
|
||||
{
|
||||
Print (" CHS:");
|
||||
Print (*chs);
|
||||
}
|
||||
|
||||
PrintEndl();
|
||||
Beep();
|
||||
}
|
||||
|
||||
|
||||
void Print (const ChsAddress &chs)
|
||||
{
|
||||
Print (chs.Cylinder);
|
||||
PrintChar ('/');
|
||||
Print (chs.Head);
|
||||
PrintChar ('/');
|
||||
Print (chs.Sector);
|
||||
}
|
||||
|
||||
|
||||
void PrintSectorCountInMB (const uint64 §orCount)
|
||||
{
|
||||
Print (sectorCount >> (TC_LB_SIZE_BIT_SHIFT_DIVISOR + 2)); Print (" MB ");
|
||||
}
|
||||
|
||||
|
||||
BiosResult ReadWriteSectors (bool write, uint16 bufferSegment, uint16 bufferOffset, byte drive, const ChsAddress &chs, byte sectorCount, bool silent)
|
||||
{
|
||||
CheckStack();
|
||||
|
||||
byte cylinderLow = (byte) chs.Cylinder;
|
||||
byte sector = chs.Sector;
|
||||
sector |= byte (chs.Cylinder >> 2) & 0xc0;
|
||||
byte function = write ? 0x03 : 0x02;
|
||||
|
||||
BiosResult result;
|
||||
byte tryCount = TC_MAX_BIOS_DISK_IO_RETRIES;
|
||||
|
||||
do
|
||||
{
|
||||
result = BiosResultSuccess;
|
||||
|
||||
__asm
|
||||
{
|
||||
push es
|
||||
mov ax, bufferSegment
|
||||
mov es, ax
|
||||
mov bx, bufferOffset
|
||||
mov dl, drive
|
||||
mov ch, cylinderLow
|
||||
mov si, chs
|
||||
mov dh, [si].Head
|
||||
mov cl, sector
|
||||
mov al, sectorCount
|
||||
mov ah, function
|
||||
int 0x13
|
||||
jnc ok // If CF=0, ignore AH to prevent issues caused by potential bugs in BIOSes
|
||||
mov result, ah
|
||||
ok:
|
||||
pop es
|
||||
}
|
||||
|
||||
if (result == BiosResultEccCorrected)
|
||||
result = BiosResultSuccess;
|
||||
|
||||
// Some BIOSes report I/O errors prematurely in some cases
|
||||
} while (result != BiosResultSuccess && --tryCount != 0);
|
||||
|
||||
if (!silent && result != BiosResultSuccess)
|
||||
PrintDiskError (result, write, drive, nullptr, &chs);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
BiosResult ReadWriteSectors (bool write, byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent)
|
||||
{
|
||||
uint16 codeSeg;
|
||||
__asm mov codeSeg, cs
|
||||
return ReadWriteSectors (write, codeSeg, (uint16) buffer, drive, chs, sectorCount, silent);
|
||||
}
|
||||
|
||||
|
||||
BiosResult ReadSectors (byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent)
|
||||
{
|
||||
return ReadWriteSectors (false, buffer, drive, chs, sectorCount, silent);
|
||||
}
|
||||
|
||||
|
||||
BiosResult WriteSectors (byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent)
|
||||
{
|
||||
return ReadWriteSectors (true, buffer, drive, chs, sectorCount, silent);
|
||||
}
|
||||
|
||||
|
||||
static BiosResult ReadWriteSectors (bool write, BiosLbaPacket &dapPacket, byte drive, const uint64 §or, uint16 sectorCount, bool silent)
|
||||
{
|
||||
CheckStack();
|
||||
|
||||
if (!IsLbaSupported (drive))
|
||||
{
|
||||
DriveGeometry geometry;
|
||||
|
||||
BiosResult result = GetDriveGeometry (drive, geometry, silent);
|
||||
if (result != BiosResultSuccess)
|
||||
return result;
|
||||
|
||||
ChsAddress chs;
|
||||
LbaToChs (geometry, sector, chs);
|
||||
return ReadWriteSectors (write, (uint16) (dapPacket.Buffer >> 16), (uint16) dapPacket.Buffer, drive, chs, sectorCount, silent);
|
||||
}
|
||||
|
||||
dapPacket.Size = sizeof (dapPacket);
|
||||
dapPacket.Reserved = 0;
|
||||
dapPacket.SectorCount = sectorCount;
|
||||
dapPacket.Sector = sector;
|
||||
|
||||
byte function = write ? 0x43 : 0x42;
|
||||
|
||||
BiosResult result;
|
||||
byte tryCount = TC_MAX_BIOS_DISK_IO_RETRIES;
|
||||
|
||||
do
|
||||
{
|
||||
result = BiosResultSuccess;
|
||||
|
||||
__asm
|
||||
{
|
||||
mov bx, 0x55aa
|
||||
mov dl, drive
|
||||
mov si, [dapPacket]
|
||||
mov ah, function
|
||||
xor al, al
|
||||
int 0x13
|
||||
jnc ok // If CF=0, ignore AH to prevent issues caused by potential bugs in BIOSes
|
||||
mov result, ah
|
||||
ok:
|
||||
}
|
||||
|
||||
if (result == BiosResultEccCorrected)
|
||||
result = BiosResultSuccess;
|
||||
|
||||
// Some BIOSes report I/O errors prematurely in some cases
|
||||
} while (result != BiosResultSuccess && --tryCount != 0);
|
||||
|
||||
if (!silent && result != BiosResultSuccess)
|
||||
PrintDiskError (result, write, drive, §or);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static BiosResult ReadWriteSectors (bool write, byte *buffer, byte drive, const uint64 §or, uint16 sectorCount, bool silent)
|
||||
{
|
||||
BiosLbaPacket dapPacket;
|
||||
dapPacket.Buffer = (uint32) buffer;
|
||||
return ReadWriteSectors (write, dapPacket, drive, sector, sectorCount, silent);
|
||||
}
|
||||
|
||||
|
||||
BiosResult ReadWriteSectors (bool write, uint16 bufferSegment, uint16 bufferOffset, byte drive, const uint64 §or, uint16 sectorCount, bool silent)
|
||||
{
|
||||
BiosLbaPacket dapPacket;
|
||||
dapPacket.Buffer = ((uint32) bufferSegment << 16) | bufferOffset;
|
||||
return ReadWriteSectors (write, dapPacket, drive, sector, sectorCount, silent);
|
||||
}
|
||||
|
||||
BiosResult ReadSectors (uint16 bufferSegment, uint16 bufferOffset, byte drive, const uint64 §or, uint16 sectorCount, bool silent)
|
||||
{
|
||||
return ReadWriteSectors (false, bufferSegment, bufferOffset, drive, sector, sectorCount, silent);
|
||||
}
|
||||
|
||||
|
||||
BiosResult ReadSectors (byte *buffer, byte drive, const uint64 §or, uint16 sectorCount, bool silent)
|
||||
{
|
||||
BiosResult result;
|
||||
uint16 codeSeg;
|
||||
__asm mov codeSeg, cs
|
||||
|
||||
result = ReadSectors (BootStarted ? codeSeg : TC_BOOT_LOADER_ALT_SEGMENT, (uint16) buffer, drive, sector, sectorCount, silent);
|
||||
|
||||
// Alternative segment is used to prevent memory corruption caused by buggy BIOSes
|
||||
if (!BootStarted)
|
||||
CopyMemory (TC_BOOT_LOADER_ALT_SEGMENT, (uint16) buffer, buffer, sectorCount * TC_LB_SIZE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
BiosResult WriteSectors (byte *buffer, byte drive, const uint64 §or, uint16 sectorCount, bool silent)
|
||||
{
|
||||
return ReadWriteSectors (true, buffer, drive, sector, sectorCount, silent);
|
||||
}
|
||||
|
||||
|
||||
BiosResult GetDriveGeometry (byte drive, DriveGeometry &geometry, bool silent)
|
||||
{
|
||||
CheckStack();
|
||||
|
||||
byte maxCylinderLow, maxHead, maxSector;
|
||||
BiosResult result;
|
||||
__asm
|
||||
{
|
||||
push es
|
||||
mov dl, drive
|
||||
mov ah, 0x08
|
||||
int 0x13
|
||||
|
||||
mov result, ah
|
||||
mov maxCylinderLow, ch
|
||||
mov maxSector, cl
|
||||
mov maxHead, dh
|
||||
pop es
|
||||
}
|
||||
|
||||
if (result == BiosResultSuccess)
|
||||
{
|
||||
geometry.Cylinders = (maxCylinderLow | (uint16 (maxSector & 0xc0) << 2)) + 1;
|
||||
geometry.Heads = maxHead + 1;
|
||||
geometry.Sectors = maxSector & ~0xc0;
|
||||
}
|
||||
else if (!silent)
|
||||
{
|
||||
Print ("Drive ");
|
||||
Print (drive ^ 0x80);
|
||||
Print (" not found: ");
|
||||
PrintErrorNoEndl ("");
|
||||
Print (result);
|
||||
PrintEndl();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void ChsToLba (const DriveGeometry &geometry, const ChsAddress &chs, uint64 &lba)
|
||||
{
|
||||
lba.HighPart = 0;
|
||||
lba.LowPart = (uint32 (chs.Cylinder) * geometry.Heads + chs.Head) * geometry.Sectors + chs.Sector - 1;
|
||||
}
|
||||
|
||||
|
||||
void LbaToChs (const DriveGeometry &geometry, const uint64 &lba, ChsAddress &chs)
|
||||
{
|
||||
chs.Sector = (byte) ((lba.LowPart % geometry.Sectors) + 1);
|
||||
uint32 ch = lba.LowPart / geometry.Sectors;
|
||||
chs.Head = (byte) (ch % geometry.Heads);
|
||||
chs.Cylinder = (uint16) (ch / geometry.Heads);
|
||||
}
|
||||
|
||||
|
||||
void PartitionEntryMBRToPartition (const PartitionEntryMBR &partEntry, Partition &partition)
|
||||
{
|
||||
partition.Active = partEntry.BootIndicator == 0x80;
|
||||
partition.EndSector.HighPart = 0;
|
||||
partition.EndSector.LowPart = partEntry.StartLBA + partEntry.SectorCountLBA - 1;
|
||||
partition.SectorCount.HighPart = 0;
|
||||
partition.SectorCount.LowPart = partEntry.SectorCountLBA;
|
||||
partition.StartSector.HighPart = 0;
|
||||
partition.StartSector.LowPart = partEntry.StartLBA;
|
||||
partition.Type = partEntry.Type;
|
||||
}
|
||||
|
||||
|
||||
BiosResult ReadWriteMBR (bool write, byte drive, bool silent)
|
||||
{
|
||||
uint64 mbrSector;
|
||||
mbrSector.HighPart = 0;
|
||||
mbrSector.LowPart = 0;
|
||||
|
||||
if (write)
|
||||
return WriteSectors (SectorBuffer, drive, mbrSector, 1, silent);
|
||||
|
||||
return ReadSectors (SectorBuffer, drive, mbrSector, 1, silent); // Uses alternative segment
|
||||
}
|
||||
|
||||
|
||||
BiosResult GetDrivePartitions (byte drive, Partition *partitionArray, size_t partitionArrayCapacity, size_t &partitionCount, bool activeOnly, Partition *findPartitionFollowingThis, bool silent)
|
||||
{
|
||||
Partition *followingPartition;
|
||||
Partition tmpPartition;
|
||||
|
||||
if (findPartitionFollowingThis)
|
||||
{
|
||||
assert (partitionArrayCapacity == 1);
|
||||
partitionArrayCapacity = 0xff;
|
||||
followingPartition = partitionArray;
|
||||
partitionArray = &tmpPartition;
|
||||
|
||||
followingPartition->Drive = TC_INVALID_BIOS_DRIVE;
|
||||
followingPartition->StartSector.LowPart = 0xFFFFffffUL;
|
||||
}
|
||||
|
||||
AcquireSectorBuffer();
|
||||
BiosResult result = ReadWriteMBR (false, drive, silent);
|
||||
ReleaseSectorBuffer();
|
||||
|
||||
partitionCount = 0;
|
||||
|
||||
MBR *mbr = (MBR *) SectorBuffer;
|
||||
if (result != BiosResultSuccess || mbr->Signature != 0xaa55)
|
||||
return result;
|
||||
|
||||
PartitionEntryMBR mbrPartitions[4];
|
||||
memcpy (mbrPartitions, mbr->Partitions, sizeof (mbrPartitions));
|
||||
size_t partitionArrayPos = 0, partitionNumber;
|
||||
|
||||
for (partitionNumber = 0;
|
||||
partitionNumber < array_capacity (mbrPartitions) && partitionArrayPos < partitionArrayCapacity;
|
||||
++partitionNumber)
|
||||
{
|
||||
const PartitionEntryMBR &partEntry = mbrPartitions[partitionNumber];
|
||||
|
||||
if (partEntry.SectorCountLBA > 0)
|
||||
{
|
||||
Partition &partition = partitionArray[partitionArrayPos];
|
||||
PartitionEntryMBRToPartition (partEntry, partition);
|
||||
|
||||
if (activeOnly && !partition.Active)
|
||||
continue;
|
||||
|
||||
partition.Drive = drive;
|
||||
partition.Number = partitionArrayPos;
|
||||
|
||||
if (partEntry.Type == 0x5 || partEntry.Type == 0xf) // Extended partition
|
||||
{
|
||||
if (IsLbaSupported (drive))
|
||||
{
|
||||
// Find all extended partitions
|
||||
uint64 firstExtStartLBA = partition.StartSector;
|
||||
uint64 extStartLBA = partition.StartSector;
|
||||
MBR *extMbr = (MBR *) SectorBuffer;
|
||||
|
||||
while (partitionArrayPos < partitionArrayCapacity &&
|
||||
(result = ReadSectors ((byte *) extMbr, drive, extStartLBA, 1, silent)) == BiosResultSuccess
|
||||
&& extMbr->Signature == 0xaa55)
|
||||
{
|
||||
if (extMbr->Partitions[0].SectorCountLBA > 0)
|
||||
{
|
||||
Partition &logPart = partitionArray[partitionArrayPos];
|
||||
PartitionEntryMBRToPartition (extMbr->Partitions[0], logPart);
|
||||
logPart.Drive = drive;
|
||||
|
||||
logPart.Number = partitionArrayPos;
|
||||
logPart.Primary = false;
|
||||
|
||||
logPart.StartSector.LowPart += extStartLBA.LowPart;
|
||||
logPart.EndSector.LowPart += extStartLBA.LowPart;
|
||||
|
||||
if (findPartitionFollowingThis)
|
||||
{
|
||||
if (logPart.StartSector.LowPart > findPartitionFollowingThis->EndSector.LowPart
|
||||
&& logPart.StartSector.LowPart < followingPartition->StartSector.LowPart)
|
||||
{
|
||||
*followingPartition = logPart;
|
||||
}
|
||||
}
|
||||
else
|
||||
++partitionArrayPos;
|
||||
}
|
||||
|
||||
// Secondary extended
|
||||
if (extMbr->Partitions[1].Type != 0x5 && extMbr->Partitions[1].Type == 0xf
|
||||
|| extMbr->Partitions[1].SectorCountLBA == 0)
|
||||
break;
|
||||
|
||||
extStartLBA.LowPart = extMbr->Partitions[1].StartLBA + firstExtStartLBA.LowPart;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
partition.Primary = true;
|
||||
|
||||
if (findPartitionFollowingThis)
|
||||
{
|
||||
if (partition.StartSector.LowPart > findPartitionFollowingThis->EndSector.LowPart
|
||||
&& partition.StartSector.LowPart < followingPartition->StartSector.LowPart)
|
||||
{
|
||||
*followingPartition = partition;
|
||||
}
|
||||
}
|
||||
else
|
||||
++partitionArrayPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
partitionCount = partitionArrayPos;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool GetActivePartition (byte drive)
|
||||
{
|
||||
size_t partCount;
|
||||
|
||||
if (GetDrivePartitions (drive, &ActivePartition, 1, partCount, true) != BiosResultSuccess || partCount < 1)
|
||||
{
|
||||
ActivePartition.Drive = TC_INVALID_BIOS_DRIVE;
|
||||
PrintError (TC_BOOT_STR_NO_BOOT_PARTITION);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,120 +1,120 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Boot_BootDiskIo
|
||||
#define TC_HEADER_Boot_BootDiskIo
|
||||
|
||||
#include "Bios.h"
|
||||
#include "BootDebug.h"
|
||||
#include "BootDefs.h"
|
||||
|
||||
#define TC_MAX_BIOS_DISK_IO_RETRIES 5
|
||||
|
||||
enum
|
||||
{
|
||||
BiosResultEccCorrected = 0x11
|
||||
};
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
struct PartitionEntryMBR
|
||||
{
|
||||
byte BootIndicator;
|
||||
|
||||
byte StartHead;
|
||||
byte StartCylSector;
|
||||
byte StartCylinder;
|
||||
|
||||
byte Type;
|
||||
|
||||
byte EndHead;
|
||||
byte EndSector;
|
||||
byte EndCylinder;
|
||||
|
||||
uint32 StartLBA;
|
||||
uint32 SectorCountLBA;
|
||||
};
|
||||
|
||||
struct MBR
|
||||
{
|
||||
byte Code[446];
|
||||
PartitionEntryMBR Partitions[4];
|
||||
uint16 Signature;
|
||||
};
|
||||
|
||||
struct BiosLbaPacket
|
||||
{
|
||||
byte Size;
|
||||
byte Reserved;
|
||||
uint16 SectorCount;
|
||||
uint32 Buffer;
|
||||
uint64 Sector;
|
||||
};
|
||||
|
||||
#pragma pack()
|
||||
|
||||
|
||||
struct ChsAddress
|
||||
{
|
||||
uint16 Cylinder;
|
||||
byte Head;
|
||||
byte Sector;
|
||||
};
|
||||
|
||||
struct Partition
|
||||
{
|
||||
byte Number;
|
||||
byte Drive;
|
||||
bool Active;
|
||||
uint64 EndSector;
|
||||
bool Primary;
|
||||
uint64 SectorCount;
|
||||
uint64 StartSector;
|
||||
byte Type;
|
||||
};
|
||||
|
||||
struct DriveGeometry
|
||||
{
|
||||
uint16 Cylinders;
|
||||
byte Heads;
|
||||
byte Sectors;
|
||||
};
|
||||
|
||||
|
||||
#ifdef TC_BOOT_DEBUG_ENABLED
|
||||
void AcquireSectorBuffer ();
|
||||
void ReleaseSectorBuffer ();
|
||||
#else
|
||||
# define AcquireSectorBuffer()
|
||||
# define ReleaseSectorBuffer()
|
||||
#endif
|
||||
|
||||
void ChsToLba (const DriveGeometry &geometry, const ChsAddress &chs, uint64 &lba);
|
||||
bool GetActivePartition (byte drive);
|
||||
BiosResult GetDriveGeometry (byte drive, DriveGeometry &geometry, bool silent = false);
|
||||
BiosResult GetDrivePartitions (byte drive, Partition *partitionArray, size_t partitionArrayCapacity, size_t &partitionCount, bool activeOnly = false, Partition *findPartitionFollowingThis = nullptr, bool silent = false);
|
||||
bool IsLbaSupported (byte drive);
|
||||
void LbaToChs (const DriveGeometry &geometry, const uint64 &lba, ChsAddress &chs);
|
||||
void Print (const ChsAddress &chs);
|
||||
void PrintDiskError (BiosResult error, bool write, byte drive, const uint64 *sector, const ChsAddress *chs = nullptr);
|
||||
void PrintSectorCountInMB (const uint64 §orCount);
|
||||
BiosResult ReadWriteMBR (bool write, byte drive, bool silent = false);
|
||||
BiosResult ReadSectors (uint16 bufferSegment, uint16 bufferOffset, byte drive, const uint64 §or, uint16 sectorCount, bool silent = false);
|
||||
BiosResult ReadSectors (byte *buffer, byte drive, const uint64 §or, uint16 sectorCount, bool silent = false);
|
||||
BiosResult ReadSectors (byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent = false);
|
||||
BiosResult ReadWriteSectors (bool write, uint16 bufferSegment, uint16 bufferOffset, byte drive, const uint64 §or, uint16 sectorCount, bool silent);
|
||||
BiosResult WriteSectors (byte *buffer, byte drive, const uint64 §or, uint16 sectorCount, bool silent = false);
|
||||
BiosResult WriteSectors (byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent = false);
|
||||
|
||||
extern byte SectorBuffer[TC_LB_SIZE];
|
||||
|
||||
#endif // TC_HEADER_Boot_BootDiskIo
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Boot_BootDiskIo
|
||||
#define TC_HEADER_Boot_BootDiskIo
|
||||
|
||||
#include "Bios.h"
|
||||
#include "BootDebug.h"
|
||||
#include "BootDefs.h"
|
||||
|
||||
#define TC_MAX_BIOS_DISK_IO_RETRIES 5
|
||||
|
||||
enum
|
||||
{
|
||||
BiosResultEccCorrected = 0x11
|
||||
};
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
struct PartitionEntryMBR
|
||||
{
|
||||
byte BootIndicator;
|
||||
|
||||
byte StartHead;
|
||||
byte StartCylSector;
|
||||
byte StartCylinder;
|
||||
|
||||
byte Type;
|
||||
|
||||
byte EndHead;
|
||||
byte EndSector;
|
||||
byte EndCylinder;
|
||||
|
||||
uint32 StartLBA;
|
||||
uint32 SectorCountLBA;
|
||||
};
|
||||
|
||||
struct MBR
|
||||
{
|
||||
byte Code[446];
|
||||
PartitionEntryMBR Partitions[4];
|
||||
uint16 Signature;
|
||||
};
|
||||
|
||||
struct BiosLbaPacket
|
||||
{
|
||||
byte Size;
|
||||
byte Reserved;
|
||||
uint16 SectorCount;
|
||||
uint32 Buffer;
|
||||
uint64 Sector;
|
||||
};
|
||||
|
||||
#pragma pack()
|
||||
|
||||
|
||||
struct ChsAddress
|
||||
{
|
||||
uint16 Cylinder;
|
||||
byte Head;
|
||||
byte Sector;
|
||||
};
|
||||
|
||||
struct Partition
|
||||
{
|
||||
byte Number;
|
||||
byte Drive;
|
||||
bool Active;
|
||||
uint64 EndSector;
|
||||
bool Primary;
|
||||
uint64 SectorCount;
|
||||
uint64 StartSector;
|
||||
byte Type;
|
||||
};
|
||||
|
||||
struct DriveGeometry
|
||||
{
|
||||
uint16 Cylinders;
|
||||
byte Heads;
|
||||
byte Sectors;
|
||||
};
|
||||
|
||||
|
||||
#ifdef TC_BOOT_DEBUG_ENABLED
|
||||
void AcquireSectorBuffer ();
|
||||
void ReleaseSectorBuffer ();
|
||||
#else
|
||||
# define AcquireSectorBuffer()
|
||||
# define ReleaseSectorBuffer()
|
||||
#endif
|
||||
|
||||
void ChsToLba (const DriveGeometry &geometry, const ChsAddress &chs, uint64 &lba);
|
||||
bool GetActivePartition (byte drive);
|
||||
BiosResult GetDriveGeometry (byte drive, DriveGeometry &geometry, bool silent = false);
|
||||
BiosResult GetDrivePartitions (byte drive, Partition *partitionArray, size_t partitionArrayCapacity, size_t &partitionCount, bool activeOnly = false, Partition *findPartitionFollowingThis = nullptr, bool silent = false);
|
||||
bool IsLbaSupported (byte drive);
|
||||
void LbaToChs (const DriveGeometry &geometry, const uint64 &lba, ChsAddress &chs);
|
||||
void Print (const ChsAddress &chs);
|
||||
void PrintDiskError (BiosResult error, bool write, byte drive, const uint64 *sector, const ChsAddress *chs = nullptr);
|
||||
void PrintSectorCountInMB (const uint64 §orCount);
|
||||
BiosResult ReadWriteMBR (bool write, byte drive, bool silent = false);
|
||||
BiosResult ReadSectors (uint16 bufferSegment, uint16 bufferOffset, byte drive, const uint64 §or, uint16 sectorCount, bool silent = false);
|
||||
BiosResult ReadSectors (byte *buffer, byte drive, const uint64 §or, uint16 sectorCount, bool silent = false);
|
||||
BiosResult ReadSectors (byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent = false);
|
||||
BiosResult ReadWriteSectors (bool write, uint16 bufferSegment, uint16 bufferOffset, byte drive, const uint64 §or, uint16 sectorCount, bool silent);
|
||||
BiosResult WriteSectors (byte *buffer, byte drive, const uint64 §or, uint16 sectorCount, bool silent = false);
|
||||
BiosResult WriteSectors (byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent = false);
|
||||
|
||||
extern byte SectorBuffer[TC_LB_SIZE];
|
||||
|
||||
#endif // TC_HEADER_Boot_BootDiskIo
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Boot_BootEncryptionIo
|
||||
#define TC_HEADER_Boot_BootEncryptionIo
|
||||
|
||||
#include "Platform.h"
|
||||
|
||||
BiosResult ReadEncryptedSectors (uint16 destSegment, uint16 destOffset, byte drive, uint64 sector, uint16 sectorCount);
|
||||
BiosResult WriteEncryptedSectors (uint16 sourceSegment, uint16 sourceOffset, byte drive, uint64 sector, uint16 sectorCount);
|
||||
static bool ReadWritePartiallyCoversEncryptedArea (const uint64 §or, uint16 sectorCount);
|
||||
|
||||
#endif // TC_HEADER_Boot_BootEncryptionIo
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Boot_BootEncryptionIo
|
||||
#define TC_HEADER_Boot_BootEncryptionIo
|
||||
|
||||
#include "Platform.h"
|
||||
|
||||
BiosResult ReadEncryptedSectors (uint16 destSegment, uint16 destOffset, byte drive, uint64 sector, uint16 sectorCount);
|
||||
BiosResult WriteEncryptedSectors (uint16 sourceSegment, uint16 sourceOffset, byte drive, uint64 sector, uint16 sectorCount);
|
||||
static bool ReadWritePartiallyCoversEncryptedArea (const uint64 §or, uint16 sectorCount);
|
||||
|
||||
#endif // TC_HEADER_Boot_BootEncryptionIo
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,34 +1,34 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Boot_BootMain
|
||||
#define TC_HEADER_Boot_BootMain
|
||||
|
||||
#include "TCdefs.h"
|
||||
#include "Platform.h"
|
||||
|
||||
static byte AskPassword (Password &password, int& pim);
|
||||
static int AskSelection (const char *options[], size_t optionCount);
|
||||
static bool AskYesNo (const char *message);
|
||||
static byte BootEncryptedDrive ();
|
||||
static void BootMenu ();
|
||||
static void ExecuteBootSector (byte drive, byte *sectorBuffer);
|
||||
static void InitScreen ();
|
||||
static bool IsMenuKey (byte scanCode);
|
||||
static bool MountVolume (byte drive, byte &exitKey);
|
||||
static bool OpenVolume (byte drive, Password &password, CRYPTO_INFO **cryptoInfo, uint32 *headerSaltCrc32 = nullptr, bool skipNormal = false, bool skipHidden = false);
|
||||
static void PrintMainMenu ();
|
||||
static void RepairMenu ();
|
||||
|
||||
#define TC_MENU_KEY_REPAIR TC_BIOS_KEY_F8
|
||||
|
||||
#endif // TC_HEADER_Boot_BootMain
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Boot_BootMain
|
||||
#define TC_HEADER_Boot_BootMain
|
||||
|
||||
#include "TCdefs.h"
|
||||
#include "Platform.h"
|
||||
|
||||
static byte AskPassword (Password &password, int& pim);
|
||||
static int AskSelection (const char *options[], size_t optionCount);
|
||||
static bool AskYesNo (const char *message);
|
||||
static byte BootEncryptedDrive ();
|
||||
static void BootMenu ();
|
||||
static void ExecuteBootSector (byte drive, byte *sectorBuffer);
|
||||
static void InitScreen ();
|
||||
static bool IsMenuKey (byte scanCode);
|
||||
static bool MountVolume (byte drive, byte &exitKey);
|
||||
static bool OpenVolume (byte drive, Password &password, CRYPTO_INFO **cryptoInfo, uint32 *headerSaltCrc32 = nullptr, bool skipNormal = false, bool skipHidden = false);
|
||||
static void PrintMainMenu ();
|
||||
static void RepairMenu ();
|
||||
|
||||
#define TC_MENU_KEY_REPAIR TC_BIOS_KEY_F8
|
||||
|
||||
#endif // TC_HEADER_Boot_BootMain
|
||||
|
||||
@@ -1,86 +1,86 @@
|
||||
/*
|
||||
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 "BootDefs.h"
|
||||
#include "BootMemory.h"
|
||||
|
||||
static uint32 MemoryMapContValue;
|
||||
|
||||
static bool GetMemoryMapEntry (BiosMemoryMapEntry &entry)
|
||||
{
|
||||
static const uint32 function = 0x0000E820UL;
|
||||
static const uint32 magic = 0x534D4150UL;
|
||||
static const uint32 bufferSize = sizeof (BiosMemoryMapEntry);
|
||||
|
||||
bool carry = false;
|
||||
uint32 resultMagic;
|
||||
uint32 resultSize;
|
||||
|
||||
__asm
|
||||
{
|
||||
push es
|
||||
|
||||
lea di, function
|
||||
TC_ASM_MOV_EAX_DI
|
||||
lea di, MemoryMapContValue
|
||||
TC_ASM_MOV_EBX_DI
|
||||
lea di, bufferSize
|
||||
TC_ASM_MOV_ECX_DI
|
||||
lea di, magic
|
||||
TC_ASM_MOV_EDX_DI
|
||||
lea di, MemoryMapContValue
|
||||
TC_ASM_MOV_DI_ECX
|
||||
|
||||
// Use alternative segment to prevent memory corruption caused by buggy BIOSes
|
||||
push TC_BOOT_LOADER_ALT_SEGMENT
|
||||
pop es
|
||||
mov di, 0
|
||||
|
||||
int 0x15
|
||||
jnc no_carry
|
||||
mov carry, true
|
||||
no_carry:
|
||||
|
||||
lea di, resultMagic
|
||||
TC_ASM_MOV_DI_EAX
|
||||
lea di, MemoryMapContValue
|
||||
TC_ASM_MOV_DI_EBX
|
||||
lea di, resultSize
|
||||
TC_ASM_MOV_DI_ECX
|
||||
|
||||
pop es
|
||||
}
|
||||
|
||||
CopyMemory (TC_BOOT_LOADER_ALT_SEGMENT, 0, &entry, sizeof (entry));
|
||||
|
||||
// BIOS may set CF at the end of the list
|
||||
if (carry)
|
||||
MemoryMapContValue = 0;
|
||||
|
||||
return resultMagic == magic && resultSize == bufferSize;
|
||||
}
|
||||
|
||||
|
||||
bool GetFirstBiosMemoryMapEntry (BiosMemoryMapEntry &entry)
|
||||
{
|
||||
MemoryMapContValue = 0;
|
||||
return GetMemoryMapEntry (entry);
|
||||
}
|
||||
|
||||
|
||||
bool GetNextBiosMemoryMapEntry (BiosMemoryMapEntry &entry)
|
||||
{
|
||||
if (MemoryMapContValue == 0)
|
||||
return false;
|
||||
|
||||
return GetMemoryMapEntry (entry);
|
||||
}
|
||||
/*
|
||||
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 "BootDefs.h"
|
||||
#include "BootMemory.h"
|
||||
|
||||
static uint32 MemoryMapContValue;
|
||||
|
||||
static bool GetMemoryMapEntry (BiosMemoryMapEntry &entry)
|
||||
{
|
||||
static const uint32 function = 0x0000E820UL;
|
||||
static const uint32 magic = 0x534D4150UL;
|
||||
static const uint32 bufferSize = sizeof (BiosMemoryMapEntry);
|
||||
|
||||
bool carry = false;
|
||||
uint32 resultMagic;
|
||||
uint32 resultSize;
|
||||
|
||||
__asm
|
||||
{
|
||||
push es
|
||||
|
||||
lea di, function
|
||||
TC_ASM_MOV_EAX_DI
|
||||
lea di, MemoryMapContValue
|
||||
TC_ASM_MOV_EBX_DI
|
||||
lea di, bufferSize
|
||||
TC_ASM_MOV_ECX_DI
|
||||
lea di, magic
|
||||
TC_ASM_MOV_EDX_DI
|
||||
lea di, MemoryMapContValue
|
||||
TC_ASM_MOV_DI_ECX
|
||||
|
||||
// Use alternative segment to prevent memory corruption caused by buggy BIOSes
|
||||
push TC_BOOT_LOADER_ALT_SEGMENT
|
||||
pop es
|
||||
mov di, 0
|
||||
|
||||
int 0x15
|
||||
jnc no_carry
|
||||
mov carry, true
|
||||
no_carry:
|
||||
|
||||
lea di, resultMagic
|
||||
TC_ASM_MOV_DI_EAX
|
||||
lea di, MemoryMapContValue
|
||||
TC_ASM_MOV_DI_EBX
|
||||
lea di, resultSize
|
||||
TC_ASM_MOV_DI_ECX
|
||||
|
||||
pop es
|
||||
}
|
||||
|
||||
CopyMemory (TC_BOOT_LOADER_ALT_SEGMENT, 0, &entry, sizeof (entry));
|
||||
|
||||
// BIOS may set CF at the end of the list
|
||||
if (carry)
|
||||
MemoryMapContValue = 0;
|
||||
|
||||
return resultMagic == magic && resultSize == bufferSize;
|
||||
}
|
||||
|
||||
|
||||
bool GetFirstBiosMemoryMapEntry (BiosMemoryMapEntry &entry)
|
||||
{
|
||||
MemoryMapContValue = 0;
|
||||
return GetMemoryMapEntry (entry);
|
||||
}
|
||||
|
||||
|
||||
bool GetNextBiosMemoryMapEntry (BiosMemoryMapEntry &entry)
|
||||
{
|
||||
if (MemoryMapContValue == 0)
|
||||
return false;
|
||||
|
||||
return GetMemoryMapEntry (entry);
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
/*
|
||||
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 "Platform.h"
|
||||
#include "Bios.h"
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
struct BiosMemoryMapEntry
|
||||
{
|
||||
uint64 BaseAddress;
|
||||
uint64 Length;
|
||||
uint32 Type;
|
||||
};
|
||||
|
||||
#pragma pack()
|
||||
|
||||
bool GetFirstBiosMemoryMapEntry (BiosMemoryMapEntry &entry);
|
||||
bool GetNextBiosMemoryMapEntry (BiosMemoryMapEntry &entry);
|
||||
/*
|
||||
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 "Platform.h"
|
||||
#include "Bios.h"
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
struct BiosMemoryMapEntry
|
||||
{
|
||||
uint64 BaseAddress;
|
||||
uint64 Length;
|
||||
uint32 Type;
|
||||
};
|
||||
|
||||
#pragma pack()
|
||||
|
||||
bool GetFirstBiosMemoryMapEntry (BiosMemoryMapEntry &entry);
|
||||
bool GetNextBiosMemoryMapEntry (BiosMemoryMapEntry &entry);
|
||||
|
||||
@@ -1,244 +1,244 @@
|
||||
;
|
||||
; 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.
|
||||
;
|
||||
|
||||
.MODEL tiny
|
||||
.386
|
||||
_TEXT SEGMENT USE16
|
||||
|
||||
INCLUDE BootDefs.i
|
||||
|
||||
ORG 7C00h ; Standard boot sector offset
|
||||
|
||||
start:
|
||||
; BIOS executes boot sector from 0:7C00 or 7C0:0000 (default CD boot loader address).
|
||||
; Far jump to the next instruction sets IP to the standard offset 7C00.
|
||||
db 0EAh ; jmp 0:main
|
||||
dw main, 0
|
||||
|
||||
loader_name_msg:
|
||||
db ' VeraCrypt Boot Loader', 13, 10, 0
|
||||
|
||||
main:
|
||||
cli
|
||||
xor ax, ax
|
||||
mov ds, ax
|
||||
mov ss, ax
|
||||
mov sp, 7C00h
|
||||
sti
|
||||
|
||||
; Display boot loader name
|
||||
test byte ptr [start + TC_BOOT_SECTOR_USER_CONFIG_OFFSET], TC_BOOT_USER_CFG_FLAG_SILENT_MODE
|
||||
jnz skip_loader_name_msg
|
||||
|
||||
lea si, loader_name_msg
|
||||
call print
|
||||
skip_loader_name_msg:
|
||||
|
||||
; Determine boot loader segment
|
||||
mov ax, TC_BOOT_LOADER_SEGMENT
|
||||
|
||||
; Check available memory
|
||||
cmp word ptr [ds:413h], TC_BOOT_LOADER_SEGMENT / 1024 * 16 + TC_BOOT_MEMORY_REQUIRED
|
||||
jge memory_ok
|
||||
|
||||
mov ax, TC_BOOT_LOADER_SEGMENT_LOW
|
||||
|
||||
cmp word ptr [ds:413h], TC_BOOT_LOADER_SEGMENT_LOW / 1024 * 16 + TC_BOOT_MEMORY_REQUIRED
|
||||
jge memory_ok
|
||||
|
||||
; Insufficient memory
|
||||
mov ax, TC_BOOT_LOADER_LOWMEM_SEGMENT
|
||||
|
||||
memory_ok:
|
||||
mov es, ax
|
||||
|
||||
; Clear BSS section
|
||||
xor al, al
|
||||
mov di, TC_COM_EXECUTABLE_OFFSET
|
||||
mov cx, TC_BOOT_MEMORY_REQUIRED * 1024 - TC_COM_EXECUTABLE_OFFSET - 1
|
||||
cld
|
||||
rep stosb
|
||||
|
||||
mov ax, es
|
||||
sub ax, TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE / 16 ; Decompressor segment
|
||||
mov es, ax
|
||||
|
||||
; Load decompressor
|
||||
mov cl, TC_BOOT_LOADER_DECOMPRESSOR_START_SECTOR
|
||||
retry_backup:
|
||||
mov al, TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT
|
||||
mov bx, TC_COM_EXECUTABLE_OFFSET
|
||||
call read_sectors
|
||||
|
||||
; Decompressor checksum
|
||||
xor ebx, ebx
|
||||
mov si, TC_COM_EXECUTABLE_OFFSET
|
||||
mov cx, TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT * TC_LB_SIZE
|
||||
call checksum
|
||||
push ebx
|
||||
|
||||
; Load compressed boot loader
|
||||
mov bx, TC_BOOT_LOADER_COMPRESSED_BUFFER_OFFSET
|
||||
mov cl, TC_BOOT_LOADER_START_SECTOR
|
||||
mov al, TC_MAX_BOOT_LOADER_SECTOR_COUNT
|
||||
|
||||
test backup_loader_used, 1
|
||||
jz non_backup
|
||||
mov al, TC_BOOT_LOADER_BACKUP_SECTOR_COUNT - TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT
|
||||
mov cl, TC_BOOT_LOADER_START_SECTOR + TC_BOOT_LOADER_BACKUP_SECTOR_COUNT
|
||||
|
||||
non_backup:
|
||||
call read_sectors
|
||||
|
||||
; Boot loader checksum
|
||||
pop ebx
|
||||
mov si, TC_BOOT_LOADER_COMPRESSED_BUFFER_OFFSET
|
||||
mov cx, word ptr [start + TC_BOOT_SECTOR_LOADER_LENGTH_OFFSET]
|
||||
call checksum
|
||||
|
||||
; Verify checksum
|
||||
cmp ebx, dword ptr [start + TC_BOOT_SECTOR_LOADER_CHECKSUM_OFFSET]
|
||||
je checksum_ok
|
||||
|
||||
; Checksum incorrect - try using backup if available
|
||||
test backup_loader_used, 1
|
||||
jnz loader_damaged
|
||||
|
||||
mov backup_loader_used, 1
|
||||
mov cl, TC_BOOT_LOADER_DECOMPRESSOR_START_SECTOR + TC_BOOT_LOADER_BACKUP_SECTOR_COUNT
|
||||
|
||||
test TC_BOOT_CFG_FLAG_BACKUP_LOADER_AVAILABLE, byte ptr [start + TC_BOOT_SECTOR_CONFIG_OFFSET]
|
||||
jnz retry_backup
|
||||
|
||||
loader_damaged:
|
||||
lea si, loader_damaged_msg
|
||||
call print
|
||||
lea si, loader_name_msg
|
||||
call print
|
||||
jmp $
|
||||
checksum_ok:
|
||||
|
||||
; Set up decompressor segment
|
||||
mov ax, es
|
||||
mov ds, ax
|
||||
cli
|
||||
mov ss, ax
|
||||
mov sp, TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE
|
||||
sti
|
||||
|
||||
push dx
|
||||
|
||||
; Decompress boot loader
|
||||
mov cx, word ptr [start + TC_BOOT_SECTOR_LOADER_LENGTH_OFFSET]
|
||||
sub cx, TC_GZIP_HEADER_SIZE
|
||||
push cx ; Compressed data size
|
||||
push TC_BOOT_LOADER_COMPRESSED_BUFFER_OFFSET + TC_GZIP_HEADER_SIZE ; Compressed data
|
||||
push TC_MAX_BOOT_LOADER_DECOMPRESSED_SIZE ; Output buffer size
|
||||
push TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE + TC_COM_EXECUTABLE_OFFSET ; Output buffer
|
||||
|
||||
push cs
|
||||
push decompressor_ret
|
||||
push es
|
||||
push TC_COM_EXECUTABLE_OFFSET
|
||||
retf
|
||||
decompressor_ret:
|
||||
|
||||
add sp, 8
|
||||
pop dx
|
||||
|
||||
; Restore boot sector segment
|
||||
push cs
|
||||
pop ds
|
||||
|
||||
; Check decompression result
|
||||
test ax, ax
|
||||
jz decompression_ok
|
||||
|
||||
lea si, loader_damaged_msg
|
||||
call print
|
||||
jmp $
|
||||
decompression_ok:
|
||||
|
||||
; DH = boot sector flags
|
||||
mov dh, byte ptr [start + TC_BOOT_SECTOR_CONFIG_OFFSET]
|
||||
|
||||
; Set up boot loader segment
|
||||
mov ax, es
|
||||
add ax, TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE / 16
|
||||
mov es, ax
|
||||
mov ds, ax
|
||||
cli
|
||||
mov ss, ax
|
||||
mov sp, TC_BOOT_LOADER_STACK_TOP
|
||||
sti
|
||||
|
||||
; Execute boot loader
|
||||
push es
|
||||
push TC_COM_EXECUTABLE_OFFSET
|
||||
retf
|
||||
|
||||
; Print string
|
||||
print:
|
||||
xor bx, bx
|
||||
mov ah, 0eh
|
||||
cld
|
||||
|
||||
@@: lodsb
|
||||
test al, al
|
||||
jz print_end
|
||||
|
||||
int 10h
|
||||
jmp @B
|
||||
|
||||
print_end:
|
||||
ret
|
||||
|
||||
; Read sectors of the first cylinder
|
||||
read_sectors:
|
||||
mov ch, 0 ; Cylinder
|
||||
mov dh, 0 ; Head
|
||||
; DL = drive number passed from BIOS
|
||||
mov ah, 2
|
||||
int 13h
|
||||
jnc read_ok
|
||||
|
||||
lea si, disk_error_msg
|
||||
call print
|
||||
read_ok:
|
||||
ret
|
||||
|
||||
; Calculate checksum
|
||||
checksum:
|
||||
push ds
|
||||
push es
|
||||
pop ds
|
||||
xor eax, eax
|
||||
cld
|
||||
|
||||
@@: lodsb
|
||||
add ebx, eax
|
||||
rol ebx, 1
|
||||
loop @B
|
||||
|
||||
pop ds
|
||||
ret
|
||||
|
||||
backup_loader_used db 0
|
||||
|
||||
disk_error_msg db 'Disk error', 13, 10, 7, 0
|
||||
loader_damaged_msg db 7, 'Loader damaged! Repair with Rescue Disk', 0
|
||||
|
||||
ORG 7C00h + 510
|
||||
dw 0AA55h ; Boot sector signature
|
||||
|
||||
_TEXT ENDS
|
||||
END start
|
||||
;
|
||||
; 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.
|
||||
;
|
||||
|
||||
.MODEL tiny
|
||||
.386
|
||||
_TEXT SEGMENT USE16
|
||||
|
||||
INCLUDE BootDefs.i
|
||||
|
||||
ORG 7C00h ; Standard boot sector offset
|
||||
|
||||
start:
|
||||
; BIOS executes boot sector from 0:7C00 or 7C0:0000 (default CD boot loader address).
|
||||
; Far jump to the next instruction sets IP to the standard offset 7C00.
|
||||
db 0EAh ; jmp 0:main
|
||||
dw main, 0
|
||||
|
||||
loader_name_msg:
|
||||
db ' VeraCrypt Boot Loader', 13, 10, 0
|
||||
|
||||
main:
|
||||
cli
|
||||
xor ax, ax
|
||||
mov ds, ax
|
||||
mov ss, ax
|
||||
mov sp, 7C00h
|
||||
sti
|
||||
|
||||
; Display boot loader name
|
||||
test byte ptr [start + TC_BOOT_SECTOR_USER_CONFIG_OFFSET], TC_BOOT_USER_CFG_FLAG_SILENT_MODE
|
||||
jnz skip_loader_name_msg
|
||||
|
||||
lea si, loader_name_msg
|
||||
call print
|
||||
skip_loader_name_msg:
|
||||
|
||||
; Determine boot loader segment
|
||||
mov ax, TC_BOOT_LOADER_SEGMENT
|
||||
|
||||
; Check available memory
|
||||
cmp word ptr [ds:413h], TC_BOOT_LOADER_SEGMENT / 1024 * 16 + TC_BOOT_MEMORY_REQUIRED
|
||||
jge memory_ok
|
||||
|
||||
mov ax, TC_BOOT_LOADER_SEGMENT_LOW
|
||||
|
||||
cmp word ptr [ds:413h], TC_BOOT_LOADER_SEGMENT_LOW / 1024 * 16 + TC_BOOT_MEMORY_REQUIRED
|
||||
jge memory_ok
|
||||
|
||||
; Insufficient memory
|
||||
mov ax, TC_BOOT_LOADER_LOWMEM_SEGMENT
|
||||
|
||||
memory_ok:
|
||||
mov es, ax
|
||||
|
||||
; Clear BSS section
|
||||
xor al, al
|
||||
mov di, TC_COM_EXECUTABLE_OFFSET
|
||||
mov cx, TC_BOOT_MEMORY_REQUIRED * 1024 - TC_COM_EXECUTABLE_OFFSET - 1
|
||||
cld
|
||||
rep stosb
|
||||
|
||||
mov ax, es
|
||||
sub ax, TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE / 16 ; Decompressor segment
|
||||
mov es, ax
|
||||
|
||||
; Load decompressor
|
||||
mov cl, TC_BOOT_LOADER_DECOMPRESSOR_START_SECTOR
|
||||
retry_backup:
|
||||
mov al, TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT
|
||||
mov bx, TC_COM_EXECUTABLE_OFFSET
|
||||
call read_sectors
|
||||
|
||||
; Decompressor checksum
|
||||
xor ebx, ebx
|
||||
mov si, TC_COM_EXECUTABLE_OFFSET
|
||||
mov cx, TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT * TC_LB_SIZE
|
||||
call checksum
|
||||
push ebx
|
||||
|
||||
; Load compressed boot loader
|
||||
mov bx, TC_BOOT_LOADER_COMPRESSED_BUFFER_OFFSET
|
||||
mov cl, TC_BOOT_LOADER_START_SECTOR
|
||||
mov al, TC_MAX_BOOT_LOADER_SECTOR_COUNT
|
||||
|
||||
test backup_loader_used, 1
|
||||
jz non_backup
|
||||
mov al, TC_BOOT_LOADER_BACKUP_SECTOR_COUNT - TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT
|
||||
mov cl, TC_BOOT_LOADER_START_SECTOR + TC_BOOT_LOADER_BACKUP_SECTOR_COUNT
|
||||
|
||||
non_backup:
|
||||
call read_sectors
|
||||
|
||||
; Boot loader checksum
|
||||
pop ebx
|
||||
mov si, TC_BOOT_LOADER_COMPRESSED_BUFFER_OFFSET
|
||||
mov cx, word ptr [start + TC_BOOT_SECTOR_LOADER_LENGTH_OFFSET]
|
||||
call checksum
|
||||
|
||||
; Verify checksum
|
||||
cmp ebx, dword ptr [start + TC_BOOT_SECTOR_LOADER_CHECKSUM_OFFSET]
|
||||
je checksum_ok
|
||||
|
||||
; Checksum incorrect - try using backup if available
|
||||
test backup_loader_used, 1
|
||||
jnz loader_damaged
|
||||
|
||||
mov backup_loader_used, 1
|
||||
mov cl, TC_BOOT_LOADER_DECOMPRESSOR_START_SECTOR + TC_BOOT_LOADER_BACKUP_SECTOR_COUNT
|
||||
|
||||
test TC_BOOT_CFG_FLAG_BACKUP_LOADER_AVAILABLE, byte ptr [start + TC_BOOT_SECTOR_CONFIG_OFFSET]
|
||||
jnz retry_backup
|
||||
|
||||
loader_damaged:
|
||||
lea si, loader_damaged_msg
|
||||
call print
|
||||
lea si, loader_name_msg
|
||||
call print
|
||||
jmp $
|
||||
checksum_ok:
|
||||
|
||||
; Set up decompressor segment
|
||||
mov ax, es
|
||||
mov ds, ax
|
||||
cli
|
||||
mov ss, ax
|
||||
mov sp, TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE
|
||||
sti
|
||||
|
||||
push dx
|
||||
|
||||
; Decompress boot loader
|
||||
mov cx, word ptr [start + TC_BOOT_SECTOR_LOADER_LENGTH_OFFSET]
|
||||
sub cx, TC_GZIP_HEADER_SIZE
|
||||
push cx ; Compressed data size
|
||||
push TC_BOOT_LOADER_COMPRESSED_BUFFER_OFFSET + TC_GZIP_HEADER_SIZE ; Compressed data
|
||||
push TC_MAX_BOOT_LOADER_DECOMPRESSED_SIZE ; Output buffer size
|
||||
push TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE + TC_COM_EXECUTABLE_OFFSET ; Output buffer
|
||||
|
||||
push cs
|
||||
push decompressor_ret
|
||||
push es
|
||||
push TC_COM_EXECUTABLE_OFFSET
|
||||
retf
|
||||
decompressor_ret:
|
||||
|
||||
add sp, 8
|
||||
pop dx
|
||||
|
||||
; Restore boot sector segment
|
||||
push cs
|
||||
pop ds
|
||||
|
||||
; Check decompression result
|
||||
test ax, ax
|
||||
jz decompression_ok
|
||||
|
||||
lea si, loader_damaged_msg
|
||||
call print
|
||||
jmp $
|
||||
decompression_ok:
|
||||
|
||||
; DH = boot sector flags
|
||||
mov dh, byte ptr [start + TC_BOOT_SECTOR_CONFIG_OFFSET]
|
||||
|
||||
; Set up boot loader segment
|
||||
mov ax, es
|
||||
add ax, TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE / 16
|
||||
mov es, ax
|
||||
mov ds, ax
|
||||
cli
|
||||
mov ss, ax
|
||||
mov sp, TC_BOOT_LOADER_STACK_TOP
|
||||
sti
|
||||
|
||||
; Execute boot loader
|
||||
push es
|
||||
push TC_COM_EXECUTABLE_OFFSET
|
||||
retf
|
||||
|
||||
; Print string
|
||||
print:
|
||||
xor bx, bx
|
||||
mov ah, 0eh
|
||||
cld
|
||||
|
||||
@@: lodsb
|
||||
test al, al
|
||||
jz print_end
|
||||
|
||||
int 10h
|
||||
jmp @B
|
||||
|
||||
print_end:
|
||||
ret
|
||||
|
||||
; Read sectors of the first cylinder
|
||||
read_sectors:
|
||||
mov ch, 0 ; Cylinder
|
||||
mov dh, 0 ; Head
|
||||
; DL = drive number passed from BIOS
|
||||
mov ah, 2
|
||||
int 13h
|
||||
jnc read_ok
|
||||
|
||||
lea si, disk_error_msg
|
||||
call print
|
||||
read_ok:
|
||||
ret
|
||||
|
||||
; Calculate checksum
|
||||
checksum:
|
||||
push ds
|
||||
push es
|
||||
pop ds
|
||||
xor eax, eax
|
||||
cld
|
||||
|
||||
@@: lodsb
|
||||
add ebx, eax
|
||||
rol ebx, 1
|
||||
loop @B
|
||||
|
||||
pop ds
|
||||
ret
|
||||
|
||||
backup_loader_used db 0
|
||||
|
||||
disk_error_msg db 'Disk error', 13, 10, 7, 0
|
||||
loader_damaged_msg db 7, 'Loader damaged! Repair with Rescue Disk', 0
|
||||
|
||||
ORG 7C00h + 510
|
||||
dw 0AA55h ; Boot sector signature
|
||||
|
||||
_TEXT ENDS
|
||||
END start
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Boot_BootStrings
|
||||
#define TC_HEADER_Boot_BootStrings
|
||||
|
||||
#define TC_BOOT_STR_ERROR "Error: "
|
||||
#define TC_BOOT_STR_NO_BOOT_PARTITION "No bootable partition found"
|
||||
#define TC_BOOT_STR_UPGRADE_BIOS "- Upgrade BIOS\r\n- Use a different motherboard model/brand\r\n"
|
||||
|
||||
#endif // TC_HEADER_Boot_BootStrings
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Boot_BootStrings
|
||||
#define TC_HEADER_Boot_BootStrings
|
||||
|
||||
#define TC_BOOT_STR_ERROR "Error: "
|
||||
#define TC_BOOT_STR_NO_BOOT_PARTITION "No bootable partition found"
|
||||
#define TC_BOOT_STR_UPGRADE_BIOS "- Upgrade BIOS\r\n- Use a different motherboard model/brand\r\n"
|
||||
|
||||
#endif // TC_HEADER_Boot_BootStrings
|
||||
|
||||
@@ -83,7 +83,7 @@ local int stored(struct state *s)
|
||||
s->bitbuf = 0;
|
||||
s->bitcnt = 0;
|
||||
|
||||
if (s->incnt + 4 > s->inlen)
|
||||
if (s->incnt + 4 > s->inlen)
|
||||
return 2; /* not enough input */
|
||||
|
||||
/* get length and check against its one's complement */
|
||||
@@ -93,7 +93,7 @@ local int stored(struct state *s)
|
||||
s->in[s->incnt++] != ((~len >> 8) & 0xff))
|
||||
return -2; /* didn't match complement! */
|
||||
|
||||
if (s->incnt + len > s->inlen)
|
||||
if (s->incnt + len > s->inlen)
|
||||
return 2; /* not enough input */
|
||||
|
||||
/* copy len bytes from in to out */
|
||||
@@ -379,21 +379,21 @@ local int dynamic(struct state *s)
|
||||
lengths[index++] = symbol;
|
||||
else { /* repeat instruction */
|
||||
len = 0; /* assume repeating zeros */
|
||||
switch(symbol)
|
||||
{
|
||||
case 16: { /* repeat last length 3..6 times */
|
||||
if (index == 0) return -5; /* no last length! */
|
||||
len = lengths[index - 1]; /* last length */
|
||||
symbol = 3 + bits(s, 2);
|
||||
break;
|
||||
}
|
||||
case 17: /* repeat zero 3..10 times */
|
||||
symbol = 3 + bits(s, 3);
|
||||
break;
|
||||
default: /* == 18, repeat zero 11..138 times */
|
||||
symbol = 11 + bits(s, 7);
|
||||
break;
|
||||
}
|
||||
switch(symbol)
|
||||
{
|
||||
case 16: { /* repeat last length 3..6 times */
|
||||
if (index == 0) return -5; /* no last length! */
|
||||
len = lengths[index - 1]; /* last length */
|
||||
symbol = 3 + bits(s, 2);
|
||||
break;
|
||||
}
|
||||
case 17: /* repeat zero 3..10 times */
|
||||
symbol = 3 + bits(s, 3);
|
||||
break;
|
||||
default: /* == 18, repeat zero 11..138 times */
|
||||
symbol = 11 + bits(s, 7);
|
||||
break;
|
||||
}
|
||||
if ((index + symbol > nlen + ndist))
|
||||
return -6; /* too many lengths! */
|
||||
while (symbol--) /* repeat last or zero symbol times */
|
||||
@@ -401,8 +401,8 @@ local int dynamic(struct state *s)
|
||||
}
|
||||
}
|
||||
|
||||
/* check for end-of-block code -- there better be one! */
|
||||
if (lengths[256] == 0)
|
||||
/* check for end-of-block code -- there better be one! */
|
||||
if (lengths[256] == 0)
|
||||
return -9;
|
||||
|
||||
/* build huffman table for literal/length codes */
|
||||
@@ -423,50 +423,50 @@ local int dynamic(struct state *s)
|
||||
void _acrtused () { }
|
||||
|
||||
// Decompress deflated data
|
||||
int far main (
|
||||
unsigned char *dest, /* pointer to destination pointer */
|
||||
unsigned int destlen, /* amount of output space */
|
||||
unsigned char *source, /* pointer to source data pointer */
|
||||
unsigned int sourcelen)
|
||||
{
|
||||
struct state s; /* input/output state */
|
||||
int last, type; /* block information */
|
||||
int err; /* return value */
|
||||
|
||||
/* initialize output state */
|
||||
s.out = dest;
|
||||
s.outlen = destlen; /* ignored if dest is NIL */
|
||||
s.outcnt = 0;
|
||||
|
||||
/* initialize input state */
|
||||
s.in = source;
|
||||
s.inlen = sourcelen;
|
||||
s.incnt = 0;
|
||||
s.bitbuf = 0;
|
||||
s.bitcnt = 0;
|
||||
|
||||
/* process blocks until last block or error */
|
||||
do {
|
||||
last = bits(&s, 1); /* one if last block */
|
||||
type = bits(&s, 2); /* block type 0..3 */
|
||||
switch(type)
|
||||
{
|
||||
case 0:
|
||||
err = stored(&s);
|
||||
break;
|
||||
case 1:
|
||||
err = fixed(&s);
|
||||
break;
|
||||
case 2:
|
||||
err = dynamic(&s);
|
||||
break;
|
||||
default:
|
||||
err = -1; /* type == 3, invalid */
|
||||
break;
|
||||
}
|
||||
|
||||
if (err != 0) break; /* return with error */
|
||||
} while (!last);
|
||||
|
||||
return err;
|
||||
int far main (
|
||||
unsigned char *dest, /* pointer to destination pointer */
|
||||
unsigned int destlen, /* amount of output space */
|
||||
unsigned char *source, /* pointer to source data pointer */
|
||||
unsigned int sourcelen)
|
||||
{
|
||||
struct state s; /* input/output state */
|
||||
int last, type; /* block information */
|
||||
int err; /* return value */
|
||||
|
||||
/* initialize output state */
|
||||
s.out = dest;
|
||||
s.outlen = destlen; /* ignored if dest is NIL */
|
||||
s.outcnt = 0;
|
||||
|
||||
/* initialize input state */
|
||||
s.in = source;
|
||||
s.inlen = sourcelen;
|
||||
s.incnt = 0;
|
||||
s.bitbuf = 0;
|
||||
s.bitcnt = 0;
|
||||
|
||||
/* process blocks until last block or error */
|
||||
do {
|
||||
last = bits(&s, 1); /* one if last block */
|
||||
type = bits(&s, 2); /* block type 0..3 */
|
||||
switch(type)
|
||||
{
|
||||
case 0:
|
||||
err = stored(&s);
|
||||
break;
|
||||
case 1:
|
||||
err = fixed(&s);
|
||||
break;
|
||||
case 2:
|
||||
err = dynamic(&s);
|
||||
break;
|
||||
default:
|
||||
err = -1; /* type == 3, invalid */
|
||||
break;
|
||||
}
|
||||
|
||||
if (err != 0) break; /* return with error */
|
||||
} while (!last);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Boot_IntFilter
|
||||
#define TC_HEADER_Boot_IntFilter
|
||||
|
||||
#include "Platform.h"
|
||||
|
||||
bool InstallInterruptFilters ();
|
||||
|
||||
#endif TC_HEADER_Boot_IntFilter
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Boot_IntFilter
|
||||
#define TC_HEADER_Boot_IntFilter
|
||||
|
||||
#include "Platform.h"
|
||||
|
||||
bool InstallInterruptFilters ();
|
||||
|
||||
#endif TC_HEADER_Boot_IntFilter
|
||||
|
||||
@@ -1,202 +1,202 @@
|
||||
#
|
||||
# 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.
|
||||
|
||||
PROJ = BootLoader
|
||||
.SILENT:
|
||||
|
||||
!ifndef MSVC16_ROOT
|
||||
!error Environment variable MSVC16_ROOT must point to the installation directory of MS Visual C++ 1.5
|
||||
!endif
|
||||
|
||||
ENVPATH = $(PATH)
|
||||
|
||||
CC = $(MSVC16_ROOT)\bin\cl.exe
|
||||
LD = $(MSVC16_ROOT)\bin\link.exe
|
||||
|
||||
AFLAGS = /nologo /omf
|
||||
|
||||
CFLAGS = /nologo /W3 /Fc /I "$(MSVC16_ROOT)\Include" /I"..\..\.." /I"..\..\..\Common" /I"..\..\..\Crypto"
|
||||
CFLAGS = $(CFLAGS) /D __int8=char /D __int16=int /D __int32=long /D BOOL=char /D FALSE=0 /D TRUE=1
|
||||
CFLAGS = $(CFLAGS) /D LITTLE_ENDIAN=1234 /D BYTE_ORDER=1234 /D TC_WINDOWS_BOOT /D TC_MINIMIZE_CODE_SIZE /D TC_NO_COMPILER_INT64
|
||||
CFLAGS = $(CFLAGS) /D malloc=malloc_NA
|
||||
|
||||
LFLAGS = /NOLOGO /ONERROR:NOEXE /NOI /BATCH
|
||||
|
||||
OBJDIR = Release
|
||||
|
||||
!ifdef RESCUE_DISK
|
||||
OBJDIR = Rescue
|
||||
CFLAGS = $(CFLAGS) /D TC_WINDOWS_BOOT_RESCUE_DISK_MODE
|
||||
!endif
|
||||
|
||||
!ifdef SINGLE_CIPHER
|
||||
OBJDIR = $(OBJDIR)_$(SINGLE_CIPHER)
|
||||
CFLAGS = $(CFLAGS) /D TC_WINDOWS_BOOT_SINGLE_CIPHER_MODE /D TC_WINDOWS_BOOT_$(SINGLE_CIPHER)
|
||||
!endif
|
||||
|
||||
!ifdef SINGLE_PRF
|
||||
OBJDIR = $(OBJDIR)_$(SINGLE_PRF)
|
||||
CFLAGS = $(CFLAGS) /D TC_WINDOWS_BOOT_$(SINGLE_PRF)
|
||||
!else
|
||||
CFLAGS = $(CFLAGS) /D TC_WINDOWS_BOOT_RIPEMD160
|
||||
!endif
|
||||
|
||||
OUTDIR = $(OBJDIR)
|
||||
TARGETEXT = com
|
||||
TARGETS = $(OUTDIR)\BootDefs.i $(OUTDIR)\BootSector.bin $(OUTDIR)\Decompressor.com
|
||||
CFLAGS = $(CFLAGS) /AT /Zl /f- /G3 /Oe /Os /Ob1 /OV0 /Gs /Gf /Gy /D NDEBUG
|
||||
LFLAGS = $(LFLAGS) /NOD /NOE /TINY
|
||||
OBJS = $(OUTDIR)\BootCrt.obj
|
||||
LIBS = slibce
|
||||
|
||||
!if 1
|
||||
SRCDIR = ..
|
||||
!else
|
||||
SRCDIR = $(MAKEDIR)
|
||||
!endif
|
||||
|
||||
TARGETS = $(TARGETS) $(OUTDIR)\$(PROJ).$(TARGETEXT)
|
||||
|
||||
OBJS = $(OBJS) $(OUTDIR)\BootConfig.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\BootConsoleIo.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\BootDebug.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\BootDiskIo.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\BootEncryptedIo.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\BootMain.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\BootMemory.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\IntFilter.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\Platform.obj
|
||||
|
||||
OBJS = $(OBJS) $(OUTDIR)\Crc.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\Crypto.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\Endian.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\Pkcs5.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\Volumes.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\Xts.obj
|
||||
|
||||
!if "$(SINGLE_PRF)" == "SHA2"
|
||||
OBJS = $(OBJS) $(OUTDIR)\Sha2Small.obj
|
||||
!else
|
||||
OBJS = $(OBJS) $(OUTDIR)\Rmd160.obj
|
||||
!endif
|
||||
|
||||
!if !DEFINED (SINGLE_CIPHER)
|
||||
OBJS = $(OBJS) $(OUTDIR)\AesSmall.obj
|
||||
!else if "$(SINGLE_CIPHER)" == "AES"
|
||||
OBJS = $(OBJS) $(OUTDIR)\Aes_hw_cpu.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\AesSmall_x86.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\Aestab.obj
|
||||
!endif
|
||||
|
||||
!if !DEFINED (SINGLE_CIPHER) || "$(SINGLE_CIPHER)" == "SERPENT"
|
||||
OBJS = $(OBJS) $(OUTDIR)\Serpent.obj
|
||||
!endif
|
||||
|
||||
!if !DEFINED (SINGLE_CIPHER) || "$(SINGLE_CIPHER)" == "TWOFISH"
|
||||
OBJS = $(OBJS) $(OUTDIR)\Twofish.obj
|
||||
!endif
|
||||
|
||||
|
||||
all: env $(TARGETS)
|
||||
|
||||
env:
|
||||
set INCLUDE=.
|
||||
set LIB=.
|
||||
set LIBPATH=.
|
||||
|
||||
clean:
|
||||
-del /q /s $(OBJDIR) >NUL:
|
||||
|
||||
|
||||
.asm{$(OUTDIR)}.obj:
|
||||
cd $(OBJDIR)
|
||||
$(AS) $(AFLAGS) /c "$(SRCDIR)\$<"
|
||||
cd ..
|
||||
|
||||
{..\..\Crypto}.asm{$(OUTDIR)}.obj:
|
||||
cd $(OBJDIR)
|
||||
echo $(<F)
|
||||
nasm.exe -Xvc -f obj -Ox -o "$(<B).obj" -l "$(<B).lst" "$(SRCDIR)\$<"
|
||||
cd ..
|
||||
|
||||
{..\..\Crypto}.c{$(OUTDIR)}.obj:
|
||||
cd $(OBJDIR)
|
||||
set PATH=.
|
||||
$(CC) $(CFLAGS) /c "$(SRCDIR)\$<"
|
||||
set PATH=$(ENVPATH)
|
||||
cd ..
|
||||
|
||||
{..\..\Common}.c{$(OUTDIR)}.obj:
|
||||
cd $(OBJDIR)
|
||||
set PATH=.
|
||||
$(CC) $(CFLAGS) /c "$(SRCDIR)\$<"
|
||||
set PATH=$(ENVPATH)
|
||||
cd ..
|
||||
|
||||
.c{$(OUTDIR)}.obj:
|
||||
cd $(OBJDIR)
|
||||
set PATH=.
|
||||
$(CC) $(CFLAGS) /c "$(SRCDIR)\$<"
|
||||
set PATH=$(ENVPATH)
|
||||
cd ..
|
||||
|
||||
.cpp{$(OUTDIR)}.obj:
|
||||
cd $(OBJDIR)
|
||||
set PATH=.
|
||||
$(CC) $(CFLAGS) /c "$(SRCDIR)\$<"
|
||||
set PATH=$(ENVPATH)
|
||||
cd ..
|
||||
|
||||
$(OUTDIR)\BootDefs.i: BootDefs.h
|
||||
cd $(OBJDIR)
|
||||
set PATH=.
|
||||
$(CC) $(CFLAGS) /D TC_ASM_PREPROCESS /P /EP "$(SRCDIR)\BootDefs.h"
|
||||
set PATH=$(ENVPATH)
|
||||
cd ..
|
||||
|
||||
$(OUTDIR)\BootSector.bin: $(OUTDIR)\BootSector.obj
|
||||
cd $(OBJDIR)
|
||||
$(LD) $(LFLAGS) BootSector.obj,BootSector.bin,,,, >NUL:
|
||||
-dd.exe conv=notrunc bs=512 if=BootSector.bin of=$(PROJ).flp 2>NUL:
|
||||
cd ..
|
||||
|
||||
$(OUTDIR)\Decompressor.com: $(OUTDIR)\BootCrt.obj $(OUTDIR)\Decompressor.obj
|
||||
cd $(OBJDIR)
|
||||
$(LD) $(LFLAGS) BootCrt.obj Decompressor.obj,Decompressor.com,Decompressor.map,$(MSVC16_ROOT)\lib\+slibce,,
|
||||
-dd.exe conv=notrunc,sync bs=512 seek=1 if=Decompressor.com of=$(PROJ).flp 2>NUL:
|
||||
cd ..
|
||||
|
||||
$(OUTDIR)\$(PROJ).$(TARGETEXT): $(OBJS)
|
||||
@echo Linking...
|
||||
cd $(OBJDIR)
|
||||
|
||||
echo >NUL: @<<$(PROJ).crf2
|
||||
|
||||
$(PROJ).$(TARGETEXT)
|
||||
$(PROJ).map
|
||||
$(MSVC16_ROOT)\lib\+
|
||||
$(LIBS)
|
||||
;
|
||||
<<
|
||||
del $(PROJ).crf >NUL: 2>NUL:
|
||||
for %F in ($(**F)) do @echo %F + >>$(PROJ).crf
|
||||
type $(PROJ).crf2 >>$(PROJ).crf
|
||||
|
||||
$(LD) $(LFLAGS) @$(PROJ).crf
|
||||
del $(PROJ).crf $(PROJ).crf2
|
||||
|
||||
# Compress the Rescue Disk botloader for Cascades and Serpent since it is too big (size > 31232 bytes)
|
||||
!if DEFINED(RESCUE_DISK) && (!DEFINED (SINGLE_CIPHER) || ("$(SINGLE_CIPHER)" == "SERPENT"))
|
||||
upx $(PROJ).$(TARGETEXT)
|
||||
!endif
|
||||
gzip.exe -c -n --best $(PROJ).$(TARGETEXT) >$(PROJ).$(TARGETEXT).gz
|
||||
-dd.exe conv=notrunc,sync bs=512 seek=5 if=$(PROJ).$(TARGETEXT).gz of=$(PROJ).flp 2>NUL:
|
||||
cd ..
|
||||
#
|
||||
# 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.
|
||||
|
||||
PROJ = BootLoader
|
||||
.SILENT:
|
||||
|
||||
!ifndef MSVC16_ROOT
|
||||
!error Environment variable MSVC16_ROOT must point to the installation directory of MS Visual C++ 1.5
|
||||
!endif
|
||||
|
||||
ENVPATH = $(PATH)
|
||||
|
||||
CC = $(MSVC16_ROOT)\bin\cl.exe
|
||||
LD = $(MSVC16_ROOT)\bin\link.exe
|
||||
|
||||
AFLAGS = /nologo /omf
|
||||
|
||||
CFLAGS = /nologo /W3 /Fc /I "$(MSVC16_ROOT)\Include" /I"..\..\.." /I"..\..\..\Common" /I"..\..\..\Crypto"
|
||||
CFLAGS = $(CFLAGS) /D __int8=char /D __int16=int /D __int32=long /D BOOL=char /D FALSE=0 /D TRUE=1
|
||||
CFLAGS = $(CFLAGS) /D LITTLE_ENDIAN=1234 /D BYTE_ORDER=1234 /D TC_WINDOWS_BOOT /D TC_MINIMIZE_CODE_SIZE /D TC_NO_COMPILER_INT64
|
||||
CFLAGS = $(CFLAGS) /D malloc=malloc_NA
|
||||
|
||||
LFLAGS = /NOLOGO /ONERROR:NOEXE /NOI /BATCH
|
||||
|
||||
OBJDIR = Release
|
||||
|
||||
!ifdef RESCUE_DISK
|
||||
OBJDIR = Rescue
|
||||
CFLAGS = $(CFLAGS) /D TC_WINDOWS_BOOT_RESCUE_DISK_MODE
|
||||
!endif
|
||||
|
||||
!ifdef SINGLE_CIPHER
|
||||
OBJDIR = $(OBJDIR)_$(SINGLE_CIPHER)
|
||||
CFLAGS = $(CFLAGS) /D TC_WINDOWS_BOOT_SINGLE_CIPHER_MODE /D TC_WINDOWS_BOOT_$(SINGLE_CIPHER)
|
||||
!endif
|
||||
|
||||
!ifdef SINGLE_PRF
|
||||
OBJDIR = $(OBJDIR)_$(SINGLE_PRF)
|
||||
CFLAGS = $(CFLAGS) /D TC_WINDOWS_BOOT_$(SINGLE_PRF)
|
||||
!else
|
||||
CFLAGS = $(CFLAGS) /D TC_WINDOWS_BOOT_RIPEMD160
|
||||
!endif
|
||||
|
||||
OUTDIR = $(OBJDIR)
|
||||
TARGETEXT = com
|
||||
TARGETS = $(OUTDIR)\BootDefs.i $(OUTDIR)\BootSector.bin $(OUTDIR)\Decompressor.com
|
||||
CFLAGS = $(CFLAGS) /AT /Zl /f- /G3 /Oe /Os /Ob1 /OV0 /Gs /Gf /Gy /D NDEBUG
|
||||
LFLAGS = $(LFLAGS) /NOD /NOE /TINY
|
||||
OBJS = $(OUTDIR)\BootCrt.obj
|
||||
LIBS = slibce
|
||||
|
||||
!if 1
|
||||
SRCDIR = ..
|
||||
!else
|
||||
SRCDIR = $(MAKEDIR)
|
||||
!endif
|
||||
|
||||
TARGETS = $(TARGETS) $(OUTDIR)\$(PROJ).$(TARGETEXT)
|
||||
|
||||
OBJS = $(OBJS) $(OUTDIR)\BootConfig.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\BootConsoleIo.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\BootDebug.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\BootDiskIo.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\BootEncryptedIo.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\BootMain.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\BootMemory.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\IntFilter.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\Platform.obj
|
||||
|
||||
OBJS = $(OBJS) $(OUTDIR)\Crc.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\Crypto.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\Endian.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\Pkcs5.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\Volumes.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\Xts.obj
|
||||
|
||||
!if "$(SINGLE_PRF)" == "SHA2"
|
||||
OBJS = $(OBJS) $(OUTDIR)\Sha2Small.obj
|
||||
!else
|
||||
OBJS = $(OBJS) $(OUTDIR)\Rmd160.obj
|
||||
!endif
|
||||
|
||||
!if !DEFINED (SINGLE_CIPHER)
|
||||
OBJS = $(OBJS) $(OUTDIR)\AesSmall.obj
|
||||
!else if "$(SINGLE_CIPHER)" == "AES"
|
||||
OBJS = $(OBJS) $(OUTDIR)\Aes_hw_cpu.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\AesSmall_x86.obj
|
||||
OBJS = $(OBJS) $(OUTDIR)\Aestab.obj
|
||||
!endif
|
||||
|
||||
!if !DEFINED (SINGLE_CIPHER) || "$(SINGLE_CIPHER)" == "SERPENT"
|
||||
OBJS = $(OBJS) $(OUTDIR)\Serpent.obj
|
||||
!endif
|
||||
|
||||
!if !DEFINED (SINGLE_CIPHER) || "$(SINGLE_CIPHER)" == "TWOFISH"
|
||||
OBJS = $(OBJS) $(OUTDIR)\Twofish.obj
|
||||
!endif
|
||||
|
||||
|
||||
all: env $(TARGETS)
|
||||
|
||||
env:
|
||||
set INCLUDE=.
|
||||
set LIB=.
|
||||
set LIBPATH=.
|
||||
|
||||
clean:
|
||||
-del /q /s $(OBJDIR) >NUL:
|
||||
|
||||
|
||||
.asm{$(OUTDIR)}.obj:
|
||||
cd $(OBJDIR)
|
||||
$(AS) $(AFLAGS) /c "$(SRCDIR)\$<"
|
||||
cd ..
|
||||
|
||||
{..\..\Crypto}.asm{$(OUTDIR)}.obj:
|
||||
cd $(OBJDIR)
|
||||
echo $(<F)
|
||||
nasm.exe -Xvc -f obj -Ox -o "$(<B).obj" -l "$(<B).lst" "$(SRCDIR)\$<"
|
||||
cd ..
|
||||
|
||||
{..\..\Crypto}.c{$(OUTDIR)}.obj:
|
||||
cd $(OBJDIR)
|
||||
set PATH=.
|
||||
$(CC) $(CFLAGS) /c "$(SRCDIR)\$<"
|
||||
set PATH=$(ENVPATH)
|
||||
cd ..
|
||||
|
||||
{..\..\Common}.c{$(OUTDIR)}.obj:
|
||||
cd $(OBJDIR)
|
||||
set PATH=.
|
||||
$(CC) $(CFLAGS) /c "$(SRCDIR)\$<"
|
||||
set PATH=$(ENVPATH)
|
||||
cd ..
|
||||
|
||||
.c{$(OUTDIR)}.obj:
|
||||
cd $(OBJDIR)
|
||||
set PATH=.
|
||||
$(CC) $(CFLAGS) /c "$(SRCDIR)\$<"
|
||||
set PATH=$(ENVPATH)
|
||||
cd ..
|
||||
|
||||
.cpp{$(OUTDIR)}.obj:
|
||||
cd $(OBJDIR)
|
||||
set PATH=.
|
||||
$(CC) $(CFLAGS) /c "$(SRCDIR)\$<"
|
||||
set PATH=$(ENVPATH)
|
||||
cd ..
|
||||
|
||||
$(OUTDIR)\BootDefs.i: BootDefs.h
|
||||
cd $(OBJDIR)
|
||||
set PATH=.
|
||||
$(CC) $(CFLAGS) /D TC_ASM_PREPROCESS /P /EP "$(SRCDIR)\BootDefs.h"
|
||||
set PATH=$(ENVPATH)
|
||||
cd ..
|
||||
|
||||
$(OUTDIR)\BootSector.bin: $(OUTDIR)\BootSector.obj
|
||||
cd $(OBJDIR)
|
||||
$(LD) $(LFLAGS) BootSector.obj,BootSector.bin,,,, >NUL:
|
||||
-dd.exe conv=notrunc bs=512 if=BootSector.bin of=$(PROJ).flp 2>NUL:
|
||||
cd ..
|
||||
|
||||
$(OUTDIR)\Decompressor.com: $(OUTDIR)\BootCrt.obj $(OUTDIR)\Decompressor.obj
|
||||
cd $(OBJDIR)
|
||||
$(LD) $(LFLAGS) BootCrt.obj Decompressor.obj,Decompressor.com,Decompressor.map,$(MSVC16_ROOT)\lib\+slibce,,
|
||||
-dd.exe conv=notrunc,sync bs=512 seek=1 if=Decompressor.com of=$(PROJ).flp 2>NUL:
|
||||
cd ..
|
||||
|
||||
$(OUTDIR)\$(PROJ).$(TARGETEXT): $(OBJS)
|
||||
@echo Linking...
|
||||
cd $(OBJDIR)
|
||||
|
||||
echo >NUL: @<<$(PROJ).crf2
|
||||
|
||||
$(PROJ).$(TARGETEXT)
|
||||
$(PROJ).map
|
||||
$(MSVC16_ROOT)\lib\+
|
||||
$(LIBS)
|
||||
;
|
||||
<<
|
||||
del $(PROJ).crf >NUL: 2>NUL:
|
||||
for %F in ($(**F)) do @echo %F + >>$(PROJ).crf
|
||||
type $(PROJ).crf2 >>$(PROJ).crf
|
||||
|
||||
$(LD) $(LFLAGS) @$(PROJ).crf
|
||||
del $(PROJ).crf $(PROJ).crf2
|
||||
|
||||
# Compress the Rescue Disk botloader for Cascades and Serpent since it is too big (size > 31232 bytes)
|
||||
!if DEFINED(RESCUE_DISK) && (!DEFINED (SINGLE_CIPHER) || ("$(SINGLE_CIPHER)" == "SERPENT"))
|
||||
upx $(PROJ).$(TARGETEXT)
|
||||
!endif
|
||||
gzip.exe -c -n --best $(PROJ).$(TARGETEXT) >$(PROJ).$(TARGETEXT).gz
|
||||
-dd.exe conv=notrunc,sync bs=512 seek=5 if=$(PROJ).$(TARGETEXT).gz of=$(PROJ).flp 2>NUL:
|
||||
cd ..
|
||||
|
||||
@@ -1,230 +1,230 @@
|
||||
/*
|
||||
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 "Platform.h"
|
||||
#include "BootConsoleIo.h"
|
||||
|
||||
|
||||
uint64 operator+ (const uint64 &a, const uint64 &b)
|
||||
{
|
||||
int carry = 0;
|
||||
uint64 r;
|
||||
|
||||
r.LowPart = a.LowPart + b.LowPart;
|
||||
__asm
|
||||
{
|
||||
jnc nocarry
|
||||
mov carry, 1
|
||||
nocarry:
|
||||
}
|
||||
|
||||
r.HighPart = a.HighPart + b.HighPart + carry;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
uint64 operator+ (const uint64 &a, uint32 b)
|
||||
{
|
||||
uint64 b64;
|
||||
b64.HighPart = 0;
|
||||
b64.LowPart = b;
|
||||
return a + b64;
|
||||
}
|
||||
|
||||
uint64 &operator+= (uint64 &a, const uint64 &b)
|
||||
{
|
||||
return a = a + b;
|
||||
}
|
||||
|
||||
uint64 operator- (const uint64 &a, const uint64 &b)
|
||||
{
|
||||
int carry = 0;
|
||||
uint64 r;
|
||||
|
||||
r.LowPart = a.LowPart - b.LowPart;
|
||||
__asm
|
||||
{
|
||||
jnc nocarry
|
||||
mov carry, 1
|
||||
nocarry:
|
||||
}
|
||||
|
||||
r.HighPart = a.HighPart - b.HighPart - carry;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
uint64 operator- (const uint64 &a, uint32 b)
|
||||
{
|
||||
uint64 b64;
|
||||
b64.HighPart = 0;
|
||||
b64.LowPart = b;
|
||||
return a - b64;
|
||||
}
|
||||
|
||||
uint64 &operator-= (uint64 &a, const uint64 &b)
|
||||
{
|
||||
return a = a - b;
|
||||
}
|
||||
|
||||
uint64 operator>> (const uint64 &a, int shiftCount)
|
||||
{
|
||||
uint64 r = a;
|
||||
|
||||
while (shiftCount--)
|
||||
{
|
||||
r.LowPart >>= 1;
|
||||
|
||||
if ((byte) r.HighPart & 1)
|
||||
r.LowPart |= 0x80000000UL;
|
||||
|
||||
r.HighPart >>= 1;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
uint64 operator<< (const uint64 &a, int shiftCount)
|
||||
{
|
||||
uint64 r = a;
|
||||
|
||||
while (shiftCount--)
|
||||
r += r;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
uint64 &operator++ (uint64 &a)
|
||||
{
|
||||
uint64 b;
|
||||
b.HighPart = 0;
|
||||
b.LowPart = 1;
|
||||
|
||||
return a += b;
|
||||
}
|
||||
|
||||
bool operator== (const uint64 &a, const uint64 &b)
|
||||
{
|
||||
return a.HighPart == b.HighPart && a.LowPart == b.LowPart;
|
||||
}
|
||||
|
||||
bool operator> (const uint64 &a, const uint64 &b)
|
||||
{
|
||||
return (a.HighPart > b.HighPart) || (a.HighPart == b.HighPart && a.LowPart > b.LowPart);
|
||||
}
|
||||
|
||||
bool operator< (const uint64 &a, const uint64 &b)
|
||||
{
|
||||
return (a.HighPart < b.HighPart) || (a.HighPart == b.HighPart && a.LowPart < b.LowPart);
|
||||
}
|
||||
|
||||
bool operator>= (const uint64 &a, const uint64 &b)
|
||||
{
|
||||
return a > b || a == b;
|
||||
}
|
||||
|
||||
bool operator<= (const uint64 &a, const uint64 &b)
|
||||
{
|
||||
return a < b || a == b;
|
||||
}
|
||||
|
||||
bool TestInt64 ()
|
||||
{
|
||||
uint64 a, b, c;
|
||||
a.HighPart = 0x00112233UL;
|
||||
a.LowPart = 0xabcd1234UL;
|
||||
|
||||
b.HighPart = 0x00ffeeddUL;
|
||||
b.LowPart = 0xffffFFFFUL;
|
||||
|
||||
a += b;
|
||||
a -= b;
|
||||
|
||||
++a;
|
||||
|
||||
b = b + (uint32) 1UL;
|
||||
|
||||
c = (a - ((a + b) >> 32) - (uint32) 1UL);
|
||||
if (c.HighPart != 0x112233UL || c.LowPart != 0xAABC0123UL)
|
||||
return false;
|
||||
|
||||
c = c << 9;
|
||||
return c.HighPart == 0x22446755UL && c.LowPart == 0x78024600UL;
|
||||
}
|
||||
|
||||
|
||||
void CopyMemory (void *source, uint16 destSegment, uint16 destOffset, uint16 blockSize)
|
||||
{
|
||||
__asm
|
||||
{
|
||||
push es
|
||||
mov si, ss:source
|
||||
mov es, ss:destSegment
|
||||
mov di, ss:destOffset
|
||||
mov cx, ss:blockSize
|
||||
cld
|
||||
rep movsb
|
||||
pop es
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CopyMemory (uint16 sourceSegment, uint16 sourceOffset, void *destination, uint16 blockSize)
|
||||
{
|
||||
__asm
|
||||
{
|
||||
push ds
|
||||
push es
|
||||
mov ax, ds
|
||||
mov es, ax
|
||||
mov di, ss:destination
|
||||
mov si, ss:sourceOffset
|
||||
mov cx, ss:blockSize
|
||||
mov ds, ss:sourceSegment
|
||||
cld
|
||||
rep movsb
|
||||
pop es
|
||||
pop ds
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void EraseMemory (void *memory, int size)
|
||||
{
|
||||
memset (memory, 0, size);
|
||||
}
|
||||
|
||||
|
||||
uint32 GetLinearAddress (uint16 segment, uint16 offset)
|
||||
{
|
||||
return (uint32 (segment) << 4) + offset;
|
||||
}
|
||||
|
||||
|
||||
bool RegionsIntersect (const uint64 &start1, uint32 length1, const uint64 &start2, const uint64 &end2)
|
||||
{
|
||||
uint64 end1 = start1 + length1 - 1UL;
|
||||
uint64 intersectEnd = (end1 <= end2) ? end1 : end2;
|
||||
|
||||
uint64 intersectStart = (start1 >= start2) ? start1 : start2;
|
||||
if (intersectStart > intersectEnd)
|
||||
return false;
|
||||
|
||||
return (intersectEnd + 1UL - intersectStart).LowPart != 0;
|
||||
}
|
||||
|
||||
|
||||
void ThrowFatalException (int line)
|
||||
{
|
||||
PrintChar ('#'); Print (line);
|
||||
while (1);
|
||||
}
|
||||
/*
|
||||
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 "Platform.h"
|
||||
#include "BootConsoleIo.h"
|
||||
|
||||
|
||||
uint64 operator+ (const uint64 &a, const uint64 &b)
|
||||
{
|
||||
int carry = 0;
|
||||
uint64 r;
|
||||
|
||||
r.LowPart = a.LowPart + b.LowPart;
|
||||
__asm
|
||||
{
|
||||
jnc nocarry
|
||||
mov carry, 1
|
||||
nocarry:
|
||||
}
|
||||
|
||||
r.HighPart = a.HighPart + b.HighPart + carry;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
uint64 operator+ (const uint64 &a, uint32 b)
|
||||
{
|
||||
uint64 b64;
|
||||
b64.HighPart = 0;
|
||||
b64.LowPart = b;
|
||||
return a + b64;
|
||||
}
|
||||
|
||||
uint64 &operator+= (uint64 &a, const uint64 &b)
|
||||
{
|
||||
return a = a + b;
|
||||
}
|
||||
|
||||
uint64 operator- (const uint64 &a, const uint64 &b)
|
||||
{
|
||||
int carry = 0;
|
||||
uint64 r;
|
||||
|
||||
r.LowPart = a.LowPart - b.LowPart;
|
||||
__asm
|
||||
{
|
||||
jnc nocarry
|
||||
mov carry, 1
|
||||
nocarry:
|
||||
}
|
||||
|
||||
r.HighPart = a.HighPart - b.HighPart - carry;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
uint64 operator- (const uint64 &a, uint32 b)
|
||||
{
|
||||
uint64 b64;
|
||||
b64.HighPart = 0;
|
||||
b64.LowPart = b;
|
||||
return a - b64;
|
||||
}
|
||||
|
||||
uint64 &operator-= (uint64 &a, const uint64 &b)
|
||||
{
|
||||
return a = a - b;
|
||||
}
|
||||
|
||||
uint64 operator>> (const uint64 &a, int shiftCount)
|
||||
{
|
||||
uint64 r = a;
|
||||
|
||||
while (shiftCount--)
|
||||
{
|
||||
r.LowPart >>= 1;
|
||||
|
||||
if ((byte) r.HighPart & 1)
|
||||
r.LowPart |= 0x80000000UL;
|
||||
|
||||
r.HighPart >>= 1;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
uint64 operator<< (const uint64 &a, int shiftCount)
|
||||
{
|
||||
uint64 r = a;
|
||||
|
||||
while (shiftCount--)
|
||||
r += r;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
uint64 &operator++ (uint64 &a)
|
||||
{
|
||||
uint64 b;
|
||||
b.HighPart = 0;
|
||||
b.LowPart = 1;
|
||||
|
||||
return a += b;
|
||||
}
|
||||
|
||||
bool operator== (const uint64 &a, const uint64 &b)
|
||||
{
|
||||
return a.HighPart == b.HighPart && a.LowPart == b.LowPart;
|
||||
}
|
||||
|
||||
bool operator> (const uint64 &a, const uint64 &b)
|
||||
{
|
||||
return (a.HighPart > b.HighPart) || (a.HighPart == b.HighPart && a.LowPart > b.LowPart);
|
||||
}
|
||||
|
||||
bool operator< (const uint64 &a, const uint64 &b)
|
||||
{
|
||||
return (a.HighPart < b.HighPart) || (a.HighPart == b.HighPart && a.LowPart < b.LowPart);
|
||||
}
|
||||
|
||||
bool operator>= (const uint64 &a, const uint64 &b)
|
||||
{
|
||||
return a > b || a == b;
|
||||
}
|
||||
|
||||
bool operator<= (const uint64 &a, const uint64 &b)
|
||||
{
|
||||
return a < b || a == b;
|
||||
}
|
||||
|
||||
bool TestInt64 ()
|
||||
{
|
||||
uint64 a, b, c;
|
||||
a.HighPart = 0x00112233UL;
|
||||
a.LowPart = 0xabcd1234UL;
|
||||
|
||||
b.HighPart = 0x00ffeeddUL;
|
||||
b.LowPart = 0xffffFFFFUL;
|
||||
|
||||
a += b;
|
||||
a -= b;
|
||||
|
||||
++a;
|
||||
|
||||
b = b + (uint32) 1UL;
|
||||
|
||||
c = (a - ((a + b) >> 32) - (uint32) 1UL);
|
||||
if (c.HighPart != 0x112233UL || c.LowPart != 0xAABC0123UL)
|
||||
return false;
|
||||
|
||||
c = c << 9;
|
||||
return c.HighPart == 0x22446755UL && c.LowPart == 0x78024600UL;
|
||||
}
|
||||
|
||||
|
||||
void CopyMemory (void *source, uint16 destSegment, uint16 destOffset, uint16 blockSize)
|
||||
{
|
||||
__asm
|
||||
{
|
||||
push es
|
||||
mov si, ss:source
|
||||
mov es, ss:destSegment
|
||||
mov di, ss:destOffset
|
||||
mov cx, ss:blockSize
|
||||
cld
|
||||
rep movsb
|
||||
pop es
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CopyMemory (uint16 sourceSegment, uint16 sourceOffset, void *destination, uint16 blockSize)
|
||||
{
|
||||
__asm
|
||||
{
|
||||
push ds
|
||||
push es
|
||||
mov ax, ds
|
||||
mov es, ax
|
||||
mov di, ss:destination
|
||||
mov si, ss:sourceOffset
|
||||
mov cx, ss:blockSize
|
||||
mov ds, ss:sourceSegment
|
||||
cld
|
||||
rep movsb
|
||||
pop es
|
||||
pop ds
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void EraseMemory (void *memory, int size)
|
||||
{
|
||||
memset (memory, 0, size);
|
||||
}
|
||||
|
||||
|
||||
uint32 GetLinearAddress (uint16 segment, uint16 offset)
|
||||
{
|
||||
return (uint32 (segment) << 4) + offset;
|
||||
}
|
||||
|
||||
|
||||
bool RegionsIntersect (const uint64 &start1, uint32 length1, const uint64 &start2, const uint64 &end2)
|
||||
{
|
||||
uint64 end1 = start1 + length1 - 1UL;
|
||||
uint64 intersectEnd = (end1 <= end2) ? end1 : end2;
|
||||
|
||||
uint64 intersectStart = (start1 >= start2) ? start1 : start2;
|
||||
if (intersectStart > intersectEnd)
|
||||
return false;
|
||||
|
||||
return (intersectEnd + 1UL - intersectStart).LowPart != 0;
|
||||
}
|
||||
|
||||
|
||||
void ThrowFatalException (int line)
|
||||
{
|
||||
PrintChar ('#'); Print (line);
|
||||
while (1);
|
||||
}
|
||||
|
||||
@@ -1,116 +1,116 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Boot_Platform
|
||||
#define TC_HEADER_Boot_Platform
|
||||
|
||||
#pragma warning (disable: 4018 4102 4704 4769)
|
||||
|
||||
#include "TCdefs.h"
|
||||
#include <memory.h>
|
||||
|
||||
typedef char bool;
|
||||
#define false 0
|
||||
#define true 1
|
||||
|
||||
#define nullptr 0
|
||||
#define NULL 0
|
||||
|
||||
typedef UINT64_STRUCT uint64;
|
||||
|
||||
#define array_capacity(arr) (sizeof (arr) / sizeof ((arr)[0]))
|
||||
|
||||
#define TC_TO_STRING2(n) #n
|
||||
#define TC_TO_STRING(n) TC_TO_STRING2(n)
|
||||
|
||||
|
||||
#define TC_X86_CARRY_FLAG 0x1
|
||||
|
||||
#define TC_ASM_EMIT(A,B) __asm _emit 0x##A __asm _emit 0x##B
|
||||
#define TC_ASM_EMIT3(A,B,C) __asm _emit 0x##A __asm _emit 0x##B __asm _emit 0x##C
|
||||
#define TC_ASM_EMIT4(A,B,C,D) __asm _emit 0x##A __asm _emit 0x##B __asm _emit 0x##C __asm _emit 0x##D
|
||||
|
||||
#define TC_ASM_MOV_EAX_DI TC_ASM_EMIT3 (66, 8B, 05)
|
||||
#define TC_ASM_MOV_EBX_DI TC_ASM_EMIT3 (66, 8B, 1D)
|
||||
#define TC_ASM_MOV_ECX_DI TC_ASM_EMIT3 (66, 8B, 0D)
|
||||
#define TC_ASM_MOV_EDX_DI TC_ASM_EMIT3 (66, 8B, 15)
|
||||
|
||||
#define TC_ASM_MOV_DI_EAX TC_ASM_EMIT3 (66, 89, 05)
|
||||
#define TC_ASM_MOV_DI_EBX TC_ASM_EMIT3 (66, 89, 1D)
|
||||
#define TC_ASM_MOV_DI_ECX TC_ASM_EMIT3 (66, 89, 0D)
|
||||
#define TC_ASM_MOV_DI_EDX TC_ASM_EMIT3 (66, 89, 15)
|
||||
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
struct Registers
|
||||
{
|
||||
uint16 Flags;
|
||||
|
||||
union
|
||||
{
|
||||
uint32 EAX;
|
||||
struct { uint16 AX; uint16 EAXH; };
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
uint32 EBX;
|
||||
struct { uint16 BX; uint16 EBXH; };
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
uint32 ECX;
|
||||
struct { uint16 CX; uint16 ECXH; };
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
uint32 EDX;
|
||||
struct { uint16 DX; uint16 EDXH; };
|
||||
};
|
||||
|
||||
uint16 DI;
|
||||
uint16 SI;
|
||||
uint16 DS;
|
||||
uint16 ES;
|
||||
uint16 SS;
|
||||
};
|
||||
|
||||
#pragma pack()
|
||||
|
||||
|
||||
uint64 operator+ (const uint64 &a, const uint64 &b);
|
||||
uint64 operator+ (const uint64 &a, uint32 b);
|
||||
uint64 &operator+= (uint64 &a, const uint64 &b);
|
||||
uint64 operator- (const uint64 &a, const uint64 &b);
|
||||
uint64 operator- (const uint64 &a, uint32 b);
|
||||
uint64 &operator-= (uint64 &a, const uint64 &b);
|
||||
uint64 operator>> (const uint64 &a, int shiftCount);
|
||||
uint64 operator<< (const uint64 &a, int shiftCount);
|
||||
uint64 &operator++ (uint64 &a);
|
||||
bool operator== (const uint64 &a, const uint64 &b);
|
||||
bool operator> (const uint64 &a, const uint64 &b);
|
||||
bool operator< (const uint64 &a, const uint64 &b);
|
||||
bool operator>= (const uint64 &a, const uint64 &b);
|
||||
bool operator<= (const uint64 &a, const uint64 &b);
|
||||
|
||||
void CopyMemory (void *source, uint16 destSegment, uint16 destOffset, uint16 blockSize);
|
||||
void CopyMemory (uint16 sourceSegment, uint16 sourceOffset, void *destination, uint16 blockSize);
|
||||
extern "C" void EraseMemory (void *memory, int size);
|
||||
uint32 GetLinearAddress (uint16 segment, uint16 offset);
|
||||
bool RegionsIntersect (const uint64 &start1, uint32 length1, const uint64 &start2, const uint64 &end2);
|
||||
bool TestInt64 ();
|
||||
extern "C" void ThrowFatalException (int line);
|
||||
|
||||
#endif // TC_HEADER_Boot_Platform
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Boot_Platform
|
||||
#define TC_HEADER_Boot_Platform
|
||||
|
||||
#pragma warning (disable: 4018 4102 4704 4769)
|
||||
|
||||
#include "TCdefs.h"
|
||||
#include <memory.h>
|
||||
|
||||
typedef char bool;
|
||||
#define false 0
|
||||
#define true 1
|
||||
|
||||
#define nullptr 0
|
||||
#define NULL 0
|
||||
|
||||
typedef UINT64_STRUCT uint64;
|
||||
|
||||
#define array_capacity(arr) (sizeof (arr) / sizeof ((arr)[0]))
|
||||
|
||||
#define TC_TO_STRING2(n) #n
|
||||
#define TC_TO_STRING(n) TC_TO_STRING2(n)
|
||||
|
||||
|
||||
#define TC_X86_CARRY_FLAG 0x1
|
||||
|
||||
#define TC_ASM_EMIT(A,B) __asm _emit 0x##A __asm _emit 0x##B
|
||||
#define TC_ASM_EMIT3(A,B,C) __asm _emit 0x##A __asm _emit 0x##B __asm _emit 0x##C
|
||||
#define TC_ASM_EMIT4(A,B,C,D) __asm _emit 0x##A __asm _emit 0x##B __asm _emit 0x##C __asm _emit 0x##D
|
||||
|
||||
#define TC_ASM_MOV_EAX_DI TC_ASM_EMIT3 (66, 8B, 05)
|
||||
#define TC_ASM_MOV_EBX_DI TC_ASM_EMIT3 (66, 8B, 1D)
|
||||
#define TC_ASM_MOV_ECX_DI TC_ASM_EMIT3 (66, 8B, 0D)
|
||||
#define TC_ASM_MOV_EDX_DI TC_ASM_EMIT3 (66, 8B, 15)
|
||||
|
||||
#define TC_ASM_MOV_DI_EAX TC_ASM_EMIT3 (66, 89, 05)
|
||||
#define TC_ASM_MOV_DI_EBX TC_ASM_EMIT3 (66, 89, 1D)
|
||||
#define TC_ASM_MOV_DI_ECX TC_ASM_EMIT3 (66, 89, 0D)
|
||||
#define TC_ASM_MOV_DI_EDX TC_ASM_EMIT3 (66, 89, 15)
|
||||
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
struct Registers
|
||||
{
|
||||
uint16 Flags;
|
||||
|
||||
union
|
||||
{
|
||||
uint32 EAX;
|
||||
struct { uint16 AX; uint16 EAXH; };
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
uint32 EBX;
|
||||
struct { uint16 BX; uint16 EBXH; };
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
uint32 ECX;
|
||||
struct { uint16 CX; uint16 ECXH; };
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
uint32 EDX;
|
||||
struct { uint16 DX; uint16 EDXH; };
|
||||
};
|
||||
|
||||
uint16 DI;
|
||||
uint16 SI;
|
||||
uint16 DS;
|
||||
uint16 ES;
|
||||
uint16 SS;
|
||||
};
|
||||
|
||||
#pragma pack()
|
||||
|
||||
|
||||
uint64 operator+ (const uint64 &a, const uint64 &b);
|
||||
uint64 operator+ (const uint64 &a, uint32 b);
|
||||
uint64 &operator+= (uint64 &a, const uint64 &b);
|
||||
uint64 operator- (const uint64 &a, const uint64 &b);
|
||||
uint64 operator- (const uint64 &a, uint32 b);
|
||||
uint64 &operator-= (uint64 &a, const uint64 &b);
|
||||
uint64 operator>> (const uint64 &a, int shiftCount);
|
||||
uint64 operator<< (const uint64 &a, int shiftCount);
|
||||
uint64 &operator++ (uint64 &a);
|
||||
bool operator== (const uint64 &a, const uint64 &b);
|
||||
bool operator> (const uint64 &a, const uint64 &b);
|
||||
bool operator< (const uint64 &a, const uint64 &b);
|
||||
bool operator>= (const uint64 &a, const uint64 &b);
|
||||
bool operator<= (const uint64 &a, const uint64 &b);
|
||||
|
||||
void CopyMemory (void *source, uint16 destSegment, uint16 destOffset, uint16 blockSize);
|
||||
void CopyMemory (uint16 sourceSegment, uint16 sourceOffset, void *destination, uint16 blockSize);
|
||||
extern "C" void EraseMemory (void *memory, int size);
|
||||
uint32 GetLinearAddress (uint16 segment, uint16 offset);
|
||||
bool RegionsIntersect (const uint64 &start1, uint32 length1, const uint64 &start2, const uint64 &end2);
|
||||
bool TestInt64 ();
|
||||
extern "C" void ThrowFatalException (int line);
|
||||
|
||||
#endif // TC_HEADER_Boot_Platform
|
||||
|
||||
Binary file not shown.
@@ -1,344 +1,344 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Boot/Windows/BootDefs.h"
|
||||
#include "Common.h"
|
||||
#include "Crypto.h"
|
||||
#include "Volumes.h"
|
||||
#include "Wipe.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
/* WARNING: Modifying the following values or their meanings can introduce incompatibility with previous versions. */
|
||||
|
||||
#define TC_IOCTL(CODE) (CTL_CODE (FILE_DEVICE_UNKNOWN, 0x800 + (CODE), METHOD_BUFFERED, FILE_ANY_ACCESS))
|
||||
|
||||
#define TC_IOCTL_GET_DRIVER_VERSION TC_IOCTL (1)
|
||||
#define TC_IOCTL_GET_BOOT_LOADER_VERSION TC_IOCTL (2)
|
||||
#define TC_IOCTL_MOUNT_VOLUME TC_IOCTL (3)
|
||||
#define TC_IOCTL_DISMOUNT_VOLUME TC_IOCTL (4)
|
||||
#define TC_IOCTL_DISMOUNT_ALL_VOLUMES TC_IOCTL (5)
|
||||
#define TC_IOCTL_GET_MOUNTED_VOLUMES TC_IOCTL (6)
|
||||
#define TC_IOCTL_GET_VOLUME_PROPERTIES TC_IOCTL (7)
|
||||
#define TC_IOCTL_GET_DEVICE_REFCOUNT TC_IOCTL (8)
|
||||
#define TC_IOCTL_IS_DRIVER_UNLOAD_DISABLED TC_IOCTL (9)
|
||||
#define TC_IOCTL_IS_ANY_VOLUME_MOUNTED TC_IOCTL (10)
|
||||
#define TC_IOCTL_GET_PASSWORD_CACHE_STATUS TC_IOCTL (11)
|
||||
#define TC_IOCTL_WIPE_PASSWORD_CACHE TC_IOCTL (12)
|
||||
#define TC_IOCTL_OPEN_TEST TC_IOCTL (13)
|
||||
#define TC_IOCTL_GET_DRIVE_PARTITION_INFO TC_IOCTL (14)
|
||||
#define TC_IOCTL_GET_DRIVE_GEOMETRY TC_IOCTL (15)
|
||||
#define TC_IOCTL_PROBE_REAL_DRIVE_SIZE TC_IOCTL (16)
|
||||
#define TC_IOCTL_GET_RESOLVED_SYMLINK TC_IOCTL (17)
|
||||
#define TC_IOCTL_GET_BOOT_ENCRYPTION_STATUS TC_IOCTL (18)
|
||||
#define TC_IOCTL_BOOT_ENCRYPTION_SETUP TC_IOCTL (19)
|
||||
#define TC_IOCTL_ABORT_BOOT_ENCRYPTION_SETUP TC_IOCTL (20)
|
||||
#define TC_IOCTL_GET_BOOT_ENCRYPTION_SETUP_RESULT TC_IOCTL (21)
|
||||
#define TC_IOCTL_GET_BOOT_DRIVE_VOLUME_PROPERTIES TC_IOCTL (22)
|
||||
#define TC_IOCTL_REOPEN_BOOT_VOLUME_HEADER TC_IOCTL (23)
|
||||
#define TC_IOCTL_GET_BOOT_ENCRYPTION_ALGORITHM_NAME TC_IOCTL (24)
|
||||
#define TC_IOCTL_GET_PORTABLE_MODE_STATUS TC_IOCTL (25)
|
||||
#define TC_IOCTL_SET_PORTABLE_MODE_STATUS TC_IOCTL (26)
|
||||
#define TC_IOCTL_IS_HIDDEN_SYSTEM_RUNNING TC_IOCTL (27)
|
||||
#define TC_IOCTL_GET_SYSTEM_DRIVE_CONFIG TC_IOCTL (28)
|
||||
#define TC_IOCTL_DISK_IS_WRITABLE TC_IOCTL (29)
|
||||
#define TC_IOCTL_START_DECOY_SYSTEM_WIPE TC_IOCTL (30)
|
||||
#define TC_IOCTL_ABORT_DECOY_SYSTEM_WIPE TC_IOCTL (31)
|
||||
#define TC_IOCTL_GET_DECOY_SYSTEM_WIPE_STATUS TC_IOCTL (32)
|
||||
#define TC_IOCTL_GET_DECOY_SYSTEM_WIPE_RESULT TC_IOCTL (33)
|
||||
#define TC_IOCTL_WRITE_BOOT_DRIVE_SECTOR TC_IOCTL (34)
|
||||
#define TC_IOCTL_GET_WARNING_FLAGS TC_IOCTL (35)
|
||||
#define TC_IOCTL_SET_SYSTEM_FAVORITE_VOLUME_DIRTY TC_IOCTL (36)
|
||||
#define TC_IOCTL_REREAD_DRIVER_CONFIG TC_IOCTL (37)
|
||||
#define TC_IOCTL_GET_SYSTEM_DRIVE_DUMP_CONFIG TC_IOCTL (38)
|
||||
#define VC_IOCTL_GET_BOOT_LOADER_FINGERPRINT TC_IOCTL (39)
|
||||
|
||||
// Legacy IOCTLs used before version 5.0
|
||||
#define TC_IOCTL_LEGACY_GET_DRIVER_VERSION 466968
|
||||
#define TC_IOCTL_LEGACY_GET_MOUNTED_VOLUMES 466948
|
||||
|
||||
|
||||
/* Start of driver interface structures, the size of these structures may
|
||||
change between versions; so make sure you first send DRIVER_VERSION to
|
||||
check that it's the correct device driver */
|
||||
|
||||
#pragma pack (push)
|
||||
#pragma pack(1)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int nReturnCode; /* Return code back from driver */
|
||||
BOOL FilesystemDirty;
|
||||
BOOL VolumeMountedReadOnlyAfterAccessDenied;
|
||||
BOOL VolumeMountedReadOnlyAfterDeviceWriteProtected;
|
||||
|
||||
wchar_t wszVolume[TC_MAX_PATH]; /* Volume to be mounted */
|
||||
Password VolumePassword; /* User password */
|
||||
BOOL bCache; /* Cache passwords in driver */
|
||||
int nDosDriveNo; /* Drive number to mount */
|
||||
uint32 BytesPerSector;
|
||||
BOOL bMountReadOnly; /* Mount volume in read-only mode */
|
||||
BOOL bMountRemovable; /* Mount volume as removable media */
|
||||
BOOL bExclusiveAccess; /* Open host file/device in exclusive access mode */
|
||||
BOOL bMountManager; /* Announce volume to mount manager */
|
||||
BOOL bPreserveTimestamp; /* Preserve file container timestamp */
|
||||
BOOL bPartitionInInactiveSysEncScope; /* If TRUE, we are to attempt to mount a partition located on an encrypted system drive without pre-boot authentication. */
|
||||
int nPartitionInInactiveSysEncScopeDriveNo; /* If bPartitionInInactiveSysEncScope is TRUE, this contains the drive number of the system drive on which the partition is located. */
|
||||
BOOL SystemFavorite;
|
||||
// Hidden volume protection
|
||||
BOOL bProtectHiddenVolume; /* TRUE if the user wants the hidden volume within this volume to be protected against being overwritten (damaged) */
|
||||
Password ProtectedHidVolPassword; /* Password to the hidden volume to be protected against overwriting */
|
||||
BOOL UseBackupHeader;
|
||||
BOOL RecoveryMode;
|
||||
int pkcs5_prf;
|
||||
int ProtectedHidVolPkcs5Prf;
|
||||
BOOL bTrueCryptMode;
|
||||
uint32 BytesPerPhysicalSector;
|
||||
int VolumePim;
|
||||
int ProtectedHidVolPim;
|
||||
wchar_t wszLabel[33]; // maximum label length is 32 for NTFS and 11 for FAT32
|
||||
BOOL bIsNTFS; // output only
|
||||
BOOL bDriverSetLabel;
|
||||
BOOL bCachePim;
|
||||
} MOUNT_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int nDosDriveNo; /* Drive letter to unmount */
|
||||
BOOL ignoreOpenFiles;
|
||||
BOOL HiddenVolumeProtectionTriggered;
|
||||
int nReturnCode; /* Return code back from driver */
|
||||
} UNMOUNT_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned __int32 ulMountedDrives; /* Bitfield of all mounted drive letters */
|
||||
wchar_t wszVolume[26][TC_MAX_PATH]; /* Volume names of mounted volumes */
|
||||
wchar_t wszLabel[26][33]; /* Labels of mounted volumes */
|
||||
wchar_t volumeID[26][VOLUME_ID_SIZE]; /* IDs of mounted volumes */
|
||||
unsigned __int64 diskLength[26];
|
||||
int ea[26];
|
||||
int volumeType[26]; /* Volume type (e.g. PROP_VOL_TYPE_OUTER, PROP_VOL_TYPE_OUTER_VOL_WRITE_PREVENTED, etc.) */
|
||||
BOOL truecryptMode[26];
|
||||
} MOUNT_LIST_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int driveNo;
|
||||
int uniqueId;
|
||||
wchar_t wszVolume[TC_MAX_PATH];
|
||||
unsigned __int64 diskLength;
|
||||
int ea;
|
||||
int mode;
|
||||
int pkcs5;
|
||||
int pkcs5Iterations;
|
||||
BOOL hiddenVolume;
|
||||
BOOL readOnly;
|
||||
BOOL removable;
|
||||
BOOL partitionInInactiveSysEncScope;
|
||||
uint32 volumeHeaderFlags;
|
||||
unsigned __int64 totalBytesRead;
|
||||
unsigned __int64 totalBytesWritten;
|
||||
int hiddenVolProtection; /* Hidden volume protection status (e.g. HIDVOL_PROT_STATUS_NONE, HIDVOL_PROT_STATUS_ACTIVE, etc.) */
|
||||
int volFormatVersion;
|
||||
int volumePim;
|
||||
wchar_t wszLabel[33];
|
||||
BOOL bDriverSetLabel;
|
||||
unsigned char volumeID[VOLUME_ID_SIZE];
|
||||
} VOLUME_PROPERTIES_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
WCHAR symLinkName[TC_MAX_PATH];
|
||||
WCHAR targetName[TC_MAX_PATH];
|
||||
} RESOLVE_SYMLINK_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
WCHAR deviceName[TC_MAX_PATH];
|
||||
PARTITION_INFORMATION partInfo;
|
||||
BOOL IsGPT;
|
||||
BOOL IsDynamic;
|
||||
}
|
||||
DISK_PARTITION_INFO_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
WCHAR deviceName[TC_MAX_PATH];
|
||||
DISK_GEOMETRY diskGeometry;
|
||||
}
|
||||
DISK_GEOMETRY_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
WCHAR DeviceName[TC_MAX_PATH];
|
||||
LARGE_INTEGER RealDriveSize;
|
||||
BOOL TimeOut;
|
||||
} ProbeRealDriveSizeRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
wchar_t wszFileName[TC_MAX_PATH]; // Volume to be "open tested"
|
||||
BOOL bDetectTCBootLoader; // Whether the driver is to determine if the first sector contains a portion of the TrueCrypt Boot Loader
|
||||
BOOL TCBootLoaderDetected;
|
||||
BOOL DetectFilesystem;
|
||||
BOOL FilesystemDetected;
|
||||
BOOL bMatchVolumeID;
|
||||
unsigned char volumeID[VOLUME_ID_SIZE];
|
||||
BOOL VolumeIDMatched;
|
||||
} OPEN_TEST_STRUCT;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SetupNone = 0,
|
||||
SetupEncryption,
|
||||
SetupDecryption
|
||||
} BootEncryptionSetupMode;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// New fields must be added at the end of the structure to maintain compatibility with previous versions
|
||||
BOOL DeviceFilterActive;
|
||||
|
||||
uint16 BootLoaderVersion;
|
||||
|
||||
BOOL DriveMounted;
|
||||
BOOL VolumeHeaderPresent;
|
||||
BOOL DriveEncrypted;
|
||||
|
||||
LARGE_INTEGER BootDriveLength;
|
||||
|
||||
int64 ConfiguredEncryptedAreaStart;
|
||||
int64 ConfiguredEncryptedAreaEnd;
|
||||
int64 EncryptedAreaStart;
|
||||
int64 EncryptedAreaEnd;
|
||||
|
||||
uint32 VolumeHeaderSaltCrc32;
|
||||
|
||||
BOOL SetupInProgress;
|
||||
BootEncryptionSetupMode SetupMode;
|
||||
BOOL TransformWaitingForIdle;
|
||||
|
||||
uint32 HibernationPreventionCount;
|
||||
|
||||
BOOL HiddenSystem;
|
||||
int64 HiddenSystemPartitionStart;
|
||||
|
||||
// Number of times the filter driver answered that an unencrypted volume
|
||||
// is read-only (or mounted an outer/normal TrueCrypt volume as read only)
|
||||
uint32 HiddenSysLeakProtectionCount;
|
||||
|
||||
} BootEncryptionStatus;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BootEncryptionSetupMode SetupMode;
|
||||
WipeAlgorithmId WipeAlgorithm;
|
||||
BOOL ZeroUnreadableSectors;
|
||||
BOOL DiscardUnreadableEncryptedSectors;
|
||||
} BootEncryptionSetupRequest;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Password VolumePassword;
|
||||
int pkcs5_prf;
|
||||
int pim;
|
||||
} ReopenBootVolumeHeaderRequest;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char BootEncryptionAlgorithmName[256];
|
||||
char BootPrfAlgorithmName[256];
|
||||
} GetBootEncryptionAlgorithmNameRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
byte Fingerprint[WHIRLPOOL_DIGESTSIZE + SHA512_DIGESTSIZE];
|
||||
} BootLoaderFingerprintRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
wchar_t DevicePath[TC_MAX_PATH];
|
||||
byte Configuration;
|
||||
BOOL DriveIsDynamic;
|
||||
uint16 BootLoaderVersion;
|
||||
byte UserConfiguration;
|
||||
char CustomUserMessage[TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH + 1];
|
||||
} GetSystemDriveConfigurationRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
WipeAlgorithmId WipeAlgorithm;
|
||||
byte WipeKey[MASTER_KEYDATA_SIZE];
|
||||
} WipeDecoySystemRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BOOL WipeInProgress;
|
||||
WipeAlgorithmId WipeAlgorithm;
|
||||
int64 WipedAreaEnd;
|
||||
} DecoySystemWipeStatus;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
LARGE_INTEGER Offset;
|
||||
byte Data[TC_SECTOR_SIZE_BIOS];
|
||||
} WriteBootDriveSectorRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BOOL PagingFileCreationPrevented;
|
||||
BOOL SystemFavoriteVolumeDirty;
|
||||
} GetWarningFlagsRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struct _DriveFilterExtension *BootDriveFilterExtension;
|
||||
BOOL HwEncryptionEnabled;
|
||||
} GetSystemDriveDumpConfigRequest;
|
||||
|
||||
#pragma pack (pop)
|
||||
|
||||
#define DRIVER_STR WIDE
|
||||
|
||||
#define TC_UNIQUE_ID_PREFIX "VeraCryptVolume"
|
||||
#define TC_MOUNT_PREFIX L"\\Device\\VeraCryptVolume"
|
||||
|
||||
#define NT_MOUNT_PREFIX DRIVER_STR("\\Device\\VeraCryptVolume")
|
||||
#define NT_ROOT_PREFIX DRIVER_STR("\\Device\\VeraCrypt")
|
||||
#define DOS_MOUNT_PREFIX_DEFAULT DRIVER_STR("\\DosDevices\\")
|
||||
#define DOS_MOUNT_PREFIX_GLOBAL DRIVER_STR("\\GLOBAL??\\") // Use Global MS-DOS device names for sanity checks on drive letters
|
||||
#define DOS_ROOT_PREFIX DRIVER_STR("\\DosDevices\\VeraCrypt")
|
||||
#define WIN32_ROOT_PREFIX DRIVER_STR("\\\\.\\VeraCrypt")
|
||||
|
||||
#define TC_DRIVER_CONFIG_REG_VALUE_NAME DRIVER_STR("VeraCryptConfig")
|
||||
#define TC_ENCRYPTION_FREE_CPU_COUNT_REG_VALUE_NAME DRIVER_STR("VeraCryptEncryptionFreeCpuCount")
|
||||
|
||||
// WARNING: Modifying the following values can introduce incompatibility with previous versions.
|
||||
#define TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD 0x1
|
||||
#define TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD_FOR_SYS_FAVORITES 0x2
|
||||
#define TC_DRIVER_CONFIG_DISABLE_NONADMIN_SYS_FAVORITES_ACCESS 0x4
|
||||
#define TC_DRIVER_CONFIG_DISABLE_HARDWARE_ENCRYPTION 0x8
|
||||
#define TC_DRIVER_CONFIG_ENABLE_EXTENDED_IOCTL 0x10
|
||||
#define TC_DRIVER_CONFIG_DISABLE_EVIL_MAID_ATTACK_DETECTION 0x20
|
||||
#define TC_DRIVER_CONFIG_CACHE_BOOT_PIM 0x40
|
||||
|
||||
#endif /* _WIN32 */
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Boot/Windows/BootDefs.h"
|
||||
#include "Common.h"
|
||||
#include "Crypto.h"
|
||||
#include "Volumes.h"
|
||||
#include "Wipe.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
/* WARNING: Modifying the following values or their meanings can introduce incompatibility with previous versions. */
|
||||
|
||||
#define TC_IOCTL(CODE) (CTL_CODE (FILE_DEVICE_UNKNOWN, 0x800 + (CODE), METHOD_BUFFERED, FILE_ANY_ACCESS))
|
||||
|
||||
#define TC_IOCTL_GET_DRIVER_VERSION TC_IOCTL (1)
|
||||
#define TC_IOCTL_GET_BOOT_LOADER_VERSION TC_IOCTL (2)
|
||||
#define TC_IOCTL_MOUNT_VOLUME TC_IOCTL (3)
|
||||
#define TC_IOCTL_DISMOUNT_VOLUME TC_IOCTL (4)
|
||||
#define TC_IOCTL_DISMOUNT_ALL_VOLUMES TC_IOCTL (5)
|
||||
#define TC_IOCTL_GET_MOUNTED_VOLUMES TC_IOCTL (6)
|
||||
#define TC_IOCTL_GET_VOLUME_PROPERTIES TC_IOCTL (7)
|
||||
#define TC_IOCTL_GET_DEVICE_REFCOUNT TC_IOCTL (8)
|
||||
#define TC_IOCTL_IS_DRIVER_UNLOAD_DISABLED TC_IOCTL (9)
|
||||
#define TC_IOCTL_IS_ANY_VOLUME_MOUNTED TC_IOCTL (10)
|
||||
#define TC_IOCTL_GET_PASSWORD_CACHE_STATUS TC_IOCTL (11)
|
||||
#define TC_IOCTL_WIPE_PASSWORD_CACHE TC_IOCTL (12)
|
||||
#define TC_IOCTL_OPEN_TEST TC_IOCTL (13)
|
||||
#define TC_IOCTL_GET_DRIVE_PARTITION_INFO TC_IOCTL (14)
|
||||
#define TC_IOCTL_GET_DRIVE_GEOMETRY TC_IOCTL (15)
|
||||
#define TC_IOCTL_PROBE_REAL_DRIVE_SIZE TC_IOCTL (16)
|
||||
#define TC_IOCTL_GET_RESOLVED_SYMLINK TC_IOCTL (17)
|
||||
#define TC_IOCTL_GET_BOOT_ENCRYPTION_STATUS TC_IOCTL (18)
|
||||
#define TC_IOCTL_BOOT_ENCRYPTION_SETUP TC_IOCTL (19)
|
||||
#define TC_IOCTL_ABORT_BOOT_ENCRYPTION_SETUP TC_IOCTL (20)
|
||||
#define TC_IOCTL_GET_BOOT_ENCRYPTION_SETUP_RESULT TC_IOCTL (21)
|
||||
#define TC_IOCTL_GET_BOOT_DRIVE_VOLUME_PROPERTIES TC_IOCTL (22)
|
||||
#define TC_IOCTL_REOPEN_BOOT_VOLUME_HEADER TC_IOCTL (23)
|
||||
#define TC_IOCTL_GET_BOOT_ENCRYPTION_ALGORITHM_NAME TC_IOCTL (24)
|
||||
#define TC_IOCTL_GET_PORTABLE_MODE_STATUS TC_IOCTL (25)
|
||||
#define TC_IOCTL_SET_PORTABLE_MODE_STATUS TC_IOCTL (26)
|
||||
#define TC_IOCTL_IS_HIDDEN_SYSTEM_RUNNING TC_IOCTL (27)
|
||||
#define TC_IOCTL_GET_SYSTEM_DRIVE_CONFIG TC_IOCTL (28)
|
||||
#define TC_IOCTL_DISK_IS_WRITABLE TC_IOCTL (29)
|
||||
#define TC_IOCTL_START_DECOY_SYSTEM_WIPE TC_IOCTL (30)
|
||||
#define TC_IOCTL_ABORT_DECOY_SYSTEM_WIPE TC_IOCTL (31)
|
||||
#define TC_IOCTL_GET_DECOY_SYSTEM_WIPE_STATUS TC_IOCTL (32)
|
||||
#define TC_IOCTL_GET_DECOY_SYSTEM_WIPE_RESULT TC_IOCTL (33)
|
||||
#define TC_IOCTL_WRITE_BOOT_DRIVE_SECTOR TC_IOCTL (34)
|
||||
#define TC_IOCTL_GET_WARNING_FLAGS TC_IOCTL (35)
|
||||
#define TC_IOCTL_SET_SYSTEM_FAVORITE_VOLUME_DIRTY TC_IOCTL (36)
|
||||
#define TC_IOCTL_REREAD_DRIVER_CONFIG TC_IOCTL (37)
|
||||
#define TC_IOCTL_GET_SYSTEM_DRIVE_DUMP_CONFIG TC_IOCTL (38)
|
||||
#define VC_IOCTL_GET_BOOT_LOADER_FINGERPRINT TC_IOCTL (39)
|
||||
|
||||
// Legacy IOCTLs used before version 5.0
|
||||
#define TC_IOCTL_LEGACY_GET_DRIVER_VERSION 466968
|
||||
#define TC_IOCTL_LEGACY_GET_MOUNTED_VOLUMES 466948
|
||||
|
||||
|
||||
/* Start of driver interface structures, the size of these structures may
|
||||
change between versions; so make sure you first send DRIVER_VERSION to
|
||||
check that it's the correct device driver */
|
||||
|
||||
#pragma pack (push)
|
||||
#pragma pack(1)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int nReturnCode; /* Return code back from driver */
|
||||
BOOL FilesystemDirty;
|
||||
BOOL VolumeMountedReadOnlyAfterAccessDenied;
|
||||
BOOL VolumeMountedReadOnlyAfterDeviceWriteProtected;
|
||||
|
||||
wchar_t wszVolume[TC_MAX_PATH]; /* Volume to be mounted */
|
||||
Password VolumePassword; /* User password */
|
||||
BOOL bCache; /* Cache passwords in driver */
|
||||
int nDosDriveNo; /* Drive number to mount */
|
||||
uint32 BytesPerSector;
|
||||
BOOL bMountReadOnly; /* Mount volume in read-only mode */
|
||||
BOOL bMountRemovable; /* Mount volume as removable media */
|
||||
BOOL bExclusiveAccess; /* Open host file/device in exclusive access mode */
|
||||
BOOL bMountManager; /* Announce volume to mount manager */
|
||||
BOOL bPreserveTimestamp; /* Preserve file container timestamp */
|
||||
BOOL bPartitionInInactiveSysEncScope; /* If TRUE, we are to attempt to mount a partition located on an encrypted system drive without pre-boot authentication. */
|
||||
int nPartitionInInactiveSysEncScopeDriveNo; /* If bPartitionInInactiveSysEncScope is TRUE, this contains the drive number of the system drive on which the partition is located. */
|
||||
BOOL SystemFavorite;
|
||||
// Hidden volume protection
|
||||
BOOL bProtectHiddenVolume; /* TRUE if the user wants the hidden volume within this volume to be protected against being overwritten (damaged) */
|
||||
Password ProtectedHidVolPassword; /* Password to the hidden volume to be protected against overwriting */
|
||||
BOOL UseBackupHeader;
|
||||
BOOL RecoveryMode;
|
||||
int pkcs5_prf;
|
||||
int ProtectedHidVolPkcs5Prf;
|
||||
BOOL bTrueCryptMode;
|
||||
uint32 BytesPerPhysicalSector;
|
||||
int VolumePim;
|
||||
int ProtectedHidVolPim;
|
||||
wchar_t wszLabel[33]; // maximum label length is 32 for NTFS and 11 for FAT32
|
||||
BOOL bIsNTFS; // output only
|
||||
BOOL bDriverSetLabel;
|
||||
BOOL bCachePim;
|
||||
} MOUNT_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int nDosDriveNo; /* Drive letter to unmount */
|
||||
BOOL ignoreOpenFiles;
|
||||
BOOL HiddenVolumeProtectionTriggered;
|
||||
int nReturnCode; /* Return code back from driver */
|
||||
} UNMOUNT_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned __int32 ulMountedDrives; /* Bitfield of all mounted drive letters */
|
||||
wchar_t wszVolume[26][TC_MAX_PATH]; /* Volume names of mounted volumes */
|
||||
wchar_t wszLabel[26][33]; /* Labels of mounted volumes */
|
||||
wchar_t volumeID[26][VOLUME_ID_SIZE]; /* IDs of mounted volumes */
|
||||
unsigned __int64 diskLength[26];
|
||||
int ea[26];
|
||||
int volumeType[26]; /* Volume type (e.g. PROP_VOL_TYPE_OUTER, PROP_VOL_TYPE_OUTER_VOL_WRITE_PREVENTED, etc.) */
|
||||
BOOL truecryptMode[26];
|
||||
} MOUNT_LIST_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int driveNo;
|
||||
int uniqueId;
|
||||
wchar_t wszVolume[TC_MAX_PATH];
|
||||
unsigned __int64 diskLength;
|
||||
int ea;
|
||||
int mode;
|
||||
int pkcs5;
|
||||
int pkcs5Iterations;
|
||||
BOOL hiddenVolume;
|
||||
BOOL readOnly;
|
||||
BOOL removable;
|
||||
BOOL partitionInInactiveSysEncScope;
|
||||
uint32 volumeHeaderFlags;
|
||||
unsigned __int64 totalBytesRead;
|
||||
unsigned __int64 totalBytesWritten;
|
||||
int hiddenVolProtection; /* Hidden volume protection status (e.g. HIDVOL_PROT_STATUS_NONE, HIDVOL_PROT_STATUS_ACTIVE, etc.) */
|
||||
int volFormatVersion;
|
||||
int volumePim;
|
||||
wchar_t wszLabel[33];
|
||||
BOOL bDriverSetLabel;
|
||||
unsigned char volumeID[VOLUME_ID_SIZE];
|
||||
} VOLUME_PROPERTIES_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
WCHAR symLinkName[TC_MAX_PATH];
|
||||
WCHAR targetName[TC_MAX_PATH];
|
||||
} RESOLVE_SYMLINK_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
WCHAR deviceName[TC_MAX_PATH];
|
||||
PARTITION_INFORMATION partInfo;
|
||||
BOOL IsGPT;
|
||||
BOOL IsDynamic;
|
||||
}
|
||||
DISK_PARTITION_INFO_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
WCHAR deviceName[TC_MAX_PATH];
|
||||
DISK_GEOMETRY diskGeometry;
|
||||
}
|
||||
DISK_GEOMETRY_STRUCT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
WCHAR DeviceName[TC_MAX_PATH];
|
||||
LARGE_INTEGER RealDriveSize;
|
||||
BOOL TimeOut;
|
||||
} ProbeRealDriveSizeRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
wchar_t wszFileName[TC_MAX_PATH]; // Volume to be "open tested"
|
||||
BOOL bDetectTCBootLoader; // Whether the driver is to determine if the first sector contains a portion of the TrueCrypt Boot Loader
|
||||
BOOL TCBootLoaderDetected;
|
||||
BOOL DetectFilesystem;
|
||||
BOOL FilesystemDetected;
|
||||
BOOL bMatchVolumeID;
|
||||
unsigned char volumeID[VOLUME_ID_SIZE];
|
||||
BOOL VolumeIDMatched;
|
||||
} OPEN_TEST_STRUCT;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SetupNone = 0,
|
||||
SetupEncryption,
|
||||
SetupDecryption
|
||||
} BootEncryptionSetupMode;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// New fields must be added at the end of the structure to maintain compatibility with previous versions
|
||||
BOOL DeviceFilterActive;
|
||||
|
||||
uint16 BootLoaderVersion;
|
||||
|
||||
BOOL DriveMounted;
|
||||
BOOL VolumeHeaderPresent;
|
||||
BOOL DriveEncrypted;
|
||||
|
||||
LARGE_INTEGER BootDriveLength;
|
||||
|
||||
int64 ConfiguredEncryptedAreaStart;
|
||||
int64 ConfiguredEncryptedAreaEnd;
|
||||
int64 EncryptedAreaStart;
|
||||
int64 EncryptedAreaEnd;
|
||||
|
||||
uint32 VolumeHeaderSaltCrc32;
|
||||
|
||||
BOOL SetupInProgress;
|
||||
BootEncryptionSetupMode SetupMode;
|
||||
BOOL TransformWaitingForIdle;
|
||||
|
||||
uint32 HibernationPreventionCount;
|
||||
|
||||
BOOL HiddenSystem;
|
||||
int64 HiddenSystemPartitionStart;
|
||||
|
||||
// Number of times the filter driver answered that an unencrypted volume
|
||||
// is read-only (or mounted an outer/normal TrueCrypt volume as read only)
|
||||
uint32 HiddenSysLeakProtectionCount;
|
||||
|
||||
} BootEncryptionStatus;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BootEncryptionSetupMode SetupMode;
|
||||
WipeAlgorithmId WipeAlgorithm;
|
||||
BOOL ZeroUnreadableSectors;
|
||||
BOOL DiscardUnreadableEncryptedSectors;
|
||||
} BootEncryptionSetupRequest;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Password VolumePassword;
|
||||
int pkcs5_prf;
|
||||
int pim;
|
||||
} ReopenBootVolumeHeaderRequest;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char BootEncryptionAlgorithmName[256];
|
||||
char BootPrfAlgorithmName[256];
|
||||
} GetBootEncryptionAlgorithmNameRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
byte Fingerprint[WHIRLPOOL_DIGESTSIZE + SHA512_DIGESTSIZE];
|
||||
} BootLoaderFingerprintRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
wchar_t DevicePath[TC_MAX_PATH];
|
||||
byte Configuration;
|
||||
BOOL DriveIsDynamic;
|
||||
uint16 BootLoaderVersion;
|
||||
byte UserConfiguration;
|
||||
char CustomUserMessage[TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH + 1];
|
||||
} GetSystemDriveConfigurationRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
WipeAlgorithmId WipeAlgorithm;
|
||||
byte WipeKey[MASTER_KEYDATA_SIZE];
|
||||
} WipeDecoySystemRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BOOL WipeInProgress;
|
||||
WipeAlgorithmId WipeAlgorithm;
|
||||
int64 WipedAreaEnd;
|
||||
} DecoySystemWipeStatus;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
LARGE_INTEGER Offset;
|
||||
byte Data[TC_SECTOR_SIZE_BIOS];
|
||||
} WriteBootDriveSectorRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BOOL PagingFileCreationPrevented;
|
||||
BOOL SystemFavoriteVolumeDirty;
|
||||
} GetWarningFlagsRequest;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struct _DriveFilterExtension *BootDriveFilterExtension;
|
||||
BOOL HwEncryptionEnabled;
|
||||
} GetSystemDriveDumpConfigRequest;
|
||||
|
||||
#pragma pack (pop)
|
||||
|
||||
#define DRIVER_STR WIDE
|
||||
|
||||
#define TC_UNIQUE_ID_PREFIX "VeraCryptVolume"
|
||||
#define TC_MOUNT_PREFIX L"\\Device\\VeraCryptVolume"
|
||||
|
||||
#define NT_MOUNT_PREFIX DRIVER_STR("\\Device\\VeraCryptVolume")
|
||||
#define NT_ROOT_PREFIX DRIVER_STR("\\Device\\VeraCrypt")
|
||||
#define DOS_MOUNT_PREFIX_DEFAULT DRIVER_STR("\\DosDevices\\")
|
||||
#define DOS_MOUNT_PREFIX_GLOBAL DRIVER_STR("\\GLOBAL??\\") // Use Global MS-DOS device names for sanity checks on drive letters
|
||||
#define DOS_ROOT_PREFIX DRIVER_STR("\\DosDevices\\VeraCrypt")
|
||||
#define WIN32_ROOT_PREFIX DRIVER_STR("\\\\.\\VeraCrypt")
|
||||
|
||||
#define TC_DRIVER_CONFIG_REG_VALUE_NAME DRIVER_STR("VeraCryptConfig")
|
||||
#define TC_ENCRYPTION_FREE_CPU_COUNT_REG_VALUE_NAME DRIVER_STR("VeraCryptEncryptionFreeCpuCount")
|
||||
|
||||
// WARNING: Modifying the following values can introduce incompatibility with previous versions.
|
||||
#define TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD 0x1
|
||||
#define TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD_FOR_SYS_FAVORITES 0x2
|
||||
#define TC_DRIVER_CONFIG_DISABLE_NONADMIN_SYS_FAVORITES_ACCESS 0x4
|
||||
#define TC_DRIVER_CONFIG_DISABLE_HARDWARE_ENCRYPTION 0x8
|
||||
#define TC_DRIVER_CONFIG_ENABLE_EXTENDED_IOCTL 0x10
|
||||
#define TC_DRIVER_CONFIG_DISABLE_EVIL_MAID_ATTACK_DETECTION 0x20
|
||||
#define TC_DRIVER_CONFIG_CACHE_BOOT_PIM 0x40
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
@@ -1,246 +1,246 @@
|
||||
/*
|
||||
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 <atlcomcli.h>
|
||||
#include <atlconv.h>
|
||||
#include <comutil.h>
|
||||
#include <windows.h>
|
||||
#include "BaseCom.h"
|
||||
#include "BootEncryption.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Registry.h"
|
||||
|
||||
using namespace VeraCrypt;
|
||||
|
||||
HRESULT CreateElevatedComObject (HWND hwnd, REFGUID guid, REFIID iid, void **ppv)
|
||||
{
|
||||
WCHAR monikerName[1024];
|
||||
WCHAR clsid[1024];
|
||||
BIND_OPTS3 bo;
|
||||
|
||||
StringFromGUID2 (guid, clsid, sizeof (clsid) / 2);
|
||||
swprintf_s (monikerName, sizeof (monikerName) / 2, L"Elevation:Administrator!new:%s", clsid);
|
||||
|
||||
memset (&bo, 0, sizeof (bo));
|
||||
bo.cbStruct = sizeof (bo);
|
||||
bo.hwnd = hwnd;
|
||||
bo.dwClassContext = CLSCTX_LOCAL_SERVER;
|
||||
|
||||
// Prevent the GUI from being half-rendered when the UAC prompt "freezes" it
|
||||
ProcessPaintMessages (hwnd, 5000);
|
||||
|
||||
return CoGetObject (monikerName, &bo, iid, ppv);
|
||||
}
|
||||
|
||||
|
||||
BOOL ComGetInstanceBase (HWND hWnd, REFCLSID clsid, REFIID iid, void **tcServer)
|
||||
{
|
||||
BOOL r;
|
||||
|
||||
if (IsUacSupported ())
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
r = CreateElevatedComObject (hWnd, clsid, iid, tcServer) == S_OK;
|
||||
if (r)
|
||||
break;
|
||||
else
|
||||
{
|
||||
if (IDRETRY == ErrorRetryCancel ("UAC_INIT_ERROR", hWnd))
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
r = CoCreateInstance (clsid, NULL, CLSCTX_LOCAL_SERVER, iid, tcServer) == S_OK;
|
||||
if (!r)
|
||||
Error ("UAC_INIT_ERROR", hWnd);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::CallDriver (DWORD ioctl, BSTR input, BSTR *output)
|
||||
{
|
||||
try
|
||||
{
|
||||
BootEncryption bootEnc (NULL);
|
||||
bootEnc.CallDriver (ioctl,
|
||||
(BYTE *) input, !(BYTE *) input ? 0 : ((DWORD *) ((BYTE *) input))[-1],
|
||||
(BYTE *) *output, !(BYTE *) *output ? 0 : ((DWORD *) ((BYTE *) *output))[-1]);
|
||||
}
|
||||
catch (SystemException &)
|
||||
{
|
||||
return GetLastError();
|
||||
}
|
||||
catch (Exception &e)
|
||||
{
|
||||
e.Show (NULL);
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::CopyFile (BSTR sourceFile, BSTR destinationFile)
|
||||
{
|
||||
|
||||
if (!::CopyFileW (sourceFile, destinationFile, FALSE))
|
||||
return GetLastError();
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::DeleteFile (BSTR file)
|
||||
{
|
||||
|
||||
if (!::DeleteFileW (file))
|
||||
return GetLastError();
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
BOOL BaseCom::IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly)
|
||||
{
|
||||
return ::IsPagingFileActive (checkNonWindowsPartitionsOnly);
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *bufferBstr, unsigned __int64 offset, unsigned __int32 size, DWORD *sizeDone)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto_ptr <File> file (device ? new Device (filePath, !write) : new File (filePath, !write));
|
||||
file->CheckOpened (SRC_POS);
|
||||
file->SeekAt (offset);
|
||||
|
||||
if (write)
|
||||
{
|
||||
file->Write ((BYTE *) *bufferBstr, size);
|
||||
*sizeDone = size;
|
||||
}
|
||||
else
|
||||
{
|
||||
*sizeDone = file->Read ((BYTE *) *bufferBstr, size);
|
||||
}
|
||||
}
|
||||
catch (SystemException &)
|
||||
{
|
||||
return GetLastError();
|
||||
}
|
||||
catch (Exception &e)
|
||||
{
|
||||
e.Show (NULL);
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::RegisterFilterDriver (BOOL registerDriver, int filterType)
|
||||
{
|
||||
try
|
||||
{
|
||||
BootEncryption bootEnc (NULL);
|
||||
bootEnc.RegisterFilterDriver (registerDriver ? true : false, (BootEncryption::FilterType) filterType);
|
||||
}
|
||||
catch (SystemException &)
|
||||
{
|
||||
return GetLastError();
|
||||
}
|
||||
catch (Exception &e)
|
||||
{
|
||||
e.Show (NULL);
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::RegisterSystemFavoritesService (BOOL registerService)
|
||||
{
|
||||
try
|
||||
{
|
||||
BootEncryption bootEnc (NULL);
|
||||
bootEnc.RegisterSystemFavoritesService (registerService);
|
||||
}
|
||||
catch (SystemException &)
|
||||
{
|
||||
return GetLastError();
|
||||
}
|
||||
catch (Exception &e)
|
||||
{
|
||||
e.Show (NULL);
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::SetDriverServiceStartType (DWORD startType)
|
||||
{
|
||||
try
|
||||
{
|
||||
BootEncryption bootEnc (NULL);
|
||||
bootEnc.SetDriverServiceStartType (startType);
|
||||
}
|
||||
catch (SystemException &)
|
||||
{
|
||||
return GetLastError();
|
||||
}
|
||||
catch (Exception &e)
|
||||
{
|
||||
e.Show (NULL);
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::WriteLocalMachineRegistryDwordValue (BSTR keyPath, BSTR valueName, DWORD value)
|
||||
{
|
||||
if (!::WriteLocalMachineRegistryDword (keyPath, valueName, value))
|
||||
return GetLastError();
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
/*
|
||||
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 <atlcomcli.h>
|
||||
#include <atlconv.h>
|
||||
#include <comutil.h>
|
||||
#include <windows.h>
|
||||
#include "BaseCom.h"
|
||||
#include "BootEncryption.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Registry.h"
|
||||
|
||||
using namespace VeraCrypt;
|
||||
|
||||
HRESULT CreateElevatedComObject (HWND hwnd, REFGUID guid, REFIID iid, void **ppv)
|
||||
{
|
||||
WCHAR monikerName[1024];
|
||||
WCHAR clsid[1024];
|
||||
BIND_OPTS3 bo;
|
||||
|
||||
StringFromGUID2 (guid, clsid, sizeof (clsid) / 2);
|
||||
swprintf_s (monikerName, sizeof (monikerName) / 2, L"Elevation:Administrator!new:%s", clsid);
|
||||
|
||||
memset (&bo, 0, sizeof (bo));
|
||||
bo.cbStruct = sizeof (bo);
|
||||
bo.hwnd = hwnd;
|
||||
bo.dwClassContext = CLSCTX_LOCAL_SERVER;
|
||||
|
||||
// Prevent the GUI from being half-rendered when the UAC prompt "freezes" it
|
||||
ProcessPaintMessages (hwnd, 5000);
|
||||
|
||||
return CoGetObject (monikerName, &bo, iid, ppv);
|
||||
}
|
||||
|
||||
|
||||
BOOL ComGetInstanceBase (HWND hWnd, REFCLSID clsid, REFIID iid, void **tcServer)
|
||||
{
|
||||
BOOL r;
|
||||
|
||||
if (IsUacSupported ())
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
r = CreateElevatedComObject (hWnd, clsid, iid, tcServer) == S_OK;
|
||||
if (r)
|
||||
break;
|
||||
else
|
||||
{
|
||||
if (IDRETRY == ErrorRetryCancel ("UAC_INIT_ERROR", hWnd))
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
r = CoCreateInstance (clsid, NULL, CLSCTX_LOCAL_SERVER, iid, tcServer) == S_OK;
|
||||
if (!r)
|
||||
Error ("UAC_INIT_ERROR", hWnd);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::CallDriver (DWORD ioctl, BSTR input, BSTR *output)
|
||||
{
|
||||
try
|
||||
{
|
||||
BootEncryption bootEnc (NULL);
|
||||
bootEnc.CallDriver (ioctl,
|
||||
(BYTE *) input, !(BYTE *) input ? 0 : ((DWORD *) ((BYTE *) input))[-1],
|
||||
(BYTE *) *output, !(BYTE *) *output ? 0 : ((DWORD *) ((BYTE *) *output))[-1]);
|
||||
}
|
||||
catch (SystemException &)
|
||||
{
|
||||
return GetLastError();
|
||||
}
|
||||
catch (Exception &e)
|
||||
{
|
||||
e.Show (NULL);
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::CopyFile (BSTR sourceFile, BSTR destinationFile)
|
||||
{
|
||||
|
||||
if (!::CopyFileW (sourceFile, destinationFile, FALSE))
|
||||
return GetLastError();
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::DeleteFile (BSTR file)
|
||||
{
|
||||
|
||||
if (!::DeleteFileW (file))
|
||||
return GetLastError();
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
BOOL BaseCom::IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly)
|
||||
{
|
||||
return ::IsPagingFileActive (checkNonWindowsPartitionsOnly);
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *bufferBstr, unsigned __int64 offset, unsigned __int32 size, DWORD *sizeDone)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto_ptr <File> file (device ? new Device (filePath, !write) : new File (filePath, !write));
|
||||
file->CheckOpened (SRC_POS);
|
||||
file->SeekAt (offset);
|
||||
|
||||
if (write)
|
||||
{
|
||||
file->Write ((BYTE *) *bufferBstr, size);
|
||||
*sizeDone = size;
|
||||
}
|
||||
else
|
||||
{
|
||||
*sizeDone = file->Read ((BYTE *) *bufferBstr, size);
|
||||
}
|
||||
}
|
||||
catch (SystemException &)
|
||||
{
|
||||
return GetLastError();
|
||||
}
|
||||
catch (Exception &e)
|
||||
{
|
||||
e.Show (NULL);
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::RegisterFilterDriver (BOOL registerDriver, int filterType)
|
||||
{
|
||||
try
|
||||
{
|
||||
BootEncryption bootEnc (NULL);
|
||||
bootEnc.RegisterFilterDriver (registerDriver ? true : false, (BootEncryption::FilterType) filterType);
|
||||
}
|
||||
catch (SystemException &)
|
||||
{
|
||||
return GetLastError();
|
||||
}
|
||||
catch (Exception &e)
|
||||
{
|
||||
e.Show (NULL);
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::RegisterSystemFavoritesService (BOOL registerService)
|
||||
{
|
||||
try
|
||||
{
|
||||
BootEncryption bootEnc (NULL);
|
||||
bootEnc.RegisterSystemFavoritesService (registerService);
|
||||
}
|
||||
catch (SystemException &)
|
||||
{
|
||||
return GetLastError();
|
||||
}
|
||||
catch (Exception &e)
|
||||
{
|
||||
e.Show (NULL);
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::SetDriverServiceStartType (DWORD startType)
|
||||
{
|
||||
try
|
||||
{
|
||||
BootEncryption bootEnc (NULL);
|
||||
bootEnc.SetDriverServiceStartType (startType);
|
||||
}
|
||||
catch (SystemException &)
|
||||
{
|
||||
return GetLastError();
|
||||
}
|
||||
catch (Exception &e)
|
||||
{
|
||||
e.Show (NULL);
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return ERROR_EXCEPTION_IN_SERVICE;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD BaseCom::WriteLocalMachineRegistryDwordValue (BSTR keyPath, BSTR valueName, DWORD value)
|
||||
{
|
||||
if (!::WriteLocalMachineRegistryDword (keyPath, valueName, value))
|
||||
return GetLastError();
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,119 +1,119 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_BASE_COM
|
||||
#define TC_HEADER_BASE_COM
|
||||
|
||||
#include <guiddef.h>
|
||||
|
||||
template <class TClass>
|
||||
class TrueCryptFactory : public IClassFactory
|
||||
{
|
||||
|
||||
public:
|
||||
TrueCryptFactory (DWORD messageThreadId) :
|
||||
RefCount (1), ServerLockCount (0), MessageThreadId (messageThreadId) { }
|
||||
|
||||
~TrueCryptFactory () { }
|
||||
|
||||
virtual ULONG STDMETHODCALLTYPE AddRef ()
|
||||
{
|
||||
return InterlockedIncrement (&RefCount) - 1;
|
||||
}
|
||||
|
||||
virtual ULONG STDMETHODCALLTYPE Release ()
|
||||
{
|
||||
ULONG r = InterlockedDecrement (&RefCount) + 1;
|
||||
|
||||
if (r == 0)
|
||||
delete this;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE QueryInterface (REFIID riid, void **ppvObject)
|
||||
{
|
||||
if (riid == IID_IUnknown || riid == IID_IClassFactory)
|
||||
*ppvObject = this;
|
||||
else
|
||||
{
|
||||
*ppvObject = NULL;
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
AddRef ();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE CreateInstance (IUnknown *pUnkOuter, REFIID riid, void **ppvObject)
|
||||
{
|
||||
if (pUnkOuter != NULL)
|
||||
return CLASS_E_NOAGGREGATION;
|
||||
|
||||
TClass *tc = new TClass (MessageThreadId);
|
||||
if (tc == NULL)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
HRESULT hr = tc->QueryInterface (riid, ppvObject);
|
||||
|
||||
if (hr)
|
||||
delete tc;
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE LockServer (BOOL fLock)
|
||||
{
|
||||
if (fLock)
|
||||
{
|
||||
InterlockedIncrement (&ServerLockCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!InterlockedDecrement (&ServerLockCount))
|
||||
PostThreadMessage (MessageThreadId, WM_APP, 0, 0);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
virtual bool IsServerLocked ()
|
||||
{
|
||||
return ServerLockCount > 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
DWORD MessageThreadId;
|
||||
LONG RefCount;
|
||||
LONG ServerLockCount;
|
||||
};
|
||||
|
||||
|
||||
class BaseCom
|
||||
{
|
||||
public:
|
||||
static DWORD CallDriver (DWORD ioctl, BSTR input, BSTR *output);
|
||||
static DWORD CopyFile (BSTR sourceFile, BSTR destinationFile);
|
||||
static DWORD DeleteFile (BSTR file);
|
||||
static BOOL IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly);
|
||||
static DWORD ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *bufferBstr, unsigned __int64 offset, unsigned __int32 size, DWORD *sizeDone);
|
||||
static DWORD RegisterFilterDriver (BOOL registerDriver, int filterType);
|
||||
static DWORD RegisterSystemFavoritesService (BOOL registerService);
|
||||
static DWORD SetDriverServiceStartType (DWORD startType);
|
||||
static DWORD WriteLocalMachineRegistryDwordValue (BSTR keyPath, BSTR valueName, DWORD value);
|
||||
};
|
||||
|
||||
|
||||
BOOL ComGetInstanceBase (HWND hWnd, REFCLSID clsid, REFIID iid, void **tcServer);
|
||||
HRESULT CreateElevatedComObject (HWND hwnd, REFGUID guid, REFIID iid, void **ppv);
|
||||
|
||||
#endif // TC_HEADER_BASE_COM
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_BASE_COM
|
||||
#define TC_HEADER_BASE_COM
|
||||
|
||||
#include <guiddef.h>
|
||||
|
||||
template <class TClass>
|
||||
class TrueCryptFactory : public IClassFactory
|
||||
{
|
||||
|
||||
public:
|
||||
TrueCryptFactory (DWORD messageThreadId) :
|
||||
RefCount (1), ServerLockCount (0), MessageThreadId (messageThreadId) { }
|
||||
|
||||
~TrueCryptFactory () { }
|
||||
|
||||
virtual ULONG STDMETHODCALLTYPE AddRef ()
|
||||
{
|
||||
return InterlockedIncrement (&RefCount) - 1;
|
||||
}
|
||||
|
||||
virtual ULONG STDMETHODCALLTYPE Release ()
|
||||
{
|
||||
ULONG r = InterlockedDecrement (&RefCount) + 1;
|
||||
|
||||
if (r == 0)
|
||||
delete this;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE QueryInterface (REFIID riid, void **ppvObject)
|
||||
{
|
||||
if (riid == IID_IUnknown || riid == IID_IClassFactory)
|
||||
*ppvObject = this;
|
||||
else
|
||||
{
|
||||
*ppvObject = NULL;
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
AddRef ();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE CreateInstance (IUnknown *pUnkOuter, REFIID riid, void **ppvObject)
|
||||
{
|
||||
if (pUnkOuter != NULL)
|
||||
return CLASS_E_NOAGGREGATION;
|
||||
|
||||
TClass *tc = new TClass (MessageThreadId);
|
||||
if (tc == NULL)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
HRESULT hr = tc->QueryInterface (riid, ppvObject);
|
||||
|
||||
if (hr)
|
||||
delete tc;
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE LockServer (BOOL fLock)
|
||||
{
|
||||
if (fLock)
|
||||
{
|
||||
InterlockedIncrement (&ServerLockCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!InterlockedDecrement (&ServerLockCount))
|
||||
PostThreadMessage (MessageThreadId, WM_APP, 0, 0);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
virtual bool IsServerLocked ()
|
||||
{
|
||||
return ServerLockCount > 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
DWORD MessageThreadId;
|
||||
LONG RefCount;
|
||||
LONG ServerLockCount;
|
||||
};
|
||||
|
||||
|
||||
class BaseCom
|
||||
{
|
||||
public:
|
||||
static DWORD CallDriver (DWORD ioctl, BSTR input, BSTR *output);
|
||||
static DWORD CopyFile (BSTR sourceFile, BSTR destinationFile);
|
||||
static DWORD DeleteFile (BSTR file);
|
||||
static BOOL IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly);
|
||||
static DWORD ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *bufferBstr, unsigned __int64 offset, unsigned __int32 size, DWORD *sizeDone);
|
||||
static DWORD RegisterFilterDriver (BOOL registerDriver, int filterType);
|
||||
static DWORD RegisterSystemFavoritesService (BOOL registerService);
|
||||
static DWORD SetDriverServiceStartType (DWORD startType);
|
||||
static DWORD WriteLocalMachineRegistryDwordValue (BSTR keyPath, BSTR valueName, DWORD value);
|
||||
};
|
||||
|
||||
|
||||
BOOL ComGetInstanceBase (HWND hWnd, REFCLSID clsid, REFIID iid, void **tcServer);
|
||||
HRESULT CreateElevatedComObject (HWND hwnd, REFGUID guid, REFIID iid, void **ppv);
|
||||
|
||||
#endif // TC_HEADER_BASE_COM
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,255 +1,255 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Common_BootEncryption
|
||||
#define TC_HEADER_Common_BootEncryption
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Exception.h"
|
||||
#include "Platform/PlatformBase.h"
|
||||
#include "Volumes.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace VeraCrypt
|
||||
{
|
||||
class File
|
||||
{
|
||||
public:
|
||||
File () : Elevated (false), FileOpen (false), FilePointerPosition(0), Handle(INVALID_HANDLE_VALUE), IsDevice(false), LastError(0) { }
|
||||
File (wstring path,bool readOnly = false, bool create = false);
|
||||
virtual ~File () { Close(); }
|
||||
|
||||
void CheckOpened (const char* srcPos) { if (!FileOpen) { SetLastError (LastError); throw SystemException (srcPos);} }
|
||||
void Close ();
|
||||
DWORD Read (byte *buffer, DWORD size);
|
||||
void Write (byte *buffer, DWORD size);
|
||||
void SeekAt (int64 position);
|
||||
|
||||
protected:
|
||||
bool Elevated;
|
||||
bool FileOpen;
|
||||
uint64 FilePointerPosition;
|
||||
HANDLE Handle;
|
||||
bool IsDevice;
|
||||
wstring Path;
|
||||
DWORD LastError;
|
||||
};
|
||||
|
||||
|
||||
class Device : public File
|
||||
{
|
||||
public:
|
||||
Device (wstring path,bool readOnly = false);
|
||||
virtual ~Device () {}
|
||||
};
|
||||
|
||||
|
||||
class Buffer
|
||||
{
|
||||
public:
|
||||
Buffer (size_t size) : DataSize (size)
|
||||
{
|
||||
DataPtr = new byte[size];
|
||||
if (!DataPtr)
|
||||
throw bad_alloc();
|
||||
}
|
||||
|
||||
~Buffer () { delete[] DataPtr; }
|
||||
byte *Ptr () const { return DataPtr; }
|
||||
size_t Size () const { return DataSize; }
|
||||
|
||||
protected:
|
||||
byte *DataPtr;
|
||||
size_t DataSize;
|
||||
};
|
||||
|
||||
|
||||
struct Partition
|
||||
{
|
||||
wstring DevicePath;
|
||||
PARTITION_INFORMATION Info;
|
||||
wstring MountPoint;
|
||||
size_t Number;
|
||||
BOOL IsGPT;
|
||||
wstring VolumeNameId;
|
||||
};
|
||||
|
||||
typedef list <Partition> PartitionList;
|
||||
|
||||
#pragma pack (push)
|
||||
#pragma pack(1)
|
||||
|
||||
struct PartitionEntryMBR
|
||||
{
|
||||
byte BootIndicator;
|
||||
|
||||
byte StartHead;
|
||||
byte StartCylSector;
|
||||
byte StartCylinder;
|
||||
|
||||
byte Type;
|
||||
|
||||
byte EndHead;
|
||||
byte EndSector;
|
||||
byte EndCylinder;
|
||||
|
||||
uint32 StartLBA;
|
||||
uint32 SectorCountLBA;
|
||||
};
|
||||
|
||||
struct MBR
|
||||
{
|
||||
byte Code[446];
|
||||
PartitionEntryMBR Partitions[4];
|
||||
uint16 Signature;
|
||||
};
|
||||
|
||||
#pragma pack (pop)
|
||||
|
||||
struct SystemDriveConfiguration
|
||||
{
|
||||
wstring DeviceKernelPath;
|
||||
wstring DevicePath;
|
||||
int DriveNumber;
|
||||
Partition DrivePartition;
|
||||
bool ExtraBootPartitionPresent;
|
||||
int64 InitialUnallocatedSpace;
|
||||
PartitionList Partitions;
|
||||
Partition SystemPartition;
|
||||
int64 TotalUnallocatedSpace;
|
||||
bool SystemLoaderPresent;
|
||||
};
|
||||
|
||||
class BootEncryption
|
||||
{
|
||||
public:
|
||||
BootEncryption (HWND parent);
|
||||
~BootEncryption ();
|
||||
|
||||
enum FilterType
|
||||
{
|
||||
DriveFilter,
|
||||
VolumeFilter,
|
||||
DumpFilter
|
||||
};
|
||||
|
||||
void SetParentWindow (HWND parent) { ParentWindow = parent; }
|
||||
void AbortDecoyOSWipe ();
|
||||
void AbortSetup ();
|
||||
void AbortSetupWait ();
|
||||
void CallDriver (DWORD ioctl, void *input = nullptr, DWORD inputSize = 0, void *output = nullptr, DWORD outputSize = 0);
|
||||
int ChangePassword (Password *oldPassword, int old_pkcs5, int old_pim, Password *newPassword, int pkcs5, int pim, int wipePassCount, HWND hwndDlg);
|
||||
void CheckDecoyOSWipeResult ();
|
||||
void CheckEncryptionSetupResult ();
|
||||
void CheckRequirements ();
|
||||
void CheckRequirementsHiddenOS ();
|
||||
void CopyFileAdmin (const wstring &sourceFile, const wstring &destinationFile);
|
||||
void CreateRescueIsoImage (bool initialSetup, const wstring &isoImagePath);
|
||||
void Deinstall (bool displayWaitDialog = false);
|
||||
void DeleteFileAdmin (const wstring &file);
|
||||
DecoySystemWipeStatus GetDecoyOSWipeStatus ();
|
||||
DWORD GetDriverServiceStartType ();
|
||||
unsigned int GetHiddenOSCreationPhase ();
|
||||
uint16 GetInstalledBootLoaderVersion ();
|
||||
void GetInstalledBootLoaderFingerprint (byte fingerprint[WHIRLPOOL_DIGESTSIZE + SHA512_DIGESTSIZE]);
|
||||
Partition GetPartitionForHiddenOS ();
|
||||
bool IsBootLoaderOnDrive (wchar_t *devicePath);
|
||||
BootEncryptionStatus GetStatus ();
|
||||
void GetVolumeProperties (VOLUME_PROPERTIES_STRUCT *properties);
|
||||
SystemDriveConfiguration GetSystemDriveConfiguration ();
|
||||
void Install (bool hiddenSystem);
|
||||
void InstallBootLoader (Device& device, bool preserveUserConfig = false, bool hiddenOSCreation = false, int pim = -1);
|
||||
void InstallBootLoader (bool preserveUserConfig = false, bool hiddenOSCreation = false);
|
||||
bool CheckBootloaderFingerprint (bool bSilent = false);
|
||||
void InvalidateCachedSysDriveProperties ();
|
||||
bool IsCDRecorderPresent ();
|
||||
bool IsHiddenSystemRunning ();
|
||||
bool IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly);
|
||||
void PrepareHiddenOSCreation (int ea, int mode, int pkcs5);
|
||||
void PrepareInstallation (bool systemPartitionOnly, Password &password, int ea, int mode, int pkcs5, int pim, const wstring &rescueIsoImagePath);
|
||||
void ProbeRealSystemDriveSize ();
|
||||
void ReadBootSectorConfig (byte *config, size_t bufLength, byte *userConfig = nullptr, string *customUserMessage = nullptr, uint16 *bootLoaderVersion = nullptr);
|
||||
uint32 ReadDriverConfigurationFlags ();
|
||||
void RegisterBootDriver (bool hiddenSystem);
|
||||
void RegisterFilterDriver (bool registerDriver, FilterType filterType);
|
||||
void RegisterSystemFavoritesService (BOOL registerService);
|
||||
void RegisterSystemFavoritesService (BOOL registerService, BOOL noFileHandling);
|
||||
void UpdateSystemFavoritesService ();
|
||||
void RenameDeprecatedSystemLoaderBackup ();
|
||||
bool RestartComputer (void);
|
||||
void InitialSecurityChecksForHiddenOS ();
|
||||
void RestrictPagingFilesToSystemPartition ();
|
||||
void SetDriverConfigurationFlag (uint32 flag, bool state);
|
||||
void SetDriverServiceStartType (DWORD startType);
|
||||
void SetHiddenOSCreationPhase (unsigned int newPhase);
|
||||
void StartDecryption (BOOL discardUnreadableEncryptedSectors);
|
||||
void StartDecoyOSWipe (WipeAlgorithmId wipeAlgorithm);
|
||||
void StartEncryption (WipeAlgorithmId wipeAlgorithm, bool zeroUnreadableSectors);
|
||||
bool SystemDriveContainsPartitionType (byte type);
|
||||
bool SystemDriveContainsExtendedPartition ();
|
||||
bool SystemDriveContainsNonStandardPartitions ();
|
||||
bool SystemPartitionCoversWholeDrive ();
|
||||
bool SystemDriveIsDynamic ();
|
||||
bool VerifyRescueDisk ();
|
||||
bool VerifyRescueDiskIsoImage (const wchar_t* imageFile);
|
||||
void WipeHiddenOSCreationConfig ();
|
||||
void WriteBootDriveSector (uint64 offset, byte *data);
|
||||
void WriteBootSectorConfig (const byte newConfig[]);
|
||||
void WriteBootSectorUserConfig (byte userConfig, const string &customUserMessage, int pim);
|
||||
void WriteLocalMachineRegistryDwordValue (wchar_t *keyPath, wchar_t *valueName, DWORD value);
|
||||
|
||||
protected:
|
||||
static const uint32 RescueIsoImageSize = 1835008; // Size of ISO9660 image with bootable emulated 1.44MB floppy disk image
|
||||
|
||||
void BackupSystemLoader ();
|
||||
void CreateBootLoaderInMemory (byte *buffer, size_t bufferSize, bool rescueDisk, bool hiddenOSCreation = false);
|
||||
void CreateVolumeHeader (uint64 volumeSize, uint64 encryptedAreaStart, Password *password, int ea, int mode, int pkcs5, int pim);
|
||||
wstring GetSystemLoaderBackupPath ();
|
||||
uint32 GetChecksum (byte *data, size_t size);
|
||||
DISK_GEOMETRY GetDriveGeometry (int driveNumber);
|
||||
PartitionList GetDrivePartitions (int driveNumber);
|
||||
wstring GetRemarksOnHiddenOS ();
|
||||
wstring GetWindowsDirectory ();
|
||||
void RegisterFilter (bool registerFilter, FilterType filterType, const GUID *deviceClassGuid = nullptr);
|
||||
void RestoreSystemLoader ();
|
||||
void InstallVolumeHeader ();
|
||||
|
||||
HWND ParentWindow;
|
||||
SystemDriveConfiguration DriveConfig;
|
||||
int SelectedEncryptionAlgorithmId;
|
||||
int SelectedPrfAlgorithmId;
|
||||
Partition HiddenOSCandidatePartition;
|
||||
byte *RescueIsoImage;
|
||||
byte RescueVolumeHeader[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE];
|
||||
byte VolumeHeader[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE];
|
||||
bool DriveConfigValid;
|
||||
bool RealSystemDriveSizeValid;
|
||||
bool RescueVolumeHeaderValid;
|
||||
bool VolumeHeaderValid;
|
||||
};
|
||||
}
|
||||
|
||||
#define TC_ABORT_TRANSFORM_WAIT_INTERVAL 10
|
||||
|
||||
#define MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_NTFS 2.1
|
||||
#define MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_FAT 1.05
|
||||
|
||||
#define TC_SYS_BOOT_LOADER_BACKUP_NAME L"Original System Loader"
|
||||
#define TC_SYS_BOOT_LOADER_BACKUP_NAME_LEGACY L"Original System Loader.bak" // Deprecated to prevent removal by some "cleaners"
|
||||
|
||||
#define TC_SYSTEM_FAVORITES_SERVICE_NAME _T(TC_APP_NAME) L"SystemFavorites"
|
||||
#define TC_SYSTEM_FAVORITES_SERVICE_LOAD_ORDER_GROUP L"Event Log"
|
||||
#define TC_SYSTEM_FAVORITES_SERVICE_CMDLINE_OPTION L"/systemFavoritesService"
|
||||
|
||||
#endif // TC_HEADER_Common_BootEncryption
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Common_BootEncryption
|
||||
#define TC_HEADER_Common_BootEncryption
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Exception.h"
|
||||
#include "Platform/PlatformBase.h"
|
||||
#include "Volumes.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace VeraCrypt
|
||||
{
|
||||
class File
|
||||
{
|
||||
public:
|
||||
File () : Elevated (false), FileOpen (false), FilePointerPosition(0), Handle(INVALID_HANDLE_VALUE), IsDevice(false), LastError(0) { }
|
||||
File (wstring path,bool readOnly = false, bool create = false);
|
||||
virtual ~File () { Close(); }
|
||||
|
||||
void CheckOpened (const char* srcPos) { if (!FileOpen) { SetLastError (LastError); throw SystemException (srcPos);} }
|
||||
void Close ();
|
||||
DWORD Read (byte *buffer, DWORD size);
|
||||
void Write (byte *buffer, DWORD size);
|
||||
void SeekAt (int64 position);
|
||||
|
||||
protected:
|
||||
bool Elevated;
|
||||
bool FileOpen;
|
||||
uint64 FilePointerPosition;
|
||||
HANDLE Handle;
|
||||
bool IsDevice;
|
||||
wstring Path;
|
||||
DWORD LastError;
|
||||
};
|
||||
|
||||
|
||||
class Device : public File
|
||||
{
|
||||
public:
|
||||
Device (wstring path,bool readOnly = false);
|
||||
virtual ~Device () {}
|
||||
};
|
||||
|
||||
|
||||
class Buffer
|
||||
{
|
||||
public:
|
||||
Buffer (size_t size) : DataSize (size)
|
||||
{
|
||||
DataPtr = new byte[size];
|
||||
if (!DataPtr)
|
||||
throw bad_alloc();
|
||||
}
|
||||
|
||||
~Buffer () { delete[] DataPtr; }
|
||||
byte *Ptr () const { return DataPtr; }
|
||||
size_t Size () const { return DataSize; }
|
||||
|
||||
protected:
|
||||
byte *DataPtr;
|
||||
size_t DataSize;
|
||||
};
|
||||
|
||||
|
||||
struct Partition
|
||||
{
|
||||
wstring DevicePath;
|
||||
PARTITION_INFORMATION Info;
|
||||
wstring MountPoint;
|
||||
size_t Number;
|
||||
BOOL IsGPT;
|
||||
wstring VolumeNameId;
|
||||
};
|
||||
|
||||
typedef list <Partition> PartitionList;
|
||||
|
||||
#pragma pack (push)
|
||||
#pragma pack(1)
|
||||
|
||||
struct PartitionEntryMBR
|
||||
{
|
||||
byte BootIndicator;
|
||||
|
||||
byte StartHead;
|
||||
byte StartCylSector;
|
||||
byte StartCylinder;
|
||||
|
||||
byte Type;
|
||||
|
||||
byte EndHead;
|
||||
byte EndSector;
|
||||
byte EndCylinder;
|
||||
|
||||
uint32 StartLBA;
|
||||
uint32 SectorCountLBA;
|
||||
};
|
||||
|
||||
struct MBR
|
||||
{
|
||||
byte Code[446];
|
||||
PartitionEntryMBR Partitions[4];
|
||||
uint16 Signature;
|
||||
};
|
||||
|
||||
#pragma pack (pop)
|
||||
|
||||
struct SystemDriveConfiguration
|
||||
{
|
||||
wstring DeviceKernelPath;
|
||||
wstring DevicePath;
|
||||
int DriveNumber;
|
||||
Partition DrivePartition;
|
||||
bool ExtraBootPartitionPresent;
|
||||
int64 InitialUnallocatedSpace;
|
||||
PartitionList Partitions;
|
||||
Partition SystemPartition;
|
||||
int64 TotalUnallocatedSpace;
|
||||
bool SystemLoaderPresent;
|
||||
};
|
||||
|
||||
class BootEncryption
|
||||
{
|
||||
public:
|
||||
BootEncryption (HWND parent);
|
||||
~BootEncryption ();
|
||||
|
||||
enum FilterType
|
||||
{
|
||||
DriveFilter,
|
||||
VolumeFilter,
|
||||
DumpFilter
|
||||
};
|
||||
|
||||
void SetParentWindow (HWND parent) { ParentWindow = parent; }
|
||||
void AbortDecoyOSWipe ();
|
||||
void AbortSetup ();
|
||||
void AbortSetupWait ();
|
||||
void CallDriver (DWORD ioctl, void *input = nullptr, DWORD inputSize = 0, void *output = nullptr, DWORD outputSize = 0);
|
||||
int ChangePassword (Password *oldPassword, int old_pkcs5, int old_pim, Password *newPassword, int pkcs5, int pim, int wipePassCount, HWND hwndDlg);
|
||||
void CheckDecoyOSWipeResult ();
|
||||
void CheckEncryptionSetupResult ();
|
||||
void CheckRequirements ();
|
||||
void CheckRequirementsHiddenOS ();
|
||||
void CopyFileAdmin (const wstring &sourceFile, const wstring &destinationFile);
|
||||
void CreateRescueIsoImage (bool initialSetup, const wstring &isoImagePath);
|
||||
void Deinstall (bool displayWaitDialog = false);
|
||||
void DeleteFileAdmin (const wstring &file);
|
||||
DecoySystemWipeStatus GetDecoyOSWipeStatus ();
|
||||
DWORD GetDriverServiceStartType ();
|
||||
unsigned int GetHiddenOSCreationPhase ();
|
||||
uint16 GetInstalledBootLoaderVersion ();
|
||||
void GetInstalledBootLoaderFingerprint (byte fingerprint[WHIRLPOOL_DIGESTSIZE + SHA512_DIGESTSIZE]);
|
||||
Partition GetPartitionForHiddenOS ();
|
||||
bool IsBootLoaderOnDrive (wchar_t *devicePath);
|
||||
BootEncryptionStatus GetStatus ();
|
||||
void GetVolumeProperties (VOLUME_PROPERTIES_STRUCT *properties);
|
||||
SystemDriveConfiguration GetSystemDriveConfiguration ();
|
||||
void Install (bool hiddenSystem);
|
||||
void InstallBootLoader (Device& device, bool preserveUserConfig = false, bool hiddenOSCreation = false, int pim = -1);
|
||||
void InstallBootLoader (bool preserveUserConfig = false, bool hiddenOSCreation = false);
|
||||
bool CheckBootloaderFingerprint (bool bSilent = false);
|
||||
void InvalidateCachedSysDriveProperties ();
|
||||
bool IsCDRecorderPresent ();
|
||||
bool IsHiddenSystemRunning ();
|
||||
bool IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly);
|
||||
void PrepareHiddenOSCreation (int ea, int mode, int pkcs5);
|
||||
void PrepareInstallation (bool systemPartitionOnly, Password &password, int ea, int mode, int pkcs5, int pim, const wstring &rescueIsoImagePath);
|
||||
void ProbeRealSystemDriveSize ();
|
||||
void ReadBootSectorConfig (byte *config, size_t bufLength, byte *userConfig = nullptr, string *customUserMessage = nullptr, uint16 *bootLoaderVersion = nullptr);
|
||||
uint32 ReadDriverConfigurationFlags ();
|
||||
void RegisterBootDriver (bool hiddenSystem);
|
||||
void RegisterFilterDriver (bool registerDriver, FilterType filterType);
|
||||
void RegisterSystemFavoritesService (BOOL registerService);
|
||||
void RegisterSystemFavoritesService (BOOL registerService, BOOL noFileHandling);
|
||||
void UpdateSystemFavoritesService ();
|
||||
void RenameDeprecatedSystemLoaderBackup ();
|
||||
bool RestartComputer (void);
|
||||
void InitialSecurityChecksForHiddenOS ();
|
||||
void RestrictPagingFilesToSystemPartition ();
|
||||
void SetDriverConfigurationFlag (uint32 flag, bool state);
|
||||
void SetDriverServiceStartType (DWORD startType);
|
||||
void SetHiddenOSCreationPhase (unsigned int newPhase);
|
||||
void StartDecryption (BOOL discardUnreadableEncryptedSectors);
|
||||
void StartDecoyOSWipe (WipeAlgorithmId wipeAlgorithm);
|
||||
void StartEncryption (WipeAlgorithmId wipeAlgorithm, bool zeroUnreadableSectors);
|
||||
bool SystemDriveContainsPartitionType (byte type);
|
||||
bool SystemDriveContainsExtendedPartition ();
|
||||
bool SystemDriveContainsNonStandardPartitions ();
|
||||
bool SystemPartitionCoversWholeDrive ();
|
||||
bool SystemDriveIsDynamic ();
|
||||
bool VerifyRescueDisk ();
|
||||
bool VerifyRescueDiskIsoImage (const wchar_t* imageFile);
|
||||
void WipeHiddenOSCreationConfig ();
|
||||
void WriteBootDriveSector (uint64 offset, byte *data);
|
||||
void WriteBootSectorConfig (const byte newConfig[]);
|
||||
void WriteBootSectorUserConfig (byte userConfig, const string &customUserMessage, int pim);
|
||||
void WriteLocalMachineRegistryDwordValue (wchar_t *keyPath, wchar_t *valueName, DWORD value);
|
||||
|
||||
protected:
|
||||
static const uint32 RescueIsoImageSize = 1835008; // Size of ISO9660 image with bootable emulated 1.44MB floppy disk image
|
||||
|
||||
void BackupSystemLoader ();
|
||||
void CreateBootLoaderInMemory (byte *buffer, size_t bufferSize, bool rescueDisk, bool hiddenOSCreation = false);
|
||||
void CreateVolumeHeader (uint64 volumeSize, uint64 encryptedAreaStart, Password *password, int ea, int mode, int pkcs5, int pim);
|
||||
wstring GetSystemLoaderBackupPath ();
|
||||
uint32 GetChecksum (byte *data, size_t size);
|
||||
DISK_GEOMETRY GetDriveGeometry (int driveNumber);
|
||||
PartitionList GetDrivePartitions (int driveNumber);
|
||||
wstring GetRemarksOnHiddenOS ();
|
||||
wstring GetWindowsDirectory ();
|
||||
void RegisterFilter (bool registerFilter, FilterType filterType, const GUID *deviceClassGuid = nullptr);
|
||||
void RestoreSystemLoader ();
|
||||
void InstallVolumeHeader ();
|
||||
|
||||
HWND ParentWindow;
|
||||
SystemDriveConfiguration DriveConfig;
|
||||
int SelectedEncryptionAlgorithmId;
|
||||
int SelectedPrfAlgorithmId;
|
||||
Partition HiddenOSCandidatePartition;
|
||||
byte *RescueIsoImage;
|
||||
byte RescueVolumeHeader[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE];
|
||||
byte VolumeHeader[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE];
|
||||
bool DriveConfigValid;
|
||||
bool RealSystemDriveSizeValid;
|
||||
bool RescueVolumeHeaderValid;
|
||||
bool VolumeHeaderValid;
|
||||
};
|
||||
}
|
||||
|
||||
#define TC_ABORT_TRANSFORM_WAIT_INTERVAL 10
|
||||
|
||||
#define MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_NTFS 2.1
|
||||
#define MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_FAT 1.05
|
||||
|
||||
#define TC_SYS_BOOT_LOADER_BACKUP_NAME L"Original System Loader"
|
||||
#define TC_SYS_BOOT_LOADER_BACKUP_NAME_LEGACY L"Original System Loader.bak" // Deprecated to prevent removal by some "cleaners"
|
||||
|
||||
#define TC_SYSTEM_FAVORITES_SERVICE_NAME _T(TC_APP_NAME) L"SystemFavorites"
|
||||
#define TC_SYSTEM_FAVORITES_SERVICE_LOAD_ORDER_GROUP L"Event Log"
|
||||
#define TC_SYSTEM_FAVORITES_SERVICE_CMDLINE_OPTION L"/systemFavoritesService"
|
||||
|
||||
#endif // TC_HEADER_Common_BootEncryption
|
||||
|
||||
@@ -1,115 +1,115 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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 "Tcdefs.h"
|
||||
#include "Crypto.h"
|
||||
#include "Fat.h"
|
||||
#include "Volumes.h"
|
||||
#include "Apidrvr.h"
|
||||
#include "Common.h"
|
||||
#include "Cache.h"
|
||||
|
||||
Password CachedPasswords[CACHE_SIZE];
|
||||
int CachedPim[CACHE_SIZE];
|
||||
int cacheEmpty = 1;
|
||||
static int nPasswordIdx = 0;
|
||||
|
||||
int ReadVolumeHeaderWCache (BOOL bBoot, BOOL bCache, BOOL bCachePim, char *header, Password *password, int pkcs5_prf, int pim, BOOL truecryptMode, PCRYPTO_INFO *retInfo)
|
||||
{
|
||||
int nReturnCode = ERR_PASSWORD_WRONG;
|
||||
int i, effectivePim;
|
||||
|
||||
/* Attempt to recognize volume using mount password */
|
||||
if (password->Length > 0)
|
||||
{
|
||||
nReturnCode = ReadVolumeHeader (bBoot, header, password, pkcs5_prf, pim, truecryptMode, retInfo, NULL);
|
||||
|
||||
/* Save mount passwords back into cache if asked to do so */
|
||||
if (bCache && (nReturnCode == 0 || nReturnCode == ERR_CIPHER_INIT_WEAK_KEY))
|
||||
{
|
||||
for (i = 0; i < CACHE_SIZE; i++)
|
||||
{
|
||||
if (memcmp (&CachedPasswords[i], password, sizeof (Password)) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (i == CACHE_SIZE)
|
||||
{
|
||||
/* Store the password */
|
||||
CachedPasswords[nPasswordIdx] = *password;
|
||||
|
||||
/* Store also PIM if requested, otherwise set to default */
|
||||
if (bCachePim && (pim > 0))
|
||||
CachedPim[nPasswordIdx] = pim;
|
||||
else
|
||||
CachedPim[nPasswordIdx] = 0;
|
||||
|
||||
/* Try another slot */
|
||||
nPasswordIdx = (nPasswordIdx + 1) % CACHE_SIZE;
|
||||
|
||||
cacheEmpty = 0;
|
||||
}
|
||||
else if (bCachePim)
|
||||
{
|
||||
CachedPim[i] = pim > 0? pim : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!cacheEmpty)
|
||||
{
|
||||
/* Attempt to recognize volume using cached passwords */
|
||||
for (i = 0; i < CACHE_SIZE; i++)
|
||||
{
|
||||
if (CachedPasswords[i].Length > 0)
|
||||
{
|
||||
if (truecryptMode)
|
||||
effectivePim = 0;
|
||||
else if (pim == -1)
|
||||
effectivePim = CachedPim[i];
|
||||
else
|
||||
effectivePim = pim;
|
||||
nReturnCode = ReadVolumeHeader (bBoot, header, &CachedPasswords[i], pkcs5_prf, effectivePim, truecryptMode, retInfo, NULL);
|
||||
|
||||
if (nReturnCode != ERR_PASSWORD_WRONG)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nReturnCode;
|
||||
}
|
||||
|
||||
|
||||
void AddPasswordToCache (Password *password, int pim)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < CACHE_SIZE; i++)
|
||||
{
|
||||
if (memcmp (&CachedPasswords[i], password, sizeof (Password)) == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
CachedPasswords[nPasswordIdx] = *password;
|
||||
CachedPim[nPasswordIdx] = pim > 0? pim : 0;
|
||||
nPasswordIdx = (nPasswordIdx + 1) % CACHE_SIZE;
|
||||
cacheEmpty = 0;
|
||||
}
|
||||
|
||||
|
||||
void WipeCache ()
|
||||
{
|
||||
burn (CachedPasswords, sizeof (CachedPasswords));
|
||||
burn (CachedPim, sizeof (CachedPim));
|
||||
nPasswordIdx = 0;
|
||||
cacheEmpty = 1;
|
||||
}
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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 "Tcdefs.h"
|
||||
#include "Crypto.h"
|
||||
#include "Fat.h"
|
||||
#include "Volumes.h"
|
||||
#include "Apidrvr.h"
|
||||
#include "Common.h"
|
||||
#include "Cache.h"
|
||||
|
||||
Password CachedPasswords[CACHE_SIZE];
|
||||
int CachedPim[CACHE_SIZE];
|
||||
int cacheEmpty = 1;
|
||||
static int nPasswordIdx = 0;
|
||||
|
||||
int ReadVolumeHeaderWCache (BOOL bBoot, BOOL bCache, BOOL bCachePim, char *header, Password *password, int pkcs5_prf, int pim, BOOL truecryptMode, PCRYPTO_INFO *retInfo)
|
||||
{
|
||||
int nReturnCode = ERR_PASSWORD_WRONG;
|
||||
int i, effectivePim;
|
||||
|
||||
/* Attempt to recognize volume using mount password */
|
||||
if (password->Length > 0)
|
||||
{
|
||||
nReturnCode = ReadVolumeHeader (bBoot, header, password, pkcs5_prf, pim, truecryptMode, retInfo, NULL);
|
||||
|
||||
/* Save mount passwords back into cache if asked to do so */
|
||||
if (bCache && (nReturnCode == 0 || nReturnCode == ERR_CIPHER_INIT_WEAK_KEY))
|
||||
{
|
||||
for (i = 0; i < CACHE_SIZE; i++)
|
||||
{
|
||||
if (memcmp (&CachedPasswords[i], password, sizeof (Password)) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (i == CACHE_SIZE)
|
||||
{
|
||||
/* Store the password */
|
||||
CachedPasswords[nPasswordIdx] = *password;
|
||||
|
||||
/* Store also PIM if requested, otherwise set to default */
|
||||
if (bCachePim && (pim > 0))
|
||||
CachedPim[nPasswordIdx] = pim;
|
||||
else
|
||||
CachedPim[nPasswordIdx] = 0;
|
||||
|
||||
/* Try another slot */
|
||||
nPasswordIdx = (nPasswordIdx + 1) % CACHE_SIZE;
|
||||
|
||||
cacheEmpty = 0;
|
||||
}
|
||||
else if (bCachePim)
|
||||
{
|
||||
CachedPim[i] = pim > 0? pim : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!cacheEmpty)
|
||||
{
|
||||
/* Attempt to recognize volume using cached passwords */
|
||||
for (i = 0; i < CACHE_SIZE; i++)
|
||||
{
|
||||
if (CachedPasswords[i].Length > 0)
|
||||
{
|
||||
if (truecryptMode)
|
||||
effectivePim = 0;
|
||||
else if (pim == -1)
|
||||
effectivePim = CachedPim[i];
|
||||
else
|
||||
effectivePim = pim;
|
||||
nReturnCode = ReadVolumeHeader (bBoot, header, &CachedPasswords[i], pkcs5_prf, effectivePim, truecryptMode, retInfo, NULL);
|
||||
|
||||
if (nReturnCode != ERR_PASSWORD_WRONG)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nReturnCode;
|
||||
}
|
||||
|
||||
|
||||
void AddPasswordToCache (Password *password, int pim)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < CACHE_SIZE; i++)
|
||||
{
|
||||
if (memcmp (&CachedPasswords[i], password, sizeof (Password)) == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
CachedPasswords[nPasswordIdx] = *password;
|
||||
CachedPim[nPasswordIdx] = pim > 0? pim : 0;
|
||||
nPasswordIdx = (nPasswordIdx + 1) % CACHE_SIZE;
|
||||
cacheEmpty = 0;
|
||||
}
|
||||
|
||||
|
||||
void WipeCache ()
|
||||
{
|
||||
burn (CachedPasswords, sizeof (CachedPasswords));
|
||||
burn (CachedPim, sizeof (CachedPim));
|
||||
nPasswordIdx = 0;
|
||||
cacheEmpty = 1;
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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 "Common.h"
|
||||
|
||||
#ifndef CACHE_SIZE
|
||||
/* WARNING: Changing this value might not be safe (some items may be hard coded for 4)! Inspection necessary. */
|
||||
#define CACHE_SIZE 4
|
||||
#endif
|
||||
|
||||
extern int cacheEmpty;
|
||||
|
||||
void AddPasswordToCache (Password *password, int pim);
|
||||
int ReadVolumeHeaderWCache (BOOL bBoot, BOOL bCache, BOOL bCachePim,char *header, Password *password, int pkcs5_prf, int pim, BOOL truecryptMode, PCRYPTO_INFO *retInfo);
|
||||
void WipeCache (void);
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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 "Common.h"
|
||||
|
||||
#ifndef CACHE_SIZE
|
||||
/* WARNING: Changing this value might not be safe (some items may be hard coded for 4)! Inspection necessary. */
|
||||
#define CACHE_SIZE 4
|
||||
#endif
|
||||
|
||||
extern int cacheEmpty;
|
||||
|
||||
void AddPasswordToCache (Password *password, int pim);
|
||||
int ReadVolumeHeaderWCache (BOOL bBoot, BOOL bCache, BOOL bCachePim,char *header, Password *password, int pkcs5_prf, int pim, BOOL truecryptMode, PCRYPTO_INFO *retInfo);
|
||||
void WipeCache (void);
|
||||
|
||||
@@ -1,184 +1,184 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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 "Tcdefs.h"
|
||||
|
||||
#include <malloc.h>
|
||||
#include <ctype.h>
|
||||
#include "Cmdline.h"
|
||||
|
||||
#include "Resource.h"
|
||||
#include "Crypto.h"
|
||||
#include "Apidrvr.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Language.h"
|
||||
#include <Strsafe.h>
|
||||
|
||||
#ifndef SRC_POS
|
||||
#define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__))
|
||||
#endif
|
||||
|
||||
/* Except in response to the WM_INITDIALOG message, the dialog box procedure
|
||||
should return nonzero if it processes the message, and zero if it does
|
||||
not. - see DialogProc */
|
||||
BOOL CALLBACK CommandHelpDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
UNREFERENCED_PARAMETER (lParam); /* remove warning */
|
||||
UNREFERENCED_PARAMETER (wParam); /* remove warning */
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
{
|
||||
wchar_t * tmp = err_malloc(8192 * sizeof (wchar_t));
|
||||
wchar_t tmp2[MAX_PATH * 2];
|
||||
argumentspec *as;
|
||||
int i;
|
||||
|
||||
LocalizeDialog (hwndDlg, "IDD_COMMANDHELP_DLG");
|
||||
|
||||
as = (argumentspec*) lParam;
|
||||
|
||||
*tmp = 0;
|
||||
|
||||
StringCchCopyW (tmp, 8192, L"VeraCrypt " _T(VERSION_STRING));
|
||||
#ifdef _WIN64
|
||||
StringCchCatW (tmp, 8192, L" (64-bit)");
|
||||
#else
|
||||
StringCchCatW (tmp, 8192, L" (32-bit)");
|
||||
#endif
|
||||
#if (defined(_DEBUG) || defined(DEBUG))
|
||||
StringCchCatW (tmp, 8192, L" (debug)");
|
||||
#endif
|
||||
|
||||
StringCchCatW (tmp, 8192, L"\n\nCommand line options:\n\n");
|
||||
for (i = 0; i < as->arg_cnt; i ++)
|
||||
{
|
||||
if (!as->args[i].Internal)
|
||||
{
|
||||
StringCchPrintfW(tmp2, MAX_PATH * 2, L"%s\t%s\n", as->args[i].short_name, as->args[i].long_name);
|
||||
StringCchCatW(tmp, 8192, tmp2);
|
||||
}
|
||||
}
|
||||
|
||||
StringCchCatW (tmp, 8192, L"\nExamples:\n\nMount a volume as X:\tveracrypt.exe /q /v volume.hc /l X\nDismount a volume X:\tveracrypt.exe /q /d X");
|
||||
|
||||
SetWindowTextW (GetDlgItem (hwndDlg, IDC_COMMANDHELP_TEXT), tmp);
|
||||
|
||||
TCfree(tmp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
case WM_COMMAND:
|
||||
EndDialog (hwndDlg, IDOK);
|
||||
return 1;
|
||||
case WM_CLOSE:
|
||||
EndDialog (hwndDlg, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Win32CommandLine (wchar_t ***lpszArgs)
|
||||
{
|
||||
int argumentCount;
|
||||
int i;
|
||||
|
||||
LPWSTR *arguments = CommandLineToArgvW (GetCommandLineW(), &argumentCount);
|
||||
if (!arguments)
|
||||
{
|
||||
handleWin32Error (NULL, SRC_POS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
--argumentCount;
|
||||
if (argumentCount < 1)
|
||||
{
|
||||
LocalFree (arguments);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*lpszArgs = malloc (sizeof (wchar_t *) * argumentCount);
|
||||
if (!*lpszArgs)
|
||||
AbortProcess ("OUTOFMEMORY");
|
||||
|
||||
for (i = 0; i < argumentCount; ++i)
|
||||
{
|
||||
wchar_t *arg = _wcsdup (arguments[i + 1]);
|
||||
if (!arg)
|
||||
AbortProcess ("OUTOFMEMORY");
|
||||
|
||||
(*lpszArgs)[i] = arg;
|
||||
}
|
||||
|
||||
LocalFree (arguments);
|
||||
return argumentCount;
|
||||
}
|
||||
|
||||
int GetArgSepPosOffset (wchar_t *lpszArgument)
|
||||
{
|
||||
if (lpszArgument[0] == L'/')
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GetArgumentID (argumentspec *as, wchar_t *lpszArgument)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < as->arg_cnt; i++)
|
||||
{
|
||||
if (_wcsicmp (as->args[i].long_name, lpszArgument) == 0)
|
||||
{
|
||||
return as->args[i].Id;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < as->arg_cnt; i++)
|
||||
{
|
||||
if (as->args[i].short_name[0] == 0)
|
||||
continue;
|
||||
|
||||
if (_wcsicmp (as->args[i].short_name, lpszArgument) == 0)
|
||||
{
|
||||
return as->args[i].Id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int GetArgumentValue (wchar_t **lpszCommandLineArgs, int *nArgIdx,
|
||||
int nNoCommandLineArgs, wchar_t *lpszValue, int nValueSize)
|
||||
{
|
||||
*lpszValue = 0;
|
||||
|
||||
if (*nArgIdx + 1 < nNoCommandLineArgs)
|
||||
{
|
||||
int x = GetArgSepPosOffset (lpszCommandLineArgs[*nArgIdx + 1]);
|
||||
if (x == 0)
|
||||
{
|
||||
/* Handles the case of space between parameter code
|
||||
and value */
|
||||
StringCchCopyW (lpszValue, nValueSize, lpszCommandLineArgs[*nArgIdx + 1]);
|
||||
lpszValue[nValueSize - 1] = 0;
|
||||
(*nArgIdx)++;
|
||||
return HAS_ARGUMENT;
|
||||
}
|
||||
}
|
||||
|
||||
return HAS_NO_ARGUMENT;
|
||||
}
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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 "Tcdefs.h"
|
||||
|
||||
#include <malloc.h>
|
||||
#include <ctype.h>
|
||||
#include "Cmdline.h"
|
||||
|
||||
#include "Resource.h"
|
||||
#include "Crypto.h"
|
||||
#include "Apidrvr.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Language.h"
|
||||
#include <Strsafe.h>
|
||||
|
||||
#ifndef SRC_POS
|
||||
#define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__))
|
||||
#endif
|
||||
|
||||
/* Except in response to the WM_INITDIALOG message, the dialog box procedure
|
||||
should return nonzero if it processes the message, and zero if it does
|
||||
not. - see DialogProc */
|
||||
BOOL CALLBACK CommandHelpDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
UNREFERENCED_PARAMETER (lParam); /* remove warning */
|
||||
UNREFERENCED_PARAMETER (wParam); /* remove warning */
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
{
|
||||
wchar_t * tmp = err_malloc(8192 * sizeof (wchar_t));
|
||||
wchar_t tmp2[MAX_PATH * 2];
|
||||
argumentspec *as;
|
||||
int i;
|
||||
|
||||
LocalizeDialog (hwndDlg, "IDD_COMMANDHELP_DLG");
|
||||
|
||||
as = (argumentspec*) lParam;
|
||||
|
||||
*tmp = 0;
|
||||
|
||||
StringCchCopyW (tmp, 8192, L"VeraCrypt " _T(VERSION_STRING));
|
||||
#ifdef _WIN64
|
||||
StringCchCatW (tmp, 8192, L" (64-bit)");
|
||||
#else
|
||||
StringCchCatW (tmp, 8192, L" (32-bit)");
|
||||
#endif
|
||||
#if (defined(_DEBUG) || defined(DEBUG))
|
||||
StringCchCatW (tmp, 8192, L" (debug)");
|
||||
#endif
|
||||
|
||||
StringCchCatW (tmp, 8192, L"\n\nCommand line options:\n\n");
|
||||
for (i = 0; i < as->arg_cnt; i ++)
|
||||
{
|
||||
if (!as->args[i].Internal)
|
||||
{
|
||||
StringCchPrintfW(tmp2, MAX_PATH * 2, L"%s\t%s\n", as->args[i].short_name, as->args[i].long_name);
|
||||
StringCchCatW(tmp, 8192, tmp2);
|
||||
}
|
||||
}
|
||||
|
||||
StringCchCatW (tmp, 8192, L"\nExamples:\n\nMount a volume as X:\tveracrypt.exe /q /v volume.hc /l X\nDismount a volume X:\tveracrypt.exe /q /d X");
|
||||
|
||||
SetWindowTextW (GetDlgItem (hwndDlg, IDC_COMMANDHELP_TEXT), tmp);
|
||||
|
||||
TCfree(tmp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
case WM_COMMAND:
|
||||
EndDialog (hwndDlg, IDOK);
|
||||
return 1;
|
||||
case WM_CLOSE:
|
||||
EndDialog (hwndDlg, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Win32CommandLine (wchar_t ***lpszArgs)
|
||||
{
|
||||
int argumentCount;
|
||||
int i;
|
||||
|
||||
LPWSTR *arguments = CommandLineToArgvW (GetCommandLineW(), &argumentCount);
|
||||
if (!arguments)
|
||||
{
|
||||
handleWin32Error (NULL, SRC_POS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
--argumentCount;
|
||||
if (argumentCount < 1)
|
||||
{
|
||||
LocalFree (arguments);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*lpszArgs = malloc (sizeof (wchar_t *) * argumentCount);
|
||||
if (!*lpszArgs)
|
||||
AbortProcess ("OUTOFMEMORY");
|
||||
|
||||
for (i = 0; i < argumentCount; ++i)
|
||||
{
|
||||
wchar_t *arg = _wcsdup (arguments[i + 1]);
|
||||
if (!arg)
|
||||
AbortProcess ("OUTOFMEMORY");
|
||||
|
||||
(*lpszArgs)[i] = arg;
|
||||
}
|
||||
|
||||
LocalFree (arguments);
|
||||
return argumentCount;
|
||||
}
|
||||
|
||||
int GetArgSepPosOffset (wchar_t *lpszArgument)
|
||||
{
|
||||
if (lpszArgument[0] == L'/')
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GetArgumentID (argumentspec *as, wchar_t *lpszArgument)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < as->arg_cnt; i++)
|
||||
{
|
||||
if (_wcsicmp (as->args[i].long_name, lpszArgument) == 0)
|
||||
{
|
||||
return as->args[i].Id;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < as->arg_cnt; i++)
|
||||
{
|
||||
if (as->args[i].short_name[0] == 0)
|
||||
continue;
|
||||
|
||||
if (_wcsicmp (as->args[i].short_name, lpszArgument) == 0)
|
||||
{
|
||||
return as->args[i].Id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int GetArgumentValue (wchar_t **lpszCommandLineArgs, int *nArgIdx,
|
||||
int nNoCommandLineArgs, wchar_t *lpszValue, int nValueSize)
|
||||
{
|
||||
*lpszValue = 0;
|
||||
|
||||
if (*nArgIdx + 1 < nNoCommandLineArgs)
|
||||
{
|
||||
int x = GetArgSepPosOffset (lpszCommandLineArgs[*nArgIdx + 1]);
|
||||
if (x == 0)
|
||||
{
|
||||
/* Handles the case of space between parameter code
|
||||
and value */
|
||||
StringCchCopyW (lpszValue, nValueSize, lpszCommandLineArgs[*nArgIdx + 1]);
|
||||
lpszValue[nValueSize - 1] = 0;
|
||||
(*nArgIdx)++;
|
||||
return HAS_ARGUMENT;
|
||||
}
|
||||
}
|
||||
|
||||
return HAS_NO_ARGUMENT;
|
||||
}
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define HAS_ARGUMENT 1
|
||||
#define HAS_NO_ARGUMENT !HAS_ARGUMENT
|
||||
|
||||
typedef struct argument_t
|
||||
{
|
||||
int Id;
|
||||
wchar_t long_name[32];
|
||||
wchar_t short_name[8];
|
||||
BOOL Internal;
|
||||
} argument;
|
||||
|
||||
typedef struct argumentspec_t
|
||||
{
|
||||
argument *args;
|
||||
int arg_cnt;
|
||||
} argumentspec;
|
||||
|
||||
BOOL CALLBACK CommandHelpDlgProc ( HWND hwndDlg , UINT msg , WPARAM wParam , LPARAM lParam );
|
||||
int Win32CommandLine ( wchar_t ***lpszArgs );
|
||||
int GetArgSepPosOffset ( wchar_t *lpszArgument );
|
||||
int GetArgumentID ( argumentspec *as , wchar_t *lpszArgument );
|
||||
int GetArgumentValue ( wchar_t **lpszCommandLineArgs , int *nArgIdx , int nNoCommandLineArgs , wchar_t *lpszValue , int nValueSize );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define HAS_ARGUMENT 1
|
||||
#define HAS_NO_ARGUMENT !HAS_ARGUMENT
|
||||
|
||||
typedef struct argument_t
|
||||
{
|
||||
int Id;
|
||||
wchar_t long_name[32];
|
||||
wchar_t short_name[8];
|
||||
BOOL Internal;
|
||||
} argument;
|
||||
|
||||
typedef struct argumentspec_t
|
||||
{
|
||||
argument *args;
|
||||
int arg_cnt;
|
||||
} argumentspec;
|
||||
|
||||
BOOL CALLBACK CommandHelpDlgProc ( HWND hwndDlg , UINT msg , WPARAM wParam , LPARAM lParam );
|
||||
int Win32CommandLine ( wchar_t ***lpszArgs );
|
||||
int GetArgSepPosOffset ( wchar_t *lpszArgument );
|
||||
int GetArgumentID ( argumentspec *as , wchar_t *lpszArgument );
|
||||
int GetArgumentValue ( wchar_t **lpszCommandLineArgs , int *nArgIdx , int nNoCommandLineArgs , wchar_t *lpszValue , int nValueSize );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,258 +1,258 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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 "Tcdefs.h"
|
||||
#include "Combo.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Xml.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#define SIZEOF_MRU_LIST 20
|
||||
|
||||
void AddComboItem (HWND hComboBox, const wchar_t *lpszFileName, BOOL saveHistory)
|
||||
{
|
||||
LPARAM nIndex;
|
||||
|
||||
if (!saveHistory)
|
||||
{
|
||||
SendMessage (hComboBox, CB_RESETCONTENT, 0, 0);
|
||||
SetWindowText (hComboBox, lpszFileName);
|
||||
return;
|
||||
}
|
||||
|
||||
nIndex = SendMessage (hComboBox, CB_FINDSTRINGEXACT, (WPARAM) - 1, (LPARAM) & lpszFileName[0]);
|
||||
|
||||
if (nIndex == CB_ERR && *lpszFileName)
|
||||
{
|
||||
time_t lTime = time (NULL);
|
||||
nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) & lpszFileName[0]);
|
||||
if (nIndex != CB_ERR)
|
||||
SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) lTime);
|
||||
}
|
||||
|
||||
if (nIndex != CB_ERR && *lpszFileName)
|
||||
nIndex = SendMessage (hComboBox, CB_SETCURSEL, nIndex, 0);
|
||||
|
||||
if (*lpszFileName == 0)
|
||||
{
|
||||
SendMessage (hComboBox, CB_SETCURSEL, (WPARAM) - 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LPARAM MoveEditToCombo (HWND hComboBox, BOOL saveHistory)
|
||||
{
|
||||
wchar_t szTmp[TC_MAX_PATH] = {0};
|
||||
|
||||
if (!saveHistory)
|
||||
{
|
||||
GetWindowText (hComboBox, szTmp, ARRAYSIZE (szTmp));
|
||||
SendMessage (hComboBox, CB_RESETCONTENT, 0, 0);
|
||||
SetWindowText (hComboBox, szTmp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
GetWindowText (hComboBox, szTmp, ARRAYSIZE (szTmp));
|
||||
|
||||
if (wcslen (szTmp) > 0)
|
||||
{
|
||||
LPARAM nIndex = SendMessage (hComboBox, CB_FINDSTRINGEXACT, (WPARAM) - 1,
|
||||
(LPARAM) & szTmp[0]);
|
||||
if (nIndex == CB_ERR)
|
||||
{
|
||||
time_t lTime = time (NULL);
|
||||
nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) & szTmp[0]);
|
||||
if (nIndex != CB_ERR)
|
||||
SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (DWORD) lTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
time_t lTime = time (NULL);
|
||||
SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (DWORD) lTime);
|
||||
}
|
||||
|
||||
return nIndex;
|
||||
}
|
||||
|
||||
return SendMessage (hComboBox, CB_GETCURSEL, 0, 0);
|
||||
}
|
||||
|
||||
int GetOrderComboIdx (HWND hComboBox, int *nIdxList, int nElems)
|
||||
{
|
||||
int x = (int) SendMessage (hComboBox, CB_GETCOUNT, 0, 0);
|
||||
if (x != CB_ERR)
|
||||
{
|
||||
int i, nHighIdx = CB_ERR;
|
||||
time_t lHighTime = -1;
|
||||
|
||||
for (i = 0; i < x; i++)
|
||||
{
|
||||
time_t lTime = SendMessage (hComboBox, CB_GETITEMDATA, (WPARAM) i, 0);
|
||||
if (lTime > lHighTime)
|
||||
{
|
||||
int n;
|
||||
for (n = 0; n < nElems; n++)
|
||||
if (nIdxList[n] == i)
|
||||
break;
|
||||
if (n == nElems)
|
||||
{
|
||||
lHighTime = lTime;
|
||||
nHighIdx = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nHighIdx;
|
||||
}
|
||||
|
||||
return CB_ERR;
|
||||
}
|
||||
|
||||
LPARAM UpdateComboOrder (HWND hComboBox)
|
||||
{
|
||||
LPARAM nIndex;
|
||||
|
||||
nIndex = SendMessage (hComboBox, CB_GETCURSEL, 0, 0);
|
||||
|
||||
if (nIndex != CB_ERR)
|
||||
{
|
||||
time_t lTime = time (NULL);
|
||||
nIndex = SendMessage (hComboBox, CB_SETITEMDATA, (WPARAM) nIndex,
|
||||
(LPARAM) lTime);
|
||||
}
|
||||
|
||||
return nIndex;
|
||||
}
|
||||
|
||||
void LoadCombo (HWND hComboBox, BOOL bEnabled, BOOL bOnlyCheckModified, BOOL *pbModified)
|
||||
{
|
||||
DWORD size;
|
||||
char *history = LoadFile (GetConfigPath (TC_APPD_FILENAME_HISTORY), &size);
|
||||
char *xml = history;
|
||||
char volume[MAX_PATH];
|
||||
int i, nComboIdx[SIZEOF_MRU_LIST] = {0};
|
||||
int count = SendMessage (hComboBox, CB_GETCOUNT, 0, 0);
|
||||
|
||||
if (xml == NULL)
|
||||
{
|
||||
// No history XML file but history is enabled
|
||||
if (bEnabled && pbModified)
|
||||
*pbModified = TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!bEnabled && bOnlyCheckModified)
|
||||
{
|
||||
// History is disable but there is a history XML file
|
||||
if (pbModified)
|
||||
*pbModified = TRUE;
|
||||
free (history);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* combo list part:- get mru items */
|
||||
for (i = 0; i < SIZEOF_MRU_LIST; i++)
|
||||
nComboIdx[i] = GetOrderComboIdx (hComboBox, &nComboIdx[0], i);
|
||||
|
||||
i = 0;
|
||||
while (xml = XmlFindElement (xml, "volume"))
|
||||
{
|
||||
wchar_t szTmp[MAX_PATH] = { 0 };
|
||||
wchar_t wszVolume[MAX_PATH] = {0};
|
||||
|
||||
if (i < count)
|
||||
{
|
||||
if (SendMessage (hComboBox, CB_GETLBTEXTLEN, nComboIdx[i], 0) < ARRAYSIZE (szTmp))
|
||||
SendMessage (hComboBox, CB_GETLBTEXT, nComboIdx[i], (LPARAM) & szTmp[0]);
|
||||
}
|
||||
|
||||
XmlGetNodeText (xml, volume, sizeof (volume));
|
||||
if (0 == MultiByteToWideChar (CP_UTF8, 0, volume, -1, wszVolume, MAX_PATH))
|
||||
wszVolume [0] = 0;
|
||||
if (!bOnlyCheckModified)
|
||||
AddComboItem (hComboBox, wszVolume, TRUE);
|
||||
|
||||
if (pbModified && wcscmp (wszVolume, szTmp))
|
||||
*pbModified = TRUE;
|
||||
|
||||
xml++;
|
||||
i++;
|
||||
}
|
||||
|
||||
if (pbModified && (i != count))
|
||||
*pbModified = TRUE;
|
||||
|
||||
if (!bOnlyCheckModified)
|
||||
SendMessage (hComboBox, CB_SETCURSEL, 0, 0);
|
||||
|
||||
free (history);
|
||||
}
|
||||
|
||||
void DumpCombo (HWND hComboBox, int bClear)
|
||||
{
|
||||
FILE *f;
|
||||
int i, nComboIdx[SIZEOF_MRU_LIST] = {0};
|
||||
|
||||
if (bClear)
|
||||
{
|
||||
DeleteFile (GetConfigPath (TC_APPD_FILENAME_HISTORY));
|
||||
return;
|
||||
}
|
||||
|
||||
f = _wfopen (GetConfigPath (TC_APPD_FILENAME_HISTORY), L"w,ccs=UTF-8");
|
||||
if (f == NULL) return;
|
||||
|
||||
XmlWriteHeader (f);
|
||||
fputws (L"\n\t<history>", f);
|
||||
|
||||
/* combo list part:- get mru items */
|
||||
for (i = 0; i < SIZEOF_MRU_LIST; i++)
|
||||
nComboIdx[i] = GetOrderComboIdx (hComboBox, &nComboIdx[0], i);
|
||||
|
||||
/* combo list part:- write out mru items */
|
||||
for (i = 0; i < SIZEOF_MRU_LIST; i++)
|
||||
{
|
||||
wchar_t szTmp[MAX_PATH] = { 0 };
|
||||
|
||||
if (SendMessage (hComboBox, CB_GETLBTEXTLEN, nComboIdx[i], 0) < ARRAYSIZE (szTmp))
|
||||
SendMessage (hComboBox, CB_GETLBTEXT, nComboIdx[i], (LPARAM) & szTmp[0]);
|
||||
|
||||
if (szTmp[0] != 0)
|
||||
{
|
||||
wchar_t q[MAX_PATH * 2] = { 0 };
|
||||
XmlQuoteTextW (szTmp, q, ARRAYSIZE (q));
|
||||
|
||||
fwprintf (f, L"\n\t\t<volume>%s</volume>", q);
|
||||
}
|
||||
}
|
||||
|
||||
fputws (L"\n\t</history>", f);
|
||||
XmlWriteFooter (f);
|
||||
fclose (f);
|
||||
}
|
||||
|
||||
void ClearCombo (HWND hComboBox)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < SIZEOF_MRU_LIST; i++)
|
||||
{
|
||||
SendMessage (hComboBox, CB_DELETESTRING, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
int IsComboEmpty (HWND hComboBox)
|
||||
{
|
||||
return SendMessage (hComboBox, CB_GETCOUNT, 0, 0) < 1;
|
||||
}
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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 "Tcdefs.h"
|
||||
#include "Combo.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Xml.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#define SIZEOF_MRU_LIST 20
|
||||
|
||||
void AddComboItem (HWND hComboBox, const wchar_t *lpszFileName, BOOL saveHistory)
|
||||
{
|
||||
LPARAM nIndex;
|
||||
|
||||
if (!saveHistory)
|
||||
{
|
||||
SendMessage (hComboBox, CB_RESETCONTENT, 0, 0);
|
||||
SetWindowText (hComboBox, lpszFileName);
|
||||
return;
|
||||
}
|
||||
|
||||
nIndex = SendMessage (hComboBox, CB_FINDSTRINGEXACT, (WPARAM) - 1, (LPARAM) & lpszFileName[0]);
|
||||
|
||||
if (nIndex == CB_ERR && *lpszFileName)
|
||||
{
|
||||
time_t lTime = time (NULL);
|
||||
nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) & lpszFileName[0]);
|
||||
if (nIndex != CB_ERR)
|
||||
SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) lTime);
|
||||
}
|
||||
|
||||
if (nIndex != CB_ERR && *lpszFileName)
|
||||
nIndex = SendMessage (hComboBox, CB_SETCURSEL, nIndex, 0);
|
||||
|
||||
if (*lpszFileName == 0)
|
||||
{
|
||||
SendMessage (hComboBox, CB_SETCURSEL, (WPARAM) - 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LPARAM MoveEditToCombo (HWND hComboBox, BOOL saveHistory)
|
||||
{
|
||||
wchar_t szTmp[TC_MAX_PATH] = {0};
|
||||
|
||||
if (!saveHistory)
|
||||
{
|
||||
GetWindowText (hComboBox, szTmp, ARRAYSIZE (szTmp));
|
||||
SendMessage (hComboBox, CB_RESETCONTENT, 0, 0);
|
||||
SetWindowText (hComboBox, szTmp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
GetWindowText (hComboBox, szTmp, ARRAYSIZE (szTmp));
|
||||
|
||||
if (wcslen (szTmp) > 0)
|
||||
{
|
||||
LPARAM nIndex = SendMessage (hComboBox, CB_FINDSTRINGEXACT, (WPARAM) - 1,
|
||||
(LPARAM) & szTmp[0]);
|
||||
if (nIndex == CB_ERR)
|
||||
{
|
||||
time_t lTime = time (NULL);
|
||||
nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) & szTmp[0]);
|
||||
if (nIndex != CB_ERR)
|
||||
SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (DWORD) lTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
time_t lTime = time (NULL);
|
||||
SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (DWORD) lTime);
|
||||
}
|
||||
|
||||
return nIndex;
|
||||
}
|
||||
|
||||
return SendMessage (hComboBox, CB_GETCURSEL, 0, 0);
|
||||
}
|
||||
|
||||
int GetOrderComboIdx (HWND hComboBox, int *nIdxList, int nElems)
|
||||
{
|
||||
int x = (int) SendMessage (hComboBox, CB_GETCOUNT, 0, 0);
|
||||
if (x != CB_ERR)
|
||||
{
|
||||
int i, nHighIdx = CB_ERR;
|
||||
time_t lHighTime = -1;
|
||||
|
||||
for (i = 0; i < x; i++)
|
||||
{
|
||||
time_t lTime = SendMessage (hComboBox, CB_GETITEMDATA, (WPARAM) i, 0);
|
||||
if (lTime > lHighTime)
|
||||
{
|
||||
int n;
|
||||
for (n = 0; n < nElems; n++)
|
||||
if (nIdxList[n] == i)
|
||||
break;
|
||||
if (n == nElems)
|
||||
{
|
||||
lHighTime = lTime;
|
||||
nHighIdx = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nHighIdx;
|
||||
}
|
||||
|
||||
return CB_ERR;
|
||||
}
|
||||
|
||||
LPARAM UpdateComboOrder (HWND hComboBox)
|
||||
{
|
||||
LPARAM nIndex;
|
||||
|
||||
nIndex = SendMessage (hComboBox, CB_GETCURSEL, 0, 0);
|
||||
|
||||
if (nIndex != CB_ERR)
|
||||
{
|
||||
time_t lTime = time (NULL);
|
||||
nIndex = SendMessage (hComboBox, CB_SETITEMDATA, (WPARAM) nIndex,
|
||||
(LPARAM) lTime);
|
||||
}
|
||||
|
||||
return nIndex;
|
||||
}
|
||||
|
||||
void LoadCombo (HWND hComboBox, BOOL bEnabled, BOOL bOnlyCheckModified, BOOL *pbModified)
|
||||
{
|
||||
DWORD size;
|
||||
char *history = LoadFile (GetConfigPath (TC_APPD_FILENAME_HISTORY), &size);
|
||||
char *xml = history;
|
||||
char volume[MAX_PATH];
|
||||
int i, nComboIdx[SIZEOF_MRU_LIST] = {0};
|
||||
int count = SendMessage (hComboBox, CB_GETCOUNT, 0, 0);
|
||||
|
||||
if (xml == NULL)
|
||||
{
|
||||
// No history XML file but history is enabled
|
||||
if (bEnabled && pbModified)
|
||||
*pbModified = TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!bEnabled && bOnlyCheckModified)
|
||||
{
|
||||
// History is disable but there is a history XML file
|
||||
if (pbModified)
|
||||
*pbModified = TRUE;
|
||||
free (history);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* combo list part:- get mru items */
|
||||
for (i = 0; i < SIZEOF_MRU_LIST; i++)
|
||||
nComboIdx[i] = GetOrderComboIdx (hComboBox, &nComboIdx[0], i);
|
||||
|
||||
i = 0;
|
||||
while (xml = XmlFindElement (xml, "volume"))
|
||||
{
|
||||
wchar_t szTmp[MAX_PATH] = { 0 };
|
||||
wchar_t wszVolume[MAX_PATH] = {0};
|
||||
|
||||
if (i < count)
|
||||
{
|
||||
if (SendMessage (hComboBox, CB_GETLBTEXTLEN, nComboIdx[i], 0) < ARRAYSIZE (szTmp))
|
||||
SendMessage (hComboBox, CB_GETLBTEXT, nComboIdx[i], (LPARAM) & szTmp[0]);
|
||||
}
|
||||
|
||||
XmlGetNodeText (xml, volume, sizeof (volume));
|
||||
if (0 == MultiByteToWideChar (CP_UTF8, 0, volume, -1, wszVolume, MAX_PATH))
|
||||
wszVolume [0] = 0;
|
||||
if (!bOnlyCheckModified)
|
||||
AddComboItem (hComboBox, wszVolume, TRUE);
|
||||
|
||||
if (pbModified && wcscmp (wszVolume, szTmp))
|
||||
*pbModified = TRUE;
|
||||
|
||||
xml++;
|
||||
i++;
|
||||
}
|
||||
|
||||
if (pbModified && (i != count))
|
||||
*pbModified = TRUE;
|
||||
|
||||
if (!bOnlyCheckModified)
|
||||
SendMessage (hComboBox, CB_SETCURSEL, 0, 0);
|
||||
|
||||
free (history);
|
||||
}
|
||||
|
||||
void DumpCombo (HWND hComboBox, int bClear)
|
||||
{
|
||||
FILE *f;
|
||||
int i, nComboIdx[SIZEOF_MRU_LIST] = {0};
|
||||
|
||||
if (bClear)
|
||||
{
|
||||
DeleteFile (GetConfigPath (TC_APPD_FILENAME_HISTORY));
|
||||
return;
|
||||
}
|
||||
|
||||
f = _wfopen (GetConfigPath (TC_APPD_FILENAME_HISTORY), L"w,ccs=UTF-8");
|
||||
if (f == NULL) return;
|
||||
|
||||
XmlWriteHeader (f);
|
||||
fputws (L"\n\t<history>", f);
|
||||
|
||||
/* combo list part:- get mru items */
|
||||
for (i = 0; i < SIZEOF_MRU_LIST; i++)
|
||||
nComboIdx[i] = GetOrderComboIdx (hComboBox, &nComboIdx[0], i);
|
||||
|
||||
/* combo list part:- write out mru items */
|
||||
for (i = 0; i < SIZEOF_MRU_LIST; i++)
|
||||
{
|
||||
wchar_t szTmp[MAX_PATH] = { 0 };
|
||||
|
||||
if (SendMessage (hComboBox, CB_GETLBTEXTLEN, nComboIdx[i], 0) < ARRAYSIZE (szTmp))
|
||||
SendMessage (hComboBox, CB_GETLBTEXT, nComboIdx[i], (LPARAM) & szTmp[0]);
|
||||
|
||||
if (szTmp[0] != 0)
|
||||
{
|
||||
wchar_t q[MAX_PATH * 2] = { 0 };
|
||||
XmlQuoteTextW (szTmp, q, ARRAYSIZE (q));
|
||||
|
||||
fwprintf (f, L"\n\t\t<volume>%s</volume>", q);
|
||||
}
|
||||
}
|
||||
|
||||
fputws (L"\n\t</history>", f);
|
||||
XmlWriteFooter (f);
|
||||
fclose (f);
|
||||
}
|
||||
|
||||
void ClearCombo (HWND hComboBox)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < SIZEOF_MRU_LIST; i++)
|
||||
{
|
||||
SendMessage (hComboBox, CB_DELETESTRING, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
int IsComboEmpty (HWND hComboBox)
|
||||
{
|
||||
return SendMessage (hComboBox, CB_GETCOUNT, 0, 0) < 1;
|
||||
}
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void AddComboItem (HWND hComboBox, const wchar_t *lpszFileName, BOOL saveHistory);
|
||||
LPARAM MoveEditToCombo (HWND hComboBox, BOOL saveHistory);
|
||||
int GetOrderComboIdx ( HWND hComboBox , int *nIdxList , int nElems );
|
||||
LPARAM UpdateComboOrder ( HWND hComboBox );
|
||||
void LoadCombo (HWND hComboBox, BOOL bEnabled, BOOL bOnlyCheckModified, BOOL *pbModified);
|
||||
void DumpCombo ( HWND hComboBox , int bClear );
|
||||
void ClearCombo (HWND hComboBox);
|
||||
int IsComboEmpty (HWND hComboBox);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void AddComboItem (HWND hComboBox, const wchar_t *lpszFileName, BOOL saveHistory);
|
||||
LPARAM MoveEditToCombo (HWND hComboBox, BOOL saveHistory);
|
||||
int GetOrderComboIdx ( HWND hComboBox , int *nIdxList , int nElems );
|
||||
LPARAM UpdateComboOrder ( HWND hComboBox );
|
||||
void LoadCombo (HWND hComboBox, BOOL bEnabled, BOOL bOnlyCheckModified, BOOL *pbModified);
|
||||
void DumpCombo ( HWND hComboBox , int bClear );
|
||||
void ClearCombo (HWND hComboBox);
|
||||
int IsComboEmpty (HWND hComboBox);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,95 +1,95 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
#include "Crypto.h"
|
||||
|
||||
#define MIN_MOUNTED_VOLUME_DRIVE_NUMBER ('A' - 'A')
|
||||
#define MAX_MOUNTED_VOLUME_DRIVE_NUMBER ('Z' - 'A')
|
||||
|
||||
#define MAX_HOST_DRIVE_NUMBER 64
|
||||
#define MAX_HOST_PARTITION_NUMBER 32
|
||||
|
||||
#define VOLUME_ID_SIZE SHA256_DIGESTSIZE
|
||||
|
||||
typedef enum
|
||||
{
|
||||
// IMPORTANT: If you add a new item here, update IsOSVersionAtLeast().
|
||||
|
||||
WIN_UNKNOWN = 0,
|
||||
WIN_31,
|
||||
WIN_95,
|
||||
WIN_98,
|
||||
WIN_ME,
|
||||
WIN_NT3,
|
||||
WIN_NT4,
|
||||
WIN_2000,
|
||||
WIN_XP,
|
||||
WIN_XP64,
|
||||
WIN_SERVER_2003,
|
||||
WIN_VISTA,
|
||||
WIN_SERVER_2008,
|
||||
WIN_7,
|
||||
WIN_SERVER_2008_R2,
|
||||
WIN_8,
|
||||
WIN_SERVER_2012,
|
||||
WIN_8_1,
|
||||
WIN_SERVER_2012_R2,
|
||||
WIN_10,
|
||||
WIN_SERVER_2016
|
||||
} OSVersionEnum;
|
||||
|
||||
/* Volume types */
|
||||
enum
|
||||
{
|
||||
TC_VOLUME_TYPE_NORMAL = 0,
|
||||
TC_VOLUME_TYPE_HIDDEN,
|
||||
TC_VOLUME_TYPE_COUNT
|
||||
};
|
||||
|
||||
/* Prop volume types */
|
||||
enum
|
||||
{
|
||||
PROP_VOL_TYPE_NORMAL = 0,
|
||||
PROP_VOL_TYPE_HIDDEN,
|
||||
PROP_VOL_TYPE_OUTER, /* Outer/normal (hidden volume protected) */
|
||||
PROP_VOL_TYPE_OUTER_VOL_WRITE_PREVENTED, /* Outer/normal (hidden volume protected AND write already prevented) */
|
||||
PROP_VOL_TYPE_SYSTEM,
|
||||
PROP_NBR_VOLUME_TYPES
|
||||
};
|
||||
|
||||
/* Hidden volume protection status */
|
||||
enum
|
||||
{
|
||||
HIDVOL_PROT_STATUS_NONE = 0,
|
||||
HIDVOL_PROT_STATUS_ACTIVE,
|
||||
HIDVOL_PROT_STATUS_ACTION_TAKEN /* Active + action taken (write operation has already been denied) */
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BOOL ReadOnly;
|
||||
BOOL Removable;
|
||||
BOOL ProtectHiddenVolume;
|
||||
BOOL PreserveTimestamp;
|
||||
BOOL PartitionInInactiveSysEncScope; /* If TRUE, we are to attempt to mount a partition located on an encrypted system drive without pre-boot authentication. */
|
||||
Password ProtectedHidVolPassword; /* Password of hidden volume to protect against overwriting */
|
||||
BOOL UseBackupHeader;
|
||||
BOOL RecoveryMode;
|
||||
int ProtectedHidVolPkcs5Prf;
|
||||
int ProtectedHidVolPim;
|
||||
wchar_t Label[33]; /* maximum label length is 32 for NTFS and 11 for FAT32 */
|
||||
} MountOptions;
|
||||
|
||||
#endif
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
#include "Crypto.h"
|
||||
|
||||
#define MIN_MOUNTED_VOLUME_DRIVE_NUMBER ('A' - 'A')
|
||||
#define MAX_MOUNTED_VOLUME_DRIVE_NUMBER ('Z' - 'A')
|
||||
|
||||
#define MAX_HOST_DRIVE_NUMBER 64
|
||||
#define MAX_HOST_PARTITION_NUMBER 32
|
||||
|
||||
#define VOLUME_ID_SIZE SHA256_DIGESTSIZE
|
||||
|
||||
typedef enum
|
||||
{
|
||||
// IMPORTANT: If you add a new item here, update IsOSVersionAtLeast().
|
||||
|
||||
WIN_UNKNOWN = 0,
|
||||
WIN_31,
|
||||
WIN_95,
|
||||
WIN_98,
|
||||
WIN_ME,
|
||||
WIN_NT3,
|
||||
WIN_NT4,
|
||||
WIN_2000,
|
||||
WIN_XP,
|
||||
WIN_XP64,
|
||||
WIN_SERVER_2003,
|
||||
WIN_VISTA,
|
||||
WIN_SERVER_2008,
|
||||
WIN_7,
|
||||
WIN_SERVER_2008_R2,
|
||||
WIN_8,
|
||||
WIN_SERVER_2012,
|
||||
WIN_8_1,
|
||||
WIN_SERVER_2012_R2,
|
||||
WIN_10,
|
||||
WIN_SERVER_2016
|
||||
} OSVersionEnum;
|
||||
|
||||
/* Volume types */
|
||||
enum
|
||||
{
|
||||
TC_VOLUME_TYPE_NORMAL = 0,
|
||||
TC_VOLUME_TYPE_HIDDEN,
|
||||
TC_VOLUME_TYPE_COUNT
|
||||
};
|
||||
|
||||
/* Prop volume types */
|
||||
enum
|
||||
{
|
||||
PROP_VOL_TYPE_NORMAL = 0,
|
||||
PROP_VOL_TYPE_HIDDEN,
|
||||
PROP_VOL_TYPE_OUTER, /* Outer/normal (hidden volume protected) */
|
||||
PROP_VOL_TYPE_OUTER_VOL_WRITE_PREVENTED, /* Outer/normal (hidden volume protected AND write already prevented) */
|
||||
PROP_VOL_TYPE_SYSTEM,
|
||||
PROP_NBR_VOLUME_TYPES
|
||||
};
|
||||
|
||||
/* Hidden volume protection status */
|
||||
enum
|
||||
{
|
||||
HIDVOL_PROT_STATUS_NONE = 0,
|
||||
HIDVOL_PROT_STATUS_ACTIVE,
|
||||
HIDVOL_PROT_STATUS_ACTION_TAKEN /* Active + action taken (write operation has already been denied) */
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BOOL ReadOnly;
|
||||
BOOL Removable;
|
||||
BOOL ProtectHiddenVolume;
|
||||
BOOL PreserveTimestamp;
|
||||
BOOL PartitionInInactiveSysEncScope; /* If TRUE, we are to attempt to mount a partition located on an encrypted system drive without pre-boot authentication. */
|
||||
Password ProtectedHidVolPassword; /* Password of hidden volume to protect against overwriting */
|
||||
BOOL UseBackupHeader;
|
||||
BOOL RecoveryMode;
|
||||
int ProtectedHidVolPkcs5Prf;
|
||||
int ProtectedHidVolPim;
|
||||
wchar_t Label[33]; /* maximum label length is 32 for NTFS and 11 for FAT32 */
|
||||
} MountOptions;
|
||||
|
||||
#endif
|
||||
|
||||
1206
src/Common/Common.rc
1206
src/Common/Common.rc
File diff suppressed because it is too large
Load Diff
270
src/Common/Crc.c
270
src/Common/Crc.c
@@ -1,135 +1,135 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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 "Tcdefs.h"
|
||||
#include "Crc.h"
|
||||
#include "Common/Endian.h"
|
||||
|
||||
#ifndef TC_MINIMIZE_CODE_SIZE
|
||||
|
||||
/* CRC polynomial 0x04c11db7 */
|
||||
unsigned __int32 crc_32_tab[]=
|
||||
{
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
|
||||
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
|
||||
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
|
||||
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
|
||||
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
|
||||
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
|
||||
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
|
||||
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
|
||||
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
|
||||
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
|
||||
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
|
||||
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
|
||||
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
|
||||
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
|
||||
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
||||
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
|
||||
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
|
||||
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
|
||||
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
|
||||
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
|
||||
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
|
||||
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
|
||||
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
|
||||
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
|
||||
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
|
||||
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
|
||||
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
|
||||
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
|
||||
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
|
||||
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
||||
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
|
||||
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
|
||||
};
|
||||
|
||||
unsigned __int32 GetCrc32 (unsigned char *data, int length)
|
||||
{
|
||||
unsigned __int32 CRC = 0xffffffff;
|
||||
|
||||
while (length--)
|
||||
{
|
||||
CRC = (CRC >> 8) ^ crc_32_tab[ (CRC ^ *data++) & 0xFF ];
|
||||
}
|
||||
|
||||
return CRC ^ 0xffffffff;
|
||||
}
|
||||
|
||||
unsigned __int32 crc32int (unsigned __int32 *data)
|
||||
{
|
||||
unsigned char *d = (unsigned char *) data;
|
||||
unsigned __int32 CRC = 0xffffffff;
|
||||
|
||||
CRC = (CRC >> 8) ^ crc_32_tab[ (CRC ^ *d++) & 0xFF ];
|
||||
CRC = (CRC >> 8) ^ crc_32_tab[ (CRC ^ *d++) & 0xFF ];
|
||||
CRC = (CRC >> 8) ^ crc_32_tab[ (CRC ^ *d++) & 0xFF ];
|
||||
return (CRC >> 8) ^ crc_32_tab[ (CRC ^ *d) & 0xFF ] ^ 0xffffffff;
|
||||
}
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
# define CRC_SELFTEST 0x6fcf9e13
|
||||
#else
|
||||
# define CRC_SELFTEST 0xca87914d
|
||||
#endif
|
||||
|
||||
BOOL crc32_selftests (void)
|
||||
{
|
||||
int i;
|
||||
unsigned __int32 crc = 0xffffffff;
|
||||
BOOL bSuccess = FALSE;
|
||||
|
||||
for (i = 0; i < (int)sizeof(crc_32_tab); i++)
|
||||
crc = UPDC32 (((unsigned char *) crc_32_tab)[i], crc);
|
||||
|
||||
bSuccess = CRC_SELFTEST == (crc ^ 0xffffffff);
|
||||
|
||||
bSuccess &= GetCrc32 ((unsigned char *)crc_32_tab, sizeof crc_32_tab) == CRC_SELFTEST;
|
||||
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
#else // TC_MINIMIZE_CODE_SIZE
|
||||
|
||||
unsigned __int32 GetCrc32 (unsigned char *data, int length)
|
||||
{
|
||||
unsigned __int32 r = 0xFFFFFFFFUL;
|
||||
int i, b;
|
||||
|
||||
for (i = 0; i < length; ++i)
|
||||
{
|
||||
r ^= data[i];
|
||||
for (b = 0; b < 8; ++b)
|
||||
{
|
||||
if ((unsigned __int8) r & 1)
|
||||
r = (r >> 1) ^ 0xEDB88320UL;
|
||||
else
|
||||
r >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
return r ^ 0xFFFFFFFFUL;
|
||||
}
|
||||
|
||||
BOOL crc32_selftests ()
|
||||
{
|
||||
unsigned __int8 testData[32];
|
||||
unsigned __int8 i;
|
||||
|
||||
for (i = 0; i < sizeof (testData); ++i)
|
||||
testData[i] = i;
|
||||
|
||||
return GetCrc32 (testData, sizeof (testData)) == 0x91267E8AUL;
|
||||
}
|
||||
|
||||
#endif // TC_MINIMIZE_CODE_SIZE
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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 "Tcdefs.h"
|
||||
#include "Crc.h"
|
||||
#include "Common/Endian.h"
|
||||
|
||||
#ifndef TC_MINIMIZE_CODE_SIZE
|
||||
|
||||
/* CRC polynomial 0x04c11db7 */
|
||||
unsigned __int32 crc_32_tab[]=
|
||||
{
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
|
||||
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
|
||||
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
|
||||
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
|
||||
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
|
||||
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
|
||||
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
|
||||
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
|
||||
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
|
||||
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
|
||||
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
|
||||
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
|
||||
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
|
||||
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
|
||||
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
||||
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
|
||||
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
|
||||
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
|
||||
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
|
||||
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
|
||||
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
|
||||
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
|
||||
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
|
||||
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
|
||||
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
|
||||
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
|
||||
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
|
||||
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
|
||||
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
|
||||
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
||||
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
|
||||
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
|
||||
};
|
||||
|
||||
unsigned __int32 GetCrc32 (unsigned char *data, int length)
|
||||
{
|
||||
unsigned __int32 CRC = 0xffffffff;
|
||||
|
||||
while (length--)
|
||||
{
|
||||
CRC = (CRC >> 8) ^ crc_32_tab[ (CRC ^ *data++) & 0xFF ];
|
||||
}
|
||||
|
||||
return CRC ^ 0xffffffff;
|
||||
}
|
||||
|
||||
unsigned __int32 crc32int (unsigned __int32 *data)
|
||||
{
|
||||
unsigned char *d = (unsigned char *) data;
|
||||
unsigned __int32 CRC = 0xffffffff;
|
||||
|
||||
CRC = (CRC >> 8) ^ crc_32_tab[ (CRC ^ *d++) & 0xFF ];
|
||||
CRC = (CRC >> 8) ^ crc_32_tab[ (CRC ^ *d++) & 0xFF ];
|
||||
CRC = (CRC >> 8) ^ crc_32_tab[ (CRC ^ *d++) & 0xFF ];
|
||||
return (CRC >> 8) ^ crc_32_tab[ (CRC ^ *d) & 0xFF ] ^ 0xffffffff;
|
||||
}
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
# define CRC_SELFTEST 0x6fcf9e13
|
||||
#else
|
||||
# define CRC_SELFTEST 0xca87914d
|
||||
#endif
|
||||
|
||||
BOOL crc32_selftests (void)
|
||||
{
|
||||
int i;
|
||||
unsigned __int32 crc = 0xffffffff;
|
||||
BOOL bSuccess = FALSE;
|
||||
|
||||
for (i = 0; i < (int)sizeof(crc_32_tab); i++)
|
||||
crc = UPDC32 (((unsigned char *) crc_32_tab)[i], crc);
|
||||
|
||||
bSuccess = CRC_SELFTEST == (crc ^ 0xffffffff);
|
||||
|
||||
bSuccess &= GetCrc32 ((unsigned char *)crc_32_tab, sizeof crc_32_tab) == CRC_SELFTEST;
|
||||
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
#else // TC_MINIMIZE_CODE_SIZE
|
||||
|
||||
unsigned __int32 GetCrc32 (unsigned char *data, int length)
|
||||
{
|
||||
unsigned __int32 r = 0xFFFFFFFFUL;
|
||||
int i, b;
|
||||
|
||||
for (i = 0; i < length; ++i)
|
||||
{
|
||||
r ^= data[i];
|
||||
for (b = 0; b < 8; ++b)
|
||||
{
|
||||
if ((unsigned __int8) r & 1)
|
||||
r = (r >> 1) ^ 0xEDB88320UL;
|
||||
else
|
||||
r >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
return r ^ 0xFFFFFFFFUL;
|
||||
}
|
||||
|
||||
BOOL crc32_selftests ()
|
||||
{
|
||||
unsigned __int8 testData[32];
|
||||
unsigned __int8 i;
|
||||
|
||||
for (i = 0; i < sizeof (testData); ++i)
|
||||
testData[i] = i;
|
||||
|
||||
return GetCrc32 (testData, sizeof (testData)) == 0x91267E8AUL;
|
||||
}
|
||||
|
||||
#endif // TC_MINIMIZE_CODE_SIZE
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#ifndef TC_HEADER_CRC
|
||||
#define TC_HEADER_CRC
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define UPDC32(octet, crc)\
|
||||
(unsigned __int32)((crc_32_tab[(((unsigned __int32)(crc)) ^ ((unsigned char)(octet))) & 0xff] ^ (((unsigned __int32)(crc)) >> 8)))
|
||||
|
||||
unsigned __int32 GetCrc32 (unsigned char *data, int length);
|
||||
unsigned __int32 crc32int (unsigned __int32 *data);
|
||||
BOOL crc32_selftests (void);
|
||||
|
||||
extern unsigned __int32 crc_32_tab[];
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_CRC
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#ifndef TC_HEADER_CRC
|
||||
#define TC_HEADER_CRC
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define UPDC32(octet, crc)\
|
||||
(unsigned __int32)((crc_32_tab[(((unsigned __int32)(crc)) ^ ((unsigned char)(octet))) & 0xff] ^ (((unsigned __int32)(crc)) >> 8)))
|
||||
|
||||
unsigned __int32 GetCrc32 (unsigned char *data, int length);
|
||||
unsigned __int32 crc32int (unsigned __int32 *data);
|
||||
BOOL crc32_selftests (void);
|
||||
|
||||
extern unsigned __int32 crc_32_tab[];
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_CRC
|
||||
|
||||
2116
src/Common/Crypto.c
2116
src/Common/Crypto.c
File diff suppressed because it is too large
Load Diff
@@ -1,363 +1,363 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
/* Update the following when adding a new cipher or EA:
|
||||
|
||||
Crypto.h:
|
||||
ID #define
|
||||
MAX_EXPANDED_KEY #define
|
||||
|
||||
Crypto.c:
|
||||
Ciphers[]
|
||||
EncryptionAlgorithms[]
|
||||
CipherInit()
|
||||
EncipherBlock()
|
||||
DecipherBlock()
|
||||
|
||||
*/
|
||||
|
||||
#ifndef CRYPTO_H
|
||||
#define CRYPTO_H
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Encryption data unit size, which may differ from the sector size and must always be 512
|
||||
#define ENCRYPTION_DATA_UNIT_SIZE 512
|
||||
|
||||
// Size of the salt (in bytes)
|
||||
#define PKCS5_SALT_SIZE 64
|
||||
|
||||
// Size of the volume header area containing concatenated master key(s) and secondary key(s) (XTS mode)
|
||||
#define MASTER_KEYDATA_SIZE 256
|
||||
|
||||
// The first PRF to try when mounting
|
||||
#define FIRST_PRF_ID 1
|
||||
|
||||
// Hash algorithms (pseudorandom functions).
|
||||
enum
|
||||
{
|
||||
SHA512 = FIRST_PRF_ID,
|
||||
WHIRLPOOL,
|
||||
SHA256,
|
||||
RIPEMD160,
|
||||
HASH_ENUM_END_ID
|
||||
};
|
||||
|
||||
// The last PRF to try when mounting and also the number of implemented PRFs
|
||||
#define LAST_PRF_ID (HASH_ENUM_END_ID - 1)
|
||||
|
||||
#define RIPEMD160_BLOCKSIZE 64
|
||||
#define RIPEMD160_DIGESTSIZE 20
|
||||
|
||||
#define SHA256_BLOCKSIZE 64
|
||||
#define SHA256_DIGESTSIZE 32
|
||||
|
||||
#define SHA512_BLOCKSIZE 128
|
||||
#define SHA512_DIGESTSIZE 64
|
||||
|
||||
#define WHIRLPOOL_BLOCKSIZE 64
|
||||
#define WHIRLPOOL_DIGESTSIZE 64
|
||||
|
||||
#define MAX_DIGESTSIZE WHIRLPOOL_DIGESTSIZE
|
||||
|
||||
#define DEFAULT_HASH_ALGORITHM FIRST_PRF_ID
|
||||
#define DEFAULT_HASH_ALGORITHM_BOOT SHA256
|
||||
|
||||
// The mode of operation used for newly created volumes and first to try when mounting
|
||||
#define FIRST_MODE_OF_OPERATION_ID 1
|
||||
|
||||
// Modes of operation
|
||||
enum
|
||||
{
|
||||
/* If you add/remove a mode, update the following: GetMaxPkcs5OutSize(), EAInitMode() */
|
||||
|
||||
XTS = FIRST_MODE_OF_OPERATION_ID,
|
||||
MODE_ENUM_END_ID
|
||||
};
|
||||
|
||||
|
||||
// The last mode of operation to try when mounting and also the number of implemented modes
|
||||
#define LAST_MODE_OF_OPERATION (MODE_ENUM_END_ID - 1)
|
||||
|
||||
// Ciphertext/plaintext block size for XTS mode (in bytes)
|
||||
#define BYTES_PER_XTS_BLOCK 16
|
||||
|
||||
// Number of ciphertext/plaintext blocks per XTS data unit
|
||||
#define BLOCKS_PER_XTS_DATA_UNIT (ENCRYPTION_DATA_UNIT_SIZE / BYTES_PER_XTS_BLOCK)
|
||||
|
||||
|
||||
// Cipher IDs
|
||||
enum
|
||||
{
|
||||
NONE = 0,
|
||||
AES,
|
||||
SERPENT,
|
||||
TWOFISH
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int Id; // Cipher ID
|
||||
#ifdef TC_WINDOWS_BOOT
|
||||
char *Name; // Name
|
||||
#else
|
||||
wchar_t *Name; // Name
|
||||
#endif
|
||||
int BlockSize; // Block size (bytes)
|
||||
int KeySize; // Key size (bytes)
|
||||
int KeyScheduleSize; // Scheduled key size (bytes)
|
||||
} Cipher;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int Ciphers[4]; // Null terminated array of ciphers used by encryption algorithm
|
||||
int Modes[LAST_MODE_OF_OPERATION + 1]; // Null terminated array of modes of operation
|
||||
int FormatEnabled;
|
||||
} EncryptionAlgorithm;
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
typedef struct
|
||||
{
|
||||
int Id; // Hash ID
|
||||
wchar_t *Name; // Name
|
||||
BOOL Deprecated;
|
||||
BOOL SystemEncryption; // Available for system encryption
|
||||
} Hash;
|
||||
#endif
|
||||
|
||||
// Maxium length of scheduled key
|
||||
#if !defined (TC_WINDOWS_BOOT) || defined (TC_WINDOWS_BOOT_AES)
|
||||
# define AES_KS (sizeof(aes_encrypt_ctx) + sizeof(aes_decrypt_ctx))
|
||||
#else
|
||||
# define AES_KS (sizeof(aes_context))
|
||||
#endif
|
||||
#define SERPENT_KS (140 * 4)
|
||||
|
||||
#ifdef TC_WINDOWS_BOOT_SINGLE_CIPHER_MODE
|
||||
|
||||
# ifdef TC_WINDOWS_BOOT_AES
|
||||
# define MAX_EXPANDED_KEY AES_KS
|
||||
# elif defined (TC_WINDOWS_BOOT_SERPENT)
|
||||
# define MAX_EXPANDED_KEY SERPENT_KS
|
||||
# elif defined (TC_WINDOWS_BOOT_TWOFISH)
|
||||
# define MAX_EXPANDED_KEY TWOFISH_KS
|
||||
# endif
|
||||
|
||||
#else
|
||||
|
||||
#define MAX_EXPANDED_KEY (AES_KS + SERPENT_KS + TWOFISH_KS)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
# define PRAND_DISK_WIPE_PASSES 3
|
||||
#else
|
||||
# define PRAND_DISK_WIPE_PASSES 256
|
||||
#endif
|
||||
|
||||
/* specific value for volume header wipe used only when drive is fully wiped. */
|
||||
#define PRAND_HEADER_WIPE_PASSES 3
|
||||
|
||||
#if !defined (TC_WINDOWS_BOOT) || defined (TC_WINDOWS_BOOT_AES)
|
||||
# include "Aes.h"
|
||||
#else
|
||||
# include "AesSmall.h"
|
||||
#endif
|
||||
|
||||
#include "Aes_hw_cpu.h"
|
||||
#include "Serpent.h"
|
||||
#include "Twofish.h"
|
||||
|
||||
#include "Rmd160.h"
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
# include "Sha2.h"
|
||||
# include "Whirlpool.h"
|
||||
#endif
|
||||
|
||||
#include "GfMul.h"
|
||||
#include "Password.h"
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
|
||||
#include "config.h"
|
||||
|
||||
typedef struct keyInfo_t
|
||||
{
|
||||
int noIterations; /* Number of times to iterate (PKCS-5) */
|
||||
int keyLength; /* Length of the key */
|
||||
uint64 dummy; /* Dummy field to ensure 16-byte alignment of this structure */
|
||||
__int8 salt[PKCS5_SALT_SIZE]; /* PKCS-5 salt */
|
||||
__int8 master_keydata[MASTER_KEYDATA_SIZE]; /* Concatenated master primary and secondary key(s) (XTS mode). For LRW (deprecated/legacy), it contains the tweak key before the master key(s). For CBC (deprecated/legacy), it contains the IV seed before the master key(s). */
|
||||
CRYPTOPP_ALIGN_DATA(16) __int8 userKey[MAX_PASSWORD]; /* Password (to which keyfiles may have been applied). WITHOUT +1 for the null terminator. */
|
||||
} KEY_INFO, *PKEY_INFO;
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct CRYPTO_INFO_t
|
||||
{
|
||||
int ea; /* Encryption algorithm ID */
|
||||
int mode; /* Mode of operation (e.g., XTS) */
|
||||
int pkcs5; /* PRF algorithm */
|
||||
|
||||
unsigned __int8 ks[MAX_EXPANDED_KEY]; /* Primary key schedule (if it is a cascade, it conatins multiple concatenated keys) */
|
||||
unsigned __int8 ks2[MAX_EXPANDED_KEY]; /* Secondary key schedule (if cascade, multiple concatenated) for XTS mode. */
|
||||
|
||||
BOOL hiddenVolume; // Indicates whether the volume is mounted/mountable as hidden volume
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
uint16 HeaderVersion;
|
||||
|
||||
GfCtx gf_ctx;
|
||||
|
||||
unsigned __int8 master_keydata[MASTER_KEYDATA_SIZE]; /* This holds the volume header area containing concatenated master key(s) and secondary key(s) (XTS mode). For LRW (deprecated/legacy), it contains the tweak key before the master key(s). For CBC (deprecated/legacy), it contains the IV seed before the master key(s). */
|
||||
unsigned __int8 k2[MASTER_KEYDATA_SIZE]; /* For XTS, this contains the secondary key (if cascade, multiple concatenated). For LRW (deprecated/legacy), it contains the tweak key. For CBC (deprecated/legacy), it contains the IV seed. */
|
||||
unsigned __int8 salt[PKCS5_SALT_SIZE];
|
||||
int noIterations;
|
||||
BOOL bTrueCryptMode;
|
||||
int volumePim;
|
||||
|
||||
uint64 volume_creation_time; // Legacy
|
||||
uint64 header_creation_time; // Legacy
|
||||
|
||||
BOOL bProtectHiddenVolume; // Indicates whether the volume contains a hidden volume to be protected against overwriting
|
||||
BOOL bHiddenVolProtectionAction; // TRUE if a write operation has been denied by the driver in order to prevent the hidden volume from being overwritten (set to FALSE upon volume mount).
|
||||
|
||||
uint64 volDataAreaOffset; // Absolute position, in bytes, of the first data sector of the volume.
|
||||
|
||||
uint64 hiddenVolumeSize; // Size of the hidden volume excluding the header (in bytes). Set to 0 for standard volumes.
|
||||
uint64 hiddenVolumeOffset; // Absolute position, in bytes, of the first hidden volume data sector within the host volume (provided that there is a hidden volume within). This must be set for all hidden volumes; in case of a normal volume, this variable is only used when protecting a hidden volume within it.
|
||||
uint64 hiddenVolumeProtectedSize;
|
||||
|
||||
BOOL bPartitionInInactiveSysEncScope; // If TRUE, the volume is a partition located on an encrypted system drive and mounted without pre-boot authentication.
|
||||
|
||||
UINT64_STRUCT FirstDataUnitNo; // First data unit number of the volume. This is 0 for file-hosted and non-system partition-hosted volumes. For partitions within key scope of system encryption this reflects real physical offset within the device (this is used e.g. when such a partition is mounted as a regular volume without pre-boot authentication).
|
||||
|
||||
uint16 RequiredProgramVersion;
|
||||
BOOL LegacyVolume;
|
||||
|
||||
uint32 SectorSize;
|
||||
|
||||
#endif // !TC_WINDOWS_BOOT
|
||||
|
||||
UINT64_STRUCT VolumeSize;
|
||||
|
||||
UINT64_STRUCT EncryptedAreaStart;
|
||||
UINT64_STRUCT EncryptedAreaLength;
|
||||
|
||||
uint32 HeaderFlags;
|
||||
|
||||
} CRYPTO_INFO, *PCRYPTO_INFO;
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#pragma pack (push)
|
||||
#pragma pack(1)
|
||||
|
||||
typedef struct BOOT_CRYPTO_HEADER_t
|
||||
{
|
||||
__int16 ea; /* Encryption algorithm ID */
|
||||
__int16 mode; /* Mode of operation (e.g., XTS) */
|
||||
__int16 pkcs5; /* PRF algorithm */
|
||||
|
||||
} BOOT_CRYPTO_HEADER, *PBOOT_CRYPTO_HEADER;
|
||||
|
||||
#pragma pack (pop)
|
||||
|
||||
#endif
|
||||
|
||||
PCRYPTO_INFO crypto_open (void);
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
void crypto_loadkey (PKEY_INFO keyInfo, char *lpszUserKey, int nUserKeyLen);
|
||||
#endif
|
||||
void crypto_close (PCRYPTO_INFO cryptoInfo);
|
||||
|
||||
int CipherGetBlockSize (int cipher);
|
||||
int CipherGetKeySize (int cipher);
|
||||
int CipherGetKeyScheduleSize (int cipher);
|
||||
BOOL CipherSupportsIntraDataUnitParallelization (int cipher);
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
const wchar_t * CipherGetName (int cipher);
|
||||
#endif
|
||||
|
||||
int CipherInit (int cipher, unsigned char *key, unsigned char *ks);
|
||||
#ifndef TC_WINDOWS_BOOT_SINGLE_CIPHER_MODE
|
||||
int EAInit (int ea, unsigned char *key, unsigned char *ks);
|
||||
#else
|
||||
int EAInit (unsigned char *key, unsigned char *ks);
|
||||
#endif
|
||||
BOOL EAInitMode (PCRYPTO_INFO ci);
|
||||
void EncipherBlock(int cipher, void *data, void *ks);
|
||||
void DecipherBlock(int cipher, void *data, void *ks);
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
void EncipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount);
|
||||
void DecipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount);
|
||||
#endif
|
||||
|
||||
int EAGetFirst ();
|
||||
int EAGetCount (void);
|
||||
int EAGetNext (int previousEA);
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
wchar_t * EAGetName (wchar_t *buf, int ea, int guiDisplay);
|
||||
int EAGetByName (wchar_t *name);
|
||||
#endif
|
||||
int EAGetKeySize (int ea);
|
||||
int EAGetFirstMode (int ea);
|
||||
int EAGetNextMode (int ea, int previousModeId);
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
wchar_t * EAGetModeName (int ea, int mode, BOOL capitalLetters);
|
||||
#endif
|
||||
int EAGetKeyScheduleSize (int ea);
|
||||
int EAGetLargestKey ();
|
||||
int EAGetLargestKeyForMode (int mode);
|
||||
|
||||
int EAGetCipherCount (int ea);
|
||||
int EAGetFirstCipher (int ea);
|
||||
int EAGetLastCipher (int ea);
|
||||
int EAGetNextCipher (int ea, int previousCipherId);
|
||||
int EAGetPreviousCipher (int ea, int previousCipherId);
|
||||
int EAIsFormatEnabled (int ea);
|
||||
BOOL EAIsModeSupported (int ea, int testedMode);
|
||||
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
const wchar_t *HashGetName (int hash_algo_id);
|
||||
|
||||
Hash *HashGet (int id);
|
||||
void HashGetName2 (wchar_t *buf, int hashId);
|
||||
BOOL HashIsDeprecated (int hashId);
|
||||
BOOL HashForSystemEncryption (int hashId);
|
||||
int GetMaxPkcs5OutSize (void);
|
||||
#endif
|
||||
|
||||
|
||||
void EncryptDataUnits (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, uint32 nbrUnits, PCRYPTO_INFO ci);
|
||||
void EncryptDataUnitsCurrentThread (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, TC_LARGEST_COMPILER_UINT nbrUnits, PCRYPTO_INFO ci);
|
||||
void DecryptDataUnits (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, uint32 nbrUnits, PCRYPTO_INFO ci);
|
||||
void DecryptDataUnitsCurrentThread (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, TC_LARGEST_COMPILER_UINT nbrUnits, PCRYPTO_INFO ci);
|
||||
void EncryptBuffer (unsigned __int8 *buf, TC_LARGEST_COMPILER_UINT len, PCRYPTO_INFO cryptoInfo);
|
||||
void DecryptBuffer (unsigned __int8 *buf, TC_LARGEST_COMPILER_UINT len, PCRYPTO_INFO cryptoInfo);
|
||||
|
||||
BOOL IsAesHwCpuSupported ();
|
||||
void EnableHwEncryption (BOOL enable);
|
||||
BOOL IsHwEncryptionEnabled ();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CRYPTO_H */
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
/* Update the following when adding a new cipher or EA:
|
||||
|
||||
Crypto.h:
|
||||
ID #define
|
||||
MAX_EXPANDED_KEY #define
|
||||
|
||||
Crypto.c:
|
||||
Ciphers[]
|
||||
EncryptionAlgorithms[]
|
||||
CipherInit()
|
||||
EncipherBlock()
|
||||
DecipherBlock()
|
||||
|
||||
*/
|
||||
|
||||
#ifndef CRYPTO_H
|
||||
#define CRYPTO_H
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Encryption data unit size, which may differ from the sector size and must always be 512
|
||||
#define ENCRYPTION_DATA_UNIT_SIZE 512
|
||||
|
||||
// Size of the salt (in bytes)
|
||||
#define PKCS5_SALT_SIZE 64
|
||||
|
||||
// Size of the volume header area containing concatenated master key(s) and secondary key(s) (XTS mode)
|
||||
#define MASTER_KEYDATA_SIZE 256
|
||||
|
||||
// The first PRF to try when mounting
|
||||
#define FIRST_PRF_ID 1
|
||||
|
||||
// Hash algorithms (pseudorandom functions).
|
||||
enum
|
||||
{
|
||||
SHA512 = FIRST_PRF_ID,
|
||||
WHIRLPOOL,
|
||||
SHA256,
|
||||
RIPEMD160,
|
||||
HASH_ENUM_END_ID
|
||||
};
|
||||
|
||||
// The last PRF to try when mounting and also the number of implemented PRFs
|
||||
#define LAST_PRF_ID (HASH_ENUM_END_ID - 1)
|
||||
|
||||
#define RIPEMD160_BLOCKSIZE 64
|
||||
#define RIPEMD160_DIGESTSIZE 20
|
||||
|
||||
#define SHA256_BLOCKSIZE 64
|
||||
#define SHA256_DIGESTSIZE 32
|
||||
|
||||
#define SHA512_BLOCKSIZE 128
|
||||
#define SHA512_DIGESTSIZE 64
|
||||
|
||||
#define WHIRLPOOL_BLOCKSIZE 64
|
||||
#define WHIRLPOOL_DIGESTSIZE 64
|
||||
|
||||
#define MAX_DIGESTSIZE WHIRLPOOL_DIGESTSIZE
|
||||
|
||||
#define DEFAULT_HASH_ALGORITHM FIRST_PRF_ID
|
||||
#define DEFAULT_HASH_ALGORITHM_BOOT SHA256
|
||||
|
||||
// The mode of operation used for newly created volumes and first to try when mounting
|
||||
#define FIRST_MODE_OF_OPERATION_ID 1
|
||||
|
||||
// Modes of operation
|
||||
enum
|
||||
{
|
||||
/* If you add/remove a mode, update the following: GetMaxPkcs5OutSize(), EAInitMode() */
|
||||
|
||||
XTS = FIRST_MODE_OF_OPERATION_ID,
|
||||
MODE_ENUM_END_ID
|
||||
};
|
||||
|
||||
|
||||
// The last mode of operation to try when mounting and also the number of implemented modes
|
||||
#define LAST_MODE_OF_OPERATION (MODE_ENUM_END_ID - 1)
|
||||
|
||||
// Ciphertext/plaintext block size for XTS mode (in bytes)
|
||||
#define BYTES_PER_XTS_BLOCK 16
|
||||
|
||||
// Number of ciphertext/plaintext blocks per XTS data unit
|
||||
#define BLOCKS_PER_XTS_DATA_UNIT (ENCRYPTION_DATA_UNIT_SIZE / BYTES_PER_XTS_BLOCK)
|
||||
|
||||
|
||||
// Cipher IDs
|
||||
enum
|
||||
{
|
||||
NONE = 0,
|
||||
AES,
|
||||
SERPENT,
|
||||
TWOFISH
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int Id; // Cipher ID
|
||||
#ifdef TC_WINDOWS_BOOT
|
||||
char *Name; // Name
|
||||
#else
|
||||
wchar_t *Name; // Name
|
||||
#endif
|
||||
int BlockSize; // Block size (bytes)
|
||||
int KeySize; // Key size (bytes)
|
||||
int KeyScheduleSize; // Scheduled key size (bytes)
|
||||
} Cipher;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int Ciphers[4]; // Null terminated array of ciphers used by encryption algorithm
|
||||
int Modes[LAST_MODE_OF_OPERATION + 1]; // Null terminated array of modes of operation
|
||||
int FormatEnabled;
|
||||
} EncryptionAlgorithm;
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
typedef struct
|
||||
{
|
||||
int Id; // Hash ID
|
||||
wchar_t *Name; // Name
|
||||
BOOL Deprecated;
|
||||
BOOL SystemEncryption; // Available for system encryption
|
||||
} Hash;
|
||||
#endif
|
||||
|
||||
// Maxium length of scheduled key
|
||||
#if !defined (TC_WINDOWS_BOOT) || defined (TC_WINDOWS_BOOT_AES)
|
||||
# define AES_KS (sizeof(aes_encrypt_ctx) + sizeof(aes_decrypt_ctx))
|
||||
#else
|
||||
# define AES_KS (sizeof(aes_context))
|
||||
#endif
|
||||
#define SERPENT_KS (140 * 4)
|
||||
|
||||
#ifdef TC_WINDOWS_BOOT_SINGLE_CIPHER_MODE
|
||||
|
||||
# ifdef TC_WINDOWS_BOOT_AES
|
||||
# define MAX_EXPANDED_KEY AES_KS
|
||||
# elif defined (TC_WINDOWS_BOOT_SERPENT)
|
||||
# define MAX_EXPANDED_KEY SERPENT_KS
|
||||
# elif defined (TC_WINDOWS_BOOT_TWOFISH)
|
||||
# define MAX_EXPANDED_KEY TWOFISH_KS
|
||||
# endif
|
||||
|
||||
#else
|
||||
|
||||
#define MAX_EXPANDED_KEY (AES_KS + SERPENT_KS + TWOFISH_KS)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
# define PRAND_DISK_WIPE_PASSES 3
|
||||
#else
|
||||
# define PRAND_DISK_WIPE_PASSES 256
|
||||
#endif
|
||||
|
||||
/* specific value for volume header wipe used only when drive is fully wiped. */
|
||||
#define PRAND_HEADER_WIPE_PASSES 3
|
||||
|
||||
#if !defined (TC_WINDOWS_BOOT) || defined (TC_WINDOWS_BOOT_AES)
|
||||
# include "Aes.h"
|
||||
#else
|
||||
# include "AesSmall.h"
|
||||
#endif
|
||||
|
||||
#include "Aes_hw_cpu.h"
|
||||
#include "Serpent.h"
|
||||
#include "Twofish.h"
|
||||
|
||||
#include "Rmd160.h"
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
# include "Sha2.h"
|
||||
# include "Whirlpool.h"
|
||||
#endif
|
||||
|
||||
#include "GfMul.h"
|
||||
#include "Password.h"
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
|
||||
#include "config.h"
|
||||
|
||||
typedef struct keyInfo_t
|
||||
{
|
||||
int noIterations; /* Number of times to iterate (PKCS-5) */
|
||||
int keyLength; /* Length of the key */
|
||||
uint64 dummy; /* Dummy field to ensure 16-byte alignment of this structure */
|
||||
__int8 salt[PKCS5_SALT_SIZE]; /* PKCS-5 salt */
|
||||
__int8 master_keydata[MASTER_KEYDATA_SIZE]; /* Concatenated master primary and secondary key(s) (XTS mode). For LRW (deprecated/legacy), it contains the tweak key before the master key(s). For CBC (deprecated/legacy), it contains the IV seed before the master key(s). */
|
||||
CRYPTOPP_ALIGN_DATA(16) __int8 userKey[MAX_PASSWORD]; /* Password (to which keyfiles may have been applied). WITHOUT +1 for the null terminator. */
|
||||
} KEY_INFO, *PKEY_INFO;
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct CRYPTO_INFO_t
|
||||
{
|
||||
int ea; /* Encryption algorithm ID */
|
||||
int mode; /* Mode of operation (e.g., XTS) */
|
||||
int pkcs5; /* PRF algorithm */
|
||||
|
||||
unsigned __int8 ks[MAX_EXPANDED_KEY]; /* Primary key schedule (if it is a cascade, it conatins multiple concatenated keys) */
|
||||
unsigned __int8 ks2[MAX_EXPANDED_KEY]; /* Secondary key schedule (if cascade, multiple concatenated) for XTS mode. */
|
||||
|
||||
BOOL hiddenVolume; // Indicates whether the volume is mounted/mountable as hidden volume
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
uint16 HeaderVersion;
|
||||
|
||||
GfCtx gf_ctx;
|
||||
|
||||
unsigned __int8 master_keydata[MASTER_KEYDATA_SIZE]; /* This holds the volume header area containing concatenated master key(s) and secondary key(s) (XTS mode). For LRW (deprecated/legacy), it contains the tweak key before the master key(s). For CBC (deprecated/legacy), it contains the IV seed before the master key(s). */
|
||||
unsigned __int8 k2[MASTER_KEYDATA_SIZE]; /* For XTS, this contains the secondary key (if cascade, multiple concatenated). For LRW (deprecated/legacy), it contains the tweak key. For CBC (deprecated/legacy), it contains the IV seed. */
|
||||
unsigned __int8 salt[PKCS5_SALT_SIZE];
|
||||
int noIterations;
|
||||
BOOL bTrueCryptMode;
|
||||
int volumePim;
|
||||
|
||||
uint64 volume_creation_time; // Legacy
|
||||
uint64 header_creation_time; // Legacy
|
||||
|
||||
BOOL bProtectHiddenVolume; // Indicates whether the volume contains a hidden volume to be protected against overwriting
|
||||
BOOL bHiddenVolProtectionAction; // TRUE if a write operation has been denied by the driver in order to prevent the hidden volume from being overwritten (set to FALSE upon volume mount).
|
||||
|
||||
uint64 volDataAreaOffset; // Absolute position, in bytes, of the first data sector of the volume.
|
||||
|
||||
uint64 hiddenVolumeSize; // Size of the hidden volume excluding the header (in bytes). Set to 0 for standard volumes.
|
||||
uint64 hiddenVolumeOffset; // Absolute position, in bytes, of the first hidden volume data sector within the host volume (provided that there is a hidden volume within). This must be set for all hidden volumes; in case of a normal volume, this variable is only used when protecting a hidden volume within it.
|
||||
uint64 hiddenVolumeProtectedSize;
|
||||
|
||||
BOOL bPartitionInInactiveSysEncScope; // If TRUE, the volume is a partition located on an encrypted system drive and mounted without pre-boot authentication.
|
||||
|
||||
UINT64_STRUCT FirstDataUnitNo; // First data unit number of the volume. This is 0 for file-hosted and non-system partition-hosted volumes. For partitions within key scope of system encryption this reflects real physical offset within the device (this is used e.g. when such a partition is mounted as a regular volume without pre-boot authentication).
|
||||
|
||||
uint16 RequiredProgramVersion;
|
||||
BOOL LegacyVolume;
|
||||
|
||||
uint32 SectorSize;
|
||||
|
||||
#endif // !TC_WINDOWS_BOOT
|
||||
|
||||
UINT64_STRUCT VolumeSize;
|
||||
|
||||
UINT64_STRUCT EncryptedAreaStart;
|
||||
UINT64_STRUCT EncryptedAreaLength;
|
||||
|
||||
uint32 HeaderFlags;
|
||||
|
||||
} CRYPTO_INFO, *PCRYPTO_INFO;
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#pragma pack (push)
|
||||
#pragma pack(1)
|
||||
|
||||
typedef struct BOOT_CRYPTO_HEADER_t
|
||||
{
|
||||
__int16 ea; /* Encryption algorithm ID */
|
||||
__int16 mode; /* Mode of operation (e.g., XTS) */
|
||||
__int16 pkcs5; /* PRF algorithm */
|
||||
|
||||
} BOOT_CRYPTO_HEADER, *PBOOT_CRYPTO_HEADER;
|
||||
|
||||
#pragma pack (pop)
|
||||
|
||||
#endif
|
||||
|
||||
PCRYPTO_INFO crypto_open (void);
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
void crypto_loadkey (PKEY_INFO keyInfo, char *lpszUserKey, int nUserKeyLen);
|
||||
#endif
|
||||
void crypto_close (PCRYPTO_INFO cryptoInfo);
|
||||
|
||||
int CipherGetBlockSize (int cipher);
|
||||
int CipherGetKeySize (int cipher);
|
||||
int CipherGetKeyScheduleSize (int cipher);
|
||||
BOOL CipherSupportsIntraDataUnitParallelization (int cipher);
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
const wchar_t * CipherGetName (int cipher);
|
||||
#endif
|
||||
|
||||
int CipherInit (int cipher, unsigned char *key, unsigned char *ks);
|
||||
#ifndef TC_WINDOWS_BOOT_SINGLE_CIPHER_MODE
|
||||
int EAInit (int ea, unsigned char *key, unsigned char *ks);
|
||||
#else
|
||||
int EAInit (unsigned char *key, unsigned char *ks);
|
||||
#endif
|
||||
BOOL EAInitMode (PCRYPTO_INFO ci);
|
||||
void EncipherBlock(int cipher, void *data, void *ks);
|
||||
void DecipherBlock(int cipher, void *data, void *ks);
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
void EncipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount);
|
||||
void DecipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount);
|
||||
#endif
|
||||
|
||||
int EAGetFirst ();
|
||||
int EAGetCount (void);
|
||||
int EAGetNext (int previousEA);
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
wchar_t * EAGetName (wchar_t *buf, int ea, int guiDisplay);
|
||||
int EAGetByName (wchar_t *name);
|
||||
#endif
|
||||
int EAGetKeySize (int ea);
|
||||
int EAGetFirstMode (int ea);
|
||||
int EAGetNextMode (int ea, int previousModeId);
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
wchar_t * EAGetModeName (int ea, int mode, BOOL capitalLetters);
|
||||
#endif
|
||||
int EAGetKeyScheduleSize (int ea);
|
||||
int EAGetLargestKey ();
|
||||
int EAGetLargestKeyForMode (int mode);
|
||||
|
||||
int EAGetCipherCount (int ea);
|
||||
int EAGetFirstCipher (int ea);
|
||||
int EAGetLastCipher (int ea);
|
||||
int EAGetNextCipher (int ea, int previousCipherId);
|
||||
int EAGetPreviousCipher (int ea, int previousCipherId);
|
||||
int EAIsFormatEnabled (int ea);
|
||||
BOOL EAIsModeSupported (int ea, int testedMode);
|
||||
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
const wchar_t *HashGetName (int hash_algo_id);
|
||||
|
||||
Hash *HashGet (int id);
|
||||
void HashGetName2 (wchar_t *buf, int hashId);
|
||||
BOOL HashIsDeprecated (int hashId);
|
||||
BOOL HashForSystemEncryption (int hashId);
|
||||
int GetMaxPkcs5OutSize (void);
|
||||
#endif
|
||||
|
||||
|
||||
void EncryptDataUnits (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, uint32 nbrUnits, PCRYPTO_INFO ci);
|
||||
void EncryptDataUnitsCurrentThread (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, TC_LARGEST_COMPILER_UINT nbrUnits, PCRYPTO_INFO ci);
|
||||
void DecryptDataUnits (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, uint32 nbrUnits, PCRYPTO_INFO ci);
|
||||
void DecryptDataUnitsCurrentThread (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, TC_LARGEST_COMPILER_UINT nbrUnits, PCRYPTO_INFO ci);
|
||||
void EncryptBuffer (unsigned __int8 *buf, TC_LARGEST_COMPILER_UINT len, PCRYPTO_INFO cryptoInfo);
|
||||
void DecryptBuffer (unsigned __int8 *buf, TC_LARGEST_COMPILER_UINT len, PCRYPTO_INFO cryptoInfo);
|
||||
|
||||
BOOL IsAesHwCpuSupported ();
|
||||
void EnableHwEncryption (BOOL enable);
|
||||
BOOL IsHwEncryptionEnabled ();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CRYPTO_H */
|
||||
|
||||
@@ -1,88 +1,88 @@
|
||||
/*
|
||||
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 "../Common/Dictionary.h"
|
||||
#include <windows.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
static map <string, void *> StringKeyMap;
|
||||
static map <int, void *> IntKeyMap;
|
||||
|
||||
static void *DataPool = NULL;
|
||||
static size_t DataPoolSize = 0;
|
||||
|
||||
|
||||
void AddDictionaryEntry (char *key, int intKey, void *value)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (key)
|
||||
StringKeyMap[key] = value;
|
||||
|
||||
if (intKey != 0)
|
||||
IntKeyMap[intKey] = value;
|
||||
}
|
||||
catch (exception&) {}
|
||||
}
|
||||
|
||||
|
||||
void *GetDictionaryValue (const char *key)
|
||||
{
|
||||
map <string, void *>::const_iterator i = StringKeyMap.find (key);
|
||||
|
||||
if (i == StringKeyMap.end())
|
||||
return NULL;
|
||||
|
||||
return i->second;
|
||||
}
|
||||
|
||||
|
||||
void *GetDictionaryValueByInt (int intKey)
|
||||
{
|
||||
map <int, void *>::const_iterator i = IntKeyMap.find (intKey);
|
||||
|
||||
if (i == IntKeyMap.end())
|
||||
return NULL;
|
||||
|
||||
return i->second;
|
||||
}
|
||||
|
||||
|
||||
void *AddPoolData (void *data, size_t dataSize)
|
||||
{
|
||||
if (DataPoolSize + dataSize > DATA_POOL_CAPACITY) return NULL;
|
||||
|
||||
if (DataPool == NULL)
|
||||
{
|
||||
DataPool = malloc (DATA_POOL_CAPACITY);
|
||||
if (DataPool == NULL) return NULL;
|
||||
}
|
||||
|
||||
memcpy ((BYTE *)DataPool + DataPoolSize, data, dataSize);
|
||||
|
||||
// Ensure 32-bit alignment for next entries
|
||||
dataSize = (dataSize + 3) & (~(size_t)3);
|
||||
|
||||
DataPoolSize += dataSize;
|
||||
return (BYTE *)DataPool + DataPoolSize - dataSize;
|
||||
}
|
||||
|
||||
|
||||
void ClearDictionaryPool ()
|
||||
{
|
||||
DataPoolSize = 0;
|
||||
StringKeyMap.clear();
|
||||
IntKeyMap.clear();
|
||||
/*
|
||||
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 "../Common/Dictionary.h"
|
||||
#include <windows.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
static map <string, void *> StringKeyMap;
|
||||
static map <int, void *> IntKeyMap;
|
||||
|
||||
static void *DataPool = NULL;
|
||||
static size_t DataPoolSize = 0;
|
||||
|
||||
|
||||
void AddDictionaryEntry (char *key, int intKey, void *value)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (key)
|
||||
StringKeyMap[key] = value;
|
||||
|
||||
if (intKey != 0)
|
||||
IntKeyMap[intKey] = value;
|
||||
}
|
||||
catch (exception&) {}
|
||||
}
|
||||
|
||||
|
||||
void *GetDictionaryValue (const char *key)
|
||||
{
|
||||
map <string, void *>::const_iterator i = StringKeyMap.find (key);
|
||||
|
||||
if (i == StringKeyMap.end())
|
||||
return NULL;
|
||||
|
||||
return i->second;
|
||||
}
|
||||
|
||||
|
||||
void *GetDictionaryValueByInt (int intKey)
|
||||
{
|
||||
map <int, void *>::const_iterator i = IntKeyMap.find (intKey);
|
||||
|
||||
if (i == IntKeyMap.end())
|
||||
return NULL;
|
||||
|
||||
return i->second;
|
||||
}
|
||||
|
||||
|
||||
void *AddPoolData (void *data, size_t dataSize)
|
||||
{
|
||||
if (DataPoolSize + dataSize > DATA_POOL_CAPACITY) return NULL;
|
||||
|
||||
if (DataPool == NULL)
|
||||
{
|
||||
DataPool = malloc (DATA_POOL_CAPACITY);
|
||||
if (DataPool == NULL) return NULL;
|
||||
}
|
||||
|
||||
memcpy ((BYTE *)DataPool + DataPoolSize, data, dataSize);
|
||||
|
||||
// Ensure 32-bit alignment for next entries
|
||||
dataSize = (dataSize + 3) & (~(size_t)3);
|
||||
|
||||
DataPoolSize += dataSize;
|
||||
return (BYTE *)DataPool + DataPoolSize - dataSize;
|
||||
}
|
||||
|
||||
|
||||
void ClearDictionaryPool ()
|
||||
{
|
||||
DataPoolSize = 0;
|
||||
StringKeyMap.clear();
|
||||
IntKeyMap.clear();
|
||||
}
|
||||
@@ -1,34 +1,34 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef DICTIONARY_H
|
||||
#define DICTIONARY_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define DATA_POOL_CAPACITY 1000000
|
||||
|
||||
void AddDictionaryEntry (char *key, int intKey, void *value);
|
||||
void *GetDictionaryValue (const char *key);
|
||||
void *GetDictionaryValueByInt (int intKey);
|
||||
void *AddPoolData (void *data, size_t dataSize);
|
||||
void ClearDictionaryPool ();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef DICTIONARY_H
|
||||
#define DICTIONARY_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define DATA_POOL_CAPACITY 1000000
|
||||
|
||||
void AddDictionaryEntry (char *key, int intKey, void *value);
|
||||
void *GetDictionaryValue (const char *key);
|
||||
void *GetDictionaryValueByInt (int intKey);
|
||||
void *AddPoolData (void *data, size_t dataSize);
|
||||
void ClearDictionaryPool ();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
23780
src/Common/Dlgcode.c
23780
src/Common/Dlgcode.c
File diff suppressed because it is too large
Load Diff
1186
src/Common/Dlgcode.h
1186
src/Common/Dlgcode.h
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,42 +1,42 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_ENCRYPTION_THREAD_POOL
|
||||
#define TC_HEADER_ENCRYPTION_THREAD_POOL
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Crypto.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
EncryptDataUnitsWork,
|
||||
DecryptDataUnitsWork,
|
||||
DeriveKeyWork
|
||||
} EncryptionThreadPoolWorkType;
|
||||
|
||||
void EncryptionThreadPoolBeginKeyDerivation (TC_EVENT *completionEvent, TC_EVENT *noOutstandingWorkItemEvent, LONG *completionFlag, LONG *outstandingWorkItemCount, int pkcs5Prf, char *password, int passwordLength, char *salt, int iterationCount, char *derivedKey);
|
||||
void EncryptionThreadPoolDoWork (EncryptionThreadPoolWorkType type, byte *data, const UINT64_STRUCT *startUnitNo, uint32 unitCount, PCRYPTO_INFO cryptoInfo);
|
||||
BOOL EncryptionThreadPoolStart (size_t encryptionFreeCpuCount);
|
||||
void EncryptionThreadPoolStop ();
|
||||
size_t GetEncryptionThreadCount ();
|
||||
size_t GetMaxEncryptionThreadCount ();
|
||||
BOOL IsEncryptionThreadPoolRunning ();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_ENCRYPTION_THREAD_POOL
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_ENCRYPTION_THREAD_POOL
|
||||
#define TC_HEADER_ENCRYPTION_THREAD_POOL
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Crypto.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
EncryptDataUnitsWork,
|
||||
DecryptDataUnitsWork,
|
||||
DeriveKeyWork
|
||||
} EncryptionThreadPoolWorkType;
|
||||
|
||||
void EncryptionThreadPoolBeginKeyDerivation (TC_EVENT *completionEvent, TC_EVENT *noOutstandingWorkItemEvent, LONG *completionFlag, LONG *outstandingWorkItemCount, int pkcs5Prf, char *password, int passwordLength, char *salt, int iterationCount, char *derivedKey);
|
||||
void EncryptionThreadPoolDoWork (EncryptionThreadPoolWorkType type, byte *data, const UINT64_STRUCT *startUnitNo, uint32 unitCount, PCRYPTO_INFO cryptoInfo);
|
||||
BOOL EncryptionThreadPoolStart (size_t encryptionFreeCpuCount);
|
||||
void EncryptionThreadPoolStop ();
|
||||
size_t GetEncryptionThreadCount ();
|
||||
size_t GetMaxEncryptionThreadCount ();
|
||||
BOOL IsEncryptionThreadPoolRunning ();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_ENCRYPTION_THREAD_POOL
|
||||
|
||||
@@ -1,59 +1,59 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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 "Tcdefs.h"
|
||||
#include "Common/Endian.h"
|
||||
|
||||
|
||||
unsigned __int16 MirrorBytes16 (unsigned __int16 x)
|
||||
{
|
||||
return (x << 8) | (x >> 8);
|
||||
}
|
||||
|
||||
|
||||
unsigned __int32 MirrorBytes32 (unsigned __int32 x)
|
||||
{
|
||||
unsigned __int32 n = (unsigned __int8) x;
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 8);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 16);
|
||||
return (n << 8) | (unsigned __int8) (x >> 24);
|
||||
}
|
||||
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
uint64 MirrorBytes64 (uint64 x)
|
||||
{
|
||||
uint64 n = (unsigned __int8) x;
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 8);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 16);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 24);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 32);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 40);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 48);
|
||||
return (n << 8) | (unsigned __int8) (x >> 56);
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
LongReverse (unsigned __int32 *buffer, unsigned byteCount)
|
||||
{
|
||||
unsigned __int32 value;
|
||||
|
||||
byteCount /= sizeof (unsigned __int32);
|
||||
while (byteCount--)
|
||||
{
|
||||
value = *buffer;
|
||||
value = ((value & 0xFF00FF00L) >> 8) | \
|
||||
((value & 0x00FF00FFL) << 8);
|
||||
*buffer++ = (value << 16) | (value >> 16);
|
||||
}
|
||||
}
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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 "Tcdefs.h"
|
||||
#include "Common/Endian.h"
|
||||
|
||||
|
||||
unsigned __int16 MirrorBytes16 (unsigned __int16 x)
|
||||
{
|
||||
return (x << 8) | (x >> 8);
|
||||
}
|
||||
|
||||
|
||||
unsigned __int32 MirrorBytes32 (unsigned __int32 x)
|
||||
{
|
||||
unsigned __int32 n = (unsigned __int8) x;
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 8);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 16);
|
||||
return (n << 8) | (unsigned __int8) (x >> 24);
|
||||
}
|
||||
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
uint64 MirrorBytes64 (uint64 x)
|
||||
{
|
||||
uint64 n = (unsigned __int8) x;
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 8);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 16);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 24);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 32);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 40);
|
||||
n <<= 8; n |= (unsigned __int8) (x >> 48);
|
||||
return (n << 8) | (unsigned __int8) (x >> 56);
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
LongReverse (unsigned __int32 *buffer, unsigned byteCount)
|
||||
{
|
||||
unsigned __int32 value;
|
||||
|
||||
byteCount /= sizeof (unsigned __int32);
|
||||
while (byteCount--)
|
||||
{
|
||||
value = *buffer;
|
||||
value = ((value & 0xFF00FF00L) >> 8) | \
|
||||
((value & 0x00FF00FFL) << 8);
|
||||
*buffer++ = (value << 16) | (value >> 16);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,149 +1,149 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#ifndef TC_ENDIAN_H
|
||||
#define TC_ENDIAN_H
|
||||
|
||||
#include "Common/Tcdefs.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
# ifndef LITTLE_ENDIAN
|
||||
# define LITTLE_ENDIAN 1234
|
||||
# endif
|
||||
# ifndef BYTE_ORDER
|
||||
# define BYTE_ORDER LITTLE_ENDIAN
|
||||
# endif
|
||||
|
||||
#elif !defined(BYTE_ORDER)
|
||||
|
||||
# ifdef TC_MACOSX
|
||||
# include <machine/endian.h>
|
||||
# elif defined (TC_BSD)
|
||||
# include <sys/endian.h>
|
||||
# elif defined (TC_SOLARIS)
|
||||
# include <sys/types.h>
|
||||
# define LITTLE_ENDIAN 1234
|
||||
# define BIG_ENDIAN 4321
|
||||
# ifdef _BIG_ENDIAN
|
||||
# define BYTE_ORDER BIG_ENDIAN
|
||||
# else
|
||||
# define BYTE_ORDER LITTLE_ENDIAN
|
||||
# endif
|
||||
# else
|
||||
# include <endian.h>
|
||||
# endif
|
||||
|
||||
# ifndef BYTE_ORDER
|
||||
# ifndef __BYTE_ORDER
|
||||
# error Byte order cannot be determined (BYTE_ORDER undefined)
|
||||
# endif
|
||||
|
||||
# define BYTE_ORDER __BYTE_ORDER
|
||||
# endif
|
||||
|
||||
# ifndef LITTLE_ENDIAN
|
||||
# define LITTLE_ENDIAN __LITTLE_ENDIAN
|
||||
# endif
|
||||
|
||||
# ifndef BIG_ENDIAN
|
||||
# define BIG_ENDIAN __BIG_ENDIAN
|
||||
# endif
|
||||
|
||||
#endif // !BYTE_ORDER
|
||||
|
||||
/* Macros to read and write 16, 32, and 64-bit quantities in a portable manner.
|
||||
These functions are implemented as macros rather than true functions as
|
||||
the need to adjust the memory pointers makes them somewhat painful to call
|
||||
in user code */
|
||||
|
||||
#define mputInt64(memPtr,data) \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 56 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 48 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 40 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 32 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 24 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 16 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 8 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( data ) & 0xFF )
|
||||
|
||||
#define mputLong(memPtr,data) \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 24 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 16 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 8 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( data ) & 0xFF )
|
||||
|
||||
#define mputWord(memPtr,data) \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 8 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( data ) & 0xFF )
|
||||
|
||||
#define mputByte(memPtr,data) \
|
||||
*memPtr++ = ( unsigned char ) data
|
||||
|
||||
#define mputBytes(memPtr,data,len) \
|
||||
memcpy (memPtr,data,len); \
|
||||
memPtr += len;
|
||||
|
||||
#define mgetInt64(memPtr) \
|
||||
( memPtr += 8, ( ( unsigned __int64 ) memPtr[ -8 ] << 56 ) | ( ( unsigned __int64 ) memPtr[ -7 ] << 48 ) | \
|
||||
( ( unsigned __int64 ) memPtr[ -6 ] << 40 ) | ( ( unsigned __int64 ) memPtr[ -5 ] << 32 ) | \
|
||||
( ( unsigned __int64 ) memPtr[ -4 ] << 24 ) | ( ( unsigned __int64 ) memPtr[ -3 ] << 16 ) | \
|
||||
( ( unsigned __int64 ) memPtr[ -2 ] << 8 ) | ( unsigned __int64 ) memPtr[ -1 ] )
|
||||
|
||||
#define mgetLong(memPtr) \
|
||||
( memPtr += 4, ( ( unsigned __int32 ) memPtr[ -4 ] << 24 ) | ( ( unsigned __int32 ) memPtr[ -3 ] << 16 ) | \
|
||||
( ( unsigned __int32 ) memPtr[ -2 ] << 8 ) | ( unsigned __int32 ) memPtr[ -1 ] )
|
||||
|
||||
#define mgetWord(memPtr) \
|
||||
( memPtr += 2, ((( unsigned short ) memPtr[ -2 ] << 8 ) | ( ( unsigned short ) memPtr[ -1 ] )) )
|
||||
|
||||
#define mgetByte(memPtr) \
|
||||
( ( unsigned char ) *memPtr++ )
|
||||
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
# define LE16(x) MirrorBytes16(x)
|
||||
# define LE32(x) MirrorBytes32(x)
|
||||
# define LE64(x) MirrorBytes64(x)
|
||||
#else
|
||||
# define LE16(x) (x)
|
||||
# define LE32(x) (x)
|
||||
# define LE64(x) (x)
|
||||
#endif
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
# define BE16(x) MirrorBytes16(x)
|
||||
# define BE32(x) MirrorBytes32(x)
|
||||
# define BE64(x) MirrorBytes64(x)
|
||||
#else
|
||||
# define BE16(x) (x)
|
||||
# define BE32(x) (x)
|
||||
# define BE64(x) (x)
|
||||
#endif
|
||||
|
||||
unsigned __int16 MirrorBytes16 (unsigned __int16 x);
|
||||
unsigned __int32 MirrorBytes32 (unsigned __int32 x);
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
uint64 MirrorBytes64 (uint64 x);
|
||||
#endif
|
||||
void LongReverse ( unsigned __int32 *buffer , unsigned byteCount );
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TC_ENDIAN_H */
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#ifndef TC_ENDIAN_H
|
||||
#define TC_ENDIAN_H
|
||||
|
||||
#include "Common/Tcdefs.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
# ifndef LITTLE_ENDIAN
|
||||
# define LITTLE_ENDIAN 1234
|
||||
# endif
|
||||
# ifndef BYTE_ORDER
|
||||
# define BYTE_ORDER LITTLE_ENDIAN
|
||||
# endif
|
||||
|
||||
#elif !defined(BYTE_ORDER)
|
||||
|
||||
# ifdef TC_MACOSX
|
||||
# include <machine/endian.h>
|
||||
# elif defined (TC_BSD)
|
||||
# include <sys/endian.h>
|
||||
# elif defined (TC_SOLARIS)
|
||||
# include <sys/types.h>
|
||||
# define LITTLE_ENDIAN 1234
|
||||
# define BIG_ENDIAN 4321
|
||||
# ifdef _BIG_ENDIAN
|
||||
# define BYTE_ORDER BIG_ENDIAN
|
||||
# else
|
||||
# define BYTE_ORDER LITTLE_ENDIAN
|
||||
# endif
|
||||
# else
|
||||
# include <endian.h>
|
||||
# endif
|
||||
|
||||
# ifndef BYTE_ORDER
|
||||
# ifndef __BYTE_ORDER
|
||||
# error Byte order cannot be determined (BYTE_ORDER undefined)
|
||||
# endif
|
||||
|
||||
# define BYTE_ORDER __BYTE_ORDER
|
||||
# endif
|
||||
|
||||
# ifndef LITTLE_ENDIAN
|
||||
# define LITTLE_ENDIAN __LITTLE_ENDIAN
|
||||
# endif
|
||||
|
||||
# ifndef BIG_ENDIAN
|
||||
# define BIG_ENDIAN __BIG_ENDIAN
|
||||
# endif
|
||||
|
||||
#endif // !BYTE_ORDER
|
||||
|
||||
/* Macros to read and write 16, 32, and 64-bit quantities in a portable manner.
|
||||
These functions are implemented as macros rather than true functions as
|
||||
the need to adjust the memory pointers makes them somewhat painful to call
|
||||
in user code */
|
||||
|
||||
#define mputInt64(memPtr,data) \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 56 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 48 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 40 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 32 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 24 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 16 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 8 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( data ) & 0xFF )
|
||||
|
||||
#define mputLong(memPtr,data) \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 24 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 16 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 8 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( data ) & 0xFF )
|
||||
|
||||
#define mputWord(memPtr,data) \
|
||||
*memPtr++ = ( unsigned char ) ( ( ( data ) >> 8 ) & 0xFF ), \
|
||||
*memPtr++ = ( unsigned char ) ( ( data ) & 0xFF )
|
||||
|
||||
#define mputByte(memPtr,data) \
|
||||
*memPtr++ = ( unsigned char ) data
|
||||
|
||||
#define mputBytes(memPtr,data,len) \
|
||||
memcpy (memPtr,data,len); \
|
||||
memPtr += len;
|
||||
|
||||
#define mgetInt64(memPtr) \
|
||||
( memPtr += 8, ( ( unsigned __int64 ) memPtr[ -8 ] << 56 ) | ( ( unsigned __int64 ) memPtr[ -7 ] << 48 ) | \
|
||||
( ( unsigned __int64 ) memPtr[ -6 ] << 40 ) | ( ( unsigned __int64 ) memPtr[ -5 ] << 32 ) | \
|
||||
( ( unsigned __int64 ) memPtr[ -4 ] << 24 ) | ( ( unsigned __int64 ) memPtr[ -3 ] << 16 ) | \
|
||||
( ( unsigned __int64 ) memPtr[ -2 ] << 8 ) | ( unsigned __int64 ) memPtr[ -1 ] )
|
||||
|
||||
#define mgetLong(memPtr) \
|
||||
( memPtr += 4, ( ( unsigned __int32 ) memPtr[ -4 ] << 24 ) | ( ( unsigned __int32 ) memPtr[ -3 ] << 16 ) | \
|
||||
( ( unsigned __int32 ) memPtr[ -2 ] << 8 ) | ( unsigned __int32 ) memPtr[ -1 ] )
|
||||
|
||||
#define mgetWord(memPtr) \
|
||||
( memPtr += 2, ((( unsigned short ) memPtr[ -2 ] << 8 ) | ( ( unsigned short ) memPtr[ -1 ] )) )
|
||||
|
||||
#define mgetByte(memPtr) \
|
||||
( ( unsigned char ) *memPtr++ )
|
||||
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
# define LE16(x) MirrorBytes16(x)
|
||||
# define LE32(x) MirrorBytes32(x)
|
||||
# define LE64(x) MirrorBytes64(x)
|
||||
#else
|
||||
# define LE16(x) (x)
|
||||
# define LE32(x) (x)
|
||||
# define LE64(x) (x)
|
||||
#endif
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
# define BE16(x) MirrorBytes16(x)
|
||||
# define BE32(x) MirrorBytes32(x)
|
||||
# define BE64(x) MirrorBytes64(x)
|
||||
#else
|
||||
# define BE16(x) (x)
|
||||
# define BE32(x) (x)
|
||||
# define BE64(x) (x)
|
||||
#endif
|
||||
|
||||
unsigned __int16 MirrorBytes16 (unsigned __int16 x);
|
||||
unsigned __int32 MirrorBytes32 (unsigned __int32 x);
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
uint64 MirrorBytes64 (uint64 x);
|
||||
#endif
|
||||
void LongReverse ( unsigned __int32 *buffer , unsigned byteCount );
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TC_ENDIAN_H */
|
||||
|
||||
@@ -1,123 +1,123 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Common_Exception
|
||||
#define TC_HEADER_Common_Exception
|
||||
|
||||
#include "Platform/PlatformBase.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Language.h"
|
||||
#include <strsafe.h>
|
||||
|
||||
namespace VeraCrypt
|
||||
{
|
||||
struct Exception
|
||||
{
|
||||
virtual void Show (HWND parent) const = 0;
|
||||
};
|
||||
|
||||
struct SystemException : public Exception
|
||||
{
|
||||
SystemException (const char *srcPos) : ErrorCode (GetLastError()), SrcPos (srcPos) { }
|
||||
|
||||
void Show (HWND parent) const
|
||||
{
|
||||
SetLastError (ErrorCode);
|
||||
handleWin32Error (parent, SrcPos);
|
||||
}
|
||||
|
||||
DWORD ErrorCode;
|
||||
const char *SrcPos;
|
||||
};
|
||||
|
||||
struct ErrorException : public Exception
|
||||
{
|
||||
ErrorException (char *langId, const char *srcPos) : SrcPos (srcPos), ErrLangId (langId) { }
|
||||
ErrorException (const wstring &errMsg, const char *srcPos) : SrcPos (srcPos), ErrLangId(NULL), ErrMsg (errMsg) { }
|
||||
|
||||
void Show (HWND parent) const
|
||||
{
|
||||
if (ErrMsg.empty())
|
||||
::ErrorDirect (AppendSrcPos (GetString (ErrLangId? ErrLangId : ""), SrcPos).c_str (), parent);
|
||||
else
|
||||
::ErrorDirect (AppendSrcPos (ErrMsg.c_str(), SrcPos).c_str (), parent);
|
||||
}
|
||||
|
||||
const char *SrcPos;
|
||||
char *ErrLangId;
|
||||
wstring ErrMsg;
|
||||
};
|
||||
|
||||
struct ParameterIncorrect : public Exception
|
||||
{
|
||||
ParameterIncorrect (const char *srcPos) : SrcPos (srcPos) { }
|
||||
|
||||
void Show (HWND parent) const
|
||||
{
|
||||
string msgBody = "Parameter incorrect.\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n" + string (SrcPos) + ")";
|
||||
MessageBoxA (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
|
||||
}
|
||||
|
||||
const char *SrcPos;
|
||||
};
|
||||
|
||||
struct RandInitFailed : public Exception
|
||||
{
|
||||
RandInitFailed (const char *srcPos, DWORD dwLastError) : SrcPos (srcPos), LastError (dwLastError) { }
|
||||
|
||||
void Show (HWND parent) const
|
||||
{
|
||||
char szErrCode[16];
|
||||
StringCchPrintfA (szErrCode, ARRAYSIZE(szErrCode), "0x%.8X", LastError);
|
||||
string msgBody = "The Random Generator initialization failed.\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n" + string (SrcPos) + "\nLast Error = " + string (szErrCode) + ")";
|
||||
MessageBoxA (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
|
||||
}
|
||||
|
||||
const char *SrcPos;
|
||||
DWORD LastError;
|
||||
};
|
||||
|
||||
struct CryptoApiFailed : public Exception
|
||||
{
|
||||
CryptoApiFailed (const char *srcPos, DWORD dwLastError) : SrcPos (srcPos), LastError (dwLastError) { }
|
||||
|
||||
void Show (HWND parent) const
|
||||
{
|
||||
char szErrCode[16];
|
||||
StringCchPrintfA (szErrCode, ARRAYSIZE(szErrCode), "0x%.8X", LastError);
|
||||
string msgBody = "Windows Crypto API failed.\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n" + string (SrcPos) + "\nLast Error = " + string (szErrCode) + ")";
|
||||
MessageBoxA (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
|
||||
}
|
||||
|
||||
const char *SrcPos;
|
||||
DWORD LastError;
|
||||
};
|
||||
|
||||
struct TimeOut : public Exception
|
||||
{
|
||||
TimeOut (const char *srcPos) : SrcPos (srcPos) { }
|
||||
void Show (HWND parent) const { ErrorDirect (AppendSrcPos (L"Timeout", SrcPos).c_str (), parent); }
|
||||
|
||||
const char *SrcPos;
|
||||
};
|
||||
|
||||
struct UserAbort : public Exception
|
||||
{
|
||||
UserAbort (const char *srcPos) { }
|
||||
void Show (HWND parent) const { }
|
||||
};
|
||||
}
|
||||
|
||||
#define throw_sys_if(condition) do { if (condition) throw SystemException( SRC_POS ); } while (false)
|
||||
|
||||
|
||||
#endif // TC_HEADER_Common_Exception
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Common_Exception
|
||||
#define TC_HEADER_Common_Exception
|
||||
|
||||
#include "Platform/PlatformBase.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Language.h"
|
||||
#include <strsafe.h>
|
||||
|
||||
namespace VeraCrypt
|
||||
{
|
||||
struct Exception
|
||||
{
|
||||
virtual void Show (HWND parent) const = 0;
|
||||
};
|
||||
|
||||
struct SystemException : public Exception
|
||||
{
|
||||
SystemException (const char *srcPos) : ErrorCode (GetLastError()), SrcPos (srcPos) { }
|
||||
|
||||
void Show (HWND parent) const
|
||||
{
|
||||
SetLastError (ErrorCode);
|
||||
handleWin32Error (parent, SrcPos);
|
||||
}
|
||||
|
||||
DWORD ErrorCode;
|
||||
const char *SrcPos;
|
||||
};
|
||||
|
||||
struct ErrorException : public Exception
|
||||
{
|
||||
ErrorException (char *langId, const char *srcPos) : SrcPos (srcPos), ErrLangId (langId) { }
|
||||
ErrorException (const wstring &errMsg, const char *srcPos) : SrcPos (srcPos), ErrLangId(NULL), ErrMsg (errMsg) { }
|
||||
|
||||
void Show (HWND parent) const
|
||||
{
|
||||
if (ErrMsg.empty())
|
||||
::ErrorDirect (AppendSrcPos (GetString (ErrLangId? ErrLangId : ""), SrcPos).c_str (), parent);
|
||||
else
|
||||
::ErrorDirect (AppendSrcPos (ErrMsg.c_str(), SrcPos).c_str (), parent);
|
||||
}
|
||||
|
||||
const char *SrcPos;
|
||||
char *ErrLangId;
|
||||
wstring ErrMsg;
|
||||
};
|
||||
|
||||
struct ParameterIncorrect : public Exception
|
||||
{
|
||||
ParameterIncorrect (const char *srcPos) : SrcPos (srcPos) { }
|
||||
|
||||
void Show (HWND parent) const
|
||||
{
|
||||
string msgBody = "Parameter incorrect.\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n" + string (SrcPos) + ")";
|
||||
MessageBoxA (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
|
||||
}
|
||||
|
||||
const char *SrcPos;
|
||||
};
|
||||
|
||||
struct RandInitFailed : public Exception
|
||||
{
|
||||
RandInitFailed (const char *srcPos, DWORD dwLastError) : SrcPos (srcPos), LastError (dwLastError) { }
|
||||
|
||||
void Show (HWND parent) const
|
||||
{
|
||||
char szErrCode[16];
|
||||
StringCchPrintfA (szErrCode, ARRAYSIZE(szErrCode), "0x%.8X", LastError);
|
||||
string msgBody = "The Random Generator initialization failed.\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n" + string (SrcPos) + "\nLast Error = " + string (szErrCode) + ")";
|
||||
MessageBoxA (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
|
||||
}
|
||||
|
||||
const char *SrcPos;
|
||||
DWORD LastError;
|
||||
};
|
||||
|
||||
struct CryptoApiFailed : public Exception
|
||||
{
|
||||
CryptoApiFailed (const char *srcPos, DWORD dwLastError) : SrcPos (srcPos), LastError (dwLastError) { }
|
||||
|
||||
void Show (HWND parent) const
|
||||
{
|
||||
char szErrCode[16];
|
||||
StringCchPrintfA (szErrCode, ARRAYSIZE(szErrCode), "0x%.8X", LastError);
|
||||
string msgBody = "Windows Crypto API failed.\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n" + string (SrcPos) + "\nLast Error = " + string (szErrCode) + ")";
|
||||
MessageBoxA (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
|
||||
}
|
||||
|
||||
const char *SrcPos;
|
||||
DWORD LastError;
|
||||
};
|
||||
|
||||
struct TimeOut : public Exception
|
||||
{
|
||||
TimeOut (const char *srcPos) : SrcPos (srcPos) { }
|
||||
void Show (HWND parent) const { ErrorDirect (AppendSrcPos (L"Timeout", SrcPos).c_str (), parent); }
|
||||
|
||||
const char *SrcPos;
|
||||
};
|
||||
|
||||
struct UserAbort : public Exception
|
||||
{
|
||||
UserAbort (const char *srcPos) { }
|
||||
void Show (HWND parent) const { }
|
||||
};
|
||||
}
|
||||
|
||||
#define throw_sys_if(condition) do { if (condition) throw SystemException( SRC_POS ); } while (false)
|
||||
|
||||
|
||||
#endif // TC_HEADER_Common_Exception
|
||||
|
||||
898
src/Common/Fat.c
898
src/Common/Fat.c
@@ -1,449 +1,449 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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 <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#include "Crypto.h"
|
||||
#include "Common/Endian.h"
|
||||
#include "Format.h"
|
||||
#include "Fat.h"
|
||||
#include "Progress.h"
|
||||
#include "Random.h"
|
||||
#include "Volumes.h"
|
||||
|
||||
void
|
||||
GetFatParams (fatparams * ft)
|
||||
{
|
||||
uint64 volumeSize = (uint64) ft->num_sectors * ft->sector_size;
|
||||
unsigned int fatsecs;
|
||||
|
||||
if(ft->cluster_size == 0) // 'Default' cluster size
|
||||
{
|
||||
uint32 clusterSize;
|
||||
|
||||
// Determine optimal cluster size to minimize FAT size (mounting delay), maximize number of files, keep 4 KB alignment, etc.
|
||||
if (volumeSize >= 2 * BYTES_PER_TB)
|
||||
clusterSize = 256 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 512 * BYTES_PER_GB)
|
||||
clusterSize = 128 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 128 * BYTES_PER_GB)
|
||||
clusterSize = 64 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 64 * BYTES_PER_GB)
|
||||
clusterSize = 32 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 32 * BYTES_PER_GB)
|
||||
clusterSize = 16 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 16 * BYTES_PER_GB)
|
||||
clusterSize = 8 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 512 * BYTES_PER_MB)
|
||||
clusterSize = 4 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 256 * BYTES_PER_MB)
|
||||
clusterSize = 2 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 1 * BYTES_PER_MB)
|
||||
clusterSize = 1 * BYTES_PER_KB;
|
||||
else
|
||||
clusterSize = 512;
|
||||
|
||||
ft->cluster_size = clusterSize / ft->sector_size;
|
||||
|
||||
if (ft->cluster_size == 0)
|
||||
ft->cluster_size = 1;
|
||||
|
||||
if (((unsigned __int64) ft->cluster_size * ft->sector_size) > TC_MAX_FAT_CLUSTER_SIZE)
|
||||
ft->cluster_size = TC_MAX_FAT_CLUSTER_SIZE / ft->sector_size;
|
||||
|
||||
if (ft->cluster_size > 128)
|
||||
ft->cluster_size = 128;
|
||||
}
|
||||
|
||||
if (volumeSize <= TC_MAX_FAT_CLUSTER_SIZE * 4)
|
||||
ft->cluster_size = 1;
|
||||
|
||||
// Geometry always set to SECTORS/1/1
|
||||
ft->secs_track = 1;
|
||||
ft->heads = 1;
|
||||
|
||||
ft->dir_entries = 512;
|
||||
ft->fats = 2;
|
||||
ft->media = 0xf8;
|
||||
ft->hidden = 0;
|
||||
|
||||
ft->size_root_dir = ft->dir_entries * 32;
|
||||
|
||||
// FAT12
|
||||
ft->size_fat = 12;
|
||||
ft->reserved = 2;
|
||||
fatsecs = ft->num_sectors - (ft->size_root_dir + ft->sector_size - 1) / ft->sector_size - ft->reserved;
|
||||
ft->cluster_count = (int) (((unsigned __int64) fatsecs * ft->sector_size) / ((unsigned __int64) ft->cluster_size * ft->sector_size));
|
||||
ft->fat_length = (((ft->cluster_count * 3 + 1) >> 1) + ft->sector_size - 1) / ft->sector_size;
|
||||
|
||||
if (ft->cluster_count >= 4085) // FAT16
|
||||
{
|
||||
ft->size_fat = 16;
|
||||
ft->reserved = 2;
|
||||
fatsecs = ft->num_sectors - (ft->size_root_dir + ft->sector_size - 1) / ft->sector_size - ft->reserved;
|
||||
ft->cluster_count = (int) (((__int64) fatsecs * ft->sector_size) / (ft->cluster_size * ft->sector_size));
|
||||
ft->fat_length = (ft->cluster_count * 2 + ft->sector_size - 1) / ft->sector_size;
|
||||
}
|
||||
|
||||
if(ft->cluster_count >= 65525) // FAT32
|
||||
{
|
||||
ft->size_fat = 32;
|
||||
ft->reserved = 32 - 1;
|
||||
|
||||
do
|
||||
{
|
||||
ft->reserved++;
|
||||
|
||||
fatsecs = ft->num_sectors - ft->reserved;
|
||||
ft->size_root_dir = ft->cluster_size * ft->sector_size;
|
||||
ft->cluster_count = (int) (((unsigned __int64) fatsecs * ft->sector_size) / (ft->cluster_size * ft->sector_size));
|
||||
ft->fat_length = (ft->cluster_count * 4 + ft->sector_size - 1) / ft->sector_size;
|
||||
|
||||
// Align data area on TC_MAX_VOLUME_SECTOR_SIZE
|
||||
|
||||
} while (ft->sector_size == TC_SECTOR_SIZE_LEGACY
|
||||
&& (ft->reserved * ft->sector_size + ft->fat_length * ft->fats * ft->sector_size) % TC_MAX_VOLUME_SECTOR_SIZE != 0);
|
||||
}
|
||||
|
||||
ft->cluster_count -= ft->fat_length * ft->fats / ft->cluster_size;
|
||||
|
||||
if (ft->num_sectors >= 65536 || ft->size_fat == 32)
|
||||
{
|
||||
ft->sectors = 0;
|
||||
ft->total_sect = ft->num_sectors;
|
||||
}
|
||||
else
|
||||
{
|
||||
ft->sectors = (uint16) ft->num_sectors;
|
||||
ft->total_sect = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PutBoot (fatparams * ft, unsigned char *boot)
|
||||
{
|
||||
int cnt = 0;
|
||||
|
||||
boot[cnt++] = 0xeb; /* boot jump */
|
||||
boot[cnt++] = 0x3c;
|
||||
boot[cnt++] = 0x90;
|
||||
memcpy (boot + cnt, "MSDOS5.0", 8); /* system id */
|
||||
cnt += 8;
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->sector_size); /* bytes per sector */
|
||||
cnt += 2;
|
||||
boot[cnt++] = (__int8) ft->cluster_size; /* sectors per cluster */
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->reserved); /* reserved sectors */
|
||||
cnt += 2;
|
||||
boot[cnt++] = (__int8) ft->fats; /* 2 fats */
|
||||
|
||||
if(ft->size_fat == 32)
|
||||
{
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x00;
|
||||
}
|
||||
else
|
||||
{
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->dir_entries); /* 512 root entries */
|
||||
cnt += 2;
|
||||
}
|
||||
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->sectors); /* # sectors */
|
||||
cnt += 2;
|
||||
boot[cnt++] = (__int8) ft->media; /* media byte */
|
||||
|
||||
if(ft->size_fat == 32)
|
||||
{
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x00;
|
||||
}
|
||||
else
|
||||
{
|
||||
*(__int16 *)(boot + cnt) = LE16((uint16) ft->fat_length); /* fat size */
|
||||
cnt += 2;
|
||||
}
|
||||
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->secs_track); /* # sectors per track */
|
||||
cnt += 2;
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->heads); /* # heads */
|
||||
cnt += 2;
|
||||
*(__int32 *)(boot + cnt) = LE32(ft->hidden); /* # hidden sectors */
|
||||
cnt += 4;
|
||||
*(__int32 *)(boot + cnt) = LE32(ft->total_sect); /* # huge sectors */
|
||||
cnt += 4;
|
||||
|
||||
if(ft->size_fat == 32)
|
||||
{
|
||||
*(__int32 *)(boot + cnt) = LE32(ft->fat_length); cnt += 4; /* fat size 32 */
|
||||
boot[cnt++] = 0x00; /* ExtFlags */
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x00; /* FSVer */
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x02; /* RootClus */
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x01; /* FSInfo */
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x06; /* BkBootSec */
|
||||
boot[cnt++] = 0x00;
|
||||
memset(boot+cnt, 0, 12); cnt+=12; /* Reserved */
|
||||
}
|
||||
|
||||
boot[cnt++] = 0x00; /* drive number */ // FIXED 80 > 00
|
||||
boot[cnt++] = 0x00; /* reserved */
|
||||
boot[cnt++] = 0x29; /* boot sig */
|
||||
|
||||
memcpy (boot + cnt, ft->volume_id, 4); /* vol id */
|
||||
cnt += 4;
|
||||
|
||||
memcpy (boot + cnt, ft->volume_name, 11); /* vol title */
|
||||
cnt += 11;
|
||||
|
||||
switch(ft->size_fat) /* filesystem type */
|
||||
{
|
||||
case 12: memcpy (boot + cnt, "FAT12 ", 8); break;
|
||||
case 16: memcpy (boot + cnt, "FAT16 ", 8); break;
|
||||
case 32: memcpy (boot + cnt, "FAT32 ", 8); break;
|
||||
}
|
||||
cnt += 8;
|
||||
|
||||
memset (boot + cnt, 0, ft->size_fat==32 ? 420:448); /* boot code */
|
||||
cnt += ft->size_fat==32 ? 420:448;
|
||||
boot[cnt++] = 0x55;
|
||||
boot[cnt++] = 0xaa; /* boot sig */
|
||||
}
|
||||
|
||||
|
||||
/* FAT32 FSInfo */
|
||||
static void PutFSInfo (unsigned char *sector, fatparams *ft)
|
||||
{
|
||||
memset (sector, 0, ft->sector_size);
|
||||
sector[3]=0x41; /* LeadSig */
|
||||
sector[2]=0x61;
|
||||
sector[1]=0x52;
|
||||
sector[0]=0x52;
|
||||
sector[484+3]=0x61; /* StrucSig */
|
||||
sector[484+2]=0x41;
|
||||
sector[484+1]=0x72;
|
||||
sector[484+0]=0x72;
|
||||
|
||||
// Free cluster count
|
||||
*(uint32 *)(sector + 488) = LE32 (ft->cluster_count - ft->size_root_dir / ft->sector_size / ft->cluster_size);
|
||||
|
||||
// Next free cluster
|
||||
*(uint32 *)(sector + 492) = LE32 (2);
|
||||
|
||||
sector[508+3]=0xaa; /* TrailSig */
|
||||
sector[508+2]=0x55;
|
||||
sector[508+1]=0x00;
|
||||
sector[508+0]=0x00;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void * dev, PCRYPTO_INFO cryptoInfo, BOOL quickFormat)
|
||||
{
|
||||
int write_buf_cnt = 0;
|
||||
char sector[TC_MAX_VOLUME_SECTOR_SIZE], *write_buf;
|
||||
unsigned __int64 nSecNo = startSector;
|
||||
int x, n;
|
||||
int retVal;
|
||||
char temporaryKey[MASTER_KEYDATA_SIZE];
|
||||
HWND hwndDlg = (HWND) hwndDlgPtr;
|
||||
|
||||
LARGE_INTEGER startOffset;
|
||||
LARGE_INTEGER newOffset;
|
||||
|
||||
// Seek to start sector
|
||||
startOffset.QuadPart = startSector * ft->sector_size;
|
||||
if (!SetFilePointerEx ((HANDLE) dev, startOffset, &newOffset, FILE_BEGIN)
|
||||
|| newOffset.QuadPart != startOffset.QuadPart)
|
||||
{
|
||||
return ERR_VOL_SEEKING;
|
||||
}
|
||||
|
||||
/* Write the data area */
|
||||
|
||||
write_buf = (char *)TCalloc (FormatWriteBufferSize);
|
||||
if (!write_buf)
|
||||
return ERR_OUTOFMEMORY;
|
||||
|
||||
memset (sector, 0, ft->sector_size);
|
||||
|
||||
if (!RandgetBytes (hwndDlg, ft->volume_id, sizeof (ft->volume_id), FALSE))
|
||||
goto fail;
|
||||
|
||||
PutBoot (ft, (unsigned char *) sector);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
|
||||
/* fat32 boot area */
|
||||
if (ft->size_fat == 32)
|
||||
{
|
||||
/* fsinfo */
|
||||
PutFSInfo((unsigned char *) sector, ft);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
|
||||
/* reserved */
|
||||
while (nSecNo - startSector < 6)
|
||||
{
|
||||
memset (sector, 0, ft->sector_size);
|
||||
sector[508+3]=0xaa; /* TrailSig */
|
||||
sector[508+2]=0x55;
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* bootsector backup */
|
||||
memset (sector, 0, ft->sector_size);
|
||||
PutBoot (ft, (unsigned char *) sector);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
|
||||
PutFSInfo((unsigned char *) sector, ft);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* reserved */
|
||||
while (nSecNo - startSector < (unsigned int)ft->reserved)
|
||||
{
|
||||
memset (sector, 0, ft->sector_size);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* write fat */
|
||||
for (x = 1; x <= ft->fats; x++)
|
||||
{
|
||||
for (n = 0; n < ft->fat_length; n++)
|
||||
{
|
||||
memset (sector, 0, ft->sector_size);
|
||||
|
||||
if (n == 0)
|
||||
{
|
||||
unsigned char fat_sig[12];
|
||||
if (ft->size_fat == 32)
|
||||
{
|
||||
fat_sig[0] = (unsigned char) ft->media;
|
||||
fat_sig[1] = fat_sig[2] = 0xff;
|
||||
fat_sig[3] = 0x0f;
|
||||
fat_sig[4] = fat_sig[5] = fat_sig[6] = 0xff;
|
||||
fat_sig[7] = 0x0f;
|
||||
fat_sig[8] = fat_sig[9] = fat_sig[10] = 0xff;
|
||||
fat_sig[11] = 0x0f;
|
||||
memcpy (sector, fat_sig, 12);
|
||||
}
|
||||
else if (ft->size_fat == 16)
|
||||
{
|
||||
fat_sig[0] = (unsigned char) ft->media;
|
||||
fat_sig[1] = 0xff;
|
||||
fat_sig[2] = 0xff;
|
||||
fat_sig[3] = 0xff;
|
||||
memcpy (sector, fat_sig, 4);
|
||||
}
|
||||
else if (ft->size_fat == 12)
|
||||
{
|
||||
fat_sig[0] = (unsigned char) ft->media;
|
||||
fat_sig[1] = 0xff;
|
||||
fat_sig[2] = 0xff;
|
||||
fat_sig[3] = 0x00;
|
||||
memcpy (sector, fat_sig, 4);
|
||||
}
|
||||
}
|
||||
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* write rootdir */
|
||||
for (x = 0; x < ft->size_root_dir / ft->sector_size; x++)
|
||||
{
|
||||
memset (sector, 0, ft->sector_size);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
|
||||
}
|
||||
|
||||
/* Fill the rest of the data area with random data */
|
||||
|
||||
if(!quickFormat)
|
||||
{
|
||||
if (!FlushFormatWriteBuffer (dev, write_buf, &write_buf_cnt, &nSecNo, cryptoInfo))
|
||||
goto fail;
|
||||
|
||||
/* Generate a random temporary key set to be used for "dummy" encryption that will fill
|
||||
the free disk space (data area) with random data. This is necessary for plausible
|
||||
deniability of hidden volumes (and also reduces the amount of predictable plaintext
|
||||
within the volume). */
|
||||
|
||||
// Temporary master key
|
||||
if (!RandgetBytes (hwndDlg, temporaryKey, EAGetKeySize (cryptoInfo->ea), FALSE))
|
||||
goto fail;
|
||||
|
||||
// Temporary secondary key (XTS mode)
|
||||
if (!RandgetBytes (hwndDlg, cryptoInfo->k2, sizeof cryptoInfo->k2, FALSE))
|
||||
goto fail;
|
||||
|
||||
retVal = EAInit (cryptoInfo->ea, temporaryKey, cryptoInfo->ks);
|
||||
if (retVal != ERR_SUCCESS)
|
||||
{
|
||||
burn (temporaryKey, sizeof(temporaryKey));
|
||||
return retVal;
|
||||
}
|
||||
if (!EAInitMode (cryptoInfo))
|
||||
{
|
||||
burn (temporaryKey, sizeof(temporaryKey));
|
||||
return ERR_MODE_INIT_FAILED;
|
||||
}
|
||||
|
||||
x = ft->num_sectors - ft->reserved - ft->size_root_dir / ft->sector_size - ft->fat_length * 2;
|
||||
while (x--)
|
||||
{
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
UpdateProgressBar (nSecNo * ft->sector_size);
|
||||
}
|
||||
else
|
||||
UpdateProgressBar ((uint64) ft->num_sectors * ft->sector_size);
|
||||
|
||||
if (!FlushFormatWriteBuffer (dev, write_buf, &write_buf_cnt, &nSecNo, cryptoInfo))
|
||||
goto fail;
|
||||
|
||||
TCfree (write_buf);
|
||||
burn (temporaryKey, sizeof(temporaryKey));
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
|
||||
TCfree (write_buf);
|
||||
burn (temporaryKey, sizeof(temporaryKey));
|
||||
return ERR_OS_ERROR;
|
||||
}
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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 <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#include "Crypto.h"
|
||||
#include "Common/Endian.h"
|
||||
#include "Format.h"
|
||||
#include "Fat.h"
|
||||
#include "Progress.h"
|
||||
#include "Random.h"
|
||||
#include "Volumes.h"
|
||||
|
||||
void
|
||||
GetFatParams (fatparams * ft)
|
||||
{
|
||||
uint64 volumeSize = (uint64) ft->num_sectors * ft->sector_size;
|
||||
unsigned int fatsecs;
|
||||
|
||||
if(ft->cluster_size == 0) // 'Default' cluster size
|
||||
{
|
||||
uint32 clusterSize;
|
||||
|
||||
// Determine optimal cluster size to minimize FAT size (mounting delay), maximize number of files, keep 4 KB alignment, etc.
|
||||
if (volumeSize >= 2 * BYTES_PER_TB)
|
||||
clusterSize = 256 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 512 * BYTES_PER_GB)
|
||||
clusterSize = 128 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 128 * BYTES_PER_GB)
|
||||
clusterSize = 64 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 64 * BYTES_PER_GB)
|
||||
clusterSize = 32 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 32 * BYTES_PER_GB)
|
||||
clusterSize = 16 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 16 * BYTES_PER_GB)
|
||||
clusterSize = 8 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 512 * BYTES_PER_MB)
|
||||
clusterSize = 4 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 256 * BYTES_PER_MB)
|
||||
clusterSize = 2 * BYTES_PER_KB;
|
||||
else if (volumeSize >= 1 * BYTES_PER_MB)
|
||||
clusterSize = 1 * BYTES_PER_KB;
|
||||
else
|
||||
clusterSize = 512;
|
||||
|
||||
ft->cluster_size = clusterSize / ft->sector_size;
|
||||
|
||||
if (ft->cluster_size == 0)
|
||||
ft->cluster_size = 1;
|
||||
|
||||
if (((unsigned __int64) ft->cluster_size * ft->sector_size) > TC_MAX_FAT_CLUSTER_SIZE)
|
||||
ft->cluster_size = TC_MAX_FAT_CLUSTER_SIZE / ft->sector_size;
|
||||
|
||||
if (ft->cluster_size > 128)
|
||||
ft->cluster_size = 128;
|
||||
}
|
||||
|
||||
if (volumeSize <= TC_MAX_FAT_CLUSTER_SIZE * 4)
|
||||
ft->cluster_size = 1;
|
||||
|
||||
// Geometry always set to SECTORS/1/1
|
||||
ft->secs_track = 1;
|
||||
ft->heads = 1;
|
||||
|
||||
ft->dir_entries = 512;
|
||||
ft->fats = 2;
|
||||
ft->media = 0xf8;
|
||||
ft->hidden = 0;
|
||||
|
||||
ft->size_root_dir = ft->dir_entries * 32;
|
||||
|
||||
// FAT12
|
||||
ft->size_fat = 12;
|
||||
ft->reserved = 2;
|
||||
fatsecs = ft->num_sectors - (ft->size_root_dir + ft->sector_size - 1) / ft->sector_size - ft->reserved;
|
||||
ft->cluster_count = (int) (((unsigned __int64) fatsecs * ft->sector_size) / ((unsigned __int64) ft->cluster_size * ft->sector_size));
|
||||
ft->fat_length = (((ft->cluster_count * 3 + 1) >> 1) + ft->sector_size - 1) / ft->sector_size;
|
||||
|
||||
if (ft->cluster_count >= 4085) // FAT16
|
||||
{
|
||||
ft->size_fat = 16;
|
||||
ft->reserved = 2;
|
||||
fatsecs = ft->num_sectors - (ft->size_root_dir + ft->sector_size - 1) / ft->sector_size - ft->reserved;
|
||||
ft->cluster_count = (int) (((__int64) fatsecs * ft->sector_size) / (ft->cluster_size * ft->sector_size));
|
||||
ft->fat_length = (ft->cluster_count * 2 + ft->sector_size - 1) / ft->sector_size;
|
||||
}
|
||||
|
||||
if(ft->cluster_count >= 65525) // FAT32
|
||||
{
|
||||
ft->size_fat = 32;
|
||||
ft->reserved = 32 - 1;
|
||||
|
||||
do
|
||||
{
|
||||
ft->reserved++;
|
||||
|
||||
fatsecs = ft->num_sectors - ft->reserved;
|
||||
ft->size_root_dir = ft->cluster_size * ft->sector_size;
|
||||
ft->cluster_count = (int) (((unsigned __int64) fatsecs * ft->sector_size) / (ft->cluster_size * ft->sector_size));
|
||||
ft->fat_length = (ft->cluster_count * 4 + ft->sector_size - 1) / ft->sector_size;
|
||||
|
||||
// Align data area on TC_MAX_VOLUME_SECTOR_SIZE
|
||||
|
||||
} while (ft->sector_size == TC_SECTOR_SIZE_LEGACY
|
||||
&& (ft->reserved * ft->sector_size + ft->fat_length * ft->fats * ft->sector_size) % TC_MAX_VOLUME_SECTOR_SIZE != 0);
|
||||
}
|
||||
|
||||
ft->cluster_count -= ft->fat_length * ft->fats / ft->cluster_size;
|
||||
|
||||
if (ft->num_sectors >= 65536 || ft->size_fat == 32)
|
||||
{
|
||||
ft->sectors = 0;
|
||||
ft->total_sect = ft->num_sectors;
|
||||
}
|
||||
else
|
||||
{
|
||||
ft->sectors = (uint16) ft->num_sectors;
|
||||
ft->total_sect = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PutBoot (fatparams * ft, unsigned char *boot)
|
||||
{
|
||||
int cnt = 0;
|
||||
|
||||
boot[cnt++] = 0xeb; /* boot jump */
|
||||
boot[cnt++] = 0x3c;
|
||||
boot[cnt++] = 0x90;
|
||||
memcpy (boot + cnt, "MSDOS5.0", 8); /* system id */
|
||||
cnt += 8;
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->sector_size); /* bytes per sector */
|
||||
cnt += 2;
|
||||
boot[cnt++] = (__int8) ft->cluster_size; /* sectors per cluster */
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->reserved); /* reserved sectors */
|
||||
cnt += 2;
|
||||
boot[cnt++] = (__int8) ft->fats; /* 2 fats */
|
||||
|
||||
if(ft->size_fat == 32)
|
||||
{
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x00;
|
||||
}
|
||||
else
|
||||
{
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->dir_entries); /* 512 root entries */
|
||||
cnt += 2;
|
||||
}
|
||||
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->sectors); /* # sectors */
|
||||
cnt += 2;
|
||||
boot[cnt++] = (__int8) ft->media; /* media byte */
|
||||
|
||||
if(ft->size_fat == 32)
|
||||
{
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x00;
|
||||
}
|
||||
else
|
||||
{
|
||||
*(__int16 *)(boot + cnt) = LE16((uint16) ft->fat_length); /* fat size */
|
||||
cnt += 2;
|
||||
}
|
||||
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->secs_track); /* # sectors per track */
|
||||
cnt += 2;
|
||||
*(__int16 *)(boot + cnt) = LE16(ft->heads); /* # heads */
|
||||
cnt += 2;
|
||||
*(__int32 *)(boot + cnt) = LE32(ft->hidden); /* # hidden sectors */
|
||||
cnt += 4;
|
||||
*(__int32 *)(boot + cnt) = LE32(ft->total_sect); /* # huge sectors */
|
||||
cnt += 4;
|
||||
|
||||
if(ft->size_fat == 32)
|
||||
{
|
||||
*(__int32 *)(boot + cnt) = LE32(ft->fat_length); cnt += 4; /* fat size 32 */
|
||||
boot[cnt++] = 0x00; /* ExtFlags */
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x00; /* FSVer */
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x02; /* RootClus */
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x01; /* FSInfo */
|
||||
boot[cnt++] = 0x00;
|
||||
boot[cnt++] = 0x06; /* BkBootSec */
|
||||
boot[cnt++] = 0x00;
|
||||
memset(boot+cnt, 0, 12); cnt+=12; /* Reserved */
|
||||
}
|
||||
|
||||
boot[cnt++] = 0x00; /* drive number */ // FIXED 80 > 00
|
||||
boot[cnt++] = 0x00; /* reserved */
|
||||
boot[cnt++] = 0x29; /* boot sig */
|
||||
|
||||
memcpy (boot + cnt, ft->volume_id, 4); /* vol id */
|
||||
cnt += 4;
|
||||
|
||||
memcpy (boot + cnt, ft->volume_name, 11); /* vol title */
|
||||
cnt += 11;
|
||||
|
||||
switch(ft->size_fat) /* filesystem type */
|
||||
{
|
||||
case 12: memcpy (boot + cnt, "FAT12 ", 8); break;
|
||||
case 16: memcpy (boot + cnt, "FAT16 ", 8); break;
|
||||
case 32: memcpy (boot + cnt, "FAT32 ", 8); break;
|
||||
}
|
||||
cnt += 8;
|
||||
|
||||
memset (boot + cnt, 0, ft->size_fat==32 ? 420:448); /* boot code */
|
||||
cnt += ft->size_fat==32 ? 420:448;
|
||||
boot[cnt++] = 0x55;
|
||||
boot[cnt++] = 0xaa; /* boot sig */
|
||||
}
|
||||
|
||||
|
||||
/* FAT32 FSInfo */
|
||||
static void PutFSInfo (unsigned char *sector, fatparams *ft)
|
||||
{
|
||||
memset (sector, 0, ft->sector_size);
|
||||
sector[3]=0x41; /* LeadSig */
|
||||
sector[2]=0x61;
|
||||
sector[1]=0x52;
|
||||
sector[0]=0x52;
|
||||
sector[484+3]=0x61; /* StrucSig */
|
||||
sector[484+2]=0x41;
|
||||
sector[484+1]=0x72;
|
||||
sector[484+0]=0x72;
|
||||
|
||||
// Free cluster count
|
||||
*(uint32 *)(sector + 488) = LE32 (ft->cluster_count - ft->size_root_dir / ft->sector_size / ft->cluster_size);
|
||||
|
||||
// Next free cluster
|
||||
*(uint32 *)(sector + 492) = LE32 (2);
|
||||
|
||||
sector[508+3]=0xaa; /* TrailSig */
|
||||
sector[508+2]=0x55;
|
||||
sector[508+1]=0x00;
|
||||
sector[508+0]=0x00;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void * dev, PCRYPTO_INFO cryptoInfo, BOOL quickFormat)
|
||||
{
|
||||
int write_buf_cnt = 0;
|
||||
char sector[TC_MAX_VOLUME_SECTOR_SIZE], *write_buf;
|
||||
unsigned __int64 nSecNo = startSector;
|
||||
int x, n;
|
||||
int retVal;
|
||||
char temporaryKey[MASTER_KEYDATA_SIZE];
|
||||
HWND hwndDlg = (HWND) hwndDlgPtr;
|
||||
|
||||
LARGE_INTEGER startOffset;
|
||||
LARGE_INTEGER newOffset;
|
||||
|
||||
// Seek to start sector
|
||||
startOffset.QuadPart = startSector * ft->sector_size;
|
||||
if (!SetFilePointerEx ((HANDLE) dev, startOffset, &newOffset, FILE_BEGIN)
|
||||
|| newOffset.QuadPart != startOffset.QuadPart)
|
||||
{
|
||||
return ERR_VOL_SEEKING;
|
||||
}
|
||||
|
||||
/* Write the data area */
|
||||
|
||||
write_buf = (char *)TCalloc (FormatWriteBufferSize);
|
||||
if (!write_buf)
|
||||
return ERR_OUTOFMEMORY;
|
||||
|
||||
memset (sector, 0, ft->sector_size);
|
||||
|
||||
if (!RandgetBytes (hwndDlg, ft->volume_id, sizeof (ft->volume_id), FALSE))
|
||||
goto fail;
|
||||
|
||||
PutBoot (ft, (unsigned char *) sector);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
|
||||
/* fat32 boot area */
|
||||
if (ft->size_fat == 32)
|
||||
{
|
||||
/* fsinfo */
|
||||
PutFSInfo((unsigned char *) sector, ft);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
|
||||
/* reserved */
|
||||
while (nSecNo - startSector < 6)
|
||||
{
|
||||
memset (sector, 0, ft->sector_size);
|
||||
sector[508+3]=0xaa; /* TrailSig */
|
||||
sector[508+2]=0x55;
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* bootsector backup */
|
||||
memset (sector, 0, ft->sector_size);
|
||||
PutBoot (ft, (unsigned char *) sector);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
|
||||
PutFSInfo((unsigned char *) sector, ft);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* reserved */
|
||||
while (nSecNo - startSector < (unsigned int)ft->reserved)
|
||||
{
|
||||
memset (sector, 0, ft->sector_size);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* write fat */
|
||||
for (x = 1; x <= ft->fats; x++)
|
||||
{
|
||||
for (n = 0; n < ft->fat_length; n++)
|
||||
{
|
||||
memset (sector, 0, ft->sector_size);
|
||||
|
||||
if (n == 0)
|
||||
{
|
||||
unsigned char fat_sig[12];
|
||||
if (ft->size_fat == 32)
|
||||
{
|
||||
fat_sig[0] = (unsigned char) ft->media;
|
||||
fat_sig[1] = fat_sig[2] = 0xff;
|
||||
fat_sig[3] = 0x0f;
|
||||
fat_sig[4] = fat_sig[5] = fat_sig[6] = 0xff;
|
||||
fat_sig[7] = 0x0f;
|
||||
fat_sig[8] = fat_sig[9] = fat_sig[10] = 0xff;
|
||||
fat_sig[11] = 0x0f;
|
||||
memcpy (sector, fat_sig, 12);
|
||||
}
|
||||
else if (ft->size_fat == 16)
|
||||
{
|
||||
fat_sig[0] = (unsigned char) ft->media;
|
||||
fat_sig[1] = 0xff;
|
||||
fat_sig[2] = 0xff;
|
||||
fat_sig[3] = 0xff;
|
||||
memcpy (sector, fat_sig, 4);
|
||||
}
|
||||
else if (ft->size_fat == 12)
|
||||
{
|
||||
fat_sig[0] = (unsigned char) ft->media;
|
||||
fat_sig[1] = 0xff;
|
||||
fat_sig[2] = 0xff;
|
||||
fat_sig[3] = 0x00;
|
||||
memcpy (sector, fat_sig, 4);
|
||||
}
|
||||
}
|
||||
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* write rootdir */
|
||||
for (x = 0; x < ft->size_root_dir / ft->sector_size; x++)
|
||||
{
|
||||
memset (sector, 0, ft->sector_size);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
|
||||
}
|
||||
|
||||
/* Fill the rest of the data area with random data */
|
||||
|
||||
if(!quickFormat)
|
||||
{
|
||||
if (!FlushFormatWriteBuffer (dev, write_buf, &write_buf_cnt, &nSecNo, cryptoInfo))
|
||||
goto fail;
|
||||
|
||||
/* Generate a random temporary key set to be used for "dummy" encryption that will fill
|
||||
the free disk space (data area) with random data. This is necessary for plausible
|
||||
deniability of hidden volumes (and also reduces the amount of predictable plaintext
|
||||
within the volume). */
|
||||
|
||||
// Temporary master key
|
||||
if (!RandgetBytes (hwndDlg, temporaryKey, EAGetKeySize (cryptoInfo->ea), FALSE))
|
||||
goto fail;
|
||||
|
||||
// Temporary secondary key (XTS mode)
|
||||
if (!RandgetBytes (hwndDlg, cryptoInfo->k2, sizeof cryptoInfo->k2, FALSE))
|
||||
goto fail;
|
||||
|
||||
retVal = EAInit (cryptoInfo->ea, temporaryKey, cryptoInfo->ks);
|
||||
if (retVal != ERR_SUCCESS)
|
||||
{
|
||||
burn (temporaryKey, sizeof(temporaryKey));
|
||||
return retVal;
|
||||
}
|
||||
if (!EAInitMode (cryptoInfo))
|
||||
{
|
||||
burn (temporaryKey, sizeof(temporaryKey));
|
||||
return ERR_MODE_INIT_FAILED;
|
||||
}
|
||||
|
||||
x = ft->num_sectors - ft->reserved - ft->size_root_dir / ft->sector_size - ft->fat_length * 2;
|
||||
while (x--)
|
||||
{
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo,
|
||||
cryptoInfo) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
UpdateProgressBar (nSecNo * ft->sector_size);
|
||||
}
|
||||
else
|
||||
UpdateProgressBar ((uint64) ft->num_sectors * ft->sector_size);
|
||||
|
||||
if (!FlushFormatWriteBuffer (dev, write_buf, &write_buf_cnt, &nSecNo, cryptoInfo))
|
||||
goto fail;
|
||||
|
||||
TCfree (write_buf);
|
||||
burn (temporaryKey, sizeof(temporaryKey));
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
|
||||
TCfree (write_buf);
|
||||
burn (temporaryKey, sizeof(temporaryKey));
|
||||
return ERR_OS_ERROR;
|
||||
}
|
||||
|
||||
138
src/Common/Fat.h
138
src/Common/Fat.h
@@ -1,69 +1,69 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
typedef struct fatparams_t
|
||||
{
|
||||
char volume_name[11];
|
||||
byte volume_id[4];
|
||||
unsigned int num_sectors; /* total number of sectors */
|
||||
int cluster_count; /* number of clusters */
|
||||
int size_root_dir; /* size of the root directory in bytes */
|
||||
int size_fat; /* size of FAT */
|
||||
int fats;
|
||||
int media;
|
||||
unsigned int cluster_size;
|
||||
int fat_length;
|
||||
uint16 dir_entries;
|
||||
uint16 sector_size;
|
||||
int hidden;
|
||||
__int16 reserved;
|
||||
uint16 sectors;
|
||||
unsigned int total_sect;
|
||||
|
||||
uint16 heads;
|
||||
uint16 secs_track;
|
||||
|
||||
} fatparams;
|
||||
|
||||
|
||||
struct msdos_boot_sector
|
||||
{
|
||||
unsigned char boot_jump[3]; /* Boot strap short or near jump */
|
||||
char system_id[8]; /* Name - can be used to special case
|
||||
partition manager volumes */
|
||||
unsigned char sector_size[2]; /* bytes per logical sector */
|
||||
unsigned char cluster_size; /* sectors/cluster */
|
||||
unsigned short reserved;/* reserved sectors */
|
||||
unsigned char fats; /* number of FATs */
|
||||
unsigned char dir_entries[2]; /* root directory entries */
|
||||
unsigned char sectors[2]; /* number of sectors */
|
||||
unsigned char media; /* media code */
|
||||
unsigned short fat_length; /* sectors/FAT */
|
||||
unsigned short secs_track; /* sectors per track */
|
||||
unsigned short heads; /* number of heads */
|
||||
unsigned __int32 hidden; /* hidden sectors */
|
||||
unsigned __int32 total_sect; /* number of sectors (if sectors == 0) */
|
||||
unsigned char drive_number; /* BIOS drive number */
|
||||
unsigned char RESERVED; /* Unused */
|
||||
unsigned char ext_boot_sign; /* 0x29 if fields below exist (DOS 3.3+) */
|
||||
unsigned char volume_id[4]; /* Volume ID number */
|
||||
char volume_label[11]; /* Volume label */
|
||||
char fs_type[8]; /* Typically FAT12, FAT16, or FAT32 */
|
||||
unsigned char boot_code[448]; /* Boot code (or message) */
|
||||
unsigned short boot_sign; /* 0xAA55 */
|
||||
};
|
||||
|
||||
|
||||
void GetFatParams ( fatparams *ft );
|
||||
void PutBoot ( fatparams *ft , unsigned char *boot );
|
||||
int FormatFat (void* hwndDlg, unsigned __int64 startSector, fatparams * ft, void * dev, PCRYPTO_INFO cryptoInfo, BOOL quickFormat);
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
typedef struct fatparams_t
|
||||
{
|
||||
char volume_name[11];
|
||||
byte volume_id[4];
|
||||
unsigned int num_sectors; /* total number of sectors */
|
||||
int cluster_count; /* number of clusters */
|
||||
int size_root_dir; /* size of the root directory in bytes */
|
||||
int size_fat; /* size of FAT */
|
||||
int fats;
|
||||
int media;
|
||||
unsigned int cluster_size;
|
||||
int fat_length;
|
||||
uint16 dir_entries;
|
||||
uint16 sector_size;
|
||||
int hidden;
|
||||
__int16 reserved;
|
||||
uint16 sectors;
|
||||
unsigned int total_sect;
|
||||
|
||||
uint16 heads;
|
||||
uint16 secs_track;
|
||||
|
||||
} fatparams;
|
||||
|
||||
|
||||
struct msdos_boot_sector
|
||||
{
|
||||
unsigned char boot_jump[3]; /* Boot strap short or near jump */
|
||||
char system_id[8]; /* Name - can be used to special case
|
||||
partition manager volumes */
|
||||
unsigned char sector_size[2]; /* bytes per logical sector */
|
||||
unsigned char cluster_size; /* sectors/cluster */
|
||||
unsigned short reserved;/* reserved sectors */
|
||||
unsigned char fats; /* number of FATs */
|
||||
unsigned char dir_entries[2]; /* root directory entries */
|
||||
unsigned char sectors[2]; /* number of sectors */
|
||||
unsigned char media; /* media code */
|
||||
unsigned short fat_length; /* sectors/FAT */
|
||||
unsigned short secs_track; /* sectors per track */
|
||||
unsigned short heads; /* number of heads */
|
||||
unsigned __int32 hidden; /* hidden sectors */
|
||||
unsigned __int32 total_sect; /* number of sectors (if sectors == 0) */
|
||||
unsigned char drive_number; /* BIOS drive number */
|
||||
unsigned char RESERVED; /* Unused */
|
||||
unsigned char ext_boot_sign; /* 0x29 if fields below exist (DOS 3.3+) */
|
||||
unsigned char volume_id[4]; /* Volume ID number */
|
||||
char volume_label[11]; /* Volume label */
|
||||
char fs_type[8]; /* Typically FAT12, FAT16, or FAT32 */
|
||||
unsigned char boot_code[448]; /* Boot code (or message) */
|
||||
unsigned short boot_sign; /* 0xAA55 */
|
||||
};
|
||||
|
||||
|
||||
void GetFatParams ( fatparams *ft );
|
||||
void PutBoot ( fatparams *ft , unsigned char *boot );
|
||||
int FormatFat (void* hwndDlg, unsigned __int64 startSector, fatparams * ft, void * dev, PCRYPTO_INFO cryptoInfo, BOOL quickFormat);
|
||||
|
||||
2108
src/Common/Format.c
2108
src/Common/Format.c
File diff suppressed because it is too large
Load Diff
@@ -1,53 +1,53 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#ifndef TC_HEADER_Format
|
||||
#define TC_HEADER_Format
|
||||
|
||||
#include "Password.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// FMIFS
|
||||
typedef BOOLEAN (__stdcall *PFMIFSCALLBACK)( int command, DWORD subCommand, PVOID parameter );
|
||||
typedef VOID (__stdcall *PFORMATEX)( PWCHAR DriveRoot, DWORD MediaFlag, PWCHAR Format, PWCHAR Label, BOOL QuickFormat, DWORD ClusterSize, PFMIFSCALLBACK Callback );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BOOL bDevice;
|
||||
BOOL hiddenVol;
|
||||
wchar_t *volumePath;
|
||||
unsigned __int64 size;
|
||||
unsigned __int64 hiddenVolHostSize;
|
||||
int ea;
|
||||
int pkcs5;
|
||||
uint32 headerFlags;
|
||||
int fileSystem;
|
||||
unsigned int clusterSize;
|
||||
BOOL sparseFileSwitch;
|
||||
BOOL quickFormat;
|
||||
DWORD sectorSize;
|
||||
int *realClusterSize;
|
||||
Password *password;
|
||||
int pim;
|
||||
HWND hwndDlg;
|
||||
BOOL bForceOperation;
|
||||
BOOL bGuiMode;
|
||||
}
|
||||
FORMAT_VOL_PARAMETERS;
|
||||
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#ifndef TC_HEADER_Format
|
||||
#define TC_HEADER_Format
|
||||
|
||||
#include "Password.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// FMIFS
|
||||
typedef BOOLEAN (__stdcall *PFMIFSCALLBACK)( int command, DWORD subCommand, PVOID parameter );
|
||||
typedef VOID (__stdcall *PFORMATEX)( PWCHAR DriveRoot, DWORD MediaFlag, PWCHAR Format, PWCHAR Label, BOOL QuickFormat, DWORD ClusterSize, PFMIFSCALLBACK Callback );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BOOL bDevice;
|
||||
BOOL hiddenVol;
|
||||
wchar_t *volumePath;
|
||||
unsigned __int64 size;
|
||||
unsigned __int64 hiddenVolHostSize;
|
||||
int ea;
|
||||
int pkcs5;
|
||||
uint32 headerFlags;
|
||||
int fileSystem;
|
||||
unsigned int clusterSize;
|
||||
BOOL sparseFileSwitch;
|
||||
BOOL quickFormat;
|
||||
DWORD sectorSize;
|
||||
int *realClusterSize;
|
||||
Password *password;
|
||||
int pim;
|
||||
HWND hwndDlg;
|
||||
BOOL bForceOperation;
|
||||
BOOL bGuiMode;
|
||||
}
|
||||
FORMAT_VOL_PARAMETERS;
|
||||
|
||||
#define FMIFS_PROGRESS 0x00
|
||||
#define FMIFS_DONE_WITH_STRUCTURE 0x01
|
||||
#define FMIFS_INCOMPATIBLE_FILE_SYSTEM 0x03
|
||||
@@ -66,29 +66,29 @@ FORMAT_VOL_PARAMETERS;
|
||||
#define FMIFS_NO_MEDIA_IN_DRIVE 0x14
|
||||
#define FMIFS_DEVICE_NOT_READY 0x18
|
||||
#define FMIFS_CHECKDISK_PROGRESS 0x19
|
||||
#define FMIFS_READ_ONLY_MODE 0x20
|
||||
|
||||
#define FMIFS_HARDDISK 0xC
|
||||
|
||||
extern int FormatWriteBufferSize;
|
||||
|
||||
int TCFormatVolume (volatile FORMAT_VOL_PARAMETERS *volParams);
|
||||
BOOL FormatNtfs (int driveNo, int clusterSize);
|
||||
BOOL FormatFs (int driveNo, int clusterSize, int fsType);
|
||||
uint64 GetVolumeDataAreaSize (BOOL hiddenVolume, uint64 volumeSize);
|
||||
int FormatNoFs (HWND hwndDlg, unsigned __int64 startSector, __int64 num_sectors, void *dev, PCRYPTO_INFO cryptoInfo, BOOL quickFormat);
|
||||
BOOL WriteSector ( void *dev , char *sector , char *write_buf , int *write_buf_cnt , __int64 *nSecNo , PCRYPTO_INFO cryptoInfo );
|
||||
BOOL FlushFormatWriteBuffer (void *dev, char *write_buf, int *write_buf_cnt, __int64 *nSecNo, PCRYPTO_INFO cryptoInfo);
|
||||
static BOOL StartFormatWriteThread ();
|
||||
static void StopFormatWriteThread ();
|
||||
|
||||
#define FILESYS_NONE 0
|
||||
#define FILESYS_FAT 1
|
||||
#define FILESYS_NTFS 2
|
||||
#define FILESYS_EXFAT 3
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_Format
|
||||
#define FMIFS_READ_ONLY_MODE 0x20
|
||||
|
||||
#define FMIFS_HARDDISK 0xC
|
||||
|
||||
extern int FormatWriteBufferSize;
|
||||
|
||||
int TCFormatVolume (volatile FORMAT_VOL_PARAMETERS *volParams);
|
||||
BOOL FormatNtfs (int driveNo, int clusterSize);
|
||||
BOOL FormatFs (int driveNo, int clusterSize, int fsType);
|
||||
uint64 GetVolumeDataAreaSize (BOOL hiddenVolume, uint64 volumeSize);
|
||||
int FormatNoFs (HWND hwndDlg, unsigned __int64 startSector, __int64 num_sectors, void *dev, PCRYPTO_INFO cryptoInfo, BOOL quickFormat);
|
||||
BOOL WriteSector ( void *dev , char *sector , char *write_buf , int *write_buf_cnt , __int64 *nSecNo , PCRYPTO_INFO cryptoInfo );
|
||||
BOOL FlushFormatWriteBuffer (void *dev, char *write_buf, int *write_buf_cnt, __int64 *nSecNo, PCRYPTO_INFO cryptoInfo);
|
||||
static BOOL StartFormatWriteThread ();
|
||||
static void StopFormatWriteThread ();
|
||||
|
||||
#define FILESYS_NONE 0
|
||||
#define FILESYS_FAT 1
|
||||
#define FILESYS_NTFS 2
|
||||
#define FILESYS_EXFAT 3
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_Format
|
||||
|
||||
1536
src/Common/GfMul.c
1536
src/Common/GfMul.c
File diff suppressed because it is too large
Load Diff
@@ -1,74 +1,74 @@
|
||||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved.
|
||||
|
||||
LICENSE TERMS
|
||||
|
||||
The free distribution and use of this software is allowed (with or without
|
||||
changes) provided that:
|
||||
|
||||
1. source code distributions include the above copyright notice, this
|
||||
list of conditions and the following disclaimer;
|
||||
|
||||
2. binary distributions include the above copyright notice, this list
|
||||
of conditions and the following disclaimer in their documentation;
|
||||
|
||||
3. the name of the copyright holder is not used to endorse products
|
||||
built using this software without specific written permission.
|
||||
|
||||
DISCLAIMER
|
||||
|
||||
This software is provided 'as is' with no explicit or implied warranties
|
||||
in respect of its properties, including, but not limited to, correctness
|
||||
and/or fitness for purpose.
|
||||
---------------------------------------------------------------------------
|
||||
Issue Date: 31/01/2004
|
||||
*/
|
||||
|
||||
/* Adapted for TrueCrypt */
|
||||
|
||||
#ifndef _GCM_H
|
||||
#define _GCM_H
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define CBLK_LEN 16 /* encryption block length */
|
||||
#define CBLK_LEN8 8
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned __int32 gf_t8k[CBLK_LEN * 2][16][CBLK_LEN / 4];
|
||||
} GfCtx8k;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned __int32 gf_t4k[CBLK_LEN8 * 2][16][CBLK_LEN / 4];
|
||||
} GfCtx4k64;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* union not used to support faster mounting */
|
||||
unsigned __int32 gf_t128[CBLK_LEN * 2 / 2][16][CBLK_LEN / 4];
|
||||
unsigned __int32 gf_t64[CBLK_LEN8 * 2][16][CBLK_LEN8 / 4];
|
||||
} GfCtx;
|
||||
|
||||
typedef int ret_type;
|
||||
|
||||
void GfMul128 (void *a, const void* b);
|
||||
void GfMul128Tab(unsigned char a[16], GfCtx8k *ctx);
|
||||
int Gf128Tab64Init (unsigned __int8 *a, GfCtx *ctx);
|
||||
void Gf128MulBy64Tab (unsigned __int8 a[8], unsigned __int8 p[16], GfCtx *ctx);
|
||||
void MirrorBits128 (unsigned __int8 *a);
|
||||
void MirrorBits64 (unsigned __int8 *a);
|
||||
BOOL GfMulSelfTest ();
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved.
|
||||
|
||||
LICENSE TERMS
|
||||
|
||||
The free distribution and use of this software is allowed (with or without
|
||||
changes) provided that:
|
||||
|
||||
1. source code distributions include the above copyright notice, this
|
||||
list of conditions and the following disclaimer;
|
||||
|
||||
2. binary distributions include the above copyright notice, this list
|
||||
of conditions and the following disclaimer in their documentation;
|
||||
|
||||
3. the name of the copyright holder is not used to endorse products
|
||||
built using this software without specific written permission.
|
||||
|
||||
DISCLAIMER
|
||||
|
||||
This software is provided 'as is' with no explicit or implied warranties
|
||||
in respect of its properties, including, but not limited to, correctness
|
||||
and/or fitness for purpose.
|
||||
---------------------------------------------------------------------------
|
||||
Issue Date: 31/01/2004
|
||||
*/
|
||||
|
||||
/* Adapted for TrueCrypt */
|
||||
|
||||
#ifndef _GCM_H
|
||||
#define _GCM_H
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define CBLK_LEN 16 /* encryption block length */
|
||||
#define CBLK_LEN8 8
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned __int32 gf_t8k[CBLK_LEN * 2][16][CBLK_LEN / 4];
|
||||
} GfCtx8k;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned __int32 gf_t4k[CBLK_LEN8 * 2][16][CBLK_LEN / 4];
|
||||
} GfCtx4k64;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* union not used to support faster mounting */
|
||||
unsigned __int32 gf_t128[CBLK_LEN * 2 / 2][16][CBLK_LEN / 4];
|
||||
unsigned __int32 gf_t64[CBLK_LEN8 * 2][16][CBLK_LEN8 / 4];
|
||||
} GfCtx;
|
||||
|
||||
typedef int ret_type;
|
||||
|
||||
void GfMul128 (void *a, const void* b);
|
||||
void GfMul128Tab(unsigned char a[16], GfCtx8k *ctx);
|
||||
int Gf128Tab64Init (unsigned __int8 *a, GfCtx *ctx);
|
||||
void Gf128MulBy64Tab (unsigned __int8 a[8], unsigned __int8 p[16], GfCtx *ctx);
|
||||
void MirrorBits128 (unsigned __int8 *a);
|
||||
void MirrorBits64 (unsigned __int8 *a);
|
||||
BOOL GfMulSelfTest ();
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
2642
src/Common/Inflate.c
2642
src/Common/Inflate.c
File diff suppressed because it is too large
Load Diff
@@ -1,51 +1,51 @@
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
|
||||
#define WSIZE 0x8000 // Window size
|
||||
#define ZCONST const
|
||||
#define OF(p) p
|
||||
|
||||
typedef unsigned long ulg;
|
||||
typedef unsigned char uch;
|
||||
typedef unsigned short ush;
|
||||
typedef void zvoid;
|
||||
|
||||
typedef struct huft
|
||||
{
|
||||
uch b, e;
|
||||
union
|
||||
{
|
||||
ush n;
|
||||
struct huft *t;
|
||||
}v;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uch *inptr, *outbufptr;
|
||||
int incnt;
|
||||
int outCounter;
|
||||
|
||||
struct huft *fixed_tl;
|
||||
struct huft *fixed_td;
|
||||
int fixed_bl, fixed_bd;
|
||||
|
||||
unsigned bk, wp;
|
||||
ulg bb;
|
||||
} G_struct;
|
||||
|
||||
#define __GPRO void
|
||||
#define __GPRO__
|
||||
#define __G
|
||||
#define __G__
|
||||
#define __GDEF
|
||||
|
||||
|
||||
#define FLUSH(cnt) { memcpy (G.outbufptr, redirSlide, cnt); G.outbufptr += cnt; G.outCounter += cnt; }
|
||||
#define NEXTBYTE (((G.incnt--) >= 0) ? (*G.inptr++) : EOF)
|
||||
|
||||
|
||||
int huft_free(struct huft *t);
|
||||
int huft_build(__GDEF ZCONST unsigned *b, unsigned n, unsigned s, ZCONST ush *d, ZCONST ush *e, struct huft **t, int *m);
|
||||
|
||||
int DecompressDeflatedData (char *out, char *in, int inLength);
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
|
||||
#define WSIZE 0x8000 // Window size
|
||||
#define ZCONST const
|
||||
#define OF(p) p
|
||||
|
||||
typedef unsigned long ulg;
|
||||
typedef unsigned char uch;
|
||||
typedef unsigned short ush;
|
||||
typedef void zvoid;
|
||||
|
||||
typedef struct huft
|
||||
{
|
||||
uch b, e;
|
||||
union
|
||||
{
|
||||
ush n;
|
||||
struct huft *t;
|
||||
}v;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uch *inptr, *outbufptr;
|
||||
int incnt;
|
||||
int outCounter;
|
||||
|
||||
struct huft *fixed_tl;
|
||||
struct huft *fixed_td;
|
||||
int fixed_bl, fixed_bd;
|
||||
|
||||
unsigned bk, wp;
|
||||
ulg bb;
|
||||
} G_struct;
|
||||
|
||||
#define __GPRO void
|
||||
#define __GPRO__
|
||||
#define __G
|
||||
#define __G__
|
||||
#define __GDEF
|
||||
|
||||
|
||||
#define FLUSH(cnt) { memcpy (G.outbufptr, redirSlide, cnt); G.outbufptr += cnt; G.outCounter += cnt; }
|
||||
#define NEXTBYTE (((G.incnt--) >= 0) ? (*G.inptr++) : EOF)
|
||||
|
||||
|
||||
int huft_free(struct huft *t);
|
||||
int huft_build(__GDEF ZCONST unsigned *b, unsigned n, unsigned s, ZCONST ush *d, ZCONST ush *e, struct huft **t, int *m);
|
||||
|
||||
int DecompressDeflatedData (char *out, char *in, int inLength);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,54 +1,54 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef KEYFILES_H
|
||||
#define KEYFILES_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
#define KEYFILE_POOL_SIZE 64
|
||||
#define KEYFILE_MAX_READ_LEN (1024*1024)
|
||||
|
||||
typedef struct KeyFileStruct
|
||||
{
|
||||
wchar_t FileName[MAX_PATH + 1];
|
||||
struct KeyFileStruct *Next;
|
||||
} KeyFile;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
wchar_t VolumeFileName[MAX_PATH + 1];
|
||||
BOOL EnableKeyFiles;
|
||||
KeyFile *FirstKeyFile;
|
||||
} KeyFilesDlgParam;
|
||||
|
||||
KeyFile *KeyFileAdd (KeyFile *firstKeyFile, KeyFile *keyFile);
|
||||
void KeyFileRemoveAll (KeyFile **firstKeyFile);
|
||||
KeyFile *KeyFileClone (KeyFile *keyFile);
|
||||
void KeyFileCloneAll (KeyFile *firstKeyFile, KeyFile **outputKeyFile);
|
||||
BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFilem, const wchar_t* volumeFileName);
|
||||
BOOL KeyFilesApplyWithPin (HWND hwndDlg, Password *password, char* pin, KeyFile *firstKeyFilem, const wchar_t* volumeFileName);
|
||||
|
||||
BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
BOOL KeyfilesPopupMenu (HWND hwndDlg, POINT popupPosition, KeyFilesDlgParam *dialogParam);
|
||||
|
||||
extern BOOL HiddenFilesPresentInKeyfilePath;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* #ifndef KEYFILES_H */
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef KEYFILES_H
|
||||
#define KEYFILES_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
#define KEYFILE_POOL_SIZE 64
|
||||
#define KEYFILE_MAX_READ_LEN (1024*1024)
|
||||
|
||||
typedef struct KeyFileStruct
|
||||
{
|
||||
wchar_t FileName[MAX_PATH + 1];
|
||||
struct KeyFileStruct *Next;
|
||||
} KeyFile;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
wchar_t VolumeFileName[MAX_PATH + 1];
|
||||
BOOL EnableKeyFiles;
|
||||
KeyFile *FirstKeyFile;
|
||||
} KeyFilesDlgParam;
|
||||
|
||||
KeyFile *KeyFileAdd (KeyFile *firstKeyFile, KeyFile *keyFile);
|
||||
void KeyFileRemoveAll (KeyFile **firstKeyFile);
|
||||
KeyFile *KeyFileClone (KeyFile *keyFile);
|
||||
void KeyFileCloneAll (KeyFile *firstKeyFile, KeyFile **outputKeyFile);
|
||||
BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFilem, const wchar_t* volumeFileName);
|
||||
BOOL KeyFilesApplyWithPin (HWND hwndDlg, Password *password, char* pin, KeyFile *firstKeyFilem, const wchar_t* volumeFileName);
|
||||
|
||||
BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
BOOL KeyfilesPopupMenu (HWND hwndDlg, POINT popupPosition, KeyFilesDlgParam *dialogParam);
|
||||
|
||||
extern BOOL HiddenFilesPresentInKeyfilePath;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* #ifndef KEYFILES_H */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,43 +1,43 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define UNKNOWN_STRING_ID L"[?]"
|
||||
|
||||
extern BOOL LocalizationActive;
|
||||
extern int LocalizationSerialNo;
|
||||
extern wchar_t UnknownString[1024];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
wchar_t *FaceName;
|
||||
int Size;
|
||||
} Font;
|
||||
|
||||
BOOL CALLBACK LanguageDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
wchar_t *GetString (const char *stringId);
|
||||
Font *GetFont (char *fontType);
|
||||
BOOL LoadLanguageFile ();
|
||||
char *GetPreferredLangId ();
|
||||
void SetPreferredLangId (char *langId);
|
||||
char *GetActiveLangPackVersion ();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define UNKNOWN_STRING_ID L"[?]"
|
||||
|
||||
extern BOOL LocalizationActive;
|
||||
extern int LocalizationSerialNo;
|
||||
extern wchar_t UnknownString[1024];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
wchar_t *FaceName;
|
||||
int Size;
|
||||
} Font;
|
||||
|
||||
BOOL CALLBACK LanguageDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
wchar_t *GetString (const char *stringId);
|
||||
Font *GetFont (char *fontType);
|
||||
BOOL LoadLanguageFile ();
|
||||
char *GetPreferredLangId ();
|
||||
void SetPreferredLangId (char *langId);
|
||||
char *GetActiveLangPackVersion ();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1 +1 @@
|
||||
!INCLUDE $(NTMAKEENV)\makefile.def
|
||||
!INCLUDE $(NTMAKEENV)\makefile.def
|
||||
|
||||
@@ -1,491 +1,491 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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 "Tcdefs.h"
|
||||
|
||||
#include "Crypto.h"
|
||||
#include "Volumes.h"
|
||||
#include "Password.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Language.h"
|
||||
#include "Pkcs5.h"
|
||||
#include "Endian.h"
|
||||
#include "Random.h"
|
||||
|
||||
#include <io.h>
|
||||
|
||||
#ifndef SRC_POS
|
||||
#define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__))
|
||||
#endif
|
||||
|
||||
void VerifyPasswordAndUpdate (HWND hwndDlg, HWND hButton, HWND hPassword,
|
||||
HWND hVerify, unsigned char *szPassword,
|
||||
char *szVerify,
|
||||
BOOL keyFilesEnabled)
|
||||
{
|
||||
wchar_t szTmp1[MAX_PASSWORD + 1];
|
||||
wchar_t szTmp2[MAX_PASSWORD + 1];
|
||||
char szTmp1Utf8[MAX_PASSWORD + 1];
|
||||
char szTmp2Utf8[MAX_PASSWORD + 1];
|
||||
int k = GetWindowTextLength (hPassword);
|
||||
BOOL bEnable = FALSE;
|
||||
int utf8Len1, utf8Len2;
|
||||
|
||||
UNREFERENCED_PARAMETER (hwndDlg); /* Remove warning */
|
||||
|
||||
GetWindowText (hPassword, szTmp1, ARRAYSIZE (szTmp1));
|
||||
GetWindowText (hVerify, szTmp2, ARRAYSIZE (szTmp2));
|
||||
|
||||
utf8Len1 = WideCharToMultiByte (CP_UTF8, 0, szTmp1, -1, szTmp1Utf8, MAX_PASSWORD + 1, NULL, NULL);
|
||||
utf8Len2 = WideCharToMultiByte (CP_UTF8, 0, szTmp2, -1, szTmp2Utf8, MAX_PASSWORD + 1, NULL, NULL);
|
||||
|
||||
if (wcscmp (szTmp1, szTmp2) != 0)
|
||||
bEnable = FALSE;
|
||||
else if (utf8Len1 <= 0)
|
||||
bEnable = FALSE;
|
||||
else
|
||||
{
|
||||
if (k >= MIN_PASSWORD || keyFilesEnabled)
|
||||
bEnable = TRUE;
|
||||
else
|
||||
bEnable = FALSE;
|
||||
}
|
||||
|
||||
if (szPassword != NULL)
|
||||
{
|
||||
if (utf8Len1 > 0)
|
||||
memcpy (szPassword, szTmp1Utf8, sizeof (szTmp1Utf8));
|
||||
else
|
||||
szPassword [0] = 0;
|
||||
}
|
||||
|
||||
if (szVerify != NULL)
|
||||
{
|
||||
if (utf8Len2 > 0)
|
||||
memcpy (szVerify, szTmp2Utf8, sizeof (szTmp2Utf8));
|
||||
else
|
||||
szVerify [0] = 0;
|
||||
}
|
||||
|
||||
burn (szTmp1, sizeof (szTmp1));
|
||||
burn (szTmp2, sizeof (szTmp2));
|
||||
burn (szTmp1Utf8, sizeof (szTmp1Utf8));
|
||||
burn (szTmp2Utf8, sizeof (szTmp2Utf8));
|
||||
|
||||
EnableWindow (hButton, bEnable);
|
||||
}
|
||||
|
||||
|
||||
BOOL CheckPasswordCharEncoding (HWND hPassword, Password *ptrPw)
|
||||
{
|
||||
int i, len;
|
||||
|
||||
if (hPassword == NULL)
|
||||
{
|
||||
if (ptrPw)
|
||||
{
|
||||
unsigned char *pw;
|
||||
len = ptrPw->Length;
|
||||
pw = (unsigned char *) ptrPw->Text;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (pw[i] >= 0x7f || pw[i] < 0x20) // A non-ASCII or non-printable character?
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t s[MAX_PASSWORD + 1];
|
||||
len = GetWindowTextLength (hPassword);
|
||||
|
||||
if (len > MAX_PASSWORD)
|
||||
return FALSE;
|
||||
|
||||
GetWindowTextW (hPassword, s, sizeof (s) / sizeof (wchar_t));
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (s[i] >= 0x7f || s[i] < 0x20) // A non-ASCII or non-printable character?
|
||||
break;
|
||||
}
|
||||
|
||||
burn (s, sizeof(s));
|
||||
|
||||
if (i < len)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
BOOL CheckPasswordLength (HWND hwndDlg, unsigned __int32 passwordLength, int pim, BOOL bForBoot, BOOL bSkipPasswordWarning, BOOL bSkipPimWarning)
|
||||
{
|
||||
BOOL bCustomPimSmall = ((pim != 0) && (pim < (bForBoot? 98 : 485)))? TRUE : FALSE;
|
||||
if (passwordLength < PASSWORD_LEN_WARNING)
|
||||
{
|
||||
if (bCustomPimSmall)
|
||||
{
|
||||
Error (bForBoot? "BOOT_PIM_REQUIRE_LONG_PASSWORD": "PIM_REQUIRE_LONG_PASSWORD", hwndDlg);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifndef _DEBUG
|
||||
if (!bSkipPasswordWarning && (MessageBoxW (hwndDlg, GetString ("PASSWORD_LENGTH_WARNING"), lpszTitle, MB_YESNO|MB_ICONWARNING|MB_DEFBUTTON2) != IDYES))
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
#ifndef _DEBUG
|
||||
else if (bCustomPimSmall)
|
||||
{
|
||||
if (!bSkipPimWarning && AskWarnNoYes ("PIM_SMALL_WARNING", hwndDlg) != IDYES)
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((pim != 0) && (pim > (bForBoot? 98 : 485)))
|
||||
{
|
||||
// warn that mount/boot will take more time
|
||||
Warning ("PIM_LARGE_WARNING", hwndDlg);
|
||||
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int ChangePwd (const wchar_t *lpszVolume, Password *oldPassword, int old_pkcs5, int old_pim, BOOL truecryptMode, Password *newPassword, int pkcs5, int pim, int wipePassCount, HWND hwndDlg)
|
||||
{
|
||||
int nDosLinkCreated = 1, nStatus = ERR_OS_ERROR;
|
||||
wchar_t szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
|
||||
wchar_t szDosDevice[TC_MAX_PATH];
|
||||
char buffer[TC_VOLUME_HEADER_EFFECTIVE_SIZE];
|
||||
PCRYPTO_INFO cryptoInfo = NULL, ci = NULL;
|
||||
void *dev = INVALID_HANDLE_VALUE;
|
||||
DWORD dwError;
|
||||
DWORD bytesRead;
|
||||
BOOL bDevice;
|
||||
unsigned __int64 hostSize = 0;
|
||||
int volumeType;
|
||||
int wipePass;
|
||||
FILETIME ftCreationTime;
|
||||
FILETIME ftLastWriteTime;
|
||||
FILETIME ftLastAccessTime;
|
||||
BOOL bTimeStampValid = FALSE;
|
||||
LARGE_INTEGER headerOffset;
|
||||
BOOL backupHeader;
|
||||
DISK_GEOMETRY driveInfo;
|
||||
|
||||
if (oldPassword->Length == 0 || newPassword->Length == 0) return -1;
|
||||
|
||||
if ((wipePassCount <= 0) || (truecryptMode && (old_pkcs5 == SHA256)))
|
||||
{
|
||||
nStatus = ERR_PARAMETER_INCORRECT;
|
||||
handleError (hwndDlg, nStatus, SRC_POS);
|
||||
return nStatus;
|
||||
}
|
||||
|
||||
if (!lpszVolume)
|
||||
{
|
||||
nStatus = ERR_OUTOFMEMORY;
|
||||
handleError (hwndDlg, nStatus, SRC_POS);
|
||||
return nStatus;
|
||||
}
|
||||
|
||||
WaitCursor ();
|
||||
|
||||
CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), lpszVolume, &bDevice);
|
||||
|
||||
if (bDevice == FALSE)
|
||||
{
|
||||
wcscpy (szCFDevice, szDiskFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
nDosLinkCreated = FakeDosNameForDevice (szDiskFile, szDosDevice, sizeof(szDosDevice), szCFDevice, sizeof(szCFDevice),FALSE);
|
||||
|
||||
if (nDosLinkCreated != 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
dev = CreateFile (szCFDevice, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
||||
|
||||
if (dev == INVALID_HANDLE_VALUE)
|
||||
goto error;
|
||||
|
||||
if (bDevice)
|
||||
{
|
||||
/* This is necessary to determine the hidden volume header offset */
|
||||
|
||||
if (dev == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
else
|
||||
{
|
||||
PARTITION_INFORMATION diskInfo;
|
||||
DWORD dwResult;
|
||||
BOOL bResult;
|
||||
|
||||
bResult = DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
|
||||
&driveInfo, sizeof (driveInfo), &dwResult, NULL);
|
||||
|
||||
if (!bResult)
|
||||
goto error;
|
||||
|
||||
bResult = GetPartitionInfo (lpszVolume, &diskInfo);
|
||||
|
||||
if (bResult)
|
||||
{
|
||||
hostSize = diskInfo.PartitionLength.QuadPart;
|
||||
}
|
||||
else
|
||||
{
|
||||
hostSize = driveInfo.Cylinders.QuadPart * driveInfo.BytesPerSector *
|
||||
driveInfo.SectorsPerTrack * driveInfo.TracksPerCylinder;
|
||||
}
|
||||
|
||||
if (hostSize == 0)
|
||||
{
|
||||
nStatus = ERR_VOL_SIZE_WRONG;
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LARGE_INTEGER fileSize;
|
||||
if (!GetFileSizeEx (dev, &fileSize))
|
||||
{
|
||||
nStatus = ERR_OS_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
hostSize = fileSize.QuadPart;
|
||||
}
|
||||
|
||||
if (Randinit ())
|
||||
{
|
||||
if (CryptoAPILastError == ERROR_SUCCESS)
|
||||
nStatus = ERR_RAND_INIT_FAILED;
|
||||
else
|
||||
nStatus = ERR_CAPI_INIT_FAILED;
|
||||
goto error;
|
||||
}
|
||||
|
||||
SetRandomPoolEnrichedByUserStatus (FALSE); /* force the display of the random enriching dialog */
|
||||
|
||||
if (!bDevice && bPreserveTimestamp)
|
||||
{
|
||||
if (GetFileTime ((HANDLE) dev, &ftCreationTime, &ftLastAccessTime, &ftLastWriteTime) == 0)
|
||||
bTimeStampValid = FALSE;
|
||||
else
|
||||
bTimeStampValid = TRUE;
|
||||
}
|
||||
|
||||
for (volumeType = TC_VOLUME_TYPE_NORMAL; volumeType < TC_VOLUME_TYPE_COUNT; volumeType++)
|
||||
{
|
||||
// Seek the volume header
|
||||
switch (volumeType)
|
||||
{
|
||||
case TC_VOLUME_TYPE_NORMAL:
|
||||
headerOffset.QuadPart = TC_VOLUME_HEADER_OFFSET;
|
||||
break;
|
||||
|
||||
case TC_VOLUME_TYPE_HIDDEN:
|
||||
if (TC_HIDDEN_VOLUME_HEADER_OFFSET + TC_VOLUME_HEADER_SIZE > hostSize)
|
||||
continue;
|
||||
|
||||
headerOffset.QuadPart = TC_HIDDEN_VOLUME_HEADER_OFFSET;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (!SetFilePointerEx ((HANDLE) dev, headerOffset, NULL, FILE_BEGIN))
|
||||
{
|
||||
nStatus = ERR_OS_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Read in volume header */
|
||||
if (!ReadEffectiveVolumeHeader (bDevice, dev, buffer, &bytesRead))
|
||||
{
|
||||
nStatus = ERR_OS_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (bytesRead != sizeof (buffer))
|
||||
{
|
||||
// Windows may report EOF when reading sectors from the last cluster of a device formatted as NTFS
|
||||
memset (buffer, 0, sizeof (buffer));
|
||||
}
|
||||
|
||||
/* Try to decrypt the header */
|
||||
|
||||
nStatus = ReadVolumeHeader (FALSE, buffer, oldPassword, old_pkcs5, old_pim, truecryptMode, &cryptoInfo, NULL);
|
||||
if (nStatus == ERR_CIPHER_INIT_WEAK_KEY)
|
||||
nStatus = 0; // We can ignore this error here
|
||||
|
||||
if (nStatus == ERR_PASSWORD_WRONG)
|
||||
{
|
||||
continue; // Try next volume type
|
||||
}
|
||||
else if (nStatus != 0)
|
||||
{
|
||||
cryptoInfo = NULL;
|
||||
goto error;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (nStatus != 0)
|
||||
{
|
||||
cryptoInfo = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (cryptoInfo->HeaderFlags & TC_HEADER_FLAG_ENCRYPTED_SYSTEM)
|
||||
{
|
||||
nStatus = ERR_SYS_HIDVOL_HEAD_REENC_MODE_WRONG;
|
||||
goto error;
|
||||
}
|
||||
|
||||
// Change the PKCS-5 PRF if requested by user
|
||||
if (pkcs5 != 0)
|
||||
cryptoInfo->pkcs5 = pkcs5;
|
||||
|
||||
RandSetHashFunction (cryptoInfo->pkcs5);
|
||||
|
||||
NormalCursor();
|
||||
UserEnrichRandomPool (hwndDlg);
|
||||
EnableElevatedCursorChange (hwndDlg);
|
||||
WaitCursor();
|
||||
|
||||
/* Re-encrypt the volume header */
|
||||
backupHeader = FALSE;
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
/* The header will be re-encrypted wipePassCount times to prevent adversaries from using
|
||||
techniques such as magnetic force microscopy or magnetic force scanning tunnelling microscopy
|
||||
to recover the overwritten header. According to Peter Gutmann, data should be overwritten 22
|
||||
times (ideally, 35 times) using non-random patterns and pseudorandom data. However, as users might
|
||||
impatiently interupt the process (etc.) we will not use the Gutmann's patterns but will write the
|
||||
valid re-encrypted header, i.e. pseudorandom data, and there will be many more passes than Guttman
|
||||
recommends. During each pass we will write a valid working header. Each pass will use the same master
|
||||
key, and also the same header key, secondary key (XTS), etc., derived from the new password. The only
|
||||
item that will be different for each pass will be the salt. This is sufficient to cause each "version"
|
||||
of the header to differ substantially and in a random manner from the versions written during the
|
||||
other passes. */
|
||||
|
||||
for (wipePass = 0; wipePass < wipePassCount; wipePass++)
|
||||
{
|
||||
// Prepare new volume header
|
||||
nStatus = CreateVolumeHeaderInMemory (hwndDlg, FALSE,
|
||||
buffer,
|
||||
cryptoInfo->ea,
|
||||
cryptoInfo->mode,
|
||||
newPassword,
|
||||
cryptoInfo->pkcs5,
|
||||
pim,
|
||||
cryptoInfo->master_keydata,
|
||||
&ci,
|
||||
cryptoInfo->VolumeSize.Value,
|
||||
(volumeType == TC_VOLUME_TYPE_HIDDEN) ? cryptoInfo->hiddenVolumeSize : 0,
|
||||
cryptoInfo->EncryptedAreaStart.Value,
|
||||
cryptoInfo->EncryptedAreaLength.Value,
|
||||
truecryptMode? 0 : cryptoInfo->RequiredProgramVersion,
|
||||
cryptoInfo->HeaderFlags,
|
||||
cryptoInfo->SectorSize,
|
||||
wipePass < wipePassCount - 1);
|
||||
|
||||
if (ci != NULL)
|
||||
crypto_close (ci);
|
||||
|
||||
if (nStatus != 0)
|
||||
goto error;
|
||||
|
||||
if (!SetFilePointerEx ((HANDLE) dev, headerOffset, NULL, FILE_BEGIN))
|
||||
{
|
||||
nStatus = ERR_OS_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!WriteEffectiveVolumeHeader (bDevice, dev, buffer))
|
||||
{
|
||||
nStatus = ERR_OS_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (bDevice
|
||||
&& !cryptoInfo->LegacyVolume
|
||||
&& !cryptoInfo->hiddenVolume
|
||||
&& cryptoInfo->HeaderVersion == 4
|
||||
&& (cryptoInfo->HeaderFlags & TC_HEADER_FLAG_NONSYS_INPLACE_ENC) != 0
|
||||
&& (cryptoInfo->HeaderFlags & ~TC_HEADER_FLAG_NONSYS_INPLACE_ENC) == 0)
|
||||
{
|
||||
nStatus = WriteRandomDataToReservedHeaderAreas (hwndDlg, dev, cryptoInfo, cryptoInfo->VolumeSize.Value, !backupHeader, backupHeader);
|
||||
if (nStatus != ERR_SUCCESS)
|
||||
goto error;
|
||||
}
|
||||
|
||||
FlushFileBuffers (dev);
|
||||
}
|
||||
|
||||
if (backupHeader || cryptoInfo->LegacyVolume)
|
||||
break;
|
||||
|
||||
backupHeader = TRUE;
|
||||
headerOffset.QuadPart += hostSize - TC_VOLUME_HEADER_GROUP_SIZE;
|
||||
}
|
||||
|
||||
/* Password successfully changed */
|
||||
nStatus = 0;
|
||||
|
||||
error:
|
||||
dwError = GetLastError ();
|
||||
|
||||
burn (buffer, sizeof (buffer));
|
||||
|
||||
if (cryptoInfo != NULL)
|
||||
crypto_close (cryptoInfo);
|
||||
|
||||
if (bTimeStampValid)
|
||||
SetFileTime (dev, &ftCreationTime, &ftLastAccessTime, &ftLastWriteTime);
|
||||
|
||||
if (dev != INVALID_HANDLE_VALUE)
|
||||
CloseHandle ((HANDLE) dev);
|
||||
|
||||
if (nDosLinkCreated == 0)
|
||||
RemoveFakeDosName (szDiskFile, szDosDevice);
|
||||
|
||||
RandStop (FALSE);
|
||||
NormalCursor ();
|
||||
|
||||
SetLastError (dwError);
|
||||
|
||||
if (nStatus == ERR_OS_ERROR && dwError == ERROR_ACCESS_DENIED
|
||||
&& bDevice
|
||||
&& !UacElevated
|
||||
&& IsUacSupported ())
|
||||
return nStatus;
|
||||
|
||||
if (nStatus != 0)
|
||||
handleError (hwndDlg, nStatus, SRC_POS);
|
||||
|
||||
return nStatus;
|
||||
}
|
||||
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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 "Tcdefs.h"
|
||||
|
||||
#include "Crypto.h"
|
||||
#include "Volumes.h"
|
||||
#include "Password.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Language.h"
|
||||
#include "Pkcs5.h"
|
||||
#include "Endian.h"
|
||||
#include "Random.h"
|
||||
|
||||
#include <io.h>
|
||||
|
||||
#ifndef SRC_POS
|
||||
#define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__))
|
||||
#endif
|
||||
|
||||
void VerifyPasswordAndUpdate (HWND hwndDlg, HWND hButton, HWND hPassword,
|
||||
HWND hVerify, unsigned char *szPassword,
|
||||
char *szVerify,
|
||||
BOOL keyFilesEnabled)
|
||||
{
|
||||
wchar_t szTmp1[MAX_PASSWORD + 1];
|
||||
wchar_t szTmp2[MAX_PASSWORD + 1];
|
||||
char szTmp1Utf8[MAX_PASSWORD + 1];
|
||||
char szTmp2Utf8[MAX_PASSWORD + 1];
|
||||
int k = GetWindowTextLength (hPassword);
|
||||
BOOL bEnable = FALSE;
|
||||
int utf8Len1, utf8Len2;
|
||||
|
||||
UNREFERENCED_PARAMETER (hwndDlg); /* Remove warning */
|
||||
|
||||
GetWindowText (hPassword, szTmp1, ARRAYSIZE (szTmp1));
|
||||
GetWindowText (hVerify, szTmp2, ARRAYSIZE (szTmp2));
|
||||
|
||||
utf8Len1 = WideCharToMultiByte (CP_UTF8, 0, szTmp1, -1, szTmp1Utf8, MAX_PASSWORD + 1, NULL, NULL);
|
||||
utf8Len2 = WideCharToMultiByte (CP_UTF8, 0, szTmp2, -1, szTmp2Utf8, MAX_PASSWORD + 1, NULL, NULL);
|
||||
|
||||
if (wcscmp (szTmp1, szTmp2) != 0)
|
||||
bEnable = FALSE;
|
||||
else if (utf8Len1 <= 0)
|
||||
bEnable = FALSE;
|
||||
else
|
||||
{
|
||||
if (k >= MIN_PASSWORD || keyFilesEnabled)
|
||||
bEnable = TRUE;
|
||||
else
|
||||
bEnable = FALSE;
|
||||
}
|
||||
|
||||
if (szPassword != NULL)
|
||||
{
|
||||
if (utf8Len1 > 0)
|
||||
memcpy (szPassword, szTmp1Utf8, sizeof (szTmp1Utf8));
|
||||
else
|
||||
szPassword [0] = 0;
|
||||
}
|
||||
|
||||
if (szVerify != NULL)
|
||||
{
|
||||
if (utf8Len2 > 0)
|
||||
memcpy (szVerify, szTmp2Utf8, sizeof (szTmp2Utf8));
|
||||
else
|
||||
szVerify [0] = 0;
|
||||
}
|
||||
|
||||
burn (szTmp1, sizeof (szTmp1));
|
||||
burn (szTmp2, sizeof (szTmp2));
|
||||
burn (szTmp1Utf8, sizeof (szTmp1Utf8));
|
||||
burn (szTmp2Utf8, sizeof (szTmp2Utf8));
|
||||
|
||||
EnableWindow (hButton, bEnable);
|
||||
}
|
||||
|
||||
|
||||
BOOL CheckPasswordCharEncoding (HWND hPassword, Password *ptrPw)
|
||||
{
|
||||
int i, len;
|
||||
|
||||
if (hPassword == NULL)
|
||||
{
|
||||
if (ptrPw)
|
||||
{
|
||||
unsigned char *pw;
|
||||
len = ptrPw->Length;
|
||||
pw = (unsigned char *) ptrPw->Text;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (pw[i] >= 0x7f || pw[i] < 0x20) // A non-ASCII or non-printable character?
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t s[MAX_PASSWORD + 1];
|
||||
len = GetWindowTextLength (hPassword);
|
||||
|
||||
if (len > MAX_PASSWORD)
|
||||
return FALSE;
|
||||
|
||||
GetWindowTextW (hPassword, s, sizeof (s) / sizeof (wchar_t));
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (s[i] >= 0x7f || s[i] < 0x20) // A non-ASCII or non-printable character?
|
||||
break;
|
||||
}
|
||||
|
||||
burn (s, sizeof(s));
|
||||
|
||||
if (i < len)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
BOOL CheckPasswordLength (HWND hwndDlg, unsigned __int32 passwordLength, int pim, BOOL bForBoot, BOOL bSkipPasswordWarning, BOOL bSkipPimWarning)
|
||||
{
|
||||
BOOL bCustomPimSmall = ((pim != 0) && (pim < (bForBoot? 98 : 485)))? TRUE : FALSE;
|
||||
if (passwordLength < PASSWORD_LEN_WARNING)
|
||||
{
|
||||
if (bCustomPimSmall)
|
||||
{
|
||||
Error (bForBoot? "BOOT_PIM_REQUIRE_LONG_PASSWORD": "PIM_REQUIRE_LONG_PASSWORD", hwndDlg);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifndef _DEBUG
|
||||
if (!bSkipPasswordWarning && (MessageBoxW (hwndDlg, GetString ("PASSWORD_LENGTH_WARNING"), lpszTitle, MB_YESNO|MB_ICONWARNING|MB_DEFBUTTON2) != IDYES))
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
#ifndef _DEBUG
|
||||
else if (bCustomPimSmall)
|
||||
{
|
||||
if (!bSkipPimWarning && AskWarnNoYes ("PIM_SMALL_WARNING", hwndDlg) != IDYES)
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((pim != 0) && (pim > (bForBoot? 98 : 485)))
|
||||
{
|
||||
// warn that mount/boot will take more time
|
||||
Warning ("PIM_LARGE_WARNING", hwndDlg);
|
||||
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int ChangePwd (const wchar_t *lpszVolume, Password *oldPassword, int old_pkcs5, int old_pim, BOOL truecryptMode, Password *newPassword, int pkcs5, int pim, int wipePassCount, HWND hwndDlg)
|
||||
{
|
||||
int nDosLinkCreated = 1, nStatus = ERR_OS_ERROR;
|
||||
wchar_t szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
|
||||
wchar_t szDosDevice[TC_MAX_PATH];
|
||||
char buffer[TC_VOLUME_HEADER_EFFECTIVE_SIZE];
|
||||
PCRYPTO_INFO cryptoInfo = NULL, ci = NULL;
|
||||
void *dev = INVALID_HANDLE_VALUE;
|
||||
DWORD dwError;
|
||||
DWORD bytesRead;
|
||||
BOOL bDevice;
|
||||
unsigned __int64 hostSize = 0;
|
||||
int volumeType;
|
||||
int wipePass;
|
||||
FILETIME ftCreationTime;
|
||||
FILETIME ftLastWriteTime;
|
||||
FILETIME ftLastAccessTime;
|
||||
BOOL bTimeStampValid = FALSE;
|
||||
LARGE_INTEGER headerOffset;
|
||||
BOOL backupHeader;
|
||||
DISK_GEOMETRY driveInfo;
|
||||
|
||||
if (oldPassword->Length == 0 || newPassword->Length == 0) return -1;
|
||||
|
||||
if ((wipePassCount <= 0) || (truecryptMode && (old_pkcs5 == SHA256)))
|
||||
{
|
||||
nStatus = ERR_PARAMETER_INCORRECT;
|
||||
handleError (hwndDlg, nStatus, SRC_POS);
|
||||
return nStatus;
|
||||
}
|
||||
|
||||
if (!lpszVolume)
|
||||
{
|
||||
nStatus = ERR_OUTOFMEMORY;
|
||||
handleError (hwndDlg, nStatus, SRC_POS);
|
||||
return nStatus;
|
||||
}
|
||||
|
||||
WaitCursor ();
|
||||
|
||||
CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), lpszVolume, &bDevice);
|
||||
|
||||
if (bDevice == FALSE)
|
||||
{
|
||||
wcscpy (szCFDevice, szDiskFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
nDosLinkCreated = FakeDosNameForDevice (szDiskFile, szDosDevice, sizeof(szDosDevice), szCFDevice, sizeof(szCFDevice),FALSE);
|
||||
|
||||
if (nDosLinkCreated != 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
dev = CreateFile (szCFDevice, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
||||
|
||||
if (dev == INVALID_HANDLE_VALUE)
|
||||
goto error;
|
||||
|
||||
if (bDevice)
|
||||
{
|
||||
/* This is necessary to determine the hidden volume header offset */
|
||||
|
||||
if (dev == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
else
|
||||
{
|
||||
PARTITION_INFORMATION diskInfo;
|
||||
DWORD dwResult;
|
||||
BOOL bResult;
|
||||
|
||||
bResult = DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
|
||||
&driveInfo, sizeof (driveInfo), &dwResult, NULL);
|
||||
|
||||
if (!bResult)
|
||||
goto error;
|
||||
|
||||
bResult = GetPartitionInfo (lpszVolume, &diskInfo);
|
||||
|
||||
if (bResult)
|
||||
{
|
||||
hostSize = diskInfo.PartitionLength.QuadPart;
|
||||
}
|
||||
else
|
||||
{
|
||||
hostSize = driveInfo.Cylinders.QuadPart * driveInfo.BytesPerSector *
|
||||
driveInfo.SectorsPerTrack * driveInfo.TracksPerCylinder;
|
||||
}
|
||||
|
||||
if (hostSize == 0)
|
||||
{
|
||||
nStatus = ERR_VOL_SIZE_WRONG;
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LARGE_INTEGER fileSize;
|
||||
if (!GetFileSizeEx (dev, &fileSize))
|
||||
{
|
||||
nStatus = ERR_OS_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
hostSize = fileSize.QuadPart;
|
||||
}
|
||||
|
||||
if (Randinit ())
|
||||
{
|
||||
if (CryptoAPILastError == ERROR_SUCCESS)
|
||||
nStatus = ERR_RAND_INIT_FAILED;
|
||||
else
|
||||
nStatus = ERR_CAPI_INIT_FAILED;
|
||||
goto error;
|
||||
}
|
||||
|
||||
SetRandomPoolEnrichedByUserStatus (FALSE); /* force the display of the random enriching dialog */
|
||||
|
||||
if (!bDevice && bPreserveTimestamp)
|
||||
{
|
||||
if (GetFileTime ((HANDLE) dev, &ftCreationTime, &ftLastAccessTime, &ftLastWriteTime) == 0)
|
||||
bTimeStampValid = FALSE;
|
||||
else
|
||||
bTimeStampValid = TRUE;
|
||||
}
|
||||
|
||||
for (volumeType = TC_VOLUME_TYPE_NORMAL; volumeType < TC_VOLUME_TYPE_COUNT; volumeType++)
|
||||
{
|
||||
// Seek the volume header
|
||||
switch (volumeType)
|
||||
{
|
||||
case TC_VOLUME_TYPE_NORMAL:
|
||||
headerOffset.QuadPart = TC_VOLUME_HEADER_OFFSET;
|
||||
break;
|
||||
|
||||
case TC_VOLUME_TYPE_HIDDEN:
|
||||
if (TC_HIDDEN_VOLUME_HEADER_OFFSET + TC_VOLUME_HEADER_SIZE > hostSize)
|
||||
continue;
|
||||
|
||||
headerOffset.QuadPart = TC_HIDDEN_VOLUME_HEADER_OFFSET;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (!SetFilePointerEx ((HANDLE) dev, headerOffset, NULL, FILE_BEGIN))
|
||||
{
|
||||
nStatus = ERR_OS_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Read in volume header */
|
||||
if (!ReadEffectiveVolumeHeader (bDevice, dev, buffer, &bytesRead))
|
||||
{
|
||||
nStatus = ERR_OS_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (bytesRead != sizeof (buffer))
|
||||
{
|
||||
// Windows may report EOF when reading sectors from the last cluster of a device formatted as NTFS
|
||||
memset (buffer, 0, sizeof (buffer));
|
||||
}
|
||||
|
||||
/* Try to decrypt the header */
|
||||
|
||||
nStatus = ReadVolumeHeader (FALSE, buffer, oldPassword, old_pkcs5, old_pim, truecryptMode, &cryptoInfo, NULL);
|
||||
if (nStatus == ERR_CIPHER_INIT_WEAK_KEY)
|
||||
nStatus = 0; // We can ignore this error here
|
||||
|
||||
if (nStatus == ERR_PASSWORD_WRONG)
|
||||
{
|
||||
continue; // Try next volume type
|
||||
}
|
||||
else if (nStatus != 0)
|
||||
{
|
||||
cryptoInfo = NULL;
|
||||
goto error;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (nStatus != 0)
|
||||
{
|
||||
cryptoInfo = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (cryptoInfo->HeaderFlags & TC_HEADER_FLAG_ENCRYPTED_SYSTEM)
|
||||
{
|
||||
nStatus = ERR_SYS_HIDVOL_HEAD_REENC_MODE_WRONG;
|
||||
goto error;
|
||||
}
|
||||
|
||||
// Change the PKCS-5 PRF if requested by user
|
||||
if (pkcs5 != 0)
|
||||
cryptoInfo->pkcs5 = pkcs5;
|
||||
|
||||
RandSetHashFunction (cryptoInfo->pkcs5);
|
||||
|
||||
NormalCursor();
|
||||
UserEnrichRandomPool (hwndDlg);
|
||||
EnableElevatedCursorChange (hwndDlg);
|
||||
WaitCursor();
|
||||
|
||||
/* Re-encrypt the volume header */
|
||||
backupHeader = FALSE;
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
/* The header will be re-encrypted wipePassCount times to prevent adversaries from using
|
||||
techniques such as magnetic force microscopy or magnetic force scanning tunnelling microscopy
|
||||
to recover the overwritten header. According to Peter Gutmann, data should be overwritten 22
|
||||
times (ideally, 35 times) using non-random patterns and pseudorandom data. However, as users might
|
||||
impatiently interupt the process (etc.) we will not use the Gutmann's patterns but will write the
|
||||
valid re-encrypted header, i.e. pseudorandom data, and there will be many more passes than Guttman
|
||||
recommends. During each pass we will write a valid working header. Each pass will use the same master
|
||||
key, and also the same header key, secondary key (XTS), etc., derived from the new password. The only
|
||||
item that will be different for each pass will be the salt. This is sufficient to cause each "version"
|
||||
of the header to differ substantially and in a random manner from the versions written during the
|
||||
other passes. */
|
||||
|
||||
for (wipePass = 0; wipePass < wipePassCount; wipePass++)
|
||||
{
|
||||
// Prepare new volume header
|
||||
nStatus = CreateVolumeHeaderInMemory (hwndDlg, FALSE,
|
||||
buffer,
|
||||
cryptoInfo->ea,
|
||||
cryptoInfo->mode,
|
||||
newPassword,
|
||||
cryptoInfo->pkcs5,
|
||||
pim,
|
||||
cryptoInfo->master_keydata,
|
||||
&ci,
|
||||
cryptoInfo->VolumeSize.Value,
|
||||
(volumeType == TC_VOLUME_TYPE_HIDDEN) ? cryptoInfo->hiddenVolumeSize : 0,
|
||||
cryptoInfo->EncryptedAreaStart.Value,
|
||||
cryptoInfo->EncryptedAreaLength.Value,
|
||||
truecryptMode? 0 : cryptoInfo->RequiredProgramVersion,
|
||||
cryptoInfo->HeaderFlags,
|
||||
cryptoInfo->SectorSize,
|
||||
wipePass < wipePassCount - 1);
|
||||
|
||||
if (ci != NULL)
|
||||
crypto_close (ci);
|
||||
|
||||
if (nStatus != 0)
|
||||
goto error;
|
||||
|
||||
if (!SetFilePointerEx ((HANDLE) dev, headerOffset, NULL, FILE_BEGIN))
|
||||
{
|
||||
nStatus = ERR_OS_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!WriteEffectiveVolumeHeader (bDevice, dev, buffer))
|
||||
{
|
||||
nStatus = ERR_OS_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (bDevice
|
||||
&& !cryptoInfo->LegacyVolume
|
||||
&& !cryptoInfo->hiddenVolume
|
||||
&& cryptoInfo->HeaderVersion == 4
|
||||
&& (cryptoInfo->HeaderFlags & TC_HEADER_FLAG_NONSYS_INPLACE_ENC) != 0
|
||||
&& (cryptoInfo->HeaderFlags & ~TC_HEADER_FLAG_NONSYS_INPLACE_ENC) == 0)
|
||||
{
|
||||
nStatus = WriteRandomDataToReservedHeaderAreas (hwndDlg, dev, cryptoInfo, cryptoInfo->VolumeSize.Value, !backupHeader, backupHeader);
|
||||
if (nStatus != ERR_SUCCESS)
|
||||
goto error;
|
||||
}
|
||||
|
||||
FlushFileBuffers (dev);
|
||||
}
|
||||
|
||||
if (backupHeader || cryptoInfo->LegacyVolume)
|
||||
break;
|
||||
|
||||
backupHeader = TRUE;
|
||||
headerOffset.QuadPart += hostSize - TC_VOLUME_HEADER_GROUP_SIZE;
|
||||
}
|
||||
|
||||
/* Password successfully changed */
|
||||
nStatus = 0;
|
||||
|
||||
error:
|
||||
dwError = GetLastError ();
|
||||
|
||||
burn (buffer, sizeof (buffer));
|
||||
|
||||
if (cryptoInfo != NULL)
|
||||
crypto_close (cryptoInfo);
|
||||
|
||||
if (bTimeStampValid)
|
||||
SetFileTime (dev, &ftCreationTime, &ftLastAccessTime, &ftLastWriteTime);
|
||||
|
||||
if (dev != INVALID_HANDLE_VALUE)
|
||||
CloseHandle ((HANDLE) dev);
|
||||
|
||||
if (nDosLinkCreated == 0)
|
||||
RemoveFakeDosName (szDiskFile, szDosDevice);
|
||||
|
||||
RandStop (FALSE);
|
||||
NormalCursor ();
|
||||
|
||||
SetLastError (dwError);
|
||||
|
||||
if (nStatus == ERR_OS_ERROR && dwError == ERROR_ACCESS_DENIED
|
||||
&& bDevice
|
||||
&& !UacElevated
|
||||
&& IsUacSupported ())
|
||||
return nStatus;
|
||||
|
||||
if (nStatus != 0)
|
||||
handleError (hwndDlg, nStatus, SRC_POS);
|
||||
|
||||
return nStatus;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,52 +1,52 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#ifndef PASSWORD_H
|
||||
#define PASSWORD_H
|
||||
|
||||
// User text input limits
|
||||
#define MIN_PASSWORD 1 // Minimum possible password length
|
||||
#define MAX_PASSWORD 64 // Maximum possible password length
|
||||
#define MAX_PIM 7 // Maximum allowed digits in a PIM (enough for maximum value)
|
||||
#define MAX_PIM_VALUE 2147468 // Maximum value to have a positive 32-bit result for formula 15000 + (PIM x 1000)
|
||||
#define MAX_BOOT_PIM 5 // Maximum allowed digits in a PIM for boot (enough for 16-bit value)
|
||||
#define MAX_BOOT_PIM_VALUE 65535
|
||||
|
||||
#define PASSWORD_LEN_WARNING 20 // Display a warning when a password is shorter than this
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// Modifying this structure can introduce incompatibility with previous versions
|
||||
unsigned __int32 Length;
|
||||
unsigned char Text[MAX_PASSWORD + 1];
|
||||
char Pad[3]; // keep 64-bit alignment
|
||||
} Password;
|
||||
|
||||
#if defined(_WIN32) && !defined(TC_WINDOWS_DRIVER)
|
||||
|
||||
void VerifyPasswordAndUpdate ( HWND hwndDlg , HWND hButton , HWND hPassword , HWND hVerify , unsigned char *szPassword , char *szVerify, BOOL keyFilesEnabled );
|
||||
BOOL CheckPasswordLength (HWND hwndDlg, unsigned __int32 passwordLength, int pim, BOOL bForBoot, BOOL bSkipPasswordWarning, BOOL bSkipPimWarning);
|
||||
BOOL CheckPasswordCharEncoding (HWND hPassword, Password *ptrPw);
|
||||
int ChangePwd (const wchar_t *lpszVolume, Password *oldPassword, int old_pkcs5, int old_pim, BOOL truecryptMode, Password *newPassword, int pkcs5, int pim, int wipePassCount, HWND hwndDlg);
|
||||
|
||||
#endif // defined(_WIN32) && !defined(TC_WINDOWS_DRIVER)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // PASSWORD_H
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#ifndef PASSWORD_H
|
||||
#define PASSWORD_H
|
||||
|
||||
// User text input limits
|
||||
#define MIN_PASSWORD 1 // Minimum possible password length
|
||||
#define MAX_PASSWORD 64 // Maximum possible password length
|
||||
#define MAX_PIM 7 // Maximum allowed digits in a PIM (enough for maximum value)
|
||||
#define MAX_PIM_VALUE 2147468 // Maximum value to have a positive 32-bit result for formula 15000 + (PIM x 1000)
|
||||
#define MAX_BOOT_PIM 5 // Maximum allowed digits in a PIM for boot (enough for 16-bit value)
|
||||
#define MAX_BOOT_PIM_VALUE 65535
|
||||
|
||||
#define PASSWORD_LEN_WARNING 20 // Display a warning when a password is shorter than this
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// Modifying this structure can introduce incompatibility with previous versions
|
||||
unsigned __int32 Length;
|
||||
unsigned char Text[MAX_PASSWORD + 1];
|
||||
char Pad[3]; // keep 64-bit alignment
|
||||
} Password;
|
||||
|
||||
#if defined(_WIN32) && !defined(TC_WINDOWS_DRIVER)
|
||||
|
||||
void VerifyPasswordAndUpdate ( HWND hwndDlg , HWND hButton , HWND hPassword , HWND hVerify , unsigned char *szPassword , char *szVerify, BOOL keyFilesEnabled );
|
||||
BOOL CheckPasswordLength (HWND hwndDlg, unsigned __int32 passwordLength, int pim, BOOL bForBoot, BOOL bSkipPasswordWarning, BOOL bSkipPimWarning);
|
||||
BOOL CheckPasswordCharEncoding (HWND hPassword, Password *ptrPw);
|
||||
int ChangePwd (const wchar_t *lpszVolume, Password *oldPassword, int old_pkcs5, int old_pim, BOOL truecryptMode, Password *newPassword, int pkcs5, int pim, int wipePassCount, HWND hwndDlg);
|
||||
|
||||
#endif // defined(_WIN32) && !defined(TC_WINDOWS_DRIVER)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // PASSWORD_H
|
||||
|
||||
1918
src/Common/Pkcs5.c
1918
src/Common/Pkcs5.c
File diff suppressed because it is too large
Load Diff
@@ -1,48 +1,48 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#ifndef TC_HEADER_PKCS5
|
||||
#define TC_HEADER_PKCS5
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
/* output written to input_digest which must be at lease 20 bytes long */
|
||||
void hmac_ripemd160 (char *key, int keylen, char *input_digest, int len);
|
||||
void derive_key_ripemd160 (char *pwd, int pwd_len, char *salt, int salt_len, uint32 iterations, char *dk, int dklen);
|
||||
|
||||
/* output written to d which must be at lease 32 bytes long */
|
||||
void hmac_sha256 (char *k, int lk, char *d, int ld);
|
||||
void derive_key_sha256 (char *pwd, int pwd_len, char *salt, int salt_len, uint32 iterations, char *dk, int dklen);
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
/* output written to d which must be at lease 64 bytes long */
|
||||
void hmac_sha512 (char *k, int lk, char *d, int ld);
|
||||
void derive_key_sha512 (char *pwd, int pwd_len, char *salt, int salt_len, uint32 iterations, char *dk, int dklen);
|
||||
|
||||
/* output written to d which must be at lease 64 bytes long */
|
||||
void hmac_whirlpool (char *k, int lk, char *d, int ld);
|
||||
void derive_key_whirlpool (char *pwd, int pwd_len, char *salt, int salt_len, uint32 iterations, char *dk, int dklen);
|
||||
|
||||
int get_pkcs5_iteration_count (int pkcs5_prf_id, int pim, BOOL truecryptMode, BOOL bBoot);
|
||||
wchar_t *get_pkcs5_prf_name (int pkcs5_prf_id);
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_PKCS5
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#ifndef TC_HEADER_PKCS5
|
||||
#define TC_HEADER_PKCS5
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
/* output written to input_digest which must be at lease 20 bytes long */
|
||||
void hmac_ripemd160 (char *key, int keylen, char *input_digest, int len);
|
||||
void derive_key_ripemd160 (char *pwd, int pwd_len, char *salt, int salt_len, uint32 iterations, char *dk, int dklen);
|
||||
|
||||
/* output written to d which must be at lease 32 bytes long */
|
||||
void hmac_sha256 (char *k, int lk, char *d, int ld);
|
||||
void derive_key_sha256 (char *pwd, int pwd_len, char *salt, int salt_len, uint32 iterations, char *dk, int dklen);
|
||||
|
||||
#ifndef TC_WINDOWS_BOOT
|
||||
/* output written to d which must be at lease 64 bytes long */
|
||||
void hmac_sha512 (char *k, int lk, char *d, int ld);
|
||||
void derive_key_sha512 (char *pwd, int pwd_len, char *salt, int salt_len, uint32 iterations, char *dk, int dklen);
|
||||
|
||||
/* output written to d which must be at lease 64 bytes long */
|
||||
void hmac_whirlpool (char *k, int lk, char *d, int ld);
|
||||
void derive_key_whirlpool (char *pwd, int pwd_len, char *salt, int salt_len, uint32 iterations, char *dk, int dklen);
|
||||
|
||||
int get_pkcs5_iteration_count (int pkcs5_prf_id, int pim, BOOL truecryptMode, BOOL bBoot);
|
||||
wchar_t *get_pkcs5_prf_name (int pkcs5_prf_id);
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_PKCS5
|
||||
|
||||
@@ -1,134 +1,134 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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 "Tcdefs.h"
|
||||
#include "Language.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Progress.h"
|
||||
#include "../Format/Tcformat.h"
|
||||
#include "../Format/FormatCom.h"
|
||||
#include "../Format/resource.h"
|
||||
|
||||
#include <Strsafe.h>
|
||||
|
||||
static ULONG prevTime, startTime;
|
||||
static __int64 TotalSize;
|
||||
static __int64 resumedPointBytesDone;
|
||||
static BOOL bProgressBarReverse = FALSE;
|
||||
static BOOL bRWThroughput = FALSE;
|
||||
static BOOL bShowStatus = FALSE;
|
||||
static BOOL bPercentMode = FALSE;
|
||||
|
||||
static wchar_t *seconds, *minutes, *hours, *days;
|
||||
|
||||
|
||||
// If bIOThroughput is TRUE, the speed reflects the amount of data read AND written per second (rather than
|
||||
// the speed of the "transform cursor").
|
||||
void InitProgressBar (__int64 totalBytes, __int64 bytesDone, BOOL bReverse, BOOL bIOThroughput, BOOL bDisplayStatus, BOOL bShowPercent)
|
||||
{
|
||||
HWND hProgressBar = GetDlgItem (hCurPage, nPbar);
|
||||
SendMessage (hProgressBar, PBM_SETRANGE32, 0, 10000);
|
||||
SendMessage (hProgressBar, PBM_SETSTEP, 1, 0);
|
||||
|
||||
bProgressBarReverse = bReverse;
|
||||
bRWThroughput = bIOThroughput;
|
||||
bShowStatus = bDisplayStatus;
|
||||
bPercentMode = bShowPercent;
|
||||
|
||||
seconds = GetString ("SECONDS");
|
||||
minutes = GetString ("MINUTES");
|
||||
hours = GetString ("HOURS");
|
||||
days = GetString ("DAYS");
|
||||
|
||||
prevTime = startTime = GetTickCount ();
|
||||
TotalSize = totalBytes;
|
||||
resumedPointBytesDone = bytesDone;
|
||||
}
|
||||
|
||||
|
||||
BOOL UpdateProgressBar (__int64 byteOffset)
|
||||
{
|
||||
return UpdateProgressBarProc (byteOffset);
|
||||
}
|
||||
|
||||
|
||||
BOOL UpdateProgressBarProc (__int64 byteOffset)
|
||||
{
|
||||
wchar_t text[100];
|
||||
wchar_t speed[100];
|
||||
HWND hProgressBar = GetDlgItem (hCurPage, nPbar);
|
||||
int time = GetTickCount ();
|
||||
int elapsed = (time - startTime) / 1000;
|
||||
|
||||
uint64 bytesDone = (bProgressBarReverse ? (TotalSize - byteOffset) : byteOffset);
|
||||
uint64 bytesPerSec = (bProgressBarReverse ? (resumedPointBytesDone - byteOffset) : (bytesDone - resumedPointBytesDone)) / (elapsed + 1);
|
||||
|
||||
if (bPercentMode)
|
||||
{
|
||||
double perc = (double) (100.0 * (bProgressBarReverse ? ((double) (TotalSize - byteOffset)) : ((double) byteOffset)) / (TotalSize == 0 ? 0.0001 : ((double) TotalSize)));
|
||||
|
||||
if (perc > 99.999999999)
|
||||
StringCchCopyW (text,ARRAYSIZE(text), GetString ("PROCESSED_PORTION_100_PERCENT"));
|
||||
else
|
||||
StringCchPrintfW (text, ARRAYSIZE (text), GetString ("PROCESSED_PORTION_X_PERCENT"), perc);
|
||||
|
||||
StringCchCatW (text, ARRAYSIZE(text), L" ");
|
||||
}
|
||||
else
|
||||
{
|
||||
GetSizeString (bytesDone, text, sizeof(text));
|
||||
if (bytesDone < (unsigned __int64) BYTES_PER_MB * 1000000)
|
||||
StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_MB, GetString ("MB"));
|
||||
else if (bytesDone < (unsigned __int64) BYTES_PER_GB * 1000000)
|
||||
StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_GB, GetString ("GB"));
|
||||
else if (bytesDone < (unsigned __int64) BYTES_PER_TB * 1000000)
|
||||
StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_TB, GetString ("TB"));
|
||||
else
|
||||
StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_PB, GetString ("PB"));
|
||||
}
|
||||
|
||||
SetWindowTextW (GetDlgItem (hCurPage, IDC_BYTESWRITTEN), text);
|
||||
|
||||
if (!bShowStatus)
|
||||
{
|
||||
GetSpeedString (bRWThroughput ? bytesPerSec*2 : bytesPerSec, speed, sizeof(speed));
|
||||
StringCchCatW (speed, ARRAYSIZE(speed), L" ");
|
||||
SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), speed);
|
||||
}
|
||||
|
||||
if (byteOffset < TotalSize)
|
||||
{
|
||||
int64 sec = (int64) ((bProgressBarReverse ? byteOffset : (TotalSize - byteOffset)) / (bytesPerSec == 0 ? 0.001 : bytesPerSec));
|
||||
|
||||
if (bytesPerSec == 0 || sec > 60 * 60 * 24 * 999)
|
||||
StringCchPrintfW (text, ARRAYSIZE(text), L"%s ", GetString ("NOT_APPLICABLE_OR_NOT_AVAILABLE"));
|
||||
else if (sec >= 60 * 60 * 24 * 2)
|
||||
StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec / (60 * 24 * 60), days);
|
||||
else if (sec >= 120 * 60)
|
||||
StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec / (60 * 60), hours);
|
||||
else if (sec >= 120)
|
||||
StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec / 60, minutes);
|
||||
else
|
||||
StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec, seconds);
|
||||
|
||||
SetWindowTextW (GetDlgItem (hCurPage, IDC_TIMEREMAIN), text);
|
||||
}
|
||||
|
||||
prevTime = time;
|
||||
|
||||
SendMessage (hProgressBar, PBM_SETPOS,
|
||||
(int) (10000.0 * (bProgressBarReverse ? (TotalSize - byteOffset) : byteOffset) / (TotalSize == 0 ? 1 : TotalSize)),
|
||||
0);
|
||||
|
||||
return bVolTransformThreadCancel;
|
||||
}
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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 "Tcdefs.h"
|
||||
#include "Language.h"
|
||||
#include "Dlgcode.h"
|
||||
#include "Progress.h"
|
||||
#include "../Format/Tcformat.h"
|
||||
#include "../Format/FormatCom.h"
|
||||
#include "../Format/resource.h"
|
||||
|
||||
#include <Strsafe.h>
|
||||
|
||||
static ULONG prevTime, startTime;
|
||||
static __int64 TotalSize;
|
||||
static __int64 resumedPointBytesDone;
|
||||
static BOOL bProgressBarReverse = FALSE;
|
||||
static BOOL bRWThroughput = FALSE;
|
||||
static BOOL bShowStatus = FALSE;
|
||||
static BOOL bPercentMode = FALSE;
|
||||
|
||||
static wchar_t *seconds, *minutes, *hours, *days;
|
||||
|
||||
|
||||
// If bIOThroughput is TRUE, the speed reflects the amount of data read AND written per second (rather than
|
||||
// the speed of the "transform cursor").
|
||||
void InitProgressBar (__int64 totalBytes, __int64 bytesDone, BOOL bReverse, BOOL bIOThroughput, BOOL bDisplayStatus, BOOL bShowPercent)
|
||||
{
|
||||
HWND hProgressBar = GetDlgItem (hCurPage, nPbar);
|
||||
SendMessage (hProgressBar, PBM_SETRANGE32, 0, 10000);
|
||||
SendMessage (hProgressBar, PBM_SETSTEP, 1, 0);
|
||||
|
||||
bProgressBarReverse = bReverse;
|
||||
bRWThroughput = bIOThroughput;
|
||||
bShowStatus = bDisplayStatus;
|
||||
bPercentMode = bShowPercent;
|
||||
|
||||
seconds = GetString ("SECONDS");
|
||||
minutes = GetString ("MINUTES");
|
||||
hours = GetString ("HOURS");
|
||||
days = GetString ("DAYS");
|
||||
|
||||
prevTime = startTime = GetTickCount ();
|
||||
TotalSize = totalBytes;
|
||||
resumedPointBytesDone = bytesDone;
|
||||
}
|
||||
|
||||
|
||||
BOOL UpdateProgressBar (__int64 byteOffset)
|
||||
{
|
||||
return UpdateProgressBarProc (byteOffset);
|
||||
}
|
||||
|
||||
|
||||
BOOL UpdateProgressBarProc (__int64 byteOffset)
|
||||
{
|
||||
wchar_t text[100];
|
||||
wchar_t speed[100];
|
||||
HWND hProgressBar = GetDlgItem (hCurPage, nPbar);
|
||||
int time = GetTickCount ();
|
||||
int elapsed = (time - startTime) / 1000;
|
||||
|
||||
uint64 bytesDone = (bProgressBarReverse ? (TotalSize - byteOffset) : byteOffset);
|
||||
uint64 bytesPerSec = (bProgressBarReverse ? (resumedPointBytesDone - byteOffset) : (bytesDone - resumedPointBytesDone)) / (elapsed + 1);
|
||||
|
||||
if (bPercentMode)
|
||||
{
|
||||
double perc = (double) (100.0 * (bProgressBarReverse ? ((double) (TotalSize - byteOffset)) : ((double) byteOffset)) / (TotalSize == 0 ? 0.0001 : ((double) TotalSize)));
|
||||
|
||||
if (perc > 99.999999999)
|
||||
StringCchCopyW (text,ARRAYSIZE(text), GetString ("PROCESSED_PORTION_100_PERCENT"));
|
||||
else
|
||||
StringCchPrintfW (text, ARRAYSIZE (text), GetString ("PROCESSED_PORTION_X_PERCENT"), perc);
|
||||
|
||||
StringCchCatW (text, ARRAYSIZE(text), L" ");
|
||||
}
|
||||
else
|
||||
{
|
||||
GetSizeString (bytesDone, text, sizeof(text));
|
||||
if (bytesDone < (unsigned __int64) BYTES_PER_MB * 1000000)
|
||||
StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_MB, GetString ("MB"));
|
||||
else if (bytesDone < (unsigned __int64) BYTES_PER_GB * 1000000)
|
||||
StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_GB, GetString ("GB"));
|
||||
else if (bytesDone < (unsigned __int64) BYTES_PER_TB * 1000000)
|
||||
StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_TB, GetString ("TB"));
|
||||
else
|
||||
StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_PB, GetString ("PB"));
|
||||
}
|
||||
|
||||
SetWindowTextW (GetDlgItem (hCurPage, IDC_BYTESWRITTEN), text);
|
||||
|
||||
if (!bShowStatus)
|
||||
{
|
||||
GetSpeedString (bRWThroughput ? bytesPerSec*2 : bytesPerSec, speed, sizeof(speed));
|
||||
StringCchCatW (speed, ARRAYSIZE(speed), L" ");
|
||||
SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), speed);
|
||||
}
|
||||
|
||||
if (byteOffset < TotalSize)
|
||||
{
|
||||
int64 sec = (int64) ((bProgressBarReverse ? byteOffset : (TotalSize - byteOffset)) / (bytesPerSec == 0 ? 0.001 : bytesPerSec));
|
||||
|
||||
if (bytesPerSec == 0 || sec > 60 * 60 * 24 * 999)
|
||||
StringCchPrintfW (text, ARRAYSIZE(text), L"%s ", GetString ("NOT_APPLICABLE_OR_NOT_AVAILABLE"));
|
||||
else if (sec >= 60 * 60 * 24 * 2)
|
||||
StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec / (60 * 24 * 60), days);
|
||||
else if (sec >= 120 * 60)
|
||||
StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec / (60 * 60), hours);
|
||||
else if (sec >= 120)
|
||||
StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec / 60, minutes);
|
||||
else
|
||||
StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec, seconds);
|
||||
|
||||
SetWindowTextW (GetDlgItem (hCurPage, IDC_TIMEREMAIN), text);
|
||||
}
|
||||
|
||||
prevTime = time;
|
||||
|
||||
SendMessage (hProgressBar, PBM_SETPOS,
|
||||
(int) (10000.0 * (bProgressBarReverse ? (TotalSize - byteOffset) : byteOffset) / (TotalSize == 0 ? 1 : TotalSize)),
|
||||
0);
|
||||
|
||||
return bVolTransformThreadCancel;
|
||||
}
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef PBM_SETSTATE
|
||||
|
||||
#define PBM_SETSTATE (WM_USER+16) // wParam = PBST_[State] (NORMAL, ERROR, PAUSED)
|
||||
#define PBST_NORMAL 0x0001
|
||||
#define PBST_ERROR 0x0002
|
||||
#define PBST_PAUSED 0x0003
|
||||
|
||||
#endif
|
||||
|
||||
void InitProgressBar (__int64 totalBytes, __int64 bytesDone, BOOL bReverse, BOOL bIOThroughput, BOOL bDisplayStatus, BOOL bShowPercent);
|
||||
BOOL UpdateProgressBar (__int64 byteOffset);
|
||||
BOOL UpdateProgressBarProc (__int64 byteOffset);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef PBM_SETSTATE
|
||||
|
||||
#define PBM_SETSTATE (WM_USER+16) // wParam = PBST_[State] (NORMAL, ERROR, PAUSED)
|
||||
#define PBST_NORMAL 0x0001
|
||||
#define PBST_ERROR 0x0002
|
||||
#define PBST_PAUSED 0x0003
|
||||
|
||||
#endif
|
||||
|
||||
void InitProgressBar (__int64 totalBytes, __int64 bytesDone, BOOL bReverse, BOOL bIOThroughput, BOOL bDisplayStatus, BOOL bShowPercent);
|
||||
BOOL UpdateProgressBar (__int64 byteOffset);
|
||||
BOOL UpdateProgressBarProc (__int64 byteOffset);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
1796
src/Common/Random.c
1796
src/Common/Random.c
File diff suppressed because it is too large
Load Diff
@@ -1,76 +1,76 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* RNG defines & pool pointers */
|
||||
#define RNG_POOL_SIZE 320 // Must be divisible by the size of the output of each of the implemented hash functions. (in bytes)
|
||||
|
||||
#if RNG_POOL_SIZE % SHA512_DIGESTSIZE || RNG_POOL_SIZE % WHIRLPOOL_DIGESTSIZE || RNG_POOL_SIZE % RIPEMD160_DIGESTSIZE
|
||||
#error RNG_POOL_SIZE must be divisible by the size of the output of each of the implemented hash functions.
|
||||
#endif
|
||||
|
||||
#define RANDOMPOOL_ALLOCSIZE RNG_POOL_SIZE
|
||||
|
||||
// After every RANDMIX_BYTE_INTERVAL-th byte written to the pool, the pool mixing function is applied to the entire pool
|
||||
#define RANDMIX_BYTE_INTERVAL 16
|
||||
|
||||
// FastPoll interval (in milliseconds)
|
||||
#define FASTPOLL_INTERVAL 500
|
||||
|
||||
void RandAddInt ( unsigned __int32 x );
|
||||
int Randinit ( void );
|
||||
void RandStop (BOOL freePool);
|
||||
BOOL IsRandomNumberGeneratorStarted ();
|
||||
void RandSetHashFunction ( int hash_algo_id );
|
||||
int RandGetHashFunction (void);
|
||||
void SetRandomPoolEnrichedByUserStatus (BOOL enriched);
|
||||
BOOL IsRandomPoolEnrichedByUser ();
|
||||
BOOL Randmix ( void );
|
||||
void RandaddBuf ( void *buf , int len );
|
||||
BOOL FastPoll ( void );
|
||||
BOOL SlowPoll ( void );
|
||||
|
||||
/* Get len random bytes from the pool (max. RNG_POOL_SIZE bytes per a single call) */
|
||||
BOOL RandgetBytes ( void* hwndDlg, unsigned char *buf , int len, BOOL forceSlowPoll );
|
||||
|
||||
/* Get len random bytes from the pool.
|
||||
* If allowAnyLength is FALSE, then len must be less or equal to RNG_POOL_SIZE
|
||||
* If allowAnyLength is TRUE, then len can have any positive value
|
||||
*/
|
||||
BOOL RandgetBytesFull ( void* hwndDlg, unsigned char *buf , int len, BOOL forceSlowPoll , BOOL allowAnyLength);
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
extern BOOL volatile bFastPollEnabled;
|
||||
extern BOOL volatile bRandmixEnabled;
|
||||
extern DWORD CryptoAPILastError;
|
||||
extern DWORD ProcessedMouseEventsCounter;
|
||||
|
||||
BOOL RandpeekBytes ( void* hwndDlg, unsigned char *buf , int len, DWORD* mouseCounter );
|
||||
void RandAddInt64 ( unsigned __int64 x );
|
||||
|
||||
LRESULT CALLBACK MouseProc ( int nCode , WPARAM wParam , LPARAM lParam );
|
||||
LRESULT CALLBACK KeyboardProc ( int nCode , WPARAM wParam , LPARAM lParam );
|
||||
static unsigned __stdcall PeriodicFastPollThreadProc (void *dummy);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* RNG defines & pool pointers */
|
||||
#define RNG_POOL_SIZE 320 // Must be divisible by the size of the output of each of the implemented hash functions. (in bytes)
|
||||
|
||||
#if RNG_POOL_SIZE % SHA512_DIGESTSIZE || RNG_POOL_SIZE % WHIRLPOOL_DIGESTSIZE || RNG_POOL_SIZE % RIPEMD160_DIGESTSIZE
|
||||
#error RNG_POOL_SIZE must be divisible by the size of the output of each of the implemented hash functions.
|
||||
#endif
|
||||
|
||||
#define RANDOMPOOL_ALLOCSIZE RNG_POOL_SIZE
|
||||
|
||||
// After every RANDMIX_BYTE_INTERVAL-th byte written to the pool, the pool mixing function is applied to the entire pool
|
||||
#define RANDMIX_BYTE_INTERVAL 16
|
||||
|
||||
// FastPoll interval (in milliseconds)
|
||||
#define FASTPOLL_INTERVAL 500
|
||||
|
||||
void RandAddInt ( unsigned __int32 x );
|
||||
int Randinit ( void );
|
||||
void RandStop (BOOL freePool);
|
||||
BOOL IsRandomNumberGeneratorStarted ();
|
||||
void RandSetHashFunction ( int hash_algo_id );
|
||||
int RandGetHashFunction (void);
|
||||
void SetRandomPoolEnrichedByUserStatus (BOOL enriched);
|
||||
BOOL IsRandomPoolEnrichedByUser ();
|
||||
BOOL Randmix ( void );
|
||||
void RandaddBuf ( void *buf , int len );
|
||||
BOOL FastPoll ( void );
|
||||
BOOL SlowPoll ( void );
|
||||
|
||||
/* Get len random bytes from the pool (max. RNG_POOL_SIZE bytes per a single call) */
|
||||
BOOL RandgetBytes ( void* hwndDlg, unsigned char *buf , int len, BOOL forceSlowPoll );
|
||||
|
||||
/* Get len random bytes from the pool.
|
||||
* If allowAnyLength is FALSE, then len must be less or equal to RNG_POOL_SIZE
|
||||
* If allowAnyLength is TRUE, then len can have any positive value
|
||||
*/
|
||||
BOOL RandgetBytesFull ( void* hwndDlg, unsigned char *buf , int len, BOOL forceSlowPoll , BOOL allowAnyLength);
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
extern BOOL volatile bFastPollEnabled;
|
||||
extern BOOL volatile bRandmixEnabled;
|
||||
extern DWORD CryptoAPILastError;
|
||||
extern DWORD ProcessedMouseEventsCounter;
|
||||
|
||||
BOOL RandpeekBytes ( void* hwndDlg, unsigned char *buf , int len, DWORD* mouseCounter );
|
||||
void RandAddInt64 ( unsigned __int64 x );
|
||||
|
||||
LRESULT CALLBACK MouseProc ( int nCode , WPARAM wParam , LPARAM lParam );
|
||||
LRESULT CALLBACK KeyboardProc ( int nCode , WPARAM wParam , LPARAM lParam );
|
||||
static unsigned __stdcall PeriodicFastPollThreadProc (void *dummy);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,300 +1,300 @@
|
||||
/*
|
||||
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 "Tcdefs.h"
|
||||
#include "Registry.h"
|
||||
#include <Strsafe.h>
|
||||
|
||||
BOOL ReadLocalMachineRegistryDword (wchar_t *subKey, wchar_t *name, DWORD *value)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD size = sizeof (*value);
|
||||
DWORD type;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
if (RegQueryValueEx (hkey, name, NULL, &type, (BYTE *) value, &size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return type == REG_DWORD;
|
||||
}
|
||||
|
||||
BOOL ReadLocalMachineRegistryMultiString (wchar_t *subKey, wchar_t *name, wchar_t *value, DWORD *size)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD type;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
if (RegQueryValueEx (hkey, name, NULL, &type, (BYTE *) value, size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return type == REG_MULTI_SZ;
|
||||
}
|
||||
|
||||
BOOL ReadLocalMachineRegistryString (const wchar_t *subKey, wchar_t *name, wchar_t *str, DWORD *size)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD type;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
if (RegQueryValueEx (hkey, name, NULL, &type, (BYTE *) str, size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return type == REG_SZ;
|
||||
}
|
||||
|
||||
BOOL ReadLocalMachineRegistryStringNonReflected (const wchar_t *subKey, wchar_t *name, wchar_t *str, DWORD *size, BOOL b32bitApp)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD type;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ | (b32bitApp? KEY_WOW64_32KEY: KEY_WOW64_64KEY), &hkey) != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
if (RegQueryValueEx (hkey, name, NULL, &type, (BYTE *) str, size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return type == REG_SZ;
|
||||
}
|
||||
|
||||
int ReadRegistryInt (wchar_t *subKey, wchar_t *name, int defaultValue)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD value, size = sizeof (DWORD);
|
||||
|
||||
if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey,
|
||||
0, KEY_READ, &hkey) != ERROR_SUCCESS)
|
||||
return defaultValue;
|
||||
|
||||
if (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) &value, &size) != ERROR_SUCCESS)
|
||||
value = defaultValue;
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return value;
|
||||
}
|
||||
|
||||
wchar_t *ReadRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *defaultValue, wchar_t *str, int maxLen)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
wchar_t value[MAX_PATH*4];
|
||||
DWORD size = sizeof (value);
|
||||
|
||||
str[maxLen/2-1] = 0;
|
||||
StringCbCopyW (str, maxLen, defaultValue);
|
||||
|
||||
ZeroMemory (value, sizeof value);
|
||||
if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey,
|
||||
0, KEY_READ, &hkey) == ERROR_SUCCESS)
|
||||
if (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) value, &size) == ERROR_SUCCESS)
|
||||
StringCbCopyW (str, maxLen,value);
|
||||
|
||||
if (hkey)
|
||||
RegCloseKey (hkey);
|
||||
return str;
|
||||
}
|
||||
|
||||
DWORD ReadRegistryBytes (wchar_t *path, wchar_t *name, char *value, int maxLen)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD size = maxLen;
|
||||
BOOL success = FALSE;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_CURRENT_USER, path, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
|
||||
return 0;
|
||||
|
||||
success = (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) value, &size) == ERROR_SUCCESS);
|
||||
RegCloseKey (hkey);
|
||||
|
||||
return success ? size : 0;
|
||||
}
|
||||
|
||||
void WriteRegistryInt (wchar_t *subKey, wchar_t *name, int value)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
|
||||
if (RegCreateKeyEx (HKEY_CURRENT_USER, subKey,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS)
|
||||
return;
|
||||
|
||||
RegSetValueEx (hkey, name, 0, REG_DWORD, (BYTE *) &value, sizeof value);
|
||||
RegCloseKey (hkey);
|
||||
}
|
||||
|
||||
BOOL WriteLocalMachineRegistryDword (wchar_t *subKey, wchar_t *name, DWORD value)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
LONG status;
|
||||
|
||||
if ((status = RegCreateKeyEx (HKEY_LOCAL_MACHINE, subKey,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp)) != ERROR_SUCCESS)
|
||||
{
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((status = RegSetValueEx (hkey, name, 0, REG_DWORD, (BYTE *) &value, sizeof value)) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WriteLocalMachineRegistryMultiString (wchar_t *subKey, wchar_t *name, wchar_t *multiString, DWORD size)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
LONG status;
|
||||
|
||||
if ((status = RegCreateKeyEx (HKEY_LOCAL_MACHINE, subKey,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp)) != ERROR_SUCCESS)
|
||||
{
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((status = RegSetValueEx (hkey, name, 0, REG_MULTI_SZ, (BYTE *) multiString, size)) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WriteLocalMachineRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *str, BOOL expandable)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
LONG status;
|
||||
|
||||
if ((status = RegCreateKeyEx (HKEY_LOCAL_MACHINE, subKey,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp)) != ERROR_SUCCESS)
|
||||
{
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((status = RegSetValueEx (hkey, name, 0, expandable ? REG_EXPAND_SZ : REG_SZ, (BYTE *) str, (DWORD) (wcslen (str) + 1) * sizeof (wchar_t))) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void WriteRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *str)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
|
||||
if (RegCreateKeyEx (HKEY_CURRENT_USER, subKey,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS)
|
||||
return;
|
||||
|
||||
RegSetValueEx (hkey, name, 0, REG_SZ, (BYTE *) str, (DWORD) (wcslen (str) + 1) * sizeof (wchar_t));
|
||||
RegCloseKey (hkey);
|
||||
}
|
||||
|
||||
BOOL WriteRegistryBytes (wchar_t *path, wchar_t *name, char *str, DWORD size)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
BOOL res;
|
||||
|
||||
if (RegCreateKeyEx (HKEY_CURRENT_USER, path,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
res = RegSetValueEx (hkey, name, 0, REG_BINARY, (BYTE *) str, size);
|
||||
RegCloseKey (hkey);
|
||||
return res == ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
BOOL DeleteLocalMachineRegistryKey (wchar_t *parentKey, wchar_t *subKeyToDelete)
|
||||
{
|
||||
LONG status;
|
||||
HKEY hkey = 0;
|
||||
|
||||
if ((status = RegOpenKeyEx (HKEY_LOCAL_MACHINE, parentKey, 0, KEY_WRITE, &hkey)) != ERROR_SUCCESS)
|
||||
{
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((status = RegDeleteKey (hkey, subKeyToDelete)) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void DeleteRegistryValue (wchar_t *subKey, wchar_t *name)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey, 0, KEY_WRITE, &hkey) != ERROR_SUCCESS)
|
||||
return;
|
||||
|
||||
RegDeleteValue (hkey, name);
|
||||
RegCloseKey (hkey);
|
||||
}
|
||||
|
||||
|
||||
void GetStartupRegKeyName (wchar_t *regk, size_t cbRegk)
|
||||
{
|
||||
// The string is split in order to prevent some antivirus packages from falsely reporting
|
||||
// VeraCrypt.exe to contain a possible Trojan horse because of this string (heuristic scan).
|
||||
StringCbPrintfW (regk, cbRegk,L"%s%s", L"Software\\Microsoft\\Windows\\Curren", L"tVersion\\Run");
|
||||
}
|
||||
|
||||
void GetRestorePointRegKeyName (wchar_t *regk, size_t cbRegk)
|
||||
{
|
||||
// The string is split in order to prevent some antivirus packages from falsely reporting
|
||||
// VeraCrypt.exe to contain a possible Trojan horse because of this string (heuristic scan).
|
||||
StringCbPrintfW (regk, cbRegk,L"%s%s%s%s", L"Software\\Microsoft\\Windows", L" NT\\Curren", L"tVersion\\Sy", L"stemRestore");
|
||||
/*
|
||||
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 "Tcdefs.h"
|
||||
#include "Registry.h"
|
||||
#include <Strsafe.h>
|
||||
|
||||
BOOL ReadLocalMachineRegistryDword (wchar_t *subKey, wchar_t *name, DWORD *value)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD size = sizeof (*value);
|
||||
DWORD type;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
if (RegQueryValueEx (hkey, name, NULL, &type, (BYTE *) value, &size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return type == REG_DWORD;
|
||||
}
|
||||
|
||||
BOOL ReadLocalMachineRegistryMultiString (wchar_t *subKey, wchar_t *name, wchar_t *value, DWORD *size)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD type;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
if (RegQueryValueEx (hkey, name, NULL, &type, (BYTE *) value, size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return type == REG_MULTI_SZ;
|
||||
}
|
||||
|
||||
BOOL ReadLocalMachineRegistryString (const wchar_t *subKey, wchar_t *name, wchar_t *str, DWORD *size)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD type;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
if (RegQueryValueEx (hkey, name, NULL, &type, (BYTE *) str, size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return type == REG_SZ;
|
||||
}
|
||||
|
||||
BOOL ReadLocalMachineRegistryStringNonReflected (const wchar_t *subKey, wchar_t *name, wchar_t *str, DWORD *size, BOOL b32bitApp)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD type;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ | (b32bitApp? KEY_WOW64_32KEY: KEY_WOW64_64KEY), &hkey) != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
if (RegQueryValueEx (hkey, name, NULL, &type, (BYTE *) str, size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return type == REG_SZ;
|
||||
}
|
||||
|
||||
int ReadRegistryInt (wchar_t *subKey, wchar_t *name, int defaultValue)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD value, size = sizeof (DWORD);
|
||||
|
||||
if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey,
|
||||
0, KEY_READ, &hkey) != ERROR_SUCCESS)
|
||||
return defaultValue;
|
||||
|
||||
if (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) &value, &size) != ERROR_SUCCESS)
|
||||
value = defaultValue;
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return value;
|
||||
}
|
||||
|
||||
wchar_t *ReadRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *defaultValue, wchar_t *str, int maxLen)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
wchar_t value[MAX_PATH*4];
|
||||
DWORD size = sizeof (value);
|
||||
|
||||
str[maxLen/2-1] = 0;
|
||||
StringCbCopyW (str, maxLen, defaultValue);
|
||||
|
||||
ZeroMemory (value, sizeof value);
|
||||
if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey,
|
||||
0, KEY_READ, &hkey) == ERROR_SUCCESS)
|
||||
if (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) value, &size) == ERROR_SUCCESS)
|
||||
StringCbCopyW (str, maxLen,value);
|
||||
|
||||
if (hkey)
|
||||
RegCloseKey (hkey);
|
||||
return str;
|
||||
}
|
||||
|
||||
DWORD ReadRegistryBytes (wchar_t *path, wchar_t *name, char *value, int maxLen)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD size = maxLen;
|
||||
BOOL success = FALSE;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_CURRENT_USER, path, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
|
||||
return 0;
|
||||
|
||||
success = (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) value, &size) == ERROR_SUCCESS);
|
||||
RegCloseKey (hkey);
|
||||
|
||||
return success ? size : 0;
|
||||
}
|
||||
|
||||
void WriteRegistryInt (wchar_t *subKey, wchar_t *name, int value)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
|
||||
if (RegCreateKeyEx (HKEY_CURRENT_USER, subKey,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS)
|
||||
return;
|
||||
|
||||
RegSetValueEx (hkey, name, 0, REG_DWORD, (BYTE *) &value, sizeof value);
|
||||
RegCloseKey (hkey);
|
||||
}
|
||||
|
||||
BOOL WriteLocalMachineRegistryDword (wchar_t *subKey, wchar_t *name, DWORD value)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
LONG status;
|
||||
|
||||
if ((status = RegCreateKeyEx (HKEY_LOCAL_MACHINE, subKey,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp)) != ERROR_SUCCESS)
|
||||
{
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((status = RegSetValueEx (hkey, name, 0, REG_DWORD, (BYTE *) &value, sizeof value)) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WriteLocalMachineRegistryMultiString (wchar_t *subKey, wchar_t *name, wchar_t *multiString, DWORD size)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
LONG status;
|
||||
|
||||
if ((status = RegCreateKeyEx (HKEY_LOCAL_MACHINE, subKey,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp)) != ERROR_SUCCESS)
|
||||
{
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((status = RegSetValueEx (hkey, name, 0, REG_MULTI_SZ, (BYTE *) multiString, size)) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WriteLocalMachineRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *str, BOOL expandable)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
LONG status;
|
||||
|
||||
if ((status = RegCreateKeyEx (HKEY_LOCAL_MACHINE, subKey,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp)) != ERROR_SUCCESS)
|
||||
{
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((status = RegSetValueEx (hkey, name, 0, expandable ? REG_EXPAND_SZ : REG_SZ, (BYTE *) str, (DWORD) (wcslen (str) + 1) * sizeof (wchar_t))) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void WriteRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *str)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
|
||||
if (RegCreateKeyEx (HKEY_CURRENT_USER, subKey,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS)
|
||||
return;
|
||||
|
||||
RegSetValueEx (hkey, name, 0, REG_SZ, (BYTE *) str, (DWORD) (wcslen (str) + 1) * sizeof (wchar_t));
|
||||
RegCloseKey (hkey);
|
||||
}
|
||||
|
||||
BOOL WriteRegistryBytes (wchar_t *path, wchar_t *name, char *str, DWORD size)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
DWORD disp;
|
||||
BOOL res;
|
||||
|
||||
if (RegCreateKeyEx (HKEY_CURRENT_USER, path,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
res = RegSetValueEx (hkey, name, 0, REG_BINARY, (BYTE *) str, size);
|
||||
RegCloseKey (hkey);
|
||||
return res == ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
BOOL DeleteLocalMachineRegistryKey (wchar_t *parentKey, wchar_t *subKeyToDelete)
|
||||
{
|
||||
LONG status;
|
||||
HKEY hkey = 0;
|
||||
|
||||
if ((status = RegOpenKeyEx (HKEY_LOCAL_MACHINE, parentKey, 0, KEY_WRITE, &hkey)) != ERROR_SUCCESS)
|
||||
{
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((status = RegDeleteKey (hkey, subKeyToDelete)) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey (hkey);
|
||||
SetLastError (status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey (hkey);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void DeleteRegistryValue (wchar_t *subKey, wchar_t *name)
|
||||
{
|
||||
HKEY hkey = 0;
|
||||
|
||||
if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey, 0, KEY_WRITE, &hkey) != ERROR_SUCCESS)
|
||||
return;
|
||||
|
||||
RegDeleteValue (hkey, name);
|
||||
RegCloseKey (hkey);
|
||||
}
|
||||
|
||||
|
||||
void GetStartupRegKeyName (wchar_t *regk, size_t cbRegk)
|
||||
{
|
||||
// The string is split in order to prevent some antivirus packages from falsely reporting
|
||||
// VeraCrypt.exe to contain a possible Trojan horse because of this string (heuristic scan).
|
||||
StringCbPrintfW (regk, cbRegk,L"%s%s", L"Software\\Microsoft\\Windows\\Curren", L"tVersion\\Run");
|
||||
}
|
||||
|
||||
void GetRestorePointRegKeyName (wchar_t *regk, size_t cbRegk)
|
||||
{
|
||||
// The string is split in order to prevent some antivirus packages from falsely reporting
|
||||
// VeraCrypt.exe to contain a possible Trojan horse because of this string (heuristic scan).
|
||||
StringCbPrintfW (regk, cbRegk,L"%s%s%s%s", L"Software\\Microsoft\\Windows", L" NT\\Curren", L"tVersion\\Sy", L"stemRestore");
|
||||
}
|
||||
@@ -1,37 +1,37 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
BOOL ReadLocalMachineRegistryDword (wchar_t *subKey, wchar_t *name, DWORD *value);
|
||||
BOOL ReadLocalMachineRegistryMultiString (wchar_t *subKey, wchar_t *name, wchar_t *value, DWORD *size);
|
||||
BOOL ReadLocalMachineRegistryString (const wchar_t *subKey, wchar_t *name, wchar_t *value, DWORD *size);
|
||||
BOOL ReadLocalMachineRegistryStringNonReflected (const wchar_t *subKey, wchar_t *name, wchar_t *str, DWORD *size, BOOL b32bitApp);
|
||||
int ReadRegistryInt (wchar_t *subKey, wchar_t *name, int defaultValue);
|
||||
wchar_t *ReadRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *defaultValue, wchar_t *str, int maxLen);
|
||||
DWORD ReadRegistryBytes (wchar_t *path, wchar_t *name, char *value, int maxLen);
|
||||
void WriteRegistryInt (wchar_t *subKey, wchar_t *name, int value);
|
||||
BOOL WriteLocalMachineRegistryDword (wchar_t *subKey, wchar_t *name, DWORD value);
|
||||
BOOL WriteLocalMachineRegistryMultiString (wchar_t *subKey, wchar_t *name, wchar_t *multiString, DWORD size);
|
||||
BOOL WriteLocalMachineRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *str, BOOL expandable);
|
||||
void WriteRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *str);
|
||||
BOOL WriteRegistryBytes (wchar_t *path, wchar_t *name, char *str, DWORD size);
|
||||
BOOL DeleteLocalMachineRegistryKey (wchar_t *parentKey, wchar_t *subKeyToDelete);
|
||||
void DeleteRegistryValue (wchar_t *subKey, wchar_t *name);
|
||||
void GetStartupRegKeyName (wchar_t *regk, size_t cbRegk);
|
||||
void GetRestorePointRegKeyName (wchar_t *regk, size_t cbRegk);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
BOOL ReadLocalMachineRegistryDword (wchar_t *subKey, wchar_t *name, DWORD *value);
|
||||
BOOL ReadLocalMachineRegistryMultiString (wchar_t *subKey, wchar_t *name, wchar_t *value, DWORD *size);
|
||||
BOOL ReadLocalMachineRegistryString (const wchar_t *subKey, wchar_t *name, wchar_t *value, DWORD *size);
|
||||
BOOL ReadLocalMachineRegistryStringNonReflected (const wchar_t *subKey, wchar_t *name, wchar_t *str, DWORD *size, BOOL b32bitApp);
|
||||
int ReadRegistryInt (wchar_t *subKey, wchar_t *name, int defaultValue);
|
||||
wchar_t *ReadRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *defaultValue, wchar_t *str, int maxLen);
|
||||
DWORD ReadRegistryBytes (wchar_t *path, wchar_t *name, char *value, int maxLen);
|
||||
void WriteRegistryInt (wchar_t *subKey, wchar_t *name, int value);
|
||||
BOOL WriteLocalMachineRegistryDword (wchar_t *subKey, wchar_t *name, DWORD value);
|
||||
BOOL WriteLocalMachineRegistryMultiString (wchar_t *subKey, wchar_t *name, wchar_t *multiString, DWORD size);
|
||||
BOOL WriteLocalMachineRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *str, BOOL expandable);
|
||||
void WriteRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *str);
|
||||
BOOL WriteRegistryBytes (wchar_t *path, wchar_t *name, char *str, DWORD size);
|
||||
BOOL DeleteLocalMachineRegistryKey (wchar_t *parentKey, wchar_t *subKeyToDelete);
|
||||
void DeleteRegistryValue (wchar_t *subKey, wchar_t *name);
|
||||
void GetStartupRegKeyName (wchar_t *regk, size_t cbRegk);
|
||||
void GetRestorePointRegKeyName (wchar_t *regk, size_t cbRegk);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,211 +1,211 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by Common.rc
|
||||
//
|
||||
#define IDI_TRUECRYPT_ICON 501
|
||||
#define IDI_TRUECRYPT_VOL_ICON 502
|
||||
#define IDD_BENCHMARK_DLG 503
|
||||
#define IDD_MOUNT_OPTIONS 504
|
||||
#define IDD_KEYFILES 505
|
||||
#define IDR_LANGUAGE 506
|
||||
#define IDI_TRUECRYPT 507
|
||||
#define IDD_ABOUT_DLG 508
|
||||
#define IDD_COMMANDHELP_DLG 509
|
||||
#define IDD_RAWDEVICES_DLG 510
|
||||
#define IDC_HOMEPAGE 511
|
||||
#define IDR_COMMON_RSRC_HEADER 512
|
||||
#define IDD_LANGUAGE 513
|
||||
#define IDD_CIPHER_TEST_DLG 514
|
||||
#define IDR_LICENSE 515
|
||||
#define IDD_AUXILIARY_DLG 516
|
||||
#define IDB_TEXTUAL_LOGO_BKG 517
|
||||
#define IDB_TEXTUAL_LOGO_96DPI 518
|
||||
#define IDB_TEXTUAL_LOGO_288DPI 519
|
||||
#define IDR_BOOT_SECTOR 520
|
||||
#define IDR_BOOT_SECTOR_AES 521
|
||||
#define IDR_BOOT_SECTOR_SERPENT 522
|
||||
#define IDR_BOOT_SECTOR_TWOFISH 523
|
||||
#define IDR_BOOT_LOADER_DECOMPRESSOR 524
|
||||
#define IDR_BOOT_LOADER 525
|
||||
#define IDR_BOOT_LOADER_AES 526
|
||||
#define IDR_BOOT_LOADER_SERPENT 527
|
||||
#define IDR_BOOT_LOADER_TWOFISH 528
|
||||
#define IDR_RESCUE_BOOT_SECTOR 529
|
||||
#define IDR_RESCUE_BOOT_SECTOR_AES 530
|
||||
#define IDR_RESCUE_BOOT_SECTOR_SERPENT 531
|
||||
#define IDR_RESCUE_BOOT_SECTOR_TWOFISH 532
|
||||
#define IDR_RESCUE_LOADER 533
|
||||
#define IDR_RESCUE_LOADER_AES 534
|
||||
#define IDR_RESCUE_LOADER_SERPENT 535
|
||||
#define IDR_RESCUE_LOADER_TWOFISH 536
|
||||
#define IDD_TOKEN_PASSWORD 537
|
||||
#define IDD_TOKEN_KEYFILES 538
|
||||
#define IDD_NEW_TOKEN_KEYFILE 539
|
||||
#define IDD_RANDOM_POOL_ENRICHMENT 540
|
||||
#define IDI_TRUECRYPT_MOUNTED_ICON 541
|
||||
#define IDR_BOOT_SECTOR_SHA2 542
|
||||
#define IDR_BOOT_SECTOR_AES_SHA2 543
|
||||
#define IDR_BOOT_SECTOR_SERPENT_SHA2 544
|
||||
#define IDR_BOOT_SECTOR_TWOFISH_SHA2 545
|
||||
#define IDR_BOOT_LOADER_SHA2 546
|
||||
#define IDR_BOOT_LOADER_AES_SHA2 547
|
||||
#define IDR_BOOT_LOADER_SERPENT_SHA2 548
|
||||
#define IDR_BOOT_LOADER_TWOFISH_SHA2 549
|
||||
#define IDR_RESCUE_BOOT_SECTOR_SHA2 550
|
||||
#define IDR_RESCUE_BOOT_SECTOR_AES_SHA2 551
|
||||
#define IDR_RESCUE_BOOT_SECTOR_SERPENT_SHA2 552
|
||||
#define IDR_RESCUE_BOOT_SECTOR_TWOFISH_SHA2 553
|
||||
#define IDR_RESCUE_LOADER_SHA2 554
|
||||
#define IDR_RESCUE_LOADER_AES_SHA2 555
|
||||
#define IDR_RESCUE_LOADER_SERPENT_SHA2 556
|
||||
#define IDR_RESCUE_LOADER_TWOFISH_SHA2 557
|
||||
#define IDC_HW_AES_LABEL_LINK 5000
|
||||
#define IDC_HW_AES 5001
|
||||
#define IDC_PARALLELIZATION_LABEL_LINK 5002
|
||||
#define IDC_PARALLELIZATION 5003
|
||||
#define IDT_TOKEN_PASSWORD 5004
|
||||
#define IDC_PRINT 5005
|
||||
#define IDC_KEY 5006
|
||||
#define IDC_PLAINTEXT 5007
|
||||
#define IDC_CIPHERTEXT 5008
|
||||
#define IDC_INFO_BOX_TEXT 5009
|
||||
#define IDC_SECONDARY_KEY 5010
|
||||
#define IDD_TEXT_INFO_DIALOG_BOX_DLG 5011
|
||||
#define IDC_TEST_DATA_UNIT_NUMBER 5012
|
||||
#define IDD_KEYFILE_GENERATOR 5013
|
||||
#define IDC_CIPHER 5014
|
||||
#define IDD_MULTI_CHOICE_DLG 5015
|
||||
#define IDC_TEST_BLOCK_NUMBER 5016
|
||||
#define IDD_STATIC_MODELESS_WAIT_DLG 5017
|
||||
#define IDC_POOL_CONTENTS 5018
|
||||
#define IDC_PRF_ID 5019
|
||||
#define IDC_KEY_SIZE 5020
|
||||
#define IDC_PLAINTEXT_SIZE 5021
|
||||
#define IDC_REDTICK 5022
|
||||
#define IDC_TESTS_MESSAGE 5023
|
||||
#define IDC_RESET 5024
|
||||
#define IDC_AUTO 5025
|
||||
#define IDC_DECRYPT 5026
|
||||
#define IDT_TEST_KEY 5027
|
||||
#define IDT_TEST_PLAINTEXT 5028
|
||||
#define IDT_PRF 5029
|
||||
#define IDT_XTS_MODE 5030
|
||||
#define IDT_TEST_CIPHERTEXT 5031
|
||||
#define IDT_KEY 5032
|
||||
#define IDT_PLAINTEXT 5033
|
||||
#define IDC_ENCRYPT 5034
|
||||
#define IDT_KEY_UNIT 5035
|
||||
#define IDT_CIPHER 5036
|
||||
#define IDT_PLAINTEXT_SIZE_UNIT 5037
|
||||
#define IDC_DEVICELIST 5038
|
||||
#define IDT_TEST_BLOCK_NUMBER 5039
|
||||
#define IDT_SECONDARY_KEY 5040
|
||||
#define IDC_PERFORM_BENCHMARK 5041
|
||||
#define IDT_TEST_DATA_UNIT_NUMBER 5042
|
||||
#define IDC_KEYFILES_HIDVOL_PROT 5043
|
||||
#define IDC_KEYLIST 5044
|
||||
#define IDC_ABOUT_BKG 5045
|
||||
#define IDT_ABOUT_VERSION 5046
|
||||
#define IDT_BOX_BENCHMARK_INFO 5047
|
||||
#define IDC_ABOUT_CREDITS 5048
|
||||
#define IDT_SORT_METHOD 5049
|
||||
#define IDC_MOUNT_READONLY 5050
|
||||
#define IDC_MOUNT_REMOVABLE 5051
|
||||
#define IDC_PROTECT_HIDDEN_VOL 5052
|
||||
#define IDC_COMMANDHELP_TEXT 5053
|
||||
#define IDC_USE_EMBEDDED_HEADER_BAK 5054
|
||||
#define IDC_MOUNT_SYSENC_PART_WITHOUT_PBA 5055
|
||||
#define IDT_HIDDEN_PROT_PASSWD 5056
|
||||
#define IDC_RESULTS 5057
|
||||
#define IDC_KEYADD 5058
|
||||
#define IDC_KEYREMOVE 5059
|
||||
#define IDC_KEYREMOVEALL 5060
|
||||
#define IDC_KEYFILES_ENABLE 5061
|
||||
#define IDT_HIDDEN_VOL_PROTECTION 5062
|
||||
#define IDC_ADD_KEYFILE_PATH 5063
|
||||
#define IDC_BENCHMARK_BUFFER_SIZE 5064
|
||||
#define IDC_SHOW_PASSWORD_MO 5065
|
||||
#define IDC_GENERATE_KEYFILE 5066
|
||||
#define IDC_BENCHMARK_SORT_METHOD 5067
|
||||
#define IDC_PASSWORD_PROT_HIDVOL 5068
|
||||
#define IDT_BUFFER_SIZE 5069
|
||||
#define IDC_LANGLIST 5070
|
||||
#define IDC_KEYFILES_ENABLE_HIDVOL_PROT 5071
|
||||
#define IDT_KEYFILES_NOTE 5072
|
||||
#define IDT_KEYFILE_WARNING 5073
|
||||
#define IDT_KEYFILE_GENERATOR_NOTE 5074
|
||||
#define IDC_GENERATE_AND_SAVE_KEYFILE 5075
|
||||
#define IDT_POOL_CONTENTS 5076
|
||||
#define IDC_GET_LANG_PACKS 5077
|
||||
#define IDT_LANGPACK_AUTHORS 5078
|
||||
#define IDC_LANGPACK_CREDITS 5079
|
||||
#define IDC_LANGPACK_VERSION 5080
|
||||
#define IDT_ACTIVE_LANG_PACK 5081
|
||||
#define IDC_DISPLAY_POOL_CONTENTS 5082
|
||||
#define IDC_XTS_MODE_ENABLED 5083
|
||||
#define IDC_MULTI_CHOICE_MSG 5084
|
||||
#define IDC_CHOICE1 5085
|
||||
#define IDC_CHOICE5 5086
|
||||
#define IDC_CHOICE2 5087
|
||||
#define IDC_CHOICE3 5088
|
||||
#define IDC_CHOICE4 5089
|
||||
#define IDC_CHOICE6 5090
|
||||
#define IDC_CHOICE7 5091
|
||||
#define IDC_CHOICE8 5092
|
||||
#define IDC_CHOICE9 5093
|
||||
#define IDC_CHOICE10 5094
|
||||
#define IDC_MC_DLG_HR1 5095
|
||||
#define IDC_MC_DLG_HR2 5096
|
||||
#define IDC_LINK_HIDVOL_PROTECTION_INFO 5097
|
||||
#define IDC_LINK_KEYFILES_INFO 5098
|
||||
#define IDC_TEXTUAL_LOGO_IMG 5099
|
||||
#define IDC_ASPECT_RATIO_CALIBRATION_BOX 5100
|
||||
#define IDC_ABOUT_LOGO_AREA 5101
|
||||
#define IDC_TOKEN_PASSWORD 5102
|
||||
#define IDC_TOKEN_FILE_LIST 5103
|
||||
#define IDC_TOKEN_FILES_ADD 5104
|
||||
#define IDC_EXPORT 5105
|
||||
#define IDC_DELETE 5106
|
||||
#define IDC_IMPORT_KEYFILE 5107
|
||||
#define IDC_SELECTED_TOKEN 5108
|
||||
#define IDT_SECURITY_TOKEN 5109
|
||||
#define IDT_TOKEN_KEYFILE_NAME 5110
|
||||
#define IDC_TOKEN_KEYFILE_NAME 5111
|
||||
#define IDT_TOKEN_PASSWORD_INFO 5112
|
||||
#define IDT_RANDOM_POOL_ENRICHMENT_NOTE 5113
|
||||
#define IDC_CONTINUE 5114
|
||||
#define IDT_ABOUT_RELEASE 5115
|
||||
#define IDT_STATIC_MODELESS_WAIT_DLG_INFO 5116
|
||||
#define IDT_NUMBER_KEYFILES 5117
|
||||
#define IDC_NUMBER_KEYFILES 5118
|
||||
#define IDT_KEYFILES_BASE_NAME 5119
|
||||
#define IDC_KEYFILES_BASE_NAME 5120
|
||||
#define IDC_KEYFILES_SIZE 5121
|
||||
#define IDC_KEYFILES_RANDOM_SIZE 5122
|
||||
#define IDT_KEYFILES_SIZE 5123
|
||||
#define IDD_STATIC_MODAL_WAIT_DLG 5124
|
||||
#define IDT_STATIC_MODAL_WAIT_DLG_INFO 5125
|
||||
#define IDC_WAIT_PROGRESS_BAR 5126
|
||||
#define IDC_PKCS5_PRF_ID 5127
|
||||
#define IDT_PKCS5_PRF 5128
|
||||
#define IDT_PIM 5129
|
||||
#define IDC_PIM 5130
|
||||
#define IDC_PIM_HELP 5131
|
||||
#define IDC_PIM_ENABLE 5132
|
||||
#define IDC_VOLUME_LABEL 5133
|
||||
#define IDT_VOLUME_LABEL 5134
|
||||
#define IDC_KEYFILES_TRY_EMPTY_PASSWORD 5135
|
||||
#define IDC_ENTROPY_BAR 5136
|
||||
#define IDT_ENTROPY_BAR 5137
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NO_MFC 1
|
||||
#define _APS_NEXT_RESOURCE_VALUE 558
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 5138
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by Common.rc
|
||||
//
|
||||
#define IDI_TRUECRYPT_ICON 501
|
||||
#define IDI_TRUECRYPT_VOL_ICON 502
|
||||
#define IDD_BENCHMARK_DLG 503
|
||||
#define IDD_MOUNT_OPTIONS 504
|
||||
#define IDD_KEYFILES 505
|
||||
#define IDR_LANGUAGE 506
|
||||
#define IDI_TRUECRYPT 507
|
||||
#define IDD_ABOUT_DLG 508
|
||||
#define IDD_COMMANDHELP_DLG 509
|
||||
#define IDD_RAWDEVICES_DLG 510
|
||||
#define IDC_HOMEPAGE 511
|
||||
#define IDR_COMMON_RSRC_HEADER 512
|
||||
#define IDD_LANGUAGE 513
|
||||
#define IDD_CIPHER_TEST_DLG 514
|
||||
#define IDR_LICENSE 515
|
||||
#define IDD_AUXILIARY_DLG 516
|
||||
#define IDB_TEXTUAL_LOGO_BKG 517
|
||||
#define IDB_TEXTUAL_LOGO_96DPI 518
|
||||
#define IDB_TEXTUAL_LOGO_288DPI 519
|
||||
#define IDR_BOOT_SECTOR 520
|
||||
#define IDR_BOOT_SECTOR_AES 521
|
||||
#define IDR_BOOT_SECTOR_SERPENT 522
|
||||
#define IDR_BOOT_SECTOR_TWOFISH 523
|
||||
#define IDR_BOOT_LOADER_DECOMPRESSOR 524
|
||||
#define IDR_BOOT_LOADER 525
|
||||
#define IDR_BOOT_LOADER_AES 526
|
||||
#define IDR_BOOT_LOADER_SERPENT 527
|
||||
#define IDR_BOOT_LOADER_TWOFISH 528
|
||||
#define IDR_RESCUE_BOOT_SECTOR 529
|
||||
#define IDR_RESCUE_BOOT_SECTOR_AES 530
|
||||
#define IDR_RESCUE_BOOT_SECTOR_SERPENT 531
|
||||
#define IDR_RESCUE_BOOT_SECTOR_TWOFISH 532
|
||||
#define IDR_RESCUE_LOADER 533
|
||||
#define IDR_RESCUE_LOADER_AES 534
|
||||
#define IDR_RESCUE_LOADER_SERPENT 535
|
||||
#define IDR_RESCUE_LOADER_TWOFISH 536
|
||||
#define IDD_TOKEN_PASSWORD 537
|
||||
#define IDD_TOKEN_KEYFILES 538
|
||||
#define IDD_NEW_TOKEN_KEYFILE 539
|
||||
#define IDD_RANDOM_POOL_ENRICHMENT 540
|
||||
#define IDI_TRUECRYPT_MOUNTED_ICON 541
|
||||
#define IDR_BOOT_SECTOR_SHA2 542
|
||||
#define IDR_BOOT_SECTOR_AES_SHA2 543
|
||||
#define IDR_BOOT_SECTOR_SERPENT_SHA2 544
|
||||
#define IDR_BOOT_SECTOR_TWOFISH_SHA2 545
|
||||
#define IDR_BOOT_LOADER_SHA2 546
|
||||
#define IDR_BOOT_LOADER_AES_SHA2 547
|
||||
#define IDR_BOOT_LOADER_SERPENT_SHA2 548
|
||||
#define IDR_BOOT_LOADER_TWOFISH_SHA2 549
|
||||
#define IDR_RESCUE_BOOT_SECTOR_SHA2 550
|
||||
#define IDR_RESCUE_BOOT_SECTOR_AES_SHA2 551
|
||||
#define IDR_RESCUE_BOOT_SECTOR_SERPENT_SHA2 552
|
||||
#define IDR_RESCUE_BOOT_SECTOR_TWOFISH_SHA2 553
|
||||
#define IDR_RESCUE_LOADER_SHA2 554
|
||||
#define IDR_RESCUE_LOADER_AES_SHA2 555
|
||||
#define IDR_RESCUE_LOADER_SERPENT_SHA2 556
|
||||
#define IDR_RESCUE_LOADER_TWOFISH_SHA2 557
|
||||
#define IDC_HW_AES_LABEL_LINK 5000
|
||||
#define IDC_HW_AES 5001
|
||||
#define IDC_PARALLELIZATION_LABEL_LINK 5002
|
||||
#define IDC_PARALLELIZATION 5003
|
||||
#define IDT_TOKEN_PASSWORD 5004
|
||||
#define IDC_PRINT 5005
|
||||
#define IDC_KEY 5006
|
||||
#define IDC_PLAINTEXT 5007
|
||||
#define IDC_CIPHERTEXT 5008
|
||||
#define IDC_INFO_BOX_TEXT 5009
|
||||
#define IDC_SECONDARY_KEY 5010
|
||||
#define IDD_TEXT_INFO_DIALOG_BOX_DLG 5011
|
||||
#define IDC_TEST_DATA_UNIT_NUMBER 5012
|
||||
#define IDD_KEYFILE_GENERATOR 5013
|
||||
#define IDC_CIPHER 5014
|
||||
#define IDD_MULTI_CHOICE_DLG 5015
|
||||
#define IDC_TEST_BLOCK_NUMBER 5016
|
||||
#define IDD_STATIC_MODELESS_WAIT_DLG 5017
|
||||
#define IDC_POOL_CONTENTS 5018
|
||||
#define IDC_PRF_ID 5019
|
||||
#define IDC_KEY_SIZE 5020
|
||||
#define IDC_PLAINTEXT_SIZE 5021
|
||||
#define IDC_REDTICK 5022
|
||||
#define IDC_TESTS_MESSAGE 5023
|
||||
#define IDC_RESET 5024
|
||||
#define IDC_AUTO 5025
|
||||
#define IDC_DECRYPT 5026
|
||||
#define IDT_TEST_KEY 5027
|
||||
#define IDT_TEST_PLAINTEXT 5028
|
||||
#define IDT_PRF 5029
|
||||
#define IDT_XTS_MODE 5030
|
||||
#define IDT_TEST_CIPHERTEXT 5031
|
||||
#define IDT_KEY 5032
|
||||
#define IDT_PLAINTEXT 5033
|
||||
#define IDC_ENCRYPT 5034
|
||||
#define IDT_KEY_UNIT 5035
|
||||
#define IDT_CIPHER 5036
|
||||
#define IDT_PLAINTEXT_SIZE_UNIT 5037
|
||||
#define IDC_DEVICELIST 5038
|
||||
#define IDT_TEST_BLOCK_NUMBER 5039
|
||||
#define IDT_SECONDARY_KEY 5040
|
||||
#define IDC_PERFORM_BENCHMARK 5041
|
||||
#define IDT_TEST_DATA_UNIT_NUMBER 5042
|
||||
#define IDC_KEYFILES_HIDVOL_PROT 5043
|
||||
#define IDC_KEYLIST 5044
|
||||
#define IDC_ABOUT_BKG 5045
|
||||
#define IDT_ABOUT_VERSION 5046
|
||||
#define IDT_BOX_BENCHMARK_INFO 5047
|
||||
#define IDC_ABOUT_CREDITS 5048
|
||||
#define IDT_SORT_METHOD 5049
|
||||
#define IDC_MOUNT_READONLY 5050
|
||||
#define IDC_MOUNT_REMOVABLE 5051
|
||||
#define IDC_PROTECT_HIDDEN_VOL 5052
|
||||
#define IDC_COMMANDHELP_TEXT 5053
|
||||
#define IDC_USE_EMBEDDED_HEADER_BAK 5054
|
||||
#define IDC_MOUNT_SYSENC_PART_WITHOUT_PBA 5055
|
||||
#define IDT_HIDDEN_PROT_PASSWD 5056
|
||||
#define IDC_RESULTS 5057
|
||||
#define IDC_KEYADD 5058
|
||||
#define IDC_KEYREMOVE 5059
|
||||
#define IDC_KEYREMOVEALL 5060
|
||||
#define IDC_KEYFILES_ENABLE 5061
|
||||
#define IDT_HIDDEN_VOL_PROTECTION 5062
|
||||
#define IDC_ADD_KEYFILE_PATH 5063
|
||||
#define IDC_BENCHMARK_BUFFER_SIZE 5064
|
||||
#define IDC_SHOW_PASSWORD_MO 5065
|
||||
#define IDC_GENERATE_KEYFILE 5066
|
||||
#define IDC_BENCHMARK_SORT_METHOD 5067
|
||||
#define IDC_PASSWORD_PROT_HIDVOL 5068
|
||||
#define IDT_BUFFER_SIZE 5069
|
||||
#define IDC_LANGLIST 5070
|
||||
#define IDC_KEYFILES_ENABLE_HIDVOL_PROT 5071
|
||||
#define IDT_KEYFILES_NOTE 5072
|
||||
#define IDT_KEYFILE_WARNING 5073
|
||||
#define IDT_KEYFILE_GENERATOR_NOTE 5074
|
||||
#define IDC_GENERATE_AND_SAVE_KEYFILE 5075
|
||||
#define IDT_POOL_CONTENTS 5076
|
||||
#define IDC_GET_LANG_PACKS 5077
|
||||
#define IDT_LANGPACK_AUTHORS 5078
|
||||
#define IDC_LANGPACK_CREDITS 5079
|
||||
#define IDC_LANGPACK_VERSION 5080
|
||||
#define IDT_ACTIVE_LANG_PACK 5081
|
||||
#define IDC_DISPLAY_POOL_CONTENTS 5082
|
||||
#define IDC_XTS_MODE_ENABLED 5083
|
||||
#define IDC_MULTI_CHOICE_MSG 5084
|
||||
#define IDC_CHOICE1 5085
|
||||
#define IDC_CHOICE5 5086
|
||||
#define IDC_CHOICE2 5087
|
||||
#define IDC_CHOICE3 5088
|
||||
#define IDC_CHOICE4 5089
|
||||
#define IDC_CHOICE6 5090
|
||||
#define IDC_CHOICE7 5091
|
||||
#define IDC_CHOICE8 5092
|
||||
#define IDC_CHOICE9 5093
|
||||
#define IDC_CHOICE10 5094
|
||||
#define IDC_MC_DLG_HR1 5095
|
||||
#define IDC_MC_DLG_HR2 5096
|
||||
#define IDC_LINK_HIDVOL_PROTECTION_INFO 5097
|
||||
#define IDC_LINK_KEYFILES_INFO 5098
|
||||
#define IDC_TEXTUAL_LOGO_IMG 5099
|
||||
#define IDC_ASPECT_RATIO_CALIBRATION_BOX 5100
|
||||
#define IDC_ABOUT_LOGO_AREA 5101
|
||||
#define IDC_TOKEN_PASSWORD 5102
|
||||
#define IDC_TOKEN_FILE_LIST 5103
|
||||
#define IDC_TOKEN_FILES_ADD 5104
|
||||
#define IDC_EXPORT 5105
|
||||
#define IDC_DELETE 5106
|
||||
#define IDC_IMPORT_KEYFILE 5107
|
||||
#define IDC_SELECTED_TOKEN 5108
|
||||
#define IDT_SECURITY_TOKEN 5109
|
||||
#define IDT_TOKEN_KEYFILE_NAME 5110
|
||||
#define IDC_TOKEN_KEYFILE_NAME 5111
|
||||
#define IDT_TOKEN_PASSWORD_INFO 5112
|
||||
#define IDT_RANDOM_POOL_ENRICHMENT_NOTE 5113
|
||||
#define IDC_CONTINUE 5114
|
||||
#define IDT_ABOUT_RELEASE 5115
|
||||
#define IDT_STATIC_MODELESS_WAIT_DLG_INFO 5116
|
||||
#define IDT_NUMBER_KEYFILES 5117
|
||||
#define IDC_NUMBER_KEYFILES 5118
|
||||
#define IDT_KEYFILES_BASE_NAME 5119
|
||||
#define IDC_KEYFILES_BASE_NAME 5120
|
||||
#define IDC_KEYFILES_SIZE 5121
|
||||
#define IDC_KEYFILES_RANDOM_SIZE 5122
|
||||
#define IDT_KEYFILES_SIZE 5123
|
||||
#define IDD_STATIC_MODAL_WAIT_DLG 5124
|
||||
#define IDT_STATIC_MODAL_WAIT_DLG_INFO 5125
|
||||
#define IDC_WAIT_PROGRESS_BAR 5126
|
||||
#define IDC_PKCS5_PRF_ID 5127
|
||||
#define IDT_PKCS5_PRF 5128
|
||||
#define IDT_PIM 5129
|
||||
#define IDC_PIM 5130
|
||||
#define IDC_PIM_HELP 5131
|
||||
#define IDC_PIM_ENABLE 5132
|
||||
#define IDC_VOLUME_LABEL 5133
|
||||
#define IDT_VOLUME_LABEL 5134
|
||||
#define IDC_KEYFILES_TRY_EMPTY_PASSWORD 5135
|
||||
#define IDC_ENTROPY_BAR 5136
|
||||
#define IDT_ENTROPY_BAR 5137
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NO_MFC 1
|
||||
#define _APS_NEXT_RESOURCE_VALUE 558
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 5138
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,226 +1,226 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Common_SecurityToken
|
||||
#define TC_HEADER_Common_SecurityToken
|
||||
|
||||
#include "Platform/PlatformBase.h"
|
||||
#if defined (TC_WINDOWS) && !defined (TC_PROTOTYPE)
|
||||
# include "Exception.h"
|
||||
#else
|
||||
# include "Platform/Exception.h"
|
||||
#endif
|
||||
|
||||
#ifndef NULL_PTR
|
||||
# define NULL_PTR 0
|
||||
#endif
|
||||
#define CK_PTR *
|
||||
#define CK_CALLBACK_FUNCTION(RET_TYPE, NAME) RET_TYPE (* NAME)
|
||||
|
||||
#ifdef TC_WINDOWS
|
||||
|
||||
# include <windows.h>
|
||||
|
||||
# define CK_DEFINE_FUNCTION(RET_TYPE, NAME) RET_TYPE __declspec(dllexport) NAME
|
||||
# define CK_DECLARE_FUNCTION(RET_TYPE, NAME) RET_TYPE __declspec(dllimport) NAME
|
||||
# define CK_DECLARE_FUNCTION_POINTER(RET_TYPE, NAME) RET_TYPE __declspec(dllimport) (* NAME)
|
||||
|
||||
# pragma pack(push, cryptoki, 1)
|
||||
# include <pkcs11.h>
|
||||
# pragma pack(pop, cryptoki)
|
||||
|
||||
#else // !TC_WINDOWS
|
||||
|
||||
# define CK_DEFINE_FUNCTION(RET_TYPE, NAME) RET_TYPE NAME
|
||||
# define CK_DECLARE_FUNCTION(RET_TYPE, NAME) RET_TYPE NAME
|
||||
# define CK_DECLARE_FUNCTION_POINTER(RET_TYPE, NAME) RET_TYPE (* NAME)
|
||||
|
||||
# include <pkcs11.h>
|
||||
|
||||
#endif // !TC_WINDOWS
|
||||
|
||||
|
||||
#define TC_SECURITY_TOKEN_KEYFILE_URL_PREFIX L"token://"
|
||||
#define TC_SECURITY_TOKEN_KEYFILE_URL_SLOT L"slot"
|
||||
#define TC_SECURITY_TOKEN_KEYFILE_URL_FILE L"file"
|
||||
|
||||
namespace VeraCrypt
|
||||
{
|
||||
struct SecurityTokenInfo
|
||||
{
|
||||
CK_SLOT_ID SlotId;
|
||||
CK_FLAGS Flags;
|
||||
wstring Label;
|
||||
string LabelUtf8;
|
||||
};
|
||||
|
||||
struct SecurityTokenKeyfilePath
|
||||
{
|
||||
SecurityTokenKeyfilePath () { }
|
||||
SecurityTokenKeyfilePath (const wstring &path) : Path (path) { }
|
||||
operator wstring () const { return Path; }
|
||||
wstring Path;
|
||||
};
|
||||
|
||||
struct SecurityTokenKeyfile
|
||||
{
|
||||
SecurityTokenKeyfile () : Handle(CK_INVALID_HANDLE), SlotId(CK_UNAVAILABLE_INFORMATION) { Token.SlotId = CK_UNAVAILABLE_INFORMATION; Token.Flags = 0; }
|
||||
SecurityTokenKeyfile (const SecurityTokenKeyfilePath &path, char* pin = nullptr);
|
||||
|
||||
operator SecurityTokenKeyfilePath () const;
|
||||
|
||||
CK_OBJECT_HANDLE Handle;
|
||||
wstring Id;
|
||||
string IdUtf8;
|
||||
CK_SLOT_ID SlotId;
|
||||
SecurityTokenInfo Token;
|
||||
};
|
||||
|
||||
struct Pkcs11Exception : public Exception
|
||||
{
|
||||
Pkcs11Exception (CK_RV errorCode = (CK_RV) -1)
|
||||
: ErrorCode (errorCode),
|
||||
SubjectErrorCodeValid (false),
|
||||
SubjectErrorCode( (uint64) -1)
|
||||
{
|
||||
}
|
||||
|
||||
Pkcs11Exception (CK_RV errorCode, uint64 subjectErrorCode)
|
||||
: ErrorCode (errorCode),
|
||||
SubjectErrorCodeValid (true),
|
||||
SubjectErrorCode (subjectErrorCode)
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef TC_HEADER_Platform_Exception
|
||||
virtual ~Pkcs11Exception () throw () { }
|
||||
TC_SERIALIZABLE_EXCEPTION (Pkcs11Exception);
|
||||
#else
|
||||
void Show (HWND parent) const;
|
||||
#endif
|
||||
operator string () const;
|
||||
CK_RV GetErrorCode () const { return ErrorCode; }
|
||||
|
||||
protected:
|
||||
CK_RV ErrorCode;
|
||||
bool SubjectErrorCodeValid;
|
||||
uint64 SubjectErrorCode;
|
||||
};
|
||||
|
||||
|
||||
#ifdef TC_HEADER_Platform_Exception
|
||||
|
||||
#define TC_EXCEPTION(NAME) TC_EXCEPTION_DECL(NAME,Exception)
|
||||
|
||||
#undef TC_EXCEPTION_SET
|
||||
#define TC_EXCEPTION_SET \
|
||||
TC_EXCEPTION_NODECL (Pkcs11Exception); \
|
||||
TC_EXCEPTION (InvalidSecurityTokenKeyfilePath); \
|
||||
TC_EXCEPTION (SecurityTokenLibraryNotInitialized); \
|
||||
TC_EXCEPTION (SecurityTokenKeyfileAlreadyExists); \
|
||||
TC_EXCEPTION (SecurityTokenKeyfileNotFound);
|
||||
|
||||
TC_EXCEPTION_SET;
|
||||
|
||||
#undef TC_EXCEPTION
|
||||
|
||||
#else // !TC_HEADER_Platform_Exception
|
||||
|
||||
struct SecurityTokenLibraryNotInitialized : public Exception
|
||||
{
|
||||
void Show (HWND parent) const { Error (SecurityTokenLibraryPath[0] == 0 ? "NO_PKCS11_MODULE_SPECIFIED" : "PKCS11_MODULE_INIT_FAILED", parent); }
|
||||
};
|
||||
|
||||
struct InvalidSecurityTokenKeyfilePath : public Exception
|
||||
{
|
||||
void Show (HWND parent) const { Error ("INVALID_TOKEN_KEYFILE_PATH", parent); }
|
||||
};
|
||||
|
||||
struct SecurityTokenKeyfileAlreadyExists : public Exception
|
||||
{
|
||||
void Show (HWND parent) const { Error ("TOKEN_KEYFILE_ALREADY_EXISTS", parent); }
|
||||
};
|
||||
|
||||
struct SecurityTokenKeyfileNotFound : public Exception
|
||||
{
|
||||
void Show (HWND parent) const { Error ("TOKEN_KEYFILE_NOT_FOUND", parent); }
|
||||
};
|
||||
|
||||
#endif // !TC_HEADER_Platform_Exception
|
||||
|
||||
|
||||
struct Pkcs11Session
|
||||
{
|
||||
Pkcs11Session () : Handle (CK_UNAVAILABLE_INFORMATION), UserLoggedIn (false) { }
|
||||
|
||||
CK_SESSION_HANDLE Handle;
|
||||
bool UserLoggedIn;
|
||||
};
|
||||
|
||||
struct GetPinFunctor
|
||||
{
|
||||
virtual ~GetPinFunctor () { }
|
||||
virtual void operator() (string &str) = 0;
|
||||
};
|
||||
|
||||
struct SendExceptionFunctor
|
||||
{
|
||||
virtual ~SendExceptionFunctor () { }
|
||||
virtual void operator() (const Exception &e) = 0;
|
||||
};
|
||||
|
||||
class SecurityToken
|
||||
{
|
||||
public:
|
||||
static void CloseAllSessions () throw ();
|
||||
static void CloseLibrary ();
|
||||
static void CreateKeyfile (CK_SLOT_ID slotId, vector <byte> &keyfileData, const string &name);
|
||||
static void DeleteKeyfile (const SecurityTokenKeyfile &keyfile);
|
||||
static vector <SecurityTokenKeyfile> GetAvailableKeyfiles (CK_SLOT_ID *slotIdFilter = nullptr, const wstring keyfileIdFilter = wstring(), char* pin = nullptr);
|
||||
static void GetKeyfileData (const SecurityTokenKeyfile &keyfile, vector <byte> &keyfileData);
|
||||
static void GetKeyfileData (const SecurityTokenKeyfile &keyfile, char* pin, vector <byte> &keyfileData);
|
||||
static list <SecurityTokenInfo> GetAvailableTokens ();
|
||||
static SecurityTokenInfo GetTokenInfo (CK_SLOT_ID slotId);
|
||||
#ifdef TC_WINDOWS
|
||||
static void InitLibrary (const wstring &pkcs11LibraryPath, auto_ptr <GetPinFunctor> pinCallback, auto_ptr <SendExceptionFunctor> warningCallback);
|
||||
#else
|
||||
static void InitLibrary (const string &pkcs11LibraryPath, auto_ptr <GetPinFunctor> pinCallback, auto_ptr <SendExceptionFunctor> warningCallback);
|
||||
#endif
|
||||
static bool IsInitialized () { return Initialized; }
|
||||
static bool IsKeyfilePathValid (const wstring &securityTokenKeyfilePath);
|
||||
|
||||
static const size_t MaxPasswordLength = 128;
|
||||
|
||||
protected:
|
||||
static void CloseSession (CK_SLOT_ID slotId);
|
||||
static vector <CK_OBJECT_HANDLE> GetObjects (CK_SLOT_ID slotId, CK_ATTRIBUTE_TYPE objectClass);
|
||||
static void GetObjectAttribute (CK_SLOT_ID slotId, CK_OBJECT_HANDLE tokenObject, CK_ATTRIBUTE_TYPE attributeType, vector <byte> &attributeValue);
|
||||
static list <CK_SLOT_ID> GetTokenSlots ();
|
||||
static void Login (CK_SLOT_ID slotId, const char* pin);
|
||||
static void LoginUserIfRequired (CK_SLOT_ID slotId, char* cmdPin = nullptr);
|
||||
static void OpenSession (CK_SLOT_ID slotId);
|
||||
static void CheckLibraryStatus ();
|
||||
|
||||
static bool Initialized;
|
||||
static auto_ptr <GetPinFunctor> PinCallback;
|
||||
static CK_FUNCTION_LIST_PTR Pkcs11Functions;
|
||||
#ifdef TC_WINDOWS
|
||||
static HMODULE Pkcs11LibraryHandle;
|
||||
#else
|
||||
static void *Pkcs11LibraryHandle;
|
||||
#endif
|
||||
static map <CK_SLOT_ID, Pkcs11Session> Sessions;
|
||||
static auto_ptr <SendExceptionFunctor> WarningCallback;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // TC_HEADER_Common_SecurityToken
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Common_SecurityToken
|
||||
#define TC_HEADER_Common_SecurityToken
|
||||
|
||||
#include "Platform/PlatformBase.h"
|
||||
#if defined (TC_WINDOWS) && !defined (TC_PROTOTYPE)
|
||||
# include "Exception.h"
|
||||
#else
|
||||
# include "Platform/Exception.h"
|
||||
#endif
|
||||
|
||||
#ifndef NULL_PTR
|
||||
# define NULL_PTR 0
|
||||
#endif
|
||||
#define CK_PTR *
|
||||
#define CK_CALLBACK_FUNCTION(RET_TYPE, NAME) RET_TYPE (* NAME)
|
||||
|
||||
#ifdef TC_WINDOWS
|
||||
|
||||
# include <windows.h>
|
||||
|
||||
# define CK_DEFINE_FUNCTION(RET_TYPE, NAME) RET_TYPE __declspec(dllexport) NAME
|
||||
# define CK_DECLARE_FUNCTION(RET_TYPE, NAME) RET_TYPE __declspec(dllimport) NAME
|
||||
# define CK_DECLARE_FUNCTION_POINTER(RET_TYPE, NAME) RET_TYPE __declspec(dllimport) (* NAME)
|
||||
|
||||
# pragma pack(push, cryptoki, 1)
|
||||
# include <pkcs11.h>
|
||||
# pragma pack(pop, cryptoki)
|
||||
|
||||
#else // !TC_WINDOWS
|
||||
|
||||
# define CK_DEFINE_FUNCTION(RET_TYPE, NAME) RET_TYPE NAME
|
||||
# define CK_DECLARE_FUNCTION(RET_TYPE, NAME) RET_TYPE NAME
|
||||
# define CK_DECLARE_FUNCTION_POINTER(RET_TYPE, NAME) RET_TYPE (* NAME)
|
||||
|
||||
# include <pkcs11.h>
|
||||
|
||||
#endif // !TC_WINDOWS
|
||||
|
||||
|
||||
#define TC_SECURITY_TOKEN_KEYFILE_URL_PREFIX L"token://"
|
||||
#define TC_SECURITY_TOKEN_KEYFILE_URL_SLOT L"slot"
|
||||
#define TC_SECURITY_TOKEN_KEYFILE_URL_FILE L"file"
|
||||
|
||||
namespace VeraCrypt
|
||||
{
|
||||
struct SecurityTokenInfo
|
||||
{
|
||||
CK_SLOT_ID SlotId;
|
||||
CK_FLAGS Flags;
|
||||
wstring Label;
|
||||
string LabelUtf8;
|
||||
};
|
||||
|
||||
struct SecurityTokenKeyfilePath
|
||||
{
|
||||
SecurityTokenKeyfilePath () { }
|
||||
SecurityTokenKeyfilePath (const wstring &path) : Path (path) { }
|
||||
operator wstring () const { return Path; }
|
||||
wstring Path;
|
||||
};
|
||||
|
||||
struct SecurityTokenKeyfile
|
||||
{
|
||||
SecurityTokenKeyfile () : Handle(CK_INVALID_HANDLE), SlotId(CK_UNAVAILABLE_INFORMATION) { Token.SlotId = CK_UNAVAILABLE_INFORMATION; Token.Flags = 0; }
|
||||
SecurityTokenKeyfile (const SecurityTokenKeyfilePath &path, char* pin = nullptr);
|
||||
|
||||
operator SecurityTokenKeyfilePath () const;
|
||||
|
||||
CK_OBJECT_HANDLE Handle;
|
||||
wstring Id;
|
||||
string IdUtf8;
|
||||
CK_SLOT_ID SlotId;
|
||||
SecurityTokenInfo Token;
|
||||
};
|
||||
|
||||
struct Pkcs11Exception : public Exception
|
||||
{
|
||||
Pkcs11Exception (CK_RV errorCode = (CK_RV) -1)
|
||||
: ErrorCode (errorCode),
|
||||
SubjectErrorCodeValid (false),
|
||||
SubjectErrorCode( (uint64) -1)
|
||||
{
|
||||
}
|
||||
|
||||
Pkcs11Exception (CK_RV errorCode, uint64 subjectErrorCode)
|
||||
: ErrorCode (errorCode),
|
||||
SubjectErrorCodeValid (true),
|
||||
SubjectErrorCode (subjectErrorCode)
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef TC_HEADER_Platform_Exception
|
||||
virtual ~Pkcs11Exception () throw () { }
|
||||
TC_SERIALIZABLE_EXCEPTION (Pkcs11Exception);
|
||||
#else
|
||||
void Show (HWND parent) const;
|
||||
#endif
|
||||
operator string () const;
|
||||
CK_RV GetErrorCode () const { return ErrorCode; }
|
||||
|
||||
protected:
|
||||
CK_RV ErrorCode;
|
||||
bool SubjectErrorCodeValid;
|
||||
uint64 SubjectErrorCode;
|
||||
};
|
||||
|
||||
|
||||
#ifdef TC_HEADER_Platform_Exception
|
||||
|
||||
#define TC_EXCEPTION(NAME) TC_EXCEPTION_DECL(NAME,Exception)
|
||||
|
||||
#undef TC_EXCEPTION_SET
|
||||
#define TC_EXCEPTION_SET \
|
||||
TC_EXCEPTION_NODECL (Pkcs11Exception); \
|
||||
TC_EXCEPTION (InvalidSecurityTokenKeyfilePath); \
|
||||
TC_EXCEPTION (SecurityTokenLibraryNotInitialized); \
|
||||
TC_EXCEPTION (SecurityTokenKeyfileAlreadyExists); \
|
||||
TC_EXCEPTION (SecurityTokenKeyfileNotFound);
|
||||
|
||||
TC_EXCEPTION_SET;
|
||||
|
||||
#undef TC_EXCEPTION
|
||||
|
||||
#else // !TC_HEADER_Platform_Exception
|
||||
|
||||
struct SecurityTokenLibraryNotInitialized : public Exception
|
||||
{
|
||||
void Show (HWND parent) const { Error (SecurityTokenLibraryPath[0] == 0 ? "NO_PKCS11_MODULE_SPECIFIED" : "PKCS11_MODULE_INIT_FAILED", parent); }
|
||||
};
|
||||
|
||||
struct InvalidSecurityTokenKeyfilePath : public Exception
|
||||
{
|
||||
void Show (HWND parent) const { Error ("INVALID_TOKEN_KEYFILE_PATH", parent); }
|
||||
};
|
||||
|
||||
struct SecurityTokenKeyfileAlreadyExists : public Exception
|
||||
{
|
||||
void Show (HWND parent) const { Error ("TOKEN_KEYFILE_ALREADY_EXISTS", parent); }
|
||||
};
|
||||
|
||||
struct SecurityTokenKeyfileNotFound : public Exception
|
||||
{
|
||||
void Show (HWND parent) const { Error ("TOKEN_KEYFILE_NOT_FOUND", parent); }
|
||||
};
|
||||
|
||||
#endif // !TC_HEADER_Platform_Exception
|
||||
|
||||
|
||||
struct Pkcs11Session
|
||||
{
|
||||
Pkcs11Session () : Handle (CK_UNAVAILABLE_INFORMATION), UserLoggedIn (false) { }
|
||||
|
||||
CK_SESSION_HANDLE Handle;
|
||||
bool UserLoggedIn;
|
||||
};
|
||||
|
||||
struct GetPinFunctor
|
||||
{
|
||||
virtual ~GetPinFunctor () { }
|
||||
virtual void operator() (string &str) = 0;
|
||||
};
|
||||
|
||||
struct SendExceptionFunctor
|
||||
{
|
||||
virtual ~SendExceptionFunctor () { }
|
||||
virtual void operator() (const Exception &e) = 0;
|
||||
};
|
||||
|
||||
class SecurityToken
|
||||
{
|
||||
public:
|
||||
static void CloseAllSessions () throw ();
|
||||
static void CloseLibrary ();
|
||||
static void CreateKeyfile (CK_SLOT_ID slotId, vector <byte> &keyfileData, const string &name);
|
||||
static void DeleteKeyfile (const SecurityTokenKeyfile &keyfile);
|
||||
static vector <SecurityTokenKeyfile> GetAvailableKeyfiles (CK_SLOT_ID *slotIdFilter = nullptr, const wstring keyfileIdFilter = wstring(), char* pin = nullptr);
|
||||
static void GetKeyfileData (const SecurityTokenKeyfile &keyfile, vector <byte> &keyfileData);
|
||||
static void GetKeyfileData (const SecurityTokenKeyfile &keyfile, char* pin, vector <byte> &keyfileData);
|
||||
static list <SecurityTokenInfo> GetAvailableTokens ();
|
||||
static SecurityTokenInfo GetTokenInfo (CK_SLOT_ID slotId);
|
||||
#ifdef TC_WINDOWS
|
||||
static void InitLibrary (const wstring &pkcs11LibraryPath, auto_ptr <GetPinFunctor> pinCallback, auto_ptr <SendExceptionFunctor> warningCallback);
|
||||
#else
|
||||
static void InitLibrary (const string &pkcs11LibraryPath, auto_ptr <GetPinFunctor> pinCallback, auto_ptr <SendExceptionFunctor> warningCallback);
|
||||
#endif
|
||||
static bool IsInitialized () { return Initialized; }
|
||||
static bool IsKeyfilePathValid (const wstring &securityTokenKeyfilePath);
|
||||
|
||||
static const size_t MaxPasswordLength = 128;
|
||||
|
||||
protected:
|
||||
static void CloseSession (CK_SLOT_ID slotId);
|
||||
static vector <CK_OBJECT_HANDLE> GetObjects (CK_SLOT_ID slotId, CK_ATTRIBUTE_TYPE objectClass);
|
||||
static void GetObjectAttribute (CK_SLOT_ID slotId, CK_OBJECT_HANDLE tokenObject, CK_ATTRIBUTE_TYPE attributeType, vector <byte> &attributeValue);
|
||||
static list <CK_SLOT_ID> GetTokenSlots ();
|
||||
static void Login (CK_SLOT_ID slotId, const char* pin);
|
||||
static void LoginUserIfRequired (CK_SLOT_ID slotId, char* cmdPin = nullptr);
|
||||
static void OpenSession (CK_SLOT_ID slotId);
|
||||
static void CheckLibraryStatus ();
|
||||
|
||||
static bool Initialized;
|
||||
static auto_ptr <GetPinFunctor> PinCallback;
|
||||
static CK_FUNCTION_LIST_PTR Pkcs11Functions;
|
||||
#ifdef TC_WINDOWS
|
||||
static HMODULE Pkcs11LibraryHandle;
|
||||
#else
|
||||
static void *Pkcs11LibraryHandle;
|
||||
#endif
|
||||
static map <CK_SLOT_ID, Pkcs11Session> Sessions;
|
||||
static auto_ptr <SendExceptionFunctor> WarningCallback;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // TC_HEADER_Common_SecurityToken
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
TARGETNAME=Common
|
||||
TARGETTYPE=DRIVER_LIBRARY
|
||||
|
||||
INCLUDES = ..;../Crypto
|
||||
|
||||
SOURCES = \
|
||||
Cache.c \
|
||||
Crc.c \
|
||||
Crypto.c \
|
||||
EncryptionThreadPool.c \
|
||||
Endian.c \
|
||||
GfMul.c \
|
||||
Pkcs5.c \
|
||||
Volumes.c \
|
||||
Xts.c \
|
||||
Tests.c \
|
||||
Wipe.c
|
||||
TARGETNAME=Common
|
||||
TARGETTYPE=DRIVER_LIBRARY
|
||||
|
||||
INCLUDES = ..;../Crypto
|
||||
|
||||
SOURCES = \
|
||||
Cache.c \
|
||||
Crc.c \
|
||||
Crypto.c \
|
||||
EncryptionThreadPool.c \
|
||||
Endian.c \
|
||||
GfMul.c \
|
||||
Pkcs5.c \
|
||||
Volumes.c \
|
||||
Xts.c \
|
||||
Tests.c \
|
||||
Wipe.c
|
||||
|
||||
@@ -1,323 +1,323 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#ifndef TCDEFS_H
|
||||
#define TCDEFS_H
|
||||
|
||||
#define TC_APP_NAME "VeraCrypt"
|
||||
|
||||
// Version displayed to user
|
||||
#define VERSION_STRING "1.17"
|
||||
|
||||
// Version number to compare against driver
|
||||
#define VERSION_NUM 0x0117
|
||||
|
||||
// Release date
|
||||
#define TC_STR_RELEASE_DATE L"February 13th, 2016"
|
||||
#define TC_RELEASE_DATE_YEAR 2016
|
||||
#define TC_RELEASE_DATE_MONTH 2
|
||||
|
||||
#define BYTES_PER_KB 1024LL
|
||||
#define BYTES_PER_MB 1048576LL
|
||||
#define BYTES_PER_GB 1073741824LL
|
||||
#define BYTES_PER_TB 1099511627776LL
|
||||
#define BYTES_PER_PB 1125899906842624LL
|
||||
|
||||
/* GUI/driver errors */
|
||||
|
||||
#define WIDE(x) (LPWSTR)L##x
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
typedef __int8 int8;
|
||||
typedef __int16 int16;
|
||||
typedef __int32 int32;
|
||||
typedef unsigned __int8 byte;
|
||||
typedef unsigned __int16 uint16;
|
||||
typedef unsigned __int32 uint32;
|
||||
|
||||
#ifdef TC_NO_COMPILER_INT64
|
||||
typedef unsigned __int32 TC_LARGEST_COMPILER_UINT;
|
||||
#else
|
||||
typedef unsigned __int64 TC_LARGEST_COMPILER_UINT;
|
||||
typedef __int64 int64;
|
||||
typedef unsigned __int64 uint64;
|
||||
#define LL(x) x##ui64
|
||||
#endif
|
||||
|
||||
#else // !_MSC_VER
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
|
||||
typedef int8_t int8;
|
||||
typedef int16_t int16;
|
||||
typedef int32_t int32;
|
||||
typedef int64_t int64;
|
||||
typedef uint8_t byte;
|
||||
typedef uint16_t uint16;
|
||||
typedef uint32_t uint32;
|
||||
typedef uint64_t uint64;
|
||||
|
||||
#define LL(x) x##ULL
|
||||
|
||||
#if UCHAR_MAX != 0xffU
|
||||
#error UCHAR_MAX != 0xff
|
||||
#endif
|
||||
#define __int8 char
|
||||
|
||||
#if USHRT_MAX != 0xffffU
|
||||
#error USHRT_MAX != 0xffff
|
||||
#endif
|
||||
#define __int16 short
|
||||
|
||||
#if UINT_MAX != 0xffffffffU
|
||||
#error UINT_MAX != 0xffffffff
|
||||
#endif
|
||||
#define __int32 int
|
||||
|
||||
typedef uint64 TC_LARGEST_COMPILER_UINT;
|
||||
|
||||
#define BOOL int
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#endif // !_MSC_VER
|
||||
|
||||
#define TC_INT_TYPES_DEFINED
|
||||
|
||||
// Integer types required by Cryptolib
|
||||
typedef unsigned __int8 uint_8t;
|
||||
typedef unsigned __int16 uint_16t;
|
||||
typedef unsigned __int32 uint_32t;
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
typedef uint64 uint_64t;
|
||||
#endif
|
||||
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
unsigned __int32 LowPart;
|
||||
unsigned __int32 HighPart;
|
||||
};
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
uint64 Value;
|
||||
#endif
|
||||
|
||||
} UINT64_STRUCT;
|
||||
|
||||
#ifndef __has_builtin // Optional of course
|
||||
#define __has_builtin(x) 0 // Compatibility with non-clang compilers
|
||||
#endif
|
||||
|
||||
#ifdef TC_WINDOWS_BOOT
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C"
|
||||
# endif
|
||||
void ThrowFatalException (int line);
|
||||
|
||||
# define TC_THROW_FATAL_EXCEPTION ThrowFatalException (__LINE__)
|
||||
#elif defined (TC_WINDOWS_DRIVER)
|
||||
# define TC_THROW_FATAL_EXCEPTION KeBugCheckEx (SECURITY_SYSTEM, __LINE__, 0, 0, 'VC')
|
||||
#elif (defined(__clang__) && __has_builtin(__builtin_trap)) \
|
||||
|| (defined(__GNUC__ ) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))) \
|
||||
|| (__has_builtin(__builtin_trap))
|
||||
# define TC_THROW_FATAL_EXCEPTION __builtin_trap()
|
||||
#else
|
||||
# define TC_THROW_FATAL_EXCEPTION *(char *) 0 = 0
|
||||
#endif
|
||||
|
||||
#ifdef __COVERITY__
|
||||
#undef TC_THROW_FATAL_EXCEPTION
|
||||
#define TC_THROW_FATAL_EXCEPTION __coverity_panic__()
|
||||
#endif
|
||||
|
||||
#ifdef TC_WINDOWS_DRIVER
|
||||
|
||||
#include <ntifs.h>
|
||||
#include <ntddk.h> /* Standard header file for nt drivers */
|
||||
#include <ntdddisk.h> /* Standard I/O control codes */
|
||||
|
||||
#define TCalloc(size) ((void *) ExAllocatePoolWithTag( NonPagedPool, size, 'MMCV' ))
|
||||
#define TCfree(memblock) ExFreePoolWithTag( memblock, 'MMCV' )
|
||||
|
||||
#define DEVICE_DRIVER
|
||||
|
||||
#ifndef BOOL
|
||||
typedef int BOOL;
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE !TRUE
|
||||
#endif
|
||||
|
||||
#else /* !TC_WINDOWS_DRIVER */
|
||||
|
||||
#define TCalloc malloc
|
||||
#define TCfree free
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#ifndef TC_LOCAL_WIN32_WINNT_OVERRIDE
|
||||
# undef _WIN32_WINNT
|
||||
# define _WIN32_WINNT 0x0501 /* Does not apply to the driver */
|
||||
#endif
|
||||
|
||||
#include <windows.h> /* Windows header */
|
||||
#include <commctrl.h> /* The common controls */
|
||||
#include <process.h> /* Process control */
|
||||
#include <winioctl.h>
|
||||
#include <stdio.h> /* For sprintf */
|
||||
#include <tchar.h>
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#endif /* !TC_WINDOWS_DRIVER */
|
||||
|
||||
#ifndef TC_TO_STRING
|
||||
# define TC_TO_STRING2(n) #n
|
||||
# define TC_TO_STRING(n) TC_TO_STRING2(n)
|
||||
#endif
|
||||
|
||||
#ifdef DEVICE_DRIVER
|
||||
# if defined (DEBUG) || 0
|
||||
# if 1 // DbgPrintEx is not available on Windows 2000
|
||||
# define Dump DbgPrint
|
||||
# else
|
||||
# define Dump(...) DbgPrintEx (DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, __VA_ARGS__)
|
||||
# endif
|
||||
# define DumpMem(...) DumpMemory (__VA_ARGS__)
|
||||
# else
|
||||
# define Dump(...)
|
||||
# define DumpMem(...)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined (trace_msg) && !defined (TC_WINDOWS_BOOT)
|
||||
# ifdef DEBUG
|
||||
# ifdef DEVICE_DRIVER
|
||||
# define trace_msg Dump
|
||||
# elif defined (_WIN32)
|
||||
# define trace_msg(...) do { char msg[2048]; StringCbPrintfA (msg, sizeof (msg), __VA_ARGS__); OutputDebugString (msg); } while (0)
|
||||
# endif
|
||||
# define trace_point trace_msg (__FUNCTION__ ":" TC_TO_STRING(__LINE__) "\n")
|
||||
# else
|
||||
# define trace_msg(...)
|
||||
# define trace_point
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef DEVICE_DRIVER
|
||||
# define TC_EVENT KEVENT
|
||||
# define TC_WAIT_EVENT(EVENT) KeWaitForSingleObject (&EVENT, Executive, KernelMode, FALSE, NULL)
|
||||
#elif defined (_WIN32)
|
||||
# define TC_EVENT HANDLE
|
||||
# define TC_WAIT_EVENT(EVENT) WaitForSingleObject (EVENT, INFINITE)
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define burn(mem,size) do { volatile char *burnm = (volatile char *)(mem); size_t burnc = size; RtlSecureZeroMemory (mem, size); while (burnc--) *burnm++ = 0; } while (0)
|
||||
#else
|
||||
#define burn(mem,size) do { volatile char *burnm = (volatile char *)(mem); int burnc = size; while (burnc--) *burnm++ = 0; } while (0)
|
||||
#endif
|
||||
|
||||
// The size of the memory area to wipe is in bytes amd it must be a multiple of 8.
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
# define FAST_ERASE64(mem,size) do { volatile uint64 *burnm = (volatile uint64 *)(mem); int burnc = size >> 3; while (burnc--) *burnm++ = 0; } while (0)
|
||||
#else
|
||||
# define FAST_ERASE64(mem,size) do { volatile unsigned __int32 *burnm = (volatile unsigned __int32 *)(mem); int burnc = size >> 2; while (burnc--) *burnm++ = 0; } while (0)
|
||||
#endif
|
||||
|
||||
#ifdef TC_WINDOWS_BOOT
|
||||
# ifndef max
|
||||
# define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
# endif
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C"
|
||||
# endif
|
||||
void EraseMemory (void *memory, int size);
|
||||
|
||||
# undef burn
|
||||
# define burn EraseMemory
|
||||
#endif
|
||||
|
||||
#ifdef MAX_PATH
|
||||
#define TC_MAX_PATH MAX_PATH
|
||||
#else
|
||||
#define TC_MAX_PATH 260 /* Includes the null terminator */
|
||||
#endif
|
||||
|
||||
#define TC_STR_RELEASED_BY L"Released by IDRIX on " TC_STR_RELEASE_DATE
|
||||
|
||||
#define MAX_URL_LENGTH 2084 /* Internet Explorer limit. Includes the terminating null character. */
|
||||
|
||||
#define TC_HOMEPAGE "http://www.idrix.fr/"
|
||||
#define TC_APPLINK "https://veracrypt.codeplex.com"
|
||||
#define TC_APPLINK_SECURE "https://veracrypt.codeplex.com"
|
||||
|
||||
enum
|
||||
{
|
||||
/* WARNING: ADD ANY NEW CODES AT THE END (DO NOT INSERT THEM BETWEEN EXISTING). DO *NOT* DELETE ANY
|
||||
EXISTING CODES! Changing these values or their meanings may cause incompatibility with other versions
|
||||
(for example, if a new version of the TrueCrypt installer receives an error code from an installed
|
||||
driver whose version is lower, it will report and interpret the error incorrectly). */
|
||||
|
||||
ERR_SUCCESS = 0,
|
||||
ERR_OS_ERROR = 1,
|
||||
ERR_OUTOFMEMORY = 2,
|
||||
ERR_PASSWORD_WRONG = 3,
|
||||
ERR_VOL_FORMAT_BAD = 4,
|
||||
ERR_DRIVE_NOT_FOUND = 5,
|
||||
ERR_FILES_OPEN = 6,
|
||||
ERR_VOL_SIZE_WRONG = 7,
|
||||
ERR_COMPRESSION_NOT_SUPPORTED = 8,
|
||||
ERR_PASSWORD_CHANGE_VOL_TYPE = 9,
|
||||
ERR_PASSWORD_CHANGE_VOL_VERSION = 10,
|
||||
ERR_VOL_SEEKING = 11,
|
||||
ERR_VOL_WRITING = 12,
|
||||
ERR_FILES_OPEN_LOCK = 13,
|
||||
ERR_VOL_READING = 14,
|
||||
ERR_DRIVER_VERSION = 15,
|
||||
ERR_NEW_VERSION_REQUIRED = 16,
|
||||
ERR_CIPHER_INIT_FAILURE = 17,
|
||||
ERR_CIPHER_INIT_WEAK_KEY = 18,
|
||||
ERR_SELF_TESTS_FAILED = 19,
|
||||
ERR_SECTOR_SIZE_INCOMPATIBLE = 20,
|
||||
ERR_VOL_ALREADY_MOUNTED = 21,
|
||||
ERR_NO_FREE_DRIVES = 22,
|
||||
ERR_FILE_OPEN_FAILED = 23,
|
||||
ERR_VOL_MOUNT_FAILED = 24,
|
||||
DEPRECATED_ERR_INVALID_DEVICE = 25,
|
||||
ERR_ACCESS_DENIED = 26,
|
||||
ERR_MODE_INIT_FAILED = 27,
|
||||
ERR_DONT_REPORT = 28,
|
||||
ERR_ENCRYPTION_NOT_COMPLETED = 29,
|
||||
ERR_PARAMETER_INCORRECT = 30,
|
||||
ERR_SYS_HIDVOL_HEAD_REENC_MODE_WRONG = 31,
|
||||
ERR_NONSYS_INPLACE_ENC_INCOMPLETE = 32,
|
||||
ERR_USER_ABORT = 33,
|
||||
ERR_UNSUPPORTED_TRUECRYPT_FORMAT = 34,
|
||||
ERR_RAND_INIT_FAILED = 35,
|
||||
ERR_CAPI_INIT_FAILED = 36
|
||||
};
|
||||
|
||||
#endif // #ifndef TCDEFS_H
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#ifndef TCDEFS_H
|
||||
#define TCDEFS_H
|
||||
|
||||
#define TC_APP_NAME "VeraCrypt"
|
||||
|
||||
// Version displayed to user
|
||||
#define VERSION_STRING "1.17"
|
||||
|
||||
// Version number to compare against driver
|
||||
#define VERSION_NUM 0x0117
|
||||
|
||||
// Release date
|
||||
#define TC_STR_RELEASE_DATE L"February 13th, 2016"
|
||||
#define TC_RELEASE_DATE_YEAR 2016
|
||||
#define TC_RELEASE_DATE_MONTH 2
|
||||
|
||||
#define BYTES_PER_KB 1024LL
|
||||
#define BYTES_PER_MB 1048576LL
|
||||
#define BYTES_PER_GB 1073741824LL
|
||||
#define BYTES_PER_TB 1099511627776LL
|
||||
#define BYTES_PER_PB 1125899906842624LL
|
||||
|
||||
/* GUI/driver errors */
|
||||
|
||||
#define WIDE(x) (LPWSTR)L##x
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
typedef __int8 int8;
|
||||
typedef __int16 int16;
|
||||
typedef __int32 int32;
|
||||
typedef unsigned __int8 byte;
|
||||
typedef unsigned __int16 uint16;
|
||||
typedef unsigned __int32 uint32;
|
||||
|
||||
#ifdef TC_NO_COMPILER_INT64
|
||||
typedef unsigned __int32 TC_LARGEST_COMPILER_UINT;
|
||||
#else
|
||||
typedef unsigned __int64 TC_LARGEST_COMPILER_UINT;
|
||||
typedef __int64 int64;
|
||||
typedef unsigned __int64 uint64;
|
||||
#define LL(x) x##ui64
|
||||
#endif
|
||||
|
||||
#else // !_MSC_VER
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
|
||||
typedef int8_t int8;
|
||||
typedef int16_t int16;
|
||||
typedef int32_t int32;
|
||||
typedef int64_t int64;
|
||||
typedef uint8_t byte;
|
||||
typedef uint16_t uint16;
|
||||
typedef uint32_t uint32;
|
||||
typedef uint64_t uint64;
|
||||
|
||||
#define LL(x) x##ULL
|
||||
|
||||
#if UCHAR_MAX != 0xffU
|
||||
#error UCHAR_MAX != 0xff
|
||||
#endif
|
||||
#define __int8 char
|
||||
|
||||
#if USHRT_MAX != 0xffffU
|
||||
#error USHRT_MAX != 0xffff
|
||||
#endif
|
||||
#define __int16 short
|
||||
|
||||
#if UINT_MAX != 0xffffffffU
|
||||
#error UINT_MAX != 0xffffffff
|
||||
#endif
|
||||
#define __int32 int
|
||||
|
||||
typedef uint64 TC_LARGEST_COMPILER_UINT;
|
||||
|
||||
#define BOOL int
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#endif // !_MSC_VER
|
||||
|
||||
#define TC_INT_TYPES_DEFINED
|
||||
|
||||
// Integer types required by Cryptolib
|
||||
typedef unsigned __int8 uint_8t;
|
||||
typedef unsigned __int16 uint_16t;
|
||||
typedef unsigned __int32 uint_32t;
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
typedef uint64 uint_64t;
|
||||
#endif
|
||||
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
unsigned __int32 LowPart;
|
||||
unsigned __int32 HighPart;
|
||||
};
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
uint64 Value;
|
||||
#endif
|
||||
|
||||
} UINT64_STRUCT;
|
||||
|
||||
#ifndef __has_builtin // Optional of course
|
||||
#define __has_builtin(x) 0 // Compatibility with non-clang compilers
|
||||
#endif
|
||||
|
||||
#ifdef TC_WINDOWS_BOOT
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C"
|
||||
# endif
|
||||
void ThrowFatalException (int line);
|
||||
|
||||
# define TC_THROW_FATAL_EXCEPTION ThrowFatalException (__LINE__)
|
||||
#elif defined (TC_WINDOWS_DRIVER)
|
||||
# define TC_THROW_FATAL_EXCEPTION KeBugCheckEx (SECURITY_SYSTEM, __LINE__, 0, 0, 'VC')
|
||||
#elif (defined(__clang__) && __has_builtin(__builtin_trap)) \
|
||||
|| (defined(__GNUC__ ) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))) \
|
||||
|| (__has_builtin(__builtin_trap))
|
||||
# define TC_THROW_FATAL_EXCEPTION __builtin_trap()
|
||||
#else
|
||||
# define TC_THROW_FATAL_EXCEPTION *(char *) 0 = 0
|
||||
#endif
|
||||
|
||||
#ifdef __COVERITY__
|
||||
#undef TC_THROW_FATAL_EXCEPTION
|
||||
#define TC_THROW_FATAL_EXCEPTION __coverity_panic__()
|
||||
#endif
|
||||
|
||||
#ifdef TC_WINDOWS_DRIVER
|
||||
|
||||
#include <ntifs.h>
|
||||
#include <ntddk.h> /* Standard header file for nt drivers */
|
||||
#include <ntdddisk.h> /* Standard I/O control codes */
|
||||
|
||||
#define TCalloc(size) ((void *) ExAllocatePoolWithTag( NonPagedPool, size, 'MMCV' ))
|
||||
#define TCfree(memblock) ExFreePoolWithTag( memblock, 'MMCV' )
|
||||
|
||||
#define DEVICE_DRIVER
|
||||
|
||||
#ifndef BOOL
|
||||
typedef int BOOL;
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE !TRUE
|
||||
#endif
|
||||
|
||||
#else /* !TC_WINDOWS_DRIVER */
|
||||
|
||||
#define TCalloc malloc
|
||||
#define TCfree free
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#ifndef TC_LOCAL_WIN32_WINNT_OVERRIDE
|
||||
# undef _WIN32_WINNT
|
||||
# define _WIN32_WINNT 0x0501 /* Does not apply to the driver */
|
||||
#endif
|
||||
|
||||
#include <windows.h> /* Windows header */
|
||||
#include <commctrl.h> /* The common controls */
|
||||
#include <process.h> /* Process control */
|
||||
#include <winioctl.h>
|
||||
#include <stdio.h> /* For sprintf */
|
||||
#include <tchar.h>
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#endif /* !TC_WINDOWS_DRIVER */
|
||||
|
||||
#ifndef TC_TO_STRING
|
||||
# define TC_TO_STRING2(n) #n
|
||||
# define TC_TO_STRING(n) TC_TO_STRING2(n)
|
||||
#endif
|
||||
|
||||
#ifdef DEVICE_DRIVER
|
||||
# if defined (DEBUG) || 0
|
||||
# if 1 // DbgPrintEx is not available on Windows 2000
|
||||
# define Dump DbgPrint
|
||||
# else
|
||||
# define Dump(...) DbgPrintEx (DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, __VA_ARGS__)
|
||||
# endif
|
||||
# define DumpMem(...) DumpMemory (__VA_ARGS__)
|
||||
# else
|
||||
# define Dump(...)
|
||||
# define DumpMem(...)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined (trace_msg) && !defined (TC_WINDOWS_BOOT)
|
||||
# ifdef DEBUG
|
||||
# ifdef DEVICE_DRIVER
|
||||
# define trace_msg Dump
|
||||
# elif defined (_WIN32)
|
||||
# define trace_msg(...) do { char msg[2048]; StringCbPrintfA (msg, sizeof (msg), __VA_ARGS__); OutputDebugString (msg); } while (0)
|
||||
# endif
|
||||
# define trace_point trace_msg (__FUNCTION__ ":" TC_TO_STRING(__LINE__) "\n")
|
||||
# else
|
||||
# define trace_msg(...)
|
||||
# define trace_point
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef DEVICE_DRIVER
|
||||
# define TC_EVENT KEVENT
|
||||
# define TC_WAIT_EVENT(EVENT) KeWaitForSingleObject (&EVENT, Executive, KernelMode, FALSE, NULL)
|
||||
#elif defined (_WIN32)
|
||||
# define TC_EVENT HANDLE
|
||||
# define TC_WAIT_EVENT(EVENT) WaitForSingleObject (EVENT, INFINITE)
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define burn(mem,size) do { volatile char *burnm = (volatile char *)(mem); size_t burnc = size; RtlSecureZeroMemory (mem, size); while (burnc--) *burnm++ = 0; } while (0)
|
||||
#else
|
||||
#define burn(mem,size) do { volatile char *burnm = (volatile char *)(mem); int burnc = size; while (burnc--) *burnm++ = 0; } while (0)
|
||||
#endif
|
||||
|
||||
// The size of the memory area to wipe is in bytes amd it must be a multiple of 8.
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
# define FAST_ERASE64(mem,size) do { volatile uint64 *burnm = (volatile uint64 *)(mem); int burnc = size >> 3; while (burnc--) *burnm++ = 0; } while (0)
|
||||
#else
|
||||
# define FAST_ERASE64(mem,size) do { volatile unsigned __int32 *burnm = (volatile unsigned __int32 *)(mem); int burnc = size >> 2; while (burnc--) *burnm++ = 0; } while (0)
|
||||
#endif
|
||||
|
||||
#ifdef TC_WINDOWS_BOOT
|
||||
# ifndef max
|
||||
# define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
# endif
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C"
|
||||
# endif
|
||||
void EraseMemory (void *memory, int size);
|
||||
|
||||
# undef burn
|
||||
# define burn EraseMemory
|
||||
#endif
|
||||
|
||||
#ifdef MAX_PATH
|
||||
#define TC_MAX_PATH MAX_PATH
|
||||
#else
|
||||
#define TC_MAX_PATH 260 /* Includes the null terminator */
|
||||
#endif
|
||||
|
||||
#define TC_STR_RELEASED_BY L"Released by IDRIX on " TC_STR_RELEASE_DATE
|
||||
|
||||
#define MAX_URL_LENGTH 2084 /* Internet Explorer limit. Includes the terminating null character. */
|
||||
|
||||
#define TC_HOMEPAGE "http://www.idrix.fr/"
|
||||
#define TC_APPLINK "https://veracrypt.codeplex.com"
|
||||
#define TC_APPLINK_SECURE "https://veracrypt.codeplex.com"
|
||||
|
||||
enum
|
||||
{
|
||||
/* WARNING: ADD ANY NEW CODES AT THE END (DO NOT INSERT THEM BETWEEN EXISTING). DO *NOT* DELETE ANY
|
||||
EXISTING CODES! Changing these values or their meanings may cause incompatibility with other versions
|
||||
(for example, if a new version of the TrueCrypt installer receives an error code from an installed
|
||||
driver whose version is lower, it will report and interpret the error incorrectly). */
|
||||
|
||||
ERR_SUCCESS = 0,
|
||||
ERR_OS_ERROR = 1,
|
||||
ERR_OUTOFMEMORY = 2,
|
||||
ERR_PASSWORD_WRONG = 3,
|
||||
ERR_VOL_FORMAT_BAD = 4,
|
||||
ERR_DRIVE_NOT_FOUND = 5,
|
||||
ERR_FILES_OPEN = 6,
|
||||
ERR_VOL_SIZE_WRONG = 7,
|
||||
ERR_COMPRESSION_NOT_SUPPORTED = 8,
|
||||
ERR_PASSWORD_CHANGE_VOL_TYPE = 9,
|
||||
ERR_PASSWORD_CHANGE_VOL_VERSION = 10,
|
||||
ERR_VOL_SEEKING = 11,
|
||||
ERR_VOL_WRITING = 12,
|
||||
ERR_FILES_OPEN_LOCK = 13,
|
||||
ERR_VOL_READING = 14,
|
||||
ERR_DRIVER_VERSION = 15,
|
||||
ERR_NEW_VERSION_REQUIRED = 16,
|
||||
ERR_CIPHER_INIT_FAILURE = 17,
|
||||
ERR_CIPHER_INIT_WEAK_KEY = 18,
|
||||
ERR_SELF_TESTS_FAILED = 19,
|
||||
ERR_SECTOR_SIZE_INCOMPATIBLE = 20,
|
||||
ERR_VOL_ALREADY_MOUNTED = 21,
|
||||
ERR_NO_FREE_DRIVES = 22,
|
||||
ERR_FILE_OPEN_FAILED = 23,
|
||||
ERR_VOL_MOUNT_FAILED = 24,
|
||||
DEPRECATED_ERR_INVALID_DEVICE = 25,
|
||||
ERR_ACCESS_DENIED = 26,
|
||||
ERR_MODE_INIT_FAILED = 27,
|
||||
ERR_DONT_REPORT = 28,
|
||||
ERR_ENCRYPTION_NOT_COMPLETED = 29,
|
||||
ERR_PARAMETER_INCORRECT = 30,
|
||||
ERR_SYS_HIDVOL_HEAD_REENC_MODE_WRONG = 31,
|
||||
ERR_NONSYS_INPLACE_ENC_INCOMPLETE = 32,
|
||||
ERR_USER_ABORT = 33,
|
||||
ERR_UNSUPPORTED_TRUECRYPT_FORMAT = 34,
|
||||
ERR_RAND_INIT_FAILED = 35,
|
||||
ERR_CAPI_INIT_FAILED = 36
|
||||
};
|
||||
|
||||
#endif // #ifndef TCDEFS_H
|
||||
|
||||
2310
src/Common/Tests.c
2310
src/Common/Tests.c
File diff suppressed because it is too large
Load Diff
@@ -1,31 +1,31 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern unsigned char ks_tmp[MAX_EXPANDED_KEY];
|
||||
|
||||
void CipherInit2(int cipher, void* key, void* ks, int key_len);
|
||||
BOOL test_hmac_sha512 (void);
|
||||
BOOL test_hmac_ripemd160 (void);
|
||||
BOOL test_hmac_whirlpool (void);
|
||||
BOOL test_pkcs5 (void);
|
||||
BOOL TestSectorBufEncryption ();
|
||||
BOOL TestLegacySectorBufEncryption ();
|
||||
BOOL AutoTestAlgorithms (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern unsigned char ks_tmp[MAX_EXPANDED_KEY];
|
||||
|
||||
void CipherInit2(int cipher, void* key, void* ks, int key_len);
|
||||
BOOL test_hmac_sha512 (void);
|
||||
BOOL test_hmac_ripemd160 (void);
|
||||
BOOL test_hmac_whirlpool (void);
|
||||
BOOL test_pkcs5 (void);
|
||||
BOOL TestSectorBufEncryption ();
|
||||
BOOL TestLegacySectorBufEncryption ();
|
||||
BOOL AutoTestAlgorithms (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
2540
src/Common/Volumes.c
2540
src/Common/Volumes.c
File diff suppressed because it is too large
Load Diff
@@ -1,155 +1,155 @@
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#ifndef TC_HEADER_Common_Volumes
|
||||
#define TC_HEADER_Common_Volumes
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Volume header version
|
||||
#define VOLUME_HEADER_VERSION 0x0005
|
||||
|
||||
// Version number written to volume header during format;
|
||||
// specifies the minimum program version required to mount the volume
|
||||
#define TC_VOLUME_MIN_REQUIRED_PROGRAM_VERSION 0x010b
|
||||
|
||||
// Version number written (encrypted) to the key data area of an encrypted system partition/drive;
|
||||
// specifies the minimum program version required to decrypt the system partition/drive
|
||||
#define TC_SYSENC_KEYSCOPE_MIN_REQ_PROG_VERSION 0x010b
|
||||
|
||||
// Current volume format version (created by TrueCrypt 6.0+)
|
||||
#define TC_VOLUME_FORMAT_VERSION 2
|
||||
|
||||
// Version number of volume format created by TrueCrypt 1.0-5.1a
|
||||
#define TC_VOLUME_FORMAT_VERSION_PRE_6_0 1
|
||||
|
||||
// Volume header sizes
|
||||
#define TC_VOLUME_HEADER_SIZE (64 * 1024L)
|
||||
#define TC_VOLUME_HEADER_EFFECTIVE_SIZE 512
|
||||
#define TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE 512
|
||||
#define TC_VOLUME_HEADER_SIZE_LEGACY 512
|
||||
|
||||
#define TC_VOLUME_HEADER_GROUP_SIZE (2 * TC_VOLUME_HEADER_SIZE)
|
||||
#define TC_TOTAL_VOLUME_HEADERS_SIZE (4 * TC_VOLUME_HEADER_SIZE)
|
||||
|
||||
// Volume offsets
|
||||
#define TC_VOLUME_HEADER_OFFSET 0
|
||||
#define TC_HIDDEN_VOLUME_HEADER_OFFSET TC_VOLUME_HEADER_SIZE
|
||||
|
||||
// Sector sizes
|
||||
#define TC_MIN_VOLUME_SECTOR_SIZE 512
|
||||
#define TC_MAX_VOLUME_SECTOR_SIZE 4096
|
||||
#define TC_SECTOR_SIZE_FILE_HOSTED_VOLUME 512
|
||||
#define TC_SECTOR_SIZE_LEGACY 512
|
||||
|
||||
// Sector size which can be safely assumed to be supported by all BIOSes
|
||||
#define TC_SECTOR_SIZE_BIOS 512
|
||||
|
||||
#define TC_VOLUME_SMALL_SIZE_THRESHOLD (2 * BYTES_PER_MB) // Volume sizes below this threshold are considered small
|
||||
|
||||
#define TC_HIDDEN_VOLUME_HOST_FS_RESERVED_END_AREA_SIZE TC_MAX_VOLUME_SECTOR_SIZE // FAT file system fills the last sector with zeroes (marked as free; observed when quick format was performed using the OS format tool).
|
||||
#define TC_HIDDEN_VOLUME_HOST_FS_RESERVED_END_AREA_SIZE_HIGH TC_VOLUME_HEADER_GROUP_SIZE // Reserved area size used for hidden volumes larger than TC_VOLUME_SMALL_SIZE_THRESHOLD
|
||||
|
||||
#define TC_VOLUME_DATA_OFFSET TC_VOLUME_HEADER_GROUP_SIZE
|
||||
|
||||
// The offset, in bytes, of the legacy hidden volume header position from the end of the file (a positive value).
|
||||
#define TC_HIDDEN_VOLUME_HEADER_OFFSET_LEGACY (TC_VOLUME_HEADER_SIZE_LEGACY + TC_SECTOR_SIZE_LEGACY * 2)
|
||||
|
||||
#define TC_MAX_128BIT_BLOCK_VOLUME_SIZE BYTES_PER_PB // Security bound (128-bit block XTS mode)
|
||||
|
||||
// Filesystem size limits
|
||||
#define TC_MIN_FAT_FS_SIZE (9 * TC_MAX_VOLUME_SECTOR_SIZE)
|
||||
#define TC_MAX_FAT_SECTOR_COUNT 0x100000000ULL
|
||||
#define TC_MIN_NTFS_FS_SIZE (884 * TC_MAX_VOLUME_SECTOR_SIZE)
|
||||
#define TC_MAX_NTFS_FS_SIZE (128LL * BYTES_PER_TB) // NTFS volume can theoretically be up to 16 exabytes, but Windows XP and 2003 limit the size to that addressable with 32-bit clusters, i.e. max size is 128 TB (if 64-KB clusters are used).
|
||||
#define TC_MAX_FAT_CLUSTER_SIZE (256 * BYTES_PER_KB) // Windows XP/Vista may crash when writing to a filesystem using clusters larger than 256 KB
|
||||
#define TC_MIN_EXFAT_FS_SIZE (42 * TC_MAX_VOLUME_SECTOR_SIZE)
|
||||
#define TC_MAX_EXFAT_FS_SIZE (128LL * BYTES_PER_PB)
|
||||
|
||||
// Volume size limits
|
||||
#define TC_MIN_VOLUME_SIZE (TC_TOTAL_VOLUME_HEADERS_SIZE + TC_MIN_FAT_FS_SIZE)
|
||||
#define TC_MIN_VOLUME_SIZE_LEGACY (37 * TC_SECTOR_SIZE_LEGACY)
|
||||
#define TC_MAX_VOLUME_SIZE_GENERAL 0x7fffFFFFffffFFFFLL // Signed 64-bit integer file offset values
|
||||
#define TC_MAX_VOLUME_SIZE TC_MAX_128BIT_BLOCK_VOLUME_SIZE
|
||||
|
||||
#define TC_MIN_HIDDEN_VOLUME_SIZE (TC_MIN_FAT_FS_SIZE + TC_HIDDEN_VOLUME_HOST_FS_RESERVED_END_AREA_SIZE)
|
||||
|
||||
#define TC_MIN_HIDDEN_VOLUME_HOST_SIZE (TC_MIN_VOLUME_SIZE + TC_MIN_HIDDEN_VOLUME_SIZE + 2 * TC_MAX_VOLUME_SECTOR_SIZE)
|
||||
#define TC_MAX_HIDDEN_VOLUME_HOST_SIZE (TC_MAX_NTFS_FS_SIZE - TC_TOTAL_VOLUME_HEADERS_SIZE)
|
||||
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
# if TC_MAX_VOLUME_SIZE > TC_MAX_VOLUME_SIZE_GENERAL
|
||||
# error TC_MAX_VOLUME_SIZE > TC_MAX_VOLUME_SIZE_GENERAL
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define HEADER_ENCRYPTED_DATA_SIZE (TC_VOLUME_HEADER_EFFECTIVE_SIZE - HEADER_ENCRYPTED_DATA_OFFSET)
|
||||
|
||||
// Volume header field offsets
|
||||
#define HEADER_SALT_OFFSET 0
|
||||
#define HEADER_ENCRYPTED_DATA_OFFSET PKCS5_SALT_SIZE
|
||||
#define HEADER_MASTER_KEYDATA_OFFSET 256
|
||||
|
||||
#define TC_HEADER_OFFSET_MAGIC 64
|
||||
#define TC_HEADER_OFFSET_VERSION 68
|
||||
#define TC_HEADER_OFFSET_REQUIRED_VERSION 70
|
||||
#define TC_HEADER_OFFSET_KEY_AREA_CRC 72
|
||||
#define TC_HEADER_OFFSET_VOLUME_CREATION_TIME 76
|
||||
#define TC_HEADER_OFFSET_MODIFICATION_TIME 84
|
||||
#define TC_HEADER_OFFSET_HIDDEN_VOLUME_SIZE 92
|
||||
#define TC_HEADER_OFFSET_VOLUME_SIZE 100
|
||||
#define TC_HEADER_OFFSET_ENCRYPTED_AREA_START 108
|
||||
#define TC_HEADER_OFFSET_ENCRYPTED_AREA_LENGTH 116
|
||||
#define TC_HEADER_OFFSET_FLAGS 124
|
||||
#define TC_HEADER_OFFSET_SECTOR_SIZE 128
|
||||
#define TC_HEADER_OFFSET_HEADER_CRC 252
|
||||
|
||||
// Volume header flags
|
||||
#define TC_HEADER_FLAG_ENCRYPTED_SYSTEM 0x1
|
||||
#define TC_HEADER_FLAG_NONSYS_INPLACE_ENC 0x2 // The volume has been created (or is being encrypted/decrypted) using non-system in-place encryption
|
||||
|
||||
|
||||
#ifndef TC_HEADER_Volume_VolumeHeader
|
||||
|
||||
#include "Password.h"
|
||||
|
||||
extern BOOL ReadVolumeHeaderRecoveryMode;
|
||||
|
||||
uint16 GetHeaderField16 (byte *header, int offset);
|
||||
uint32 GetHeaderField32 (byte *header, int offset);
|
||||
UINT64_STRUCT GetHeaderField64 (byte *header, int offset);
|
||||
#ifdef TC_WINDOWS_BOOT
|
||||
int ReadVolumeHeader (BOOL bBoot, char *encryptedHeader, Password *password, int pim, PCRYPTO_INFO *retInfo, CRYPTO_INFO *retHeaderCryptoInfo);
|
||||
#else
|
||||
int ReadVolumeHeader (BOOL bBoot, char *encryptedHeader, Password *password, int pkcs5_prf, int pim, BOOL truecryptMode, PCRYPTO_INFO *retInfo, CRYPTO_INFO *retHeaderCryptoInfo);
|
||||
#ifdef _WIN32
|
||||
void ComputeBootloaderFingerprint (byte *bootLoaderBuf, unsigned int bootLoaderSize, byte* fingerprint);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined (DEVICE_DRIVER) && !defined (TC_WINDOWS_BOOT)
|
||||
int CreateVolumeHeaderInMemory (HWND hwndDlg, BOOL bBoot, char *encryptedHeader, int ea, int mode, Password *password, int pkcs5_prf, int pim, char *masterKeydata, PCRYPTO_INFO *retInfo, unsigned __int64 volumeSize, unsigned __int64 hiddenVolumeSize, unsigned __int64 encryptedAreaStart, unsigned __int64 encryptedAreaLength, uint16 requiredProgramVersion, uint32 headerFlags, uint32 sectorSize, BOOL bWipeMode);
|
||||
BOOL ReadEffectiveVolumeHeader (BOOL device, HANDLE fileHandle, byte *header, DWORD *bytesRead);
|
||||
BOOL WriteEffectiveVolumeHeader (BOOL device, HANDLE fileHandle, byte *header);
|
||||
int WriteRandomDataToReservedHeaderAreas (HWND hwndDlg, HANDLE dev, CRYPTO_INFO *cryptoInfo, uint64 dataAreaSize, BOOL bPrimaryOnly, BOOL bBackupOnly);
|
||||
#endif
|
||||
|
||||
#endif // !TC_HEADER_Volume_VolumeHeader
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_Common_Volumes
|
||||
/*
|
||||
Legal Notice: Some portions of the source code contained in this file were
|
||||
derived from the source code of TrueCrypt 7.1a, which is
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
|
||||
governed by the TrueCrypt License 3.0, also from the source code of
|
||||
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
|
||||
and which is governed by the 'License Agreement for Encryption for the Masses'
|
||||
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. */
|
||||
|
||||
#ifndef TC_HEADER_Common_Volumes
|
||||
#define TC_HEADER_Common_Volumes
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Volume header version
|
||||
#define VOLUME_HEADER_VERSION 0x0005
|
||||
|
||||
// Version number written to volume header during format;
|
||||
// specifies the minimum program version required to mount the volume
|
||||
#define TC_VOLUME_MIN_REQUIRED_PROGRAM_VERSION 0x010b
|
||||
|
||||
// Version number written (encrypted) to the key data area of an encrypted system partition/drive;
|
||||
// specifies the minimum program version required to decrypt the system partition/drive
|
||||
#define TC_SYSENC_KEYSCOPE_MIN_REQ_PROG_VERSION 0x010b
|
||||
|
||||
// Current volume format version (created by TrueCrypt 6.0+)
|
||||
#define TC_VOLUME_FORMAT_VERSION 2
|
||||
|
||||
// Version number of volume format created by TrueCrypt 1.0-5.1a
|
||||
#define TC_VOLUME_FORMAT_VERSION_PRE_6_0 1
|
||||
|
||||
// Volume header sizes
|
||||
#define TC_VOLUME_HEADER_SIZE (64 * 1024L)
|
||||
#define TC_VOLUME_HEADER_EFFECTIVE_SIZE 512
|
||||
#define TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE 512
|
||||
#define TC_VOLUME_HEADER_SIZE_LEGACY 512
|
||||
|
||||
#define TC_VOLUME_HEADER_GROUP_SIZE (2 * TC_VOLUME_HEADER_SIZE)
|
||||
#define TC_TOTAL_VOLUME_HEADERS_SIZE (4 * TC_VOLUME_HEADER_SIZE)
|
||||
|
||||
// Volume offsets
|
||||
#define TC_VOLUME_HEADER_OFFSET 0
|
||||
#define TC_HIDDEN_VOLUME_HEADER_OFFSET TC_VOLUME_HEADER_SIZE
|
||||
|
||||
// Sector sizes
|
||||
#define TC_MIN_VOLUME_SECTOR_SIZE 512
|
||||
#define TC_MAX_VOLUME_SECTOR_SIZE 4096
|
||||
#define TC_SECTOR_SIZE_FILE_HOSTED_VOLUME 512
|
||||
#define TC_SECTOR_SIZE_LEGACY 512
|
||||
|
||||
// Sector size which can be safely assumed to be supported by all BIOSes
|
||||
#define TC_SECTOR_SIZE_BIOS 512
|
||||
|
||||
#define TC_VOLUME_SMALL_SIZE_THRESHOLD (2 * BYTES_PER_MB) // Volume sizes below this threshold are considered small
|
||||
|
||||
#define TC_HIDDEN_VOLUME_HOST_FS_RESERVED_END_AREA_SIZE TC_MAX_VOLUME_SECTOR_SIZE // FAT file system fills the last sector with zeroes (marked as free; observed when quick format was performed using the OS format tool).
|
||||
#define TC_HIDDEN_VOLUME_HOST_FS_RESERVED_END_AREA_SIZE_HIGH TC_VOLUME_HEADER_GROUP_SIZE // Reserved area size used for hidden volumes larger than TC_VOLUME_SMALL_SIZE_THRESHOLD
|
||||
|
||||
#define TC_VOLUME_DATA_OFFSET TC_VOLUME_HEADER_GROUP_SIZE
|
||||
|
||||
// The offset, in bytes, of the legacy hidden volume header position from the end of the file (a positive value).
|
||||
#define TC_HIDDEN_VOLUME_HEADER_OFFSET_LEGACY (TC_VOLUME_HEADER_SIZE_LEGACY + TC_SECTOR_SIZE_LEGACY * 2)
|
||||
|
||||
#define TC_MAX_128BIT_BLOCK_VOLUME_SIZE BYTES_PER_PB // Security bound (128-bit block XTS mode)
|
||||
|
||||
// Filesystem size limits
|
||||
#define TC_MIN_FAT_FS_SIZE (9 * TC_MAX_VOLUME_SECTOR_SIZE)
|
||||
#define TC_MAX_FAT_SECTOR_COUNT 0x100000000ULL
|
||||
#define TC_MIN_NTFS_FS_SIZE (884 * TC_MAX_VOLUME_SECTOR_SIZE)
|
||||
#define TC_MAX_NTFS_FS_SIZE (128LL * BYTES_PER_TB) // NTFS volume can theoretically be up to 16 exabytes, but Windows XP and 2003 limit the size to that addressable with 32-bit clusters, i.e. max size is 128 TB (if 64-KB clusters are used).
|
||||
#define TC_MAX_FAT_CLUSTER_SIZE (256 * BYTES_PER_KB) // Windows XP/Vista may crash when writing to a filesystem using clusters larger than 256 KB
|
||||
#define TC_MIN_EXFAT_FS_SIZE (42 * TC_MAX_VOLUME_SECTOR_SIZE)
|
||||
#define TC_MAX_EXFAT_FS_SIZE (128LL * BYTES_PER_PB)
|
||||
|
||||
// Volume size limits
|
||||
#define TC_MIN_VOLUME_SIZE (TC_TOTAL_VOLUME_HEADERS_SIZE + TC_MIN_FAT_FS_SIZE)
|
||||
#define TC_MIN_VOLUME_SIZE_LEGACY (37 * TC_SECTOR_SIZE_LEGACY)
|
||||
#define TC_MAX_VOLUME_SIZE_GENERAL 0x7fffFFFFffffFFFFLL // Signed 64-bit integer file offset values
|
||||
#define TC_MAX_VOLUME_SIZE TC_MAX_128BIT_BLOCK_VOLUME_SIZE
|
||||
|
||||
#define TC_MIN_HIDDEN_VOLUME_SIZE (TC_MIN_FAT_FS_SIZE + TC_HIDDEN_VOLUME_HOST_FS_RESERVED_END_AREA_SIZE)
|
||||
|
||||
#define TC_MIN_HIDDEN_VOLUME_HOST_SIZE (TC_MIN_VOLUME_SIZE + TC_MIN_HIDDEN_VOLUME_SIZE + 2 * TC_MAX_VOLUME_SECTOR_SIZE)
|
||||
#define TC_MAX_HIDDEN_VOLUME_HOST_SIZE (TC_MAX_NTFS_FS_SIZE - TC_TOTAL_VOLUME_HEADERS_SIZE)
|
||||
|
||||
#ifndef TC_NO_COMPILER_INT64
|
||||
# if TC_MAX_VOLUME_SIZE > TC_MAX_VOLUME_SIZE_GENERAL
|
||||
# error TC_MAX_VOLUME_SIZE > TC_MAX_VOLUME_SIZE_GENERAL
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define HEADER_ENCRYPTED_DATA_SIZE (TC_VOLUME_HEADER_EFFECTIVE_SIZE - HEADER_ENCRYPTED_DATA_OFFSET)
|
||||
|
||||
// Volume header field offsets
|
||||
#define HEADER_SALT_OFFSET 0
|
||||
#define HEADER_ENCRYPTED_DATA_OFFSET PKCS5_SALT_SIZE
|
||||
#define HEADER_MASTER_KEYDATA_OFFSET 256
|
||||
|
||||
#define TC_HEADER_OFFSET_MAGIC 64
|
||||
#define TC_HEADER_OFFSET_VERSION 68
|
||||
#define TC_HEADER_OFFSET_REQUIRED_VERSION 70
|
||||
#define TC_HEADER_OFFSET_KEY_AREA_CRC 72
|
||||
#define TC_HEADER_OFFSET_VOLUME_CREATION_TIME 76
|
||||
#define TC_HEADER_OFFSET_MODIFICATION_TIME 84
|
||||
#define TC_HEADER_OFFSET_HIDDEN_VOLUME_SIZE 92
|
||||
#define TC_HEADER_OFFSET_VOLUME_SIZE 100
|
||||
#define TC_HEADER_OFFSET_ENCRYPTED_AREA_START 108
|
||||
#define TC_HEADER_OFFSET_ENCRYPTED_AREA_LENGTH 116
|
||||
#define TC_HEADER_OFFSET_FLAGS 124
|
||||
#define TC_HEADER_OFFSET_SECTOR_SIZE 128
|
||||
#define TC_HEADER_OFFSET_HEADER_CRC 252
|
||||
|
||||
// Volume header flags
|
||||
#define TC_HEADER_FLAG_ENCRYPTED_SYSTEM 0x1
|
||||
#define TC_HEADER_FLAG_NONSYS_INPLACE_ENC 0x2 // The volume has been created (or is being encrypted/decrypted) using non-system in-place encryption
|
||||
|
||||
|
||||
#ifndef TC_HEADER_Volume_VolumeHeader
|
||||
|
||||
#include "Password.h"
|
||||
|
||||
extern BOOL ReadVolumeHeaderRecoveryMode;
|
||||
|
||||
uint16 GetHeaderField16 (byte *header, int offset);
|
||||
uint32 GetHeaderField32 (byte *header, int offset);
|
||||
UINT64_STRUCT GetHeaderField64 (byte *header, int offset);
|
||||
#ifdef TC_WINDOWS_BOOT
|
||||
int ReadVolumeHeader (BOOL bBoot, char *encryptedHeader, Password *password, int pim, PCRYPTO_INFO *retInfo, CRYPTO_INFO *retHeaderCryptoInfo);
|
||||
#else
|
||||
int ReadVolumeHeader (BOOL bBoot, char *encryptedHeader, Password *password, int pkcs5_prf, int pim, BOOL truecryptMode, PCRYPTO_INFO *retInfo, CRYPTO_INFO *retHeaderCryptoInfo);
|
||||
#ifdef _WIN32
|
||||
void ComputeBootloaderFingerprint (byte *bootLoaderBuf, unsigned int bootLoaderSize, byte* fingerprint);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined (DEVICE_DRIVER) && !defined (TC_WINDOWS_BOOT)
|
||||
int CreateVolumeHeaderInMemory (HWND hwndDlg, BOOL bBoot, char *encryptedHeader, int ea, int mode, Password *password, int pkcs5_prf, int pim, char *masterKeydata, PCRYPTO_INFO *retInfo, unsigned __int64 volumeSize, unsigned __int64 hiddenVolumeSize, unsigned __int64 encryptedAreaStart, unsigned __int64 encryptedAreaLength, uint16 requiredProgramVersion, uint32 headerFlags, uint32 sectorSize, BOOL bWipeMode);
|
||||
BOOL ReadEffectiveVolumeHeader (BOOL device, HANDLE fileHandle, byte *header, DWORD *bytesRead);
|
||||
BOOL WriteEffectiveVolumeHeader (BOOL device, HANDLE fileHandle, byte *header);
|
||||
int WriteRandomDataToReservedHeaderAreas (HWND hwndDlg, HANDLE dev, CRYPTO_INFO *cryptoInfo, uint64 dataAreaSize, BOOL bPrimaryOnly, BOOL bBackupOnly);
|
||||
#endif
|
||||
|
||||
#endif // !TC_HEADER_Volume_VolumeHeader
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_Common_Volumes
|
||||
|
||||
@@ -1,198 +1,198 @@
|
||||
/*
|
||||
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 "Tcdefs.h"
|
||||
#include "Wipe.h"
|
||||
|
||||
|
||||
static BOOL Wipe1PseudoRandom (int pass, byte *buffer, size_t size)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
// Fill buffer with wipe patterns defined in "National Industrial Security Program Operating Manual", US DoD 5220.22-M.
|
||||
// Return: FALSE = buffer must be filled with random data
|
||||
|
||||
static BOOL Wipe3Dod5220 (int pass, byte *buffer, size_t size)
|
||||
{
|
||||
byte wipeChar;
|
||||
|
||||
switch (pass)
|
||||
{
|
||||
case 1:
|
||||
wipeChar = 0;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
wipeChar = 0xff;
|
||||
break;
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
memset (buffer, wipeChar, size);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static BOOL Wipe7Dod5220 (int pass, byte randChars[TC_WIPE_RAND_CHAR_COUNT], byte *buffer, size_t size)
|
||||
{
|
||||
byte wipeChar;
|
||||
|
||||
switch (pass)
|
||||
{
|
||||
case 1:
|
||||
wipeChar = randChars[0];
|
||||
break;
|
||||
|
||||
case 2:
|
||||
wipeChar = ~randChars[0];
|
||||
break;
|
||||
|
||||
case 4:
|
||||
wipeChar = randChars[1];
|
||||
break;
|
||||
|
||||
case 5:
|
||||
wipeChar = randChars[2];
|
||||
break;
|
||||
|
||||
case 6:
|
||||
wipeChar = ~randChars[2];
|
||||
break;
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
memset (buffer, wipeChar, size);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
// Fill the buffer with wipe patterns defined in the paper "Secure Deletion of Data from Magnetic and Solid-State Memory" by Peter Gutmann.
|
||||
// Return: FALSE = buffer must be filled with random data
|
||||
|
||||
static BOOL Wipe35Gutmann (int pass, byte *buffer, size_t size)
|
||||
{
|
||||
byte wipePat3[] = { 0x92, 0x49, 0x24 };
|
||||
int wipePat3Pos;
|
||||
size_t i;
|
||||
|
||||
switch (pass)
|
||||
{
|
||||
case 5:
|
||||
memset (buffer, 0x55, size);
|
||||
break;
|
||||
|
||||
case 6:
|
||||
memset (buffer, 0xaa, size);
|
||||
break;
|
||||
|
||||
case 7:
|
||||
case 26:
|
||||
case 29:
|
||||
wipePat3Pos = 0;
|
||||
goto wipe3;
|
||||
|
||||
case 8:
|
||||
case 27:
|
||||
case 30:
|
||||
wipePat3Pos = 1;
|
||||
goto wipe3;
|
||||
|
||||
case 9:
|
||||
case 28:
|
||||
case 31:
|
||||
wipePat3Pos = 2;
|
||||
goto wipe3;
|
||||
|
||||
wipe3:
|
||||
if (pass >= 29)
|
||||
{
|
||||
wipePat3[0] = ~wipePat3[0];
|
||||
wipePat3[1] = ~wipePat3[1];
|
||||
wipePat3[2] = ~wipePat3[2];
|
||||
}
|
||||
|
||||
for (i = 0; i < size; ++i)
|
||||
{
|
||||
buffer[i] = wipePat3[wipePat3Pos++ % 3];
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (pass >= 10 && pass <= 25)
|
||||
memset (buffer, (pass - 10) * 0x11, size);
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
int GetWipePassCount (WipeAlgorithmId algorithm)
|
||||
{
|
||||
switch (algorithm)
|
||||
{
|
||||
case TC_WIPE_1_RAND:
|
||||
return 1;
|
||||
|
||||
case TC_WIPE_3_DOD_5220:
|
||||
return 3;
|
||||
|
||||
case TC_WIPE_7_DOD_5220:
|
||||
return 7;
|
||||
|
||||
case TC_WIPE_35_GUTMANN:
|
||||
return 35;
|
||||
|
||||
case TC_WIPE_256:
|
||||
return 256;
|
||||
}
|
||||
|
||||
return -1; // Prevent compiler warnings
|
||||
}
|
||||
|
||||
|
||||
BOOL WipeBuffer (WipeAlgorithmId algorithm, byte randChars[TC_WIPE_RAND_CHAR_COUNT], int pass, byte *buffer, size_t size)
|
||||
{
|
||||
switch (algorithm)
|
||||
{
|
||||
case TC_WIPE_1_RAND:
|
||||
case TC_WIPE_256:
|
||||
return Wipe1PseudoRandom (pass, buffer, size);
|
||||
|
||||
case TC_WIPE_3_DOD_5220:
|
||||
return Wipe3Dod5220 (pass, buffer, size);
|
||||
|
||||
case TC_WIPE_7_DOD_5220:
|
||||
return Wipe7Dod5220 (pass, randChars, buffer, size);
|
||||
|
||||
case TC_WIPE_35_GUTMANN:
|
||||
return Wipe35Gutmann (pass, buffer, size);
|
||||
|
||||
/* we will never reach here because all calls to WipeBuffer are preceeded
|
||||
* by a call to GetWipePassCount that already checks the same algorithm
|
||||
* parameters and in case of unsupported value an error is returned before
|
||||
* calling WipeBuffer
|
||||
*/
|
||||
/*
|
||||
default:
|
||||
TC_THROW_FATAL_EXCEPTION;*/
|
||||
}
|
||||
|
||||
return FALSE; // Prevent compiler warnings
|
||||
}
|
||||
/*
|
||||
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 "Tcdefs.h"
|
||||
#include "Wipe.h"
|
||||
|
||||
|
||||
static BOOL Wipe1PseudoRandom (int pass, byte *buffer, size_t size)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
// Fill buffer with wipe patterns defined in "National Industrial Security Program Operating Manual", US DoD 5220.22-M.
|
||||
// Return: FALSE = buffer must be filled with random data
|
||||
|
||||
static BOOL Wipe3Dod5220 (int pass, byte *buffer, size_t size)
|
||||
{
|
||||
byte wipeChar;
|
||||
|
||||
switch (pass)
|
||||
{
|
||||
case 1:
|
||||
wipeChar = 0;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
wipeChar = 0xff;
|
||||
break;
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
memset (buffer, wipeChar, size);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static BOOL Wipe7Dod5220 (int pass, byte randChars[TC_WIPE_RAND_CHAR_COUNT], byte *buffer, size_t size)
|
||||
{
|
||||
byte wipeChar;
|
||||
|
||||
switch (pass)
|
||||
{
|
||||
case 1:
|
||||
wipeChar = randChars[0];
|
||||
break;
|
||||
|
||||
case 2:
|
||||
wipeChar = ~randChars[0];
|
||||
break;
|
||||
|
||||
case 4:
|
||||
wipeChar = randChars[1];
|
||||
break;
|
||||
|
||||
case 5:
|
||||
wipeChar = randChars[2];
|
||||
break;
|
||||
|
||||
case 6:
|
||||
wipeChar = ~randChars[2];
|
||||
break;
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
memset (buffer, wipeChar, size);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
// Fill the buffer with wipe patterns defined in the paper "Secure Deletion of Data from Magnetic and Solid-State Memory" by Peter Gutmann.
|
||||
// Return: FALSE = buffer must be filled with random data
|
||||
|
||||
static BOOL Wipe35Gutmann (int pass, byte *buffer, size_t size)
|
||||
{
|
||||
byte wipePat3[] = { 0x92, 0x49, 0x24 };
|
||||
int wipePat3Pos;
|
||||
size_t i;
|
||||
|
||||
switch (pass)
|
||||
{
|
||||
case 5:
|
||||
memset (buffer, 0x55, size);
|
||||
break;
|
||||
|
||||
case 6:
|
||||
memset (buffer, 0xaa, size);
|
||||
break;
|
||||
|
||||
case 7:
|
||||
case 26:
|
||||
case 29:
|
||||
wipePat3Pos = 0;
|
||||
goto wipe3;
|
||||
|
||||
case 8:
|
||||
case 27:
|
||||
case 30:
|
||||
wipePat3Pos = 1;
|
||||
goto wipe3;
|
||||
|
||||
case 9:
|
||||
case 28:
|
||||
case 31:
|
||||
wipePat3Pos = 2;
|
||||
goto wipe3;
|
||||
|
||||
wipe3:
|
||||
if (pass >= 29)
|
||||
{
|
||||
wipePat3[0] = ~wipePat3[0];
|
||||
wipePat3[1] = ~wipePat3[1];
|
||||
wipePat3[2] = ~wipePat3[2];
|
||||
}
|
||||
|
||||
for (i = 0; i < size; ++i)
|
||||
{
|
||||
buffer[i] = wipePat3[wipePat3Pos++ % 3];
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (pass >= 10 && pass <= 25)
|
||||
memset (buffer, (pass - 10) * 0x11, size);
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
int GetWipePassCount (WipeAlgorithmId algorithm)
|
||||
{
|
||||
switch (algorithm)
|
||||
{
|
||||
case TC_WIPE_1_RAND:
|
||||
return 1;
|
||||
|
||||
case TC_WIPE_3_DOD_5220:
|
||||
return 3;
|
||||
|
||||
case TC_WIPE_7_DOD_5220:
|
||||
return 7;
|
||||
|
||||
case TC_WIPE_35_GUTMANN:
|
||||
return 35;
|
||||
|
||||
case TC_WIPE_256:
|
||||
return 256;
|
||||
}
|
||||
|
||||
return -1; // Prevent compiler warnings
|
||||
}
|
||||
|
||||
|
||||
BOOL WipeBuffer (WipeAlgorithmId algorithm, byte randChars[TC_WIPE_RAND_CHAR_COUNT], int pass, byte *buffer, size_t size)
|
||||
{
|
||||
switch (algorithm)
|
||||
{
|
||||
case TC_WIPE_1_RAND:
|
||||
case TC_WIPE_256:
|
||||
return Wipe1PseudoRandom (pass, buffer, size);
|
||||
|
||||
case TC_WIPE_3_DOD_5220:
|
||||
return Wipe3Dod5220 (pass, buffer, size);
|
||||
|
||||
case TC_WIPE_7_DOD_5220:
|
||||
return Wipe7Dod5220 (pass, randChars, buffer, size);
|
||||
|
||||
case TC_WIPE_35_GUTMANN:
|
||||
return Wipe35Gutmann (pass, buffer, size);
|
||||
|
||||
/* we will never reach here because all calls to WipeBuffer are preceeded
|
||||
* by a call to GetWipePassCount that already checks the same algorithm
|
||||
* parameters and in case of unsupported value an error is returned before
|
||||
* calling WipeBuffer
|
||||
*/
|
||||
/*
|
||||
default:
|
||||
TC_THROW_FATAL_EXCEPTION;*/
|
||||
}
|
||||
|
||||
return FALSE; // Prevent compiler warnings
|
||||
}
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Common_Wipe
|
||||
#define TC_HEADER_Common_Wipe
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
/* WARNING: As these values are written to config files, if they or their meanings
|
||||
are changed, incompatiblity with other versions may arise (upgrade, downgrade, etc.).
|
||||
When adding a new constant, verify that the value is unique within this block. */
|
||||
TC_WIPE_NONE = 0,
|
||||
TC_WIPE_1_RAND = 100,
|
||||
TC_WIPE_3_DOD_5220 = 300,
|
||||
TC_WIPE_7_DOD_5220 = 700,
|
||||
TC_WIPE_35_GUTMANN = 3500,
|
||||
TC_WIPE_256 = 25600
|
||||
|
||||
} WipeAlgorithmId;
|
||||
|
||||
#define TC_WIPE_RAND_CHAR_COUNT 3
|
||||
|
||||
int GetWipePassCount (WipeAlgorithmId algorithm);
|
||||
BOOL WipeBuffer (WipeAlgorithmId algorithm, byte randChars[TC_WIPE_RAND_CHAR_COUNT], int pass, byte *buffer, size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_Common_Wipe
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Common_Wipe
|
||||
#define TC_HEADER_Common_Wipe
|
||||
|
||||
#include "Tcdefs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
/* WARNING: As these values are written to config files, if they or their meanings
|
||||
are changed, incompatiblity with other versions may arise (upgrade, downgrade, etc.).
|
||||
When adding a new constant, verify that the value is unique within this block. */
|
||||
TC_WIPE_NONE = 0,
|
||||
TC_WIPE_1_RAND = 100,
|
||||
TC_WIPE_3_DOD_5220 = 300,
|
||||
TC_WIPE_7_DOD_5220 = 700,
|
||||
TC_WIPE_35_GUTMANN = 3500,
|
||||
TC_WIPE_256 = 25600
|
||||
|
||||
} WipeAlgorithmId;
|
||||
|
||||
#define TC_WIPE_RAND_CHAR_COUNT 3
|
||||
|
||||
int GetWipePassCount (WipeAlgorithmId algorithm);
|
||||
BOOL WipeBuffer (WipeAlgorithmId algorithm, byte randChars[TC_WIPE_RAND_CHAR_COUNT], int pass, byte *buffer, size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_Common_Wipe
|
||||
|
||||
536
src/Common/Xml.c
536
src/Common/Xml.c
@@ -1,268 +1,268 @@
|
||||
/*
|
||||
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 <windows.h>
|
||||
#include <stdio.h>
|
||||
#include "Xml.h"
|
||||
|
||||
|
||||
static BOOL BeginsWith (char *string, char *subString)
|
||||
{
|
||||
while (*string++ == *subString++)
|
||||
{
|
||||
if (*subString == 0) return TRUE;
|
||||
if (*string == 0) return FALSE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
char *XmlNextNode (char *xmlNode)
|
||||
{
|
||||
char *t = xmlNode + 1;
|
||||
while ((t = strchr (t, '<')) != NULL)
|
||||
{
|
||||
if (t[1] != '/')
|
||||
return t;
|
||||
|
||||
t++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char *XmlFindElement (char *xmlNode, char *nodeName)
|
||||
{
|
||||
char *t = xmlNode;
|
||||
size_t nameLen = strlen (nodeName);
|
||||
|
||||
do
|
||||
{
|
||||
if (BeginsWith (t + 1, nodeName)
|
||||
&& (t[nameLen + 1] == '>'
|
||||
|| t[nameLen + 1] == ' ')) return t;
|
||||
|
||||
} while (t = XmlNextNode (t));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char *XmlFindElementByAttributeValue (char *xml, char *nodeName, char *attrName, char *attrValue)
|
||||
{
|
||||
char attr[2048];
|
||||
|
||||
while (xml = XmlFindElement (xml, nodeName))
|
||||
{
|
||||
XmlGetAttributeText (xml, attrName, attr, sizeof (attr));
|
||||
if (strcmp (attr, attrValue) == 0)
|
||||
return xml;
|
||||
|
||||
xml++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char *XmlGetAttributeText (char *xmlNode, char *xmlAttrName, char *xmlAttrValue, int xmlAttrValueSize)
|
||||
{
|
||||
char *t = xmlNode;
|
||||
char *e = xmlNode;
|
||||
int l = 0;
|
||||
|
||||
xmlAttrValue[0] = 0;
|
||||
if (t[0] != '<') return NULL;
|
||||
|
||||
e = strchr (e, '>');
|
||||
if (e == NULL) return NULL;
|
||||
|
||||
while ((t = strstr (t, xmlAttrName)) && t < e)
|
||||
{
|
||||
char *o = t + strlen (xmlAttrName);
|
||||
if (t[-1] == ' '
|
||||
&&
|
||||
(BeginsWith (o, "=\"")
|
||||
|| BeginsWith (o, "= \"")
|
||||
|| BeginsWith (o, " =\"")
|
||||
|| BeginsWith (o, " = \""))
|
||||
)
|
||||
break;
|
||||
|
||||
t++;
|
||||
}
|
||||
|
||||
if (t == NULL || t > e) return NULL;
|
||||
|
||||
t = strchr (t, '"') + 1;
|
||||
e = strchr (t, '"');
|
||||
l = (int)(e - t);
|
||||
if (e == NULL || l > xmlAttrValueSize) return NULL;
|
||||
|
||||
memcpy (xmlAttrValue, t, l);
|
||||
xmlAttrValue[l] = 0;
|
||||
|
||||
return xmlAttrValue;
|
||||
}
|
||||
|
||||
|
||||
char *XmlGetNodeText (char *xmlNode, char *xmlText, int xmlTextSize)
|
||||
{
|
||||
char *t = xmlNode;
|
||||
char *e = xmlNode + 1;
|
||||
int l = 0, i = 0, j = 0;
|
||||
|
||||
xmlText[0] = 0;
|
||||
|
||||
if (t[0] != '<')
|
||||
return NULL;
|
||||
|
||||
t = strchr (t, '>') + 1;
|
||||
if (t == (char *)1) return NULL;
|
||||
|
||||
e = strchr (e, '<');
|
||||
if (e == NULL) return NULL;
|
||||
|
||||
l = (int)(e - t);
|
||||
if (e == NULL || l > xmlTextSize) return NULL;
|
||||
|
||||
while (i < l)
|
||||
{
|
||||
if (BeginsWith (&t[i], "<"))
|
||||
{
|
||||
xmlText[j++] = '<';
|
||||
i += 4;
|
||||
continue;
|
||||
}
|
||||
if (BeginsWith (&t[i], ">"))
|
||||
{
|
||||
xmlText[j++] = '>';
|
||||
i += 4;
|
||||
continue;
|
||||
}
|
||||
if (BeginsWith (&t[i], "&"))
|
||||
{
|
||||
xmlText[j++] = '&';
|
||||
i += 5;
|
||||
continue;
|
||||
}
|
||||
xmlText[j++] = t[i++];
|
||||
}
|
||||
xmlText[j] = 0;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
char *XmlQuoteText (const char *textSrc, char *textDst, int textDstMaxSize)
|
||||
{
|
||||
char *textDstLast = textDst + textDstMaxSize - 1;
|
||||
|
||||
if (textDstMaxSize == 0)
|
||||
return NULL;
|
||||
|
||||
while (*textSrc != 0 && textDst <= textDstLast)
|
||||
{
|
||||
char c = *textSrc++;
|
||||
switch (c)
|
||||
{
|
||||
case '&':
|
||||
if (textDst + 6 > textDstLast)
|
||||
return NULL;
|
||||
strcpy (textDst, "&");
|
||||
textDst += 5;
|
||||
continue;
|
||||
|
||||
case '>':
|
||||
if (textDst + 5 > textDstLast)
|
||||
return NULL;
|
||||
strcpy (textDst, ">");
|
||||
textDst += 4;
|
||||
continue;
|
||||
|
||||
case '<':
|
||||
if (textDst + 5 > textDstLast)
|
||||
return NULL;
|
||||
strcpy (textDst, "<");
|
||||
textDst += 4;
|
||||
continue;
|
||||
|
||||
default:
|
||||
*textDst++ = c;
|
||||
}
|
||||
}
|
||||
|
||||
if (textDst > textDstLast)
|
||||
return NULL;
|
||||
|
||||
*textDst = 0;
|
||||
return textDst;
|
||||
}
|
||||
|
||||
wchar_t *XmlQuoteTextW (const wchar_t *textSrc, wchar_t *textDst, int textDstMaxSize)
|
||||
{
|
||||
wchar_t *textDstLast = textDst + textDstMaxSize - 1;
|
||||
|
||||
if (textDstMaxSize == 0)
|
||||
return NULL;
|
||||
|
||||
while (*textSrc != 0 && textDst <= textDstLast)
|
||||
{
|
||||
wchar_t c = *textSrc++;
|
||||
switch (c)
|
||||
{
|
||||
case L'&':
|
||||
if (textDst + 6 > textDstLast)
|
||||
return NULL;
|
||||
wcscpy (textDst, L"&");
|
||||
textDst += 5;
|
||||
continue;
|
||||
|
||||
case L'>':
|
||||
if (textDst + 5 > textDstLast)
|
||||
return NULL;
|
||||
wcscpy (textDst, L">");
|
||||
textDst += 4;
|
||||
continue;
|
||||
|
||||
case L'<':
|
||||
if (textDst + 5 > textDstLast)
|
||||
return NULL;
|
||||
wcscpy (textDst, L"<");
|
||||
textDst += 4;
|
||||
continue;
|
||||
|
||||
default:
|
||||
*textDst++ = c;
|
||||
}
|
||||
}
|
||||
|
||||
if (textDst > textDstLast)
|
||||
return NULL;
|
||||
|
||||
*textDst = 0;
|
||||
return textDst;
|
||||
}
|
||||
|
||||
|
||||
int XmlWriteHeader (FILE *file)
|
||||
{
|
||||
return fputws (L"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<VeraCrypt>", file);
|
||||
}
|
||||
|
||||
|
||||
int XmlWriteFooter (FILE *file)
|
||||
{
|
||||
return fputws (L"\n</VeraCrypt>", file);
|
||||
}
|
||||
/*
|
||||
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 <windows.h>
|
||||
#include <stdio.h>
|
||||
#include "Xml.h"
|
||||
|
||||
|
||||
static BOOL BeginsWith (char *string, char *subString)
|
||||
{
|
||||
while (*string++ == *subString++)
|
||||
{
|
||||
if (*subString == 0) return TRUE;
|
||||
if (*string == 0) return FALSE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
char *XmlNextNode (char *xmlNode)
|
||||
{
|
||||
char *t = xmlNode + 1;
|
||||
while ((t = strchr (t, '<')) != NULL)
|
||||
{
|
||||
if (t[1] != '/')
|
||||
return t;
|
||||
|
||||
t++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char *XmlFindElement (char *xmlNode, char *nodeName)
|
||||
{
|
||||
char *t = xmlNode;
|
||||
size_t nameLen = strlen (nodeName);
|
||||
|
||||
do
|
||||
{
|
||||
if (BeginsWith (t + 1, nodeName)
|
||||
&& (t[nameLen + 1] == '>'
|
||||
|| t[nameLen + 1] == ' ')) return t;
|
||||
|
||||
} while (t = XmlNextNode (t));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char *XmlFindElementByAttributeValue (char *xml, char *nodeName, char *attrName, char *attrValue)
|
||||
{
|
||||
char attr[2048];
|
||||
|
||||
while (xml = XmlFindElement (xml, nodeName))
|
||||
{
|
||||
XmlGetAttributeText (xml, attrName, attr, sizeof (attr));
|
||||
if (strcmp (attr, attrValue) == 0)
|
||||
return xml;
|
||||
|
||||
xml++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char *XmlGetAttributeText (char *xmlNode, char *xmlAttrName, char *xmlAttrValue, int xmlAttrValueSize)
|
||||
{
|
||||
char *t = xmlNode;
|
||||
char *e = xmlNode;
|
||||
int l = 0;
|
||||
|
||||
xmlAttrValue[0] = 0;
|
||||
if (t[0] != '<') return NULL;
|
||||
|
||||
e = strchr (e, '>');
|
||||
if (e == NULL) return NULL;
|
||||
|
||||
while ((t = strstr (t, xmlAttrName)) && t < e)
|
||||
{
|
||||
char *o = t + strlen (xmlAttrName);
|
||||
if (t[-1] == ' '
|
||||
&&
|
||||
(BeginsWith (o, "=\"")
|
||||
|| BeginsWith (o, "= \"")
|
||||
|| BeginsWith (o, " =\"")
|
||||
|| BeginsWith (o, " = \""))
|
||||
)
|
||||
break;
|
||||
|
||||
t++;
|
||||
}
|
||||
|
||||
if (t == NULL || t > e) return NULL;
|
||||
|
||||
t = strchr (t, '"') + 1;
|
||||
e = strchr (t, '"');
|
||||
l = (int)(e - t);
|
||||
if (e == NULL || l > xmlAttrValueSize) return NULL;
|
||||
|
||||
memcpy (xmlAttrValue, t, l);
|
||||
xmlAttrValue[l] = 0;
|
||||
|
||||
return xmlAttrValue;
|
||||
}
|
||||
|
||||
|
||||
char *XmlGetNodeText (char *xmlNode, char *xmlText, int xmlTextSize)
|
||||
{
|
||||
char *t = xmlNode;
|
||||
char *e = xmlNode + 1;
|
||||
int l = 0, i = 0, j = 0;
|
||||
|
||||
xmlText[0] = 0;
|
||||
|
||||
if (t[0] != '<')
|
||||
return NULL;
|
||||
|
||||
t = strchr (t, '>') + 1;
|
||||
if (t == (char *)1) return NULL;
|
||||
|
||||
e = strchr (e, '<');
|
||||
if (e == NULL) return NULL;
|
||||
|
||||
l = (int)(e - t);
|
||||
if (e == NULL || l > xmlTextSize) return NULL;
|
||||
|
||||
while (i < l)
|
||||
{
|
||||
if (BeginsWith (&t[i], "<"))
|
||||
{
|
||||
xmlText[j++] = '<';
|
||||
i += 4;
|
||||
continue;
|
||||
}
|
||||
if (BeginsWith (&t[i], ">"))
|
||||
{
|
||||
xmlText[j++] = '>';
|
||||
i += 4;
|
||||
continue;
|
||||
}
|
||||
if (BeginsWith (&t[i], "&"))
|
||||
{
|
||||
xmlText[j++] = '&';
|
||||
i += 5;
|
||||
continue;
|
||||
}
|
||||
xmlText[j++] = t[i++];
|
||||
}
|
||||
xmlText[j] = 0;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
char *XmlQuoteText (const char *textSrc, char *textDst, int textDstMaxSize)
|
||||
{
|
||||
char *textDstLast = textDst + textDstMaxSize - 1;
|
||||
|
||||
if (textDstMaxSize == 0)
|
||||
return NULL;
|
||||
|
||||
while (*textSrc != 0 && textDst <= textDstLast)
|
||||
{
|
||||
char c = *textSrc++;
|
||||
switch (c)
|
||||
{
|
||||
case '&':
|
||||
if (textDst + 6 > textDstLast)
|
||||
return NULL;
|
||||
strcpy (textDst, "&");
|
||||
textDst += 5;
|
||||
continue;
|
||||
|
||||
case '>':
|
||||
if (textDst + 5 > textDstLast)
|
||||
return NULL;
|
||||
strcpy (textDst, ">");
|
||||
textDst += 4;
|
||||
continue;
|
||||
|
||||
case '<':
|
||||
if (textDst + 5 > textDstLast)
|
||||
return NULL;
|
||||
strcpy (textDst, "<");
|
||||
textDst += 4;
|
||||
continue;
|
||||
|
||||
default:
|
||||
*textDst++ = c;
|
||||
}
|
||||
}
|
||||
|
||||
if (textDst > textDstLast)
|
||||
return NULL;
|
||||
|
||||
*textDst = 0;
|
||||
return textDst;
|
||||
}
|
||||
|
||||
wchar_t *XmlQuoteTextW (const wchar_t *textSrc, wchar_t *textDst, int textDstMaxSize)
|
||||
{
|
||||
wchar_t *textDstLast = textDst + textDstMaxSize - 1;
|
||||
|
||||
if (textDstMaxSize == 0)
|
||||
return NULL;
|
||||
|
||||
while (*textSrc != 0 && textDst <= textDstLast)
|
||||
{
|
||||
wchar_t c = *textSrc++;
|
||||
switch (c)
|
||||
{
|
||||
case L'&':
|
||||
if (textDst + 6 > textDstLast)
|
||||
return NULL;
|
||||
wcscpy (textDst, L"&");
|
||||
textDst += 5;
|
||||
continue;
|
||||
|
||||
case L'>':
|
||||
if (textDst + 5 > textDstLast)
|
||||
return NULL;
|
||||
wcscpy (textDst, L">");
|
||||
textDst += 4;
|
||||
continue;
|
||||
|
||||
case L'<':
|
||||
if (textDst + 5 > textDstLast)
|
||||
return NULL;
|
||||
wcscpy (textDst, L"<");
|
||||
textDst += 4;
|
||||
continue;
|
||||
|
||||
default:
|
||||
*textDst++ = c;
|
||||
}
|
||||
}
|
||||
|
||||
if (textDst > textDstLast)
|
||||
return NULL;
|
||||
|
||||
*textDst = 0;
|
||||
return textDst;
|
||||
}
|
||||
|
||||
|
||||
int XmlWriteHeader (FILE *file)
|
||||
{
|
||||
return fputws (L"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<VeraCrypt>", file);
|
||||
}
|
||||
|
||||
|
||||
int XmlWriteFooter (FILE *file)
|
||||
{
|
||||
return fputws (L"\n</VeraCrypt>", file);
|
||||
}
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
char *XmlNextNode (char *xmlNode);
|
||||
char *XmlFindElement (char *xmlNode, char *nodeName);
|
||||
char *XmlGetAttributeText (char *xmlNode, char *xmlAttrName, char *xmlAttrValue, int xmlAttrValueSize);
|
||||
char *XmlGetNodeText (char *xmlNode, char *xmlText, int xmlTextSize);
|
||||
int XmlWriteHeader (FILE *file);
|
||||
int XmlWriteFooter (FILE *file);
|
||||
char *XmlFindElementByAttributeValue (char *xml, char *nodeName, char *attrName, char *attrValue);
|
||||
char *XmlQuoteText (const char *textSrc, char *textDst, int textDstMaxSize);
|
||||
wchar_t *XmlQuoteTextW (const wchar_t *textSrc, wchar_t *textDst, int textDstMaxSize);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
char *XmlNextNode (char *xmlNode);
|
||||
char *XmlFindElement (char *xmlNode, char *nodeName);
|
||||
char *XmlGetAttributeText (char *xmlNode, char *xmlAttrName, char *xmlAttrValue, int xmlAttrValueSize);
|
||||
char *XmlGetNodeText (char *xmlNode, char *xmlText, int xmlTextSize);
|
||||
int XmlWriteHeader (FILE *file);
|
||||
int XmlWriteFooter (FILE *file);
|
||||
char *XmlFindElementByAttributeValue (char *xml, char *nodeName, char *attrName, char *attrValue);
|
||||
char *XmlQuoteText (const char *textSrc, char *textDst, int textDstMaxSize);
|
||||
wchar_t *XmlQuoteTextW (const wchar_t *textSrc, wchar_t *textDst, int textDstMaxSize);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
1500
src/Common/Xts.c
1500
src/Common/Xts.c
File diff suppressed because it is too large
Load Diff
168
src/Common/Xts.h
168
src/Common/Xts.h
@@ -1,84 +1,84 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef XTS_H
|
||||
#define XTS_H
|
||||
|
||||
// Header files (optional)
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Common/Endian.h"
|
||||
#include "Crypto.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Macros
|
||||
|
||||
#ifndef LITTLE_ENDIAN
|
||||
# define LITTLE_ENDIAN 1
|
||||
#endif
|
||||
|
||||
#ifndef BIG_ENDIAN
|
||||
# define BIG_ENDIAN 2
|
||||
#endif
|
||||
|
||||
#ifndef BYTE_ORDER
|
||||
# define BYTE_ORDER LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
#ifndef LE64
|
||||
# if BYTE_ORDER == LITTLE_ENDIAN
|
||||
# define LE64(x) (x)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// Custom data types
|
||||
|
||||
#ifndef TC_LARGEST_COMPILER_UINT
|
||||
# ifdef TC_NO_COMPILER_INT64
|
||||
typedef unsigned __int32 TC_LARGEST_COMPILER_UINT;
|
||||
# else
|
||||
typedef unsigned __int64 TC_LARGEST_COMPILER_UINT;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef TCDEFS_H
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
unsigned __int32 LowPart;
|
||||
unsigned __int32 HighPart;
|
||||
};
|
||||
# ifndef TC_NO_COMPILER_INT64
|
||||
unsigned __int64 Value;
|
||||
# endif
|
||||
|
||||
} UINT64_STRUCT;
|
||||
#endif
|
||||
|
||||
// Public function prototypes
|
||||
|
||||
void EncryptBufferXTS (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
static void EncryptBufferXTSParallel (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
static void EncryptBufferXTSNonParallel (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
void DecryptBufferXTS (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
static void DecryptBufferXTSParallel (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
static void DecryptBufferXTSNonParallel (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // #ifndef XTS_H
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef XTS_H
|
||||
#define XTS_H
|
||||
|
||||
// Header files (optional)
|
||||
|
||||
#include "Tcdefs.h"
|
||||
#include "Common/Endian.h"
|
||||
#include "Crypto.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Macros
|
||||
|
||||
#ifndef LITTLE_ENDIAN
|
||||
# define LITTLE_ENDIAN 1
|
||||
#endif
|
||||
|
||||
#ifndef BIG_ENDIAN
|
||||
# define BIG_ENDIAN 2
|
||||
#endif
|
||||
|
||||
#ifndef BYTE_ORDER
|
||||
# define BYTE_ORDER LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
#ifndef LE64
|
||||
# if BYTE_ORDER == LITTLE_ENDIAN
|
||||
# define LE64(x) (x)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// Custom data types
|
||||
|
||||
#ifndef TC_LARGEST_COMPILER_UINT
|
||||
# ifdef TC_NO_COMPILER_INT64
|
||||
typedef unsigned __int32 TC_LARGEST_COMPILER_UINT;
|
||||
# else
|
||||
typedef unsigned __int64 TC_LARGEST_COMPILER_UINT;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef TCDEFS_H
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
unsigned __int32 LowPart;
|
||||
unsigned __int32 HighPart;
|
||||
};
|
||||
# ifndef TC_NO_COMPILER_INT64
|
||||
unsigned __int64 Value;
|
||||
# endif
|
||||
|
||||
} UINT64_STRUCT;
|
||||
#endif
|
||||
|
||||
// Public function prototypes
|
||||
|
||||
void EncryptBufferXTS (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
static void EncryptBufferXTSParallel (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
static void EncryptBufferXTSNonParallel (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
void DecryptBufferXTS (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
static void DecryptBufferXTSParallel (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
static void DecryptBufferXTSNonParallel (unsigned __int8 *buffer, TC_LARGEST_COMPILER_UINT length, const UINT64_STRUCT *startDataUnitNo, unsigned int startCipherBlockNo, unsigned __int8 *ks, unsigned __int8 *ks2, int cipher);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // #ifndef XTS_H
|
||||
|
||||
430
src/Crypto/Aes.h
430
src/Crypto/Aes.h
@@ -1,215 +1,215 @@
|
||||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Copyright (c) 1998-2007, Brian Gladman, Worcester, UK. All rights reserved.
|
||||
|
||||
LICENSE TERMS
|
||||
|
||||
The free distribution and use of this software is allowed (with or without
|
||||
changes) provided that:
|
||||
|
||||
1. source code distributions include the above copyright notice, this
|
||||
list of conditions and the following disclaimer;
|
||||
|
||||
2. binary distributions include the above copyright notice, this list
|
||||
of conditions and the following disclaimer in their documentation;
|
||||
|
||||
3. the name of the copyright holder is not used to endorse products
|
||||
built using this software without specific written permission.
|
||||
|
||||
DISCLAIMER
|
||||
|
||||
This software is provided 'as is' with no explicit or implied warranties
|
||||
in respect of its properties, including, but not limited to, correctness
|
||||
and/or fitness for purpose.
|
||||
---------------------------------------------------------------------------
|
||||
Issue Date: 20/12/2007
|
||||
|
||||
This file contains the definitions required to use AES in C. See aesopt.h
|
||||
for optimisation details.
|
||||
*/
|
||||
|
||||
/* Adapted for TrueCrypt */
|
||||
|
||||
#ifndef _AES_H
|
||||
#define _AES_H
|
||||
|
||||
#include "Common/Tcdefs.h"
|
||||
|
||||
#ifndef EXIT_SUCCESS
|
||||
#define EXIT_SUCCESS 0
|
||||
#define EXIT_FAILURE 1
|
||||
#endif
|
||||
#define INT_RETURN int
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
// #define AES_128 /* define if AES with 128 bit keys is needed */
|
||||
// #define AES_192 /* define if AES with 192 bit keys is needed */
|
||||
#define AES_256 /* define if AES with 256 bit keys is needed */
|
||||
// #define AES_VAR /* define if a variable key size is needed */
|
||||
// #define AES_MODES /* define if support is needed for modes */
|
||||
|
||||
/* The following must also be set in assembler files if being used */
|
||||
|
||||
#define AES_ENCRYPT /* if support for encryption is needed */
|
||||
#define AES_DECRYPT /* if support for decryption is needed */
|
||||
#define AES_ERR_CHK /* for parameter checks & error return codes */
|
||||
#define AES_REV_DKS /* define to reverse decryption key schedule */
|
||||
|
||||
#define AES_BLOCK_SIZE 16 /* the AES block size in bytes */
|
||||
#define N_COLS 4 /* the number of columns in the state */
|
||||
|
||||
/* The key schedule length is 11, 13 or 15 16-byte blocks for 128, */
|
||||
/* 192 or 256-bit keys respectively. That is 176, 208 or 240 bytes */
|
||||
/* or 44, 52 or 60 32-bit words. */
|
||||
|
||||
#if defined( AES_VAR ) || defined( AES_256 )
|
||||
#define KS_LENGTH 60
|
||||
#elif defined( AES_192 )
|
||||
#define KS_LENGTH 52
|
||||
#else
|
||||
#define KS_LENGTH 44
|
||||
#endif
|
||||
|
||||
#if defined( AES_ERR_CHK )
|
||||
#define AES_RETURN INT_RETURN
|
||||
#else
|
||||
#define AES_RETURN VOID_RETURN
|
||||
#endif
|
||||
|
||||
/* the character array 'inf' in the following structures is used */
|
||||
/* to hold AES context information. This AES code uses cx->inf.b[0] */
|
||||
/* to hold the number of rounds multiplied by 16. The other three */
|
||||
/* elements can be used by code that implements additional modes */
|
||||
|
||||
typedef union
|
||||
{ uint_32t l;
|
||||
uint_8t b[4];
|
||||
} aes_inf;
|
||||
|
||||
typedef struct
|
||||
{ uint_32t ks[KS_LENGTH];
|
||||
aes_inf inf;
|
||||
} aes_encrypt_ctx;
|
||||
|
||||
typedef struct
|
||||
{ uint_32t ks[KS_LENGTH];
|
||||
aes_inf inf;
|
||||
} aes_decrypt_ctx;
|
||||
|
||||
/* This routine must be called before first use if non-static */
|
||||
/* tables are being used */
|
||||
|
||||
AES_RETURN aes_init(void);
|
||||
|
||||
/* Key lengths in the range 16 <= key_len <= 32 are given in bytes, */
|
||||
/* those in the range 128 <= key_len <= 256 are given in bits */
|
||||
|
||||
#if defined( AES_ENCRYPT )
|
||||
|
||||
#if defined(AES_128) || defined(AES_VAR)
|
||||
AES_RETURN aes_encrypt_key128(const unsigned char *key, aes_encrypt_ctx cx[1]);
|
||||
#endif
|
||||
|
||||
#if defined(AES_192) || defined(AES_VAR)
|
||||
AES_RETURN aes_encrypt_key192(const unsigned char *key, aes_encrypt_ctx cx[1]);
|
||||
#endif
|
||||
|
||||
#if defined(AES_256) || defined(AES_VAR)
|
||||
AES_RETURN aes_encrypt_key256(const unsigned char *key, aes_encrypt_ctx cx[1]);
|
||||
#endif
|
||||
|
||||
#if defined(AES_VAR)
|
||||
AES_RETURN aes_encrypt_key(const unsigned char *key, int key_len, aes_encrypt_ctx cx[1]);
|
||||
#endif
|
||||
|
||||
AES_RETURN aes_encrypt(const unsigned char *in, unsigned char *out, const aes_encrypt_ctx cx[1]);
|
||||
|
||||
#endif
|
||||
|
||||
#if defined( AES_DECRYPT )
|
||||
|
||||
#if defined(AES_128) || defined(AES_VAR)
|
||||
AES_RETURN aes_decrypt_key128(const unsigned char *key, aes_decrypt_ctx cx[1]);
|
||||
#endif
|
||||
|
||||
#if defined(AES_192) || defined(AES_VAR)
|
||||
AES_RETURN aes_decrypt_key192(const unsigned char *key, aes_decrypt_ctx cx[1]);
|
||||
#endif
|
||||
|
||||
#if defined(AES_256) || defined(AES_VAR)
|
||||
AES_RETURN aes_decrypt_key256(const unsigned char *key, aes_decrypt_ctx cx[1]);
|
||||
#endif
|
||||
|
||||
#if defined(AES_VAR)
|
||||
AES_RETURN aes_decrypt_key(const unsigned char *key, int key_len, aes_decrypt_ctx cx[1]);
|
||||
#endif
|
||||
|
||||
AES_RETURN aes_decrypt(const unsigned char *in, unsigned char *out, const aes_decrypt_ctx cx[1]);
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(AES_MODES)
|
||||
|
||||
/* Multiple calls to the following subroutines for multiple block */
|
||||
/* ECB, CBC, CFB, OFB and CTR mode encryption can be used to handle */
|
||||
/* long messages incremantally provided that the context AND the iv */
|
||||
/* are preserved between all such calls. For the ECB and CBC modes */
|
||||
/* each individual call within a series of incremental calls must */
|
||||
/* process only full blocks (i.e. len must be a multiple of 16) but */
|
||||
/* the CFB, OFB and CTR mode calls can handle multiple incremental */
|
||||
/* calls of any length. Each mode is reset when a new AES key is */
|
||||
/* set but ECB and CBC operations can be reset without setting a */
|
||||
/* new key by setting a new IV value. To reset CFB, OFB and CTR */
|
||||
/* without setting the key, aes_mode_reset() must be called and the */
|
||||
/* IV must be set. NOTE: All these calls update the IV on exit so */
|
||||
/* this has to be reset if a new operation with the same IV as the */
|
||||
/* previous one is required (or decryption follows encryption with */
|
||||
/* the same IV array). */
|
||||
|
||||
AES_RETURN aes_test_alignment_detection(unsigned int n);
|
||||
|
||||
AES_RETURN aes_ecb_encrypt(const unsigned char *ibuf, unsigned char *obuf,
|
||||
int len, const aes_encrypt_ctx cx[1]);
|
||||
|
||||
AES_RETURN aes_ecb_decrypt(const unsigned char *ibuf, unsigned char *obuf,
|
||||
int len, const aes_decrypt_ctx cx[1]);
|
||||
|
||||
AES_RETURN aes_cbc_encrypt(const unsigned char *ibuf, unsigned char *obuf,
|
||||
int len, unsigned char *iv, const aes_encrypt_ctx cx[1]);
|
||||
|
||||
AES_RETURN aes_cbc_decrypt(const unsigned char *ibuf, unsigned char *obuf,
|
||||
int len, unsigned char *iv, const aes_decrypt_ctx cx[1]);
|
||||
|
||||
AES_RETURN aes_mode_reset(aes_encrypt_ctx cx[1]);
|
||||
|
||||
AES_RETURN aes_cfb_encrypt(const unsigned char *ibuf, unsigned char *obuf,
|
||||
int len, unsigned char *iv, aes_encrypt_ctx cx[1]);
|
||||
|
||||
AES_RETURN aes_cfb_decrypt(const unsigned char *ibuf, unsigned char *obuf,
|
||||
int len, unsigned char *iv, aes_encrypt_ctx cx[1]);
|
||||
|
||||
#define aes_ofb_encrypt aes_ofb_crypt
|
||||
#define aes_ofb_decrypt aes_ofb_crypt
|
||||
|
||||
AES_RETURN aes_ofb_crypt(const unsigned char *ibuf, unsigned char *obuf,
|
||||
int len, unsigned char *iv, aes_encrypt_ctx cx[1]);
|
||||
|
||||
typedef void cbuf_inc(unsigned char *cbuf);
|
||||
|
||||
#define aes_ctr_encrypt aes_ctr_crypt
|
||||
#define aes_ctr_decrypt aes_ctr_crypt
|
||||
|
||||
AES_RETURN aes_ctr_crypt(const unsigned char *ibuf, unsigned char *obuf,
|
||||
int len, unsigned char *cbuf, cbuf_inc ctr_inc, aes_encrypt_ctx cx[1]);
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Copyright (c) 1998-2007, Brian Gladman, Worcester, UK. All rights reserved.
|
||||
|
||||
LICENSE TERMS
|
||||
|
||||
The free distribution and use of this software is allowed (with or without
|
||||
changes) provided that:
|
||||
|
||||
1. source code distributions include the above copyright notice, this
|
||||
list of conditions and the following disclaimer;
|
||||
|
||||
2. binary distributions include the above copyright notice, this list
|
||||
of conditions and the following disclaimer in their documentation;
|
||||
|
||||
3. the name of the copyright holder is not used to endorse products
|
||||
built using this software without specific written permission.
|
||||
|
||||
DISCLAIMER
|
||||
|
||||
This software is provided 'as is' with no explicit or implied warranties
|
||||
in respect of its properties, including, but not limited to, correctness
|
||||
and/or fitness for purpose.
|
||||
---------------------------------------------------------------------------
|
||||
Issue Date: 20/12/2007
|
||||
|
||||
This file contains the definitions required to use AES in C. See aesopt.h
|
||||
for optimisation details.
|
||||
*/
|
||||
|
||||
/* Adapted for TrueCrypt */
|
||||
|
||||
#ifndef _AES_H
|
||||
#define _AES_H
|
||||
|
||||
#include "Common/Tcdefs.h"
|
||||
|
||||
#ifndef EXIT_SUCCESS
|
||||
#define EXIT_SUCCESS 0
|
||||
#define EXIT_FAILURE 1
|
||||
#endif
|
||||
#define INT_RETURN int
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
// #define AES_128 /* define if AES with 128 bit keys is needed */
|
||||
// #define AES_192 /* define if AES with 192 bit keys is needed */
|
||||
#define AES_256 /* define if AES with 256 bit keys is needed */
|
||||
// #define AES_VAR /* define if a variable key size is needed */
|
||||
// #define AES_MODES /* define if support is needed for modes */
|
||||
|
||||
/* The following must also be set in assembler files if being used */
|
||||
|
||||
#define AES_ENCRYPT /* if support for encryption is needed */
|
||||
#define AES_DECRYPT /* if support for decryption is needed */
|
||||
#define AES_ERR_CHK /* for parameter checks & error return codes */
|
||||
#define AES_REV_DKS /* define to reverse decryption key schedule */
|
||||
|
||||
#define AES_BLOCK_SIZE 16 /* the AES block size in bytes */
|
||||
#define N_COLS 4 /* the number of columns in the state */
|
||||
|
||||
/* The key schedule length is 11, 13 or 15 16-byte blocks for 128, */
|
||||
/* 192 or 256-bit keys respectively. That is 176, 208 or 240 bytes */
|
||||
/* or 44, 52 or 60 32-bit words. */
|
||||
|
||||
#if defined( AES_VAR ) || defined( AES_256 )
|
||||
#define KS_LENGTH 60
|
||||
#elif defined( AES_192 )
|
||||
#define KS_LENGTH 52
|
||||
#else
|
||||
#define KS_LENGTH 44
|
||||
#endif
|
||||
|
||||
#if defined( AES_ERR_CHK )
|
||||
#define AES_RETURN INT_RETURN
|
||||
#else
|
||||
#define AES_RETURN VOID_RETURN
|
||||
#endif
|
||||
|
||||
/* the character array 'inf' in the following structures is used */
|
||||
/* to hold AES context information. This AES code uses cx->inf.b[0] */
|
||||
/* to hold the number of rounds multiplied by 16. The other three */
|
||||
/* elements can be used by code that implements additional modes */
|
||||
|
||||
typedef union
|
||||
{ uint_32t l;
|
||||
uint_8t b[4];
|
||||
} aes_inf;
|
||||
|
||||
typedef struct
|
||||
{ uint_32t ks[KS_LENGTH];
|
||||
aes_inf inf;
|
||||
} aes_encrypt_ctx;
|
||||
|
||||
typedef struct
|
||||
{ uint_32t ks[KS_LENGTH];
|
||||
aes_inf inf;
|
||||
} aes_decrypt_ctx;
|
||||
|
||||
/* This routine must be called before first use if non-static */
|
||||
/* tables are being used */
|
||||
|
||||
AES_RETURN aes_init(void);
|
||||
|
||||
/* Key lengths in the range 16 <= key_len <= 32 are given in bytes, */
|
||||
/* those in the range 128 <= key_len <= 256 are given in bits */
|
||||
|
||||
#if defined( AES_ENCRYPT )
|
||||
|
||||
#if defined(AES_128) || defined(AES_VAR)
|
||||
AES_RETURN aes_encrypt_key128(const unsigned char *key, aes_encrypt_ctx cx[1]);
|
||||
#endif
|
||||
|
||||
#if defined(AES_192) || defined(AES_VAR)
|
||||
AES_RETURN aes_encrypt_key192(const unsigned char *key, aes_encrypt_ctx cx[1]);
|
||||
#endif
|
||||
|
||||
#if defined(AES_256) || defined(AES_VAR)
|
||||
AES_RETURN aes_encrypt_key256(const unsigned char *key, aes_encrypt_ctx cx[1]);
|
||||
#endif
|
||||
|
||||
#if defined(AES_VAR)
|
||||
AES_RETURN aes_encrypt_key(const unsigned char *key, int key_len, aes_encrypt_ctx cx[1]);
|
||||
#endif
|
||||
|
||||
AES_RETURN aes_encrypt(const unsigned char *in, unsigned char *out, const aes_encrypt_ctx cx[1]);
|
||||
|
||||
#endif
|
||||
|
||||
#if defined( AES_DECRYPT )
|
||||
|
||||
#if defined(AES_128) || defined(AES_VAR)
|
||||
AES_RETURN aes_decrypt_key128(const unsigned char *key, aes_decrypt_ctx cx[1]);
|
||||
#endif
|
||||
|
||||
#if defined(AES_192) || defined(AES_VAR)
|
||||
AES_RETURN aes_decrypt_key192(const unsigned char *key, aes_decrypt_ctx cx[1]);
|
||||
#endif
|
||||
|
||||
#if defined(AES_256) || defined(AES_VAR)
|
||||
AES_RETURN aes_decrypt_key256(const unsigned char *key, aes_decrypt_ctx cx[1]);
|
||||
#endif
|
||||
|
||||
#if defined(AES_VAR)
|
||||
AES_RETURN aes_decrypt_key(const unsigned char *key, int key_len, aes_decrypt_ctx cx[1]);
|
||||
#endif
|
||||
|
||||
AES_RETURN aes_decrypt(const unsigned char *in, unsigned char *out, const aes_decrypt_ctx cx[1]);
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(AES_MODES)
|
||||
|
||||
/* Multiple calls to the following subroutines for multiple block */
|
||||
/* ECB, CBC, CFB, OFB and CTR mode encryption can be used to handle */
|
||||
/* long messages incremantally provided that the context AND the iv */
|
||||
/* are preserved between all such calls. For the ECB and CBC modes */
|
||||
/* each individual call within a series of incremental calls must */
|
||||
/* process only full blocks (i.e. len must be a multiple of 16) but */
|
||||
/* the CFB, OFB and CTR mode calls can handle multiple incremental */
|
||||
/* calls of any length. Each mode is reset when a new AES key is */
|
||||
/* set but ECB and CBC operations can be reset without setting a */
|
||||
/* new key by setting a new IV value. To reset CFB, OFB and CTR */
|
||||
/* without setting the key, aes_mode_reset() must be called and the */
|
||||
/* IV must be set. NOTE: All these calls update the IV on exit so */
|
||||
/* this has to be reset if a new operation with the same IV as the */
|
||||
/* previous one is required (or decryption follows encryption with */
|
||||
/* the same IV array). */
|
||||
|
||||
AES_RETURN aes_test_alignment_detection(unsigned int n);
|
||||
|
||||
AES_RETURN aes_ecb_encrypt(const unsigned char *ibuf, unsigned char *obuf,
|
||||
int len, const aes_encrypt_ctx cx[1]);
|
||||
|
||||
AES_RETURN aes_ecb_decrypt(const unsigned char *ibuf, unsigned char *obuf,
|
||||
int len, const aes_decrypt_ctx cx[1]);
|
||||
|
||||
AES_RETURN aes_cbc_encrypt(const unsigned char *ibuf, unsigned char *obuf,
|
||||
int len, unsigned char *iv, const aes_encrypt_ctx cx[1]);
|
||||
|
||||
AES_RETURN aes_cbc_decrypt(const unsigned char *ibuf, unsigned char *obuf,
|
||||
int len, unsigned char *iv, const aes_decrypt_ctx cx[1]);
|
||||
|
||||
AES_RETURN aes_mode_reset(aes_encrypt_ctx cx[1]);
|
||||
|
||||
AES_RETURN aes_cfb_encrypt(const unsigned char *ibuf, unsigned char *obuf,
|
||||
int len, unsigned char *iv, aes_encrypt_ctx cx[1]);
|
||||
|
||||
AES_RETURN aes_cfb_decrypt(const unsigned char *ibuf, unsigned char *obuf,
|
||||
int len, unsigned char *iv, aes_encrypt_ctx cx[1]);
|
||||
|
||||
#define aes_ofb_encrypt aes_ofb_crypt
|
||||
#define aes_ofb_decrypt aes_ofb_crypt
|
||||
|
||||
AES_RETURN aes_ofb_crypt(const unsigned char *ibuf, unsigned char *obuf,
|
||||
int len, unsigned char *iv, aes_encrypt_ctx cx[1]);
|
||||
|
||||
typedef void cbuf_inc(unsigned char *cbuf);
|
||||
|
||||
#define aes_ctr_encrypt aes_ctr_crypt
|
||||
#define aes_ctr_decrypt aes_ctr_crypt
|
||||
|
||||
AES_RETURN aes_ctr_crypt(const unsigned char *ibuf, unsigned char *obuf,
|
||||
int len, unsigned char *cbuf, cbuf_inc ctr_inc, aes_encrypt_ctx cx[1]);
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,169 +1,169 @@
|
||||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Copyright (c) 1998-2006, Brian Gladman, Worcester, UK. All rights reserved.
|
||||
|
||||
LICENSE TERMS
|
||||
|
||||
The free distribution and use of this software in both source and binary
|
||||
form is allowed (with or without changes) provided that:
|
||||
|
||||
1. distributions of this source code include the above copyright
|
||||
notice, this list of conditions and the following disclaimer;
|
||||
|
||||
2. distributions in binary form include the above copyright
|
||||
notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other associated materials;
|
||||
|
||||
3. the copyright holder's name is not used to endorse products
|
||||
built using this software without specific written permission.
|
||||
|
||||
ALTERNATIVELY, provided that this notice is retained in full, this product
|
||||
may be distributed under the terms of the GNU General Public License (GPL),
|
||||
in which case the provisions of the GPL apply INSTEAD OF those given above.
|
||||
|
||||
DISCLAIMER
|
||||
|
||||
This software is provided 'as is' with no explicit or implied warranties
|
||||
in respect of its properties, including, but not limited to, correctness
|
||||
and/or fitness for purpose.
|
||||
---------------------------------------------------------------------------
|
||||
Issue 09/09/2006
|
||||
|
||||
This is an AES implementation that uses only 8-bit byte operations on the
|
||||
cipher state.
|
||||
*/
|
||||
|
||||
#ifndef AES_H
|
||||
#define AES_H
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* This provides speed optimisation opportunities if 32-bit word
|
||||
operations are available
|
||||
*/
|
||||
#if 1
|
||||
# define HAVE_UINT_32T
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
# define AES_ENC_PREKEYED /* AES encryption with a precomputed key schedule */
|
||||
#endif
|
||||
#if 1
|
||||
# define AES_DEC_PREKEYED /* AES decryption with a precomputed key schedule */
|
||||
#endif
|
||||
#if 0
|
||||
# define AES_ENC_128_OTFK /* AES encryption with 'on the fly' 128 bit keying */
|
||||
#endif
|
||||
#if 0
|
||||
# define AES_DEC_128_OTFK /* AES decryption with 'on the fly' 128 bit keying */
|
||||
#endif
|
||||
#if 0
|
||||
# define AES_ENC_256_OTFK /* AES encryption with 'on the fly' 256 bit keying */
|
||||
#endif
|
||||
#if 0
|
||||
# define AES_DEC_256_OTFK /* AES decryption with 'on the fly' 256 bit keying */
|
||||
#endif
|
||||
|
||||
#define N_ROW 4
|
||||
#define N_COL 4
|
||||
#define N_BLOCK (N_ROW * N_COL)
|
||||
#define N_MAX_ROUNDS 14
|
||||
|
||||
typedef unsigned char uint_8t;
|
||||
|
||||
typedef uint_8t return_type;
|
||||
typedef uint_8t length_type;
|
||||
typedef uint_8t uint_type;
|
||||
|
||||
typedef unsigned char uint_8t;
|
||||
|
||||
typedef struct
|
||||
{ uint_8t ksch[(N_MAX_ROUNDS + 1) * N_BLOCK];
|
||||
uint_8t rnd;
|
||||
} aes_context;
|
||||
|
||||
/* The following calls are for a precomputed key schedule
|
||||
|
||||
NOTE: If the length_type used for the key length is an
|
||||
unsigned 8-bit character, a key length of 256 bits must
|
||||
be entered as a length in bytes (valid inputs are hence
|
||||
128, 192, 16, 24 and 32).
|
||||
*/
|
||||
|
||||
#if defined( AES_ENC_PREKEYED ) || defined( AES_DEC_PREKEYED )
|
||||
|
||||
return_type aes_set_key( const unsigned char key[],
|
||||
length_type keylen,
|
||||
aes_context ctx[1] );
|
||||
#endif
|
||||
|
||||
#if defined( AES_ENC_PREKEYED )
|
||||
|
||||
return_type aes_encrypt( const unsigned char in[N_BLOCK],
|
||||
unsigned char out[N_BLOCK],
|
||||
const aes_context ctx[1] );
|
||||
#endif
|
||||
|
||||
#if defined( AES_DEC_PREKEYED )
|
||||
|
||||
return_type aes_decrypt( const unsigned char in[N_BLOCK],
|
||||
unsigned char out[N_BLOCK],
|
||||
const aes_context ctx[1] );
|
||||
#endif
|
||||
|
||||
/* The following calls are for 'on the fly' keying. In this case the
|
||||
encryption and decryption keys are different.
|
||||
|
||||
The encryption subroutines take a key in an array of bytes in
|
||||
key[L] where L is 16, 24 or 32 bytes for key lengths of 128,
|
||||
192, and 256 bits respectively. They then encrypts the input
|
||||
data, in[] with this key and put the reult in the output array
|
||||
out[]. In addition, the second key array, o_key[L], is used
|
||||
to output the key that is needed by the decryption subroutine
|
||||
to reverse the encryption operation. The two key arrays can
|
||||
be the same array but in this case the original key will be
|
||||
overwritten.
|
||||
|
||||
In the same way, the decryption subroutines output keys that
|
||||
can be used to reverse their effect when used for encryption.
|
||||
|
||||
Only 128 and 256 bit keys are supported in these 'on the fly'
|
||||
modes.
|
||||
*/
|
||||
|
||||
#if defined( AES_ENC_128_OTFK )
|
||||
void aes_encrypt_128( const unsigned char in[N_BLOCK],
|
||||
unsigned char out[N_BLOCK],
|
||||
const unsigned char key[N_BLOCK],
|
||||
uint_8t o_key[N_BLOCK] );
|
||||
#endif
|
||||
|
||||
#if defined( AES_DEC_128_OTFK )
|
||||
void aes_decrypt_128( const unsigned char in[N_BLOCK],
|
||||
unsigned char out[N_BLOCK],
|
||||
const unsigned char key[N_BLOCK],
|
||||
unsigned char o_key[N_BLOCK] );
|
||||
#endif
|
||||
|
||||
#if defined( AES_ENC_256_OTFK )
|
||||
void aes_encrypt_256( const unsigned char in[N_BLOCK],
|
||||
unsigned char out[N_BLOCK],
|
||||
const unsigned char key[2 * N_BLOCK],
|
||||
unsigned char o_key[2 * N_BLOCK] );
|
||||
#endif
|
||||
|
||||
#if defined( AES_DEC_256_OTFK )
|
||||
void aes_decrypt_256( const unsigned char in[N_BLOCK],
|
||||
unsigned char out[N_BLOCK],
|
||||
const unsigned char key[2 * N_BLOCK],
|
||||
unsigned char o_key[2 * N_BLOCK] );
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Copyright (c) 1998-2006, Brian Gladman, Worcester, UK. All rights reserved.
|
||||
|
||||
LICENSE TERMS
|
||||
|
||||
The free distribution and use of this software in both source and binary
|
||||
form is allowed (with or without changes) provided that:
|
||||
|
||||
1. distributions of this source code include the above copyright
|
||||
notice, this list of conditions and the following disclaimer;
|
||||
|
||||
2. distributions in binary form include the above copyright
|
||||
notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other associated materials;
|
||||
|
||||
3. the copyright holder's name is not used to endorse products
|
||||
built using this software without specific written permission.
|
||||
|
||||
ALTERNATIVELY, provided that this notice is retained in full, this product
|
||||
may be distributed under the terms of the GNU General Public License (GPL),
|
||||
in which case the provisions of the GPL apply INSTEAD OF those given above.
|
||||
|
||||
DISCLAIMER
|
||||
|
||||
This software is provided 'as is' with no explicit or implied warranties
|
||||
in respect of its properties, including, but not limited to, correctness
|
||||
and/or fitness for purpose.
|
||||
---------------------------------------------------------------------------
|
||||
Issue 09/09/2006
|
||||
|
||||
This is an AES implementation that uses only 8-bit byte operations on the
|
||||
cipher state.
|
||||
*/
|
||||
|
||||
#ifndef AES_H
|
||||
#define AES_H
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* This provides speed optimisation opportunities if 32-bit word
|
||||
operations are available
|
||||
*/
|
||||
#if 1
|
||||
# define HAVE_UINT_32T
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
# define AES_ENC_PREKEYED /* AES encryption with a precomputed key schedule */
|
||||
#endif
|
||||
#if 1
|
||||
# define AES_DEC_PREKEYED /* AES decryption with a precomputed key schedule */
|
||||
#endif
|
||||
#if 0
|
||||
# define AES_ENC_128_OTFK /* AES encryption with 'on the fly' 128 bit keying */
|
||||
#endif
|
||||
#if 0
|
||||
# define AES_DEC_128_OTFK /* AES decryption with 'on the fly' 128 bit keying */
|
||||
#endif
|
||||
#if 0
|
||||
# define AES_ENC_256_OTFK /* AES encryption with 'on the fly' 256 bit keying */
|
||||
#endif
|
||||
#if 0
|
||||
# define AES_DEC_256_OTFK /* AES decryption with 'on the fly' 256 bit keying */
|
||||
#endif
|
||||
|
||||
#define N_ROW 4
|
||||
#define N_COL 4
|
||||
#define N_BLOCK (N_ROW * N_COL)
|
||||
#define N_MAX_ROUNDS 14
|
||||
|
||||
typedef unsigned char uint_8t;
|
||||
|
||||
typedef uint_8t return_type;
|
||||
typedef uint_8t length_type;
|
||||
typedef uint_8t uint_type;
|
||||
|
||||
typedef unsigned char uint_8t;
|
||||
|
||||
typedef struct
|
||||
{ uint_8t ksch[(N_MAX_ROUNDS + 1) * N_BLOCK];
|
||||
uint_8t rnd;
|
||||
} aes_context;
|
||||
|
||||
/* The following calls are for a precomputed key schedule
|
||||
|
||||
NOTE: If the length_type used for the key length is an
|
||||
unsigned 8-bit character, a key length of 256 bits must
|
||||
be entered as a length in bytes (valid inputs are hence
|
||||
128, 192, 16, 24 and 32).
|
||||
*/
|
||||
|
||||
#if defined( AES_ENC_PREKEYED ) || defined( AES_DEC_PREKEYED )
|
||||
|
||||
return_type aes_set_key( const unsigned char key[],
|
||||
length_type keylen,
|
||||
aes_context ctx[1] );
|
||||
#endif
|
||||
|
||||
#if defined( AES_ENC_PREKEYED )
|
||||
|
||||
return_type aes_encrypt( const unsigned char in[N_BLOCK],
|
||||
unsigned char out[N_BLOCK],
|
||||
const aes_context ctx[1] );
|
||||
#endif
|
||||
|
||||
#if defined( AES_DEC_PREKEYED )
|
||||
|
||||
return_type aes_decrypt( const unsigned char in[N_BLOCK],
|
||||
unsigned char out[N_BLOCK],
|
||||
const aes_context ctx[1] );
|
||||
#endif
|
||||
|
||||
/* The following calls are for 'on the fly' keying. In this case the
|
||||
encryption and decryption keys are different.
|
||||
|
||||
The encryption subroutines take a key in an array of bytes in
|
||||
key[L] where L is 16, 24 or 32 bytes for key lengths of 128,
|
||||
192, and 256 bits respectively. They then encrypts the input
|
||||
data, in[] with this key and put the reult in the output array
|
||||
out[]. In addition, the second key array, o_key[L], is used
|
||||
to output the key that is needed by the decryption subroutine
|
||||
to reverse the encryption operation. The two key arrays can
|
||||
be the same array but in this case the original key will be
|
||||
overwritten.
|
||||
|
||||
In the same way, the decryption subroutines output keys that
|
||||
can be used to reverse their effect when used for encryption.
|
||||
|
||||
Only 128 and 256 bit keys are supported in these 'on the fly'
|
||||
modes.
|
||||
*/
|
||||
|
||||
#if defined( AES_ENC_128_OTFK )
|
||||
void aes_encrypt_128( const unsigned char in[N_BLOCK],
|
||||
unsigned char out[N_BLOCK],
|
||||
const unsigned char key[N_BLOCK],
|
||||
uint_8t o_key[N_BLOCK] );
|
||||
#endif
|
||||
|
||||
#if defined( AES_DEC_128_OTFK )
|
||||
void aes_decrypt_128( const unsigned char in[N_BLOCK],
|
||||
unsigned char out[N_BLOCK],
|
||||
const unsigned char key[N_BLOCK],
|
||||
unsigned char o_key[N_BLOCK] );
|
||||
#endif
|
||||
|
||||
#if defined( AES_ENC_256_OTFK )
|
||||
void aes_encrypt_256( const unsigned char in[N_BLOCK],
|
||||
unsigned char out[N_BLOCK],
|
||||
const unsigned char key[2 * N_BLOCK],
|
||||
unsigned char o_key[2 * N_BLOCK] );
|
||||
#endif
|
||||
|
||||
#if defined( AES_DEC_256_OTFK )
|
||||
void aes_decrypt_256( const unsigned char in[N_BLOCK],
|
||||
unsigned char out[N_BLOCK],
|
||||
const unsigned char key[2 * N_BLOCK],
|
||||
unsigned char o_key[2 * N_BLOCK] );
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,330 +1,330 @@
|
||||
;
|
||||
; Copyright (c) 2010 TrueCrypt Developers Association. All rights reserved.
|
||||
;
|
||||
; Governed by the TrueCrypt License 3.0 the full text of which is contained in
|
||||
; the file License.txt included in TrueCrypt binary and source code distribution
|
||||
; packages.
|
||||
;
|
||||
|
||||
|
||||
%ifidn __BITS__, 16
|
||||
%define R e
|
||||
%elifidn __BITS__, 32
|
||||
%define R e
|
||||
%elifidn __BITS__, 64
|
||||
%define R r
|
||||
%endif
|
||||
|
||||
|
||||
%macro export_function 1-2 0
|
||||
|
||||
%ifdef MS_STDCALL
|
||||
global %1@%2
|
||||
export _%1@%2
|
||||
%1@%2:
|
||||
%elifidn __BITS__, 16
|
||||
global _%1
|
||||
_%1:
|
||||
%else
|
||||
global %1
|
||||
%1:
|
||||
%endif
|
||||
|
||||
%endmacro
|
||||
|
||||
|
||||
%macro aes_function_entry 1
|
||||
|
||||
; void (const byte *ks, byte *data);
|
||||
|
||||
export_function %1, 8
|
||||
|
||||
%ifidn __BITS__, 32
|
||||
mov ecx, [esp + 4 + 4 * 0]
|
||||
mov edx, [esp + 4 + 4 * 1]
|
||||
%elifidn __BITS__, 64
|
||||
%ifnidn __OUTPUT_FORMAT__, win64
|
||||
mov rcx, rdi
|
||||
mov rdx, rsi
|
||||
%endif
|
||||
%endif
|
||||
|
||||
; ecx/rcx = ks
|
||||
; edx/rdx = data
|
||||
|
||||
%endmacro
|
||||
|
||||
|
||||
%macro aes_function_exit 0
|
||||
|
||||
; void (const byte *, byte *);
|
||||
|
||||
%ifdef MS_STDCALL
|
||||
ret 8
|
||||
%else
|
||||
ret
|
||||
%endif
|
||||
|
||||
%endmacro
|
||||
|
||||
|
||||
%macro push_xmm 2
|
||||
sub rsp, 16 * (%2 - %1 + 1)
|
||||
|
||||
%assign stackoffset 0
|
||||
%assign regnumber %1
|
||||
|
||||
%rep (%2 - %1 + 1)
|
||||
movdqu [rsp + 16 * stackoffset], xmm%[regnumber]
|
||||
|
||||
%assign stackoffset stackoffset+1
|
||||
%assign regnumber regnumber+1
|
||||
%endrep
|
||||
%endmacro
|
||||
|
||||
|
||||
%macro pop_xmm 2
|
||||
%assign stackoffset 0
|
||||
%assign regnumber %1
|
||||
|
||||
%rep (%2 - %1 + 1)
|
||||
movdqu xmm%[regnumber], [rsp + 16 * stackoffset]
|
||||
|
||||
%assign stackoffset stackoffset+1
|
||||
%assign regnumber regnumber+1
|
||||
%endrep
|
||||
|
||||
add rsp, 16 * (%2 - %1 + 1)
|
||||
%endmacro
|
||||
|
||||
|
||||
%macro aes_hw_cpu 2
|
||||
%define OPERATION %1
|
||||
%define BLOCK_COUNT %2
|
||||
|
||||
; Load data blocks
|
||||
%assign block 1
|
||||
%rep BLOCK_COUNT
|
||||
movdqu xmm%[block], [%[R]dx + 16 * (block - 1)]
|
||||
%assign block block+1
|
||||
%endrep
|
||||
|
||||
; Encrypt/decrypt data blocks
|
||||
%assign round 0
|
||||
%rep 15
|
||||
movdqu xmm0, [%[R]cx + 16 * round]
|
||||
|
||||
%assign block 1
|
||||
%rep BLOCK_COUNT
|
||||
|
||||
%if round = 0
|
||||
pxor xmm%[block], xmm0
|
||||
%else
|
||||
%if round < 14
|
||||
aes%[OPERATION] xmm%[block], xmm0
|
||||
%else
|
||||
aes%[OPERATION]last xmm%[block], xmm0
|
||||
%endif
|
||||
%endif
|
||||
|
||||
%assign block block+1
|
||||
%endrep
|
||||
|
||||
%assign round round+1
|
||||
%endrep
|
||||
|
||||
; Store data blocks
|
||||
%assign block 1
|
||||
%rep BLOCK_COUNT
|
||||
movdqu [%[R]dx + 16 * (block - 1)], xmm%[block]
|
||||
%assign block block+1
|
||||
%endrep
|
||||
|
||||
%undef OPERATION
|
||||
%undef BLOCK_COUNT
|
||||
%endmacro
|
||||
|
||||
|
||||
%macro aes_hw_cpu_32_blocks 1
|
||||
%define OPERATION_32_BLOCKS %1
|
||||
|
||||
%ifidn __BITS__, 64
|
||||
%define MAX_REG_BLOCK_COUNT 15
|
||||
%else
|
||||
%define MAX_REG_BLOCK_COUNT 7
|
||||
%endif
|
||||
|
||||
%ifidn __OUTPUT_FORMAT__, win64
|
||||
%if MAX_REG_BLOCK_COUNT > 5
|
||||
push_xmm 6, MAX_REG_BLOCK_COUNT
|
||||
%endif
|
||||
%endif
|
||||
|
||||
mov eax, 32 / MAX_REG_BLOCK_COUNT
|
||||
.1:
|
||||
aes_hw_cpu %[OPERATION_32_BLOCKS], MAX_REG_BLOCK_COUNT
|
||||
|
||||
add %[R]dx, 16 * MAX_REG_BLOCK_COUNT
|
||||
dec eax
|
||||
jnz .1
|
||||
|
||||
%if (32 % MAX_REG_BLOCK_COUNT) != 0
|
||||
aes_hw_cpu %[OPERATION_32_BLOCKS], (32 % MAX_REG_BLOCK_COUNT)
|
||||
%endif
|
||||
|
||||
%ifidn __OUTPUT_FORMAT__, win64
|
||||
%if MAX_REG_BLOCK_COUNT > 5
|
||||
pop_xmm 6, MAX_REG_BLOCK_COUNT
|
||||
%endif
|
||||
%endif
|
||||
|
||||
%undef OPERATION_32_BLOCKS
|
||||
%undef MAX_REG_BLOCK_COUNT
|
||||
%endmacro
|
||||
|
||||
|
||||
%ifidn __BITS__, 16
|
||||
|
||||
USE16
|
||||
SEGMENT _TEXT PUBLIC CLASS=CODE USE16
|
||||
SEGMENT _DATA PUBLIC CLASS=DATA USE16
|
||||
GROUP DGROUP _TEXT _DATA
|
||||
SECTION _TEXT
|
||||
|
||||
%else
|
||||
|
||||
SECTION .text
|
||||
|
||||
%endif
|
||||
|
||||
|
||||
; void aes_hw_cpu_enable_sse ();
|
||||
|
||||
export_function aes_hw_cpu_enable_sse
|
||||
mov %[R]ax, cr4
|
||||
or ax, 1 << 9
|
||||
mov cr4, %[R]ax
|
||||
ret
|
||||
|
||||
|
||||
%ifidn __BITS__, 16
|
||||
|
||||
|
||||
; byte is_aes_hw_cpu_supported ();
|
||||
|
||||
export_function is_aes_hw_cpu_supported
|
||||
mov eax, 1
|
||||
cpuid
|
||||
mov eax, ecx
|
||||
shr eax, 25
|
||||
and al, 1
|
||||
ret
|
||||
|
||||
|
||||
; void aes_hw_cpu_decrypt (const byte *ks, byte *data);
|
||||
|
||||
export_function aes_hw_cpu_decrypt
|
||||
mov ax, -16
|
||||
jmp aes_hw_cpu_encrypt_decrypt
|
||||
|
||||
; void aes_hw_cpu_encrypt (const byte *ks, byte *data);
|
||||
|
||||
export_function aes_hw_cpu_encrypt
|
||||
mov ax, 16
|
||||
|
||||
aes_hw_cpu_encrypt_decrypt:
|
||||
push bp
|
||||
mov bp, sp
|
||||
push di
|
||||
push si
|
||||
|
||||
mov si, [bp + 4] ; ks
|
||||
mov di, [bp + 4 + 2] ; data
|
||||
|
||||
movdqu xmm0, [si]
|
||||
movdqu xmm1, [di]
|
||||
|
||||
pxor xmm1, xmm0
|
||||
|
||||
mov cx, 13
|
||||
|
||||
.round1_13:
|
||||
add si, ax
|
||||
movdqu xmm0, [si]
|
||||
|
||||
cmp ax, 0
|
||||
jl .decrypt
|
||||
|
||||
aesenc xmm1, xmm0
|
||||
jmp .2
|
||||
.decrypt:
|
||||
aesdec xmm1, xmm0
|
||||
.2:
|
||||
loop .round1_13
|
||||
|
||||
add si, ax
|
||||
movdqu xmm0, [si]
|
||||
|
||||
cmp ax, 0
|
||||
jl .decrypt_last
|
||||
|
||||
aesenclast xmm1, xmm0
|
||||
jmp .3
|
||||
.decrypt_last:
|
||||
aesdeclast xmm1, xmm0
|
||||
.3:
|
||||
movdqu [di], xmm1
|
||||
|
||||
pop si
|
||||
pop di
|
||||
pop bp
|
||||
ret
|
||||
|
||||
|
||||
%else ; __BITS__ != 16
|
||||
|
||||
|
||||
; byte is_aes_hw_cpu_supported ();
|
||||
|
||||
export_function is_aes_hw_cpu_supported
|
||||
push %[R]bx
|
||||
|
||||
mov eax, 1
|
||||
cpuid
|
||||
mov eax, ecx
|
||||
shr eax, 25
|
||||
and eax, 1
|
||||
|
||||
pop %[R]bx
|
||||
ret
|
||||
|
||||
|
||||
; void aes_hw_cpu_decrypt (const byte *ks, byte *data);
|
||||
|
||||
aes_function_entry aes_hw_cpu_decrypt
|
||||
aes_hw_cpu dec, 1
|
||||
aes_function_exit
|
||||
|
||||
|
||||
; void aes_hw_cpu_decrypt_32_blocks (const byte *ks, byte *data);
|
||||
|
||||
aes_function_entry aes_hw_cpu_decrypt_32_blocks
|
||||
aes_hw_cpu_32_blocks dec
|
||||
aes_function_exit
|
||||
|
||||
|
||||
; void aes_hw_cpu_encrypt (const byte *ks, byte *data);
|
||||
|
||||
aes_function_entry aes_hw_cpu_encrypt
|
||||
aes_hw_cpu enc, 1
|
||||
aes_function_exit
|
||||
|
||||
|
||||
; void aes_hw_cpu_encrypt_32_blocks (const byte *ks, byte *data);
|
||||
|
||||
aes_function_entry aes_hw_cpu_encrypt_32_blocks
|
||||
aes_hw_cpu_32_blocks enc
|
||||
aes_function_exit
|
||||
|
||||
|
||||
%endif ; __BITS__ != 16
|
||||
;
|
||||
; Copyright (c) 2010 TrueCrypt Developers Association. All rights reserved.
|
||||
;
|
||||
; Governed by the TrueCrypt License 3.0 the full text of which is contained in
|
||||
; the file License.txt included in TrueCrypt binary and source code distribution
|
||||
; packages.
|
||||
;
|
||||
|
||||
|
||||
%ifidn __BITS__, 16
|
||||
%define R e
|
||||
%elifidn __BITS__, 32
|
||||
%define R e
|
||||
%elifidn __BITS__, 64
|
||||
%define R r
|
||||
%endif
|
||||
|
||||
|
||||
%macro export_function 1-2 0
|
||||
|
||||
%ifdef MS_STDCALL
|
||||
global %1@%2
|
||||
export _%1@%2
|
||||
%1@%2:
|
||||
%elifidn __BITS__, 16
|
||||
global _%1
|
||||
_%1:
|
||||
%else
|
||||
global %1
|
||||
%1:
|
||||
%endif
|
||||
|
||||
%endmacro
|
||||
|
||||
|
||||
%macro aes_function_entry 1
|
||||
|
||||
; void (const byte *ks, byte *data);
|
||||
|
||||
export_function %1, 8
|
||||
|
||||
%ifidn __BITS__, 32
|
||||
mov ecx, [esp + 4 + 4 * 0]
|
||||
mov edx, [esp + 4 + 4 * 1]
|
||||
%elifidn __BITS__, 64
|
||||
%ifnidn __OUTPUT_FORMAT__, win64
|
||||
mov rcx, rdi
|
||||
mov rdx, rsi
|
||||
%endif
|
||||
%endif
|
||||
|
||||
; ecx/rcx = ks
|
||||
; edx/rdx = data
|
||||
|
||||
%endmacro
|
||||
|
||||
|
||||
%macro aes_function_exit 0
|
||||
|
||||
; void (const byte *, byte *);
|
||||
|
||||
%ifdef MS_STDCALL
|
||||
ret 8
|
||||
%else
|
||||
ret
|
||||
%endif
|
||||
|
||||
%endmacro
|
||||
|
||||
|
||||
%macro push_xmm 2
|
||||
sub rsp, 16 * (%2 - %1 + 1)
|
||||
|
||||
%assign stackoffset 0
|
||||
%assign regnumber %1
|
||||
|
||||
%rep (%2 - %1 + 1)
|
||||
movdqu [rsp + 16 * stackoffset], xmm%[regnumber]
|
||||
|
||||
%assign stackoffset stackoffset+1
|
||||
%assign regnumber regnumber+1
|
||||
%endrep
|
||||
%endmacro
|
||||
|
||||
|
||||
%macro pop_xmm 2
|
||||
%assign stackoffset 0
|
||||
%assign regnumber %1
|
||||
|
||||
%rep (%2 - %1 + 1)
|
||||
movdqu xmm%[regnumber], [rsp + 16 * stackoffset]
|
||||
|
||||
%assign stackoffset stackoffset+1
|
||||
%assign regnumber regnumber+1
|
||||
%endrep
|
||||
|
||||
add rsp, 16 * (%2 - %1 + 1)
|
||||
%endmacro
|
||||
|
||||
|
||||
%macro aes_hw_cpu 2
|
||||
%define OPERATION %1
|
||||
%define BLOCK_COUNT %2
|
||||
|
||||
; Load data blocks
|
||||
%assign block 1
|
||||
%rep BLOCK_COUNT
|
||||
movdqu xmm%[block], [%[R]dx + 16 * (block - 1)]
|
||||
%assign block block+1
|
||||
%endrep
|
||||
|
||||
; Encrypt/decrypt data blocks
|
||||
%assign round 0
|
||||
%rep 15
|
||||
movdqu xmm0, [%[R]cx + 16 * round]
|
||||
|
||||
%assign block 1
|
||||
%rep BLOCK_COUNT
|
||||
|
||||
%if round = 0
|
||||
pxor xmm%[block], xmm0
|
||||
%else
|
||||
%if round < 14
|
||||
aes%[OPERATION] xmm%[block], xmm0
|
||||
%else
|
||||
aes%[OPERATION]last xmm%[block], xmm0
|
||||
%endif
|
||||
%endif
|
||||
|
||||
%assign block block+1
|
||||
%endrep
|
||||
|
||||
%assign round round+1
|
||||
%endrep
|
||||
|
||||
; Store data blocks
|
||||
%assign block 1
|
||||
%rep BLOCK_COUNT
|
||||
movdqu [%[R]dx + 16 * (block - 1)], xmm%[block]
|
||||
%assign block block+1
|
||||
%endrep
|
||||
|
||||
%undef OPERATION
|
||||
%undef BLOCK_COUNT
|
||||
%endmacro
|
||||
|
||||
|
||||
%macro aes_hw_cpu_32_blocks 1
|
||||
%define OPERATION_32_BLOCKS %1
|
||||
|
||||
%ifidn __BITS__, 64
|
||||
%define MAX_REG_BLOCK_COUNT 15
|
||||
%else
|
||||
%define MAX_REG_BLOCK_COUNT 7
|
||||
%endif
|
||||
|
||||
%ifidn __OUTPUT_FORMAT__, win64
|
||||
%if MAX_REG_BLOCK_COUNT > 5
|
||||
push_xmm 6, MAX_REG_BLOCK_COUNT
|
||||
%endif
|
||||
%endif
|
||||
|
||||
mov eax, 32 / MAX_REG_BLOCK_COUNT
|
||||
.1:
|
||||
aes_hw_cpu %[OPERATION_32_BLOCKS], MAX_REG_BLOCK_COUNT
|
||||
|
||||
add %[R]dx, 16 * MAX_REG_BLOCK_COUNT
|
||||
dec eax
|
||||
jnz .1
|
||||
|
||||
%if (32 % MAX_REG_BLOCK_COUNT) != 0
|
||||
aes_hw_cpu %[OPERATION_32_BLOCKS], (32 % MAX_REG_BLOCK_COUNT)
|
||||
%endif
|
||||
|
||||
%ifidn __OUTPUT_FORMAT__, win64
|
||||
%if MAX_REG_BLOCK_COUNT > 5
|
||||
pop_xmm 6, MAX_REG_BLOCK_COUNT
|
||||
%endif
|
||||
%endif
|
||||
|
||||
%undef OPERATION_32_BLOCKS
|
||||
%undef MAX_REG_BLOCK_COUNT
|
||||
%endmacro
|
||||
|
||||
|
||||
%ifidn __BITS__, 16
|
||||
|
||||
USE16
|
||||
SEGMENT _TEXT PUBLIC CLASS=CODE USE16
|
||||
SEGMENT _DATA PUBLIC CLASS=DATA USE16
|
||||
GROUP DGROUP _TEXT _DATA
|
||||
SECTION _TEXT
|
||||
|
||||
%else
|
||||
|
||||
SECTION .text
|
||||
|
||||
%endif
|
||||
|
||||
|
||||
; void aes_hw_cpu_enable_sse ();
|
||||
|
||||
export_function aes_hw_cpu_enable_sse
|
||||
mov %[R]ax, cr4
|
||||
or ax, 1 << 9
|
||||
mov cr4, %[R]ax
|
||||
ret
|
||||
|
||||
|
||||
%ifidn __BITS__, 16
|
||||
|
||||
|
||||
; byte is_aes_hw_cpu_supported ();
|
||||
|
||||
export_function is_aes_hw_cpu_supported
|
||||
mov eax, 1
|
||||
cpuid
|
||||
mov eax, ecx
|
||||
shr eax, 25
|
||||
and al, 1
|
||||
ret
|
||||
|
||||
|
||||
; void aes_hw_cpu_decrypt (const byte *ks, byte *data);
|
||||
|
||||
export_function aes_hw_cpu_decrypt
|
||||
mov ax, -16
|
||||
jmp aes_hw_cpu_encrypt_decrypt
|
||||
|
||||
; void aes_hw_cpu_encrypt (const byte *ks, byte *data);
|
||||
|
||||
export_function aes_hw_cpu_encrypt
|
||||
mov ax, 16
|
||||
|
||||
aes_hw_cpu_encrypt_decrypt:
|
||||
push bp
|
||||
mov bp, sp
|
||||
push di
|
||||
push si
|
||||
|
||||
mov si, [bp + 4] ; ks
|
||||
mov di, [bp + 4 + 2] ; data
|
||||
|
||||
movdqu xmm0, [si]
|
||||
movdqu xmm1, [di]
|
||||
|
||||
pxor xmm1, xmm0
|
||||
|
||||
mov cx, 13
|
||||
|
||||
.round1_13:
|
||||
add si, ax
|
||||
movdqu xmm0, [si]
|
||||
|
||||
cmp ax, 0
|
||||
jl .decrypt
|
||||
|
||||
aesenc xmm1, xmm0
|
||||
jmp .2
|
||||
.decrypt:
|
||||
aesdec xmm1, xmm0
|
||||
.2:
|
||||
loop .round1_13
|
||||
|
||||
add si, ax
|
||||
movdqu xmm0, [si]
|
||||
|
||||
cmp ax, 0
|
||||
jl .decrypt_last
|
||||
|
||||
aesenclast xmm1, xmm0
|
||||
jmp .3
|
||||
.decrypt_last:
|
||||
aesdeclast xmm1, xmm0
|
||||
.3:
|
||||
movdqu [di], xmm1
|
||||
|
||||
pop si
|
||||
pop di
|
||||
pop bp
|
||||
ret
|
||||
|
||||
|
||||
%else ; __BITS__ != 16
|
||||
|
||||
|
||||
; byte is_aes_hw_cpu_supported ();
|
||||
|
||||
export_function is_aes_hw_cpu_supported
|
||||
push %[R]bx
|
||||
|
||||
mov eax, 1
|
||||
cpuid
|
||||
mov eax, ecx
|
||||
shr eax, 25
|
||||
and eax, 1
|
||||
|
||||
pop %[R]bx
|
||||
ret
|
||||
|
||||
|
||||
; void aes_hw_cpu_decrypt (const byte *ks, byte *data);
|
||||
|
||||
aes_function_entry aes_hw_cpu_decrypt
|
||||
aes_hw_cpu dec, 1
|
||||
aes_function_exit
|
||||
|
||||
|
||||
; void aes_hw_cpu_decrypt_32_blocks (const byte *ks, byte *data);
|
||||
|
||||
aes_function_entry aes_hw_cpu_decrypt_32_blocks
|
||||
aes_hw_cpu_32_blocks dec
|
||||
aes_function_exit
|
||||
|
||||
|
||||
; void aes_hw_cpu_encrypt (const byte *ks, byte *data);
|
||||
|
||||
aes_function_entry aes_hw_cpu_encrypt
|
||||
aes_hw_cpu enc, 1
|
||||
aes_function_exit
|
||||
|
||||
|
||||
; void aes_hw_cpu_encrypt_32_blocks (const byte *ks, byte *data);
|
||||
|
||||
aes_function_entry aes_hw_cpu_encrypt_32_blocks
|
||||
aes_hw_cpu_32_blocks enc
|
||||
aes_function_exit
|
||||
|
||||
|
||||
%endif ; __BITS__ != 16
|
||||
|
||||
@@ -8,27 +8,27 @@
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Crypto_Aes_Hw_Cpu
|
||||
#define TC_HEADER_Crypto_Aes_Hw_Cpu
|
||||
|
||||
#include "Common/Tcdefs.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
byte is_aes_hw_cpu_supported ();
|
||||
void aes_hw_cpu_enable_sse ();
|
||||
void aes_hw_cpu_decrypt (const byte *ks, byte *data);
|
||||
void aes_hw_cpu_decrypt_32_blocks (const byte *ks, byte *data);
|
||||
void aes_hw_cpu_encrypt (const byte *ks, byte *data);
|
||||
void aes_hw_cpu_encrypt_32_blocks (const byte *ks, byte *data);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_Crypto_Aes_Hw_Cpu
|
||||
*/
|
||||
|
||||
#ifndef TC_HEADER_Crypto_Aes_Hw_Cpu
|
||||
#define TC_HEADER_Crypto_Aes_Hw_Cpu
|
||||
|
||||
#include "Common/Tcdefs.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
byte is_aes_hw_cpu_supported ();
|
||||
void aes_hw_cpu_enable_sse ();
|
||||
void aes_hw_cpu_decrypt (const byte *ks, byte *data);
|
||||
void aes_hw_cpu_decrypt_32_blocks (const byte *ks, byte *data);
|
||||
void aes_hw_cpu_encrypt (const byte *ks, byte *data);
|
||||
void aes_hw_cpu_encrypt_32_blocks (const byte *ks, byte *data);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TC_HEADER_Crypto_Aes_Hw_Cpu
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user