peass-ng/PEASS-ng · error · ArgumentException

personalization length must be exactly 16 bytes

Error message

personalization length must be exactly 16 bytes

What it means

BLAKE2b's personalization parameter must be exactly 16 bytes per the specification; a non-null personalization of any other length throws this ArgumentException. Passing null is allowed (no personalization).

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/digests/Blake2bDigest.cs:205

        {
            if (digestLength < 1 || digestLength > 64)
                throw new ArgumentException("Invalid digest length (required: 1 - 64)");

            this.digestLength = digestLength;
            this.buffer = new byte[BLOCK_LENGTH_BYTES];

            if (salt != null)
            {
                if (salt.Length != 16)
                    throw new ArgumentException("salt length must be exactly 16 bytes");

                this.salt = new byte[16];
                Array.Copy(salt, 0, this.salt, 0, salt.Length);
            }
            if (personalization != null)
            {
                if (personalization.Length != 16)
                    throw new ArgumentException("personalization length must be exactly 16 bytes");

                this.personalization = new byte[16];
                Array.Copy(personalization, 0, this.personalization, 0, personalization.Length);
            }
            if (key != null)
            {
                if (key.Length > 64)
                    throw new ArgumentException("Keys > 64 are not supported");

                this.key = new byte[key.Length];
                Array.Copy(key, 0, this.key, 0, key.Length);

                keyLength = key.Length;
                Array.Copy(key, 0, buffer, 0, key.Length);
                bufferPos = BLOCK_LENGTH_BYTES; // zero padding
            }
            Init();
        }

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Ensure the personalization string is exactly 16 bytes (pad/truncate as needed)
  2. Pass null when no personalization is needed
  3. Constant-fold and validate personalization constants at startup

Example fix

// before
var d = new Blake2bDigest(key, 64, null, Encoding.UTF8.GetBytes("MyApp"));
// after
byte[] pers = new byte[16];
Array.Copy(Encoding.UTF8.GetBytes("MyApp"), pers, 5);
var d = new Blake2bDigest(key, 64, null, pers);
Defensive patterns

Strategy: validation

Validate before calling

byte[] NormalizePersonalization(byte[] pers) {
    if (pers == null) return null;
    if (pers.Length == 16) return pers;
    var p = new byte[16];
    Array.Copy(pers, p, Math.Min(pers.Length, 16));
    return p;
}

Prevention

When it happens

Trigger: new Blake2bDigest(key, digestLength, salt, personalization) where personalization != null and personalization.Length != 16.

Common situations: Using application-name strings longer or shorter than 16 bytes, passing empty arrays instead of null, reusing 32-byte personalization constants from BLAKE2s configs.

Related errors


AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02). Data as JSON: /api/errors/de5d2555ba65b8eb. Report an issue: GitHub.