From 3daa36293ee2709e90578ae2277bf4f5532c63e8 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 13 Sep 2020 08:32:19 +0100 Subject: [PATCH] Remove dependency of sshrand.c on SHA-512. Rather like some of the tricks I did in mpint.h, this replaces the unparametrised function random_setup_special() with one called random_setup_custom() taking a hash-algorithm parameter. The old syntax random_setup_special() still exists, and is a macro wrapper on random_setup_custom() that passes ssh_sha512 as an argument. This means I can keep the choice of hash function consistent between the key generation front ends. This adds potential flexibility: now, anyone wanting a different kind of special RNG can make it out of whatever primitive they like. But a more immediate point is to remove an inter-module dependency: sshrand.c now doesn't need to be linked against the SHA-512 code. --- putty.h | 11 ++++++++--- sshrand.c | 6 +++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/putty.h b/putty.h index 46c4e54e..ca8ee4a5 100644 --- a/putty.h +++ b/putty.h @@ -1818,9 +1818,14 @@ void random_unref(void); * logical main() no matter whether it needed random numbers or * not. */ void random_clear(void); -/* random_setup_special is used by PuTTYgen. It makes an extra-big - * random number generator. */ -void random_setup_special(void); +/* random_setup_custom sets up the process-global random number + * generator specially, with a hash function of your choice. */ +void random_setup_custom(const ssh_hashalg *hash); +/* random_setup_special() is a macro wrapper on that, which makes an + * extra-big one based on SHA-512. It's defined this way to avoid what + * would otherwise be an unnecessary module dependency from sshrand.c + * to sshsh512.c. */ +#define random_setup_special() random_setup_custom(&ssh_sha512) /* Manually drop a random seed into the random number generator, e.g. * just before generating a key. */ void random_reseed(ptrlen seed); diff --git a/sshrand.c b/sshrand.c index 387a068a..7f3d6411 100644 --- a/sshrand.c +++ b/sshrand.c @@ -19,7 +19,7 @@ int random_active = 0; */ void random_add_noise(NoiseSourceId source, const void *noise, int length) { } void random_ref(void) { } -void random_setup_special(void) { } +void random_setup_custom(const ssh_hashalg *hash) { } void random_unref(void) { } void random_read(void *out, size_t size) { @@ -97,10 +97,10 @@ void random_ref(void) random_create(&ssh_sha256); } -void random_setup_special() +void random_setup_custom(const ssh_hashalg *hash) { random_active++; - random_create(&ssh_sha512); + random_create(hash); } void random_reseed(ptrlen seed)