{"record":{"id":"6c1c7be6c590525c","repo":"denoland/deno","slug":"err-ossl-evp-not-xof-or-invalid-length","errorCode":"ERR_OSSL_EVP_NOT_XOF_OR_INVALID_LENGTH","errorMessage":"Invalid XOF digest length","messagePattern":"Invalid XOF digest length","errorType":"exception","errorClass":"NodeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal/crypto/hash.ts","lineNumber":125,"sourceCode":"    warnedShakeOutputLength = true;\n    const process = lazyProcess().default;\n    process.emitWarning(\n      \"Creating SHAKE128/256 digests without an explicit options.outputLength is deprecated.\",\n      \"DeprecationWarning\",\n      \"DEP0198\",\n    );\n  }\n\n  try {\n    this[kHandle] = isCopy\n      ? op_node_hash_clone(algorithm, xofLen)\n      : op_node_create_hash(algoLower, xofLen);\n  } catch (err) {\n    // TODO(lucacasonato): don't do this\n    if (\n      err.message === \"Output length mismatch for non-extendable algorithm\"\n    ) {\n      throw new NodeError(\n        \"ERR_OSSL_EVP_NOT_XOF_OR_INVALID_LENGTH\",\n        \"Invalid XOF digest length\",\n      );\n    } else {\n      throw err;\n    }\n  }\n\n  if (this[kHandle] === null) throw new ERR_CRYPTO_HASH_FINALIZED();\n\n  const LazyTransform = lazyLazyTransform().default;\n  ReflectApply(LazyTransform, this, [options]);\n}\n\ninterface Hash {\n  [kHandle]: object;\n  [kFinalized]: boolean;\n}","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/internal/crypto/hash.ts#L107-L143","documentation":"When a Hash is created with an options.outputLength and the algorithm is not an eXtendable-Output-Function, the native op rejects the length with 'Output length mismatch for non-extendable algorithm', which the polyfill remaps to Node's ERR_OSSL_EVP_NOT_XOF_OR_INVALID_LENGTH ('Invalid XOF digest length'). Only XOFs (shake128, shake256) can produce caller-chosen digest sizes.","triggerScenarios":"crypto.createHash('sha256', { outputLength: 16 }); or h.copy({ outputLength: 8 }) on a sha256 hash. Also a shake digest whose outputLength is outside the algorithm's allowed range triggers the same OpenSSL error.","commonSituations":"Truncating a digest to fit a fixed-size column or token and assuming every algorithm supports outputLength; code written against shake128 ported to sha256 without dropping the option; copying a configurable hash factory across algorithms.","solutions":["Remove options.outputLength for fixed-length algorithms (sha1/sha256/sha384/sha512/md5) and slice the digest instead: digest.subarray(0, 16)","Switch to 'shake128' or 'shake256' when a variable-length digest is genuinely required","If using shake, pass an explicit outputLength every time (omitting it is deprecated via DEP0198)"],"exampleFix":"// before\nconst d = crypto.createHash('sha256', { outputLength: 16 }).update(data).digest();\n\n// after\nconst d = crypto.createHash('sha256').update(data).digest().subarray(0, 16);","handlingStrategy":"validation","validationCode":"const XOF = new Set(['shake128', 'shake256']);\nif (options?.outputLength !== undefined && !XOF.has(algorithm)) {\n  throw new RangeError(`outputLength is only valid for XOF algorithms, not ${algorithm}`);\n}\nconst h = crypto.createHash(algorithm, options);","typeGuard":"const isXofAlgorithm = (a: string): boolean => a === 'shake128' || a === 'shake256';","tryCatchPattern":"catch (e) { if ((e as NodeJS.ErrnoException).code === 'ERR_OSSL_EVP_NOT_XOF_OR_INVALID_LENGTH') { /* drop outputLength or switch to shake128/256, then retry */ } throw e; }","preventionTips":["Only pass outputLength for shake128/shake256","Truncate fixed-length digests with Buffer.subarray instead of outputLength","Make the hash algorithm and options a single validated config object"],"tags":["crypto","hash","shake","xof","node-compat"],"backgroundTag":"invalid-digest-length","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}