{"record":{"id":"cd7512ee29a01429","repo":"peass-ng/PEASS-ng","slug":"invalid-parameter-passed-to-threefish-init","errorCode":null,"errorMessage":"Invalid parameter passed to Threefish init - ","messagePattern":"Invalid parameter passed to Threefish init - ","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/engines/ThreefishEngine.cs","lineNumber":174,"sourceCode":"\t\tpublic virtual void Init(bool forEncryption, ICipherParameters parameters)\n\t\t{\n\t\t\tbyte[] keyBytes;\n\t\t\tbyte[] tweakBytes;\n\n\t\t\tif (parameters is TweakableBlockCipherParameters)\n\t\t\t{\n\t\t\t\tTweakableBlockCipherParameters tParams = (TweakableBlockCipherParameters)parameters;\n\t\t\t\tkeyBytes = tParams.Key.GetKey();\n\t\t\t\ttweakBytes = tParams.Tweak;\n\t\t\t}\n\t\t\telse if (parameters is KeyParameter)\n\t\t\t{\n\t\t\t\tkeyBytes = ((KeyParameter)parameters).GetKey();\n\t\t\t\ttweakBytes = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tthrow new ArgumentException(\"Invalid parameter passed to Threefish init - \"\n\t\t\t\t\t+ Platform.GetTypeName(parameters));\n\t\t\t}\n\n\t\t\tulong[] keyWords = null;\n\t\t\tulong[] tweakWords = null;\n\n\t\t\tif (keyBytes != null)\n\t\t\t{\n\t\t\t\tif (keyBytes.Length != this.blocksizeBytes)\n\t\t\t\t{\n\t\t\t\t\tthrow new ArgumentException(\"Threefish key must be same size as block (\" + blocksizeBytes\n\t\t\t\t\t\t\t\t\t\t\t\t+ \" bytes)\");\n\t\t\t\t}\n\t\t\t\tkeyWords = new ulong[blocksizeWords];\n\t\t\t\tfor (int i = 0; i < keyWords.Length; i++)\n\t\t\t\t{\n\t\t\t\t\tkeyWords[i] = BytesToWord(keyBytes, i * 8);\n\t\t\t\t}","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/engines/ThreefishEngine.cs#L156-L192","documentation":"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.","triggerScenarios":"Calling Init with e.g. ParametersWithIV, ParametersWithRandom, ParametersWithSalt, or null in a position where a KeyParameter/ParametersWithTweak is expected.","commonSituations":"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.","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"],"exampleFix":"// before\nengine.Init(true, new ParametersWithIV(new KeyParameter(key), iv));\n// after\nengine.Init(true, new ParametersWithTweak(new KeyParameter(key), tweak));","handlingStrategy":"type-guard","validationCode":"if (!(parameters is KeyParameter) && !(parameters is ParametersWithTweak))\n    throw new ArgumentException(\"Threefish requires KeyParameter or ParametersWithTweak\");","typeGuard":"bool IsValidThreefishParameters(ICipherParameters p) => p is KeyParameter || (p is ParametersWithTweak wt && wt.Parameters is KeyParameter);","tryCatchPattern":"try { engine.Init(forEnc, parameters); }\ncatch (ArgumentException ex) { /* inspect ex.Message for the offending type name */ }","preventionTips":["Never reuse AES/CBC Init code (ParametersWithIV) for Threefish","Wrap key+tweak strictly with ParametersWithTweak","Type-check ICipherParameters before dispatching to engines"],"tags":["csharp","cryptography","threefish","parameters"],"backgroundTag":"unsupported-cipher-parameters","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}