Files
27Aug2021-Cpp2IL-Dump/Assembly-CSharp/BestHTTP/SecureProtocol/Org/BouncyCastle/Crypto/Engines/NaccacheSternEngine.cs
T
niko c12fbe3fc6 m
2026-04-12 16:51:38 +02:00

351 lines
12 KiB
C#

using System;
using System.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using Cpp2IlInjected;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines
{
// Token: 0x02001D78 RID: 7544
[Token(Token = "0x2001D78")]
public class NaccacheSternEngine : IAsymmetricBlockCipher
{
// Token: 0x17001D72 RID: 7538
// (get) Token: 0x0600BBB9 RID: 48057 RVA: 0x00295DD8 File Offset: 0x00293FD8
[Token(Token = "0x17001D72")]
public string AlgorithmName
{
[Token(Token = "0x600BBB9")]
[Address(RVA = "0x272A5E0", Offset = "0x27295E0", VA = "0x18272A5E0", Slot = "4")]
get
{
return "NaccacheStern";
}
}
// Token: 0x0600BBBA RID: 48058 RVA: 0x00295DEC File Offset: 0x00293FEC
[Token(Token = "0x600BBBA")]
[Address(RVA = "0x2729430", Offset = "0x2728430", VA = "0x182729430", Slot = "9")]
public virtual void Init(bool forEncryption, ICipherParameters parameters)
{
for (;;)
{
this.forEncryption = forEncryption;
if (parameters == 0 || ((parameters == 0 || (parameters != 0 && parameters != 0)) && (parameters == 0 || parameters != 0)))
{
int num = 0;
this.key = num;
if (forEncryption)
{
return;
}
int num2 = 0;
if (num != 0)
{
IList[] array = new IList[num2];
if (0 >= array)
{
return;
}
if (array != 0)
{
break;
}
}
}
}
int num3;
IList list = Platform.CreateArrayList(num3);
throw new ArrayTypeMismatchException();
}
// Token: 0x17001D73 RID: 7539
// (set) Token: 0x0600BBBB RID: 48059 RVA: 0x0000220F File Offset: 0x0000040F
[Token(Token = "0x17001D73")]
[Obsolete]
public virtual bool Debug
{
[Token(Token = "0x600BBBB")]
[Address(RVA = "0x4242D0", Offset = "0x4232D0", VA = "0x1804242D0", Slot = "10")]
set
{
throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
}
}
// Token: 0x0600BBBC RID: 48060 RVA: 0x00295E84 File Offset: 0x00294084
[Token(Token = "0x600BBBC")]
[Address(RVA = "0x2729370", Offset = "0x2728370", VA = "0x182729370", Slot = "11")]
public virtual int GetInputBlockSize()
{
NaccacheSternKeyParameters naccacheSternKeyParameters = this.key;
if (!this.forEncryption)
{
BigInteger n = naccacheSternKeyParameters.n;
int num = 0;
int num2 = n.BitLength;
num2 += num;
return num2 + 1;
}
int lowerSigmaBound = naccacheSternKeyParameters.lowerSigmaBound;
return lowerSigmaBound + 7;
}
// Token: 0x0600BBBD RID: 48061 RVA: 0x00295ED4 File Offset: 0x002940D4
[Token(Token = "0x600BBBD")]
[Address(RVA = "0x27293D0", Offset = "0x27283D0", VA = "0x1827293D0", Slot = "12")]
public virtual int GetOutputBlockSize()
{
NaccacheSternKeyParameters naccacheSternKeyParameters = this.key;
if (!this.forEncryption)
{
int lowerSigmaBound = naccacheSternKeyParameters.lowerSigmaBound;
return lowerSigmaBound + 7;
}
BigInteger n = naccacheSternKeyParameters.n;
int num = 0;
int num2 = n.BitLength;
num2 += num;
return num2 + 1;
}
// Token: 0x0600BBBE RID: 48062 RVA: 0x00295F24 File Offset: 0x00294124
[Token(Token = "0x600BBBE")]
[Address(RVA = "0x27298D0", Offset = "0x27288D0", VA = "0x1827298D0", Slot = "13")]
public virtual byte[] ProcessBlock(byte[] inBytes, int inOff, int length)
{
if (this.key != (ulong)0L)
{
if (!this.forEncryption)
{
}
BigInteger bigInteger = new BigInteger(1, inBytes, length, length);
int num = 0;
if ((this.forEncryption ? 1 : 0) == num)
{
IList list = Platform.CreateArrayList();
if (num >= list)
{
BigInteger bigInteger2;
return bigInteger2.ToByteArray();
}
int num2 = 0;
BigInteger bigInteger4;
BigInteger bigInteger3 = bigInteger.ModPow(bigInteger4, num2);
IList list2 = this.lookup[num];
int intValue = bigInteger3.IntValue;
if (intValue != -1)
{
BigInteger bigInteger5 = BigInteger.ValueOf((long)intValue);
num++;
object[] array = new object[6];
throw new ArrayTypeMismatchException();
}
goto IL_B5;
}
}
InvalidOperationException ex = new InvalidOperationException("NaccacheStern engine not initialised");
IL_B5:
InvalidCipherTextException ex2 = new InvalidCipherTextException("Lookup failed");
inBytes[1] = (byte)length;
throw new ArrayTypeMismatchException();
}
// Token: 0x0600BBBF RID: 48063 RVA: 0x00296068 File Offset: 0x00294268
[Token(Token = "0x600BBBF")]
[Address(RVA = "0x2729280", Offset = "0x2728280", VA = "0x182729280", Slot = "14")]
public virtual byte[] Encrypt(BigInteger plain)
{
BigInteger n = this.key.n;
int num = 0;
int bitLength = n.BitLength;
num += bitLength;
num++;
byte[] array = new byte[num];
NaccacheSternKeyParameters naccacheSternKeyParameters = this.key;
BigInteger g = naccacheSternKeyParameters.g;
BigInteger n2 = naccacheSternKeyParameters.n;
byte[] array2 = g.ModPow(plain, n2).ToByteArray();
int length = array2.Length;
int num2 = array.Length;
int num3 = 0;
num2 -= length;
Array.Copy(array2, num3, array, num2, length);
return array;
}
// Token: 0x0600BBC0 RID: 48064 RVA: 0x002960F4 File Offset: 0x002942F4
[Token(Token = "0x600BBC0")]
[Address(RVA = "0x2729040", Offset = "0x2728040", VA = "0x182729040", Slot = "15")]
public virtual byte[] AddCryptedBlocks(byte[] block1, byte[] block2)
{
if (!this.forEncryption)
{
}
int inputBlockSize = this.GetInputBlockSize();
int inputBlockSize2 = this.GetInputBlockSize();
BigInteger bigInteger = new BigInteger(1, block1);
BigInteger bigInteger2 = new BigInteger(1, block2);
BigInteger bigInteger3 = bigInteger.Multiply(bigInteger2);
BigInteger n = this.key.n;
BigInteger bigInteger4 = bigInteger3.Mod(n);
BigInteger n2 = this.key.n;
int num = 0;
int bitLength = n2.BitLength;
num += bitLength;
num++;
byte[] array = new byte[num];
byte[] array2 = bigInteger4.ToByteArray();
int length = array2.Length;
int num2 = array.Length;
int num3 = 0;
num2 -= length;
Array.Copy(array2, num3, array, num2, length);
return array;
}
// Token: 0x0600BBC1 RID: 48065 RVA: 0x002961B4 File Offset: 0x002943B4
[Token(Token = "0x600BBC1")]
[Address(RVA = "0x2729F30", Offset = "0x2728F30", VA = "0x182729F30", Slot = "16")]
public virtual byte[] ProcessData(byte[] data)
{
/*
An exception occurred when decompiling this method (0600BBC1)
ICSharpCode.Decompiler.DecompilerException: Error decompiling System.Byte[] BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines.NaccacheSternEngine::ProcessData(System.Byte[])
---> System.Exception: Basic block has to end with unconditional control flow.
{
IL_7D:
stloc:InvalidCipherTextException(var_13_87, newobj:InvalidCipherTextException(InvalidCipherTextException::.ctor, ldstr:string("cipher returned null")))
}
at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.FlattenBasicBlocks(ILNode node) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\ILAst\ILAstOptimizer.cs:line 1852
at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.FlattenBasicBlocks(ILNode node) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\ILAst\ILAstOptimizer.cs:line 1878
at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.FlattenBasicBlocks(ILNode node) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\ILAst\ILAstOptimizer.cs:line 1878
at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.FlattenBasicBlocks(ILNode node) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\ILAst\ILAstOptimizer.cs:line 1846
at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.FlattenBasicBlocks(ILNode node) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\ILAst\ILAstOptimizer.cs:line 1878
at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.FlattenBasicBlocks(ILNode node) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\ILAst\ILAstOptimizer.cs:line 1878
at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.FlattenBasicBlocks(ILNode node) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\ILAst\ILAstOptimizer.cs:line 1846
at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.Optimize(DecompilerContext context, ILBlock method, AutoPropertyProvider autoPropertyProvider, StateMachineKind& stateMachineKind, MethodDef& inlinedMethod, AsyncMethodDebugInfo& asyncInfo, ILAstOptimizationStep abortBeforeStep) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\ILAst\ILAstOptimizer.cs:line 355
at ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(IEnumerable`1 parameters, MethodDebugInfoBuilder& builder) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\Ast\AstMethodBodyBuilder.cs:line 123
at ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(MethodDef methodDef, DecompilerContext context, AutoPropertyProvider autoPropertyProvider, IEnumerable`1 parameters, Boolean valueParameterIsKeyword, StringBuilder sb, MethodDebugInfoBuilder& stmtsBuilder) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\Ast\AstMethodBodyBuilder.cs:line 88
--- End of inner exception stack trace ---
at ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(MethodDef methodDef, DecompilerContext context, AutoPropertyProvider autoPropertyProvider, IEnumerable`1 parameters, Boolean valueParameterIsKeyword, StringBuilder sb, MethodDebugInfoBuilder& stmtsBuilder) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\Ast\AstMethodBodyBuilder.cs:line 92
at ICSharpCode.Decompiler.Ast.AstBuilder.AddMethodBody(EntityDeclaration methodNode, EntityDeclaration& updatedNode, MethodDef method, IEnumerable`1 parameters, Boolean valueParameterIsKeyword, MethodKind methodKind) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\Ast\AstBuilder.cs:line 1663
*/;
}
// Token: 0x0600BBC2 RID: 48066 RVA: 0x0029624C File Offset: 0x0029444C
[Token(Token = "0x600BBC2")]
[Address(RVA = "0x272A110", Offset = "0x2729110", VA = "0x18272A110")]
private static BigInteger chineseRemainder(IList congruences, IList primes)
{
int num;
BigInteger zero;
BigInteger bigInteger;
BigInteger bigInteger4;
for (;;)
{
num = 0;
zero = BigInteger.Zero;
BigInteger one = BigInteger.One;
num += num;
num++;
uint num2;
if (num < (int)num2)
{
num += num;
num++;
}
if (num == 0)
{
num += num;
num++;
num += 19;
num += num;
num += 19;
}
if (num != 0)
{
int num3 = 0;
bigInteger = one.Multiply(num);
num++;
if (num < num3)
{
num += num;
num++;
}
if (num >= num)
{
goto IL_EE;
}
uint num4;
if (num < (int)num4)
{
num += num;
num++;
}
if (num == 0)
{
num++;
num += 19;
num += 19;
}
if (num != 0)
{
BigInteger bigInteger2 = bigInteger.Divide(num);
BigInteger bigInteger3 = bigInteger2.ModInverse(num);
int num5 = 0;
bigInteger4 = bigInteger2.Multiply(bigInteger3);
if (num < num5)
{
num += num;
num++;
}
if (num == 0)
{
num += num;
num += 19;
}
if (num != 0)
{
break;
}
}
}
}
BigInteger bigInteger5 = bigInteger4.Multiply(num);
BigInteger bigInteger6 = zero.Add(bigInteger5);
num++;
IL_EE:
return bigInteger6.Mod(bigInteger);
}
// Token: 0x0600BBC3 RID: 48067 RVA: 0x00296358 File Offset: 0x00294558
[Token(Token = "0x600BBC3")]
[Address(RVA = "0x412370", Offset = "0x411370", VA = "0x180412370")]
public NaccacheSternEngine()
{
int num = 0;
this.Debug = num != 0;
}
// Token: 0x04007664 RID: 30308
[FieldOffset(Offset = "0x10")]
[Token(Token = "0x4007664")]
private bool forEncryption;
// Token: 0x04007665 RID: 30309
[FieldOffset(Offset = "0x18")]
[Token(Token = "0x4007665")]
private NaccacheSternKeyParameters key;
// Token: 0x04007666 RID: 30310
[FieldOffset(Offset = "0x20")]
[Token(Token = "0x4007666")]
private IList[] lookup;
}
}