VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Format/InPlace.h
blob: 82bae5b42481a9474f464c960424ab1e19eac0da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 Copyright (c) 2008-2010 TrueCrypt Developers Association. All rights reserved.

 Governed by the TrueCrypt License 3.0 the full text of which is contained in
 the file License.txt included in TrueCrypt binary and source code distribution
 packages.
*/

#ifdef __cplusplus
extern "C" {
#endif

#include "Format.h"

enum nonsys_inplace_enc_status
{
	NONSYS_INPLACE_ENC_STATUS_NONE = 0,
	NONSYS_INPLACE_ENC_STATUS_PREPARING,
	NONSYS_INPLACE_ENC_STATUS_RESIZING,
	NONSYS_INPLACE_ENC_STATUS_ENCRYPTING,
	NONSYS_INPLACE_ENC_STATUS_FINALIZING,
	NONSYS_INPLACE_ENC_STATUS_PAUSED,
	NONSYS_INPLACE_ENC_STATUS_FINISHED,
	NONSYS_INPLACE_ENC_STATUS_ERROR
};

BOOL CheckRequirementsForNonSysInPlaceEnc (const char *devicePath, BOOL silent);
int EncryptPartitionInPlaceBegin (volatile FORMAT_VOL_PARAMETERS *volParams, volatile HANDLE *outHandle, WipeAlgorithmId wipeAlgorithm);
int EncryptPartitionInPlaceResume (HANDLE dev, volatile FORMAT_VOL_PARAMETERS *volParams, WipeAlgorithmId wipeAlgorithm, volatile BOOL *bTryToCorrectReadErrors);
void ShowInPlaceEncErrMsgWAltSteps (char *iniStrId, BOOL bErr);
void SetNonSysInplaceEncUIStatus (int nonSysInplaceEncStatus);
int FastVolumeHeaderUpdate (HANDLE dev, CRYPTO_INFO *headerCryptoInfo, CRYPTO_INFO *masterCryptoInfo, __int64 deviceSize);

static HANDLE OpenPartitionVolume (const char *devName, BOOL bExclusiveRequired, BOOL bSharedRequired, BOOL bSharedRequiresConfirmation, BOOL bShowAlternativeSteps, BOOL bSilent);
static int DismountFileSystem (HANDLE dev, int driveLetter, BOOL bForcedAllowed, BOOL bForcedRequiresConfirmation, BOOL bSilent);
static int ConcealNTFS (HANDLE dev);
BOOL SaveNonSysInPlaceEncSettings (int delta, WipeAlgorithmId wipeAlgorithm);
static void ExportProgressStats (__int64 bytesDone, __int64 totalSize);
int ZeroUnreadableSectors (HANDLE dev, LARGE_INTEGER startOffset, int64 size, int sectorSize, uint64 *zeroedSectorCount);
static int OpenBackupHeader (HANDLE dev, const char *devicePath, Password *password, PCRYPTO_INFO *retCryptoInfo, CRYPTO_INFO *headerCryptoInfo, __int64 deviceSize);
BOOL MoveClustersBeforeThreshold (HANDLE volumeHandle, PWSTR volumeDevicePath, int64 clusterThreshold);

#ifdef __cplusplus
}
#endif
span class="p">:freedrive mydriveletter && goto :cont echo ERROR: No free drive letter found. goto :exit :cont echo Using drive letter %mydriveletter%: for our tests echo. 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 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 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 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 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 test.sha512.hc /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% :exit