From 18d5e5528f480885d3373d200dffc8cd6beeca81 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Fri, 28 Jun 2019 14:22:03 -0400 Subject: [PATCH] Fix divide by 0 finding (GH #855) I'm not sure which tool is producing this finding. I am pretty sure it is a false positive, but clear it for the sake of dark and silent cockpits --- pwdbased.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pwdbased.h b/pwdbased.h index a27550a7..e2a01464 100644 --- a/pwdbased.h +++ b/pwdbased.h @@ -245,7 +245,11 @@ size_t PKCS5_PBKDF2_HMAC::DeriveKey(byte *derived, size_t derivedLen, byte pu // Business logic if (!iterations) { iterations = 1; } + // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 HMAC hmac(secret, secretLen); + if (hmac.DigestSize() == 0) + throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); + SecByteBlock buffer(hmac.DigestSize()); ThreadUserTimer timer;