VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2023-06-20 23:15:46 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2023-06-20 23:15:46 +0200
commitfbb1d180348f027974269dc22696a9d74a47f61d (patch)
treea285a250f91a3ec4caca7db2c5e78966614e08be /src
parent2bfeba160c80802287a9c63b0d0e7bd0a1a95079 (diff)
downloadVeraCrypt-fbb1d180348f027974269dc22696a9d74a47f61d.tar.gz
VeraCrypt-fbb1d180348f027974269dc22696a9d74a47f61d.zip
Windows: Allow selecting size unit (KB/MB/GB) for generated keyfiles
This change also makes it possible to generate keyfiles larger than 1 MiB although only the first 1 MiB will be taken into account by VeraCrypt. Update strings in XML files
Diffstat (limited to 'src')
-rw-r--r--src/Common/Common.rc15
-rw-r--r--src/Common/Dlgcode.c73
-rw-r--r--src/Common/Language.xml4
-rw-r--r--src/Common/Resource.h3
4 files changed, 68 insertions, 27 deletions
diff --git a/src/Common/Common.rc b/src/Common/Common.rc
index 6d50a1fb..aa1ca18f 100644
--- a/src/Common/Common.rc
+++ b/src/Common/Common.rc
@@ -211,7 +211,7 @@ BEGIN
CONTROL "",IDC_INFO_BOX_TEXT,"RichEdit20W",ES_MULTILINE | ES_READONLY | ES_NUMBER | WS_BORDER | WS_VSCROLL | WS_TABSTOP,5,6,361,188
END
-IDD_KEYFILE_GENERATOR DIALOGEX 0, 0, 357, 362
+IDD_KEYFILE_GENERATOR DIALOGEX 0, 0, 357, 369
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "VeraCrypt - Keyfile Generator"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
@@ -221,18 +221,19 @@ BEGIN
CONTROL "Display pool content",IDC_DISPLAY_POOL_CONTENTS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,209,51,141,10
EDITTEXT IDC_NUMBER_KEYFILES,124,278,51,14,ES_RIGHT | ES_AUTOHSCROLL | ES_NUMBER
EDITTEXT IDC_KEYFILES_SIZE,124,298,51,14,ES_RIGHT | ES_AUTOHSCROLL | ES_NUMBER
+ COMBOBOX IDC_KEYFILES_SIZE_UNIT,182,299,41,137,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
CONTROL "Random size ( 64 <-> 1048576 )",IDC_KEYFILES_RANDOM_SIZE,
- "Button",BS_AUTOCHECKBOX | WS_TABSTOP,181,300,174,10
- EDITTEXT IDC_KEYFILES_BASE_NAME,124,318,141,14,ES_AUTOHSCROLL
- PUSHBUTTON "Generate and Save Keyfile...",IDC_GENERATE_AND_SAVE_KEYFILE,124,336,141,14
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,124,317,174,10
+ EDITTEXT IDC_KEYFILES_BASE_NAME,124,331,141,14,ES_AUTOHSCROLL
+ PUSHBUTTON "Generate and Save Keyfile...",IDC_GENERATE_AND_SAVE_KEYFILE,124,349,141,14
LTEXT "IMPORTANT: Move your mouse as randomly as possible within this window. The longer you move it, the better. This significantly increases the cryptographic strength of the keyfile.",IDT_KEYFILE_GENERATOR_NOTE,11,5,271,33
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,1,40,356,1,WS_EX_STATICEDGE
RTEXT "Mixing PRF:",IDT_PRF,7,51,85,10,SS_CENTERIMAGE
GROUPBOX "Current Pool Content",IDT_POOL_CONTENTS,6,70,344,170
CTEXT "",IDC_POOL_CONTENTS,16,83,323,148,0,WS_EX_TRANSPARENT
RTEXT "Number of keyfiles:",IDT_NUMBER_KEYFILES,9,281,110,8
- RTEXT "Keyfiles base name:",IDT_KEYFILES_BASE_NAME,9,321,110,8
- RTEXT "Keyfiles size (in Bytes):",IDT_KEYFILES_SIZE,9,300,110,8
+ RTEXT "Keyfiles base name:",IDT_KEYFILES_BASE_NAME,9,334,110,8
+ RTEXT "Keyfiles size:",IDT_KEYFILES_SIZE,9,300,110,8
CONTROL "",IDC_ENTROPY_BAR,"msctls_progress32",PBS_SMOOTH | WS_BORDER,18,255,321,12
GROUPBOX "Randomness Collected From Mouse Movements",IDT_ENTROPY_BAR,6,244,344,29
END
@@ -424,7 +425,7 @@ BEGIN
BEGIN
LEFTMARGIN, 7
TOPMARGIN, 7
- BOTTOMMARGIN, 358
+ BOTTOMMARGIN, 365
END
IDD_MULTI_CHOICE_DLG, DIALOG
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index 2fd18606..76748fe5 100644
--- a/src/Common/Dlgcode.c
+++ b/src/Common/Dlgcode.c
@@ -7167,6 +7167,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
case WM_INITDIALOG:
{
HWND hComboBox = GetDlgItem (hwndDlg, IDC_PRF_ID);
+ HWND hSizeUnit = GetDlgItem (hwndDlg, IDC_KEYFILES_SIZE_UNIT);
HCRYPTPROV hRngProv = NULL;
VirtualLock (randPool, sizeof(randPool));
@@ -7196,6 +7197,16 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
}
SelectAlgo (hComboBox, &hash_algo);
+ // populate keyfiles size unit combo
+ SendMessage (hSizeUnit, CB_RESETCONTENT, 0, 0);
+ AddComboPair (hSizeUnit, GetString ("BYTES"), 0);
+ AddComboPair (hSizeUnit, GetString ("KB"), 1);
+ AddComboPair (hSizeUnit, GetString ("MB"), 2);
+ AddComboPair (hSizeUnit, GetString ("GB"), 3);
+
+ // set default keyfiles size unit
+ SendMessage (hSizeUnit, CB_SETCURSEL, 0, 0);
+
SetCheckBox (hwndDlg, IDC_DISPLAY_POOL_CONTENTS, bDisplayPoolContents);
hEntropyBar = GetDlgItem (hwndDlg, IDC_ENTROPY_BAR);
SendMessage (hEntropyBar, PBM_SETRANGE32, 0, maxEntropyLevel);
@@ -7303,6 +7314,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
if (lw == IDC_KEYFILES_RANDOM_SIZE)
{
EnableWindow(GetDlgItem (hwndDlg, IDC_KEYFILES_SIZE), !GetCheckBox (hwndDlg, IDC_KEYFILES_RANDOM_SIZE));
+ EnableWindow(GetDlgItem (hwndDlg, IDC_KEYFILES_SIZE_UNIT), !GetCheckBox (hwndDlg, IDC_KEYFILES_RANDOM_SIZE));
}
if (lw == IDC_GENERATE_AND_SAVE_KEYFILE)
@@ -7313,7 +7325,10 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
wchar_t szFileName [2*TC_MAX_PATH + 16];
unsigned char *keyfile = NULL;
int fhKeyfile = -1, status;
- long keyfilesCount = 0, keyfilesSize = 0, i;
+ long keyfilesCount = 0, i;
+ unsigned long long keyfilesSize = 0, remainingBytes = 0;
+ int selectedUnitIndex, selectedUnitFactor, loopIndex, rndBytesLength;
+ DWORD dwLastError = 0;
wchar_t* fileExtensionPtr = 0;
wchar_t szSuffix[32];
BOOL bRandomSize = GetCheckBox (hwndDlg, IDC_KEYFILES_RANDOM_SIZE);
@@ -7335,12 +7350,23 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
szNumber[0] = 0;
keyfilesSize = wcstoul(szNumber, NULL, 0);
- if (keyfilesSize < 64 || keyfilesSize > 1024*1024)
+ // multiply by the unit factor
+ selectedUnitIndex = ComboBox_GetCurSel (GetDlgItem (hwndDlg, IDC_KEYFILES_SIZE_UNIT));
+ if (selectedUnitIndex != CB_ERR)
+ {
+ selectedUnitFactor = (CK_SLOT_ID) ComboBox_GetItemData (GetDlgItem (hwndDlg, IDC_KEYFILES_SIZE_UNIT), selectedUnitIndex);
+ for (loopIndex = 0; loopIndex < selectedUnitFactor; loopIndex++)
+ keyfilesSize *= 1024ULL;
+ }
+
+ if (keyfilesSize < 64)
{
Warning("KEYFILE_INCORRECT_SIZE", hwndDlg);
SendMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM) GetDlgItem (hwndDlg, IDC_KEYFILES_SIZE), TRUE);
return 1;
}
+
+ remainingBytes = keyfilesSize;
}
if (!GetWindowText(GetDlgItem (hwndDlg, IDC_KEYFILES_BASE_NAME), szFileBaseName, TC_MAX_PATH))
@@ -7372,7 +7398,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
WaitCursor();
- keyfile = (unsigned char*) TCalloc( bRandomSize? KEYFILE_MAX_READ_LEN : keyfilesSize );
+ keyfile = (unsigned char*) TCalloc(KEYFILE_MAX_READ_LEN);
for (i= 0; i < keyfilesCount; i++)
{
@@ -7435,32 +7461,45 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
return 1;
}
- /* since keyfilesSize < 1024 * 1024, we mask with 0x000FFFFF */
- keyfilesSize = (long) (((unsigned long) keyfilesSize) & 0x000FFFFF);
+ /* since random keyfilesSize < 1024 * 1024, we mask with 0x000FFFFF */
+ keyfilesSize = (unsigned long long) (((unsigned long) keyfilesSize) & 0x000FFFFF);
keyfilesSize %= ((KEYFILE_MAX_READ_LEN - 64) + 1);
keyfilesSize += 64;
+
+ remainingBytes = keyfilesSize;
}
- /* Generate the keyfile */
- if (!RandgetBytesFull (hwndDlg, keyfile, keyfilesSize, TRUE, TRUE))
- {
- _close (fhKeyfile);
- DeleteFile (szFileName);
- TCfree(keyfile);
- NormalCursor();
- return 1;
- }
+ do {
+ rndBytesLength = (int) min (remainingBytes, (unsigned long long) KEYFILE_MAX_READ_LEN);
+
+ /* Generate the keyfile */
+ if (!RandgetBytesFull (hwndDlg, keyfile, rndBytesLength, TRUE, TRUE))
+ {
+ _close (fhKeyfile);
+ DeleteFile (szFileName);
+ TCfree(keyfile);
+ NormalCursor();
+ return 1;
+ }
+
+ /* Write the keyfile */
+ status = _write (fhKeyfile, keyfile, rndBytesLength);
+ } while (status != -1 && (remainingBytes -= (unsigned long long) rndBytesLength) > 0);
+
+ /* save last error code */
+ if (status == -1)
+ dwLastError = GetLastError();
- /* Write the keyfile */
- status = _write (fhKeyfile, keyfile, keyfilesSize);
- burn (keyfile, keyfilesSize);
+ burn (keyfile, KEYFILE_MAX_READ_LEN);
_close (fhKeyfile);
if (status == -1)
{
TCfree(keyfile);
NormalCursor();
+ /* restore last error code */
+ SetLastError(dwLastError);
handleWin32Error (hwndDlg, SRC_POS);
return 1;
}
diff --git a/src/Common/Language.xml b/src/Common/Language.xml
index a2555147..8d6fb7ab 100644
--- a/src/Common/Language.xml
+++ b/src/Common/Language.xml
@@ -356,7 +356,7 @@
<entry lang="en" key="IDT_KEYFILE_WARNING">WARNING: If you lose a keyfile or if any bit of its first 1024 kilobytes changes, it will be impossible to mount volumes that use the keyfile!</entry>
<entry lang="en" key="IDT_KEY_UNIT">bits</entry>
<entry lang="en" key="IDT_NUMBER_KEYFILES">Number of keyfiles:</entry>
- <entry lang="en" key="IDT_KEYFILES_SIZE">Keyfiles size (in Bytes):</entry>
+ <entry lang="en" key="IDT_KEYFILES_SIZE">Keyfiles size:</entry>
<entry lang="en" key="IDT_KEYFILES_BASE_NAME">Keyfiles base name:</entry>
<entry lang="en" key="IDT_LANGPACK_AUTHORS">Translated by:</entry>
<entry lang="en" key="IDT_PLAINTEXT">Plaintext size:</entry>
@@ -938,7 +938,7 @@
<entry lang="en" key="ENTER_HEADER_BACKUP_PASSWORD">Enter password for the header stored in backup file</entry>
<entry lang="en" key="KEYFILE_CREATED">Keyfiles have been successfully created.</entry>
<entry lang="en" key="KEYFILE_INCORRECT_NUMBER">The number of keyfiles you supplied is invalid.</entry>
- <entry lang="en" key="KEYFILE_INCORRECT_SIZE">The keyfile size must be comprized between 64 and 1048576 bytes.</entry>
+ <entry lang="en" key="KEYFILE_INCORRECT_SIZE">The keyfile size must be at least 64 bytes.</entry>
<entry lang="en" key="KEYFILE_EMPTY_BASE_NAME">Please enter a name for the keyfile(s) to be generated</entry>
<entry lang="en" key="KEYFILE_INVALID_BASE_NAME">The base name of the keyfile(s) is invalid</entry>
<entry lang="en" key="KEYFILE_ALREADY_EXISTS">The keyfile '%s' already exists.\nDo you want to overwrite it? The generation process will be stopped if you answer No.</entry>
diff --git a/src/Common/Resource.h b/src/Common/Resource.h
index a913bc26..c9142ece 100644
--- a/src/Common/Resource.h
+++ b/src/Common/Resource.h
@@ -224,6 +224,7 @@
#define IDC_BENCHMARK_PREBOOT 5140
#define IDD_TEXT_EDIT_DLG 5141
#define IDC_DISABLE_MOUNT_MANAGER 5142
+#define IDC_KEYFILES_SIZE_UNIT 5143
// Next default values for new objects
//
@@ -232,7 +233,7 @@
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 578
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 5143
+#define _APS_NEXT_CONTROL_VALUE 5144
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif