#include <windows.h>
#include <commctrl.h>
#include <time.h>
-#ifndef NO_SECURITY
-#include <aclapi.h>
-#endif
#include <stdio.h>
+#include <stdlib.h>
#define PUTTY_DO_GLOBALS
#define DEFAULT_KEYSIZE 1024
-/*
- * TODO:
- * - test the generated keys for actual working-RSA-key-hood
- */
-
/* ----------------------------------------------------------------------
* Progress report code. This is really horrible :-)
*/
PostMessage(params->dialog, WM_DONEKEY, 0, 0);
- free(params);
+ sfree(params);
return 0;
}
dec1 = bignum_decimal(key->exponent);
dec2 = bignum_decimal(key->modulus);
- buffer = malloc(strlen(dec1)+strlen(dec2)+
- strlen(key->comment)+30);
+ buffer = smalloc(strlen(dec1)+strlen(dec2)+
+ strlen(key->comment)+30);
sprintf(buffer, "%d %s %s %s",
ssh1_bignum_bitcount(key->modulus),
dec1, dec2, key->comment);
SetDlgItemText(hwnd, id, buffer);
- free(dec1);
- free(dec2);
- free(buffer);
+ sfree(dec1);
+ sfree(dec2);
+ sfree(buffer);
}
/*
enum {
controlidstart = 100,
IDC_TITLE,
- IDC_BOX_KEY, IDC_BOXT_KEY,
+ IDC_BOX_KEY,
IDC_NOKEY,
IDC_GENERATING,
IDC_PROGRESS,
IDC_COMMENTSTATIC, IDC_COMMENTEDIT,
IDC_PASSPHRASE1STATIC, IDC_PASSPHRASE1EDIT,
IDC_PASSPHRASE2STATIC, IDC_PASSPHRASE2EDIT,
- IDC_BOX_ACTIONS, IDC_BOXT_ACTIONS,
+ IDC_BOX_ACTIONS,
IDC_GENSTATIC, IDC_GENERATE,
IDC_LOADSTATIC, IDC_LOAD,
IDC_SAVESTATIC, IDC_SAVE,
- IDC_BOX_PARAMS, IDC_BOXT_PARAMS,
+ IDC_BOX_PARAMS,
IDC_BITSSTATIC, IDC_BITS,
IDC_ABOUT,
};
switch (msg) {
case WM_INITDIALOG:
- state = malloc(sizeof(*state));
+ state = smalloc(sizeof(*state));
state->generation_thread_exists = FALSE;
+ state->collecting_entropy = FALSE;
+ state->entropy = NULL;
state->key_exists = FALSE;
SetWindowLong(hwnd, GWL_USERDATA, (LONG)state);
{
bartitle(&cp, "Public and private key generation for PuTTY",
IDC_TITLE);
beginbox(&cp, "Key",
- IDC_BOX_KEY, IDC_BOXT_KEY);
+ IDC_BOX_KEY);
cp2 = cp;
statictext(&cp2, "No key.", IDC_NOKEY);
cp2 = cp;
IDC_PASSPHRASE2EDIT, 70);
endbox(&cp);
beginbox(&cp, "Actions",
- IDC_BOX_ACTIONS, IDC_BOXT_ACTIONS);
+ IDC_BOX_ACTIONS);
staticbtn(&cp, "Generate a public/private key pair",
IDC_GENSTATIC, "&Generate", IDC_GENERATE);
staticbtn(&cp, "Load an existing private key file",
staticbtn(&cp, "Save the generated key to a new file",
IDC_SAVESTATIC, "&Save", IDC_SAVE);
endbox(&cp);
- beginbox(&cp, "Actions",
- IDC_BOX_ACTIONS, IDC_BOXT_ACTIONS);
+ beginbox(&cp, "Parameters",
+ IDC_BOX_PARAMS);
staticedit(&cp, "Number of &bits in a generated key:",
IDC_BITSSTATIC, IDC_BITS, 20);
endbox(&cp);
return 1;
case WM_MOUSEMOVE:
state = (struct MainDlgState *)GetWindowLong(hwnd, GWL_USERDATA);
- if (state->collecting_entropy) {
+ if (state->collecting_entropy &&
+ state->entropy &&
+ state->entropy_got < state->entropy_required) {
state->entropy[state->entropy_got++] = lParam;
state->entropy[state->entropy_got++] = GetMessageTime();
SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS,
*/
random_add_heavynoise(state->entropy, state->entropy_size);
memset(state->entropy, 0, state->entropy_size);
- free(state->entropy);
+ sfree(state->entropy);
+ state->collecting_entropy = FALSE;
SetDlgItemText(hwnd, IDC_GENERATING, generating_msg);
SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0,
MAKELPARAM(0, PROGRESSRANGE));
SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS, 0, 0);
- params = malloc(sizeof(*params));
+ params = smalloc(sizeof(*params));
params->progressbar = GetDlgItem(hwnd, IDC_PROGRESS);
params->dialog = hwnd;
params->keysize = state->keysize;
MessageBox(hwnd, "Out of thread resources",
"Key generation error",
MB_OK | MB_ICONERROR);
- free(params);
+ sfree(params);
} else {
state->generation_thread_exists = TRUE;
- state->collecting_entropy = FALSE;
}
}
}
HWND editctl = GetDlgItem(hwnd, IDC_COMMENTEDIT);
int len = GetWindowTextLength(editctl);
if (state->key.comment)
- free(state->key.comment);
- state->key.comment = malloc(len+1);
+ sfree(state->key.comment);
+ state->key.comment = smalloc(len+1);
GetWindowText(editctl, state->key.comment, len+1);
}
}
case IDC_GENERATE:
state = (struct MainDlgState *)GetWindowLong(hwnd, GWL_USERDATA);
if (!state->generation_thread_exists) {
+ BOOL ok;
+ state->keysize = GetDlgItemInt(hwnd, IDC_BITS,
+ &ok, FALSE);
+ if (!ok) state->keysize = DEFAULT_KEYSIZE;
+ 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);
state->key_exists = FALSE;
SetDlgItemText(hwnd, IDC_GENERATING, entropy_msg);
state->collecting_entropy = TRUE;
- {
- BOOL ok;
- state->keysize = GetDlgItemInt(hwnd, IDC_BITS,
- &ok, FALSE);
- if (!ok) state->keysize = DEFAULT_KEYSIZE;
- }
/*
* My brief statistical tests on mouse movements
state->entropy_got = 0;
state->entropy_size = (state->entropy_required *
sizeof(*state->entropy));
- state->entropy = malloc(state->entropy_size);
+ state->entropy = smalloc(state->entropy_size);
SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0,
MAKELPARAM(0, state->entropy_required));
ret = loadrsakey(filename, &newkey, &newaux,
passphrase);
} while (ret == -1);
- if (comment) free(comment);
+ if (comment) sfree(comment);
if (ret == 0) {
MessageBox(NULL, "Couldn't load private key.",
"PuTTYgen Error", MB_OK | MB_ICONERROR);
* the user will immediately want to change it, which is
* what we want :-)
*/
- state->key.comment = malloc(30);
+ state->key.comment = smalloc(30);
{
time_t t;
struct tm *tm;
break;
case WM_CLOSE:
state = (struct MainDlgState *)GetWindowLong(hwnd, GWL_USERDATA);
- free(state);
+ sfree(state);
EndDialog(hwnd, 1);
return 0;
}