328 lines
14 KiB
C#
328 lines
14 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Digests;
|
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities;
|
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
|
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC;
|
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC.Multiplier;
|
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
|
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
|
using Cpp2IlInjected;
|
|
|
|
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines
|
|
{
|
|
// Token: 0x020016CD RID: 5837
|
|
[Token(Token = "0x20016CD")]
|
|
[StructLayout(3)]
|
|
public class SM2Engine
|
|
{
|
|
// Token: 0x06009CD4 RID: 40148 RVA: 0x00239CD0 File Offset: 0x00237ED0
|
|
[Token(Token = "0x6009CD4")]
|
|
[Address(RVA = "0x20FEDF0", Offset = "0x20FD7F0", VA = "0x1820FEDF0")]
|
|
public SM2Engine()
|
|
{
|
|
SM3Digest sm3Digest = new SM3Digest();
|
|
base..ctor();
|
|
this.mDigest = sm3Digest;
|
|
}
|
|
|
|
// Token: 0x06009CD5 RID: 40149 RVA: 0x00239CF0 File Offset: 0x00237EF0
|
|
[Token(Token = "0x6009CD5")]
|
|
[Address(RVA = "0x3C3A30", Offset = "0x3C2430", VA = "0x1803C3A30")]
|
|
public SM2Engine(IDigest digest)
|
|
{
|
|
this.mDigest = digest;
|
|
}
|
|
|
|
// Token: 0x06009CD6 RID: 40150 RVA: 0x00239D0C File Offset: 0x00237F0C
|
|
[Token(Token = "0x6009CD6")]
|
|
[Address(RVA = "0x20FE640", Offset = "0x20FD040", VA = "0x1820FE640", Slot = "4")]
|
|
public virtual void Init(bool forEncryption, ICipherParameters param)
|
|
{
|
|
bool flag;
|
|
for (;;)
|
|
{
|
|
this.mForEncryption = forEncryption;
|
|
if (!forEncryption)
|
|
{
|
|
if (param == 0)
|
|
{
|
|
}
|
|
int num = 0;
|
|
if (param == 0)
|
|
{
|
|
continue;
|
|
}
|
|
this.mECKey = param;
|
|
this.mECParams = num;
|
|
}
|
|
if (param != 0)
|
|
{
|
|
if (typeof(ParametersWithRandom).TypeHandle == 0)
|
|
{
|
|
}
|
|
if (typeof(ParametersWithRandom).TypeHandle != 0)
|
|
{
|
|
this.mECKey = typeof(ParametersWithRandom).TypeHandle;
|
|
this.mECParams = param;
|
|
if (typeof(ParametersWithRandom).TypeHandle != 0 && typeof(ParametersWithRandom).TypeHandle != 0 && !flag)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this.mRandom = flag;
|
|
string text = this.mECParams.curve.ToString();
|
|
this.mCurveLength = text;
|
|
}
|
|
|
|
// Token: 0x06009CD7 RID: 40151 RVA: 0x00239DA8 File Offset: 0x00237FA8
|
|
[Token(Token = "0x6009CD7")]
|
|
[Address(RVA = "0x20FED40", Offset = "0x20FD740", VA = "0x1820FED40", Slot = "5")]
|
|
public virtual byte[] ProcessBlock(byte[] input, int inOff, int inLen)
|
|
{
|
|
if (!this.mForEncryption)
|
|
{
|
|
return this.Decrypt(input, inOff, inLen);
|
|
}
|
|
return this.Encrypt(input, inOff, inLen);
|
|
}
|
|
|
|
// Token: 0x06009CD8 RID: 40152 RVA: 0x00239DD4 File Offset: 0x00237FD4
|
|
[Token(Token = "0x6009CD8")]
|
|
[Address(RVA = "0x20FDC40", Offset = "0x20FC640", VA = "0x1820FDC40", Slot = "6")]
|
|
protected virtual ECMultiplier CreateBasePointMultiplier()
|
|
{
|
|
/*
|
|
An exception occurred when decompiling this method (06009CD8)
|
|
|
|
ICSharpCode.Decompiler.DecompilerException: Error decompiling BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC.Multiplier.ECMultiplier BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines.SM2Engine::CreateBasePointMultiplier()
|
|
|
|
---> System.Exception: Basic block has to end with unconditional control flow.
|
|
{
|
|
Block_0:
|
|
stloc:FixedPointCombMultiplier(var_0_05, newobj:FixedPointCombMultiplier(FixedPointCombMultiplier::.ctor))
|
|
}
|
|
|
|
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.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: 0x06009CD9 RID: 40153 RVA: 0x00239DE8 File Offset: 0x00237FE8
|
|
[Token(Token = "0x6009CD9")]
|
|
[Address(RVA = "0x20FE0F0", Offset = "0x20FCAF0", VA = "0x1820FE0F0")]
|
|
private byte[] Encrypt(byte[] input, int inOff, int inLen)
|
|
{
|
|
byte[] array;
|
|
int num2;
|
|
int num9;
|
|
for (;;)
|
|
{
|
|
array = new byte[inLen];
|
|
int length = array.Length;
|
|
int num = 0;
|
|
Array.Copy(input, inLen, array, num, length);
|
|
num2 = this.mECParams.n.BitLength;
|
|
SecureRandom secureRandom = this.mRandom;
|
|
BigInteger bigInteger = new BigInteger(num2, secureRandom);
|
|
while (bigInteger.sign == 0)
|
|
{
|
|
}
|
|
BigInteger n = this.mECParams.n;
|
|
int num3 = 0;
|
|
int num4 = bigInteger.CompareTo(n);
|
|
ECPoint g = this.mECParams.g;
|
|
int num5 = 0;
|
|
if (num5 < num3)
|
|
{
|
|
num5 += num5;
|
|
num5++;
|
|
}
|
|
int num6 = 0;
|
|
ulong num8;
|
|
int num7 = num8.CompareTo((ulong)num6);
|
|
ECKeyParameters eckeyParameters = this.mECKey;
|
|
num2 = num7;
|
|
num8 += num8;
|
|
num7 += 19;
|
|
if (eckeyParameters != 0)
|
|
{
|
|
num9 = 0;
|
|
if (eckeyParameters != 0)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
int length2 = array.Length;
|
|
while (num9 == length2)
|
|
{
|
|
}
|
|
num9++;
|
|
IDigest digest = this.mDigest;
|
|
byte[] array2 = DigestUtilities.DoFinal(this.mDigest);
|
|
byte[][] array3 = new byte[3][];
|
|
if (num2 != 0)
|
|
{
|
|
}
|
|
array3[0] = num2;
|
|
array3[1] = array;
|
|
if (array2 != 0)
|
|
{
|
|
}
|
|
array3[2] = array2;
|
|
return Arrays.ConcatenateAll(array3);
|
|
}
|
|
|
|
// Token: 0x06009CDA RID: 40154 RVA: 0x00239F24 File Offset: 0x00238124
|
|
[Token(Token = "0x6009CDA")]
|
|
[Address(RVA = "0x20FDC90", Offset = "0x20FC690", VA = "0x1820FDC90")]
|
|
private byte[] Decrypt(byte[] input, int inOff, int inLen)
|
|
{
|
|
/*
|
|
An exception occurred when decompiling this method (06009CDA)
|
|
|
|
ICSharpCode.Decompiler.DecompilerException: Error decompiling System.Byte[] BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines.SM2Engine::Decrypt(System.Byte[],System.Int32,System.Int32)
|
|
|
|
---> System.Exception: Basic block has to end with unconditional control flow.
|
|
{
|
|
IL_139:
|
|
stloc:int32(var_28_13A, ldc.i4:int32(0))
|
|
call:void(Arrays::Fill, ldloc:uint8[](var_13_6C), ldloc:int32[exp:uint8](var_28_13A))
|
|
stloc:InvalidCipherTextException(var_29_14F, newobj:InvalidCipherTextException(InvalidCipherTextException::.ctor, ldstr:string("invalid cipher text")))
|
|
}
|
|
|
|
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.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: 0x06009CDB RID: 40155 RVA: 0x0023A084 File Offset: 0x00238284
|
|
[Token(Token = "0x6009CDB")]
|
|
[Address(RVA = "0x20FECC0", Offset = "0x20FD6C0", VA = "0x1820FECC0")]
|
|
private bool NotEncrypted(byte[] encData, byte[] input, int inOff)
|
|
{
|
|
int num = 0;
|
|
int length = encData.Length;
|
|
if (num != length)
|
|
{
|
|
num++;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// Token: 0x06009CDC RID: 40156 RVA: 0x0023A0AC File Offset: 0x002382AC
|
|
[Token(Token = "0x6009CDC")]
|
|
[Address(RVA = "0x20FE900", Offset = "0x20FD300", VA = "0x1820FE900")]
|
|
private void Kdf(IDigest digest, ECPoint c1, byte[] encData)
|
|
{
|
|
int num;
|
|
byte[] array = new byte[num];
|
|
int num2 = 0;
|
|
if (array != 0)
|
|
{
|
|
int curveCoordinateSystem = c1.CurveCoordinateSystem;
|
|
ECFieldElement affineXCoord = c1.AffineXCoord;
|
|
this.AddFieldElement(digest, affineXCoord);
|
|
num2 += num2;
|
|
num2++;
|
|
}
|
|
int num3 = 0;
|
|
if (num3 < encData.Length)
|
|
{
|
|
if (array == 0)
|
|
{
|
|
int curveCoordinateSystem2 = c1.CurveCoordinateSystem;
|
|
ECFieldElement affineXCoord2 = c1.AffineXCoord;
|
|
this.AddFieldElement(digest, affineXCoord2);
|
|
}
|
|
int num4 = 0;
|
|
Pack.UInt32_To_BE((uint)1, array, num4);
|
|
int num5 = encData.Length;
|
|
num5 -= num2;
|
|
int num6;
|
|
this.Xor(encData, array, num2, num6);
|
|
num2 += num6;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06009CDD RID: 40157 RVA: 0x0023A148 File Offset: 0x00238348
|
|
[Token(Token = "0x6009CDD")]
|
|
[Address(RVA = "0x20FED70", Offset = "0x20FD770", VA = "0x1820FED70")]
|
|
private void Xor(byte[] data, byte[] kdfOut, int dOff, int dRemaining)
|
|
{
|
|
int num = 0;
|
|
num++;
|
|
}
|
|
|
|
// Token: 0x06009CDE RID: 40158 RVA: 0x0023A164 File Offset: 0x00238364
|
|
[Token(Token = "0x6009CDE")]
|
|
[Address(RVA = "0x20FEC00", Offset = "0x20FD600", VA = "0x1820FEC00")]
|
|
private BigInteger NextK()
|
|
{
|
|
int bitLength = this.mECParams.n.BitLength;
|
|
SecureRandom secureRandom = this.mRandom;
|
|
BigInteger bigInteger = new BigInteger(bitLength, secureRandom);
|
|
while (bigInteger.sign == 0)
|
|
{
|
|
}
|
|
BigInteger n = this.mECParams.n;
|
|
int num = bigInteger.CompareTo(n);
|
|
return bigInteger;
|
|
}
|
|
|
|
// Token: 0x06009CDF RID: 40159 RVA: 0x0023A1B8 File Offset: 0x002383B8
|
|
[Token(Token = "0x6009CDF")]
|
|
[Address(RVA = "0x20FDBB0", Offset = "0x20FC5B0", VA = "0x1820FDBB0")]
|
|
private void AddFieldElement(IDigest digest, ECFieldElement v)
|
|
{
|
|
}
|
|
|
|
// Token: 0x040066CB RID: 26315
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x10")]
|
|
[Token(Token = "0x40066CB")]
|
|
private readonly IDigest mDigest;
|
|
|
|
// Token: 0x040066CC RID: 26316
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x18")]
|
|
[Token(Token = "0x40066CC")]
|
|
private bool mForEncryption;
|
|
|
|
// Token: 0x040066CD RID: 26317
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x20")]
|
|
[Token(Token = "0x40066CD")]
|
|
private ECKeyParameters mECKey;
|
|
|
|
// Token: 0x040066CE RID: 26318
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x28")]
|
|
[Token(Token = "0x40066CE")]
|
|
private ECDomainParameters mECParams;
|
|
|
|
// Token: 0x040066CF RID: 26319
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x30")]
|
|
[Token(Token = "0x40066CF")]
|
|
private int mCurveLength;
|
|
|
|
// Token: 0x040066D0 RID: 26320
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x38")]
|
|
[Token(Token = "0x40066D0")]
|
|
private SecureRandom mRandom;
|
|
}
|
|
}
|