456 lines
15 KiB
C#
456 lines
15 KiB
C#
using System;
|
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Encoders;
|
|
using Cpp2IlInjected;
|
|
|
|
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Prng.Drbg
|
|
{
|
|
// Token: 0x02001BD3 RID: 7123
|
|
[Token(Token = "0x2001BD3")]
|
|
public class CtrSP800Drbg : ISP80090Drbg
|
|
{
|
|
// Token: 0x0600B210 RID: 45584 RVA: 0x0026C6E0 File Offset: 0x0026A8E0
|
|
[Token(Token = "0x600B210")]
|
|
[Address(RVA = "0x1801DA0", Offset = "0x1800BA0", VA = "0x181801DA0")]
|
|
public CtrSP800Drbg(IBlockCipher engine, int keySizeInBits, int securityStrength, IEntropySource entropySource, byte[] personalizationString, byte[] nonce)
|
|
{
|
|
if (!this.IsTdea(engine) || keySizeInBits == 168)
|
|
{
|
|
}
|
|
this.mEntropySource = 0;
|
|
this.mEngine = engine;
|
|
this.mKeySizeInBits = keySizeInBits;
|
|
this.mSecurityStrength = securityStrength;
|
|
this.mSeedLength = (int)((uint)2);
|
|
bool flag = this.IsTdea(engine);
|
|
this.mIsTdea = flag;
|
|
byte[] entropy = this.GetEntropy();
|
|
}
|
|
|
|
// Token: 0x0600B211 RID: 45585 RVA: 0x0026C74C File Offset: 0x0026A94C
|
|
[Token(Token = "0x600B211")]
|
|
[Address(RVA = "0x1800A50", Offset = "0x17FF850", VA = "0x181800A50")]
|
|
private void CTR_DRBG_Instantiate_algorithm(byte[] entropy, byte[] nonce, byte[] personalisationString)
|
|
{
|
|
byte[][] array = new byte[3][];
|
|
if (entropy != 0)
|
|
{
|
|
}
|
|
array[0] = entropy;
|
|
if (nonce != 0)
|
|
{
|
|
}
|
|
array[1] = nonce;
|
|
if (personalisationString != 0)
|
|
{
|
|
}
|
|
array[2] = personalisationString;
|
|
byte[] array2 = Arrays.ConcatenateAll(array);
|
|
int num = this.mSeedLength;
|
|
byte[] array3 = this.Block_Cipher_df(array2, num);
|
|
IBlockCipher blockCipher = this.mEngine;
|
|
int num2 = this.mKeySizeInBits;
|
|
num2 += 7;
|
|
byte[] array4 = new byte[0];
|
|
this.mKey = array4;
|
|
byte[] array5 = new byte[array3];
|
|
byte[] array6 = this.mKey;
|
|
this.mV = array5;
|
|
this.CTR_DRBG_Update(array3, array6, array5);
|
|
this.mReseedCounter = (long)((ulong)1L);
|
|
}
|
|
|
|
// Token: 0x0600B212 RID: 45586 RVA: 0x0026C7F8 File Offset: 0x0026A9F8
|
|
[Token(Token = "0x600B212")]
|
|
[Address(RVA = "0x1800D20", Offset = "0x17FFB20", VA = "0x181800D20")]
|
|
private void CTR_DRBG_Update(byte[] seed, byte[] key, byte[] v)
|
|
{
|
|
byte[] array = new byte[seed.Length];
|
|
IBlockCipher blockCipher = this.mEngine;
|
|
byte[] array2 = new byte[array];
|
|
IBlockCipher blockCipher2 = this.mEngine;
|
|
IBlockCipher blockCipher3 = this.mEngine;
|
|
KeyParameter keyParameter = new KeyParameter(this.ExpandKey(key));
|
|
int num = 0;
|
|
int num6;
|
|
if (num < seed.Length)
|
|
{
|
|
int num2 = v.Length;
|
|
uint num3;
|
|
num2 -= (int)num3;
|
|
byte b;
|
|
num3 += (uint)b;
|
|
IBlockCipher blockCipher4 = this.mEngine;
|
|
if (num < num2)
|
|
{
|
|
num += num;
|
|
num++;
|
|
}
|
|
int num4 = array.Length;
|
|
num4 -= num;
|
|
int num5 = 0;
|
|
num += array2;
|
|
num6 = 0;
|
|
num5 += num5;
|
|
num += 4;
|
|
num += 19;
|
|
}
|
|
int length = array.Length;
|
|
if (num6 < length)
|
|
{
|
|
num6++;
|
|
}
|
|
int num7 = 0;
|
|
int length2 = v.Length;
|
|
int num8 = 0;
|
|
Array.Copy(array, num7, v, num8, length2);
|
|
}
|
|
|
|
// Token: 0x0600B213 RID: 45587 RVA: 0x0026C8E0 File Offset: 0x0026AAE0
|
|
[Token(Token = "0x600B213")]
|
|
[Address(RVA = "0x1800C70", Offset = "0x17FFA70", VA = "0x181800C70")]
|
|
private void CTR_DRBG_Reseed_algorithm(byte[] additionalInput)
|
|
{
|
|
byte[] array = Arrays.Concatenate(this.GetEntropy(), additionalInput);
|
|
int num = this.mSeedLength;
|
|
byte[] array2 = this.Block_Cipher_df(array, num);
|
|
byte[] array3 = this.mV;
|
|
byte[] array4 = this.mKey;
|
|
this.CTR_DRBG_Update(array2, array4, array3);
|
|
this.mReseedCounter = (long)((ulong)1L);
|
|
}
|
|
|
|
// Token: 0x0600B214 RID: 45588 RVA: 0x0026C92C File Offset: 0x0026AB2C
|
|
[Token(Token = "0x600B214")]
|
|
[Address(RVA = "0x1801C40", Offset = "0x1800A40", VA = "0x181801C40")]
|
|
private void XOR(byte[] output, byte[] a, byte[] b, int bOff)
|
|
{
|
|
int num = 0;
|
|
int length = output.Length;
|
|
if (num < length)
|
|
{
|
|
num++;
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600B215 RID: 45589 RVA: 0x0026C950 File Offset: 0x0026AB50
|
|
[Token(Token = "0x600B215")]
|
|
[Address(RVA = "0x1800220", Offset = "0x17FF020", VA = "0x181800220")]
|
|
private void AddOneTo(byte[] longer)
|
|
{
|
|
int num = longer.Length;
|
|
uint num2;
|
|
num -= (int)num2;
|
|
byte b;
|
|
num2 += (uint)b;
|
|
}
|
|
|
|
// Token: 0x0600B216 RID: 45590 RVA: 0x0026C974 File Offset: 0x0026AB74
|
|
[Token(Token = "0x600B216")]
|
|
[Address(RVA = "0x18015A0", Offset = "0x18003A0", VA = "0x1818015A0")]
|
|
private byte[] GetEntropy()
|
|
{
|
|
IEntropySource entropySource = this.mEntropySource;
|
|
int num = this.mSecurityStrength;
|
|
num += 7;
|
|
num += typeof(IEntropySource).TypeHandle;
|
|
throw new NullReferenceException();
|
|
}
|
|
|
|
// Token: 0x0600B217 RID: 45591 RVA: 0x0026C9A0 File Offset: 0x0026ABA0
|
|
[Token(Token = "0x600B217")]
|
|
[Address(RVA = "0x1800570", Offset = "0x17FF370", VA = "0x181800570")]
|
|
private byte[] Block_Cipher_df(byte[] inputString, int bitLength)
|
|
{
|
|
IBlockCipher blockCipher = this.mEngine;
|
|
int length = inputString.Length;
|
|
byte[] array = new byte[0];
|
|
int num = 0;
|
|
int num2 = 0;
|
|
this.copyIntToByteArray(array, length, num2);
|
|
this.copyIntToByteArray(array, length, 4);
|
|
int num3 = 0;
|
|
Array.Copy(inputString, num3, array, 8, length);
|
|
int num4 = this.mKeySizeInBits;
|
|
num3 += num4;
|
|
byte[] array2 = new byte[num3];
|
|
byte[] array3 = new byte[num3];
|
|
byte[] array4 = new byte[num3];
|
|
int num5 = this.mKeySizeInBits;
|
|
num3 += num5;
|
|
byte[] array5 = new byte[num3];
|
|
int num6 = 0;
|
|
int length2 = array5.Length;
|
|
int num7 = 0;
|
|
byte[] k_BITS = CtrSP800Drbg.K_BITS;
|
|
Array.Copy(k_BITS, num7, array5, num6, length2);
|
|
int num9;
|
|
if (k_BITS > 0)
|
|
{
|
|
array4[0] = (byte)num;
|
|
array4[0] = (byte)num;
|
|
array4[0] = (byte)num;
|
|
array4[0] = (byte)num;
|
|
this.BCC(array3, array5, array4, array);
|
|
int num8 = array2.Length;
|
|
num8 -= num;
|
|
num9 = 0;
|
|
Array.Copy(array3, num9, array2, num, num8);
|
|
int num10 = this.mKeySizeInBits;
|
|
num += num9;
|
|
num10 += num9;
|
|
num++;
|
|
}
|
|
byte[] array6 = new byte[num9];
|
|
int length3 = array5.Length;
|
|
int num11 = 0;
|
|
int num12 = 0;
|
|
Array.Copy(array2, num12, array5, num11, length3);
|
|
int length4 = array6.Length;
|
|
int num13 = 0;
|
|
int length5 = array5.Length;
|
|
Array.Copy(array2, length5, array6, num13, length4);
|
|
byte[] array7 = new byte[0];
|
|
IBlockCipher blockCipher2 = this.mEngine;
|
|
KeyParameter keyParameter = new KeyParameter(this.ExpandKey(array5));
|
|
int num14 = 0;
|
|
if (num14 < array7.Length)
|
|
{
|
|
IBlockCipher blockCipher3 = this.mEngine;
|
|
if (num14 < blockCipher2)
|
|
{
|
|
num14 += num14;
|
|
num14++;
|
|
}
|
|
int num15 = array7.Length;
|
|
num15 -= num14;
|
|
int num16 = 0;
|
|
Array.Copy(array6, num16, array7, num14, num15);
|
|
num16 += num16;
|
|
num14 += 4;
|
|
num14 += 19;
|
|
}
|
|
return array7;
|
|
}
|
|
|
|
// Token: 0x0600B218 RID: 45592 RVA: 0x0026CB94 File Offset: 0x0026AD94
|
|
[Token(Token = "0x600B218")]
|
|
[Address(RVA = "0x1800280", Offset = "0x17FF080", VA = "0x181800280")]
|
|
private void BCC(byte[] bccOut, byte[] k, byte[] iV, byte[] data)
|
|
{
|
|
IBlockCipher blockCipher = this.mEngine;
|
|
byte[] array = new byte[0];
|
|
byte[] array2 = new byte[0];
|
|
IBlockCipher blockCipher2 = this.mEngine;
|
|
KeyParameter keyParameter = new KeyParameter(this.ExpandKey(k));
|
|
IBlockCipher blockCipher3 = this.mEngine;
|
|
int num = 0;
|
|
int length = array2.Length;
|
|
if (num < length)
|
|
{
|
|
num++;
|
|
}
|
|
IBlockCipher blockCipher4 = this.mEngine;
|
|
int num2 = 0;
|
|
if (num2 < num)
|
|
{
|
|
num2 += num2;
|
|
num2++;
|
|
}
|
|
num++;
|
|
}
|
|
|
|
// Token: 0x0600B219 RID: 45593 RVA: 0x0026CC24 File Offset: 0x0026AE24
|
|
[Token(Token = "0x600B219")]
|
|
[Address(RVA = "0x1801FD0", Offset = "0x1800DD0", VA = "0x181801FD0")]
|
|
private void copyIntToByteArray(byte[] buf, int value, int offSet)
|
|
{
|
|
int num = offSet + 1;
|
|
}
|
|
|
|
// Token: 0x17001BF5 RID: 7157
|
|
// (get) Token: 0x0600B21A RID: 45594 RVA: 0x0026CC3C File Offset: 0x0026AE3C
|
|
[Token(Token = "0x17001BF5")]
|
|
public int BlockSize
|
|
{
|
|
[Token(Token = "0x600B21A")]
|
|
[Address(RVA = "0x1802070", Offset = "0x1800E70", VA = "0x181802070", Slot = "4")]
|
|
get
|
|
{
|
|
return this.mV.Length;
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600B21B RID: 45595 RVA: 0x0026CC5C File Offset: 0x0026AE5C
|
|
[Token(Token = "0x600B21B")]
|
|
[Address(RVA = "0x1801100", Offset = "0x17FFF00", VA = "0x181801100", Slot = "5")]
|
|
public int Generate(byte[] output, byte[] additionalInput, bool predictionResistant)
|
|
{
|
|
/*
|
|
An exception occurred when decompiling this method (0600B21B)
|
|
|
|
ICSharpCode.Decompiler.DecompilerException: Error decompiling System.Int32 BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Prng.Drbg.CtrSP800Drbg::Generate(System.Byte[],System.Byte[],System.Boolean)
|
|
|
|
---> System.Exception: Basic block has to end with unconditional control flow.
|
|
{
|
|
IL_146:
|
|
stloc:ArgumentException(var_25_15C, newobj:ArgumentException(ArgumentException::.ctor, call:string(string::Concat, ldstr:string[exp:object]("Number of bits per request limited to "), ldloc:ArgumentException[exp:object](var_24)), ldstr:string("output")))
|
|
}
|
|
|
|
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: 0x0600B21C RID: 45596 RVA: 0x0026CDC8 File Offset: 0x0026AFC8
|
|
[Token(Token = "0x600B21C")]
|
|
[Address(RVA = "0x1801C30", Offset = "0x1800A30", VA = "0x181801C30", Slot = "6")]
|
|
public void Reseed(byte[] additionalInput)
|
|
{
|
|
this.CTR_DRBG_Reseed_algorithm(additionalInput);
|
|
}
|
|
|
|
// Token: 0x0600B21D RID: 45597 RVA: 0x0026CDDC File Offset: 0x0026AFDC
|
|
[Token(Token = "0x600B21D")]
|
|
[Address(RVA = "0x18016F0", Offset = "0x18004F0", VA = "0x1818016F0")]
|
|
private bool IsTdea(IBlockCipher cipher)
|
|
{
|
|
bool flag;
|
|
bool flag2;
|
|
return flag || flag2;
|
|
}
|
|
|
|
// Token: 0x0600B21E RID: 45598 RVA: 0x0026CDF8 File Offset: 0x0026AFF8
|
|
[Token(Token = "0x600B21E")]
|
|
[Address(RVA = "0x1801640", Offset = "0x1800440", VA = "0x181801640")]
|
|
private int GetMaxSecurityStrength(IBlockCipher cipher, int keySizeInBits)
|
|
{
|
|
if (!this.IsTdea(cipher) || keySizeInBits == 168)
|
|
{
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
// Token: 0x0600B21F RID: 45599 RVA: 0x0026CE20 File Offset: 0x0026B020
|
|
[Token(Token = "0x600B21F")]
|
|
[Address(RVA = "0x1801030", Offset = "0x17FFE30", VA = "0x181801030")]
|
|
private byte[] ExpandKey(byte[] key)
|
|
{
|
|
if (!this.mIsTdea)
|
|
{
|
|
return key;
|
|
}
|
|
byte[] array = new byte[24];
|
|
int num = 0;
|
|
int num2 = 0;
|
|
this.PadKey(key, num2, array, num);
|
|
ulong num3;
|
|
this.PadKey(key, 7, array, (int)num3);
|
|
ulong num4;
|
|
this.PadKey(key, 14, array, (int)num4);
|
|
return array;
|
|
}
|
|
|
|
// Token: 0x0600B220 RID: 45600 RVA: 0x0026CE68 File Offset: 0x0026B068
|
|
[Token(Token = "0x600B220")]
|
|
[Address(RVA = "0x1801780", Offset = "0x1800580", VA = "0x181801780")]
|
|
private void PadKey(byte[] keyMaster, int keyOff, byte[] tmp, int tmpOff)
|
|
{
|
|
int length = keyMaster.Length;
|
|
int num = keyOff + 1;
|
|
byte b;
|
|
tmp[0] = b;
|
|
int length2 = keyMaster.Length;
|
|
byte b2;
|
|
tmp[0] = b2;
|
|
int length3 = keyMaster.Length;
|
|
byte b3;
|
|
tmp[0] = b3;
|
|
int length4 = keyMaster.Length;
|
|
byte b4;
|
|
tmp[0] = b4;
|
|
int length5 = keyMaster.Length;
|
|
byte b5;
|
|
tmp[0] = b5;
|
|
int length6 = keyMaster.Length;
|
|
byte b6;
|
|
b6 += b6;
|
|
int length7 = tmp.Length;
|
|
int length8 = tmp.Length;
|
|
byte b7;
|
|
tmp[0] = b7;
|
|
}
|
|
|
|
// Token: 0x04007173 RID: 29043
|
|
[Token(Token = "0x4007173")]
|
|
private static readonly long TDEA_RESEED_MAX = (long)((uint)int.MinValue);
|
|
|
|
// Token: 0x04007174 RID: 29044
|
|
[Token(Token = "0x4007174")]
|
|
private static readonly long AES_RESEED_MAX = (long)((ulong)140737488355328L);
|
|
|
|
// Token: 0x04007175 RID: 29045
|
|
[Token(Token = "0x4007175")]
|
|
private static readonly int TDEA_MAX_BITS_REQUEST;
|
|
|
|
// Token: 0x04007176 RID: 29046
|
|
[Token(Token = "0x4007176")]
|
|
private static readonly int AES_MAX_BITS_REQUEST;
|
|
|
|
// Token: 0x04007177 RID: 29047
|
|
[FieldOffset(Offset = "0x10")]
|
|
[Token(Token = "0x4007177")]
|
|
private readonly IEntropySource mEntropySource;
|
|
|
|
// Token: 0x04007178 RID: 29048
|
|
[FieldOffset(Offset = "0x18")]
|
|
[Token(Token = "0x4007178")]
|
|
private readonly IBlockCipher mEngine;
|
|
|
|
// Token: 0x04007179 RID: 29049
|
|
[FieldOffset(Offset = "0x20")]
|
|
[Token(Token = "0x4007179")]
|
|
private readonly int mKeySizeInBits;
|
|
|
|
// Token: 0x0400717A RID: 29050
|
|
[FieldOffset(Offset = "0x24")]
|
|
[Token(Token = "0x400717A")]
|
|
private readonly int mSeedLength;
|
|
|
|
// Token: 0x0400717B RID: 29051
|
|
[FieldOffset(Offset = "0x28")]
|
|
[Token(Token = "0x400717B")]
|
|
private readonly int mSecurityStrength;
|
|
|
|
// Token: 0x0400717C RID: 29052
|
|
[FieldOffset(Offset = "0x30")]
|
|
[Token(Token = "0x400717C")]
|
|
private byte[] mKey;
|
|
|
|
// Token: 0x0400717D RID: 29053
|
|
[FieldOffset(Offset = "0x38")]
|
|
[Token(Token = "0x400717D")]
|
|
private byte[] mV;
|
|
|
|
// Token: 0x0400717E RID: 29054
|
|
[FieldOffset(Offset = "0x40")]
|
|
[Token(Token = "0x400717E")]
|
|
private long mReseedCounter;
|
|
|
|
// Token: 0x0400717F RID: 29055
|
|
[FieldOffset(Offset = "0x48")]
|
|
[Token(Token = "0x400717F")]
|
|
private bool mIsTdea;
|
|
|
|
// Token: 0x04007180 RID: 29056
|
|
[Token(Token = "0x4007180")]
|
|
private static readonly byte[] K_BITS = Hex.Decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F");
|
|
}
|
|
}
|