Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scrypt wrong result with certain parameters #409

Open
guidovranken opened this issue Feb 16, 2020 · 0 comments
Open

scrypt wrong result with certain parameters #409

guidovranken opened this issue Feb 16, 2020 · 0 comments

Comments

@guidovranken
Copy link

    var password = sjcl.codec.hex.toBits("70617373776F7264"); /* "password" */
    var salt = sjcl.codec.hex.toBits("73616C74"); /* "salt" */

    var N = 2;
    var r = 7;
    var p = 1;
    var keySize = 32;
    var derivedKey = sjcl.misc.scrypt(password, salt, N, r, p, keySize * 8);
    console.log(sjcl.codec.hex.fromBits(derivedKey));

This prints:

27272e9e07a3143ed35f946a73c575200059562bdcc24e7b1a18d65b3599575a

But it should print:

728b28339ff809588c6c25fa06299b4f7e557b1527876015f0aef7c8581936f2

You can confirm with this Botan program:

#include <botan/scrypt.h>
#include <string>
#include <stdlib.h>

#define CF_CHECK_NE(expr, res) if ( (expr) == (res) ) { goto end; }

int main(int argc, char** argv)
{
    const size_t N = 2;
    const size_t r = 7;
    const size_t p = 1;
    const size_t size = 32;

    unsigned char* out = (uint8_t*)malloc(size);
    const std::string password = "password";
    const std::string salt = "salt";

    try {
        std::unique_ptr<::Botan::PasswordHashFamily> pwdhash_fam = nullptr;
        std::unique_ptr<::Botan::PasswordHash> pwdhash = nullptr;

        /* Initialize */
        {
            CF_CHECK_NE(pwdhash_fam = ::Botan::PasswordHashFamily::create("Scrypt"), nullptr);
            CF_CHECK_NE(pwdhash = pwdhash_fam->from_params(N, r, p), nullptr);

        }

        /* Process */
        {
            pwdhash->derive_key(
                    out,
                    size,
                    password.data(),
                    password.size(),
                    (const uint8_t*)salt.data(),
                    salt.size());
        }

        for (size_t i = 0; i < size; i++) {
            printf("%02X ", out[i]);
        }
        printf("\n");
    } catch ( ... ) { }

end:
    free(out);
    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant