[PATCH] cipher:kdf:baloon: Validate parameters.
NIIBE Yutaka via Gcrypt-devel <[email protected]>
| Newsgroups | gmane.comp.encryption.gpg.libgcrypt.devel |
|---|---|
| Message-ID | <74f0c825951a6004435bba12bcbfeb2fd0e9d662.1785997008.git.gniibe@fsij.org> |
* cipher/kdf.c (BALLOON_TIMECOST_MAX): New. (BALLOON_PARALLELISM_MAX): New. (balloon_open): Validate parameters with those constants. Calculate the multiplication in 64-bit. -- GnuPG-bug-id: 8383 Signed-off-by: NIIBE Yutaka <[email protected]> --- cipher/kdf.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) _______________________________________________ Gcrypt-devel mailing list [email protected] https://lists.gnupg.org/mailman/listinfo/gcrypt-devel
0001-cipher-kdf-baloon-Validate-parameters.patch
(text/x-patch, 1.1 KB)
diff --git a/cipher/kdf.c b/cipher/kdf.c
index 66eff6c6..82791af7 100644
--- a/cipher/kdf.c
+++ b/cipher/kdf.c
@@ -1047,6 +1047,9 @@ ballon_context_size (unsigned int parallelism)
return n;
}
+#define BALLOON_TIMECOST_MAX (16777216-1)
+#define BALLOON_PARALLELISM_MAX (16777216-1)
+
static gpg_err_code_t
balloon_open (gcry_kdf_hd_t *hd, int subalgo,
const unsigned long *param, unsigned int paramlen,
@@ -1121,6 +1124,12 @@ balloon_open (gcry_kdf_hd_t *hd, int subalgo,
if (s_cost < 1)
return GPG_ERR_INV_VALUE;
+ if (t_cost < 1 || t_cost > BALLOON_TIMECOST_MAX)
+ return GPG_ERR_INV_VALUE;
+
+ if (parallelism < 1 || parallelism > BALLOON_PARALLELISM_MAX)
+ return GPG_ERR_INV_VALUE;
+
n = ballon_context_size (parallelism);
b = xtrymalloc (n);
if (!b)
@@ -1138,7 +1147,7 @@ balloon_open (gcry_kdf_hd_t *hd, int subalgo,
b->t_cost = t_cost;
b->parallelism = parallelism;
- b->n_blocks = (s_cost * 1024) / b->blklen;
+ b->n_blocks = (s_cost * U64_C(1024)) / b->blklen;
block = xtrycalloc (parallelism * b->n_blocks, b->blklen);
if (!block)