341 lines
14 KiB
C#
341 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.Field;
|
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
|
|
using Cpp2IlInjected;
|
|
|
|
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Agreement
|
|
{
|
|
// Token: 0x02001730 RID: 5936
|
|
[Token(Token = "0x2001730")]
|
|
[StructLayout(3)]
|
|
public class SM2KeyExchange
|
|
{
|
|
// Token: 0x0600A076 RID: 41078 RVA: 0x002547D8 File Offset: 0x002529D8
|
|
[Token(Token = "0x600A076")]
|
|
[Address(RVA = "0x665130", Offset = "0x663B30", VA = "0x180665130")]
|
|
public SM2KeyExchange()
|
|
{
|
|
SM3Digest sm3Digest = new SM3Digest();
|
|
base..ctor();
|
|
this.mDigest = sm3Digest;
|
|
}
|
|
|
|
// Token: 0x0600A077 RID: 41079 RVA: 0x002547F8 File Offset: 0x002529F8
|
|
[Token(Token = "0x600A077")]
|
|
[Address(RVA = "0x3C3A30", Offset = "0x3C2430", VA = "0x1803C3A30")]
|
|
public SM2KeyExchange(IDigest digest)
|
|
{
|
|
this.mDigest = digest;
|
|
}
|
|
|
|
// Token: 0x0600A078 RID: 41080 RVA: 0x00254814 File Offset: 0x00252A14
|
|
[Token(Token = "0x600A078")]
|
|
[Address(RVA = "0x664760", Offset = "0x663160", VA = "0x180664760", Slot = "4")]
|
|
public virtual void Init(ICipherParameters privParam)
|
|
{
|
|
while (privParam != 0)
|
|
{
|
|
if ((privParam != 0 || privParam != 0) && privParam != 0 && privParam != 0)
|
|
{
|
|
if (privParam == 0)
|
|
{
|
|
}
|
|
if (privParam != 0 && privParam != 0 && privParam != 0)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
int num = 0;
|
|
byte[] array = new byte[0];
|
|
this.mUserID = array;
|
|
string text = num.ToString();
|
|
this.mInitiator = text != null;
|
|
int num2;
|
|
this.mStaticKey = num2;
|
|
TypeCode typeCode = num.GetTypeCode();
|
|
this.mEphemeralKey = typeCode;
|
|
ECDomainParameters parameters = this.mStaticKey.parameters;
|
|
this.mECParams = parameters;
|
|
string text2;
|
|
this.mStaticPubPoint = text2;
|
|
ECDomainParameters ecdomainParameters = this.mECParams;
|
|
bool flag;
|
|
this.mEphemeralPubPoint = flag;
|
|
string text3 = ecdomainParameters.curve.ToString();
|
|
this.mW = text3;
|
|
}
|
|
|
|
// Token: 0x0600A079 RID: 41081 RVA: 0x002548DC File Offset: 0x00252ADC
|
|
[Token(Token = "0x600A079")]
|
|
[Address(RVA = "0x663FA0", Offset = "0x6629A0", VA = "0x180663FA0", Slot = "5")]
|
|
public virtual byte[] CalculateKey(int kLen, ICipherParameters pubParam)
|
|
{
|
|
while (pubParam != 0)
|
|
{
|
|
if ((pubParam != 0 || pubParam != 0) && pubParam != 0 && pubParam != 0)
|
|
{
|
|
if (pubParam == 0)
|
|
{
|
|
}
|
|
if (pubParam != 0 && pubParam != 0 && pubParam != 0)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
int num = 0;
|
|
byte[] array = new byte[0];
|
|
ECPoint ecpoint = this.mStaticPubPoint;
|
|
byte[] array2 = this.mUserID;
|
|
IDigest digest = this.mDigest;
|
|
byte[] z = this.GetZ(digest, array2, ecpoint);
|
|
IDigest digest2 = this.mDigest;
|
|
string text = num.ToString();
|
|
byte[] z2 = this.GetZ(digest2, array, ecpoint);
|
|
if (!this.mInitiator)
|
|
{
|
|
}
|
|
throw new NullReferenceException();
|
|
}
|
|
|
|
// Token: 0x0600A07A RID: 41082 RVA: 0x0025497C File Offset: 0x00252B7C
|
|
[Token(Token = "0x600A07A")]
|
|
[Address(RVA = "0x6638E0", Offset = "0x6622E0", VA = "0x1806638E0", Slot = "6")]
|
|
public virtual byte[][] CalculateKeyWithConfirmation(int kLen, byte[] confirmationTag, ICipherParameters pubParam)
|
|
{
|
|
/*
|
|
An exception occurred when decompiling this method (0600A07A)
|
|
|
|
ICSharpCode.Decompiler.DecompilerException: Error decompiling System.Byte[][] BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Agreement.SM2KeyExchange::CalculateKeyWithConfirmation(System.Int32,System.Byte[],BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.ICipherParameters)
|
|
|
|
---> System.Exception: Basic block has to end with unconditional control flow.
|
|
{
|
|
IL_139:
|
|
stloc:ArgumentException(var_32_143, newobj:ArgumentException(ArgumentException::.ctor, ldstr:string("if initiating, confirmationTag must be set")))
|
|
}
|
|
|
|
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: 0x0600A07B RID: 41083 RVA: 0x00254AD0 File Offset: 0x00252CD0
|
|
[Token(Token = "0x600A07B")]
|
|
[Address(RVA = "0x6642A0", Offset = "0x662CA0", VA = "0x1806642A0", Slot = "7")]
|
|
protected virtual ECPoint CalculateU(SM2KeyExchangePublicParameters otherPub)
|
|
{
|
|
ECDomainParameters parameters = this.mStaticKey.parameters;
|
|
ECCurve curve = parameters.curve;
|
|
string text = otherPub.ToString();
|
|
ECCurve curve2 = parameters.curve;
|
|
ECPoint q = otherPub.StaticPublicKey.q;
|
|
ECPoint ecpoint = ECAlgorithms.CleanPoint(curve2, q);
|
|
string text2 = this.mEphemeralPubPoint.CurveCoordinateSystem.ToString();
|
|
string text3 = ecpoint.CurveCoordinateSystem.ToString();
|
|
ECPrivateKeyParameters ecprivateKeyParameters = this.mStaticKey;
|
|
ECPrivateKeyParameters ecprivateKeyParameters2 = this.mEphemeralKey;
|
|
BigInteger d = ecprivateKeyParameters.d;
|
|
BigInteger d2 = ecprivateKeyParameters2.d;
|
|
BigInteger bigInteger2;
|
|
BigInteger bigInteger = bigInteger2.Multiply(d2);
|
|
BigInteger bigInteger3 = d.Add(bigInteger);
|
|
BigInteger bigInteger4 = this.mECParams.h.Multiply(bigInteger3);
|
|
BigInteger n = this.mECParams.n;
|
|
BigInteger bigInteger5 = bigInteger4.Mod(n);
|
|
BigInteger bigInteger7;
|
|
BigInteger bigInteger6 = bigInteger5.Multiply(bigInteger7);
|
|
BigInteger n2 = this.mECParams.n;
|
|
BigInteger bigInteger8 = bigInteger6.Mod(n2);
|
|
ECPoint ecpoint2;
|
|
bool flag = ECAlgorithms.SumOfTwoMultiplies(ecpoint2, bigInteger5, ecpoint, bigInteger8).SatisfiesCurveEquation();
|
|
throw new NullReferenceException();
|
|
}
|
|
|
|
// Token: 0x0600A07C RID: 41084 RVA: 0x00254BD8 File Offset: 0x00252DD8
|
|
[Token(Token = "0x600A07C")]
|
|
[Address(RVA = "0x664A70", Offset = "0x663470", VA = "0x180664A70", Slot = "8")]
|
|
protected virtual byte[] Kdf(ECPoint u, byte[] za, byte[] zb, int klen)
|
|
{
|
|
IDigest digest = this.mDigest;
|
|
int num;
|
|
byte[] array = new byte[num];
|
|
byte[] array2 = new byte[num];
|
|
int num2 = 0;
|
|
if (array2 != 0)
|
|
{
|
|
int curveCoordinateSystem = u.CurveCoordinateSystem;
|
|
IDigest digest2 = this.mDigest;
|
|
ECFieldElement affineXCoord = u.AffineXCoord;
|
|
this.AddFieldElement(digest2, affineXCoord);
|
|
IDigest digest3 = this.mDigest;
|
|
int length = za.Length;
|
|
IDigest digest4 = this.mDigest;
|
|
int length2 = zb.Length;
|
|
}
|
|
if (num2 < array2.Length)
|
|
{
|
|
if (array2 == 0)
|
|
{
|
|
int curveCoordinateSystem2 = u.CurveCoordinateSystem;
|
|
IDigest digest5 = this.mDigest;
|
|
ECFieldElement affineXCoord2 = u.AffineXCoord;
|
|
this.AddFieldElement(digest5, affineXCoord2);
|
|
IDigest digest6 = this.mDigest;
|
|
int length3 = za.Length;
|
|
IDigest digest7 = this.mDigest;
|
|
int length4 = zb.Length;
|
|
}
|
|
num2++;
|
|
int num3 = 0;
|
|
Pack.UInt32_To_BE((uint)num2, array, num3);
|
|
IDigest digest8 = this.mDigest;
|
|
IDigest digest9 = this.mDigest;
|
|
int num4 = array2.Length;
|
|
num4 -= num2;
|
|
int num5 = 0;
|
|
int num6;
|
|
Array.Copy(array, num5, array2, num2, num6);
|
|
num2 += num6;
|
|
}
|
|
return array2;
|
|
}
|
|
|
|
// Token: 0x0600A07D RID: 41085 RVA: 0x00254CEC File Offset: 0x00252EEC
|
|
[Token(Token = "0x600A07D")]
|
|
[Address(RVA = "0x664E60", Offset = "0x663860", VA = "0x180664E60")]
|
|
private BigInteger Reduce(BigInteger x)
|
|
{
|
|
BigInteger one = BigInteger.One;
|
|
int num = this.mW;
|
|
BigInteger bigInteger = one.ShiftLeft(num);
|
|
BigInteger one2 = BigInteger.One;
|
|
BigInteger bigInteger2 = bigInteger.Subtract(one2);
|
|
BigInteger bigInteger3 = x.And(bigInteger2);
|
|
int num2 = this.mW;
|
|
return bigInteger3.SetBit(num2);
|
|
}
|
|
|
|
// Token: 0x0600A07E RID: 41086 RVA: 0x00254D40 File Offset: 0x00252F40
|
|
[Token(Token = "0x600A07E")]
|
|
[Address(RVA = "0x664F30", Offset = "0x663930", VA = "0x180664F30")]
|
|
private byte[] S1(IDigest digest, ECPoint u, byte[] inner)
|
|
{
|
|
ECFieldElement affineXCoord = u.AffineXCoord;
|
|
this.AddFieldElement(digest, affineXCoord);
|
|
int length = inner.Length;
|
|
return DigestUtilities.DoFinal(digest);
|
|
}
|
|
|
|
// Token: 0x0600A07F RID: 41087 RVA: 0x00254D70 File Offset: 0x00252F70
|
|
[Token(Token = "0x600A07F")]
|
|
[Address(RVA = "0x663720", Offset = "0x662120", VA = "0x180663720")]
|
|
private byte[] CalculateInnerHash(IDigest digest, ECPoint u, byte[] za, byte[] zb, ECPoint p1, ECPoint p2)
|
|
{
|
|
int curveCoordinateSystem = u.CurveCoordinateSystem;
|
|
int length = za.Length;
|
|
return DigestUtilities.DoFinal(digest);
|
|
}
|
|
|
|
// Token: 0x0600A080 RID: 41088 RVA: 0x00254D9C File Offset: 0x00252F9C
|
|
[Token(Token = "0x600A080")]
|
|
[Address(RVA = "0x665030", Offset = "0x663A30", VA = "0x180665030")]
|
|
private byte[] S2(IDigest digest, ECPoint u, byte[] inner)
|
|
{
|
|
ECFieldElement affineXCoord = u.AffineXCoord;
|
|
this.AddFieldElement(digest, affineXCoord);
|
|
int length = inner.Length;
|
|
return DigestUtilities.DoFinal(digest);
|
|
}
|
|
|
|
// Token: 0x0600A081 RID: 41089 RVA: 0x00254DCC File Offset: 0x00252FCC
|
|
[Token(Token = "0x600A081")]
|
|
[Address(RVA = "0x664500", Offset = "0x662F00", VA = "0x180664500")]
|
|
private byte[] GetZ(IDigest digest, byte[] userID, ECPoint pubPoint)
|
|
{
|
|
int length = userID.Length;
|
|
IFiniteField field = this.mECParams.curve.Field;
|
|
ECFieldElement a = this.mECParams.curve.A;
|
|
this.AddFieldElement(digest, a);
|
|
int curveCoordinateSystem = this.mECParams.g.CurveCoordinateSystem;
|
|
ECFieldElement affineXCoord = this.mECParams.g.AffineXCoord;
|
|
this.AddFieldElement(digest, affineXCoord);
|
|
int curveCoordinateSystem2 = pubPoint.CurveCoordinateSystem;
|
|
ECFieldElement affineXCoord2 = pubPoint.AffineXCoord;
|
|
this.AddFieldElement(digest, affineXCoord2);
|
|
return DigestUtilities.DoFinal(digest);
|
|
}
|
|
|
|
// Token: 0x0600A082 RID: 41090 RVA: 0x00254E5C File Offset: 0x0025305C
|
|
[Token(Token = "0x600A082")]
|
|
[Address(RVA = "0x663670", Offset = "0x662070", VA = "0x180663670")]
|
|
private void AddUserID(IDigest digest, byte[] userID)
|
|
{
|
|
int length = userID.Length;
|
|
}
|
|
|
|
// Token: 0x0600A083 RID: 41091 RVA: 0x00254E78 File Offset: 0x00253078
|
|
[Token(Token = "0x600A083")]
|
|
[Address(RVA = "0x6635E0", Offset = "0x661FE0", VA = "0x1806635E0")]
|
|
private void AddFieldElement(IDigest digest, ECFieldElement v)
|
|
{
|
|
}
|
|
|
|
// Token: 0x04006988 RID: 27016
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x10")]
|
|
[Token(Token = "0x4006988")]
|
|
private readonly IDigest mDigest;
|
|
|
|
// Token: 0x04006989 RID: 27017
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x18")]
|
|
[Token(Token = "0x4006989")]
|
|
private byte[] mUserID;
|
|
|
|
// Token: 0x0400698A RID: 27018
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x20")]
|
|
[Token(Token = "0x400698A")]
|
|
private ECPrivateKeyParameters mStaticKey;
|
|
|
|
// Token: 0x0400698B RID: 27019
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x28")]
|
|
[Token(Token = "0x400698B")]
|
|
private ECPoint mStaticPubPoint;
|
|
|
|
// Token: 0x0400698C RID: 27020
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x30")]
|
|
[Token(Token = "0x400698C")]
|
|
private ECPoint mEphemeralPubPoint;
|
|
|
|
// Token: 0x0400698D RID: 27021
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x38")]
|
|
[Token(Token = "0x400698D")]
|
|
private ECDomainParameters mECParams;
|
|
|
|
// Token: 0x0400698E RID: 27022
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x40")]
|
|
[Token(Token = "0x400698E")]
|
|
private int mW;
|
|
|
|
// Token: 0x0400698F RID: 27023
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x48")]
|
|
[Token(Token = "0x400698F")]
|
|
private ECPrivateKeyParameters mEphemeralKey;
|
|
|
|
// Token: 0x04006990 RID: 27024
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x50")]
|
|
[Token(Token = "0x4006990")]
|
|
private bool mInitiator;
|
|
}
|
|
}
|