gchq/CyberChef · error · OperationError

No padding requested but input is not a ${blockSize}-byte mu

Error message

No padding requested but input is not a ${blockSize}-byte multiple.

What it means

Thrown by RC6.applyPadding when padding is 'NO' but the message length is not a multiple of the block size (blockSize = w/8, 16 bytes for the default w=32). ECB/CBC require block-aligned input; with 'NO' padding and misaligned data there is nothing valid the cipher can do.

Source

Thrown at src/core/lib/RC6.mjs:358

 * @param {number} blockSize - Block size in bytes
 * @returns {number[]} - Padded message
 */
function applyPadding(message, padding, blockSize) {
    const remainder = message.length % blockSize;
    let nPadding = remainder === 0 ? 0 : blockSize - remainder;

    // For PKCS5, always add at least one byte (full block if already aligned)
    if (padding === "PKCS5" && remainder === 0) {
        nPadding = blockSize;
    }

    if (nPadding === 0) return [...message];

    const paddedMessage = [...message];

    switch (padding) {
        case "NO":
            throw new OperationError(`No padding requested but input is not a ${blockSize}-byte multiple.`);

        case "PKCS5":
            for (let i = 0; i < nPadding; i++) {
                paddedMessage.push(nPadding);
            }
            break;

        case "ZERO":
            for (let i = 0; i < nPadding; i++) {
                paddedMessage.push(0);
            }
            break;

        case "RANDOM":
            for (let i = 0; i < nPadding; i++) {
                paddedMessage.push(Math.floor(Math.random() * 256));
            }
            break;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Choose 'PKCS5' (or another padding) for ECB/CBC with arbitrary-length input.
  2. Pre-pad/pre-trim the message to an exact blockSize multiple before using 'NO'.
  3. Switch to a stream mode (CFB/OFB/CTR) if you truly want no padding.

Example fix

// before
encryptRC6(arbitraryLengthMsg, key, iv, 'CBC', 'NO');
// after
encryptRC6(arbitraryLengthMsg, key, iv, 'CBC', 'PKCS5');
Defensive patterns

Strategy: validation

Validate before calling

const blockSize = w / 8; // 16 for default w=32
if (padding === 'NO' && message.length % blockSize !== 0) {
  throw new Error(`Message (${message.length}B) is not a multiple of ${blockSize}B; choose a padding scheme.`);
}
encryptRC6(message, key, iv, mode, padding, rounds, w);

Try / catch

try {
  return encryptRC6(message, key, iv, mode, 'NO', rounds, w);
} catch (e) {
  if (e instanceof OperationError && /No padding requested/.test(e.message)) {
    return encryptRC6(message, key, iv, mode, 'PKCS5', rounds, w);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling encryptRC6(message, key, iv, 'ECB'|'CBC', 'NO', ...) with a message whose length % blockSize != 0. Stream modes (CFB/OFB/CTR) bypass padding and never hit this.

Common situations: Selecting 'No padding' in the UI for an input that isn't already block-aligned; binary payload of arbitrary length fed to ECB/CBC; assuming the cipher will pad when padding is explicitly 'NO'.

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/b0d5eb37ef4dec44. Report an issue: GitHub.