1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-04-18 03:28:07 -05:00

Windows PuTTYgen: remove state->collecting_entropy.

There's no point having a separate boolean flag. All we have to do is
remember to NULL out the strbuf point state->entropy when we free the
strbuf (which is a good idea in any case!), and then we can use the
non-NULL-ness of that pointer as the indicator that we're currently
collecting entropy.
This commit is contained in:
Simon Tatham 2022-01-08 11:23:46 +00:00
parent 9529769b60
commit e7a695103f

View File

@ -630,7 +630,6 @@ static DWORD WINAPI generate_key_thread(void *param)
} }
struct MainDlgState { struct MainDlgState {
bool collecting_entropy;
bool generation_thread_exists; bool generation_thread_exists;
bool key_exists; bool key_exists;
int entropy_got, entropy_required; int entropy_got, entropy_required;
@ -1200,7 +1199,6 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg,
state = snew(struct MainDlgState); state = snew(struct MainDlgState);
state->generation_thread_exists = false; state->generation_thread_exists = false;
state->collecting_entropy = false;
state->entropy = NULL; state->entropy = NULL;
state->key_exists = false; state->key_exists = false;
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR) state); SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR) state);
@ -1407,8 +1405,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg,
return 1; return 1;
case WM_MOUSEMOVE: case WM_MOUSEMOVE:
state = (struct MainDlgState *) GetWindowLongPtr(hwnd, GWLP_USERDATA); state = (struct MainDlgState *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
if (state->collecting_entropy && if (state->entropy && state->entropy_got < state->entropy_required) {
state->entropy && state->entropy_got < state->entropy_required) {
put_uint32(state->entropy, lParam); put_uint32(state->entropy, lParam);
put_uint32(state->entropy, GetMessageTime()); put_uint32(state->entropy, GetMessageTime());
state->entropy_got += 2; state->entropy_got += 2;
@ -1420,7 +1417,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg,
*/ */
random_reseed(ptrlen_from_strbuf(state->entropy)); random_reseed(ptrlen_from_strbuf(state->entropy));
strbuf_free(state->entropy); strbuf_free(state->entropy);
state->collecting_entropy = false; state->entropy = NULL;
start_generating_key(hwnd, state); start_generating_key(hwnd, state);
} }
@ -1634,7 +1631,6 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg,
ui_set_state(hwnd, state, 1); ui_set_state(hwnd, state, 1);
SetDlgItemText(hwnd, IDC_GENERATING, entropy_msg); SetDlgItemText(hwnd, IDC_GENERATING, entropy_msg);
state->key_exists = false; state->key_exists = false;
state->collecting_entropy = true;
state->entropy_got = 0; state->entropy_got = 0;
state->entropy = strbuf_new_nm(); state->entropy = strbuf_new_nm();