gchq/CyberChef · error · OperationError

Unknown padding type: ${padding}

Error message

Unknown padding type: ${padding}

What it means

applyPadding's switch has cases for NO, PKCS5, ZERO, RANDOM, BIT. The default case rejects any other padding string so the cipher never silently picks an unintended scheme. This is a programmer/API error rather than a data error.

Source

Thrown at src/core/lib/Present.mjs:266

                paddedMessage.push(0);
            }
            break;

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

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

        default:
            throw new OperationError(`Unknown padding type: ${padding}`);
    }

    return paddedMessage;
}

/**
 * Remove padding from message
 * @param {number[]} message - Padded message
 * @param {string} padding - Padding type ("NO", "PKCS5", "ZERO", "RANDOM", "BIT")
 * @param {number} blockSize - Block size in bytes
 * @returns {number[]} - Unpadded message
 */
function removePadding(message, padding, blockSize) {
    if (message.length === 0) return message;

    switch (padding) {
        case "NO":
        case "ZERO":

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Use one of the documented values exactly: 'NO', 'PKCS5', 'ZERO', 'RANDOM', 'BIT' (case-sensitive).
  2. Constrain the UI dropdown to FROM/TO padding options so users cannot type arbitrary values.
  3. Normalize input before calling: padding = padding.toUpperCase(); validate against a Set of allowed values.
  4. Default to 'PKCS5' when the incoming value is missing or unrecognized.

Example fix

// before
encryptPRESENT(msg, key, iv, 'ECB', 'PKCS7'); // typo -> Unknown padding type

// after
const ALLOWED = new Set(['NO','PKCS5','ZERO','RANDOM','BIT']);
const safePad = ALLOWED.has(padding) ? padding : 'PKCS5';
encryptPRESENT(msg, key, iv, 'ECB', safePad);
Defensive patterns

Strategy: validation

Validate before calling

const PRESENT_PADS = new Set(['NO','PKCS5','ZERO','RANDOM','BIT']);
function normalizePadding(p) {
  const up = String(p || '').toUpperCase();
  return PRESENT_PADS.has(up) ? up : 'PKCS5';
}

encryptPRESENT(msg, key, iv, mode, normalizePadding(padding));

Type guard

function isPresentPadding(x): x is 'NO'|'PKCS5'|'ZERO'|'RANDOM'|'BIT' {
  return ['NO','PKCS5','ZERO','RANDOM','BIT'].includes(x);
}

Prevention

When it happens

Trigger: Calling applyPadding (via encryptPRESENT) with a padding argument outside the supported set: typos like 'PKCS7', 'None', lowercase 'pkcs5', 'CTS', 'ANSI', or passing undefined/null.

Common situations: Recipe/JSON config with a typo or wrong casing; copying a padding name from an AES recipe ('PKCS7') into a PRESENT recipe; version mismatch where an older caller sends a value the newer library removed; passing the empty default from an unconfigured dropdown.

Related errors


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