From fd80bc0679fda98df83ee30aa22c00f0643ef147 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Fri, 5 Jun 2026 21:03:49 +0900 Subject: [PATCH] Windows: allow selecting KDFs in benchmark dialog Add a KDF checklist to the Windows benchmark dialog while keeping all algorithms selected by default. Filter KDF benchmark execution to the checked algorithms and silently skip when none are selected. Reuse existing KDF localization strings and keep Language.xml unchanged. --- src/Common/Common.rc | 16 ++-- src/Common/Dlgcode.c | 188 ++++++++++++++++++++++++++++++++++++++++-- src/Common/Resource.h | 3 +- 3 files changed, 194 insertions(+), 13 deletions(-) diff --git a/src/Common/Common.rc b/src/Common/Common.rc index bb9f617d..640895a2 100644 --- a/src/Common/Common.rc +++ b/src/Common/Common.rc @@ -141,7 +141,7 @@ BEGIN CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,1,158,208,1,WS_EX_STATICEDGE END -IDD_BENCHMARK_DLG DIALOGEX 0, 0, 330, 247 +IDD_BENCHMARK_DLG DIALOGEX 0, 0, 420, 247 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "VeraCrypt - Algorithms Benchmark" FONT 8, "MS Shell Dlg", 400, 0, 0x1 @@ -151,18 +151,20 @@ BEGIN EDITTEXT IDC_PIM,209,11,42,14,ES_RIGHT | ES_AUTOHSCROLL | ES_NUMBER | NOT WS_VISIBLE CONTROL "Pre-Boot",IDC_BENCHMARK_PREBOOT,"Button",BS_AUTOCHECKBOX | NOT WS_VISIBLE | WS_TABSTOP,258,14,71,10 COMBOBOX IDC_BENCHMARK_SORT_METHOD,55,40,139,74,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP - DEFPUSHBUTTON "Benchmark",IDC_PERFORM_BENCHMARK,265,60,58,14 - PUSHBUTTON "Close",IDCLOSE,265,79,58,14 + DEFPUSHBUTTON "Benchmark",IDC_PERFORM_BENCHMARK,355,60,58,14 + PUSHBUTTON "Close",IDCLOSE,355,79,58,14 CONTROL "",IDC_RESULTS,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,7,60,249,160 + LTEXT "KDF:",IDT_KDF,265,107,148,9,NOT WS_VISIBLE + CONTROL "",IDC_BENCHMARK_KDF_LIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_NOCOLUMNHEADER | LVS_NOSORTHEADER | WS_BORDER | NOT WS_VISIBLE | WS_TABSTOP,265,119,148,101 LTEXT "Hardware-accelerated AES:",IDC_HW_AES_LABEL_LINK,148,233,108,9,SS_NOTIFY,WS_EX_RIGHT CONTROL "",IDC_HW_AES,"Static",SS_LEFTNOWORDWRAP | WS_GROUP,262,232,57,11,WS_EX_STATICEDGE LTEXT "Parallelization:",IDC_PARALLELIZATION_LABEL_LINK,4,233,67,9,SS_NOTIFY,WS_EX_RIGHT CONTROL "",IDC_PARALLELIZATION,"Static",SS_LEFTNOWORDWRAP | WS_GROUP,77,232,57,11,WS_EX_STATICEDGE - CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,2,32,328,1,WS_EX_STATICEDGE + CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,2,32,418,1,WS_EX_STATICEDGE LTEXT "Buffer Size:",IDT_BUFFER_SIZE,154,14,53,8,0,WS_EX_RIGHT LTEXT "Sort Method:",IDT_SORT_METHOD,0,42,53,8,0,WS_EX_RIGHT - LTEXT "Speed is affected by CPU load and storage device characteristics.\n\nThese tests take place in RAM.",IDT_BOX_BENCHMARK_INFO,266,107,57,100 - CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,2,228,328,1,WS_EX_STATICEDGE + LTEXT "Speed is affected by CPU load and storage device characteristics.\n\nThese tests take place in RAM.",IDT_BOX_BENCHMARK_INFO,266,107,148,100 + CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,2,228,418,1,WS_EX_STATICEDGE LTEXT "Benchmark: ",IDT_BENCHMARK,0,14,53,8,0,WS_EX_RIGHT RTEXT "Volume PIM:",IDT_PIM,154,14,53,8,NOT WS_VISIBLE END @@ -402,7 +404,7 @@ BEGIN IDD_BENCHMARK_DLG, DIALOG BEGIN LEFTMARGIN, 7 - RIGHTMARGIN, 323 + RIGHTMARGIN, 413 TOPMARGIN, 7 BOTTOMMARGIN, 240 END diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c index 940f709e..8915578a 100644 --- a/src/Common/Dlgcode.c +++ b/src/Common/Dlgcode.c @@ -414,6 +414,8 @@ int benchmarkType = BENCHMARK_TYPE_ENCRYPTION; int benchmarkPim = -1; BOOL benchmarkPreBoot = FALSE; BOOL benchmarkGPT = FALSE; +BOOL benchmarkSelectedKdfs[LAST_PRF_ID + 1]; +BOOL benchmarkKdfListUpdating = FALSE; #endif // #ifndef SETUP @@ -6202,6 +6204,161 @@ void GetSpeedString (unsigned __int64 speed, wchar_t *str, size_t cbStr) StringCbPrintfW (str, cbStr, L"%I64d %s", speed, b); } +static void ResetBenchmarkList (HWND hwndDlg); + +static void ResetBenchmarkKdfSelections (void) +{ + int kdf; + + memset (benchmarkSelectedKdfs, 0, sizeof (benchmarkSelectedKdfs)); + for (kdf = FIRST_PRF_ID; kdf <= LAST_PRF_ID; kdf++) + benchmarkSelectedKdfs[kdf] = TRUE; +} + +static BOOL BenchmarkKdfAllowedForCurrentOptions (int kdf) +{ + PRF_BOOT_TYPE bootType = PRF_BOOT_NO; + + if (benchmarkPreBoot) + bootType = benchmarkGPT ? PRF_BOOT_GPT : PRF_BOOT_MBR; + + return is_pkcs5_prf_supported (kdf, bootType) && HashIsAvailable (kdf); +} + +static BOOL BenchmarkKdfSelectedForCurrentOptions (int kdf) +{ + return BenchmarkKdfAllowedForCurrentOptions (kdf) && benchmarkSelectedKdfs[kdf]; +} + +static int GetBenchmarkKdfListItem (HWND hList, int itemIndex) +{ + LVITEMW LvItem; + + memset (&LvItem, 0, sizeof (LvItem)); + LvItem.mask = LVIF_PARAM; + LvItem.iItem = itemIndex; + + if (!ListView_GetItem (hList, &LvItem)) + return 0; + + return (int) LvItem.lParam; +} + +static void InitBenchmarkKdfList (HWND hwndDlg) +{ + LVCOLUMNW LvCol; + int thid, itemIndex = 0; + HWND hList = GetDlgItem (hwndDlg, IDC_BENCHMARK_KDF_LIST); + + if (!hList) + return; + + benchmarkKdfListUpdating = TRUE; + + ListView_DeleteAllItems (hList); + + SendMessage (hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, + LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP); + + memset (&LvCol, 0, sizeof (LvCol)); + LvCol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM | LVCF_FMT; + LvCol.pszText = GetString ("KDF"); + LvCol.cx = CompensateXDPI (126); + LvCol.fmt = LVCFMT_LEFT; + SendMessageW (hList, LVM_INSERTCOLUMNW, 0, (LPARAM) &LvCol); + + for (thid = FIRST_PRF_ID; thid <= LAST_PRF_ID; thid++) + { + LVITEMW LvItem; + + memset (&LvItem, 0, sizeof (LvItem)); + LvItem.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE; + LvItem.iItem = itemIndex; + LvItem.pszText = get_kdf_name (thid); + LvItem.lParam = (LPARAM) thid; + LvItem.stateMask = LVIS_STATEIMAGEMASK; + LvItem.state = INDEXTOSTATEIMAGEMASK (benchmarkSelectedKdfs[thid] ? 2 : 1); + + ListView_InsertItem (hList, &LvItem); + itemIndex++; + } + + benchmarkKdfListUpdating = FALSE; +} + +static void UpdateBenchmarkKdfListForCurrentOptions (HWND hwndDlg) +{ + int itemIndex; + HWND hList = GetDlgItem (hwndDlg, IDC_BENCHMARK_KDF_LIST); + int itemCount = ListView_GetItemCount (hList); + + benchmarkKdfListUpdating = TRUE; + + for (itemIndex = 0; itemIndex < itemCount; itemIndex++) + { + int kdf = GetBenchmarkKdfListItem (hList, itemIndex); + ListView_SetCheckState (hList, itemIndex, BenchmarkKdfSelectedForCurrentOptions (kdf)); + } + + benchmarkKdfListUpdating = FALSE; +} + +static void UpdateBenchmarkKdfSelectorVisibility (HWND hwndDlg) +{ + BOOL show = (benchmarkType == BENCHMARK_TYPE_PRF); + + ShowWindow (GetDlgItem (hwndDlg, IDT_KDF), show ? SW_SHOW : SW_HIDE); + ShowWindow (GetDlgItem (hwndDlg, IDC_BENCHMARK_KDF_LIST), show ? SW_SHOW : SW_HIDE); + ShowWindow (GetDlgItem (hwndDlg, IDT_BOX_BENCHMARK_INFO), show ? SW_HIDE : SW_SHOW); + + if (show) + UpdateBenchmarkKdfListForCurrentOptions (hwndDlg); +} + +static BOOL BenchmarkHasSelectedKdfForCurrentOptions (void) +{ + int kdf; + + for (kdf = FIRST_PRF_ID; kdf <= LAST_PRF_ID; kdf++) + { + if (BenchmarkKdfSelectedForCurrentOptions (kdf)) + return TRUE; + } + + return FALSE; +} + +static BOOL HandleBenchmarkKdfListItemChanged (HWND hwndDlg, LPNMLISTVIEW changedItem) +{ + int kdf; + BOOL selected; + HWND hList = GetDlgItem (hwndDlg, IDC_BENCHMARK_KDF_LIST); + + if (benchmarkKdfListUpdating + || changedItem->iItem < 0 + || !(changedItem->uChanged & LVIF_STATE) + || !((changedItem->uOldState ^ changedItem->uNewState) & LVIS_STATEIMAGEMASK)) + { + return TRUE; + } + + kdf = GetBenchmarkKdfListItem (hList, changedItem->iItem); + selected = ListView_GetCheckState (hList, changedItem->iItem); + + if (!BenchmarkKdfAllowedForCurrentOptions (kdf)) + { + if (selected) + ListView_SetCheckState (hList, changedItem->iItem, FALSE); + + return TRUE; + } + + benchmarkSelectedKdfs[kdf] = selected; + benchmarkTotalItems = 0; + ResetBenchmarkList (hwndDlg); + return TRUE; +} + static void ResetBenchmarkList (HWND hwndDlg) { LVCOLUMNW LvCol; @@ -6527,11 +6684,7 @@ static BOOL PerformBenchmark(HWND hBenchDlg, HWND hwndDlg) for (thid = FIRST_PRF_ID; thid <= LAST_PRF_ID; thid++) { - if (benchmarkPreBoot && !benchmarkGPT && !HashForSystemEncryption (thid)) - continue; - - // we don't support Argon2 for system encryption - if (benchmarkPreBoot && thid == ARGON2) + if (!BenchmarkKdfSelectedForCurrentOptions (thid)) continue; if (QueryPerformanceCounter (&performanceCountStart) == 0) @@ -6762,6 +6915,8 @@ BOOL CALLBACK BenchmarkDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP benchmarkBufferSize = BENCHMARK_DEFAULT_BUF_SIZE; benchmarkSortMethod = BENCHMARK_SORT_BY_SPEED; benchmarkType = BENCHMARK_TYPE_ENCRYPTION; + benchmarkPreBoot = FALSE; + ResetBenchmarkKdfSelections (); if (lParam) { @@ -6782,6 +6937,8 @@ BOOL CALLBACK BenchmarkDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP SendMessage (hList,LVM_INSERTCOLUMNW,0,(LPARAM)&LvCol); ResetBenchmarkList (hwndDlg); + InitBenchmarkKdfList (hwndDlg); + UpdateBenchmarkKdfSelectorVisibility (hwndDlg); /* Combo boxes */ @@ -6903,6 +7060,14 @@ BOOL CALLBACK BenchmarkDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP } break; + case WM_NOTIFY: + if (((LPNMHDR) lParam)->idFrom == IDC_BENCHMARK_KDF_LIST + && ((LPNMHDR) lParam)->code == LVN_ITEMCHANGED) + { + return HandleBenchmarkKdfListItemChanged (hwndDlg, (LPNMLISTVIEW) lParam); + } + break; + case WM_COMMAND: switch (lw) @@ -6929,6 +7094,7 @@ BOOL CALLBACK BenchmarkDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP if (benchmarkType == BENCHMARK_TYPE_PRF) { + benchmarkPreBoot = GetCheckBox (hwndDlg, IDC_BENCHMARK_PREBOOT); ShowWindow (GetDlgItem (hwndDlg, IDC_BENCHMARK_BUFFER_SIZE), SW_HIDE); ShowWindow (GetDlgItem (hwndDlg, IDT_BUFFER_SIZE), SW_HIDE); ShowWindow (GetDlgItem (hwndDlg, IDC_PIM), SW_SHOW); @@ -6943,6 +7109,16 @@ BOOL CALLBACK BenchmarkDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP ShowWindow (GetDlgItem (hwndDlg, IDT_PIM), SW_HIDE); ShowWindow (GetDlgItem (hwndDlg, IDC_BENCHMARK_PREBOOT), SW_HIDE); } + + UpdateBenchmarkKdfSelectorVisibility (hwndDlg); + return 1; + + case IDC_BENCHMARK_PREBOOT: + + benchmarkPreBoot = GetCheckBox (hwndDlg, IDC_BENCHMARK_PREBOOT); + UpdateBenchmarkKdfListForCurrentOptions (hwndDlg); + benchmarkTotalItems = 0; + ResetBenchmarkList (hwndDlg); return 1; case IDC_PERFORM_BENCHMARK: @@ -6951,6 +7127,8 @@ BOOL CALLBACK BenchmarkDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP { benchmarkPim = GetPim (hwndDlg, IDC_PIM, 0); benchmarkPreBoot = GetCheckBox (hwndDlg, IDC_BENCHMARK_PREBOOT); + if (!BenchmarkHasSelectedKdfForCurrentOptions ()) + return 1; } else { diff --git a/src/Common/Resource.h b/src/Common/Resource.h index 93c7ab08..bc5dd32a 100644 --- a/src/Common/Resource.h +++ b/src/Common/Resource.h @@ -227,6 +227,7 @@ #define IDC_LINK_KEYFILES_EXTENSIONS_WARNING 5144 #define IDC_DISABLE_MEMORY_PROTECTION 5145 #define IDC_DISABLE_MEMORY_PROTECTION_HELP 5146 +#define IDC_BENCHMARK_KDF_LIST 5147 // Next default values for new objects // @@ -235,7 +236,7 @@ #define _APS_NO_MFC 1 #define _APS_NEXT_RESOURCE_VALUE 585 #define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 5147 +#define _APS_NEXT_CONTROL_VALUE 5148 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif