gchq/CyberChef · error · OperationError

Incorrect hash length

Error message

Incorrect hash length

What it means

Thrown by CitrixCTX1Decode when the input byte length is not a multiple of 4. Citrix CTX1 hashes encode in 4-byte groups (two payload bytes per group after decoding), so a length that isn't divisible by 4 cannot be a well-formed CTX1 hash.

Source

Thrown at src/core/operations/CitrixCTX1Decode.mjs:39

        this.name = "Citrix CTX1 Decode";
        this.module = "Encodings";
        this.description = "Decodes strings in a Citrix CTX1 password format to plaintext.";
        this.infoURL = "https://www.reddit.com/r/AskNetsec/comments/1s3r6y/citrix_ctx1_hash_decoding/";
        this.inputType = "ArrayBuffer";
        this.outputType = "string";
        this.args = [];
    }

    /**
     * @param {ArrayBuffer} input
     * @param {Object[]} args
     * @returns {string}
     */
    run(input, args) {
        input = new Uint8Array(input);
        if (input.length % 4 !== 0) {
            throw new OperationError("Incorrect hash length");
        }
        const revinput = input.reverse();
        const result = [];
        let temp = 0;
        for (let i = 0; i < revinput.length; i += 2) {
            if (i + 2 >= revinput.length) {
                temp = 0;
            } else {
                temp = ((revinput[i + 2] - 0x41) & 0xf) ^ (((revinput[i + 3]- 0x41) << 4) & 0xf0);
            }
            temp = (((revinput[i] - 0x41) & 0xf) ^ (((revinput[i + 1] - 0x41) << 4) & 0xf0)) ^ 0xa5 ^ temp;
            result.push(temp);
        }
        // Decodes a utf-16le string
        return cptable.utils.decode(1200, result.reverse());
    }

}

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Trim trailing whitespace/newlines from the hash before decoding.
  2. Verify the input is actually a CTX1 hash (ASCII letters in the A–P range, length multiple of 4).
  3. Re-copy the full hash without truncation.
  4. Confirm the input type fed to the operation matches bytes vs string expectations.

Example fix

// before — hash with trailing newline → length % 4 != 0
// input (bytes): "MMEGGGHD\n"
// after — trimmed, length divisible by 4
// input (bytes): "MMEGGGHD"
Defensive patterns

Strategy: validation

Validate before calling

const bytes = new Uint8Array(input);
if (bytes.length === 0 || bytes.length % 4 !== 0) { /* reject — not a valid CTX1 length */ }

Type guard

function isCtx1Length(bytes) { return bytes.length > 0 && bytes.length % 4 === 0; }

Try / catch

null

Prevention

When it happens

Trigger: CitrixCTX1Decode.run wraps input in Uint8Array and tests input.length % 4 !== 0. Any input whose byte length mod 4 is nonzero throws immediately — truncated hashes, extra whitespace/newline bytes, or wrong input type (string vs bytes) causing length mismatch.

Common situations: User pastes a CTX1 hash with a trailing newline or space (adds 1 byte → not divisible by 4), copies a partial hash, or feeds a plaintext password expecting CTX1 format.

Related errors


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