Skip to content

PBKDF2 hang (very long loop) if iterations == 0 #2088

@guidovranken

Description

@guidovranken
#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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions