1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 11:32:48 -05:00

Label random-noise sources with an enum of ids.

The upcoming PRNG revamp will want to tell noise sources apart, so
that it can treat them all fairly. So I've added an extra parameter to
noise_ultralight and random_add_noise, which takes values in an
enumeration covering all the vague classes of entropy source I'm
collecting. In this commit, though, it's simply ignored.
This commit is contained in:
Simon Tatham
2019-01-22 18:25:54 +00:00
parent 628e794832
commit 5087792440
17 changed files with 66 additions and 47 deletions

View File

@ -2696,7 +2696,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
* Add the mouse position and message time to the random
* number noise.
*/
noise_ultralight(lParam);
noise_ultralight(NOISE_SOURCE_MOUSEPOS, lParam);
if (wParam & (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON) &&
GetCapture() == hwnd) {
@ -2724,7 +2724,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
last_mousemove = WM_NCMOUSEMOVE;
}
}
noise_ultralight(lParam);
noise_ultralight(NOISE_SOURCE_MOUSEPOS, lParam);
break;
case WM_IGNORE_CLIP:
ignore_clip = wParam; /* don't panic on DESTROYCLIPBOARD */
@ -3179,7 +3179,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
* Add the scan code and keypress timing to the random
* number noise.
*/
noise_ultralight(lParam);
noise_ultralight(NOISE_SOURCE_KEY, lParam);
/*
* We don't do TranslateMessage since it disassociates the

View File

@ -689,7 +689,7 @@ void handle_got_event(HANDLE event)
h->u.o.sentdata(h, -h->u.o.writeerr);
} else {
bufchain_consume(&h->u.o.queued_data, h->u.o.lenwritten);
noise_ultralight(h->u.o.lenwritten);
noise_ultralight(NOISE_SOURCE_IOLEN, h->u.o.lenwritten);
h->u.o.sentdata(h, bufchain_size(&h->u.o.queued_data));
handle_try_output(&h->u.o);
}

View File

@ -1387,7 +1387,7 @@ void try_send(NetSocket *s)
bufchain_prefix(&s->output_data, &data, &len);
}
nsent = p_send(s->s, data, len, urgentflag);
noise_ultralight(nsent);
noise_ultralight(NOISE_SOURCE_IOLEN, nsent);
if (nsent <= 0) {
err = (nsent < 0 ? p_WSAGetLastError() : 0);
if ((err < WSABASEERR && nsent < 0) || err == WSAEWOULDBLOCK) {
@ -1538,7 +1538,7 @@ void select_result(WPARAM wParam, LPARAM lParam)
return;
}
noise_ultralight(lParam);
noise_ultralight(NOISE_SOURCE_IOID, wParam);
switch (WSAGETSELECTEVENT(lParam)) {
case FD_CONNECT:
@ -1582,7 +1582,7 @@ void select_result(WPARAM wParam, LPARAM lParam)
atmark = true;
ret = p_recv(s->s, buf, sizeof(buf), 0);
noise_ultralight(ret);
noise_ultralight(NOISE_SOURCE_IOLEN, ret);
if (ret < 0) {
err = p_WSAGetLastError();
if (err == WSAEWOULDBLOCK) {
@ -1605,7 +1605,7 @@ void select_result(WPARAM wParam, LPARAM lParam)
* end with type==2 (urgent data).
*/
ret = p_recv(s->s, buf, sizeof(buf), MSG_OOB);
noise_ultralight(ret);
noise_ultralight(NOISE_SOURCE_IOLEN, ret);
if (ret <= 0) {
int err = p_WSAGetLastError();
plug_closing(s->plug, winsock_error_string(err), err, 0);

View File

@ -122,26 +122,26 @@ void noise_regular(void)
FILETIME times[4];
w = GetForegroundWindow();
random_add_noise(&w, sizeof(w));
random_add_noise(NOISE_SOURCE_FGWINDOW, &w, sizeof(w));
w = GetCapture();
random_add_noise(&w, sizeof(w));
random_add_noise(NOISE_SOURCE_CAPTURE, &w, sizeof(w));
w = GetClipboardOwner();
random_add_noise(&w, sizeof(w));
random_add_noise(NOISE_SOURCE_CLIPBOARD, &w, sizeof(w));
z = GetQueueStatus(QS_ALLEVENTS);
random_add_noise(&z, sizeof(z));
random_add_noise(NOISE_SOURCE_QUEUE, &z, sizeof(z));
GetCursorPos(&pt);
random_add_noise(&pt, sizeof(pt));
random_add_noise(NOISE_SOURCE_CURSORPOS, &pt, sizeof(pt));
GlobalMemoryStatus(&memstat);
random_add_noise(&memstat, sizeof(memstat));
random_add_noise(NOISE_SOURCE_MEMINFO, &memstat, sizeof(memstat));
GetThreadTimes(GetCurrentThread(), times, times + 1, times + 2,
times + 3);
random_add_noise(&times, sizeof(times));
random_add_noise(NOISE_SOURCE_THREADTIME, &times, sizeof(times));
GetProcessTimes(GetCurrentProcess(), times, times + 1, times + 2,
times + 3);
random_add_noise(&times, sizeof(times));
random_add_noise(NOISE_SOURCE_PROCTIME, &times, sizeof(times));
}
/*
@ -150,16 +150,16 @@ void noise_regular(void)
* counter to the noise pool. It gets the scan code or mouse
* position passed in.
*/
void noise_ultralight(unsigned long data)
void noise_ultralight(NoiseSourceId id, unsigned long data)
{
DWORD wintime;
LARGE_INTEGER perftime;
random_add_noise(&data, sizeof(DWORD));
random_add_noise(id, &data, sizeof(DWORD));
wintime = GetTickCount();
random_add_noise(&wintime, sizeof(DWORD));
random_add_noise(NOISE_SOURCE_TIME, &wintime, sizeof(DWORD));
if (QueryPerformanceCounter(&perftime))
random_add_noise(&perftime, sizeof(perftime));
random_add_noise(NOISE_SOURCE_PERFCOUNT, &perftime, sizeof(perftime));
}

View File

@ -220,7 +220,7 @@ int stdin_gotdata(struct handle *h, void *data, int len)
fprintf(stderr, "Unable to read from standard input: %s\n", buf);
cleanup_exit(0);
}
noise_ultralight(len);
noise_ultralight(NOISE_SOURCE_IOLEN, len);
if (backend_connected(backend)) {
if (len > 0) {
return backend_send(backend, data, len);
@ -574,8 +574,7 @@ int main(int argc, char **argv)
};
int e;
noise_ultralight(socket);
noise_ultralight(things.lNetworkEvents);
noise_ultralight(NOISE_SOURCE_IOID, socket);
for (e = 0; e < lenof(eventtypes); e++)
if (things.lNetworkEvents & eventtypes[e].mask) {

View File

@ -578,8 +578,7 @@ int do_eventsel_loop(HANDLE other_event)
};
int e;
noise_ultralight(socket);
noise_ultralight(things.lNetworkEvents);
noise_ultralight(NOISE_SOURCE_IOID, socket);
for (e = 0; e < lenof(eventtypes); e++)
if (things.lNetworkEvents & eventtypes[e].mask) {