aboutsummaryrefslogtreecommitdiffstats
path: root/libar2_hash_buf_size.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-02-14 00:03:02 +0100
committerMattias Andrée <maandree@kth.se>2022-02-14 00:03:02 +0100
commitc9e67109d0425fbb1d371200eefec858ae11c0bf (patch)
tree9e5bae57a8726d16c7e268663da29882e0516665 /libar2_hash_buf_size.c
parentAdd libar2_hash_buf_size and fix related documentation for libar2_hash (diff)
downloadlibar2-c9e67109d0425fbb1d371200eefec858ae11c0bf.tar.gz
libar2-c9e67109d0425fbb1d371200eefec858ae11c0bf.tar.bz2
libar2-c9e67109d0425fbb1d371200eefec858ae11c0bf.tar.xz
Fix previous commit
Diffstat (limited to 'libar2_hash_buf_size.c')
-rw-r--r--libar2_hash_buf_size.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/libar2_hash_buf_size.c b/libar2_hash_buf_size.c
index b165d4b..109969f 100644
--- a/libar2_hash_buf_size.c
+++ b/libar2_hash_buf_size.c
@@ -5,5 +5,11 @@
size_t
libar2_hash_buf_size(struct libar2_argon2_parameters *params)
{
- return (params->hashlen > 64 && (params->hashlen & 127)) ? (params->hashlen | 127) + 1 : params->hashlen;
+ if (params->hashlen <= 64)
+ return params->hashlen;
+ if (params->hashlen > SIZE_MAX / 128 * 64 - 31) {
+ errno = EOVERFLOW;
+ return 0;
+ }
+ return (params->hashlen + 31) / 64 * 128;
}