289 lines
11 KiB
C#
289 lines
11 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Digests;
|
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines;
|
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities;
|
|
using Cpp2IlInjected;
|
|
|
|
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Generators
|
|
{
|
|
// Token: 0x020016A0 RID: 5792
|
|
[Token(Token = "0x20016A0")]
|
|
[StructLayout(3)]
|
|
public class SCrypt
|
|
{
|
|
// Token: 0x06009AD0 RID: 39632 RVA: 0x00229A5C File Offset: 0x00227C5C
|
|
[Token(Token = "0x6009AD0")]
|
|
[Address(RVA = "0x1F5CCB0", Offset = "0x1F5B6B0", VA = "0x181F5CCB0")]
|
|
public static byte[] Generate(byte[] P, byte[] S, int N, int r, int p, int dkLen)
|
|
{
|
|
/*
|
|
An exception occurred when decompiling this method (06009AD0)
|
|
|
|
ICSharpCode.Decompiler.DecompilerException: Error decompiling System.Byte[] BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Generators.SCrypt::Generate(System.Byte[],System.Byte[],System.Int32,System.Int32,System.Int32,System.Int32)
|
|
|
|
---> System.Exception: Basic block has to end with unconditional control flow.
|
|
{
|
|
IL_2D:
|
|
stloc:ArgumentException(var_4_37, newobj:ArgumentException(ArgumentException::.ctor, ldstr:string("Cost parameter N must be > 1 and < 65536.")))
|
|
}
|
|
|
|
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.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: 0x06009AD1 RID: 39633 RVA: 0x00229AA4 File Offset: 0x00227CA4
|
|
[Token(Token = "0x6009AD1")]
|
|
[Address(RVA = "0x1F5D010", Offset = "0x1F5BA10", VA = "0x181F5D010")]
|
|
private static byte[] MFcrypt(byte[] P, byte[] S, int N, int r, int p, int dkLen)
|
|
{
|
|
int num;
|
|
do
|
|
{
|
|
num = 0;
|
|
byte[] array = SCrypt.SingleIterationPBKDF2(P, S, N);
|
|
int length = array.Length;
|
|
uint[] array2 = new uint[length];
|
|
int num2 = 0;
|
|
Pack.LE_To_UInt32(array, num2, array2);
|
|
if (num < length)
|
|
{
|
|
num += r;
|
|
}
|
|
int num3 = 0;
|
|
Pack.UInt32_To_LE(array2, array, num3);
|
|
int num4 = 0;
|
|
Array[] array3 = new Array[2];
|
|
if (array != 0)
|
|
{
|
|
}
|
|
array3[0] = array;
|
|
if (array2 != 0)
|
|
{
|
|
}
|
|
array3[1] = array2;
|
|
int length2 = array3.Length;
|
|
if (num4 < length2)
|
|
{
|
|
Array array4 = array3[num4];
|
|
if (array4 != 0)
|
|
{
|
|
int num5 = array4.System.Collections.ICollection.Count;
|
|
int num6 = 0;
|
|
Array.Clear(array4, num6, num5);
|
|
}
|
|
num4++;
|
|
}
|
|
if (num != -1)
|
|
{
|
|
}
|
|
}
|
|
while (num != 0);
|
|
byte[] array5;
|
|
return array5;
|
|
}
|
|
|
|
// Token: 0x06009AD2 RID: 39634 RVA: 0x00229B6C File Offset: 0x00227D6C
|
|
[Token(Token = "0x6009AD2")]
|
|
[Address(RVA = "0x1F5D8A0", Offset = "0x1F5C2A0", VA = "0x181F5D8A0")]
|
|
private static byte[] SingleIterationPBKDF2(byte[] P, byte[] S, int dkLen)
|
|
{
|
|
ICipherParameters cipherParameters;
|
|
do
|
|
{
|
|
string text = new Pkcs5S2ParametersGenerator(new Sha256Digest()).ToString();
|
|
}
|
|
while (cipherParameters == 0 || cipherParameters == 0);
|
|
byte[] array;
|
|
return array;
|
|
}
|
|
|
|
// Token: 0x06009AD3 RID: 39635 RVA: 0x00229BA0 File Offset: 0x00227DA0
|
|
[Token(Token = "0x6009AD3")]
|
|
[Address(RVA = "0x1F5D2D0", Offset = "0x1F5BCD0", VA = "0x181F5D2D0")]
|
|
private static void SMix(uint[] B, int BOff, int N, int r)
|
|
{
|
|
uint[] array7;
|
|
do
|
|
{
|
|
int num = 0;
|
|
uint[] array = new uint[0];
|
|
uint[] array2 = new uint[0];
|
|
uint[] array3 = new uint[r];
|
|
uint[] array4 = new uint[r];
|
|
uint[][] array5 = new uint[r][];
|
|
int num2 = 0;
|
|
Array.Copy(B, r, array4, num2, r);
|
|
if (num < N)
|
|
{
|
|
if (array5 != 0 && (array5 == 0 || array5 == 0))
|
|
{
|
|
goto IL_151;
|
|
}
|
|
array5[0] = num;
|
|
num++;
|
|
}
|
|
if (num < N)
|
|
{
|
|
int num3 = array4.Length;
|
|
uint num4 = array4[num];
|
|
uint[] array6 = array5[(int)num4];
|
|
num3--;
|
|
num++;
|
|
}
|
|
int num5 = 0;
|
|
int length = array5.Length;
|
|
if (num5 < length)
|
|
{
|
|
array7 = array5[num5];
|
|
if (array7 != 0)
|
|
{
|
|
int num6 = 0;
|
|
Array.Clear(array7, num6, num5);
|
|
}
|
|
num5++;
|
|
}
|
|
Array[] array8 = new Array[4];
|
|
if (array4 != 0)
|
|
{
|
|
}
|
|
array8[0] = array4;
|
|
if (array8 != 0)
|
|
{
|
|
}
|
|
array8[1] = array8;
|
|
if (array8 != 0)
|
|
{
|
|
}
|
|
array8[2] = array8;
|
|
if (array8 != 0)
|
|
{
|
|
}
|
|
array8[3] = array8;
|
|
int length2 = array8.Length;
|
|
if (num5 < length2)
|
|
{
|
|
Array array9 = array8[num5];
|
|
if (array9 != 0)
|
|
{
|
|
int num7 = array9.System.Collections.ICollection.Count;
|
|
int num8 = 0;
|
|
Array.Clear(array9, num8, num7);
|
|
}
|
|
num5++;
|
|
}
|
|
if (num != -1)
|
|
{
|
|
}
|
|
}
|
|
while (array7 != 0);
|
|
return;
|
|
IL_151:
|
|
throw new IndexOutOfRangeException();
|
|
}
|
|
|
|
// Token: 0x06009AD4 RID: 39636 RVA: 0x00229D4C File Offset: 0x00227F4C
|
|
[Token(Token = "0x6009AD4")]
|
|
[Address(RVA = "0x1F5CA80", Offset = "0x1F5B480", VA = "0x181F5CA80")]
|
|
private static void BlockMix(uint[] B, uint[] X1, uint[] X2, uint[] Y, int r)
|
|
{
|
|
int length = B.Length;
|
|
int num = 0;
|
|
ulong num2;
|
|
Array.Copy(B, length, X1, num, (int)num2);
|
|
int num3 = B.Length;
|
|
int num4 = 0;
|
|
int num5 = 0;
|
|
SCrypt.Xor(X1, B, num4, X2);
|
|
Salsa20Engine.SalsaCore(8, X2, X1);
|
|
int num6 = 0;
|
|
ulong num7;
|
|
Array.Copy(X1, num6, Y, num5, (int)num7);
|
|
num3 -= num5;
|
|
num3 += num4;
|
|
num4 += 16;
|
|
int length2 = Y.Length;
|
|
int num8 = 0;
|
|
int num9 = 0;
|
|
Array.Copy(Y, num9, B, num8, (int)num2);
|
|
}
|
|
|
|
// Token: 0x06009AD5 RID: 39637 RVA: 0x00229DD4 File Offset: 0x00227FD4
|
|
[Token(Token = "0x6009AD5")]
|
|
[Address(RVA = "0x1F5DA10", Offset = "0x1F5C410", VA = "0x181F5DA10")]
|
|
private static void Xor(uint[] a, uint[] b, int bOff, uint[] output)
|
|
{
|
|
int length = output.Length;
|
|
uint num = b[bOff];
|
|
output[0] = num;
|
|
}
|
|
|
|
// Token: 0x06009AD6 RID: 39638 RVA: 0x00229E00 File Offset: 0x00228000
|
|
[Token(Token = "0x6009AD6")]
|
|
[Address(RVA = "0x1F5CC80", Offset = "0x1F5B680", VA = "0x181F5CC80")]
|
|
private static void Clear(Array array)
|
|
{
|
|
if (array != 0)
|
|
{
|
|
int num = array.System.Collections.ICollection.Count;
|
|
int num2 = 0;
|
|
Array.Clear(array, num2, num);
|
|
}
|
|
}
|
|
|
|
// Token: 0x06009AD7 RID: 39639 RVA: 0x00229E24 File Offset: 0x00228024
|
|
[Token(Token = "0x6009AD7")]
|
|
[Address(RVA = "0x1F5CC00", Offset = "0x1F5B600", VA = "0x181F5CC00")]
|
|
private static void ClearAll(params Array[] arrays)
|
|
{
|
|
int num = 0;
|
|
int length = arrays.Length;
|
|
if (num < length)
|
|
{
|
|
Array array = arrays[num];
|
|
if (array != 0)
|
|
{
|
|
int num2 = array.System.Collections.ICollection.Count;
|
|
int num3 = 0;
|
|
Array.Clear(array, num3, num2);
|
|
}
|
|
num++;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06009AD8 RID: 39640 RVA: 0x00229E68 File Offset: 0x00228068
|
|
[Token(Token = "0x6009AD8")]
|
|
[Address(RVA = "0x1F5D000", Offset = "0x1F5BA00", VA = "0x181F5D000")]
|
|
private static bool IsPowerOf2(int x)
|
|
{
|
|
int num = x - 1;
|
|
return x == num;
|
|
}
|
|
|
|
// Token: 0x06009AD9 RID: 39641 RVA: 0x00229E80 File Offset: 0x00228080
|
|
[Token(Token = "0x6009AD9")]
|
|
[Address(RVA = "0x3C1670", Offset = "0x3C0070", VA = "0x1803C1670")]
|
|
public SCrypt()
|
|
{
|
|
}
|
|
}
|
|
}
|