peass-ng/PEASS-ng · error · ArgumentException

Invalid blocksize - Threefish is defined with block size of

Error message

Invalid blocksize - Threefish is defined with block size of 256, 512, or 1024 bits

What it means

The ThreefishEngine constructor selects a cipher implementation based on the requested block size; only 256, 512 and 1024 bits are defined by the Threefish algorithm. Any other blocksize value reaches the default case and throws ArgumentException.

Source

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

			/*
	         * Provide room for original key words, extended key word and repeat of key words for modulo
	         * free lookup of key schedule words.
	         */
			this.kw = new ulong[2 * blocksizeWords + 1];

			switch (blocksizeBits)
			{
				case BLOCKSIZE_256:
					cipher = new Threefish256Cipher(kw, t);
					break;
				case BLOCKSIZE_512:
					cipher = new Threefish512Cipher(kw, t);
					break;
				case BLOCKSIZE_1024:
					cipher = new Threefish1024Cipher(kw, t);
					break;
				default:
					throw new ArgumentException(
						"Invalid blocksize - Threefish is defined with block size of 256, 512, or 1024 bits");
			}
		}

		/// <summary>
		/// Initialise the engine.
		/// </summary>
		/// <param name="forEncryption">Initialise for encryption if true, for decryption if false.</param>
		/// <param name="parameters">an instance of <see cref="TweakableBlockCipherParameters"/> or <see cref="KeyParameter"/> (to
		///               use a 0 tweak)</param>
		public virtual void Init(bool forEncryption, ICipherParameters parameters)
		{
			byte[] keyBytes;
			byte[] tweakBytes;

			if (parameters is TweakableBlockCipherParameters)
			{
				TweakableBlockCipherParameters tParams = (TweakableBlockCipherParameters)parameters;

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Instantiate with one of the supported sizes: new ThreefishEngine(ThreefishEngine.BLOCKSIZE_256), _512 or _1024
  2. Derive block size from the intended key size (32, 64 or 128 bytes) and validate before constructing
  3. Use the named constants rather than raw integers to avoid unit mistakes

Example fix

// before
var engine = new ThreefishEngine(16);
// after
var engine = new ThreefishEngine(ThreefishEngine.BLOCKSIZE_256);
Defensive patterns

Strategy: validation

Validate before calling

if (blockSizeBytes != 32 && blockSizeBytes != 64 && blockSizeBytes != 128)
    throw new ArgumentException("Threefish block size must be 32, 64 or 128 bytes");
var engine = new ThreefishEngine(blockSizeBytes);

Type guard

bool IsValidThreefishBlocksize(int bytes) => bytes == 32 || bytes == 64 || bytes == 128;

Try / catch

try { var engine = new ThreefishEngine(size); }
catch (ArgumentException ex) { /* map to supported variant or fail fast */ }

Prevention

When it happens

Trigger: Constructing ThreefishEngine with a blocksize argument other than BLOCKSIZE_256 (32), BLOCKSIZE_512 (64) or BLOCKSIZE_1024 (128) bytes — e.g. ThreefishEngine(16) or ThreefishEngine(0).

Common situations: Assuming Threefish supports AES-like 128-bit blocks; computing block size from an input key length (e.g. 128-bit key => 16 bytes); passing bits instead of bytes or vice versa.

Related errors


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