1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 09:58:01 +00:00

Windows PuTTYgen: make state->entropy into a strbuf.

This offloads the memory management into centralised code which is
better at it than the ad-hoc code here. Now I don't have to predict in
advance how much memory the entropy will consume, and can change that
decision on the fly.
This commit is contained in:
Simon Tatham 2022-01-08 11:20:27 +00:00
parent 498c0a3abc
commit 9529769b60

View File

@ -633,7 +633,8 @@ struct MainDlgState {
bool collecting_entropy; bool collecting_entropy;
bool generation_thread_exists; bool generation_thread_exists;
bool key_exists; bool key_exists;
int entropy_got, entropy_required, entropy_size; int entropy_got, entropy_required;
strbuf *entropy;
int key_bits, curve_bits; int key_bits, curve_bits;
bool ssh2; bool ssh2;
keytype keytype; keytype keytype;
@ -642,7 +643,6 @@ struct MainDlgState {
FingerprintType fptype; FingerprintType fptype;
char **commentptr; /* points to key.comment or ssh2key.comment */ char **commentptr; /* points to key.comment or ssh2key.comment */
ssh2_userkey ssh2key; ssh2_userkey ssh2key;
unsigned *entropy;
union { union {
RSAKey key; RSAKey key;
struct dsa_key dsakey; struct dsa_key dsakey;
@ -1409,18 +1409,17 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg,
state = (struct MainDlgState *) GetWindowLongPtr(hwnd, GWLP_USERDATA); state = (struct MainDlgState *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
if (state->collecting_entropy && if (state->collecting_entropy &&
state->entropy && state->entropy_got < state->entropy_required) { state->entropy && state->entropy_got < state->entropy_required) {
state->entropy[state->entropy_got++] = lParam; put_uint32(state->entropy, lParam);
state->entropy[state->entropy_got++] = GetMessageTime(); put_uint32(state->entropy, GetMessageTime());
state->entropy_got += 2;
SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS, SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS,
state->entropy_got, 0); state->entropy_got, 0);
if (state->entropy_got >= state->entropy_required) { if (state->entropy_got >= state->entropy_required) {
/* /*
* Seed the entropy pool * Seed the entropy pool
*/ */
random_reseed( random_reseed(ptrlen_from_strbuf(state->entropy));
make_ptrlen(state->entropy, state->entropy_size)); strbuf_free(state->entropy);
smemclr(state->entropy, state->entropy_size);
sfree(state->entropy);
state->collecting_entropy = false; state->collecting_entropy = false;
start_generating_key(hwnd, state); start_generating_key(hwnd, state);
@ -1638,9 +1637,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg,
state->collecting_entropy = true; state->collecting_entropy = true;
state->entropy_got = 0; state->entropy_got = 0;
state->entropy_size = (state->entropy_required * state->entropy = strbuf_new_nm();
sizeof(unsigned));
state->entropy = snewn(state->entropy_required, unsigned);
SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0, SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0,
MAKELPARAM(0, state->entropy_required)); MAKELPARAM(0, state->entropy_required));