peass-ng/PEASS-ng · error · ArgumentException

BLAKE2b digest bit length must be a multiple of 8 and not gr

Error message

BLAKE2b digest bit length must be a multiple of 8 and not greater than 512

What it means

The Blake2bDigest(int digestSize) constructor requires the digest size in BITS to be between 8 and 512 inclusive and a multiple of 8; anything else throws this ArgumentException immediately. This enforces the BLAKE2b specification's allowable output lengths (8-512 bits, byte-aligned).

Source

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

            this.key = Arrays.Clone(digest.key);
            this.digestLength = digest.digestLength;
            this.chainValue = Arrays.Clone(digest.chainValue);
            this.personalization = Arrays.Clone(digest.personalization);
            this.salt = Arrays.Clone(digest.salt);
            this.t0 = digest.t0;
            this.t1 = digest.t1;
            this.f0 = digest.f0;
        }

        /**
         * Basic sized constructor - size in bits.
         *
         * @param digestSize size of the digest in bits
         */
        public Blake2bDigest(int digestSize)
        {
            if (digestSize < 8 || digestSize > 512 || digestSize % 8 != 0)
                throw new ArgumentException("BLAKE2b digest bit length must be a multiple of 8 and not greater than 512");

            buffer = new byte[BLOCK_LENGTH_BYTES];
            keyLength = 0;
            this.digestLength = digestSize / 8;
            Init();
        }

        /**
         * Blake2b for authentication ("Prefix-MAC mode").
         * After calling the doFinal() method, the key will
         * remain to be used for further computations of
         * this instance.
         * The key can be overwritten using the clearKey() method.
         *
         * @param key A key up to 64 bytes or null
         */
        public Blake2bDigest(byte[] key)
        {

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Pass a multiple of 8 between 8 and 512 (e.g. 512 for the default 64-byte digest)
  2. If your config stores bytes, multiply by 8 before constructing
  3. Use the parameterless Blake2bDigest() for the standard 512-bit digest

Example fix

// before
var d = new Blake2bDigest(64); // 64 bits, likely meant bytes
// after
var d = new Blake2bDigest(64 * 8); // 512 bits = 64-byte digest
Defensive patterns

Strategy: validation

Validate before calling

bool IsValidBlake2bBits(int bits) => bits >= 8 && bits <= 512 && bits % 8 == 0;

Prevention

When it happens

Trigger: new Blake2bDigest(bits) where bits < 8, bits > 512, or bits % 8 != 0 (e.g. Blake2bDigest(520), Blake2bDigest(100)).

Common situations: Confusing bits with bytes (passing 64 expecting 64-byte digest when max is 512 bits; passing 0 or negative defaults), porting configs that store byte sizes (32/64) into a bits parameter.

Related errors


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