Documentation
¶
Index ¶
Constants ¶
const SEPARATOR = "$"
Variables ¶
Functions ¶
func Hash ¶
Returns the derived key of the given password using the scrypt key-derivation functions based on the given parameters. The parameters are prepended to the derived key and separated by the "$" character (0x24). If the provided parameters are invalid, an error will be returned
func Upgrade ¶
func Upgrade(password, hash []byte, timeout time.Duration, memMiBytes int) (result, salt, derivedKey []byte, err error)
Upgrade the password-hash combination by recalibrating the scrypt parameters to the given timeout and memory constraints. Returns an error if the password and hash do not match, calibration fails or rehash fails. Returns a new hash with the updated parameters.
Types ¶
type Params ¶
type Params struct { N int // CPU/Memory cost parameter (logN) R int // Block size parameter (octets) P int // Parallelization parameter (positive integer) SaltLength int // Length of the salt (octets) KeyLength int // Length of the derived key (octets) }
Input parameters for the scrypt key-derivation function as described in Colin Percival's paper (http://www.tarsnap.com/scrypt/scrypt.pdf) he recommended parameters for interactive logins as of 2017 are N=32768, r=8 and p=1. The parameters N, r, and p should be increased as memory latency and CPU parallelism increases; consider setting N to the highest power of 2 you can derive within 100 milliseconds.
Sensible defaults for the scrypt key-derivation function These defaults will consume 32MB of memory (128 * r * N) The derived key will have a length of 32bytes (256bits)
func Decode ¶
Extracts the scrypt parameters, salt and derived key from the given hash. It returns an error if the hash format is invalid and/or the parameters are invalid
func (*Params) Calibrate ¶
Calibrates the parameters to be the hardest setting for the given time and memory constraints. The params will use the given memory (MiB) and will take the given time to compute (but not less that timeout / 2) The default timeout (when timeout == 0) is 200ms The default memory usage (when memMiBytes = 0) is 32MiB