{"record":{"id":"ff8a89b189ecf6b2","repo":"peass-ng/PEASS-ng","slug":"outputlength-not-a-multiple-of-8","errorCode":null,"errorMessage":"outputLength not a multiple of 8","messagePattern":"outputLength not a multiple of 8","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/digests/KeccakDigest.cs","lineNumber":256,"sourceCode":"                    ulong mask = (1UL << partial) - 1UL;\n                    state[full] ^= Pack.LE_To_UInt64(dataQueue, off) & mask;\n                }\n            }\n\n            state[(rate - 1) >> 6] ^= (1UL << 63);\n\n            bitsInQueue = 0;\n            squeezing = true;\n        }\n\n        protected void Squeeze(byte[] output, int offset, long outputLength)\n        {\n            if (!squeezing)\n            {\n                PadAndSwitchToSqueezingPhase();\n            }\n            if ((outputLength & 7L) != 0L)\n                throw new InvalidOperationException(\"outputLength not a multiple of 8\");\n\n            long i = 0;\n            while (i < outputLength)\n            {\n                if (bitsInQueue == 0)\n                {\n                    KeccakExtract();\n                }\n                int partialBlock = (int)System.Math.Min((long)bitsInQueue, outputLength - i);\n                Array.Copy(dataQueue, (rate - bitsInQueue) >> 3, output, offset + (int)(i >> 3), partialBlock >> 3);\n                bitsInQueue -= partialBlock;\n                i += partialBlock;\n            }\n        }\n\n        private void KeccakAbsorb(byte[] data, int off)\n        {\n            int count = rate >> 6;","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/digests/KeccakDigest.cs#L238-L274","documentation":"KeccakDigest.Squeeze throws InvalidOperationException when the requested outputLength in bits is not a whole number of bytes ((outputLength & 7) != 0). The squeeze loop produces bytes only, so a bit-level output length is unsupported. Reached via DoFinal with a partial-bit request.","triggerScenarios":"Requesting a digest/DoFinal output whose bit length is not a multiple of 8 (e.g. 254 bits instead of 256) through the partial-bits output path.","commonSituations":"Custom rate/output-size configuration for Keccak where the developer divides bits by 8 incorrectly; truncated-hash schemes computed in bits.","solutions":["Round the requested output length up to a multiple of 8 bits, then truncate the resulting byte array yourself.","Verify the outputLength parameter passed down from your wrapper is byte-aligned.","For truncated output, generate the next multiple of 8 bits and copy the needed bytes."],"exampleFix":"// before\nint outBits = 100; // not a multiple of 8 -> throws\nSqueeze(output, outBits);\n// after\nint outBits = ((100 + 7) / 8) * 8; // 104\nbyte[] buf = new byte[outBits / 8];\nSqueeze(buf, outBits);\nbyte[] truncated = buf.Take(13).ToArray();","handlingStrategy":"validation","validationCode":"if ((outputLengthBits & 7L) != 0L)\n    outputLengthBits = (outputLengthBits + 7) / 8 * 8; // round up to byte boundary","typeGuard":"bool IsByteAligned(long bits) => (bits & 7L) == 0L;","tryCatchPattern":"try { Squeeze(buf, outputLengthBits); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"multiple of 8\")) { throw new ArgumentOutOfRangeException(nameof(outputLengthBits), \"Must be a multiple of 8\"); }","preventionTips":["Express output sizes in bytes, converting to bits only at the call site.","Truncate larger byte-aligned outputs in application code instead of asking the digest for bit-level output.","Assert outputLength % 8 == 0 in tests for custom Keccak configurations."],"tags":["csharp","bouncycastle","keccak","bit-alignment"],"backgroundTag":"output-length-not-byte-aligned","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}