peass-ng/PEASS-ng · error · InvalidOperationException

Gost28147 engine not initialised

Error message

Gost28147 engine not initialised

What it means

Gost28147Engine.ProcessBlock throws this InvalidOperationException as a state guard because the block cipher's workingKey is null, i.e. Init() was never called (or was called with a null key) before attempting to encrypt or decrypt a block.

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/engines/Gost28147Engine.cs:212

		public virtual bool IsPartialBlockOkay
		{
			get { return false; }
		}

		public virtual int GetBlockSize()
		{
			return BlockSize;
		}

		public virtual int ProcessBlock(
			byte[] input,
			int inOff,
			byte[] output,
			int outOff)
		{
			if (workingKey == null)
				throw new InvalidOperationException("Gost28147 engine not initialised");

			Check.DataLength(input, inOff, BlockSize, "input buffer too short");
			Check.OutputLength(output, outOff, BlockSize, "output buffer too short");

			Gost28147Func(workingKey, input, inOff, output, outOff);

			return BlockSize;
		}

		public virtual void Reset()
		{
		}

		private int[] generateWorkingKey(
			bool forEncryption,
			byte[] userKey)
		{
			this.forEncryption = forEncryption;

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Call engine.Init(forEncryption, new KeyParameter(key)) before ProcessBlock
  2. Ensure the earlier Init actually reached the key-generation branch (valid KeyParameter/SBox params)
  3. Re-create or re-Init the engine after any initialization failure

Example fix

// before
var gost = new Gost28147Engine();
gost.ProcessBlock(input, 0, output, 0);
// after
var gost = new Gost28147Engine();
gost.Init(true, new KeyParameter(key));
gost.ProcessBlock(input, 0, output, 0);
Defensive patterns

Strategy: try-catch

Validate before calling

if (!initialized) engine.Init(forEncryption, new KeyParameter(key));

Type guard

static bool IsGostReady(Gost28147Engine e) => e != null; // workingKey is private; track init yourself

Try / catch

try { engine.ProcessBlock(input, 0, output, 0); } catch (InvalidOperationException ex) { /* Init then retry once */ }

Prevention

When it happens

Trigger: Calling ProcessBlock before Init, after Init was called with null parameters only (no key), or after a prior Init threw (bad S-box or wrong parameter type).

Common situations: An earlier invalid-parameter ArgumentException swallowed by caller, a two-phase init where the key-setting branch never executed, or reuse across threads without initialization.

Related errors


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