326 lines
14 KiB
C#
326 lines
14 KiB
C#
using System;
|
|
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: 0x02001CAA RID: 7338
|
|
[Token(Token = "0x2001CAA")]
|
|
public class SM2Engine
|
|
{
|
|
// Token: 0x0600B8AE RID: 47278 RVA: 0x00291468 File Offset: 0x0028F668
|
|
[Token(Token = "0x600B8AE")]
|
|
[Address(RVA = "0x1DFBA50", Offset = "0x1DFA850", VA = "0x181DFBA50")]
|
|
public SM2Engine()
|
|
{
|
|
SM3Digest sm3Digest = new SM3Digest();
|
|
base..ctor();
|
|
this.mDigest = sm3Digest;
|
|
}
|
|
|
|
// Token: 0x0600B8AF RID: 47279 RVA: 0x00291488 File Offset: 0x0028F688
|
|
[Token(Token = "0x600B8AF")]
|
|
[Address(RVA = "0x3FFB80", Offset = "0x3FE980", VA = "0x1803FFB80")]
|
|
public SM2Engine(IDigest digest)
|
|
{
|
|
this.mDigest = digest;
|
|
}
|
|
|
|
// Token: 0x0600B8B0 RID: 47280 RVA: 0x002914A4 File Offset: 0x0028F6A4
|
|
[Token(Token = "0x600B8B0")]
|
|
[Address(RVA = "0x1DFB2A0", Offset = "0x1DFA0A0", VA = "0x181DFB2A0", 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: 0x0600B8B1 RID: 47281 RVA: 0x00291540 File Offset: 0x0028F740
|
|
[Token(Token = "0x600B8B1")]
|
|
[Address(RVA = "0x1DFB9A0", Offset = "0x1DFA7A0", VA = "0x181DFB9A0", 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: 0x0600B8B2 RID: 47282 RVA: 0x0029156C File Offset: 0x0028F76C
|
|
[Token(Token = "0x600B8B2")]
|
|
[Address(RVA = "0x1DFA8A0", Offset = "0x1DF96A0", VA = "0x181DFA8A0", Slot = "6")]
|
|
protected virtual ECMultiplier CreateBasePointMultiplier()
|
|
{
|
|
/*
|
|
An exception occurred when decompiling this method (0600B8B2)
|
|
|
|
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 1660
|
|
*/;
|
|
}
|
|
|
|
// Token: 0x0600B8B3 RID: 47283 RVA: 0x00291580 File Offset: 0x0028F780
|
|
[Token(Token = "0x600B8B3")]
|
|
[Address(RVA = "0x1DFAD50", Offset = "0x1DF9B50", VA = "0x181DFAD50")]
|
|
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: 0x0600B8B4 RID: 47284 RVA: 0x002916BC File Offset: 0x0028F8BC
|
|
[Token(Token = "0x600B8B4")]
|
|
[Address(RVA = "0x1DFA8F0", Offset = "0x1DF96F0", VA = "0x181DFA8F0")]
|
|
private byte[] Decrypt(byte[] input, int inOff, int inLen)
|
|
{
|
|
/*
|
|
An exception occurred when decompiling this method (0600B8B4)
|
|
|
|
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 1660
|
|
*/;
|
|
}
|
|
|
|
// Token: 0x0600B8B5 RID: 47285 RVA: 0x0029181C File Offset: 0x0028FA1C
|
|
[Token(Token = "0x600B8B5")]
|
|
[Address(RVA = "0x1DFB920", Offset = "0x1DFA720", VA = "0x181DFB920")]
|
|
private bool NotEncrypted(byte[] encData, byte[] input, int inOff)
|
|
{
|
|
int num = 0;
|
|
int length = encData.Length;
|
|
if (num != length)
|
|
{
|
|
num++;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// Token: 0x0600B8B6 RID: 47286 RVA: 0x00291844 File Offset: 0x0028FA44
|
|
[Token(Token = "0x600B8B6")]
|
|
[Address(RVA = "0x1DFB560", Offset = "0x1DFA360", VA = "0x181DFB560")]
|
|
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: 0x0600B8B7 RID: 47287 RVA: 0x002918E0 File Offset: 0x0028FAE0
|
|
[Token(Token = "0x600B8B7")]
|
|
[Address(RVA = "0x1DFB9D0", Offset = "0x1DFA7D0", VA = "0x181DFB9D0")]
|
|
private void Xor(byte[] data, byte[] kdfOut, int dOff, int dRemaining)
|
|
{
|
|
int num = 0;
|
|
num++;
|
|
}
|
|
|
|
// Token: 0x0600B8B8 RID: 47288 RVA: 0x002918FC File Offset: 0x0028FAFC
|
|
[Token(Token = "0x600B8B8")]
|
|
[Address(RVA = "0x1DFB860", Offset = "0x1DFA660", VA = "0x181DFB860")]
|
|
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: 0x0600B8B9 RID: 47289 RVA: 0x00291950 File Offset: 0x0028FB50
|
|
[Token(Token = "0x600B8B9")]
|
|
[Address(RVA = "0x1DFA810", Offset = "0x1DF9610", VA = "0x181DFA810")]
|
|
private void AddFieldElement(IDigest digest, ECFieldElement v)
|
|
{
|
|
}
|
|
|
|
// Token: 0x0400750E RID: 29966
|
|
[FieldOffset(Offset = "0x10")]
|
|
[Token(Token = "0x400750E")]
|
|
private readonly IDigest mDigest;
|
|
|
|
// Token: 0x0400750F RID: 29967
|
|
[FieldOffset(Offset = "0x18")]
|
|
[Token(Token = "0x400750F")]
|
|
private bool mForEncryption;
|
|
|
|
// Token: 0x04007510 RID: 29968
|
|
[FieldOffset(Offset = "0x20")]
|
|
[Token(Token = "0x4007510")]
|
|
private ECKeyParameters mECKey;
|
|
|
|
// Token: 0x04007511 RID: 29969
|
|
[FieldOffset(Offset = "0x28")]
|
|
[Token(Token = "0x4007511")]
|
|
private ECDomainParameters mECParams;
|
|
|
|
// Token: 0x04007512 RID: 29970
|
|
[FieldOffset(Offset = "0x30")]
|
|
[Token(Token = "0x4007512")]
|
|
private int mCurveLength;
|
|
|
|
// Token: 0x04007513 RID: 29971
|
|
[FieldOffset(Offset = "0x38")]
|
|
[Token(Token = "0x4007513")]
|
|
private SecureRandom mRandom;
|
|
}
|
|
}
|