PBKDF2 hang (very long loop) if iterations == 0
guidovranken opened this issue · comments
Guido Vranken commented
#include <botan/pbkdf.h>
#include <botan/pwdhash.h>
#define CF_CHECK_NE(expr, res) if ( (expr) == (res) ) { goto end; }
int main(void)
{
std::unique_ptr<::Botan::PasswordHashFamily> pwdhash_fam = nullptr;
std::unique_ptr<::Botan::PasswordHash> pwdhash = nullptr;
uint8_t out[1];
char key[8] = { 0 };
uint8_t salt[8] = { 0 };
/* Initialize */
{
CF_CHECK_NE(pwdhash_fam = ::Botan::PasswordHashFamily::create("PBKDF2(SHA-256)"), nullptr);
CF_CHECK_NE(pwdhash = pwdhash_fam->from_params(0), nullptr);
}
/* Process */
{
pwdhash->derive_key(
out,
1,
key,
sizeof(key),
salt,
sizeof(salt));
}
end:
return 0;
}
I think it might be more appropriate to throw an exception?
Jack Lloyd commented
Fixed now in #2090 thanks!
Guido Vranken commented
You're welcome