277 lines
12 KiB
C#
277 lines
12 KiB
C#
using System;
|
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
|
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 Cpp2IlInjected;
|
|
|
|
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers
|
|
{
|
|
// Token: 0x02001C83 RID: 7299
|
|
[Token(Token = "0x2001C83")]
|
|
public class ECDsaSigner : IDsaExt, IDsa
|
|
{
|
|
// Token: 0x0600B49D RID: 46237 RVA: 0x0026FAC4 File Offset: 0x0026DCC4
|
|
[Token(Token = "0x600B49D")]
|
|
[Address(RVA = "0x2357820", Offset = "0x2356820", VA = "0x182357820")]
|
|
public ECDsaSigner()
|
|
{
|
|
RandomDsaKCalculator randomDsaKCalculator = new RandomDsaKCalculator();
|
|
this.kCalculator = randomDsaKCalculator;
|
|
}
|
|
|
|
// Token: 0x0600B49E RID: 46238 RVA: 0x0026FAE4 File Offset: 0x0026DCE4
|
|
[Token(Token = "0x600B49E")]
|
|
[Address(RVA = "0x493D90", Offset = "0x492D90", VA = "0x180493D90")]
|
|
public ECDsaSigner(IDsaKCalculator kCalculator)
|
|
{
|
|
this.kCalculator = kCalculator;
|
|
}
|
|
|
|
// Token: 0x17001C75 RID: 7285
|
|
// (get) Token: 0x0600B49F RID: 46239 RVA: 0x0026FB00 File Offset: 0x0026DD00
|
|
[Token(Token = "0x17001C75")]
|
|
public virtual string AlgorithmName
|
|
{
|
|
[Token(Token = "0x600B49F")]
|
|
[Address(RVA = "0x2357880", Offset = "0x2356880", VA = "0x182357880", Slot = "9")]
|
|
get
|
|
{
|
|
return "ECDSA";
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600B4A0 RID: 46240 RVA: 0x0026FB14 File Offset: 0x0026DD14
|
|
[Token(Token = "0x600B4A0")]
|
|
[Address(RVA = "0x23570F0", Offset = "0x23560F0", VA = "0x1823570F0", Slot = "10")]
|
|
public virtual void Init(bool forSigning, ICipherParameters parameters)
|
|
{
|
|
/*
|
|
An exception occurred when decompiling this method (0600B4A0)
|
|
|
|
ICSharpCode.Decompiler.DecompilerException: Error decompiling System.Void BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers.ECDsaSigner::Init(System.Boolean,BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.ICipherParameters)
|
|
|
|
---> System.Exception: Basic block has to end with unconditional control flow.
|
|
{
|
|
IL_75:
|
|
stloc:InvalidKeyException(var_11_7F, newobj:InvalidKeyException(InvalidKeyException::.ctor, ldstr:string("EC public key required for verification")))
|
|
}
|
|
|
|
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: 0x17001C76 RID: 7286
|
|
// (get) Token: 0x0600B4A1 RID: 46241 RVA: 0x0026FBA4 File Offset: 0x0026DDA4
|
|
[Token(Token = "0x17001C76")]
|
|
public virtual BigInteger Order
|
|
{
|
|
[Token(Token = "0x600B4A1")]
|
|
[Address(RVA = "0x23578B0", Offset = "0x23568B0", VA = "0x1823578B0", Slot = "11")]
|
|
get
|
|
{
|
|
return this.key.parameters.n;
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600B4A2 RID: 46242 RVA: 0x0026FBC8 File Offset: 0x0026DDC8
|
|
[Token(Token = "0x600B4A2")]
|
|
[Address(RVA = "0x2356B30", Offset = "0x2355B30", VA = "0x182356B30", Slot = "12")]
|
|
public virtual BigInteger[] GenerateSignature(byte[] message)
|
|
{
|
|
BigInteger n;
|
|
ECKeyParameters eckeyParameters;
|
|
do
|
|
{
|
|
n = this.key.parameters.n;
|
|
eckeyParameters = this.key;
|
|
}
|
|
while (eckeyParameters == 0 || eckeyParameters == 0);
|
|
IDsaKCalculator dsaKCalculator = this.kCalculator;
|
|
IDsaKCalculator dsaKCalculator2 = this.kCalculator;
|
|
if (eckeyParameters == 0)
|
|
{
|
|
SecureRandom secureRandom = this.random;
|
|
}
|
|
int num = 0;
|
|
IDsaKCalculator dsaKCalculator3 = this.kCalculator;
|
|
if (num < dsaKCalculator2)
|
|
{
|
|
num += num;
|
|
num++;
|
|
}
|
|
uint num2;
|
|
if (num < (int)num2)
|
|
{
|
|
num += num;
|
|
num++;
|
|
}
|
|
char c;
|
|
string text = c.ToString();
|
|
BigInteger bigInteger;
|
|
while (bigInteger.sign == 0)
|
|
{
|
|
}
|
|
BigInteger bigInteger3;
|
|
BigInteger bigInteger4;
|
|
BigInteger bigInteger2 = bigInteger3.Multiply(bigInteger4).Mod(n);
|
|
while (bigInteger2.sign == 0)
|
|
{
|
|
}
|
|
return new BigInteger[] { bigInteger, bigInteger2 };
|
|
}
|
|
|
|
// Token: 0x0600B4A3 RID: 46243 RVA: 0x0026FC9C File Offset: 0x0026DE9C
|
|
[Token(Token = "0x600B4A3")]
|
|
[Address(RVA = "0x23573D0", Offset = "0x23563D0", VA = "0x1823573D0", Slot = "13")]
|
|
public virtual bool VerifySignature(byte[] message, BigInteger r, BigInteger s)
|
|
{
|
|
BigInteger n = this.key.parameters.n;
|
|
int num = r.CompareTo(n);
|
|
int num2 = s.CompareTo(n);
|
|
BigInteger bigInteger = s.ModInverse(n);
|
|
BigInteger bigInteger3;
|
|
BigInteger bigInteger2 = bigInteger3.Mod(n);
|
|
BigInteger bigInteger4 = r.Multiply(bigInteger);
|
|
int num3 = 0;
|
|
BigInteger bigInteger5 = bigInteger4.Mod(n);
|
|
ECPoint ecpoint = ECAlgorithms.SumOfTwoMultiplies(this.key.parameters.g, bigInteger2, num3, bigInteger5);
|
|
if (!ecpoint.IsInfinity)
|
|
{
|
|
bool flag = ecpoint.SatisfiesOrder();
|
|
if (flag && flag)
|
|
{
|
|
BigInteger eight = ECDsaSigner.Eight;
|
|
ECMultiplier ecmultiplier = this.CreateBasePointMultiplier();
|
|
if (ecmultiplier != 0 && ecmultiplier == 0)
|
|
{
|
|
ECFieldElement affineYCoord = ecpoint.AffineYCoord;
|
|
if (flag.GetTypeCode() != TypeCode.Empty)
|
|
{
|
|
int num4 = flag.CompareTo(r);
|
|
bool flag2;
|
|
if (!flag2)
|
|
{
|
|
BigInteger bigInteger6 = r.Add(n);
|
|
}
|
|
return true;
|
|
}
|
|
goto IL_DD;
|
|
}
|
|
}
|
|
bool flag3 = ecpoint.IsNormalized();
|
|
sbyte b;
|
|
string text = b.ToString();
|
|
}
|
|
IL_DD:
|
|
throw new NullReferenceException();
|
|
}
|
|
|
|
// Token: 0x0600B4A4 RID: 46244 RVA: 0x0026FD8C File Offset: 0x0026DF8C
|
|
[Token(Token = "0x600B4A4")]
|
|
[Address(RVA = "0x2356A20", Offset = "0x2355A20", VA = "0x182356A20", Slot = "14")]
|
|
protected virtual BigInteger CalculateE(BigInteger n, byte[] message)
|
|
{
|
|
int num = message.Length;
|
|
BigInteger bigInteger = new BigInteger(1, message);
|
|
if (n.BitLength < num)
|
|
{
|
|
int bitLength = n.BitLength;
|
|
num -= bitLength;
|
|
BigInteger bigInteger2 = bigInteger.ShiftRight(num);
|
|
}
|
|
return bigInteger;
|
|
}
|
|
|
|
// Token: 0x0600B4A5 RID: 46245 RVA: 0x0026FDCC File Offset: 0x0026DFCC
|
|
[Token(Token = "0x600B4A5")]
|
|
[Address(RVA = "0x2356AE0", Offset = "0x2355AE0", VA = "0x182356AE0", Slot = "15")]
|
|
protected virtual ECMultiplier CreateBasePointMultiplier()
|
|
{
|
|
/*
|
|
An exception occurred when decompiling this method (0600B4A5)
|
|
|
|
ICSharpCode.Decompiler.DecompilerException: Error decompiling BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC.Multiplier.ECMultiplier BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers.ECDsaSigner::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: 0x0600B4A6 RID: 46246 RVA: 0x0026FDE0 File Offset: 0x0026DFE0
|
|
[Token(Token = "0x600B4A6")]
|
|
[Address(RVA = "0x2356FD0", Offset = "0x2355FD0", VA = "0x182356FD0", Slot = "16")]
|
|
protected virtual ECFieldElement GetDenominator(int coordinateSystem, ECPoint p)
|
|
{
|
|
if (coordinateSystem <= 6)
|
|
{
|
|
BigInteger bigInteger = p.YCoord.ToBigInteger();
|
|
bool flag = p.SatisfiesCurveEquation();
|
|
}
|
|
throw new NullReferenceException();
|
|
}
|
|
|
|
// Token: 0x0600B4A7 RID: 46247 RVA: 0x0026FE0C File Offset: 0x0026E00C
|
|
[Token(Token = "0x600B4A7")]
|
|
[Address(RVA = "0x2357080", Offset = "0x2356080", VA = "0x182357080", Slot = "17")]
|
|
protected virtual SecureRandom InitSecureRandom(bool needed, SecureRandom provided)
|
|
{
|
|
do
|
|
{
|
|
if (!needed)
|
|
{
|
|
}
|
|
}
|
|
while (provided != 0);
|
|
return new SecureRandom();
|
|
}
|
|
|
|
// Token: 0x0600B4A8 RID: 46248 RVA: 0x0026FE28 File Offset: 0x0026E028
|
|
// Note: this type is marked as 'beforefieldinit'.
|
|
[Token(Token = "0x600B4A8")]
|
|
[Address(RVA = "0x23577C0", Offset = "0x23567C0", VA = "0x1823577C0")]
|
|
static ECDsaSigner()
|
|
{
|
|
BigInteger bigInteger;
|
|
ECDsaSigner.Eight = bigInteger;
|
|
}
|
|
|
|
// Token: 0x04007258 RID: 29272
|
|
[Token(Token = "0x4007258")]
|
|
private static readonly BigInteger Eight;
|
|
|
|
// Token: 0x04007259 RID: 29273
|
|
[FieldOffset(Offset = "0x10")]
|
|
[Token(Token = "0x4007259")]
|
|
protected readonly IDsaKCalculator kCalculator;
|
|
|
|
// Token: 0x0400725A RID: 29274
|
|
[FieldOffset(Offset = "0x18")]
|
|
[Token(Token = "0x400725A")]
|
|
protected ECKeyParameters key;
|
|
|
|
// Token: 0x0400725B RID: 29275
|
|
[FieldOffset(Offset = "0x20")]
|
|
[Token(Token = "0x400725B")]
|
|
protected SecureRandom random;
|
|
}
|
|
}
|