Skip to content

Default hash length is twice what it needs to be #36

Description

@multiwebinc

The key length can safely be set to 16 instead of 32 because the string length of the hash returned by scrypt() for some reason is always doubled. So if you put 16 in, you get a 32 character hash, if you put 32 in you get 64 characters being produced. Since only the first 32 characters of the hash are ever used, making it longer than this is unnecessary.

var_dump(scrypt('password', 'salty', pow(2,14), 8, 2, 16));
var_dump(scrypt('password', 'salty', pow(2,14), 8, 2, 20));
var_dump(scrypt('password', 'salty', pow(2,14), 8, 2, 24));
var_dump(scrypt('password', 'salty', pow(2,14), 8, 2, 28));
var_dump(scrypt('password', 'salty', pow(2,14), 8, 2, 32));
var_dump(scrypt('password', 'salty', pow(2,14), 8, 2, 50));

Produces the output:

string(32) "e5135483ad9e2955f65dd1287a3b83d0"
string(40) "e5135483ad9e2955f65dd1287a3b83d0632f5082"
string(48) "e5135483ad9e2955f65dd1287a3b83d0632f50823b3ad12f"
string(56) "e5135483ad9e2955f65dd1287a3b83d0632f50823b3ad12fc3b7e874"
string(64) "e5135483ad9e2955f65dd1287a3b83d0632f50823b3ad12fc3b7e87432085014"
string(100) "e5135483ad9e2955f65dd1287a3b83d0632f50823b3ad12fc3b7e87432085014bf127be1b54afcb040ac456c4ff

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions