{"record":{"id":"e64a2a3e057b0bf9","repo":"gchq/CyberChef","slug":"err-e64a2a","errorCode":null,"errorMessage":"${err}","messagePattern":"\\$\\{err\\}","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/GOSTDecrypt.mjs","lineNumber":145,"sourceCode":"            version: versionNum,\n            length: blockLength,\n            mode: \"ES\",\n            sBox: sBoxVal,\n            block: blockMode,\n            keyMeshing: keyMeshing,\n            padding: padding\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.decrypt(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 GOSTDecrypt;\n","sourceCodeStart":127,"sourceCodeEnd":152,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/GOSTDecrypt.mjs#L127-L152","documentation":"A catch-all around the crypto-gost-js engine calls in GOST Decrypt that re-throws any library exception as an OperationError. The underlying `err` is most often a key-length, IV-length, sBox, or hex-decode failure raised inside `GostEngine.getGostCipher` or `cipher.decrypt`. GOST keys must be 256 bits (32 bytes / 64 hex chars); block modes other than ECB require an IV equal to the block size (8 bytes for Magma, 16 for Kuznyechik).","triggerScenarios":"Supplying a key that is not exactly 32 bytes; choosing CBC/CFB/OFB/CTR but leaving the IV empty or the wrong length; passing non-hex characters when Input type is \"Hex\"; selecting an invalid sBox for the 1989 variant; decrypting data whose ciphertext length is not a whole number of blocks with NO padding.","commonSituations":"Pasting a key copied from a PEM/base64 source without converting to the configured key format; forgetting that the IV must match the block size of the chosen algorithm (Magma 64-bit vs Kuznyechik 128-bit); interop with another tool that used a different padding or mode.","solutions":["Ensure the key is exactly 32 bytes; if Input type is Hex, that is 64 hex digits.","Provide an IV of the correct block size for any non-ECB mode (8 bytes for Magma, 16 for Kuznyechik).","Verify the Input type matches the actual input encoding; switch to Raw if the input is text.","Set padding to match how the data was encrypted (e.g. PKCS5).","Inspect the wrapped `err.message` (it is preserved) to identify the exact library failure."],"exampleFix":"// before: key too short, no IV for CBC\nargs = [\"aabb\", \"\", \"Hex\", \"Raw\", \"GOST R 34.12 (Magma, 2015)\", \"E-A\", \"CBC\", \"NO\", \"NO\"];\n// after: 32-byte key, 8-byte IV for 64-bit Magma CBC\nargs = [\"aabb...dd\".padEnd(64,\"0\"), \"0011223344556677\", \"Hex\", \"Raw\", \"GOST R 34.12 (Magma, 2015)\", \"E-A\", \"CBC\", \"NO\", \"PKCS5\"];","handlingStrategy":"try-catch","validationCode":"// Validate key/iv lengths before baking\nconst KEY_BYTES = 32;\nif (hexKey.length !== KEY_BYTES * 2) throw new Error(`Key must be ${KEY_BYTES} bytes (${KEY_BYTES*2} hex chars)`);\nif (mode !== \"ECB\" && hexIv.length !== (blockBits/8) * 2) throw new Error(`IV must be ${blockBits/8} bytes for ${mode}`);","typeGuard":"/** Hex string of even length with only 0-9a-fA-F */\nfunction isHex(s) { return typeof s === \"string\" && /^[0-9a-fA-F]*$/.test(s) && s.length % 2 === 0; }","tryCatchPattern":"try { chef.bake(input, recipe); }\ncatch (e) {\n  if (e.message && /key|iv|length|sbox/i.test(e.message)) handleUserError(e);\n  else throw e;\n}","preventionTips":["Always supply a 32-byte (64-hex) GOST key.","Match IV length to the algorithm's block size for non-ECB modes.","Confirm Input type matches the real input encoding before baking.","Keep the original error text — the wrapped err carries the library's precise message."],"tags":["crypto","gost","cipher","input-validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}