mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 03:22:48 -05:00
Replace random_byte() with random_read().
This is in preparation for a PRNG revamp which will want to have a well defined boundary for any given request-for-randomness, so that it can destroy the evidence afterwards. So no more looping round calling random_byte() and then stopping when we feel like it: now you say up front how many random bytes you want, and call random_read() which gives you that many in one go. Most of the call sites that had to be fixed are fairly mechanical, and quite a few ended up more concise afterwards. A few became more cumbersome, such as mp_random_bits, in which the new API doesn't let me load the random bytes directly into the target integer without triggering undefined behaviour, so instead I have to allocate a separate temporary buffer. The _most_ interesting call site was in the PKCS#1 v1.5 padding code in sshrsa.c (used in SSH-1), in which you need a stream of _nonzero_ random bytes. The previous code just looped on random_byte, retrying if it got a zero. Now I'm doing a much more interesting thing with an mpint, essentially scaling a binary fraction repeatedly to extract a number in the range [0,255) and then adding 1 to it.
This commit is contained in:
@ -58,7 +58,6 @@ static int uss_dirhandle_cmp(void *av, void *bv)
|
||||
|
||||
static SftpServer *uss_new(const SftpServerVtable *vt)
|
||||
{
|
||||
int i;
|
||||
UnixSftpServer *uss = snew(UnixSftpServer);
|
||||
|
||||
memset(uss, 0, sizeof(UnixSftpServer));
|
||||
@ -66,8 +65,7 @@ static SftpServer *uss_new(const SftpServerVtable *vt)
|
||||
uss->dirhandles = newtree234(uss_dirhandle_cmp);
|
||||
uss->srv.vt = vt;
|
||||
|
||||
for (i = 0; i < lenof(uss->handlekey); i++)
|
||||
uss->handlekey[i] = random_byte();
|
||||
random_read(uss->handlekey, sizeof(uss->handlekey));
|
||||
|
||||
return &uss->srv;
|
||||
}
|
||||
|
@ -116,9 +116,7 @@ static char *make_dirname(const char *pi_name, char **logtext)
|
||||
/*
|
||||
* Invent some random data.
|
||||
*/
|
||||
for (i = 0; i < SALT_SIZE; i++) {
|
||||
saltbuf[i] = random_byte();
|
||||
}
|
||||
random_read(saltbuf, SALT_SIZE);
|
||||
ret = write(saltfd, saltbuf, SALT_SIZE);
|
||||
/* POSIX atomicity guarantee: because we wrote less than
|
||||
* PIPE_BUF bytes, the write either completed in full or
|
||||
|
Reference in New Issue
Block a user