scrypt

scrypt is a password-based key derivation function designed to be both computationally and memory-intensive, making it resistant to brute-force attacks using specialized hardware like GPUs and ASICs.

How scrypt Works

scrypt requires a large amount of memory to compute, which is expensive to implement in parallel on GPUs or custom hardware. It uses a memory-hard algorithm that mixes data in a large memory buffer.

Parameters

scrypt(password, salt, N, r, p, keyLen)

N: CPU/memory cost parameter (power of 2, e.g., 2^14)
r: Block size parameter (typically 8)
p: Parallelization parameter (typically 1)

Memory usage ≈ 128 * N * r bytes
Time ≈ proportional to N * r * p

Usage Example

# Python
import hashlib

password = b"secretpassword"
salt = os.urandom(16)

# Derive key using scrypt
derived_key = hashlib.scrypt(
    password,
    salt=salt,
    n=16384,    # 2^14
    r=8,
    p=1,
    dklen=32
)

Recommended Parameters

  • Interactive logins: N=2^14, r=8, p=1 (~100ms, 16MB)
  • Sensitive storage: N=2^20, r=8, p=1 (~5s, 1GB)
  • Increase N as hardware improves

Advantages

  • Memory-hardness resists GPU/ASIC attacks
  • Configurable time-memory trade-off
  • Used in cryptocurrency (Litecoin)

See Also