From 52fa23c7fe7c8b6448b396acc6fc8013b030918a Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 9 Apr 2021 17:48:28 +0100 Subject: [PATCH] Argon2 hprime: remove pointless bounds check. Coverity points out that we don't need to check the output buffer bound before writing out the first 32 bytes of each full-length BLAKE2b invocation, because the only time we're doing a full-length one in the first place is if the output buffer bound was at least 64 bytes. (More specifically: whenever we're in the while loop, length > 64, so setting chunk = 32 and then checking if chunk > length has a totally predictable answer.) --- sshargon2.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/sshargon2.c b/sshargon2.c index 08875ee5..25385d7e 100644 --- a/sshargon2.c +++ b/sshargon2.c @@ -66,12 +66,9 @@ static void hprime_final(ssh_hash *h, unsigned length, void *vout) uint8_t hashbuf[64]; ssh_hash_final(h, hashbuf); - unsigned chunk = 32; - if (chunk > length) - chunk = length; - memcpy(out, hashbuf, chunk); - out += chunk; - length -= chunk; + memcpy(out, hashbuf, 32); + out += 32; + length -= 32; h = blake2b_new_general(length > 64 ? 64 : length); put_data(h, hashbuf, 64);