scrypt(password,
salt,
key_len,
N,
r,
p,
num_keys=1)
|
|
Derive one or more keys from a passphrase.
This function performs key derivation according to
the scrypt algorithm, introduced in Percival's paper
"Stronger key derivation via sequential memory-hard functions".
This implementation is based on RFC7914.
A good choice of parameters (N, r , p) was suggested
by Colin Percival in his presentation in 2009:
- (16384, 8, 1) for interactive logins (<=100ms)
- (1048576, 8, 1) for file encryption (<=5s)
- Parameters:
password (string) - The secret pass phrase to generate the keys from.
salt (string) - A string to use for better protection from dictionary attacks.
This value does not need to be kept secret,
but it should be randomly chosen for each derivation.
It is recommended to be at least 8 bytes long.
key_len (integer) - The length in bytes of every derived key.
N (integer) - CPU/Memory cost parameter. It must be a power of 2 and less
than 2**32.
r (integer) - Block size parameter.
p (integer) - Parallelization parameter.
It must be no greater than (2**32-1)/(4r).
num_keys (integer) - The number of keys to derive. Every key is key_len bytes long.
By default, only 1 key is generated.
The maximum cumulative length of all keys is (2**32-1)*32
(that is, 128TB).
- Returns:
- A byte string or a tuple of byte strings.
|