{"record":{"id":"09be22a13d1f8b79","repo":"peass-ng/PEASS-ng","slug":"personalization-length-must-be-exactly-8-bytes","errorCode":null,"errorMessage":"Personalization length must be exactly 8 bytes","messagePattern":"Personalization length must be exactly 8 bytes","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/digests/Blake2sDigest.cs","lineNumber":227,"sourceCode":"        {\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];\n                Array.Copy(personalization, 0, this.personalization, 0, personalization.Length);\n            }\n            if (key != null)\n            {\n                if (key.Length > 32)\n                    throw new ArgumentException(\"Keys > 32 bytes are not supported\");\n\n                this.key = new byte[key.Length];\n                Array.Copy(key, 0, this.key, 0, key.Length);\n\n                keyLength = key.Length;\n                Array.Copy(key, 0, buffer, 0, key.Length);\n                bufferPos = BLOCK_LENGTH_BYTES; // zero padding\n            }\n            Init();\n        }","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/digests/Blake2sDigest.cs#L209-L245","documentation":"Blake2s reserves exactly 8 bytes for the personalization field in its parameter block. When a non-null personalization is supplied, the constructor requires it to be exactly 8 bytes and throws ArgumentException otherwise.","triggerScenarios":"Calling new Blake2sDigest(key, digestBytes, salt, personalization) with personalization.Length != 8 — e.g. an application name/domain string of arbitrary length, an empty array, or a longer context string.","commonSituations":"Passing a domain or app-name string directly (\"myapp\" = 5 bytes, or UTF-8 of a long product name) instead of a fixed 8-byte context identifier; padding mistakes when porting between Blake2 variants.","solutions":["Encode the personalization context and truncate or zero-pad it to exactly 8 bytes before passing it.","Pass null to leave the personalization field zeroed.","Centralize creation of the 8-byte personalization block in one helper so callers cannot pass raw strings."],"exampleFix":"// before\nvar digest = new Blake2sDigest(null, 32, null, Encoding.UTF8.GetBytes(\"MyApplication\"));\n// after\nbyte[] p = new byte[8];\nbyte[] raw = Encoding.UTF8.GetBytes(\"MyApp\");\nArray.Copy(raw, p, Math.Min(raw.Length, 8));\nvar digest = new Blake2sDigest(null, 32, null, p);","handlingStrategy":"validation","validationCode":"if (personalization != null && personalization.Length != 8)\n    throw new ArgumentException(\"Blake2s personalization must be exactly 8 bytes\");\nvar digest = new Blake2sDigest(key, 32, salt, personalization);","typeGuard":"static bool IsValidPersonalization(byte[] p) => p == null || p.Length == 8;","tryCatchPattern":"try { var d = new Blake2sDigest(key, 32, salt, personalization); }\ncatch (ArgumentException ex) { /* zero-pad context to 8 bytes */ }","preventionTips":["Encode context strings then zero-pad/truncate to 8 bytes","Centralize personalization-block creation","Never pass raw strings of arbitrary length"],"tags":["csharp","cryptography","argument-validation","blake2s"],"backgroundTag":"invalid-parameter-length","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}