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

PRESENT in CBC mode requires an IV of exactly 8 bytes (64 bits, matching the block size). ECB mode does not use an IV and is explicitly exempt from this check. The most common cause is an encoding mismatch between the IV string and the selected encoding option, analogous to the key-length error.

Source

Thrown at src/core/operations/PRESENTDecrypt.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 = decryptPRESENT(input, key, iv, mode, padding);
        return outputType === "Hex" ? toHex(output, "") : Utils.byteArrayToUtf8(output);
    }

}

export default PRESENTDecrypt;

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 (ECB does not require one)

Example fix

// before: iv="0102030405060708", option="UTF8" -> 16 bytes (FAILS in CBC)
// after:  iv="0102030405060708", option="Hex" -> 8 bytes (OK in CBC)
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 16-character hex string is correct (decodes to 8 bytes); an 8-character ASCII string treated as UTF8 is 8 bytes; a 16-character hex string treated as UTF8 is 16 bytes (wrong).

Common situations: User enters a hex IV but leaves the encoding option on UTF8. User provides an empty IV for CBC mode (should use ECB if no IV). User confuses the IV with the key and enters a 10- or 16-byte value.

Related errors


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