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

@ -987,7 +987,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
bool generated_something = false;
char num_keypad_key = '\0';
noise_ultralight(event->keyval);
noise_ultralight(NOISE_SOURCE_KEY, event->keyval);
#ifdef OSX_META_KEY_CONFIG
if (event->state & inst->system_mod_mask)
@ -2059,7 +2059,7 @@ static gboolean button_internal(GtkFrontend *inst, GdkEventButton *event)
/* Remember the timestamp. */
inst->input_event_time = event->time;
noise_ultralight(event->button);
noise_ultralight(NOISE_SOURCE_MOUSEBUTTON, event->button);
show_mouseptr(inst, true);
@ -2187,7 +2187,8 @@ gint motion_event(GtkWidget *widget, GdkEventMotion *event, gpointer data)
/* Remember the timestamp. */
inst->input_event_time = event->time;
noise_ultralight(((uint32_t)event->x << 16) | (uint32_t)event->y);
noise_ultralight(NOISE_SOURCE_MOUSEPOS,
((uint32_t)event->x << 16) | (uint32_t)event->y);
show_mouseptr(inst, true);

View File

@ -167,7 +167,7 @@ static int fdsocket_try_send(FdSocket *fds)
bufchain_prefix(&fds->pending_output_data, &data, &len);
ret = write(fds->outfd, data, len);
noise_ultralight(ret);
noise_ultralight(NOISE_SOURCE_IOID, ret);
if (ret < 0 && errno != EWOULDBLOCK) {
if (!fds->pending_error) {
fds->pending_error = errno;

View File

@ -1121,7 +1121,7 @@ void try_send(NetSocket *s)
bufchain_prefix(&s->output_data, &data, &len);
}
nsent = send(s->s, data, len, urgentflag);
noise_ultralight(nsent);
noise_ultralight(NOISE_SOURCE_IOLEN, nsent);
if (nsent <= 0) {
err = (nsent < 0 ? errno : 0);
if (err == EWOULDBLOCK) {
@ -1275,7 +1275,7 @@ static void net_select_result(int fd, int event)
if (!s)
return; /* boggle */
noise_ultralight(event);
noise_ultralight(NOISE_SOURCE_IOID, fd);
switch (event) {
case 4: /* exceptional */
@ -1287,7 +1287,7 @@ static void net_select_result(int fd, int event)
* type==2 (urgent data).
*/
ret = recv(s->s, buf, sizeof(buf), MSG_OOB);
noise_ultralight(ret);
noise_ultralight(NOISE_SOURCE_IOLEN, ret);
if (ret <= 0) {
plug_closing(s->plug,
ret == 0 ? "Internal networking trouble" :
@ -1370,7 +1370,7 @@ static void net_select_result(int fd, int event)
atmark = true;
ret = recv(s->s, buf, s->oobpending ? 1 : sizeof(buf), 0);
noise_ultralight(ret);
noise_ultralight(NOISE_SOURCE_IOLEN, ret);
if (ret < 0) {
if (errno == EWOULDBLOCK) {
break;

View File

@ -121,16 +121,16 @@ void noise_regular(void)
if ((fd = open("/proc/meminfo", O_RDONLY)) >= 0) {
while ( (ret = read(fd, buf, sizeof(buf))) > 0)
random_add_noise(buf, ret);
random_add_noise(NOISE_SOURCE_MEMINFO, buf, ret);
close(fd);
}
if ((fd = open("/proc/stat", O_RDONLY)) >= 0) {
while ( (ret = read(fd, buf, sizeof(buf))) > 0)
random_add_noise(buf, ret);
random_add_noise(NOISE_SOURCE_STAT, buf, ret);
close(fd);
}
getrusage(RUSAGE_SELF, &rusage);
random_add_noise(&rusage, sizeof(rusage));
random_add_noise(NOISE_SOURCE_RUSAGE, &rusage, sizeof(rusage));
}
/*
@ -138,10 +138,10 @@ void noise_regular(void)
* will add the current time to the noise pool. It gets the scan
* code or mouse position passed in, and adds that too.
*/
void noise_ultralight(unsigned long data)
void noise_ultralight(NoiseSourceId id, unsigned long data)
{
struct timeval tv;
gettimeofday(&tv, NULL);
random_add_noise(&tv, sizeof(tv));
random_add_noise(&data, sizeof(data));
random_add_noise(NOISE_SOURCE_TIME, &tv, sizeof(tv));
random_add_noise(id, &data, sizeof(data));
}

View File

@ -52,7 +52,7 @@ void uxsel_input_remove(uxsel_id *id) { }
*/
void random_save_seed(void) {}
void random_destroy_seed(void) {}
void noise_ultralight(unsigned long data) {}
void noise_ultralight(NoiseSourceId id, unsigned long data) {}
char *platform_default_s(const char *name) { return NULL; }
bool platform_default_b(const char *name, bool def) { return def; }
int platform_default_i(const char *name, int def) { return def; }

View File

@ -958,7 +958,7 @@ int main(int argc, char **argv)
if (backend_connected(backend)) {
ret = read(STDIN_FILENO, buf, sizeof(buf));
noise_ultralight(ret);
noise_ultralight(NOISE_SOURCE_IOLEN, ret);
if (ret < 0) {
perror("stdin: read");
exit(1);

View File

@ -15,7 +15,7 @@ const bool dup_check_launchable = false; /* no need to check host name
const bool use_pty_argv = true;
/* gtkwin.c will call this, and in pterm it's not needed */
void noise_ultralight(unsigned long data) { }
void noise_ultralight(NoiseSourceId id, unsigned long data) { }
const struct BackendVtable *select_backend(Conf *conf)
{

View File

@ -115,7 +115,7 @@ void select_result(int fd, int event)
{
struct fd *fdstruct = find234(fds, &fd, uxsel_fd_findcmp);
noise_ultralight(fd);
noise_ultralight(NOISE_SOURCE_IOID, fd);
/*
* Apparently this can sometimes be NULL. Can't see how, but I