{"record":{"id":"b41344e146e40934","repo":"peass-ng/PEASS-ng","slug":"threefish-engine-not-initialised","errorCode":null,"errorMessage":"Threefish engine not initialised","messagePattern":"Threefish engine not initialised","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/engines/ThreefishEngine.cs","lineNumber":323,"sourceCode":"\t\t\t\tWordToBytes(this.currentBlock[i >> 3], outBytes, outOff + i);\n\t\t\t}\n\n\t\t\treturn blocksizeBytes;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Process a block of data represented as 64 bit words.\n\t\t/// </summary>\n\t\t/// <returns>the number of 8 byte words processed (which will be the same as the block size).</returns>\n\t\t/// <param name=\"inWords\">a block sized buffer of words to process.</param>\n\t\t/// <param name=\"outWords\">a block sized buffer of words to receive the output of the operation.</param>\n\t\t/// <exception cref=\"DataLengthException\">if either the input or output is not block sized</exception>\n\t\t/// <exception cref=\"InvalidOperationException\">if this engine is not initialised</exception>\n\t\tinternal int ProcessBlock(ulong[] inWords, ulong[] outWords)\n\t\t{\n\t\t\tif (kw[blocksizeWords] == 0)\n\t\t\t{\n\t\t\t\tthrow new InvalidOperationException(\"Threefish engine not initialised\");\n\t\t\t}\n\n\t\t\tif (inWords.Length != blocksizeWords)\n\t\t\t{\n\t\t\t\tthrow new DataLengthException(\"Input buffer too short\");\n\t\t\t}\n\t\t\tif (outWords.Length != blocksizeWords)\n\t\t\t{\n\t\t\t\tthrow new DataLengthException(\"Output buffer too short\");\n\t\t\t}\n\n\t\t\tif (forEncryption)\n\t\t\t{\n\t\t\t\tcipher.EncryptBlock(inWords, outWords);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tcipher.DecryptBlock(inWords, outWords);","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/engines/ThreefishEngine.cs#L305-L341","documentation":"The internal ProcessBlock(ulong[], ulong[]) throws this InvalidOperationException when kw[blocksizeWords] == 0, i.e. the key-schedule extension word is still zero because Init() was never called (or was called with a null key, the documented way to mean 'not initialised'). Threefish requires a key and tweak to be set before any block can be processed; the parity/extension word doubles as the initialised flag.","triggerScenarios":"Calling ProcessBlock(ulong[] inWords, ulong[] outWords) (directly or via the byte[] overload) before calling Init(true/false, keyParameters), or after Init was passed a null key — ThreefishEngine treats Init(forEncryption, null) as 'de-initialise'.","commonSituations":"Reusing a freshly constructed engine without wiring key parameters; resetting the cipher with a null key and then continuing to process blocks; a code path that constructs the engine lazily but processes eagerly; mixing engines where only one of several got Init called.","solutions":["Call engine.Init(forEncryption, new TweakableBlockCipherParameters(key, tweak, null)) — or the appropriate IBlockCipherParameters — before the first ProcessBlock.","Check initialization state in your wrapper: track a bool set in Init and throw/guard before processing if it's false.","If you reset with a null key, re-Init with a real key before the next ProcessBlock.","Never assume a newly constructed ThreefishEngine is usable: construction and initialisation are separate steps."],"exampleFix":"// before\nvar engine = new ThreefishEngine(256);\nengine.ProcessBlock(input, 0, output, 0); // InvalidOperationException: not initialised\n// after\nvar engine = new ThreefishEngine(256);\nengine.Init(true, new TweakableBlockCipherParameters(new KeyParameter(key), tweak, null));\nengine.ProcessBlock(input, 0, output, 0);","handlingStrategy":"validation","validationCode":"// C#\nif (!initialized)\n    throw new InvalidOperationException(\"Call Init(forEncryption, cipherParameters) before ProcessBlock\");\nengine.Init(forEncryption, new TweakableBlockCipherParameters(new KeyParameter(key), tweak, null));","typeGuard":"bool IsCipherReady(IBlockCipher engine, Func<bool> initTracker) => engine != null && initTracker();","tryCatchPattern":"try\n{\n    engine.ProcessBlock(input, 0, output, 0);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"not initialised\"))\n{\n    throw new CryptographyException(\"Threefish engine used before Init() — supply key and tweak parameters first\", ex);\n}","preventionTips":["Treat construction and Init as one mandatory pair — never expose an un-initialised engine to callers.","Track initialisation with a bool flag set inside your Init wrapper.","Remember Init(forEncryption, null) de-initialises: re-Init with real parameters afterwards.","Centralise cipher creation in a factory that always applies key parameters."],"tags":["csharp","cryptography","not-initialized","threefish"],"backgroundTag":"cipher-not-initialized","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}