{"record":{"id":"8001f53de47ce9ca","repo":"gchq/CyberChef","slug":"invalid-iv-length-iv-length-bytes-expected-0","errorCode":null,"errorMessage":"Invalid IV length: ${iv.length} bytes (expected: 0 or 8)","messagePattern":"Invalid IV length: (.+?) bytes \\(expected: 0 or 8\\)","errorType":"validation","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/Rabbit.mjs","lineNumber":78,"sourceCode":"    /**\n     * @param {string} input\n     * @param {Object[]} args\n     * @returns {string}\n     */\n    run(input, args) {\n        const key = Utils.convertToByteArray(args[0].string, args[0].option),\n            iv = Utils.convertToByteArray(args[1].string, args[1].option),\n            endianness = args[2],\n            inputType = args[3],\n            outputType = args[4];\n\n        const littleEndian = endianness === \"Little\";\n\n        if (key.length !== 16) {\n            throw new OperationError(`Invalid key length: ${key.length} bytes (expected: 16)`);\n        }\n        if (iv.length !== 0 && iv.length !== 8) {\n            throw new OperationError(`Invalid IV length: ${iv.length} bytes (expected: 0 or 8)`);\n        }\n\n        // Inner State\n        const X = new Uint32Array(8), C = new Uint32Array(8);\n        let b = 0;\n\n        // Counter System\n        const A = [\n            0x4d34d34d, 0xd34d34d3, 0x34d34d34, 0x4d34d34d,\n            0xd34d34d3, 0x34d34d34, 0x4d34d34d, 0xd34d34d3\n        ];\n        const counterUpdate = function() {\n            for (let j = 0; j < 8; j++) {\n                const temp = C[j] + A[j] + b;\n                b = (temp / ((1 << 30) * 4)) >>> 0;\n                C[j] = temp;\n            }\n        };","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/Rabbit.mjs#L60-L96","documentation":"Thrown by the Rabbit cipher when an IV is supplied that is neither empty (0 bytes, meaning no IV) nor exactly 8 bytes (64 bits), the two legal IV sizes for Rabbit. The IV is decoded from the user string via Utils.convertToByteArray, so a wrong encoding or length trips this guard.","triggerScenarios":"Supplying an IV of any length other than 0 or 8 bytes; selecting the wrong IV format option; passing a partial hex/Base64 IV; leaving stray whitespace that decodes to extra bytes.","commonSituations":"Using a 16-byte IV (common from AES-GCM contexts) by mistake; mismatching the IV format dropdown; pasting an IV that was truncated or padded.","solutions":["Supply an 8-byte IV (8 Latin1 chars, 16 hex chars, or Base64 decoding to 8 bytes), or leave it empty for no IV.","Check the 'IV format' option matches the IV string encoding.","Strip whitespace/newlines from the IV input before running.","Confirm the IV came from the same keying material as the original encryption (length must be 8, not 16)."],"exampleFix":"// before\n//   iv string: \"00112233445566778899\" (hex, 10 bytes) -> error\n// after\n//   iv string: \"0011223344556677\" (hex, 16 chars -> 8 bytes)","handlingStrategy":"validation","validationCode":"const ivBytes = Utils.convertToByteArray(ivStr, ivOption);\nif (ivBytes.length !== 0 && ivBytes.length !== 8) {\n  throw new Error(`IV must be 0 or 8 bytes, got ${ivBytes.length}`);\n}","typeGuard":"function isValidRabbitIV(ivBytes) { return ivBytes.length === 0 || ivBytes.length === 8; }","tryCatchPattern":"try { chef.rabbit(input, { iv: ivStr }); } catch (e) { if (/Invalid IV length/.test(e.message)) fixIV(); else throw e; }","preventionTips":["Leave IV empty for no-IV mode, or supply exactly 8 bytes.","Match the IV format option to the IV string encoding.","Strip whitespace from the IV field."],"tags":["crypto","rabbit","iv-validation","validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}