{"record":{"id":"e4b364f6159b04ca","repo":"gchq/CyberChef","slug":"err-e4b364","errorCode":null,"errorMessage":"${err}","messagePattern":"\\$\\{err\\}","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/GOSTSign.mjs","lineNumber":136,"sourceCode":"\n        const algorithm = {\n            version: versionNum,\n            length: blockLength,\n            mode: \"MAC\",\n            sBox: sBoxVal,\n            macLength: macLength\n        };\n\n        try {\n            const Hex = CryptoGost.coding.Hex;\n            if (iv) algorithm.iv = Hex.decode(iv);\n\n            const cipher = GostEngine.getGostCipher(algorithm);\n            const out = Hex.encode(cipher.sign(Hex.decode(key), Hex.decode(input)));\n\n            return outputType === \"Hex\" ? out : Utils.byteArrayToChars(fromHex(out));\n        } catch (err) {\n            throw new OperationError(err);\n        }\n    }\n\n}\n\nexport default GOSTSign;\n","sourceCodeStart":118,"sourceCodeEnd":143,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/GOSTSign.mjs#L118-L143","documentation":"Catch-all around the MAC engine in GOST Sign, re-raising any crypto-gost-js error as an OperationError. Common underlying causes: key not 256 bits, an invalid macLength, bad sBox for the 1989 variant, non-hex input where applicable, or IV-length problems when an IV is supplied.","triggerScenarios":"Key shorter/longer than 32 bytes; macLength out of range for the algorithm; non-hex characters in key/input; an sBox the 1989 MAC rejects.","commonSituations":"Pasting a base64 key into a Hex field; choosing a macLength larger than the block size; interop with tooling using a different sBox default.","solutions":["Provide a 32-byte (64-hex) key.","Use a macLength within the block-size bit range.","Match input/key encoding to the Input type.","Inspect the preserved `err` for the exact library message."],"exampleFix":"// before\nkey = \"aabb\"; // too short for MAC\n// after\nkey = \"aabb...\".padEnd(64,\"0\"); // 32-byte key","handlingStrategy":"try-catch","validationCode":"if (hexKey.length !== 64) throw new Error(\"GOST MAC key must be 32 bytes / 64 hex chars\");\nif (!Number.isInteger(macLength) || macLength <= 0 || macLength > blockBits) throw new Error(`macLength must be 1..${blockBits}`);","typeGuard":"function isHex(s){return typeof s===\"string\"&&/^[0-9a-fA-F]*$/.test(s)&&s.length%2===0;}","tryCatchPattern":"try { chef.bake(input, recipe); }\ncatch (e) { if (/key|mac|length|sbox/i.test(e.message||\"\")) handleUserError(e); else throw e; }","preventionTips":["Use a 32-byte key.","Keep macLength within the block-size bit range.","Match input/key encoding to the Input type.","Inspect the wrapped err for the library's message."],"tags":["crypto","gost","mac","input-validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}