nacl.hashlib module exposes directly usable implementations
of raw constructs which libsodium exposes with simplified APIs, like the
nacl.hash and in
blake2b(data=b'', digest_size=BYTES, key=b'', salt=b'', person=b'')¶
Returns an hash object which exposes an API mostly compatible to python3.6’s hashlib.blake2b (the only difference being missing support for tree hashing parameters in the contructor)
hexdigest()have the same semantics as described in hashlib documentation.
Each instance exposes the
nameproperties as required by hashlib API.
the maximum allowed value of the requested digest_size
the maximum allowed size of the password parameter
the maximimum size of the personalization
the maximimum size of the salt
scrypt(password, salt='', n=2**20, r=8, p=1, maxmem=2**25, dklen=64)¶
Derive a raw cryptographic key using the scrypt KDF.
- password (bytes) – the input password
- salt (bytes) – a crypographically-strong random salt
- n (int) – CPU/Memory cost factor
- r (int) – block size multiplier: the used block size will be 128 * r
- p (int) – requested parallelism: the number of indipendently running scrypt constructs which will contribute to the final key generation
- maxmem (int) – maximum memory the whole scrypt construct will be entitled to use
- dklen (int) – length of the derived key
a buffer dklen bytes long containing the derived key
Implements the same signature as the
hashlib.scryptimplemented in cpython version 3.6
The recommended values for n, r, p in 2012 were n = 2**14, r = 8, p = 1; as of 2016, libsodium suggests using n = 2**14, r = 8, p = 1 in a “interactive” setting and n = 2**20, r = 8, p = 1 in a “sensitive” setting.
The total memory usage will respectively be a little greater than 16MB in the “interactive” setting, and a little greater than 1GB in the “sensitive” setting.