gchq/CyberChef · error · OperationError
Invalid IV length: ${iv.length} bytes (expected: 0 or 8)
Error message
Invalid IV length: ${iv.length} bytes (expected: 0 or 8) What it means
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.
Source
Thrown at src/core/operations/Rabbit.mjs:78
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const key = Utils.convertToByteArray(args[0].string, args[0].option),
iv = Utils.convertToByteArray(args[1].string, args[1].option),
endianness = args[2],
inputType = args[3],
outputType = args[4];
const littleEndian = endianness === "Little";
if (key.length !== 16) {
throw new OperationError(`Invalid key length: ${key.length} bytes (expected: 16)`);
}
if (iv.length !== 0 && iv.length !== 8) {
throw new OperationError(`Invalid IV length: ${iv.length} bytes (expected: 0 or 8)`);
}
// Inner State
const X = new Uint32Array(8), C = new Uint32Array(8);
let b = 0;
// Counter System
const A = [
0x4d34d34d, 0xd34d34d3, 0x34d34d34, 0x4d34d34d,
0xd34d34d3, 0x34d34d34, 0x4d34d34d, 0xd34d34d3
];
const counterUpdate = function() {
for (let j = 0; j < 8; j++) {
const temp = C[j] + A[j] + b;
b = (temp / ((1 << 30) * 4)) >>> 0;
C[j] = temp;
}
};View on GitHub (pinned to 4290ea7539)
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).
Example fix
// before // iv string: "00112233445566778899" (hex, 10 bytes) -> error // after // iv string: "0011223344556677" (hex, 16 chars -> 8 bytes)
Defensive patterns
Strategy: validation
Validate before calling
const ivBytes = Utils.convertToByteArray(ivStr, ivOption);
if (ivBytes.length !== 0 && ivBytes.length !== 8) {
throw new Error(`IV must be 0 or 8 bytes, got ${ivBytes.length}`);
} Type guard
function isValidRabbitIV(ivBytes) { return ivBytes.length === 0 || ivBytes.length === 8; } Try / catch
try { chef.rabbit(input, { iv: ivStr }); } catch (e) { if (/Invalid IV length/.test(e.message)) fixIV(); else throw e; } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid key length: ${key.length} bytes (expected: 16)
- Letter ${letter} is not included in LS47
- Unknown padding type: ${padding}
- Invalid key length: ${key.length} bytes The following algor
- Invalid key length: ${key.length} bytes The following algor
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/8001f53de47ce9ca.
Report an issue: GitHub.