gchq/CyberChef · error · OperationError

Invalid IV length: ${iv.length} bytes PRESENT uses an IV le

Error message

Invalid IV length: ${iv.length} bytes

PRESENT uses an IV length of 8 bytes (64 bits).
Make sure you have specified the type correctly (e.g. Hex vs UTF8).

What it means

Identical validation to error 548 but in the encrypt operation. PRESENT in CBC mode requires an 8-byte (64-bit) IV. ECB mode is exempt. An encoding mismatch between the IV string and the selected encoding option is the most common cause.

Source

Thrown at src/core/operations/PRESENTEncrypt.mjs:82

    }

    /**
     * @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),
            [,, mode, inputType, outputType, padding] = args;

        if (key.length !== 10 && key.length !== 16)
            throw new OperationError(`Invalid key length: ${key.length} bytes

PRESENT uses a key length of 10 bytes (80 bits) or 16 bytes (128 bits).`);

        if (iv.length !== 8 && mode !== "ECB")
            throw new OperationError(`Invalid IV length: ${iv.length} bytes

PRESENT uses an IV length of 8 bytes (64 bits).
Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);

        input = Utils.convertToByteArray(input, inputType);
        const output = encryptPRESENT(input, key, iv, mode, padding);
        return outputType === "Hex" ? toHex(output, "") : Utils.byteArrayToUtf8(output);
    }

}

export default PRESENTEncrypt;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Provide exactly 8 bytes of IV material for CBC mode
  2. Verify the IV encoding option matches the IV string representation
  3. Switch to ECB mode if no IV is available

Example fix

// before: iv="0123456789abcdef", option="UTF8" -> 16 bytes (FAILS)
// after:  iv="0123456789abcdef", option="Hex" -> 8 bytes (OK)
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check: validate IV length for CBC mode
const ivBytes = Utils.convertToByteArray(ivString, ivOption);
if (mode !== 'ECB' && ivBytes.length !== 8) {
  throw new Error(`IV must be 8 bytes for CBC, got ${ivBytes.length}. Check encoding option.`);
}

Type guard

function isValidPresentIv(ivBytes, mode) {
  return mode === 'ECB' || ivBytes.length === 8;
}

Prevention

When it happens

Trigger: The IV argument, after convertToByteArray, yields a byte array whose length is not 8, and mode is not 'ECB'. A hex IV string interpreted as UTF8 produces twice the expected byte count.

Common situations: User enters a hex IV with the encoding option on UTF8. User provides an empty IV for CBC mode. User enters a key-length IV by mistake.

Related errors


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