{"record":{"id":"063725aa0a7efa29","repo":"ory/kratos","slug":"scrypt-n-d-not-in-1-d","errorCode":null,"errorMessage":"scrypt N=%d not in [1, %d]","messagePattern":"scrypt N=(.+?) not in \\[1, (.+?)\\]","errorType":"validation","errorClass":"ErrHashParametersOutOfBounds","httpStatus":null,"severity":"error","filePath":"hash/hash_limits.go","lineNumber":94,"sourceCode":"\tmaxBcryptCost = 15\n)\n\nfunc validateFirebaseScryptParams(logN, r, p uint32) error {\n\tif logN > maxScryptLogN {\n\t\treturn errors.Wrapf(ErrHashParametersOutOfBounds, \"firescrypt ln=%d exceeds max %d\", logN, maxScryptLogN)\n\t}\n\tif r == 0 || r > maxScryptR {\n\t\treturn errors.Wrapf(ErrHashParametersOutOfBounds, \"firescrypt r=%d not in [1, %d]\", r, maxScryptR)\n\t}\n\tif p == 0 || p > maxScryptP {\n\t\treturn errors.Wrapf(ErrHashParametersOutOfBounds, \"firescrypt p=%d not in [1, %d]\", p, maxScryptP)\n\t}\n\treturn nil\n}\n\nfunc validateScryptParams(n, r, p uint32) error {\n\tif n == 0 || n > maxScryptN {\n\t\treturn errors.Wrapf(ErrHashParametersOutOfBounds, \"scrypt N=%d not in [1, %d]\", n, maxScryptN)\n\t}\n\tif r == 0 || r > maxScryptR {\n\t\treturn errors.Wrapf(ErrHashParametersOutOfBounds, \"scrypt r=%d not in [1, %d]\", r, maxScryptR)\n\t}\n\tif p == 0 || p > maxScryptP {\n\t\treturn errors.Wrapf(ErrHashParametersOutOfBounds, \"scrypt p=%d not in [1, %d]\", p, maxScryptP)\n\t}\n\treturn nil\n}\n\nfunc validateArgon2Params(memoryKiB uint64, iterations uint32, parallelism uint8) error {\n\tif memoryKiB == 0 || memoryKiB > uint64(maxArgon2MemoryKiB) {\n\t\treturn errors.Wrapf(ErrHashParametersOutOfBounds, \"argon2 m=%d KiB not in [1, %d]\", memoryKiB, maxArgon2MemoryKiB)\n\t}\n\tif iterations == 0 || iterations > maxArgon2Iterations {\n\t\treturn errors.Wrapf(ErrHashParametersOutOfBounds, \"argon2 t=%d not in [1, %d]\", iterations, maxArgon2Iterations)\n\t}\n\tif parallelism == 0 || parallelism > maxArgon2Parallelism {","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/ory/kratos/blob/b86338da04a040247a07f46100a86dcfb3875909/hash/hash_limits.go#L76-L112","documentation":"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.","triggerScenarios":"decodeScryptHash encounters an scrypt hash string (e.g. sCrypt:/... or $scrypt$...) with N=0 or N>131072, via ValidateImportedHash or during password comparison.","commonSituations":"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.","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"],"exampleFix":"// before (N=2^20, rejected)\n$scrypt$N=1048576$r=8$p=1$...\n// after (N=2^17, accepted)\n$scrypt$N=131072$r=8$p=1$...","handlingStrategy":"validation","validationCode":"func scryptNOK(n uint32) bool { return n >= 1 && n <= 1<<17 }\n// Or pre-validate the whole hash: hash.ValidateImportedHash(hashed)","typeGuard":null,"tryCatchPattern":"if err := hash.ValidateImportedHash(raw); errors.Is(err, hash.ErrHashParametersOutOfBounds) {\n    return fmt.Errorf(\"scrypt N out of range: %w\", err)\n}","preventionTips":["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"],"tags":["hashing","scrypt","security"],"backgroundTag":"value-out-of-range","analyzedSha":"b86338da04a040247a07f46100a86dcfb3875909","analyzedAt":"2026-09-07T15:58:15.934Z","contentChangedAt":"2026-09-07T15:58:15.934Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}