{"record":{"id":"53bca174cc2d484d","repo":"peass-ng/PEASS-ng","slug":"invalid-digest-length-required-1-32","errorCode":null,"errorMessage":"Invalid digest length (required: 1 - 32)","messagePattern":"Invalid digest length \\(required: 1 - 32\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/digests/Blake2sDigest.cs","lineNumber":211,"sourceCode":"\n        /**\n         * BLAKE2s with key, required digest length, salt and personalization.\n         * <p/>\n         * After calling the doFinal() method, the key, the salt and the personal\n         * string will remain and might be used for further computations with this\n         * instance. The key can be overwritten using the clearKey() method, the\n         * salt (pepper) can be overwritten using the clearSalt() method.\n         *\n         * @param key             a key up to 32 bytes or null\n         * @param digestBytes     from 1 up to 32 bytes\n         * @param salt            8 bytes or null\n         * @param personalization 8 bytes or null\n         */\n        public Blake2sDigest(byte[] key, int digestBytes, byte[] salt,\n                             byte[] personalization)\n        {\n            if (digestBytes < 1 || digestBytes > 32)\n                throw new ArgumentException(\"Invalid digest length (required: 1 - 32)\");\n\n            this.digestLength = digestBytes;\n            this.buffer = new byte[BLOCK_LENGTH_BYTES];\n\n            if (salt != null)\n            {\n                if (salt.Length != 8)\n                    throw new ArgumentException(\"Salt length must be exactly 8 bytes\");\n\n                this.salt = new byte[8];\n                Array.Copy(salt, 0, this.salt, 0, salt.Length);\n            }\n            if (personalization != null)\n            {\n                if (personalization.Length != 8)\n                    throw new ArgumentException(\"Personalization length must be exactly 8 bytes\");\n\n                this.personalization = new byte[8];","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/digests/Blake2sDigest.cs#L193-L229","documentation":"Blake2s produces between 1 and 32 bytes of output (digest length is written into the parameter block). The full constructor Blake2sDigest(key, digestBytes, salt, personalization) validates digestBytes and throws ArgumentException for any value outside 1..32.","triggerScenarios":"Calling new Blake2sDigest(key, digestBytes, salt, personalization) with digestBytes < 1 or digestBytes > 32 — e.g. passing 64 to mirror a Blake2b/SHA-512 output size, or passing 0/-1 by accident.","commonSituations":"Porting code from Blake2b (up to 64 bytes) or SHA-256 configs where a bit size (256) was passed instead of a byte size (32); config-driven digest sizes; off-by-one when computing output length.","solutions":["Pass a digest byte size between 1 and 32; remember this constructor takes BYTES, not bits (use 32 for a 256-bit hash).","If you need a longer digest, use Blake2bDigest (up to 64 bytes) or a different algorithm.","Clamp or validate user/config-supplied digest sizes before constructing the digest."],"exampleFix":"// before\nvar digest = new Blake2sDigest(null, 256, null, null); // bits passed by mistake\n// after\nvar digest = new Blake2sDigest(null, 32, null, null); // 32 bytes = 256 bits","handlingStrategy":"validation","validationCode":"if (digestBytes < 1 || digestBytes > 32)\n    throw new ArgumentOutOfRangeException(nameof(digestBytes), \"Blake2s digest must be 1-32 bytes\");\nvar digest = new Blake2sDigest(key, digestBytes, salt, personalization);","typeGuard":"static bool IsValidDigestBytes(int n) => n >= 1 && n <= 32;","tryCatchPattern":"try { var d = new Blake2sDigest(key, digestBytes, salt, pers); }\ncatch (ArgumentException ex) { /* clamp to 32 or surface config error */ }","preventionTips":["Remember sizes here are bytes, not bits","Whitelist allowed sizes in configuration","Unit-test digest construction with configured sizes"],"tags":["csharp","cryptography","argument-validation","blake2s"],"backgroundTag":"invalid-digest-length","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}