1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2026-06-09 22:36:59 -05:00

Windows: Add an SDK for VeraCrypt Format that allows third-party application to create volumes

This commit is contained in:
Mounir IDRASSI
2025-06-13 21:12:14 +09:00
parent 1ed5225971
commit 2b531dd113
17 changed files with 1241 additions and 139 deletions
+291
View File
@@ -0,0 +1,291 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ARM64">
<Configuration>Debug</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM64">
<Configuration>Release</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\Common\BaseCom.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\Common\BootEncryption.cpp" />
<ClCompile Include="..\Common\Cmdline.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\Common\Combo.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\Common\CommandAPDU.cpp" />
<ClCompile Include="..\Common\Crc.c" />
<ClCompile Include="..\Common\Crypto.c" />
<ClCompile Include="..\Common\Dictionary.c">
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">CompileAsCpp</CompileAs>
</ClCompile>
<ClCompile Include="..\Common\Dlgcode.c">
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">CompileAsCpp</CompileAs>
</ClCompile>
<ClCompile Include="..\Common\EMVCard.cpp" />
<ClCompile Include="..\Common\EMVToken.cpp" />
<ClCompile Include="..\Common\EncryptionThreadPool.c" />
<ClCompile Include="..\Common\Endian.c" />
<ClCompile Include="..\Common\Fat.c" />
<ClCompile Include="..\Common\Format.c" />
<ClCompile Include="..\Common\GfMul.c" />
<ClCompile Include="..\Common\Keyfiles.c">
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">CompileAsCpp</CompileAs>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">false</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\Common\Language.c" />
<ClCompile Include="..\Common\Password.c" />
<ClCompile Include="..\Common\PCSCException.cpp" />
<ClCompile Include="..\Common\Pkcs5.c" />
<ClCompile Include="..\Common\Progress.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">false</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\Common\Random.c" />
<ClCompile Include="..\Common\Registry.c" />
<ClCompile Include="..\Common\ResponseAPDU.cpp" />
<ClCompile Include="..\Common\SCard.cpp" />
<ClCompile Include="..\Common\SCardLoader.cpp" />
<ClCompile Include="..\Common\SCardManager.cpp" />
<ClCompile Include="..\Common\SCardReader.cpp" />
<ClCompile Include="..\Common\SecurityToken.cpp" />
<ClCompile Include="..\Common\Tests.c" />
<ClCompile Include="..\Common\TLVParser.cpp" />
<ClCompile Include="..\Common\Token.cpp" />
<ClCompile Include="..\Common\Volumes.c" />
<ClCompile Include="..\Common\Wipe.c" />
<ClCompile Include="..\Common\Xml.c" />
<ClCompile Include="..\Common\Xts.c" />
<ClCompile Include="..\Format\Tcformat.c">
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">CompileAsCpp</CompileAs>
</ClCompile>
<ClCompile Include="VeraCryptFormatSDK.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="VeraCryptFormatSDK.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{ed4d0684-b0cf-4698-8487-3f3b314422e9}</ProjectGuid>
<RootNamespace>FormatDLL</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<SpectreMitigation>Spectre</SpectreMitigation>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<SpectreMitigation>Spectre</SpectreMitigation>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<TargetName>VeraCryptFormat</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
<TargetName>VeraCryptFormat</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<TargetName>VeraCryptFormat</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
<TargetName>VeraCryptFormat</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>VCSDK_DLL;_DEBUG;VCSDK_EXPORTS;_WINDOWS;_USRDLL;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NON_CONFORMING_SWPRINTFS%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>Default</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>
</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>..\Common;..\Crypto;..\;..\PKCS11;..\Common\zlib;..\Common\libzip;..\Common\lzma;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>..\Crypto\x64\Debug\crypto.lib;..\Common\x64\Debug\Zip.lib;mpr.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>md "..\Debug\SDK Files\x64" 2&gt;NUL:
copy $(TargetPath) "..\Debug\SDK Files\x64\VeraCryptFormat.dll"
copy $(TargetPath) "..\Debug\SDK Files\x64\VeraCryptFormat.lib"
copy VeraCryptFormatSDK.h "..\Debug\SDK Files\VeraCryptFormatSDK.h"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>VCSDK_DLL;_DEBUG;VCSDK_EXPORTS;_WINDOWS;_USRDLL;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NON_CONFORMING_SWPRINTFS%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>Default</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>
</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>..\Common;..\Crypto;..\;..\PKCS11;..\Common\zlib;..\Common\libzip;..\Common\lzma;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>..\Crypto\arm64\Debug\crypto.lib;..\Common\arm64\Debug\Zip.lib;mpr.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>md "..\Debug\SDK Files\arm64" 2&gt;NUL:
copy $(TargetPath) "..\Debug\SDK Files\arm64\VeraCryptFormat.dll"
copy $(TargetPath) "..\Debug\SDK Files\arm64\VeraCryptFormat.lib"
copy VeraCryptFormatSDK.h "..\Debug\SDK Files\VeraCryptFormatSDK.h"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>VCSDK_DLL;NDEBUG;VCSDK_EXPORTS;_WINDOWS;_USRDLL;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NON_CONFORMING_SWPRINTFS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>Default</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>
</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>..\Common;..\Crypto;..\;..\PKCS11;..\Common\zlib;..\Common\libzip;..\Common\lzma;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>..\Crypto\x64\Release\crypto.lib;..\Common\x64\Release\Zip.lib;mpr.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>md "..\Release\SDK Files\x64" 2&gt;NUL:
copy $(TargetPath) "..\Release\SDK Files\x64\VeraCryptFormat.dll"
copy $(TargetPath) "..\Release\SDK Files\x64\VeraCryptFormat.lib"
copy VeraCryptFormatSDK.h "..\Release\SDK Files\VeraCryptFormatSDK.h"
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>VCSDK_DLL;NDEBUG;VCSDK_EXPORTS;_WINDOWS;_USRDLL;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NON_CONFORMING_SWPRINTFS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>Default</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>
</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>..\Common;..\Crypto;..\;..\PKCS11;..\Common\zlib;..\Common\libzip;..\Common\lzma;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>..\Crypto\arm64\Release\crypto.lib;..\Common\arm64\Release\Zip.lib;mpr.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>md "..\Release\SDK Files\arm64" 2&gt;NUL:
copy $(TargetPath) "..\Release\SDK Files\arm64\VeraCryptFormat.dll"
copy $(TargetPath) "..\Release\SDK Files\arm64\VeraCryptFormat.lib"
copy VeraCryptFormatSDK.h "..\Release\SDK Files\VeraCryptFormatSDK.h"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
+144
View File
@@ -0,0 +1,144 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Source Files\Common">
<UniqueIdentifier>{30ee2663-9bf7-4e14-8331-09f652ef9ca0}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="VeraCryptFormatSDK.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Common\CommandAPDU.cpp">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\EMVCard.cpp">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\EMVToken.cpp">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\PCSCException.cpp">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\ResponseAPDU.cpp">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\SCard.cpp">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\SCardLoader.cpp">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\SCardManager.cpp">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\SCardReader.cpp">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\TLVParser.cpp">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Token.cpp">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\BaseCom.cpp">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\BootEncryption.cpp">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Cmdline.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Combo.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Crc.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Crypto.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Dictionary.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Dlgcode.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\EncryptionThreadPool.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Endian.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Fat.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Format.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\GfMul.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Keyfiles.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Language.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Password.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Pkcs5.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Progress.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Random.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Registry.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\SecurityToken.cpp">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Tests.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Volumes.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Wipe.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Xml.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Xts.c">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="..\Format\Tcformat.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="VeraCryptFormatSDK.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
+401
View File
@@ -0,0 +1,401 @@
/*
* VeraCrypt Format SDK
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file provides a C-style DLL interface for creating VeraCrypt file containers
* and formatting non-system partitions. It serves as a headless, thread-safe wrapper
* around the core logic from Tcformat.c and related VeraCrypt source files.
*
* First created by Mounir IDRASSI (mounir.idrassi@amcrypto.jp)
*
*/
#include "Tcdefs.h"
#include <string>
#include <vector>
#include <mutex>
#include <atomic>
#include <Strsafe.h>
#include "Dlgcode.h"
#include "Crypto.h"
#include "Apidrvr.h"
#include "Common/Common.h"
#include "Common/Dictionary.h"
#include "Common/Pkcs5.h"
#include "Platform/Finally.h"
#include "Random.h"
#include "Format.h"
#include "Volumes.h"
#include "Keyfiles.h"
#include "Password.h"
#include "Tests.h"
#include "Wipe.h"
#include "VeraCryptFormatSdk.h"
// Global variables from Tcformat.c we need to control
extern BOOL bDevice;
extern unsigned __int64 nVolumeSize;
extern int nVolumeEA;
extern int hash_algo;
extern int volumePim;
extern volatile int fileSystem;
extern volatile int clusterSize;
extern volatile BOOL quickFormat;
extern volatile BOOL fastCreateFile;
extern volatile BOOL dynamicFormat;
extern Password volumePassword;
extern KeyFile *FirstKeyFile;
extern wchar_t szDiskFile[TC_MAX_PATH+1];
extern HINSTANCE hInst;
extern BOOL bGuiMode;
// Core formatting function from Format.c
int TCFormatVolume (volatile FORMAT_VOL_PARAMETERS *volParams);
// Helper functions from other parts of VeraCrypt
void WipePasswordsAndKeyfiles (bool bFull);
int DriverAttach ();
BOOL AutoTestAlgorithms();
extern "C" DWORD GetFormatSectorSize();
void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine);
void cleanup ();
// Global mutex to ensure that volume creation operations are serialized,
// as the underlying code uses extensive global state.
static std::mutex g_sdkMutex;
static std::atomic<bool> g_isInitialized = false;
static HINSTANCE g_hDllInstance = NULL;
// Helper to map string representations to internal VeraCrypt EA IDs
static int MapEncryptionAlgorithm(const wchar_t* algoName)
{
if (!algoName) return 0;
wchar_t buf[100];
for (int ea = EAGetFirst(); ea != 0; ea = EAGetNext(ea))
{
if (EAIsFormatEnabled(ea) && _wcsicmp(algoName, EAGetName(buf, ARRAYSIZE(buf), ea, 1)) == 0)
{
return ea;
}
}
return 0; // Not found
}
// Helper to map string representations to internal VeraCrypt Hash IDs
static int MapHashAlgorithm(const wchar_t* hashName)
{
if (!hashName) return 0;
for (int id = FIRST_PRF_ID; id <= LAST_PRF_ID; ++id)
{
if (!HashIsDeprecated(id) && _wcsicmp(hashName, HashGetName(id)) == 0)
{
return id;
}
}
// Check for aliases
if (_wcsicmp(hashName, L"BLAKE2s") == 0) return BLAKE2S;
if (_wcsicmp(hashName, L"sha256") == 0) return SHA256;
if (_wcsicmp(hashName, L"sha512") == 0) return SHA512;
return 0; // Not found
}
// Helper to map string representations to internal VeraCrypt Filesystem IDs
static int MapFilesystem(const wchar_t* fsName)
{
if (!fsName || _wcsicmp(fsName, L"None") == 0) return FILESYS_NONE;
if (_wcsicmp(fsName, L"FAT") == 0) return FILESYS_FAT;
if (_wcsicmp(fsName, L"NTFS") == 0) return FILESYS_NTFS;
if (_wcsicmp(fsName, L"ExFAT") == 0) return FILESYS_EXFAT;
if (IsOSVersionAtLeast(WIN_10, 0) && _wcsicmp(fsName, L"ReFS") == 0) return FILESYS_REFS;
return -1; // Invalid filesystem
}
struct SdkProgressContext
{
VeraCrypt_Progress_Callback UserCallback;
uint64_t TotalSize;
void* UserData;
};
// This function is intended to be called by the internal TCFormatVolume function.
// It translates the progress into a percentage and calls the user-provided callback.
static BOOL __cdecl SdkProgressCallback(unsigned __int64 bytesProcessed, void* cbData)
{
if (!cbData) return FALSE;
SdkProgressContext* context = static_cast<SdkProgressContext*>(cbData);
if (context->UserCallback && context->TotalSize > 0)
{
int percentage = static_cast<int>((bytesProcessed * 100) / context->TotalSize);
if (percentage > 100) percentage = 100;
return context->UserCallback(percentage, context->UserData);
}
return TRUE;
}
// The core implementation of the volume creation logic. Not exported.
static int CreateVolumeInternal(const VeraCryptFormatOptions* options)
{
// --- Parameter validation ---
if (!options || !options->path || wcslen(options->path) == 0) return VCF_ERROR_INVALID_PARAMETER;
if (!options->password && (options->keyfiles == nullptr || options->keyfiles[0] == nullptr)) return VCF_ERROR_PASSWORD_OR_KEYFILE_REQUIRED;
if (!options->isDevice && (options->dynamicFormat || options->fastCreateFile) && options->quickFormat == FALSE) return VCF_ERROR_INVALID_PARAMETER;
if (options->isDevice && (options->dynamicFormat || options->fastCreateFile)) return VCF_ERROR_INVALID_PARAMETER;
// Lock the mutex to protect the global state used by VeraCrypt's format code
std::lock_guard<std::mutex> lock(g_sdkMutex);
// Use a finally block to ensure cleanup of globals and memory
finally_do({
// Clean up all sensitive data from globals
WipePasswordsAndKeyfiles(true);
// Reset globals to default state
KeyFileRemoveAll(&FirstKeyFile);
FirstKeyFile = nullptr;
bDevice = FALSE;
nVolumeSize = 0;
nVolumeEA = 1;
hash_algo = DEFAULT_HASH_ALGORITHM;
volumePim = 0;
fileSystem = FILESYS_NONE;
clusterSize = 0;
quickFormat = FALSE;
fastCreateFile = FALSE;
dynamicFormat = FALSE;
szDiskFile[0] = L'\0';
});
// --- Setup VeraCrypt's global state from our options struct ---
bDevice = options->isDevice;
nVolumeSize = options->size;
nVolumeEA = MapEncryptionAlgorithm(options->encryptionAlgorithm);
if (nVolumeEA == 0) return VCF_ERROR_INVALID_ENCRYPTION_ALGORITHM;
hash_algo = MapHashAlgorithm(options->hashAlgorithm);
if (hash_algo == 0) return VCF_ERROR_INVALID_HASH_ALGORITHM;
fileSystem = MapFilesystem(options->filesystem);
if (fileSystem == -1) return VCF_ERROR_INVALID_FILESYSTEM;
volumePim = options->pim;
quickFormat = options->quickFormat;
fastCreateFile = options->fastCreateFile;
dynamicFormat = options->dynamicFormat;
clusterSize = options->clusterSize;
if(dynamicFormat || fastCreateFile) quickFormat = TRUE;
if (options->password)
{
if (!CheckPasswordLength(NULL, (int)strlen(options->password), options->pim, FALSE, 0, TRUE, TRUE))
{
return VCF_ERROR_PASSWORD_POLICY;
}
strcpy_s((char*)volumePassword.Text, sizeof(volumePassword.Text), options->password);
volumePassword.Length = (unsigned __int32)strlen(options->password);
}
else
{
volumePassword.Text[0] = 0;
volumePassword.Length = 0;
}
// --- Handle Keyfiles ---
FirstKeyFile = nullptr;
if (options->keyfiles)
{
for (int i = 0; options->keyfiles[i] != nullptr; ++i)
{
KeyFile* kf = (KeyFile*)malloc(sizeof(KeyFile));
if (!kf)
{
KeyFileRemoveAll(&FirstKeyFile);
return VCF_ERROR_OUT_OF_MEMORY;
}
StringCbCopyW(kf->FileName, sizeof(kf->FileName), options->keyfiles[i]);
FirstKeyFile = KeyFileAdd(FirstKeyFile, kf);
}
}
if (!KeyFilesApply(NULL, &volumePassword, FirstKeyFile, NULL))
{
return VCF_ERROR_KEYFILE_ERROR;
}
// --- Prepare for TCFormatVolume ---
StringCbCopyW(szDiskFile, sizeof(szDiskFile), options->path);
// --- Perform Validation (ported from Tcformat.c) ---
if (bDevice)
{
nVolumeSize = GetDeviceSize(szDiskFile);
if (nVolumeSize == (uint64_t)-1) return VCF_ERROR_CANNOT_GET_DEVICE_SIZE;
}
else // For file containers
{
if (nVolumeSize % TC_SECTOR_SIZE_FILE_HOSTED_VOLUME != 0) return VCF_ERROR_INVALID_VOLUME_SIZE;
if (nVolumeSize < TC_MIN_VOLUME_SIZE) return VCF_ERROR_VOLUME_SIZE_TOO_SMALL;
if (!dynamicFormat)
{
wchar_t root[TC_MAX_PATH];
ULARGE_INTEGER freeSpace;
if (GetVolumePathName(szDiskFile, root, ARRAYSIZE(root)) && GetDiskFreeSpaceEx(root, &freeSpace, 0, 0))
{
if (nVolumeSize > freeSpace.QuadPart) return VCF_ERROR_CONTAINER_TOO_LARGE_FOR_HOST;
}
}
}
// Validate filesystem choice against volume size
uint64_t dataAreaSize = GetVolumeDataAreaSize(FALSE, nVolumeSize);
DWORD sectorSize = bDevice ? GetFormatSectorSize() : TC_SECTOR_SIZE_FILE_HOSTED_VOLUME;
if (fileSystem == FILESYS_NTFS && (dataAreaSize < TC_MIN_NTFS_FS_SIZE || dataAreaSize > TC_MAX_NTFS_FS_SIZE))
return VCF_ERROR_FILESYSTEM_INVALID_FOR_SIZE;
if (fileSystem == FILESYS_FAT && (dataAreaSize < TC_MIN_FAT_FS_SIZE || dataAreaSize > (TC_MAX_FAT_SECTOR_COUNT * sectorSize)))
return VCF_ERROR_FILESYSTEM_INVALID_FOR_SIZE;
if (fileSystem == FILESYS_EXFAT && (dataAreaSize < TC_MIN_EXFAT_FS_SIZE || dataAreaSize > TC_MAX_EXFAT_FS_SIZE))
return VCF_ERROR_FILESYSTEM_INVALID_FOR_SIZE;
if (fileSystem == FILESYS_REFS && (dataAreaSize < TC_MIN_REFS_FS_SIZE || dataAreaSize > TC_MAX_REFS_FS_SIZE))
return VCF_ERROR_FILESYSTEM_INVALID_FOR_SIZE;
// --- Prepare parameters for the core formatting function ---
FORMAT_VOL_PARAMETERS volParams = { 0 };
volParams.bDevice = bDevice;
volParams.hiddenVol = FALSE; // SDK does not support hidden volumes
volParams.volumePath = szDiskFile;
volParams.size = nVolumeSize;
volParams.ea = nVolumeEA;
volParams.pkcs5 = hash_algo;
volParams.fileSystem = fileSystem;
volParams.clusterSize = clusterSize;
volParams.quickFormat = quickFormat;
volParams.fastCreateFile = fastCreateFile;
volParams.sparseFileSwitch = dynamicFormat;
volParams.sectorSize = sectorSize;
volParams.password = &volumePassword;
volParams.pim = volumePim;
volParams.bGuiMode = FALSE;
volParams.hwndDlg = NULL;
volParams.bForceOperation = TRUE;
// Setup progress callback
SdkProgressContext progressCtx = { 0 };
if (options->progressCallback)
{
progressCtx.UserCallback = options->progressCallback;
progressCtx.UserData = options->progressUserData;
progressCtx.TotalSize = GetVolumeDataAreaSize(FALSE, nVolumeSize);
volParams.progress_callback = SdkProgressCallback;
volParams.progress_callback_user_data = &progressCtx;
}
// --- Call the core function ---
RandSetHashFunction(hash_algo);
int status = TCFormatVolume(&volParams);
// --- Return result ---
if (status == ERR_SUCCESS) return VCF_SUCCESS;
// Map internal errors to public SDK errors
switch (status)
{
case ERR_OUTOFMEMORY: return VCF_ERROR_OUT_OF_MEMORY;
case ERR_OS_ERROR:
{
DWORD lastError = GetLastError();
if (lastError == ERROR_ACCESS_DENIED) return VCF_ERROR_ACCESS_DENIED;
return VCF_ERROR_OS_ERROR;
}
case ERR_USER_ABORT: return VCF_ERROR_USER_ABORT;
default: return VCF_ERROR_GENERIC;
}
}
// --- Public DLL Exported Functions ---
extern "C"
{
VCF_API int __cdecl VeraCryptFormat_Initialize()
{
std::lock_guard<std::mutex> lock(g_sdkMutex);
if (g_isInitialized)
{
return VCF_SUCCESS;
}
Silent = TRUE; // We don't want UI
bGuiMode = FALSE; // Ensure GUI mode is off
InitApp(g_hDllInstance, L"");
if (DriverAttach() != 0) return VCF_ERROR_NO_DRIVER;
if (!AutoTestAlgorithms()) { cleanup(); return VCF_ERROR_SELF_TEST_FAILED; }
if (Randinit()) { cleanup(); return VCF_ERROR_RNG_INIT_FAILED; }
g_isInitialized = true;
return VCF_SUCCESS;
}
VCF_API void __cdecl VeraCryptFormat_Shutdown()
{
std::lock_guard<std::mutex> lock(g_sdkMutex);
if (g_isInitialized)
{
RandStop(TRUE);
cleanup();
g_isInitialized = false;
}
}
VCF_API int __cdecl VeraCryptFormat(const VeraCryptFormatOptions* options)
{
if (!g_isInitialized)
{
return VCF_ERROR_NOT_INITIALIZED;
}
// The internal function handles all logic and thread safety.
return CreateVolumeInternal(options);
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
g_hDllInstance = hinstDLL;
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
if (g_isInitialized)
{
VeraCryptFormat_Shutdown();
}
break;
}
return TRUE;
}
}
+136
View File
@@ -0,0 +1,136 @@
#pragma once
#include <stdint.h>
#ifdef VCSDK_EXPORTS
#define VCF_API __declspec(dllexport)
#else
#define VCF_API __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C" {
#endif
// --- Public Data Structures and Callbacks ---
/**
* @brief Defines the parameters for creating a VeraCrypt volume.
*/
typedef struct _VeraCryptFormatOptions
{
/** The full path to the file container to be created, or the device path (e.g., "\\.\PhysicalDrive1" or "\\.\HarddiskVolume1"). */
const wchar_t* path;
/** Set to TRUE if the path points to a device/partition, FALSE for a file container. */
BOOL isDevice;
/** The password for the new volume. Can be NULL if keyfiles are used. Must be UTF-8 encoded. */
const char* password;
/** A NULL-terminated array of wide-char strings, each being a full path to a keyfile. Set to NULL if no keyfiles are used. */
const wchar_t** keyfiles;
/** The Personal Iterations Multiplier (PIM). Use 0 for default PIM. */
int pim;
/** The size of the volume in bytes. This is only used for file containers (when isDevice is FALSE). Must be a multiple of 512. */
uint64_t size;
/** The encryption algorithm to use. E.g., L"AES", L"Serpent", L"Twofish", L"AES-Twofish-Serpent". */
const wchar_t* encryptionAlgorithm;
/** The header key derivation and random pool hash algorithm. E.g., L"SHA-512", L"RIPEMD-160", L"Whirlpool", L"BLAKE2s-256", L"SHA-256". */
const wchar_t* hashAlgorithm;
/** The filesystem for the new volume. E.g., L"NTFS", L"FAT", L"ExFAT", L"ReFS", or L"None". */
const wchar_t* filesystem;
/** The cluster size in sectors (e.g., 1, 2, 4, 8...). Use 0 for default. */
int clusterSize;
/** If TRUE, performs a quick format. This is faster but less secure as old data is not overwritten. */
BOOL quickFormat;
/** If TRUE, creates a dynamically-expanding (sparse) file container. Only for file containers. Implies quickFormat=TRUE. */
BOOL dynamicFormat;
/** If TRUE, creates a file container very quickly without waiting for random pool to be filled. Less secure. Only for file containers. Implies quickFormat=TRUE. */
BOOL fastCreateFile;
/** A callback function to receive progress updates. Can be NULL. It can return FALSE to abort the operation. */
BOOL (CALLBACK *progressCallback)(int percentComplete, void* userData);
/** User-defined data to be passed to the progress callback. */
void* progressUserData;
} VeraCryptFormatOptions;
/**
* @brief Progress callback function pointer type.
* @param percentComplete The percentage of the format operation that is complete (0-100).
* @param userData The user-defined data pointer passed in VeraCryptFormatOptions.
* @return Returns TRUE to continue the operation, or FALSE to abort it.
*/
typedef BOOL (CALLBACK *VeraCrypt_Progress_Callback)(int percentComplete, void* userData);
// --- Public Error Codes ---
#define VCF_SUCCESS 0
#define VCF_ERROR_GENERIC 1 // A generic or unknown error occurred.
#define VCF_ERROR_INVALID_PARAMETER 2 // An invalid parameter was passed (e.g. NULL path).
#define VCF_ERROR_PASSWORD_OR_KEYFILE_REQUIRED 3 // A password and/or keyfile must be provided.
#define VCF_ERROR_INVALID_ENCRYPTION_ALGORITHM 4
#define VCF_ERROR_INVALID_HASH_ALGORITHM 5
#define VCF_ERROR_INVALID_FILESYSTEM 6
#define VCF_ERROR_PASSWORD_POLICY 7 // Password is too long or violates other policies.
#define VCF_ERROR_KEYFILE_ERROR 8 // Error reading or processing a keyfile.
#define VCF_ERROR_OUT_OF_MEMORY 9
#define VCF_ERROR_OS_ERROR 10 // A Windows API call failed.
#define VCF_ERROR_CANNOT_GET_DEVICE_SIZE 11
#define VCF_ERROR_VOLUME_SIZE_TOO_SMALL 12
#define VCF_ERROR_RNG_INIT_FAILED 13
#define VCF_ERROR_NO_DRIVER 14 // VeraCrypt driver is not running.
#define VCF_ERROR_SELF_TEST_FAILED 15
#define VCF_ERROR_USER_ABORT 16 // Should not occur in SDK, but mapped for completeness.
#define VCF_ERROR_INITIALIZATION_FAILED 17
#define VCF_ERROR_NOT_INITIALIZED 18
#define VCF_ERROR_INVALID_VOLUME_SIZE 19 // e.g., not a multiple of sector size.
#define VCF_ERROR_FILESYSTEM_INVALID_FOR_SIZE 21 // The selected filesystem cannot be used for the given volume size.
#define VCF_ERROR_CONTAINER_TOO_LARGE_FOR_HOST 22 // The file container is larger than the available free space.
#define VCF_ERROR_ACCESS_DENIED 23 // The target path is read-only or cannot be created.
// --- Public API Functions ---
/**
* @brief Initializes the VeraCrypt Format SDK.
* This function must be called once per process before any other SDK functions.
* It attaches to the VeraCrypt driver, runs self-tests, and seeds the RNG.
* This function is thread-safe.
*
* @return Returns VCF_SUCCESS (0) on success, or a non-zero VCF_ERROR_* code on failure.
*/
VCF_API int __cdecl VeraCryptFormat_Initialize();
/**
* @brief Shuts down the VeraCrypt Format SDK.
* Call this function when the SDK is no longer needed to release resources.
*/
VCF_API void __cdecl VeraCryptFormat_Shutdown();
/**
* @brief Creates a VeraCrypt volume (file container or formatted partition).
* This is the main entry point for the VeraCrypt Format SDK.
* This function is synchronous and will block until the format operation is complete.
* It is thread-safe, but operations are serialized internally.
* VeraCryptFormat_Initialize() must be called successfully before using this function.
*
* @param options A pointer to a VeraCryptFormatOptions struct containing all parameters for the operation.
* @return Returns VCF_SUCCESS (0) on success, or a non-zero VCF_ERROR_* code on failure.
*/
VCF_API int __cdecl VeraCryptFormat(const VeraCryptFormatOptions* options);
#ifdef __cplusplus
}
#endif