Fix _rs_init split in half during merge (#734)

This commit is contained in:
LexaPrime 2024-07-22 22:27:38 +02:00 committed by GitHub
parent 661803c9ec
commit e829ad267c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 8 deletions

View File

@ -97,6 +97,14 @@ _rs_init(u_char *buf, size_t n)
{
if (n < KEYSZ + IVSZ)
return;
if (rs == NULL) {
if (_rs_allocate(&rs, &rsx) == -1)
_exit(1);
}
chacha_keysetup(&rsx->rs_chacha, buf, KEYSZ * 8);
chacha_ivsetup(&rsx->rs_chacha, buf + KEYSZ);
}
#ifndef WITH_OPENSSL
@ -135,14 +143,18 @@ getrnd(u_char *s, size_t len)
return;
fatal("Couldn't open %s: %s", SSH_RANDOM_DEV,
strerror(save_errno));
if (rs == NULL) {
if (_rs_allocate(&rs, &rsx) == -1)
_exit(1);
}
chacha_keysetup(&rsx->rs_chacha, buf, KEYSZ * 8);
chacha_ivsetup(&rsx->rs_chacha, buf + KEYSZ);
while (o < len) {
r = read(fd, s + o, len - o);
if (r < 0) {
if (errno == EAGAIN || errno == EINTR ||
errno == EWOULDBLOCK)
continue;
fatal("read %s: %s", SSH_RANDOM_DEV, strerror(errno));
}
o += r;
}
close(fd);
}
#endif /* !WINDOWS */
#endif /* WITH_OPENSSL */
@ -290,4 +302,4 @@ arc4random_buf(void *_buf, size_t n)
}
explicit_bzero(&r, sizeof(r));
}
#endif /* !defined(HAVE_ARC4RANDOM_BUF) && defined(HAVE_ARC4RANDOM) */
#endif /* !defined(HAVE_ARC4RANDOM_BUF) && defined(HAVE_ARC4RANDOM) */