{"record":{"id":"33c1eabedf7a318e","repo":"peass-ng/PEASS-ng","slug":"invalid-s-box-passed-to-gost28147-init","errorCode":null,"errorMessage":"invalid S-box passed to GOST28147 init","messagePattern":"invalid S-box passed to GOST28147 init","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/engines/Gost28147Engine.cs","lineNumber":165,"sourceCode":"\t\t*\n\t\t* @param forEncryption whether or not we are for encryption.\n\t\t* @param parameters the parameters required to set up the cipher.\n\t\t* @exception ArgumentException if the parameters argument is inappropriate.\n\t\t*/\n\t\tpublic virtual void Init(\n\t\t\tbool forEncryption,\n\t\t\tICipherParameters parameters)\n\t\t{\n\t\t\tif (parameters is ParametersWithSBox)\n\t\t\t{\n\t\t\t\tParametersWithSBox param = (ParametersWithSBox)parameters;\n\n\t\t\t\t//\n\t\t\t\t// Set the S-Box\n\t\t\t\t//\n\t\t\t\tbyte[] sBox = param.GetSBox();\n\t\t\t\tif (sBox.Length != Sbox_Default.Length)\n\t\t\t\t\tthrow new ArgumentException(\"invalid S-box passed to GOST28147 init\");\n\n\t\t\t\tthis.S = Arrays.Clone(sBox);\n\n\t\t\t\t//\n\t\t\t\t// set key if there is one\n\t\t\t\t//\n\t\t\t\tif (param.Parameters != null)\n\t\t\t\t{\n\t\t\t\t\tworkingKey = generateWorkingKey(forEncryption,\n\t\t\t\t\t\t\t((KeyParameter)param.Parameters).GetKey());\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (parameters is KeyParameter)\n\t\t\t{\n\t\t\t\tworkingKey = generateWorkingKey(forEncryption,\n\t\t\t\t\t\t\t\t\t((KeyParameter)parameters).GetKey());\n\t\t\t}\n\t\t\telse if (parameters != null)","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/engines/Gost28147Engine.cs#L147-L183","documentation":"Gost28147Engine.Init throws this ArgumentException when a ParametersWithSBox carries an S-box byte[] whose length differs from the default (8x16 = 128 bytes expected). GOST 28147 substitution blocks must have the same size as the built-in default table.","triggerScenarios":"Calling Init with ParametersWithSBox containing a truncated, corrupted, or wrongly-encoded S-box byte[] whose length != Sbox_Default.Length.","commonSituations":"Loading an S-box from a file that includes headers or a different byte order, hand-typed S-box strings decoded incorrectly, or a custom S-box in a non-128-byte representation.","solutions":["Supply a complete 128-byte S-box (8 substitution rows of 16 bytes)","Verify the S-box source encoding (hex/base64) and strip any framing","If unsure, omit the S-box parameter to use the library default"],"exampleFix":"// before\nbyte[] sBox = File.ReadAllBytes(\"sbox.bin\"); // wrong length\nengine.Init(forEncryption, new ParametersWithSBox(new KeyParameter(key), sBox));\n// after\nif (sBox.Length != 128) throw new InvalidOperationException(\"bad sbox\");\nengine.Init(forEncryption, new ParametersWithSBox(new KeyParameter(key), sBox));","handlingStrategy":"validation","validationCode":"if (sBox == null || sBox.Length != 128) throw new ArgumentException(\"GOST S-box must be 128 bytes\");","typeGuard":"static bool IsValidGostSBox(byte[] sBox) => sBox != null && sBox.Length == 128;","tryCatchPattern":"try { engine.Init(forEncryption, new ParametersWithSBox(new KeyParameter(key), sBox)); } catch (ArgumentException ex) { /* fall back to default S-box */ }","preventionTips":["Load S-boxes from trusted, length-checked sources","Validate decoded S-box length before wrapping in ParametersWithSBox","Use the library default S-box when a custom one isn't required"],"tags":["csharp","cryptography","gost","argument-validation"],"backgroundTag":"invalid-sbox-parameter","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}