diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Common/Common.rc | 15 | ||||
-rw-r--r-- | src/Common/Dlgcode.c | 73 | ||||
-rw-r--r-- | src/Common/Language.xml | 4 | ||||
-rw-r--r-- | src/Common/Resource.h | 3 |
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 @@ -210,9 +210,9 @@ BEGIN PUSHBUTTON "&Print",IDC_PRINT,156,200,58,14 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 BEGIN @@ -220,20 +220,21 @@ BEGIN COMBOBOX IDC_PRF_ID,97,49,91,90,CBS_DROPDOWNLIST | WS_TABSTOP 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 @@ -423,9 +424,9 @@ BEGIN IDD_KEYFILE_GENERATOR, DIALOG BEGIN LEFTMARGIN, 7 TOPMARGIN, 7 - BOTTOMMARGIN, 358 + BOTTOMMARGIN, 365 END IDD_MULTI_CHOICE_DLG, DIALOG BEGIN 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 @@ -7166,8 +7166,9 @@ 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)); VirtualLock (lastRandPool, sizeof(lastRandPool)); @@ -7195,8 +7196,18 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP AddComboPair (hComboBox, HashGetName(hid), hid); } 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); SendMessage (hEntropyBar, PBM_SETSTEP, 1, 0); @@ -7302,8 +7313,9 @@ 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) { @@ -7312,9 +7324,12 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP wchar_t szDirName[TC_MAX_PATH]; 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); @@ -7334,14 +7349,25 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP if (!GetWindowText(GetDlgItem (hwndDlg, IDC_KEYFILES_SIZE), szNumber, ARRAYSIZE(szNumber))) 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)) szFileBaseName[0] = 0; @@ -7371,9 +7397,9 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP StringCbCat(szDirName, sizeof(szDirName), L"\\"); 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++) { StringCbCopyW(szFileName, sizeof(szFileName), szDirName); @@ -7434,34 +7460,47 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP NormalCursor(); 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 @@ -355,9 +355,9 @@ <entry lang="en" key="IDT_KEYFILE_GENERATOR_NOTE">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.</entry> <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> <entry lang="en" key="IDT_PLAINTEXT_SIZE_UNIT">bits</entry> @@ -937,9 +937,9 @@ <entry lang="en" key="ENTER_HIDDEN_VOL_PASSWORD">Enter password for the hidden volume</entry> <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> <entry lang="en" key="HEADER_DAMAGED_AUTO_USED_HEADER_BAK">WARNING: The header of this volume is damaged! VeraCrypt automatically used the backup of the volume header embedded in the volume.\n\nYou should repair the volume header by selecting 'Tools' > 'Restore Volume Header'.</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 @@ -223,16 +223,17 @@ #define IDC_BENCHMARK_LIST 5139 #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 // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #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 |