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.
This commit is contained in:
Simon Tatham 2020-09-13 08:32:19 +01:00
Родитель 132d48b8f3
Коммит 3daa36293e
2 изменённых файлов: 11 добавлений и 6 удалений

11
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);

Просмотреть файл

@ -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)