{"record":{"id":"c9efb68762e22635","repo":"gchq/CyberChef","slug":"invalid-number-of-rounds-rounds-rounds-must-b-c9efb6","errorCode":null,"errorMessage":"Invalid number of rounds: ${rounds}\n\nRounds must be an integer between 1 and 255. Standard XTEA uses 32 rounds.","messagePattern":"Invalid number of rounds: (.+?)\n\nRounds must be an integer between 1 and 255\\. Standard XTEA uses 32 rounds\\.","errorType":"validation","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/XTEAEncrypt.mjs","lineNumber":96,"sourceCode":"    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            [,, mode, inputType, outputType, padding, rounds] = args;\n\n        if (key.length !== 16)\n            throw new OperationError(`Invalid key length: ${key.length} bytes\n\nXTEA requires a key length of 16 bytes (128 bits).\nMake sure you have specified the type correctly (e.g. Hex vs UTF8).`);\n\n        if (iv.length !== TEA_BLOCK_SIZE && iv.length !== 0 && mode !== \"ECB\")\n            throw new OperationError(`Invalid IV length: ${iv.length} bytes\n\nXTEA uses an IV length of ${TEA_BLOCK_SIZE} bytes (${TEA_BLOCK_SIZE * 8} bits).\nMake sure you have specified the type correctly (e.g. Hex vs UTF8).`);\n\n        if (!Number.isInteger(rounds) || rounds < 1 || rounds > 255)\n            throw new OperationError(`Invalid number of rounds: ${rounds}\n\nRounds must be an integer between 1 and 255. Standard XTEA uses 32 rounds.`);\n\n        // Default IV to null bytes if empty (like AES)\n        const actualIv = iv.length === 0 ? new Array(TEA_BLOCK_SIZE).fill(0) : iv;\n\n        input = Utils.convertToByteArray(input, inputType);\n        const output = encryptXTEA(input, key, actualIv, mode, padding, rounds);\n        return outputType === \"Hex\" ? toHex(output, \"\") : Utils.byteArrayToUtf8(output);\n    }\n\n}\n\nexport default XTEAEncrypt;\n","sourceCodeStart":78,"sourceCodeEnd":111,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/XTEAEncrypt.mjs#L78-L111","documentation":"Thrown by XTEAEncrypt.run when rounds (args[6]) is not an integer in 1–255. Same bounds as decrypt; standard XTEA uses 32 rounds and you must use the same count on both sides.","triggerScenarios":"rounds is fractional, NaN, out of range, or a string. Remember: a valid-but-wrong integer does not throw, it just produces ciphertext that won't decrypt with a different count.","commonSituations":"Non-standard round counts set manually; recipe JSON serialising rounds as a string; disagreement between encrypt and decrypt counts.","solutions":["Set rounds to the intended integer (32 for standard XTEA).","Pass rounds as a number, not a string, within 1–255.","Record the count used for encryption and reuse it for decryption."],"exampleFix":"// before\nargs:[key, iv, \"CBC\", \"Hex\", \"Hex\", \"PKCS5\", \"32\"]\n// after\nargs:[key, iv, \"CBC\", \"Hex\", \"Hex\", \"PKCS5\", 32]","handlingStrategy":"validation","validationCode":"function xteaRoundsArg(rounds) {\n  if (!Number.isInteger(rounds) || rounds < 1 || rounds > 255) throw new Error(\"rounds must be an integer 1..255\");\n  return rounds;\n}","typeGuard":"const isValidXteaRounds = (r) => Number.isInteger(r) && r >= 1 && r <= 255;","tryCatchPattern":"try { chef.bake(data, recipe); } catch (e) { if (/Invalid number of rounds/.test(e.message)) { /* set rounds=32 */ } else throw e; }","preventionTips":["Use 32 rounds and store the value with the ciphertext metadata.","Pass rounds as a number.","Validate range before baking."],"tags":["xtea","crypto","rounds","operation-args"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}