+ state->is_dsa = IsDlgButtonChecked(hwnd, IDC_KEYSSH2DSA);
+ if (state->keysize < 256) {
+ int ret = MessageBox(hwnd,
+ "PuTTYgen will not generate a key"
+ " smaller than 256 bits.\n"
+ "Key length reset to 256. Continue?",
+ "PuTTYgen Warning",
+ MB_ICONWARNING | MB_OKCANCEL);
+ if (ret != IDOK)
+ break;
+ state->keysize = 256;
+ SetDlgItemInt(hwnd, IDC_BITS, 256, FALSE);
+ }
+ hidemany(hwnd, nokey_ids, TRUE);
+ hidemany(hwnd, generating_ids, FALSE);
+ hidemany(hwnd, gotkey_ids, TRUE);
+ EnableWindow(GetDlgItem(hwnd, IDC_GENERATE), 0);
+ EnableWindow(GetDlgItem(hwnd, IDC_LOAD), 0);
+ EnableWindow(GetDlgItem(hwnd, IDC_SAVE), 0);
+ EnableWindow(GetDlgItem(hwnd, IDC_SAVEPUB), 0);
+ EnableWindow(GetDlgItem(hwnd, IDC_KEYSSH1), 0);
+ EnableWindow(GetDlgItem(hwnd, IDC_KEYSSH2RSA), 0);
+ EnableWindow(GetDlgItem(hwnd, IDC_KEYSSH2DSA), 0);
+ EnableWindow(GetDlgItem(hwnd, IDC_BITS), 0);
+ state->key_exists = FALSE;
+ SetDlgItemText(hwnd, IDC_GENERATING, entropy_msg);
+ state->collecting_entropy = TRUE;
+
+ /*
+ * My brief statistical tests on mouse movements
+ * suggest that there are about 2.5 bits of
+ * randomness in the x position, 2.5 in the y
+ * position, and 1.7 in the message time, making
+ * 5.7 bits of unpredictability per mouse movement.
+ * However, other people have told me it's far less
+ * than that, so I'm going to be stupidly cautious
+ * and knock that down to a nice round 2. With this
+ * method, we require two words per mouse movement,
+ * so with 2 bits per mouse movement we expect 2
+ * bits every 2 words.
+ */
+ state->entropy_required = (state->keysize / 2) * 2;
+ state->entropy_got = 0;
+ state->entropy_size = (state->entropy_required *
+ sizeof(*state->entropy));
+ state->entropy = smalloc(state->entropy_size);
+
+ SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0,
+ MAKELPARAM(0, state->entropy_required));
+ SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS, 0, 0);
+ }
+ break;
+ case IDC_SAVE:
+ case IDC_EXPORT_OPENSSH:
+ case IDC_EXPORT_SSHCOM:
+ state =
+ (struct MainDlgState *) GetWindowLong(hwnd, GWL_USERDATA);
+ if (state->key_exists) {
+ char filename[FILENAME_MAX];
+ char passphrase[PASSPHRASE_MAXLEN];
+ char passphrase2[PASSPHRASE_MAXLEN];
+ int type, realtype;
+
+ if (state->ssh2)
+ realtype = SSH_KEYTYPE_SSH2;
+ else
+ realtype = SSH_KEYTYPE_SSH1;
+
+ if (LOWORD(wParam) == IDC_EXPORT_OPENSSH)
+ type = SSH_KEYTYPE_OPENSSH;
+ else if (LOWORD(wParam) == IDC_EXPORT_SSHCOM)
+ type = SSH_KEYTYPE_SSHCOM;
+ else
+ type = realtype;
+
+ if (type != realtype &&
+ import_target_type(type) != realtype) {
+ char msg[256];
+ sprintf(msg, "Cannot export an SSH%d key in an SSH%d"
+ " format", (state->ssh2 ? 2 : 1),
+ (state->ssh2 ? 1 : 2));
+ MessageBox(hwnd, msg,
+ "PuTTYgen Error", MB_OK | MB_ICONERROR);
+ break;