gchq/CyberChef · error · OperationError
Bit length limited to 4096 bits for performance reasons
Error message
Bit length limited to 4096 bits for performance reasons
What it means
Thrown by RandomPrime when the requested bit length exceeds 4096. This is an artificial cap to prevent performance problems: Miller-Rabin testing and big-integer arithmetic on >4096-bit numbers are slow in the browser/worker.
Source
Thrown at src/core/operations/RandomPrime.mjs:127
value: ["Decimal", "Hexadecimal"]
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const [bits, cryptoGrade, outputFormat] = args;
if (bits < 2) {
throw new OperationError("Bit length must be at least 2");
}
if (bits > 4096) {
throw new OperationError("Bit length limited to 4096 bits for performance reasons");
}
const rounds = cryptoGrade ? 40 : 7;
let attempts = 0;
const maxAttempts = 10000;
let n = randBigInt(bits);
while (!isProbablePrime(n, rounds)) {
n = randBigInt(bits);
attempts++;
if (attempts > maxAttempts) {
throw new OperationError(`Failed to generate prime after ${maxAttempts} attempts. Try a different bit length.`);
}
}
// Return only the prime for pipeabilityView on GitHub (pinned to 4290ea7539)
Solutions
- Limit the request to <= 4096 bits.
- If you truly need a larger prime, generate it externally with a native crypto library.
- Reconsider whether such a large prime is necessary for your use case.
Example fix
// before // bits: 8192 // after // bits: 4096
Defensive patterns
Strategy: validation
Validate before calling
if (bits > 4096) throw new Error('Bit length capped at 4096'); Type guard
const withinCap = b => Number.isInteger(b) && b <= 4096;
Try / catch
try { randomPrime(bits); } catch (e) { if (/4096/.test(e.message)) bits = 4096; else throw e; } Prevention
- Cap bits at 4096.
- Use native tooling for larger primes.
When it happens
Trigger: Requesting 8192-bit or larger primes; copy-pasting an RSA-8192 key size into the bit field.
Common situations: Assuming modern RSA sizes (8192) are supported; wanting extra security margin; scripted requests with large bit counts.
Related errors
- Bit length limited to 4096 bits for performance reasons
- Bit length must be at least 2
- Letter ${letter} is not included in LS47
- Unknown padding type: ${padding}
- Invalid key length: ${key.length} bytes The following algor
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/edce1101a235d057.
Report an issue: GitHub.