peass-ng/PEASS-ng · error · ArgumentException
Invalid parameter passed to Threefish init -
Error message
Invalid parameter passed to Threefish init -
What it means
ThreefishEngine.Init only accepts KeyParameter (key only, no tweak) or ParametersWithTweak wrapping a KeyParameter. Any other ICipherParameters type falls through to the else branch and throws ArgumentException, appending the actual type name.
Source
Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/engines/ThreefishEngine.cs:174
public virtual void Init(bool forEncryption, ICipherParameters parameters)
{
byte[] keyBytes;
byte[] tweakBytes;
if (parameters is TweakableBlockCipherParameters)
{
TweakableBlockCipherParameters tParams = (TweakableBlockCipherParameters)parameters;
keyBytes = tParams.Key.GetKey();
tweakBytes = tParams.Tweak;
}
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);
}View on GitHub (pinned to 53fb989abc)
Solutions
- Pass a KeyParameter directly for tweakless operation
- Use new ParametersWithTweak(new KeyParameter(key), tweakBytes) when a tweak is required
- Check the runtime type of your ICipherParameters before calling Init
Example fix
// before engine.Init(true, new ParametersWithIV(new KeyParameter(key), iv)); // after engine.Init(true, new ParametersWithTweak(new KeyParameter(key), tweak));
Defensive patterns
Strategy: type-guard
Validate before calling
if (!(parameters is KeyParameter) && !(parameters is ParametersWithTweak))
throw new ArgumentException("Threefish requires KeyParameter or ParametersWithTweak"); Type guard
bool IsValidThreefishParameters(ICipherParameters p) => p is KeyParameter || (p is ParametersWithTweak wt && wt.Parameters is KeyParameter);
Try / catch
try { engine.Init(forEnc, parameters); }
catch (ArgumentException ex) { /* inspect ex.Message for the offending type name */ } Prevention
- Never reuse AES/CBC Init code (ParametersWithIV) for Threefish
- Wrap key+tweak strictly with ParametersWithTweak
- Type-check ICipherParameters before dispatching to engines
When it happens
Trigger: Calling Init with e.g. ParametersWithIV, ParametersWithRandom, ParametersWithSalt, or null in a position where a KeyParameter/ParametersWithTweak is expected.
Common situations: Copy-pasting Init code written for AES/CBC (which uses ParametersWithIV) and applying it to Threefish; wrapping the wrong parameter class when trying to supply a tweak.
Related errors
- Invalid blocksize - Threefish is defined with block size of
- Threefish key must be same size as block (
- Threefish tweak must be bytes
- Tweak must be words.
- Output buffer too short
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/cd7512ee29a01429.
Report an issue: GitHub.