{"record":{"id":"3776fde82477e324","repo":"gchq/CyberChef","slug":"err-3776fd","errorCode":null,"errorMessage":"${err}","messagePattern":"\\$\\{err\\}","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/GOSTHash.mjs","lineNumber":85,"sourceCode":"        const versionNum = version === \"GOST 28147 (1994)\" ? 1994 : 2012;\n        const algorithm = {\n            name: versionNum === 1994 ? \"GOST 28147\" : \"GOST R 34.10\",\n            version: versionNum,\n            mode: \"HASH\"\n        };\n\n        if (versionNum === 1994) {\n            algorithm.sBox = sBox;\n        } else {\n            algorithm.length = parseInt(length, 10);\n        }\n\n        try {\n            const gostDigest = new GostDigest(algorithm);\n\n            return toHexFast(gostDigest.digest(input));\n        } catch (err) {\n            throw new OperationError(err);\n        }\n    }\n\n}\n\nexport default GOSTHash;\n","sourceCodeStart":67,"sourceCodeEnd":92,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/GOSTHash.mjs#L67-L92","documentation":"Catch-all around `GostDigest.digest` in GOST Hash, re-raising any crypto-gost-js error as an OperationError. For the 1994 variant the sBox is attached; for newer variants the digest length is parsed from the `length` arg. Failures usually come from an invalid sBox name, a non-numeric/unsupported length, or malformed input passed to the digest engine.","triggerScenarios":"Selecting a 1994 hash variant with an sBox value the library rejects; choosing a 2012 variant with a length string that isn't a supported bit size (e.g. not 256/512); input that the digest engine cannot consume.","commonSituations":"Misreading the length field as bytes instead of bits; mixing an sBox intended for the block cipher into the hash op; older recipes using a length value no longer accepted by the vendored crypto-gost-js.","solutions":["Use a supported digest length (typically 256 or 512 bits for GOST R 34.11-2012).","For the 1994 variant, keep the default sBox (E-A / D-A) unless interop demands otherwise.","Inspect the wrapped `err` for the exact library message."],"exampleFix":"// before\nargs = [inputType, \"GOST R 34.11 (2012)\", \"128\", includeNames, length];\n// after\nargs = [inputType, \"GOST R 34.11 (2012)\", \"256\", includeNames, length];","handlingStrategy":"try-catch","validationCode":"const SUPPORTED_LENGTHS = [\"256\",\"512\"];\nif (variant !== \"GOST R 34.11 (1994)\" && !SUPPORTED_LENGTHS.includes(String(length))) {\n  throw new Error(`Unsupported digest length ${length}; use ${SUPPORTED_LENGTHS.join(\"/\")} bits`);\n}","typeGuard":"function isSupportedLength(v){return[\"256\",\"512\"].includes(String(v));}","tryCatchPattern":"try { chef.bake(input, recipe); }\ncatch (e) { if (/length|sbox|digest/i.test(e.message||\"\")) handleUserError(e); else throw e; }","preventionTips":["Use supported digest lengths (256/512 bits for 2012 variants).","Keep the default sBox for the 1994 variant unless interop requires otherwise.","Inspect the wrapped err for the library's message."],"tags":["crypto","gost","hash","input-validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}