ory/kratos · error · ErrHashParametersOutOfBounds
scrypt N= not in [1, ]
Error message
scrypt N=%d not in [1, %d]
What it means
This error means a plain scrypt password hash declares an N (CPU/memory cost) parameter that is 0 or greater than 2^17 (131072). N=0 is invalid (no work); N above 2^17 would make each compare allocate up to 128*N*r bytes, risking memory exhaustion at login time. It wraps ErrHashParametersOutOfBounds from validateScryptParams during hash decode.
Solutions
- Decode the hash parameters and confirm N is a power of two in [1, 131072]
- Re-hash with an OWASP-recommended configuration (e.g. N=2^17, r=8, p=1)
- If the hash came from file-encryption tooling, do not import it as a password hash — derive a password hash with this library instead
Example fix
// before (N=2^20, rejected) $scrypt$N=1048576$r=8$p=1$... // after (N=2^17, accepted) $scrypt$N=131072$r=8$p=1$...
Defensive patterns
Strategy: validation
Validate before calling
func scryptNOK(n uint32) bool { return n >= 1 && n <= 1<<17 }
// Or pre-validate the whole hash: hash.ValidateImportedHash(hashed) Try / catch
if err := hash.ValidateImportedHash(raw); errors.Is(err, hash.ErrHashParametersOutOfBounds) {
return fmt.Errorf("scrypt N out of range: %w", err)
} Prevention
- Standardize on OWASP scrypt configs (N<=2^17, r=8, p=1) across your systems
- Do not import scrypt hashes produced by file-encryption tools (tarsnap, age)
- Run ValidateImportedHash before storing any externally sourced hash
When it happens
Trigger: decodeScryptHash encounters an scrypt hash string (e.g. sCrypt:/... or $scrypt$...) with N=0 or N>131072, via ValidateImportedHash or during password comparison.
Common situations: Importing scrypt hashes from file-encryption tooling (tarsnap, age) which use N far above 2^17; over-tuned security configs raising N beyond OWASP's 2^17 maximum; hand-edited hash parameters.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- firescrypt ln= exceeds max
- firescrypt r= not in [1, ]
- firescrypt p= not in [1, ]
- scrypt r= not in [1, ]
- scrypt p= not in [1, ]
AI-assisted analysis of ory/kratos@b86338da04 (2026-09-07).
Data as JSON: /api/errors/063725aa0a7efa29.
Report an issue: GitHub.
Appendix: source
Thrown at hash/hash_limits.go:94
maxBcryptCost = 15
)
func validateFirebaseScryptParams(logN, r, p uint32) error {
if logN > maxScryptLogN {
return errors.Wrapf(ErrHashParametersOutOfBounds, "firescrypt ln=%d exceeds max %d", logN, maxScryptLogN)
}
if r == 0 || r > maxScryptR {
return errors.Wrapf(ErrHashParametersOutOfBounds, "firescrypt r=%d not in [1, %d]", r, maxScryptR)
}
if p == 0 || p > maxScryptP {
return errors.Wrapf(ErrHashParametersOutOfBounds, "firescrypt p=%d not in [1, %d]", p, maxScryptP)
}
return nil
}
func validateScryptParams(n, r, p uint32) error {
if n == 0 || n > maxScryptN {
return errors.Wrapf(ErrHashParametersOutOfBounds, "scrypt N=%d not in [1, %d]", n, maxScryptN)
}
if r == 0 || r > maxScryptR {
return errors.Wrapf(ErrHashParametersOutOfBounds, "scrypt r=%d not in [1, %d]", r, maxScryptR)
}
if p == 0 || p > maxScryptP {
return errors.Wrapf(ErrHashParametersOutOfBounds, "scrypt p=%d not in [1, %d]", p, maxScryptP)
}
return nil
}
func validateArgon2Params(memoryKiB uint64, iterations uint32, parallelism uint8) error {
if memoryKiB == 0 || memoryKiB > uint64(maxArgon2MemoryKiB) {
return errors.Wrapf(ErrHashParametersOutOfBounds, "argon2 m=%d KiB not in [1, %d]", memoryKiB, maxArgon2MemoryKiB)
}
if iterations == 0 || iterations > maxArgon2Iterations {
return errors.Wrapf(ErrHashParametersOutOfBounds, "argon2 t=%d not in [1, %d]", iterations, maxArgon2Iterations)
}
if parallelism == 0 || parallelism > maxArgon2Parallelism {View on GitHub (pinned to b86338da04)