X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/0c2986d033e11b811c34221a1fd4db3c9bc095e5..b8957e432baa265e13e3acc12faefd92c60c8a5f:/puttygen.c diff --git a/puttygen.c b/puttygen.c index 46815d6f..4fae90cd 100644 --- a/puttygen.c +++ b/puttygen.c @@ -5,10 +5,8 @@ #include #include #include -#ifndef NO_SECURITY -#include -#endif #include +#include #define PUTTY_DO_GLOBALS @@ -20,11 +18,6 @@ #define DEFAULT_KEYSIZE 1024 -/* - * TODO: - * - test the generated keys for actual working-RSA-key-hood - */ - /* ---------------------------------------------------------------------- * Progress report code. This is really horrible :-) */ @@ -322,13 +315,15 @@ static int CALLBACK MainDlgProc (HWND hwnd, UINT msg, static const char generating_msg[] = "Please wait while a key is generated..."; static const char entropy_msg[] = - "Please move the mouse in this window to generate randomness"; + "Please generate some randomness by moving the mouse over the blank area."; struct MainDlgState *state; switch (msg) { case WM_INITDIALOG: state = malloc(sizeof(*state)); state->generation_thread_exists = FALSE; + state->collecting_entropy = FALSE; + state->entropy = NULL; state->key_exists = FALSE; SetWindowLong(hwnd, GWL_USERDATA, (LONG)state); { @@ -370,9 +365,9 @@ static int CALLBACK MainDlgProc (HWND hwnd, UINT msg, 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); - staticedit(&cp, "Length of generated keys in &bits:", + beginbox(&cp, "Parameters", + IDC_BOX_PARAMS, IDC_BOXT_PARAMS); + staticedit(&cp, "Number of &bits in a generated key:", IDC_BITSSTATIC, IDC_BITS, 20); endbox(&cp); } @@ -392,7 +387,9 @@ static int CALLBACK MainDlgProc (HWND hwnd, UINT msg, 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, @@ -407,6 +404,7 @@ static int CALLBACK MainDlgProc (HWND hwnd, UINT msg, random_add_heavynoise(state->entropy, state->entropy_size); memset(state->entropy, 0, state->entropy_size); free(state->entropy); + state->collecting_entropy = FALSE; SetDlgItemText(hwnd, IDC_GENERATING, generating_msg); SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0, @@ -428,7 +426,6 @@ static int CALLBACK MainDlgProc (HWND hwnd, UINT msg, free(params); } else { state->generation_thread_exists = TRUE; - state->collecting_entropy = FALSE; } } } @@ -476,16 +473,18 @@ static int CALLBACK MainDlgProc (HWND hwnd, UINT msg, /* * My brief statistical tests on mouse movements - * suggest that there are about 5 bits of - * randomness in the x position, 5 in the y + * 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 - * 11.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 4. + * 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 / 4) * 2; + state->entropy_required = (state->keysize/2) * 2; state->entropy_got = 0; state->entropy_size = (state->entropy_required * sizeof(*state->entropy));