peass-ng/PEASS-ng · error · ArgumentException
needs to be a multiple of 8
Error message
needs to be a multiple of 8
What it means
Sha512tDigest truncates SHA-512 to bitLength bits, and truncation is only well-defined on byte boundaries, so the constructor requires bitLength % 8 == 0. The library throws ArgumentException('needs to be a multiple of 8') otherwise.
Source
Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/digests/Sha512tDigest.cs:26
*/
public class Sha512tDigest
: LongDigest
{
private const ulong A5 = 0xa5a5a5a5a5a5a5a5UL;
private readonly int digestLength;
private ulong H1t, H2t, H3t, H4t, H5t, H6t, H7t, H8t;
/**
* Standard constructor
*/
public Sha512tDigest(int bitLength)
{
if (bitLength >= 512)
throw new ArgumentException("cannot be >= 512", "bitLength");
if (bitLength % 8 != 0)
throw new ArgumentException("needs to be a multiple of 8", "bitLength");
if (bitLength == 384)
throw new ArgumentException("cannot be 384 use SHA384 instead", "bitLength");
this.digestLength = bitLength / 8;
tIvGenerate(digestLength * 8);
Reset();
}
/**
* Copy constructor. This will copy the state of the provided
* message digest.
*/
public Sha512tDigest(Sha512tDigest t)
: base(t)
{
this.digestLength = t.digestLength;View on GitHub (pinned to 53fb989abc)
Solutions
- Pass a bitLength that is a multiple of 8 (e.g. 8, 16, ..., 504) and also < 512 and != 384.
- If you have a byte length, multiply by 8 before passing it.
- Validate input before constructing if the value comes from external config.
Example fix
// before var digest = new Sha512tDigest(254); // after var digest = new Sha512tDigest(256);
Defensive patterns
Strategy: validation
Validate before calling
if (bitLength % 8 != 0 || bitLength >= 512 || bitLength == 384) throw new ArgumentOutOfRangeException(nameof(bitLength));
Type guard
bool IsByteAligned(int bits) => bits % 8 == 0;
Try / catch
try { var d = new Sha512tDigest(bits); }
catch (ArgumentException ex) when (ex.ParamName == "bitLength") { bits = (bits / 8 + 1) * 8; d = new Sha512tDigest(bits); } Prevention
- Convert byte lengths to bits with * 8 before passing.
- Reject user-supplied bit sizes that are not byte-aligned at config load time.
- Add unit tests covering boundary sizes (0, 8, 504, 511).
When it happens
Trigger: new Sha512tDigest(bitLength) with a bitLength not divisible by 8, e.g. 253 or 511.
Common situations: Parsing a bit size from a string like 'SHA-512/254' or computing bitLength from bytes incorrectly (multiplying by 4 instead of 8).
Related errors
- cannot be >= 512
- cannot be 384 use SHA384 instead
- baseDigest output not large enough to support length
- BLAKE2b digest bit length must be a multiple of 8 and not gr
- Invalid digest length (required: 1 - 64)
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/8c115e7fda497912.
Report an issue: GitHub.