diff options
author | Mattias Andrée <maandree@kth.se> | 2022-02-14 21:25:06 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2022-02-14 21:25:06 +0100 |
commit | ea7d8f4a919bf6c9e68ea4a55ef763c310ecfc9b (patch) | |
tree | 416ad9e2f06aef594714b06a91f7f379d1766749 /libar2_hash_buf_size.c | |
parent | Fix previous commit (diff) | |
download | libar2-ea7d8f4a919bf6c9e68ea4a55ef763c310ecfc9b.tar.gz libar2-ea7d8f4a919bf6c9e68ea4a55ef763c310ecfc9b.tar.bz2 libar2-ea7d8f4a919bf6c9e68ea4a55ef763c310ecfc9b.tar.xz |
Refine libar2_hash_buf_size + add test + securely erase parts of the hash output buffer that is written to but is not part of the hash
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | libar2_hash_buf_size.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/libar2_hash_buf_size.c b/libar2_hash_buf_size.c index 109969f..3010a8a 100644 --- a/libar2_hash_buf_size.c +++ b/libar2_hash_buf_size.c @@ -3,13 +3,14 @@ size_t -libar2_hash_buf_size(struct libar2_argon2_parameters *params) +libar2_hash_buf_size(const struct libar2_argon2_parameters *params) { if (params->hashlen <= 64) return params->hashlen; - if (params->hashlen > SIZE_MAX / 128 * 64 - 31) { + if (params->hashlen > SIZE_MAX - 31 || + ((params->hashlen + 31) | 31) == SIZE_MAX) { errno = EOVERFLOW; return 0; } - return (params->hashlen + 31) / 64 * 128; + return ((params->hashlen + 31) | 31) + 1; } |