| 1 |
scrypt reference vectors |
| 2 |
^^^^^^^^^^^^^^^^^^^^^^^^ |
| 3 |
|
| 4 |
Libsodium exposes both a simplified scrypt KDF/password storage API |
| 5 |
which parametrizes the CPU and memory load in term of a opslimit parameter |
| 6 |
and a memlimit one, and a "traditional" low-level API parametrized in terms |
| 7 |
of a (N, r, p) triple. |
| 8 |
|
| 9 |
While we used the vectors from `RFC 7914`_ to test the traditional API, |
| 10 |
the simplified API is only implemented by libsodium, and therefore we just |
| 11 |
added a KDF generation check using the ascii encoded passphrase |
| 12 |
"The quick brown fox jumps over the lazy dog.", and verified the results |
| 13 |
were the same we could get from the version of hashlib.scrypt, as provided |
| 14 |
in python version 3.6 stdlib. |
| 15 |
|
| 16 |
.. code-block:: python |
| 17 |
|
| 18 |
>>> import hashlib |
| 19 |
>>> import nacl |
| 20 |
>>> import nacl.bindings |
| 21 |
>>> import nacl.pwhash.scrypt |
| 22 |
>>> pick_scrypt_params = nacl.bindings.nacl_bindings_pick_scrypt_params |
| 23 |
>>> nacl.pwhash.scrypt.kdf(32, |
| 24 |
... b'The quick brown fox jumps over the lazy dog.', |
| 25 |
... b"ef537f25c895bfa782526529a9b63d97", |
| 26 |
... opslimit=20000, memlimit=100 * (2 ** 20)) |
| 27 |
b'\x10e>\xc8A8\x11\xde\x07\xf1\x0f\x98EG\xe6}V]\xd4yN\xae\xd3P\x87yP\x1b\xc7+n*' |
| 28 |
>>> n_log2, r, p = pick_scrypt_params(20000, 100 * (2 ** 20)) |
| 29 |
>>> print(2 ** n_log2, r, p) |
| 30 |
1024 8 1 |
| 31 |
>>> hashlib.scrypt(b'The quick brown fox jumps over the lazy dog.', |
| 32 |
... salt=b"ef537f25c895bfa782526529a9b63d97", |
| 33 |
... n=1024, r=8, p=1, dklen=32) |
| 34 |
b'\x10e>\xc8A8\x11\xde\x07\xf1\x0f\x98EG\xe6}V]\xd4yN\xae\xd3P\x87yP\x1b\xc7+n*' |
| 35 |
|
| 36 |
.. _RFC 7914: https://tools.ietf.org/html/rfc7914 |