mirror of
https://github.com/veracrypt/VeraCrypt
synced 2024-11-27 13:33:29 +01:00
Normalize all line terminators
This commit is contained in:
parent
98b04198c6
commit
fc37cc4a02
1006
License.txt
1006
License.txt
File diff suppressed because it is too large
Load Diff
528
README.md
528
README.md
@ -1,264 +1,264 @@
|
||||
This archive contains the source code of VeraCrypt.
|
||||
It is based on original TrueCrypt 7.1a with security enhancements and modifications.
|
||||
|
||||
|
||||
Important
|
||||
=========
|
||||
|
||||
You may use the source code contained in this archive only if you accept and
|
||||
agree to the license terms contained in the file 'License.txt', which is
|
||||
included in this archive.
|
||||
|
||||
Note that the license specifies, for example, that a derived work must not be
|
||||
called 'TrueCrypt' or 'VeraCrypt'
|
||||
|
||||
|
||||
|
||||
Contents
|
||||
========
|
||||
|
||||
I. Windows
|
||||
Requirements for Building VeraCrypt for Windows
|
||||
Instructions for Building VeraCrypt for Windows
|
||||
Instructions for Signing and Packaging VeraCrypt for Windows
|
||||
|
||||
II. Linux and Mac OS X
|
||||
Requirements for Building VeraCrypt for Linux and Mac OS X
|
||||
Instructions for Building VeraCrypt for Linux and Mac OS X
|
||||
Mac OS X specifics
|
||||
|
||||
III. FreeBSD and OpenSolaris
|
||||
|
||||
IV. Third-Party Developers (Contributors)
|
||||
|
||||
V. Legal Information
|
||||
|
||||
VI. Further Information
|
||||
|
||||
|
||||
|
||||
I. Windows
|
||||
==========
|
||||
|
||||
Requirements for Building VeraCrypt for Windows:
|
||||
------------------------------------------------
|
||||
|
||||
- Microsoft Visual C++ 2008 SP1 (Professional Edition or compatible)
|
||||
- Microsoft Visual C++ 1.52 (available from MSDN Subscriber Downloads)
|
||||
- Microsoft Windows SDK for Windows 7 (configured for Visual C++)
|
||||
- Microsoft Windows SDK for Windows 8.1 (needed for SHA-256 code signing)
|
||||
- Microsoft Windows Driver Kit 7.1.0 (build 7600.16385.1)
|
||||
- RSA Security Inc. PKCS #11 Cryptographic Token Interface (Cryptoki) 2.20
|
||||
header files (available at ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-11/v2-20)
|
||||
- NASM assembler 2.08 or compatible
|
||||
- gzip compressor
|
||||
- upx packer (available at http://upx.sourceforge.net/)
|
||||
|
||||
IMPORTANT:
|
||||
|
||||
The 64-bit editions of Windows Vista and later versions of Windows, and in
|
||||
some cases (e.g. playback of HD DVD content) also the 32-bit editions, do not
|
||||
allow the VeraCrypt driver to run without an appropriate digital signature.
|
||||
Therefore, all .sys files in official VeraCrypt binary packages are digitally
|
||||
signed with the digital certificate of the IDRIX, which was
|
||||
issued by Thawte certification authority. At the end of each official .exe and
|
||||
.sys file, there are embedded digital signatures and all related certificates
|
||||
(i.e. all certificates in the relevant certification chain, such as the
|
||||
certification authority certificates, CA-MS cross-certificate, and the
|
||||
IDRIX certificate).
|
||||
Keep this in mind if you compile VeraCrypt
|
||||
and compare your binaries with the official binaries. If your binaries are
|
||||
unsigned, the sizes of the official binaries will usually be approximately
|
||||
10 KB greater than sizes of your binaries (there may be further differences
|
||||
if you use a different version of the compiler, or if you install a different
|
||||
or no service pack for Visual Studio, or different hotfixes for it, or if you
|
||||
use different versions of the required SDKs).
|
||||
|
||||
|
||||
Instructions for Building VeraCrypt for Windows:
|
||||
------------------------------------------------
|
||||
|
||||
1) Create an environment variable 'MSVC16_ROOT' pointing to the folder 'MSVC15'
|
||||
extracted from the Visual C++ 1.52 self-extracting package.
|
||||
|
||||
Note: The 16-bit installer MSVC15\SETUP.EXE cannot be run on 64-bit Windows,
|
||||
but it is actually not necessary to run it. You only need to extract the
|
||||
folder 'MSVC15', which contains the 32-bit binaries required to build the
|
||||
VeraCrypt Boot Loader.
|
||||
|
||||
2) If you have installed the Windows Driver Development Kit in another
|
||||
directory than '%SYSTEMDRIVE%\WinDDK', create an environment variable
|
||||
'WINDDK_ROOT' pointing to the DDK installation directory.
|
||||
|
||||
3) Copy the PKCS #11 header files to a standard include path or create an
|
||||
environment variable 'PKCS11_INC' pointing to the directory where
|
||||
the PKCS #11 header files are installed.
|
||||
|
||||
4) Open the solution file 'VeraCrypt.sln' in Microsoft Visual Studio 2008.
|
||||
|
||||
5) Select 'All' as the active solution configuration.
|
||||
|
||||
6) Build the solution.
|
||||
|
||||
7) If successful, there should be newly built VeraCrypt binaries in the
|
||||
'Release' folder.
|
||||
|
||||
Instructions for Signing and Packaging VeraCrypt for Windows:
|
||||
-------------------------------------------------------------
|
||||
|
||||
First, create an environment variable 'WSDK81' pointing to the Windows SDK
|
||||
for Windows 8.1 installation directory.
|
||||
The folder "Signing" contains a batch file (sign.bat) that will sign all
|
||||
VeraCrypt components using a code signing certificate present on the
|
||||
certificate store and also build the final installation setup.
|
||||
The batch file suppose that the code signing certificate is issued by Thawt.
|
||||
This is the case for IDRIX's certificate. If yours is issued by another CA,
|
||||
then you should put the Root and Intermediate certificates in the "Signing"
|
||||
folder and then modify sign.bat accordingly.
|
||||
|
||||
|
||||
II. Linux and Mac OS X
|
||||
======================
|
||||
|
||||
Requirements for Building VeraCrypt for Linux and Mac OS X:
|
||||
-----------------------------------------------------------
|
||||
|
||||
- GNU Make
|
||||
- GNU C++ Compiler 4.0 or compatible
|
||||
- Apple Xcode (Mac OS X only)
|
||||
- NASM assembler 2.08 or compatible (x86/x64 architecture only)
|
||||
- pkg-config
|
||||
- makeself (Linux only)
|
||||
- wxWidgets 3.0 shared library and header files installed or
|
||||
wxWidgets 3.0 library source code (available at http://www.wxwidgets.org)
|
||||
- FUSE library and header files (available at https://github.com/libfuse/libfuse
|
||||
and https://osxfuse.github.io/)
|
||||
- RSA Security Inc. PKCS #11 Cryptographic Token Interface (Cryptoki) 2.20
|
||||
header files (available at ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-11/v2-20).
|
||||
They are already included in the source tree under the directory PKCS11 but
|
||||
it is possible to override it using the environment variable 'PKCS11_INC'.
|
||||
|
||||
|
||||
Instructions for Building VeraCrypt for Linux and Mac OS X:
|
||||
-----------------------------------------------------------
|
||||
|
||||
1) Change the current directory to the root of the VeraCrypt source code.
|
||||
|
||||
2) If you have no wxWidgets shared library installed, run the following
|
||||
command to configure the wxWidgets static library for VeraCrypt and to
|
||||
build it:
|
||||
|
||||
$ make WXSTATIC=1 WX_ROOT=/usr/src/wxWidgets wxbuild
|
||||
|
||||
The variable WX_ROOT must point to the location of the source code of the
|
||||
wxWidgets library. Output files will be placed in the './wxrelease/'
|
||||
directory.
|
||||
|
||||
3) To build VeraCrypt, run the following command:
|
||||
|
||||
$ make
|
||||
|
||||
or if you have no wxWidgets shared library installed:
|
||||
|
||||
$ make WXSTATIC=1
|
||||
|
||||
4) If successful, the VeraCrypt executable should be located in the directory
|
||||
'Main'.
|
||||
|
||||
By default, a universal executable supporting both graphical and text user
|
||||
interface (through the switch --text) is built.
|
||||
On Linux, a console-only executable, which requires no GUI library, can be
|
||||
built using the 'NOGUI' parameter:
|
||||
|
||||
$ make NOGUI=1 WXSTATIC=1 WX_ROOT=/usr/src/wxWidgets wxbuild
|
||||
$ make NOGUI=1 WXSTATIC=1
|
||||
|
||||
On MacOSX, building a console-only executable is not supported.
|
||||
|
||||
Mac OS X specifics:
|
||||
-----------------------------------------------------------
|
||||
|
||||
Under MacOSX, the SDK for OSX 10.7 is used by default. To use another version
|
||||
of the SDK (i.e. 10.6), you can export the environment variable VC_OSX_TARGET:
|
||||
|
||||
$ export VC_OSX_TARGET=10.6
|
||||
|
||||
|
||||
Before building under MacOSX, pkg-config must be installed if not yet available.
|
||||
Get it from http://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz and
|
||||
compile using the following commands :
|
||||
|
||||
$ ./configure --with-internal-glib
|
||||
$ make
|
||||
$ sudo make install
|
||||
|
||||
After making sure pkg-config is available, download and install OSXFuse from
|
||||
https://osxfuse.github.io/ (MacFUSE compatibility layer must selected)
|
||||
|
||||
The script build_veracrypt_macosx.sh available under "src/Build" performs the
|
||||
full build of VeraCrypt including the creation of the installer pkg. It expects
|
||||
to find the wxWidgets 3.0.2 sources at the same level as where you put
|
||||
VeraCrypt sources (i.e. if "src" path is "/Users/joe/Projects/VeraCrypt/src"
|
||||
then wxWidgets should be at "/Users/joe/Projects/wxWidgets-wxWidgets-3.0.2")
|
||||
|
||||
The build process uses Code Signing certificates whose ID is specified in
|
||||
src/Main/Main.make (lines 167 & 169). You'll have to modify these lines to put
|
||||
the ID of your Code Signing certificates or comment them if you don't have one.
|
||||
|
||||
Because of incompatibility issues with OSXFUSE, the SDK 10.9 generates a
|
||||
VeraCrypt binary that has issues communicating with the OSXFUSE kernel extension.
|
||||
Thus, we recommend to use the SDK 10.8 or earlier for building VeraCrypt.
|
||||
|
||||
|
||||
|
||||
III. FreeBSD and OpenSolaris
|
||||
============================
|
||||
|
||||
FreeBSD and OpenSolaris are not yet supported.
|
||||
|
||||
|
||||
|
||||
IV. Third-Party Developers (Contributors)
|
||||
=========================================
|
||||
|
||||
If you intend to implement a feature, please contact us first to make sure:
|
||||
|
||||
1) That the feature has not been implemented (we may have already implemented
|
||||
it, but haven't released the code yet).
|
||||
2) That the feature is acceptable.
|
||||
3) Whether we need help of third-party developers with implementing the feature.
|
||||
|
||||
Information on how to contact us can be found at:
|
||||
https://veracrypt.codeplex.com/
|
||||
|
||||
|
||||
|
||||
V. Legal Information
|
||||
====================
|
||||
|
||||
Copyright Information
|
||||
---------------------
|
||||
|
||||
This software as a whole:
|
||||
Copyright (c) 2013-2015 IDRIX. All rights reserved.
|
||||
|
||||
Portions of this software:
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association. All rights reserved.
|
||||
Copyright (c) 1998-2000 Paul Le Roux. All rights reserved.
|
||||
Copyright (c) 1998-2008 Brian Gladman, Worcester, UK. All rights reserved.
|
||||
Copyright (c) 2002-2004 Mark Adler. All rights reserved.
|
||||
For more information, please see the legal notices attached to parts of the
|
||||
source code.
|
||||
|
||||
Trademark Information
|
||||
---------------------
|
||||
|
||||
Any trademarks contained in the source code, binaries, and/or in the
|
||||
documentation, are the sole property of their respective owners.
|
||||
|
||||
|
||||
|
||||
VI. Further Information
|
||||
=======================
|
||||
|
||||
http://www.veracrypt.fr
|
||||
This archive contains the source code of VeraCrypt.
|
||||
It is based on original TrueCrypt 7.1a with security enhancements and modifications.
|
||||
|
||||
|
||||
Important
|
||||
=========
|
||||
|
||||
You may use the source code contained in this archive only if you accept and
|
||||
agree to the license terms contained in the file 'License.txt', which is
|
||||
included in this archive.
|
||||
|
||||
Note that the license specifies, for example, that a derived work must not be
|
||||
called 'TrueCrypt' or 'VeraCrypt'
|
||||
|
||||
|
||||
|
||||
Contents
|
||||
========
|
||||
|
||||
I. Windows
|
||||
Requirements for Building VeraCrypt for Windows
|
||||
Instructions for Building VeraCrypt for Windows
|
||||
Instructions for Signing and Packaging VeraCrypt for Windows
|
||||
|
||||
II. Linux and Mac OS X
|
||||
Requirements for Building VeraCrypt for Linux and Mac OS X
|
||||
Instructions for Building VeraCrypt for Linux and Mac OS X
|
||||
Mac OS X specifics
|
||||
|
||||
III. FreeBSD and OpenSolaris
|
||||
|
||||
IV. Third-Party Developers (Contributors)
|
||||
|
||||
V. Legal Information
|
||||
|
||||
VI. Further Information
|
||||
|
||||
|
||||
|
||||
I. Windows
|
||||
==========
|
||||
|
||||
Requirements for Building VeraCrypt for Windows:
|
||||
------------------------------------------------
|
||||
|
||||
- Microsoft Visual C++ 2008 SP1 (Professional Edition or compatible)
|
||||
- Microsoft Visual C++ 1.52 (available from MSDN Subscriber Downloads)
|
||||
- Microsoft Windows SDK for Windows 7 (configured for Visual C++)
|
||||
- Microsoft Windows SDK for Windows 8.1 (needed for SHA-256 code signing)
|
||||
- Microsoft Windows Driver Kit 7.1.0 (build 7600.16385.1)
|
||||
- RSA Security Inc. PKCS #11 Cryptographic Token Interface (Cryptoki) 2.20
|
||||
header files (available at ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-11/v2-20)
|
||||
- NASM assembler 2.08 or compatible
|
||||
- gzip compressor
|
||||
- upx packer (available at http://upx.sourceforge.net/)
|
||||
|
||||
IMPORTANT:
|
||||
|
||||
The 64-bit editions of Windows Vista and later versions of Windows, and in
|
||||
some cases (e.g. playback of HD DVD content) also the 32-bit editions, do not
|
||||
allow the VeraCrypt driver to run without an appropriate digital signature.
|
||||
Therefore, all .sys files in official VeraCrypt binary packages are digitally
|
||||
signed with the digital certificate of the IDRIX, which was
|
||||
issued by Thawte certification authority. At the end of each official .exe and
|
||||
.sys file, there are embedded digital signatures and all related certificates
|
||||
(i.e. all certificates in the relevant certification chain, such as the
|
||||
certification authority certificates, CA-MS cross-certificate, and the
|
||||
IDRIX certificate).
|
||||
Keep this in mind if you compile VeraCrypt
|
||||
and compare your binaries with the official binaries. If your binaries are
|
||||
unsigned, the sizes of the official binaries will usually be approximately
|
||||
10 KB greater than sizes of your binaries (there may be further differences
|
||||
if you use a different version of the compiler, or if you install a different
|
||||
or no service pack for Visual Studio, or different hotfixes for it, or if you
|
||||
use different versions of the required SDKs).
|
||||
|
||||
|
||||
Instructions for Building VeraCrypt for Windows:
|
||||
------------------------------------------------
|
||||
|
||||
1) Create an environment variable 'MSVC16_ROOT' pointing to the folder 'MSVC15'
|
||||
extracted from the Visual C++ 1.52 self-extracting package.
|
||||
|
||||
Note: The 16-bit installer MSVC15\SETUP.EXE cannot be run on 64-bit Windows,
|
||||
but it is actually not necessary to run it. You only need to extract the
|
||||
folder 'MSVC15', which contains the 32-bit binaries required to build the
|
||||
VeraCrypt Boot Loader.
|
||||
|
||||
2) If you have installed the Windows Driver Development Kit in another
|
||||
directory than '%SYSTEMDRIVE%\WinDDK', create an environment variable
|
||||
'WINDDK_ROOT' pointing to the DDK installation directory.
|
||||
|
||||
3) Copy the PKCS #11 header files to a standard include path or create an
|
||||
environment variable 'PKCS11_INC' pointing to the directory where
|
||||
the PKCS #11 header files are installed.
|
||||
|
||||
4) Open the solution file 'VeraCrypt.sln' in Microsoft Visual Studio 2008.
|
||||
|
||||
5) Select 'All' as the active solution configuration.
|
||||
|
||||
6) Build the solution.
|
||||
|
||||
7) If successful, there should be newly built VeraCrypt binaries in the
|
||||
'Release' folder.
|
||||
|
||||
Instructions for Signing and Packaging VeraCrypt for Windows:
|
||||
-------------------------------------------------------------
|
||||
|
||||
First, create an environment variable 'WSDK81' pointing to the Windows SDK
|
||||
for Windows 8.1 installation directory.
|
||||
The folder "Signing" contains a batch file (sign.bat) that will sign all
|
||||
VeraCrypt components using a code signing certificate present on the
|
||||
certificate store and also build the final installation setup.
|
||||
The batch file suppose that the code signing certificate is issued by Thawt.
|
||||
This is the case for IDRIX's certificate. If yours is issued by another CA,
|
||||
then you should put the Root and Intermediate certificates in the "Signing"
|
||||
folder and then modify sign.bat accordingly.
|
||||
|
||||
|
||||
II. Linux and Mac OS X
|
||||
======================
|
||||
|
||||
Requirements for Building VeraCrypt for Linux and Mac OS X:
|
||||
-----------------------------------------------------------
|
||||
|
||||
- GNU Make
|
||||
- GNU C++ Compiler 4.0 or compatible
|
||||
- Apple Xcode (Mac OS X only)
|
||||
- NASM assembler 2.08 or compatible (x86/x64 architecture only)
|
||||
- pkg-config
|
||||
- makeself (Linux only)
|
||||
- wxWidgets 3.0 shared library and header files installed or
|
||||
wxWidgets 3.0 library source code (available at http://www.wxwidgets.org)
|
||||
- FUSE library and header files (available at https://github.com/libfuse/libfuse
|
||||
and https://osxfuse.github.io/)
|
||||
- RSA Security Inc. PKCS #11 Cryptographic Token Interface (Cryptoki) 2.20
|
||||
header files (available at ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-11/v2-20).
|
||||
They are already included in the source tree under the directory PKCS11 but
|
||||
it is possible to override it using the environment variable 'PKCS11_INC'.
|
||||
|
||||
|
||||
Instructions for Building VeraCrypt for Linux and Mac OS X:
|
||||
-----------------------------------------------------------
|
||||
|
||||
1) Change the current directory to the root of the VeraCrypt source code.
|
||||
|
||||
2) If you have no wxWidgets shared library installed, run the following
|
||||
command to configure the wxWidgets static library for VeraCrypt and to
|
||||
build it:
|
||||
|
||||
$ make WXSTATIC=1 WX_ROOT=/usr/src/wxWidgets wxbuild
|
||||
|
||||
The variable WX_ROOT must point to the location of the source code of the
|
||||
wxWidgets library. Output files will be placed in the './wxrelease/'
|
||||
directory.
|
||||
|
||||
3) To build VeraCrypt, run the following command:
|
||||
|
||||
$ make
|
||||
|
||||
or if you have no wxWidgets shared library installed:
|
||||
|
||||
$ make WXSTATIC=1
|
||||
|
||||
4) If successful, the VeraCrypt executable should be located in the directory
|
||||
'Main'.
|
||||
|
||||
By default, a universal executable supporting both graphical and text user
|
||||
interface (through the switch --text) is built.
|
||||
On Linux, a console-only executable, which requires no GUI library, can be
|
||||
built using the 'NOGUI' parameter:
|
||||
|
||||
$ make NOGUI=1 WXSTATIC=1 WX_ROOT=/usr/src/wxWidgets wxbuild
|
||||
$ make NOGUI=1 WXSTATIC=1
|
||||
|
||||
On MacOSX, building a console-only executable is not supported.
|
||||
|
||||
Mac OS X specifics:
|
||||
-----------------------------------------------------------
|
||||
|
||||
Under MacOSX, the SDK for OSX 10.7 is used by default. To use another version
|
||||
of the SDK (i.e. 10.6), you can export the environment variable VC_OSX_TARGET:
|
||||
|
||||
$ export VC_OSX_TARGET=10.6
|
||||
|
||||
|
||||
Before building under MacOSX, pkg-config must be installed if not yet available.
|
||||
Get it from http://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz and
|
||||
compile using the following commands :
|
||||
|
||||
$ ./configure --with-internal-glib
|
||||
$ make
|
||||
$ sudo make install
|
||||
|
||||
After making sure pkg-config is available, download and install OSXFuse from
|
||||
https://osxfuse.github.io/ (MacFUSE compatibility layer must selected)
|
||||
|
||||
The script build_veracrypt_macosx.sh available under "src/Build" performs the
|
||||
full build of VeraCrypt including the creation of the installer pkg. It expects
|
||||
to find the wxWidgets 3.0.2 sources at the same level as where you put
|
||||
VeraCrypt sources (i.e. if "src" path is "/Users/joe/Projects/VeraCrypt/src"
|
||||
then wxWidgets should be at "/Users/joe/Projects/wxWidgets-wxWidgets-3.0.2")
|
||||
|
||||
The build process uses Code Signing certificates whose ID is specified in
|
||||
src/Main/Main.make (lines 167 & 169). You'll have to modify these lines to put
|
||||
the ID of your Code Signing certificates or comment them if you don't have one.
|
||||
|
||||
Because of incompatibility issues with OSXFUSE, the SDK 10.9 generates a
|
||||
VeraCrypt binary that has issues communicating with the OSXFUSE kernel extension.
|
||||
Thus, we recommend to use the SDK 10.8 or earlier for building VeraCrypt.
|
||||
|
||||
|
||||
|
||||
III. FreeBSD and OpenSolaris
|
||||
============================
|
||||
|
||||
FreeBSD and OpenSolaris are not yet supported.
|
||||
|
||||
|
||||
|
||||
IV. Third-Party Developers (Contributors)
|
||||
=========================================
|
||||
|
||||
If you intend to implement a feature, please contact us first to make sure:
|
||||
|
||||
1) That the feature has not been implemented (we may have already implemented
|
||||
it, but haven't released the code yet).
|
||||
2) That the feature is acceptable.
|
||||
3) Whether we need help of third-party developers with implementing the feature.
|
||||
|
||||
Information on how to contact us can be found at:
|
||||
https://veracrypt.codeplex.com/
|
||||
|
||||
|
||||
|
||||
V. Legal Information
|
||||
====================
|
||||
|
||||
Copyright Information
|
||||
---------------------
|
||||
|
||||
This software as a whole:
|
||||
Copyright (c) 2013-2015 IDRIX. All rights reserved.
|
||||
|
||||
Portions of this software:
|
||||
Copyright (c) 2003-2012 TrueCrypt Developers Association. All rights reserved.
|
||||
Copyright (c) 1998-2000 Paul Le Roux. All rights reserved.
|
||||
Copyright (c) 1998-2008 Brian Gladman, Worcester, UK. All rights reserved.
|
||||
Copyright (c) 2002-2004 Mark Adler. All rights reserved.
|
||||
For more information, please see the legal notices attached to parts of the
|
||||
source code.
|
||||
|
||||
Trademark Information
|
||||
---------------------
|
||||
|
||||
Any trademarks contained in the source code, binaries, and/or in the
|
||||
documentation, are the sole property of their respective owners.
|
||||
|
||||
|
||||
|
||||
VI. Further Information
|
||||
=======================
|
||||
|
||||
http://www.veracrypt.fr
|
||||
|
642
Tests/bench.bat
642
Tests/bench.bat
@ -1,321 +1,321 @@
|
||||
@echo off
|
||||
|
||||
setlocal
|
||||
|
||||
call :freedrive mydriveletter && goto :cont
|
||||
echo ERROR: No free drive letter found.
|
||||
goto :exit
|
||||
:cont
|
||||
|
||||
echo Using drive letter %mydriveletter%: for our tests
|
||||
echo.
|
||||
|
||||
IF NOT EXIST test.sha512.hc GOTO :whirlpool
|
||||
|
||||
rem Get start time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Mount SHA-512 container (Normal)
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume test.sha512.hc /hash sha512 /l %mydriveletter% /password test /q /silent /m ro
|
||||
|
||||
rem Get end time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Get elapsed time:
|
||||
set /A elapsed=end-start
|
||||
|
||||
rem Show elapsed time:
|
||||
set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100
|
||||
if %hh% lss 10 set hh=0%hh%
|
||||
if %mm% lss 10 set mm=0%mm%
|
||||
if %ss% lss 10 set ss=0%ss%
|
||||
if %cc% lss 10 set cc=0%cc%
|
||||
echo SHA-512 (Normal) = %hh%:%mm%:%ss%,%cc%
|
||||
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /dismount %mydriveletter% /silent /q
|
||||
|
||||
rem Get start time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Mount SHA-512 container (Hidden)
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume test.sha512.hc /hash sha512 /l %mydriveletter% /password testhidden /q /silent /m ro
|
||||
|
||||
rem Get end time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Get elapsed time:
|
||||
set /A elapsed=end-start
|
||||
|
||||
rem Show elapsed time:
|
||||
set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100
|
||||
if %hh% lss 10 set hh=0%hh%
|
||||
if %mm% lss 10 set mm=0%mm%
|
||||
if %ss% lss 10 set ss=0%ss%
|
||||
if %cc% lss 10 set cc=0%cc%
|
||||
echo SHA-512 (Hidden) = %hh%:%mm%:%ss%,%cc%
|
||||
echo.
|
||||
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /dismount %mydriveletter% /silent /q
|
||||
|
||||
:whirlpool
|
||||
|
||||
IF NOT EXIST test.whirlpool.hc GOTO :sha256
|
||||
|
||||
rem Get start time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Mount Whirlpool container (Normal).
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume test.whirlpool.hc /hash whirlpool /l %mydriveletter% /password test /q /silent /m ro
|
||||
|
||||
rem Get end time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Get elapsed time:
|
||||
set /A elapsed=end-start
|
||||
|
||||
rem Show elapsed time:
|
||||
set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100
|
||||
if %hh% lss 10 set hh=0%hh%
|
||||
if %mm% lss 10 set mm=0%mm%
|
||||
if %ss% lss 10 set ss=0%ss%
|
||||
if %cc% lss 10 set cc=0%cc%
|
||||
echo Whirlpool (Normal) = %hh%:%mm%:%ss%,%cc%
|
||||
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /dismount %mydriveletter% /silent /q
|
||||
|
||||
rem Get start time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Mount Whirlpool container (Hidden).
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume test.whirlpool.hc /hash whirlpool /l %mydriveletter% /password testhidden /q /silent /m ro
|
||||
|
||||
rem Get end time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Get elapsed time:
|
||||
set /A elapsed=end-start
|
||||
|
||||
rem Show elapsed time:
|
||||
set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100
|
||||
if %hh% lss 10 set hh=0%hh%
|
||||
if %mm% lss 10 set mm=0%mm%
|
||||
if %ss% lss 10 set ss=0%ss%
|
||||
if %cc% lss 10 set cc=0%cc%
|
||||
echo Whirlpool (Hidden) = %hh%:%mm%:%ss%,%cc%
|
||||
echo.
|
||||
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /dismount %mydriveletter% /silent /q
|
||||
|
||||
:sha256
|
||||
|
||||
IF NOT EXIST test.sha256.hc GOTO :ripemd160
|
||||
|
||||
rem Get start time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Mount SHA-256 container (Normal)
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume test.sha256.hc /hash sha256 /l %mydriveletter% /password test /q /silent /m ro
|
||||
|
||||
rem Get end time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Get elapsed time:
|
||||
set /A elapsed=end-start
|
||||
|
||||
rem Show elapsed time:
|
||||
set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100
|
||||
if %hh% lss 10 set hh=0%hh%
|
||||
if %mm% lss 10 set mm=0%mm%
|
||||
if %ss% lss 10 set ss=0%ss%
|
||||
if %cc% lss 10 set cc=0%cc%
|
||||
echo SHA-256 (Normal) = %hh%:%mm%:%ss%,%cc%
|
||||
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /dismount %mydriveletter% /silent /q
|
||||
|
||||
rem Get start time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Mount SHA-256 container (Hidden)
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume test.sha256.hc /hash sha256 /l %mydriveletter% /password testhidden /q /silent /m ro
|
||||
|
||||
rem Get end time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Get elapsed time:
|
||||
set /A elapsed=end-start
|
||||
|
||||
rem Show elapsed time:
|
||||
set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100
|
||||
if %hh% lss 10 set hh=0%hh%
|
||||
if %mm% lss 10 set mm=0%mm%
|
||||
if %ss% lss 10 set ss=0%ss%
|
||||
if %cc% lss 10 set cc=0%cc%
|
||||
echo SHA-256 (Hidden) = %hh%:%mm%:%ss%,%cc%
|
||||
echo.
|
||||
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /dismount %mydriveletter% /silent /q
|
||||
|
||||
:ripemd160
|
||||
|
||||
IF NOT EXIST test.ripemd160.hc GOTO :autodetect
|
||||
|
||||
rem Get start time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Mount RIPEMD-160 container (Normal)
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume test.ripemd160.hc /hash ripemd160 /l %mydriveletter% /password test /q /silent /m ro
|
||||
|
||||
rem Get end time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Get elapsed time:
|
||||
set /A elapsed=end-start
|
||||
|
||||
rem Show elapsed time:
|
||||
set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100
|
||||
if %hh% lss 10 set hh=0%hh%
|
||||
if %mm% lss 10 set mm=0%mm%
|
||||
if %ss% lss 10 set ss=0%ss%
|
||||
if %cc% lss 10 set cc=0%cc%
|
||||
echo RIPEMD-160 (Normal) = %hh%:%mm%:%ss%,%cc%
|
||||
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /dismount %mydriveletter% /silent /q
|
||||
|
||||
rem Get start time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Mount RIPEMD-160 container (Hidden)
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume test.ripemd160.hc /hash ripemd160 /l %mydriveletter% /password testhidden /q /silent /m ro
|
||||
|
||||
rem Get end time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Get elapsed time:
|
||||
set /A elapsed=end-start
|
||||
|
||||
rem Show elapsed time:
|
||||
set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100
|
||||
if %hh% lss 10 set hh=0%hh%
|
||||
if %mm% lss 10 set mm=0%mm%
|
||||
if %ss% lss 10 set ss=0%ss%
|
||||
if %cc% lss 10 set cc=0%cc%
|
||||
echo RIPEMD-160 (Hidden) = %hh%:%mm%:%ss%,%cc%
|
||||
echo.
|
||||
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /dismount %mydriveletter% /silent /q
|
||||
|
||||
:autodetect
|
||||
|
||||
call :availablevolume testvolume && goto :contautodetect
|
||||
goto :exit
|
||||
:contautodetect
|
||||
|
||||
rem Get start time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Try to mount with a wrong password and PRF autodetection
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume %testvolume% /l %mydriveletter% /password wrongpassword /q /silent /m ro
|
||||
|
||||
rem Get end time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Get elapsed time:
|
||||
set /A elapsed=end-start
|
||||
|
||||
rem Show elapsed time:
|
||||
set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100
|
||||
if %hh% lss 10 set hh=0%hh%
|
||||
if %mm% lss 10 set mm=0%mm%
|
||||
if %ss% lss 10 set ss=0%ss%
|
||||
if %cc% lss 10 set cc=0%cc%
|
||||
echo Wrong Password (PRF Auto-detection)= %hh%:%mm%:%ss%,%cc%
|
||||
echo.
|
||||
|
||||
|
||||
goto :exit
|
||||
|
||||
rem Finds a free drive letter.
|
||||
rem
|
||||
rem Parameters:
|
||||
rem %1 = Output variable name.
|
||||
rem
|
||||
rem Example:
|
||||
rem call :freedrive mydriveletter && goto :cont
|
||||
rem echo ERROR: No free drive letter found.
|
||||
rem goto :EOF
|
||||
rem :cont
|
||||
rem echo Found drive letter: %mydriveletter%
|
||||
:freedrive
|
||||
setlocal EnableDelayedExpansion
|
||||
set exitcode=0
|
||||
set "output_var=%~1"
|
||||
for %%i in (C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z) do (
|
||||
set "drive=%%i:"
|
||||
rem If 'subst' fails, the drive letter is already in use.
|
||||
rem This way we can even detect optical drives that have a drive
|
||||
rem letter but no media in them, a case that goes undetected when
|
||||
rem using 'if exist'.
|
||||
subst !drive! %SystemDrive%\ >nul
|
||||
if !errorlevel! == 0 (
|
||||
subst !drive! /d >nul
|
||||
set "drive=%%i"
|
||||
goto :freedrive0
|
||||
)
|
||||
)
|
||||
set exitcode=1
|
||||
set drive=
|
||||
:freedrive0
|
||||
endlocal & set "%output_var%=%drive%" & exit /b %exitcode%
|
||||
|
||||
:availablevolume
|
||||
setlocal EnableDelayedExpansion
|
||||
set exitcode=0
|
||||
set "output_var=%~1"
|
||||
for %%i in (test.sha512.hc,test.sha256.hc,test.whirlpool.hc,test.ripemd160.hc) do (
|
||||
if exist %%i (
|
||||
set "volume=%%i"
|
||||
goto :availablevolume0
|
||||
)
|
||||
)
|
||||
set exitcode=1
|
||||
set volume=
|
||||
:availablevolume0
|
||||
endlocal & set "%output_var%=%volume%" & exit /b %exitcode%
|
||||
|
||||
:exit
|
||||
@echo off
|
||||
|
||||
setlocal
|
||||
|
||||
call :freedrive mydriveletter && goto :cont
|
||||
echo ERROR: No free drive letter found.
|
||||
goto :exit
|
||||
:cont
|
||||
|
||||
echo Using drive letter %mydriveletter%: for our tests
|
||||
echo.
|
||||
|
||||
IF NOT EXIST test.sha512.hc GOTO :whirlpool
|
||||
|
||||
rem Get start time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Mount SHA-512 container (Normal)
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume test.sha512.hc /hash sha512 /l %mydriveletter% /password test /q /silent /m ro
|
||||
|
||||
rem Get end time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Get elapsed time:
|
||||
set /A elapsed=end-start
|
||||
|
||||
rem Show elapsed time:
|
||||
set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100
|
||||
if %hh% lss 10 set hh=0%hh%
|
||||
if %mm% lss 10 set mm=0%mm%
|
||||
if %ss% lss 10 set ss=0%ss%
|
||||
if %cc% lss 10 set cc=0%cc%
|
||||
echo SHA-512 (Normal) = %hh%:%mm%:%ss%,%cc%
|
||||
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /dismount %mydriveletter% /silent /q
|
||||
|
||||
rem Get start time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Mount SHA-512 container (Hidden)
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume test.sha512.hc /hash sha512 /l %mydriveletter% /password testhidden /q /silent /m ro
|
||||
|
||||
rem Get end time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Get elapsed time:
|
||||
set /A elapsed=end-start
|
||||
|
||||
rem Show elapsed time:
|
||||
set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100
|
||||
if %hh% lss 10 set hh=0%hh%
|
||||
if %mm% lss 10 set mm=0%mm%
|
||||
if %ss% lss 10 set ss=0%ss%
|
||||
if %cc% lss 10 set cc=0%cc%
|
||||
echo SHA-512 (Hidden) = %hh%:%mm%:%ss%,%cc%
|
||||
echo.
|
||||
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /dismount %mydriveletter% /silent /q
|
||||
|
||||
:whirlpool
|
||||
|
||||
IF NOT EXIST test.whirlpool.hc GOTO :sha256
|
||||
|
||||
rem Get start time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Mount Whirlpool container (Normal).
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume test.whirlpool.hc /hash whirlpool /l %mydriveletter% /password test /q /silent /m ro
|
||||
|
||||
rem Get end time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Get elapsed time:
|
||||
set /A elapsed=end-start
|
||||
|
||||
rem Show elapsed time:
|
||||
set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100
|
||||
if %hh% lss 10 set hh=0%hh%
|
||||
if %mm% lss 10 set mm=0%mm%
|
||||
if %ss% lss 10 set ss=0%ss%
|
||||
if %cc% lss 10 set cc=0%cc%
|
||||
echo Whirlpool (Normal) = %hh%:%mm%:%ss%,%cc%
|
||||
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /dismount %mydriveletter% /silent /q
|
||||
|
||||
rem Get start time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Mount Whirlpool container (Hidden).
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume test.whirlpool.hc /hash whirlpool /l %mydriveletter% /password testhidden /q /silent /m ro
|
||||
|
||||
rem Get end time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Get elapsed time:
|
||||
set /A elapsed=end-start
|
||||
|
||||
rem Show elapsed time:
|
||||
set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100
|
||||
if %hh% lss 10 set hh=0%hh%
|
||||
if %mm% lss 10 set mm=0%mm%
|
||||
if %ss% lss 10 set ss=0%ss%
|
||||
if %cc% lss 10 set cc=0%cc%
|
||||
echo Whirlpool (Hidden) = %hh%:%mm%:%ss%,%cc%
|
||||
echo.
|
||||
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /dismount %mydriveletter% /silent /q
|
||||
|
||||
:sha256
|
||||
|
||||
IF NOT EXIST test.sha256.hc GOTO :ripemd160
|
||||
|
||||
rem Get start time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Mount SHA-256 container (Normal)
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume test.sha256.hc /hash sha256 /l %mydriveletter% /password test /q /silent /m ro
|
||||
|
||||
rem Get end time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Get elapsed time:
|
||||
set /A elapsed=end-start
|
||||
|
||||
rem Show elapsed time:
|
||||
set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100
|
||||
if %hh% lss 10 set hh=0%hh%
|
||||
if %mm% lss 10 set mm=0%mm%
|
||||
if %ss% lss 10 set ss=0%ss%
|
||||
if %cc% lss 10 set cc=0%cc%
|
||||
echo SHA-256 (Normal) = %hh%:%mm%:%ss%,%cc%
|
||||
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /dismount %mydriveletter% /silent /q
|
||||
|
||||
rem Get start time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Mount SHA-256 container (Hidden)
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume test.sha256.hc /hash sha256 /l %mydriveletter% /password testhidden /q /silent /m ro
|
||||
|
||||
rem Get end time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Get elapsed time:
|
||||
set /A elapsed=end-start
|
||||
|
||||
rem Show elapsed time:
|
||||
set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100
|
||||
if %hh% lss 10 set hh=0%hh%
|
||||
if %mm% lss 10 set mm=0%mm%
|
||||
if %ss% lss 10 set ss=0%ss%
|
||||
if %cc% lss 10 set cc=0%cc%
|
||||
echo SHA-256 (Hidden) = %hh%:%mm%:%ss%,%cc%
|
||||
echo.
|
||||
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /dismount %mydriveletter% /silent /q
|
||||
|
||||
:ripemd160
|
||||
|
||||
IF NOT EXIST test.ripemd160.hc GOTO :autodetect
|
||||
|
||||
rem Get start time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Mount RIPEMD-160 container (Normal)
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume test.ripemd160.hc /hash ripemd160 /l %mydriveletter% /password test /q /silent /m ro
|
||||
|
||||
rem Get end time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Get elapsed time:
|
||||
set /A elapsed=end-start
|
||||
|
||||
rem Show elapsed time:
|
||||
set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100
|
||||
if %hh% lss 10 set hh=0%hh%
|
||||
if %mm% lss 10 set mm=0%mm%
|
||||
if %ss% lss 10 set ss=0%ss%
|
||||
if %cc% lss 10 set cc=0%cc%
|
||||
echo RIPEMD-160 (Normal) = %hh%:%mm%:%ss%,%cc%
|
||||
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /dismount %mydriveletter% /silent /q
|
||||
|
||||
rem Get start time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Mount RIPEMD-160 container (Hidden)
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume test.ripemd160.hc /hash ripemd160 /l %mydriveletter% /password testhidden /q /silent /m ro
|
||||
|
||||
rem Get end time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Get elapsed time:
|
||||
set /A elapsed=end-start
|
||||
|
||||
rem Show elapsed time:
|
||||
set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100
|
||||
if %hh% lss 10 set hh=0%hh%
|
||||
if %mm% lss 10 set mm=0%mm%
|
||||
if %ss% lss 10 set ss=0%ss%
|
||||
if %cc% lss 10 set cc=0%cc%
|
||||
echo RIPEMD-160 (Hidden) = %hh%:%mm%:%ss%,%cc%
|
||||
echo.
|
||||
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /dismount %mydriveletter% /silent /q
|
||||
|
||||
:autodetect
|
||||
|
||||
call :availablevolume testvolume && goto :contautodetect
|
||||
goto :exit
|
||||
:contautodetect
|
||||
|
||||
rem Get start time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Try to mount with a wrong password and PRF autodetection
|
||||
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume %testvolume% /l %mydriveletter% /password wrongpassword /q /silent /m ro
|
||||
|
||||
rem Get end time:
|
||||
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
|
||||
set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
|
||||
)
|
||||
|
||||
rem Get elapsed time:
|
||||
set /A elapsed=end-start
|
||||
|
||||
rem Show elapsed time:
|
||||
set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100
|
||||
if %hh% lss 10 set hh=0%hh%
|
||||
if %mm% lss 10 set mm=0%mm%
|
||||
if %ss% lss 10 set ss=0%ss%
|
||||
if %cc% lss 10 set cc=0%cc%
|
||||
echo Wrong Password (PRF Auto-detection)= %hh%:%mm%:%ss%,%cc%
|
||||
echo.
|
||||
|
||||
|
||||
goto :exit
|
||||
|
||||
rem Finds a free drive letter.
|
||||
rem
|
||||
rem Parameters:
|
||||
rem %1 = Output variable name.
|
||||
rem
|
||||
rem Example:
|
||||
rem call :freedrive mydriveletter && goto :cont
|
||||
rem echo ERROR: No free drive letter found.
|
||||
rem goto :EOF
|
||||
rem :cont
|
||||
rem echo Found drive letter: %mydriveletter%
|
||||
:freedrive
|
||||
setlocal EnableDelayedExpansion
|
||||
set exitcode=0
|
||||
set "output_var=%~1"
|
||||
for %%i in (C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z) do (
|
||||
set "drive=%%i:"
|
||||
rem If 'subst' fails, the drive letter is already in use.
|
||||
rem This way we can even detect optical drives that have a drive
|
||||
rem letter but no media in them, a case that goes undetected when
|
||||
rem using 'if exist'.
|
||||
subst !drive! %SystemDrive%\ >nul
|
||||
if !errorlevel! == 0 (
|
||||
subst !drive! /d >nul
|
||||
set "drive=%%i"
|
||||
goto :freedrive0
|
||||
)
|
||||
)
|
||||
set exitcode=1
|
||||
set drive=
|
||||
:freedrive0
|
||||
endlocal & set "%output_var%=%drive%" & exit /b %exitcode%
|
||||
|
||||
:availablevolume
|
||||
setlocal EnableDelayedExpansion
|
||||
set exitcode=0
|
||||
set "output_var=%~1"
|
||||
for %%i in (test.sha512.hc,test.sha256.hc,test.whirlpool.hc,test.ripemd160.hc) do (
|
||||
if exist %%i (
|
||||
set "volume=%%i"
|
||||
goto :availablevolume0
|
||||
)
|
||||
)
|
||||
set exitcode=1
|
||||
set volume=
|
||||
:availablevolume0
|
||||
endlocal & set "%output_var%=%volume%" & exit /b %exitcode%
|
||||
|
||||
:exit
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -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
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user