Files
Aug2021-Cpp2IL-Dump/Assembly-CSharp/BestHTTP/SecureProtocol/Org/BouncyCastle/Crypto/Generators/BCrypt.cs
T
2026-04-10 22:50:51 +02:00

422 lines
14 KiB
C#

using System;
using System.Runtime.CompilerServices;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using Cpp2IlInjected;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Generators
{
// Token: 0x02001C5E RID: 7262
[Token(Token = "0x2001C5E")]
public sealed class BCrypt
{
// Token: 0x0600B604 RID: 46596 RVA: 0x0027C7A4 File Offset: 0x0027A9A4
[Token(Token = "0x600B604")]
[Address(RVA = "0x1A290D0", Offset = "0x1A27ED0", VA = "0x181A290D0")]
private BCrypt()
{
uint[] array = new uint[1024];
this.S = array;
uint[] array2 = new uint[18];
this.P = array2;
}
// Token: 0x0600B605 RID: 46597 RVA: 0x0027C7D8 File Offset: 0x0027A9D8
[Token(Token = "0x600B605")]
[Address(RVA = "0x1A28560", Offset = "0x1A27360", VA = "0x181A28560")]
private uint F(uint x)
{
int length = this.S.Length;
return x;
}
// Token: 0x0600B606 RID: 46598 RVA: 0x0027C7F8 File Offset: 0x0027A9F8
[Token(Token = "0x600B606")]
[Address(RVA = "0x1A28D90", Offset = "0x1A27B90", VA = "0x181A28D90")]
private void ProcessTable(uint xl, uint xr, uint[] table)
{
int length = table.Length;
int num = 0;
if (length > 0)
{
uint[] p = this.P;
uint num2 = this.F(xl);
uint[] p2 = this.P;
uint num3 = this.F(xl);
uint[] p3 = this.P;
int length2 = p3.Length;
uint num5;
uint num4 = num5 + 1U;
num5 += (uint)2;
uint num6 = p3[8];
num++;
table[0] = xl;
num += 2;
}
}
// Token: 0x0600B607 RID: 46599 RVA: 0x0027C870 File Offset: 0x0027AA70
[Token(Token = "0x600B607")]
[Address(RVA = "0x1A28830", Offset = "0x1A27630", VA = "0x181A28830")]
private void InitState()
{
uint[] s = this.S;
int num = 0;
int num2 = 0;
ulong num3;
Array.Copy(BCrypt.KS0, num2, s, num, (int)num3);
uint[] s2 = this.S;
int num4 = 0;
ulong num5;
Array.Copy(BCrypt.KS1, num4, s2, 256, (int)num5);
uint[] s3 = this.S;
int num6 = 0;
ulong num7;
Array.Copy(BCrypt.KS2, num6, s3, 512, (int)num7);
uint[] s4 = this.S;
int num8 = 0;
ulong num9;
Array.Copy(BCrypt.KS3, num8, s4, 768, (int)num9);
int num10 = 0;
uint[] p = this.P;
int num11 = 0;
ulong num12;
Array.Copy(BCrypt.KP, num11, p, num10, (int)num12);
}
// Token: 0x0600B608 RID: 46600 RVA: 0x0027C91C File Offset: 0x0027AB1C
[Token(Token = "0x600B608")]
[Address(RVA = "0x1A27A60", Offset = "0x1A26860", VA = "0x181A27A60")]
private void CyclicXorKey(byte[] key)
{
int length = key.Length;
int num = 0;
int length2 = key.Length;
int num2 = 0;
num2++;
uint[] p = this.P;
num++;
}
// Token: 0x0600B609 RID: 46601 RVA: 0x0027C958 File Offset: 0x0027AB58
[Token(Token = "0x600B609")]
[Address(RVA = "0x1A28090", Offset = "0x1A26E90", VA = "0x181A28090")]
private byte[] EncryptMagicString()
{
uint[] array = new uint[6];
uint num = BCrypt.MAGIC_STRING[0];
array[0] = num;
uint num2 = BCrypt.MAGIC_STRING[0];
array[0] = num2;
uint num3 = BCrypt.MAGIC_STRING[1];
array[1] = num3;
uint num4 = BCrypt.MAGIC_STRING[1];
array[1] = num4;
uint num5 = BCrypt.MAGIC_STRING[2];
array[2] = num5;
uint num6 = BCrypt.MAGIC_STRING[2];
array[2] = num6;
int num7 = 0;
int length = array.Length;
uint num8 = this.P[0];
num7 += 8;
uint num9 = this.F(num8);
uint[] p = this.P;
uint num10 = this.F(num8);
uint[] p2 = this.P;
int length2 = p2.Length;
uint num12;
uint num11 = num12 + 1U;
num12 += (uint)2;
uint num13 = p2[8];
num7.m_value = (int)num13;
num7 += 2;
array[0] = num8;
ulong num14;
num14 += (ulong)1L;
byte[] array2 = new byte[24];
int num15 = 0;
Pack.UInt32_To_BE(array, array2, num15);
int length3 = array.Length;
int num16 = 0;
Array.Clear(array, num16, length3);
uint[] p3 = this.P;
int length4 = p3.Length;
int num17 = 0;
Array.Clear(p3, num17, length4);
uint[] s = this.S;
int length5 = s.Length;
int num18 = 0;
Array.Clear(s, num18, length5);
return array2;
}
// Token: 0x0600B60A RID: 46602 RVA: 0x0027CAE0 File Offset: 0x0027ACE0
[Token(Token = "0x600B60A")]
[Address(RVA = "0x1A289E0", Offset = "0x1A277E0", VA = "0x181A289E0")]
private void ProcessTableWithSalt(uint[] table, uint[] salt32Bit, uint iv1, uint iv2)
{
int length = salt32Bit.Length;
uint num = salt32Bit[0];
int length2 = table.Length;
int num2 = 0;
if (length2 > 0)
{
uint[] p = this.P;
uint num3 = this.F(iv1);
uint[] p2 = this.P;
uint num4 = this.F(iv1);
int length3 = this.P.Length;
uint num6;
uint num5 = num6 + 1U;
num6 += (uint)2;
table[0] = num;
table[0] = iv1;
int length4 = salt32Bit.Length;
num2 += 2;
uint num7 = this.P[0];
uint num8 = this.F(num7);
uint[] p3 = this.P;
uint num9 = this.F(iv1);
int length5 = this.P.Length;
uint num11;
uint num10 = num11 + 1U;
num11 += (uint)2;
table[0] = iv1;
table[0] = iv1;
int length6 = salt32Bit.Length;
num2 += 4;
}
}
// Token: 0x0600B60B RID: 46603 RVA: 0x0027CBD0 File Offset: 0x0027ADD0
[Token(Token = "0x600B60B")]
[Address(RVA = "0x1A27B20", Offset = "0x1A26920", VA = "0x181A27B20")]
private byte[] DeriveRawKey(int cost, byte[] salt, byte[] psw)
{
while (salt.Length != 16)
{
}
if (psw.Length == 0)
{
byte[] array = new byte[4];
}
int num = 0;
uint[] s = this.S;
int num2 = 0;
int num3 = 0;
ulong num4;
Array.Copy(BCrypt.KS0, num3, s, num2, (int)num4);
uint[] s2 = this.S;
int num5 = 0;
ulong num6;
Array.Copy(BCrypt.KS1, num5, s2, 256, (int)num6);
uint[] s3 = this.S;
int num7 = 0;
ulong num8;
Array.Copy(BCrypt.KS2, num7, s3, 512, (int)num8);
uint[] s4 = this.S;
int num9 = 0;
ulong num10;
Array.Copy(BCrypt.KS3, num9, s4, 768, (int)num10);
int num11 = 0;
uint[] p = this.P;
int num12 = 0;
ulong num13;
Array.Copy(BCrypt.KP, num12, p, num11, (int)num13);
uint[] array2 = new uint[0];
int num14 = 0;
Pack.BE_To_UInt32(salt, num14, array2);
uint[] array3 = new uint[salt.Length];
uint num15 = array2[1];
array3[0] = num15;
uint num16 = array2[1];
array3[0] = num16;
uint num17 = array2[0];
array3[1] = num17;
uint num18 = array2[0];
array3[1] = num18;
this.CyclicXorKey(psw);
uint[] p2 = this.P;
int num19 = 0;
this.ProcessTableWithSalt(p2, array2, (uint)num19, (uint)num);
int num20 = array2.Length;
int num21 = 0;
Array.Clear(array2, num21, num20);
uint[] p3 = this.P;
num20 = p3.Length;
uint num22 = p3[num21];
uint num23 = p3[num20];
uint[] s5 = this.S;
this.ProcessTableWithSalt(s5, array3, num22, num23);
int length = array3.Length;
int num24 = 0;
Array.Clear(array3, num24, length);
this.CyclicXorKey(psw);
uint[] p4 = this.P;
int num25 = 0;
int num26 = 0;
this.ProcessTable((uint)num26, (uint)num25, p4);
uint[] p5 = this.P;
int length2 = p5.Length;
uint[] s6 = this.S;
uint num27 = p5[8];
uint num28 = p5[8];
this.ProcessTable(num28, num27, s6);
this.CyclicXorKey(salt);
uint[] p6 = this.P;
int num29 = 0;
int num30 = 0;
this.ProcessTable((uint)num30, (uint)num29, p6);
uint[] p7 = this.P;
int length3 = p7.Length;
uint[] s7 = this.S;
uint num31 = p7[8];
uint num32 = p7[8];
this.ProcessTable(num32, num31, s7);
num++;
while (num != 1)
{
}
return this.EncryptMagicString();
}
// Token: 0x0600B60C RID: 46604 RVA: 0x0027CE5C File Offset: 0x0027B05C
[Token(Token = "0x600B60C")]
[Address(RVA = "0x1A28970", Offset = "0x1A27770", VA = "0x181A28970")]
public static byte[] PasswordToByteArray(char[] password)
{
byte[] array = Strings.ToUtf8ByteArray(password);
int num = 0;
return Arrays.Append(array, (byte)num);
}
// Token: 0x0600B60D RID: 46605 RVA: 0x0027CE7C File Offset: 0x0027B07C
[Token(Token = "0x600B60D")]
[Address(RVA = "0x1A28630", Offset = "0x1A27430", VA = "0x181A28630")]
public static byte[] Generate(byte[] password, byte[] salt, int cost)
{
/*
An exception occurred when decompiling this method (0600B60D)
ICSharpCode.Decompiler.DecompilerException: Error decompiling System.Byte[] BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Generators.BCrypt::Generate(System.Byte[],System.Byte[],System.Int32)
---> System.Exception: Basic block has to end with unconditional control flow.
{
IL_43:
stloc:ArgumentNullException(var_4_4D, newobj:ArgumentNullException(ArgumentNullException::.ctor, ldstr:string("password")))
stloc:ArgumentException(var_5_5E, newobj:ArgumentException(ArgumentException::.ctor, ldstr:string("BCrypt cost must be from 4..31"), ldstr:string("cost")))
}
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: 0x0600B60E RID: 46606 RVA: 0x0027CEE8 File Offset: 0x0027B0E8
// Note: this type is marked as 'beforefieldinit'.
[Token(Token = "0x600B60E")]
[Address(RVA = "0x1A28F50", Offset = "0x1A27D50", VA = "0x181A28F50")]
static BCrypt()
{
uint[] array = new uint[6];
RuntimeHelpers.InitializeArray(array, fieldof(<PrivateImplementationDetails>.007AFA4B68442DD6E0877DE7624D0A5F508C474F).FieldHandle);
BCrypt.MAGIC_STRING = array;
uint[] array2 = new uint[18];
RuntimeHelpers.InitializeArray(array2, fieldof(<PrivateImplementationDetails>.643A9D76937E94519B73BE072D65E79BAFF3C213).FieldHandle);
BCrypt.KP = array2;
uint[] array3 = new uint[256];
RuntimeHelpers.InitializeArray(array3, fieldof(<PrivateImplementationDetails>.E117A40BF9A3AE32474AD7B22EB4C60E95D3BE2A).FieldHandle);
BCrypt.KS0 = array3;
uint[] array4 = new uint[256];
RuntimeHelpers.InitializeArray(array4, fieldof(<PrivateImplementationDetails>.6F576E8737EAAC9B6B12BDFC370048CD205E2CDD).FieldHandle);
BCrypt.KS1 = array4;
uint[] array5 = new uint[256];
RuntimeHelpers.InitializeArray(array5, fieldof(<PrivateImplementationDetails>.E2F8F75B7ABE5A6E4ECF5E32B935909BE2CC9F4B).FieldHandle);
BCrypt.KS2 = array5;
uint[] array6 = new uint[256];
RuntimeHelpers.InitializeArray(array6, fieldof(<PrivateImplementationDetails>.1C1237F52E2ED7B4D229AE3978DA144B9E653F5E).FieldHandle);
BCrypt.KS3 = array6;
}
// Token: 0x0400736C RID: 29548
[Token(Token = "0x400736C")]
private static readonly uint[] MAGIC_STRING;
// Token: 0x0400736D RID: 29549
[Token(Token = "0x400736D")]
internal const int MAGIC_STRING_LENGTH = 6;
// Token: 0x0400736E RID: 29550
[Token(Token = "0x400736E")]
private static readonly uint[] KP;
// Token: 0x0400736F RID: 29551
[Token(Token = "0x400736F")]
private static readonly uint[] KS0;
// Token: 0x04007370 RID: 29552
[Token(Token = "0x4007370")]
private static readonly uint[] KS1;
// Token: 0x04007371 RID: 29553
[Token(Token = "0x4007371")]
private static readonly uint[] KS2;
// Token: 0x04007372 RID: 29554
[Token(Token = "0x4007372")]
private static readonly uint[] KS3;
// Token: 0x04007373 RID: 29555
[Token(Token = "0x4007373")]
private const int ROUNDS = 16;
// Token: 0x04007374 RID: 29556
[Token(Token = "0x4007374")]
private const int SBOX_SK = 256;
// Token: 0x04007375 RID: 29557
[Token(Token = "0x4007375")]
private const int SBOX_SK2 = 512;
// Token: 0x04007376 RID: 29558
[Token(Token = "0x4007376")]
private const int SBOX_SK3 = 768;
// Token: 0x04007377 RID: 29559
[Token(Token = "0x4007377")]
private const int P_SZ = 18;
// Token: 0x04007378 RID: 29560
[FieldOffset(Offset = "0x10")]
[Token(Token = "0x4007378")]
private readonly uint[] S;
// Token: 0x04007379 RID: 29561
[FieldOffset(Offset = "0x18")]
[Token(Token = "0x4007379")]
private readonly uint[] P;
// Token: 0x0400737A RID: 29562
[Token(Token = "0x400737A")]
internal const int SALT_SIZE_BYTES = 16;
// Token: 0x0400737B RID: 29563
[Token(Token = "0x400737B")]
internal const int MIN_COST = 4;
// Token: 0x0400737C RID: 29564
[Token(Token = "0x400737C")]
internal const int MAX_COST = 31;
// Token: 0x0400737D RID: 29565
[Token(Token = "0x400737D")]
internal const int MAX_PASSWORD_BYTES = 72;
}
}