1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2026-06-20 03:25:03 -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
-33
View File
@@ -2177,39 +2177,6 @@ BOOL SaveNonSysInPlaceEncSettings (int delta, WipeAlgorithmId newWipeAlgorithm,
return SaveBufferToFile (str, GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC), (DWORD) strlen(str), FALSE, FALSE);
}
// This function moves the file pointer to the given offset. It first retrieves the current
// file position using SetFilePointerEx() with FILE_CURRENT as the reference point, and then
// calculates the difference between the current position and the desired position. Subsequently,
// it moves the file pointer by the difference calculated using SetFilePointerEx() again.
//
// This approach of moving the file pointer relatively (instead of absolutely) was implemented
// as a workaround to address the performance issues related to in-place encryption. When using
// SetFilePointerEx() with FILE_BEGIN as the reference point, reaching the end of large drives
// during in-place encryption can cause significant slowdowns. By moving the file pointer
// relatively, these performance issues are mitigated.
//
// We fall back to absolute positioning if the relative positioning fails.
BOOL MoveFilePointer (HANDLE dev, LARGE_INTEGER offset)
{
LARGE_INTEGER currOffset;
LARGE_INTEGER diffOffset;
currOffset.QuadPart = 0;
if (SetFilePointerEx (dev, currOffset, &currOffset, FILE_CURRENT))
{
diffOffset.QuadPart = offset.QuadPart - currOffset.QuadPart;
if (diffOffset.QuadPart == 0)
return TRUE;
// Moves the file pointer by the difference between current and desired positions
if (SetFilePointerEx (dev, diffOffset, NULL, FILE_CURRENT))
return TRUE;
}
// An error occurred, fallback to absolute positioning
return SetFilePointerEx (dev, offset, NULL, FILE_BEGIN);
}
// Repairs damaged sectors (i.e. those with read errors) by zeroing them.
// Note that this operating fails if there are any write errors.
int ZeroUnreadableSectors (HANDLE dev, LARGE_INTEGER startOffset, int64 size, int sectorSize, uint64 *zeroedSectorCount)
+53 -51
View File
@@ -304,6 +304,58 @@ vector <HostDevice> DeferredNonSysInPlaceEncDevices;
int iMaxPasswordLength = MAX_PASSWORD;
void WipePasswordsAndKeyfiles(bool bFull)
{
wchar_t tmp[MAX_PASSWORD + 1];
// Attempt to wipe passwords stored in the input field buffers
wmemset(tmp, L'X', MAX_PASSWORD);
tmp[MAX_PASSWORD] = 0;
if (hPasswordInputField)
SetWindowText(hPasswordInputField, tmp);
if (hVerifyPasswordInputField)
SetWindowText(hVerifyPasswordInputField, tmp);
burn(&szVerify[0], sizeof(szVerify));
burn(&volumePassword, sizeof(volumePassword));
burn(&szRawPassword[0], sizeof(szRawPassword));
burn(&volumePim, sizeof(volumePim));
burn(&CmdVolumePassword, sizeof(CmdVolumePassword));
burn(&CmdVolumePim, sizeof(CmdVolumePim));
if (bFull)
{
burn(&outerVolumePassword, sizeof(outerVolumePassword));
burn(&outerVolumePim, sizeof(outerVolumePim));
}
if (hPasswordInputField)
SetWindowText(hPasswordInputField, L"");
if (hVerifyPasswordInputField)
SetWindowText(hVerifyPasswordInputField, L"");
KeyFileRemoveAll(&FirstKeyFile);
KeyFileRemoveAll(&defaultKeyFilesParam.FirstKeyFile);
}
DWORD GetFormatSectorSize()
{
if (!bDevice)
return TC_SECTOR_SIZE_FILE_HOSTED_VOLUME;
DISK_GEOMETRY_EX geometry;
if (!GetDriveGeometry(szDiskFile, &geometry))
{
handleWin32Error(MainDlg, SRC_POS);
AbortProcessSilent();
}
return geometry.Geometry.BytesPerSector;
}
#ifndef VCSDK_DLL
// specific definitions and implementation for support of resume operation
// in wait dialog mechanism
@@ -414,40 +466,6 @@ static BOOL ElevateWholeWizardProcess (wstring arguments)
}
}
static void WipePasswordsAndKeyfiles (bool bFull)
{
wchar_t tmp[MAX_PASSWORD+1];
// Attempt to wipe passwords stored in the input field buffers
wmemset (tmp, L'X', MAX_PASSWORD);
tmp [MAX_PASSWORD] = 0;
if (hPasswordInputField)
SetWindowText (hPasswordInputField, tmp);
if (hVerifyPasswordInputField)
SetWindowText (hVerifyPasswordInputField, tmp);
burn (&szVerify[0], sizeof (szVerify));
burn (&volumePassword, sizeof (volumePassword));
burn (&szRawPassword[0], sizeof (szRawPassword));
burn (&volumePim, sizeof (volumePim));
burn (&CmdVolumePassword, sizeof (CmdVolumePassword));
burn (&CmdVolumePim, sizeof (CmdVolumePim));
if (bFull)
{
burn (&outerVolumePassword, sizeof (outerVolumePassword));
burn (&outerVolumePim, sizeof (outerVolumePim));
}
if (hPasswordInputField)
SetWindowText (hPasswordInputField, L"");
if (hVerifyPasswordInputField)
SetWindowText (hVerifyPasswordInputField, L"");
KeyFileRemoveAll (&FirstKeyFile);
KeyFileRemoveAll (&defaultKeyFilesParam.FirstKeyFile);
}
static void localcleanup (void)
{
wchar_t tmp[RANDPOOL_DISPLAY_SIZE+1];
@@ -10661,20 +10679,4 @@ int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t *lpsz
return 0;
}
static DWORD GetFormatSectorSize ()
{
if (!bDevice)
return TC_SECTOR_SIZE_FILE_HOSTED_VOLUME;
DISK_GEOMETRY_EX geometry;
if (!GetDriveGeometry (szDiskFile, &geometry))
{
handleWin32Error (MainDlg, SRC_POS);
AbortProcessSilent();
}
return geometry.Geometry.BytesPerSector;
}
#endif
+1 -1
View File
@@ -78,7 +78,7 @@ static void WipeAbort (void);
static void UpdateWipeProgressBar (void);
static void InitWipeProgressBar (void);
static void UpdateWipeControls (void);
static DWORD GetFormatSectorSize ();
DWORD GetFormatSectorSize ();
extern BOOL showKeys;
extern volatile HWND hMasterKey;