Scrypt.ts overview

The scrypt password hasher, Node-only (or Workers with nodejs_compat) because effect/crypto has no scrypt, hence its own subpath. Put it beside the default in a multiAlgorithmVerifier to verify old hashes, and sign-in rehashes them.


Exports Grouped by Category


utils

layer

Layer providing the scrypt hasher as the PasswordHasher (see scryptHasher). Node.js only.

Signature

declare const layer: (options?: {
  readonly cost?: number
  readonly blockSize?: number
  readonly parallelization?: number
}) => Layer.Layer<PasswordHasher>

Source

scryptHasher

scrypt Password Hasher implementing the PasswordHasher trait.

Uses Node’s built-in crypto.scrypt (dependency-free) with OWASP-recommended parameters (N=2^17, r=8, p=1). scrypt is memory-hard, making it more resistant to GPU/ASIC attacks than PBKDF2.

PHC-style format: scrypt$N$r$p$salt$hash (N/r/p are stored so parameters can be tuned without breaking existing hashes).

verify reads N, r and p from the stored hash and refuses, before running the KDF, any set outside these limits. The refusal is a HashingError:

  • N is a power of two with 2 ≤ N ≤ max(2^20, cost);
  • r is an integer with 1 ≤ r ≤ max(32, blockSize);
  • p is an integer with 1 ≤ p ≤ max(16, parallelization);
  • the memory a derivation needs, 128 * r * (N + p + 2) bytes, is at most max(256 MiB, the memory the configured cost, blockSize and parallelization need).

The defaults need about 128 MiB and pass. A hash written with valid configured parameters always verifies, even above 256 MiB, but a crafted stored hash cannot make verify allocate gigabytes. hash applies the same checks to the configured parameters, so a hasher never writes a hash its own verify would refuse (e.g. blockSize: 0, which Node itself accepts).

needsRehash returns true for a hash that verify would refuse, and for one whose N, r or p is below the configured value. A stored set that is at least as strong in every parameter is kept; one that is weaker in any parameter is replaced by the configured set, even where it was stronger in another.

Signature

declare const scryptHasher: (options?: {
  readonly cost?: number
  readonly blockSize?: number
  readonly parallelization?: number
}) => typeof PasswordHasher.Service

Source


This site uses Just the Docs, a documentation theme for Jekyll.