From c478cf175887c84dc071c4f73a7667603b354789 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 18 Mar 2016 15:38:26 +0100 Subject: kdf: Make PBKDF2 check work on all platforms. * cipher/kdf.c (_gcry_kdf_pkdf2): Chnage DKLEN to unsigned long. -- The previous pacth has no effect because on almost all platformans an unsigned int is 32 bit and thus the 0xffffffff is anyway the largest value. This patch changes the variable to an unsigned long so that at least on common 64 bit Unix systems (but not on 64 bit Windows) there is an actual check. Signed-off-by: Werner Koch --- cipher/kdf.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cipher/kdf.c b/cipher/kdf.c index 831edd24..27f57896 100644 --- a/cipher/kdf.c +++ b/cipher/kdf.c @@ -125,7 +125,7 @@ _gcry_kdf_pkdf2 (const void *passphrase, size_t passphraselen, gpg_err_code_t ec; gcry_md_hd_t md; int secmode; - unsigned int dklen = keysize; + unsigned long dklen = keysize; char *dk = keybuffer; unsigned int hlen; /* Output length of the digest function. */ unsigned int l; /* Rounded up number of blocks. */ @@ -151,11 +151,14 @@ _gcry_kdf_pkdf2 (const void *passphrase, size_t passphraselen, secmode = _gcry_is_secure (passphrase) || _gcry_is_secure (keybuffer); /* Step 1 */ - /* If dkLen > (2^32 - 1) * hLen, output "derived key too long" and stop. - We use a stronger inequality. */ + /* If dkLen > (2^32 - 1) * hLen, output "derived key too long" and + * stop. We use a stronger inequality but only if our type can hold + * a larger value. */ - if (dklen > 4294967295U) +#if SIZEOF_UNSIGNED_LONG > 4 + if (dklen > 0xffffffffU) return GPG_ERR_INV_VALUE; +#endif /* Step 2 */ -- cgit v1.2.1