0

I have an implementation of scrypt that doesn’t produce the same output as an online scrypt key generator I found. For example, if I run my own scrypt in a function like this:

void test_scrypt(void)
{
    char passwdTxt[] = "abc";
    int passwdlen = strlen(passwdTxt);
    uint8_t passwd[passwdlen];
    memcpy(passwd, passwdTxt, passwdlen);

    uint8_t salt[] = {0x5C,0x57,0xD8,0x6B,0x73,0x5E,0x98,0xD5,0x1A,0xA5,0x34,0x16,0xE2,0x90,0x29,0xAF};
    int saltlen = 16;
    int buflen = 32;
    uint8_t buf[buflen];
    int N = 16384;
    int r = 8;
    int p = 1;
    crypto_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen);

    int i;
    printf("Key:\n\r");
    for (i = 0; i < buflen; ++i)
        printf("%02x ", buf[i]);
}

It produces the following output:

Key:
d6 2b 0e 12 75 e3 0a 85 ce 22 03 43 ef 7e e6 d2 97 77 e1 5c 3e 35 03 63 0b fc 54 7b 8f 18 ef 63

However, when I run the same input at the site https://gchq.github.io/CyberChef/?op=Scrypt I get the following result (note the 'output' section has a different hash from mine): Cyber Chef Scrypt Keygen

Does anyone here have their own Scrypt generator they could run this input condition on, and tell me if my output is correct or not?
I was thinking that maybe my salt is not quite valid, like perhaps I should be only using 1-128 bit (non-extended ASCII) values per byte?

katrik
  • 35
  • 3

1 Answers1

3

Your code has computed the correct answer.

There are some known-answer tests in the scrypt Git repository. They're going to be a little more reliable than GCHQ's toy web interface which is apparently buggy (and which gives me different-length outputs each time).

Squeamish Ossifrage
  • 48,392
  • 3
  • 116
  • 223
  • Thank you. Yeah all the known test vectors I had seen used 'normal text' based salts, so I just wanted to try it with more exotic octets. I'm glad you were able to corroborate. – katrik Jul 14 '18 at 01:59
  • 1
    @katrik you may also want to note that RFC 7914 has test vectors for all the intermediate functions in scrypt which can be quite convenient for debugging. – SEJPM Jul 14 '18 at 11:35