peass-ng/PEASS-ng · error · ArgumentException

Keys > 32 bytes are not supported

Error message

Keys > 32 bytes are not supported

What it means

Same 32-byte key limit as the simple constructor, but raised by the full Blake2sDigest(key, digestBytes, salt, personalization) constructor after the salt/personalization checks. Blake2s keyed mode cannot hold more than 32 key bytes in its parameter block, so a longer key throws ArgumentException.

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/digests/Blake2sDigest.cs:235

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

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

                this.personalization = new byte[8];
                Array.Copy(personalization, 0, this.personalization, 0, personalization.Length);
            }
            if (key != null)
            {
                if (key.Length > 32)
                    throw new ArgumentException("Keys > 32 bytes 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();
        }

        // initialize chainValue
        private void Init()
        {
            if (chainValue == null)
            {
                chainValue = new uint[8];

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Derive or truncate the key to at most 32 bytes (HKDF/PBKDF2 with 32-byte output) before constructing the digest.
  2. Use Blake2bDigest if keys longer than 32 bytes are required.
  3. Pass null and use keyless hashing if the byte array is data rather than a key.

Example fix

// before
var digest = new Blake2sDigest(sixtyFourByteKey, 32, salt, null);
// after
byte[] key32 = new byte[32];
Array.Copy(sixtyFourByteKey, key32, 32);
var digest = new Blake2sDigest(key32, 32, salt, null);
Defensive patterns

Strategy: validation

Validate before calling

if (key != null && key.Length > 32)
    key = DeriveSubkey(key, 32); // HKDF/PBKDF2 with 32-byte output
var digest = new Blake2sDigest(key, 32, salt, pers);

Type guard

static bool IsValidKey(byte[] key) => key == null || key.Length <= 32;

Try / catch

try { var d = new Blake2sDigest(key, 32, salt, pers); }
catch (ArgumentException ex) { /* derive 32-byte key and retry */ }

Prevention

When it happens

Trigger: new Blake2sDigest(key, digestBytes, salt, personalization) with key != null and key.Length > 32 — e.g. a 64-byte key that worked with Blake2b, or a derived key blob passed wholesale.

Common situations: Migrating keyed hashing from Blake2b (64-byte keys) to Blake2s (32-byte max); passing a full PEM/DER key file; supplying concatenations of key material.

Related errors


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