peass-ng/PEASS-ng · error · ArgumentException

Threefish key must be same size as block (

Error message

Threefish key must be same size as block (

What it means

During Init, the key byte array must match the engine's configured block size in bytes (32, 64, or 128). The engine converts the key into blocksizeWords 64-bit words and throws ArgumentException when the lengths differ.

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/engines/ThreefishEngine.cs:185

			else if (parameters is KeyParameter)
			{
				keyBytes = ((KeyParameter)parameters).GetKey();
				tweakBytes = null;
			}
			else
			{
				throw new ArgumentException("Invalid parameter passed to Threefish init - "
					+ Platform.GetTypeName(parameters));
			}

			ulong[] keyWords = null;
			ulong[] tweakWords = null;

			if (keyBytes != null)
			{
				if (keyBytes.Length != this.blocksizeBytes)
				{
					throw new ArgumentException("Threefish key must be same size as block (" + blocksizeBytes
												+ " bytes)");
				}
				keyWords = new ulong[blocksizeWords];
				for (int i = 0; i < keyWords.Length; i++)
				{
					keyWords[i] = BytesToWord(keyBytes, i * 8);
				}
			}
			if (tweakBytes != null)
			{
				if (tweakBytes.Length != TWEAK_SIZE_BYTES)
				{
					throw new ArgumentException("Threefish tweak must be " + TWEAK_SIZE_BYTES + " bytes");
				}
				tweakWords = new ulong[] { BytesToWord(tweakBytes, 0), BytesToWord(tweakBytes, 8) };
			}
			Init(forEncryption, keyWords, tweakWords);
		}

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Ensure the key length equals the engine block size in bytes (32 for 256-bit, 64 for 512-bit, 128 for 1024-bit)
  2. Construct the engine from the key: new ThreefishEngine(key.Length) then Init with that key
  3. KDF-expand the key to the required size if the source key is shorter

Example fix

// before
var engine = new ThreefishEngine(ThreefishEngine.BLOCKSIZE_512);
engine.Init(true, new KeyParameter(key32));
// after
var engine = new ThreefishEngine(ThreefishEngine.BLOCKSIZE_256);
engine.Init(true, new KeyParameter(key32));
Defensive patterns

Strategy: validation

Validate before calling

if (key == null || key.Length != engine.GetBlockSize())
    throw new ArgumentException("Threefish key length must equal block size (32/64/128 bytes)");
engine.Init(forEncryption, new KeyParameter(key));

Type guard

bool IsValidThreefishKey(ThreefishEngine e, byte[] key) => key != null && key.Length == e.GetBlockSize();

Try / catch

try { engine.Init(forEnc, new KeyParameter(key)); }
catch (ArgumentException ex) { /* reject key, re-derive at correct size */ }

Prevention

When it happens

Trigger: Creating ThreefishEngine(BLOCKSIZE_512) but calling Init with a 32-byte key (or vice versa); any key length not equal to blocksizeBytes.

Common situations: Mixing Threefish-256 key with a Threefish-1024 engine; deriving a key whose size was computed for a different variant; truncating a hex-decoded key.

Related errors


AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02). Data as JSON: /api/errors/898e9f6756054035. Report an issue: GitHub.