{"record":{"id":"38df3e46ca5b3758","repo":"gchq/CyberChef","slug":"invalid-block-cipher-mode-mode-38df3e","errorCode":null,"errorMessage":"Invalid block cipher mode: ${mode}","messagePattern":"Invalid block cipher mode: (.+?)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/lib/RC6.mjs","lineNumber":528,"sourceCode":"            }\n            return cipherText.slice(0, messageLength);\n        }\n\n        case \"CTR\": {\n            let counter = [...iv];\n            for (let i = 0; i < paddedMessage.length; i += blockSize) {\n                const encrypted = encryptBlock(counter, S, rounds, w);\n                const block = paddedMessage.slice(i, i + blockSize);\n                // Pad block if shorter than blockSize\n                while (block.length < blockSize) block.push(0);\n                cipherText.push(...xorBlocks(encrypted, block));\n                counter = incrementCounter(counter);\n            }\n            return cipherText.slice(0, messageLength);\n        }\n\n        default:\n            throw new OperationError(`Invalid block cipher mode: ${mode}`);\n    }\n\n    return cipherText;\n}\n\n/**\n * Decrypt using RC6 cipher with specified block mode\n *\n * @param {number[]} cipherText - Ciphertext as byte array\n * @param {number[]} key - Key as byte array\n * @param {number[]} iv - IV (block size bytes, not used for ECB)\n * @param {string} mode - Block cipher mode (\"ECB\", \"CBC\", \"CFB\", \"OFB\", \"CTR\")\n * @param {string} padding - Padding type (\"NO\", \"PKCS5\", \"ZERO\", \"RANDOM\", \"BIT\")\n * @param {number} rounds - Number of rounds (default: 20)\n * @param {number} w - Word size in bits (default: 32)\n * @returns {number[]} - Plaintext as byte array\n */\nexport function decryptRC6(cipherText, key, iv, mode = \"ECB\", padding = \"PKCS5\", rounds = 20, w = 32) {","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/lib/RC6.mjs#L510-L546","documentation":"Default branch of the mode switch inside encryptRC6 (RC6.mjs:528). After the padding step, the function dispatches on mode; any value outside {ECB, CBC, CFB, OFB, CTR} reaches this throw and reports the bad mode string.","triggerScenarios":"encryptRC6 is called with a mode argument that is not one of the five supported literals. Examples: 'CBC/PKCS7', 'GCM' (RC6 here does not implement AEAD), 'ctr' (lowercase), an empty string, or undefined leaking through from an unconfigured recipe field.","commonSituations":"User-typed mode string passed unvalidated; mode coming from a config file with different naming convention; assumption that an AEAD mode like GCM is supported when only the five classic modes are.","solutions":["Pass one of: 'ECB', 'CBC', 'CFB', 'OFB', 'CTR'.","Normalise and validate the mode string (trim + uppercase) against an allowlist before calling encryptRC6.","If you need an AEAD mode, RC6 in this library does not provide it — pick a different cipher or mode."],"exampleFix":"// before\nconst ct = encryptRC6(msg, key, iv, \"gcm\");\n// after\nconst ct = encryptRC6(msg, key, iv, \"CTR\");","handlingStrategy":"validation","validationCode":"const RC6_MODES = new Set([\"ECB\", \"CBC\", \"CFB\", \"OFB\", \"CTR\"]);\nfunction normaliseMode(m) {\n  const v = String(m).trim().toUpperCase();\n  if (!RC6_MODES.has(v)) throw new TypeError(`Unsupported RC6 mode: ${JSON.stringify(m)}`);\n  return v;\n}","typeGuard":"function isRc6Mode(v) {\n  return typeof v === \"string\" &&\n    [\"ECB\",\"CBC\",\"CFB\",\"OFB\",\"CTR\"].includes(v.trim().toUpperCase());\n}","tryCatchPattern":"try {\n  encryptRC6(msg, key, iv, normaliseMode(mode), padding);\n} catch (e) {\n  if (e instanceof TypeError && /Unsupported RC6 mode/.test(e.message)) {\n    // report unsupported mode to caller\n  } else throw e;\n}","preventionTips":["Validate mode against an allowlist before invoking the cipher.","Remember RC6 here has no AEAD (GCM/CCM) support.","Share one mode-allowlist constant across encrypt and decrypt code paths."],"tags":["rc6","cipher","block-mode","enum","argument-error"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}