Tests: refactor test batch script, clear and better code.

This commit is contained in:
Mounir IDRASSI 2024-07-26 11:31:28 +02:00
parent 3d76bb8f67
commit 1e92048017
No known key found for this signature in database
GPG Key ID: FC1B00364B3FE937

View File

@ -1,391 +1,90 @@
@echo off @echo off
setlocal EnableDelayedExpansion
:: Define constants
set "VERACRYPT_PATH=c:\Program Files\VeraCrypt\veracrypt.exe"
set "PASSWORD=test"
set "HIDDEN_PASSWORD=testhidden"
:: Find a free drive letter
call :freedrive mydriveletter || (
echo ERROR: No free drive letter found.
goto :exit
)
echo Using drive letter !mydriveletter!: for our tests
echo.
:: Define an array of hash algorithms and their corresponding container files
set "algorithms[0]=sha512,test.sha512.hc"
set "algorithms[1]=whirlpool,test.whirlpool.hc"
set "algorithms[2]=sha256,test.sha256.hc"
set "algorithms[3]=blake2s,test.blake2s.hc"
set "algorithms[4]=streebog,test.streebog.hc"
:: Loop through each algorithm
for /L %%i in (0,1,4) do (
for /F "tokens=1,2 delims=," %%a in ("!algorithms[%%i]!") do (
set "hash=%%a"
set "container=%%b"
if exist "!container!" (
call :mount_and_measure "!hash!" "!container!" "Normal" "!PASSWORD!"
call :mount_and_measure "!hash!" "!container!" "Hidden" "!HIDDEN_PASSWORD!"
echo.
)
)
)
:: Autodetect test
call :availablevolume testvolume || goto :exit
call :measure_time "Wrong Password (PRF Auto-detection)" ^
"/volume !testvolume! /l !mydriveletter! /password wrongpassword /q /silent /m ro"
echo.
goto :exit
:: Subroutine to mount a volume and measure the time taken
:mount_and_measure
setlocal setlocal
set "hash=%~1"
set "container=%~2"
set "type=%~3"
set "volumepassword=%~4"
call :freedrive mydriveletter && goto :cont call :measure_time "%hash% (%type%)" ^
echo ERROR: No free drive letter found. "/volume !container! /hash !hash! /l !mydriveletter! /password !volumepassword! /q /silent /m ro"
goto :exit
:cont
echo Using drive letter %mydriveletter%: for our tests if not exist !mydriveletter!:\ (
echo. echo ERROR: Drive letter !mydriveletter!: does not exist after mount operation.
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%
rem Check if the drive letter exists after mount operation
if not exist %mydriveletter%:\ (
echo ERROR: Drive letter %mydriveletter%: does not exist after mount operation.
goto :exit goto :exit
) )
"c:\Program Files\VeraCrypt\veracrypt.exe" /dismount %mydriveletter% /silent /q "!VERACRYPT_PATH!" /dismount !mydriveletter! /silent /q
exit /b
rem Get start time: :: Subroutine to measure the time taken for a command to execute
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do ( :measure_time
set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100" setlocal
) set "oper=%~1"
set "command=%~2"
rem Mount SHA-512 container (Hidden) 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"
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume test.sha512.hc /hash sha512 /l %mydriveletter% /password testhidden /q /silent /m ro
rem Get end time: "!VERACRYPT_PATH!" %command%
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" 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 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 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 %hh% lss 10 set hh=0%hh%
if %mm% lss 10 set mm=0%mm% if %mm% lss 10 set mm=0%mm%
if %ss% lss 10 set ss=0%ss% if %ss% lss 10 set ss=0%ss%
if %cc% lss 10 set cc=0%cc% if %cc% lss 10 set cc=0%cc%
echo SHA-512 (Hidden) = %hh%:%mm%:%ss%,%cc%
echo.
rem Check if the drive letter exists after mount operation echo %oper% = %hh%:%mm%:%ss%,%cc%
if not exist %mydriveletter%:\ ( exit /b
echo ERROR: Drive letter %mydriveletter%: does not exist after mount operation.
goto :exit
)
"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%
rem Check if the drive letter exists after mount operation
if not exist %mydriveletter%:\ (
echo ERROR: Drive letter %mydriveletter%: does not exist after mount operation.
goto :exit
)
"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.
rem Check if the drive letter exists after mount operation
if not exist %mydriveletter%:\ (
echo ERROR: Drive letter %mydriveletter%: does not exist after mount operation.
goto :exit
)
"c:\Program Files\VeraCrypt\veracrypt.exe" /dismount %mydriveletter% /silent /q
:sha256
IF NOT EXIST test.sha256.hc GOTO :blake2s
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%
rem Check if the drive letter exists after mount operation
if not exist %mydriveletter%:\ (
echo ERROR: Drive letter %mydriveletter%: does not exist after mount operation.
goto :exit
)
"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.
rem Check if the drive letter exists after mount operation
if not exist %mydriveletter%:\ (
echo ERROR: Drive letter %mydriveletter%: does not exist after mount operation.
goto :exit
)
"c:\Program Files\VeraCrypt\veracrypt.exe" /dismount %mydriveletter% /silent /q
:blake2s
IF NOT EXIST test.blake2s.hc GOTO :streebog
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 BLAKE2s container (Normal)
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume test.blake2s.hc /hash blake2s /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 BLAKE2s (Normal) = %hh%:%mm%:%ss%,%cc%
rem Check if the drive letter exists after mount operation
if not exist %mydriveletter%:\ (
echo ERROR: Drive letter %mydriveletter%: does not exist after mount operation.
goto :exit
)
"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 BLAKE2s container (Hidden)
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume test.blake2s.hc /hash blake2s /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 BLAKE2s (Hidden) = %hh%:%mm%:%ss%,%cc%
echo.
rem Check if the drive letter exists after mount operation
if not exist %mydriveletter%:\ (
echo ERROR: Drive letter %mydriveletter%: does not exist after mount operation.
goto :exit
)
"c:\Program Files\VeraCrypt\veracrypt.exe" /dismount %mydriveletter% /silent /q
:streebog
IF NOT EXIST test.streebog.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 Streebog container (Normal)
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume test.streebog.hc /hash streebog /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 Streebog (Normal) = %hh%:%mm%:%ss%,%cc%
rem Check if the drive letter exists after mount operation
if not exist %mydriveletter%:\ (
echo ERROR: Drive letter %mydriveletter%: does not exist after mount operation.
goto :exit
)
"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 Streebog container (Hidden)
"c:\Program Files\VeraCrypt\veracrypt.exe" /volume test.streebog.hc /hash streebog /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 Streebog (Hidden) = %hh%:%mm%:%ss%,%cc%
echo.
rem Check if the drive letter exists after mount operation
if not exist %mydriveletter%:\ (
echo ERROR: Drive letter %mydriveletter%: does not exist after mount operation.
goto :exit
)
"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 Finds a free drive letter.
rem rem
@ -420,6 +119,7 @@ set drive=
:freedrive0 :freedrive0
endlocal & set "%output_var%=%drive%" & exit /b %exitcode% endlocal & set "%output_var%=%drive%" & exit /b %exitcode%
:: Subroutine to find an available volume
:availablevolume :availablevolume
setlocal EnableDelayedExpansion setlocal EnableDelayedExpansion
set exitcode=0 set exitcode=0