{"record":{"id":"e5ef59e1990472ab","repo":"peass-ng/PEASS-ng","slug":"must-be-one-of-128-224-256-288-384-or-512","errorCode":null,"errorMessage":"must be one of 128, 224, 256, 288, 384, or 512.","messagePattern":"must be one of 128, 224, 256, 288, 384, or 512\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/digests/KeccakDigest.cs","lineNumber":132,"sourceCode":"        public virtual int GetByteLength()\n        {\n            return rate >> 3;\n        }\n\n        private void Init(int bitLength)\n        {\n            switch (bitLength)\n            {\n                case 128:\n                case 224:\n                case 256:\n                case 288:\n                case 384:\n                case 512:\n                    InitSponge(1600 - (bitLength << 1));\n                    break;\n                default:\n                    throw new ArgumentException(\"must be one of 128, 224, 256, 288, 384, or 512.\", \"bitLength\");\n            }\n        }\n\n        private void InitSponge(int rate)\n        {\n            if (rate <= 0 || rate >= 1600 || (rate & 63) != 0)\n                throw new InvalidOperationException(\"invalid rate value\");\n\n            this.rate = rate;\n            Array.Clear(state, 0, state.Length);\n            Arrays.Fill(this.dataQueue, (byte)0);\n            this.bitsInQueue = 0;\n            this.squeezing = false;\n            this.fixedOutputLength = (1600 - rate) >> 1;\n        }\n\n        protected void Absorb(byte data)\n        {","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/digests/KeccakDigest.cs#L114-L150","documentation":"KeccakDigest only supports fixed output lengths of 128, 224, 256, 288, 384, or 512 bits, because only those produce a valid sponge rate. Init() validates the bitLength passed to the constructor and throws ArgumentException (naming the bitLength parameter) for any other value.","triggerScenarios":"Calling new KeccakDigest(bitLength) with bitLength not in {128, 224, 256, 288, 384, 512} — e.g. 384 vs 512 typos, 0, or SHA3 sizes like 256 passed to a custom subclass expecting bytes.","commonSituations":"Config-driven digest sizes including non-standard values; confusing SHA3-256 with Keccak-256 (both valid here, but e.g. 248 is not); passing byte sizes (32) instead of bits.","solutions":["Pass one of the allowed bit lengths: 128, 224, 256, 288, 384, or 512.","Convert byte-based configuration to bits (multiply by 8) before constructing.","Whitelist the allowed sizes in config parsing and fail early with a clear message."],"exampleFix":"// before\nvar keccak = new KeccakDigest(32); // bytes given, bits expected\n// after\nvar keccak = new KeccakDigest(256);","handlingStrategy":"validation","validationCode":"int[] allowed = { 128, 224, 256, 288, 384, 512 };\nif (Array.IndexOf(allowed, bitLength) < 0)\n    throw new ArgumentOutOfRangeException(nameof(bitLength), \"Keccak supports 128/224/256/288/384/512 bits\");\nvar keccak = new KeccakDigest(bitLength);","typeGuard":"static bool IsValidKeccakLength(int bits) => bits == 128 || bits == 224 || bits == 256 || bits == 288 || bits == 384 || bits == 512;","tryCatchPattern":"try { var k = new KeccakDigest(bitLength); }\ncatch (ArgumentException ex) { /* map to nearest supported length or fail fast */ }","preventionTips":["Convert byte configs to bits before constructing","Whitelist the six supported lengths","Don't confuse SHA3 sizes with allowed Keccak custom sizes"],"tags":["csharp","cryptography","argument-validation","keccak"],"backgroundTag":"invalid-digest-length","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}