357 lines
10 KiB
C#
357 lines
10 KiB
C#
using System;
|
|
using System.Collections;
|
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
|
using Cpp2IlInjected;
|
|
|
|
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Prng.Drbg
|
|
{
|
|
// Token: 0x02001CB6 RID: 7350
|
|
[Token(Token = "0x2001CB6")]
|
|
public class HashSP800Drbg : ISP80090Drbg
|
|
{
|
|
// Token: 0x0600B5FE RID: 46590 RVA: 0x00276654 File Offset: 0x00274854
|
|
[Token(Token = "0x600B5FE")]
|
|
[Address(RVA = "0x235E280", Offset = "0x235D280", VA = "0x18235E280")]
|
|
static HashSP800Drbg()
|
|
{
|
|
IDictionary dictionary = HashSP800Drbg.seedlens;
|
|
IDictionary dictionary2 = HashSP800Drbg.seedlens;
|
|
IDictionary dictionary3 = HashSP800Drbg.seedlens;
|
|
IDictionary dictionary4 = HashSP800Drbg.seedlens;
|
|
IDictionary dictionary5 = HashSP800Drbg.seedlens;
|
|
IDictionary dictionary6 = HashSP800Drbg.seedlens;
|
|
IDictionary dictionary7 = HashSP800Drbg.seedlens;
|
|
}
|
|
|
|
// Token: 0x0600B5FF RID: 46591 RVA: 0x002766CC File Offset: 0x002748CC
|
|
[Token(Token = "0x600B5FF")]
|
|
[Address(RVA = "0x235E5B0", Offset = "0x235D5B0", VA = "0x18235E5B0")]
|
|
public HashSP800Drbg(IDigest digest, int securityStrength, IEntropySource entropySource, byte[] personalizationString, byte[] nonce)
|
|
{
|
|
int num;
|
|
do
|
|
{
|
|
base..ctor();
|
|
this.mDigest = digest;
|
|
this.mEntropySource = entropySource;
|
|
this.mSecurityStrength = securityStrength;
|
|
IDictionary dictionary = HashSP800Drbg.seedlens;
|
|
num = 0;
|
|
}
|
|
while ("{il2cpp array field local12->}" != num);
|
|
byte[] one = HashSP800Drbg.ONE;
|
|
this.mSeedLength = one;
|
|
byte[] entropy = this.GetEntropy();
|
|
byte[][] array = new byte[3][];
|
|
if (entropy != 0)
|
|
{
|
|
}
|
|
array[0] = entropy;
|
|
byte[] array2 = Arrays.ConcatenateAll(array);
|
|
IDigest digest2 = this.mDigest;
|
|
int num2 = this.mSeedLength;
|
|
byte[] array3 = DrbgUtilities.HashDF(digest2, array2, num2);
|
|
this.mV = array3;
|
|
int num3 = array3.Length;
|
|
num3++;
|
|
byte[] array4 = new byte[num3];
|
|
byte[] array5 = this.mV;
|
|
int length = array5.Length;
|
|
int num4 = 0;
|
|
Array.Copy(array5, num4, array4, 1, length);
|
|
int num5 = this.mSeedLength;
|
|
byte[] array6 = DrbgUtilities.HashDF(this.mDigest, array4, num5);
|
|
this.mC = array6;
|
|
this.mReseedCounter = (long)((ulong)1L);
|
|
}
|
|
|
|
// Token: 0x17001C94 RID: 7316
|
|
// (get) Token: 0x0600B600 RID: 46592 RVA: 0x002767CC File Offset: 0x002749CC
|
|
[Token(Token = "0x17001C94")]
|
|
public int BlockSize
|
|
{
|
|
[Token(Token = "0x600B600")]
|
|
[Address(RVA = "0x235EA10", Offset = "0x235DA10", VA = "0x18235EA10", Slot = "4")]
|
|
get
|
|
{
|
|
IDigest digest = this.mDigest;
|
|
throw new NullReferenceException();
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600B601 RID: 46593 RVA: 0x002767E8 File Offset: 0x002749E8
|
|
[Token(Token = "0x600B601")]
|
|
[Address(RVA = "0x235D910", Offset = "0x235C910", VA = "0x18235D910", Slot = "5")]
|
|
public int Generate(byte[] output, byte[] additionalInput, bool predictionResistant)
|
|
{
|
|
int length = output.Length;
|
|
long num = this.mReseedCounter;
|
|
if (predictionResistant)
|
|
{
|
|
this.Reseed(additionalInput);
|
|
}
|
|
if (additionalInput != 0)
|
|
{
|
|
byte[] array = this.mV;
|
|
int num2 = additionalInput.Length;
|
|
num2++;
|
|
byte[] array2 = new byte[num2];
|
|
array2[0] = (byte)((ulong)2L);
|
|
byte[] array3 = this.mV;
|
|
int length2 = array3.Length;
|
|
int num3 = 0;
|
|
uint num4;
|
|
Array.Copy(array3, num3, array2, (int)num4, length2);
|
|
int num5 = this.mV.Length;
|
|
int length3 = additionalInput.Length;
|
|
num5++;
|
|
int num6 = 0;
|
|
Array.Copy(additionalInput, num6, array2, num5, length3);
|
|
byte[] array4 = this.Hash(array2);
|
|
byte[] array5 = this.mV;
|
|
this.AddTo(array5, array4);
|
|
}
|
|
byte[] array6 = this.mV;
|
|
IDigest digest = this.mDigest;
|
|
byte[] array7 = new byte[array6.Length];
|
|
int length4 = array6.Length;
|
|
int num7 = 0;
|
|
int num8 = 0;
|
|
Array.Copy(array6, num8, array7, num7, length4);
|
|
byte[] array8 = new byte[additionalInput];
|
|
IDigest digest2 = this.mDigest;
|
|
byte[] array9 = new byte[array8];
|
|
int i = 0;
|
|
this.DoHash(array7, array9);
|
|
int num9 = array9.Length;
|
|
int num10 = array8.Length;
|
|
int num11 = i * num9;
|
|
num10 -= num11;
|
|
if (num10 <= num9)
|
|
{
|
|
num9 = num10;
|
|
}
|
|
int num12 = 0;
|
|
Array.Copy(array9, num12, array8, num11, num9);
|
|
byte[] one = HashSP800Drbg.ONE;
|
|
this.AddTo(array7, one);
|
|
i++;
|
|
while (i <= additionalInput)
|
|
{
|
|
}
|
|
int num13 = this.mV.Length;
|
|
num13++;
|
|
byte[] array10 = new byte[num13];
|
|
byte[] array11 = this.mV;
|
|
int length5 = array11.Length;
|
|
int num14 = 0;
|
|
Array.Copy(array11, num14, array10, 1, length5);
|
|
array10[0] = (byte)((ulong)3L);
|
|
byte[] array12 = this.Hash(array10);
|
|
byte[] array13 = this.mV;
|
|
this.AddTo(array13, array12);
|
|
byte[] array14 = this.mC;
|
|
byte[] array15 = this.mV;
|
|
this.AddTo(array15, array14);
|
|
byte[] array16 = new byte[0];
|
|
long num15 = this.mReseedCounter;
|
|
array16[0] = (byte)num15;
|
|
long num16 = this.mReseedCounter;
|
|
array16[0] = (byte)num16;
|
|
long num17 = this.mReseedCounter;
|
|
array16[0] = (byte)num17;
|
|
long num18 = this.mReseedCounter;
|
|
array16[0] = (byte)num18;
|
|
byte[] array17 = this.mV;
|
|
this.AddTo(array17, array16);
|
|
int num19 = 0;
|
|
int length6 = output.Length;
|
|
int num20 = 0;
|
|
Array.Copy(array8, num20, output, num19, length6);
|
|
return length;
|
|
}
|
|
|
|
// Token: 0x0600B602 RID: 46594 RVA: 0x00276A70 File Offset: 0x00274C70
|
|
[Token(Token = "0x600B602")]
|
|
[Address(RVA = "0x235DE70", Offset = "0x235CE70", VA = "0x18235DE70")]
|
|
private byte[] GetEntropy()
|
|
{
|
|
IEntropySource entropySource = this.mEntropySource;
|
|
int num = this.mSecurityStrength;
|
|
num += 7;
|
|
num += typeof(IEntropySource).TypeHandle;
|
|
throw new NullReferenceException();
|
|
}
|
|
|
|
// Token: 0x0600B603 RID: 46595 RVA: 0x00276A9C File Offset: 0x00274C9C
|
|
[Token(Token = "0x600B603")]
|
|
[Address(RVA = "0x235D780", Offset = "0x235C780", VA = "0x18235D780")]
|
|
private void AddTo(byte[] longer, byte[] shorter)
|
|
{
|
|
int length = shorter.Length;
|
|
int num = 0;
|
|
int num2 = longer.Length;
|
|
int num3 = length - 1;
|
|
num2 -= length;
|
|
byte b;
|
|
num += (int)b;
|
|
byte b2;
|
|
num += (int)b2;
|
|
num3 = num2 - 1;
|
|
byte b3;
|
|
num += (int)b3;
|
|
}
|
|
|
|
// Token: 0x0600B604 RID: 46596 RVA: 0x00276ADC File Offset: 0x00274CDC
|
|
[Token(Token = "0x600B604")]
|
|
[Address(RVA = "0x235DFA0", Offset = "0x235CFA0", VA = "0x18235DFA0", Slot = "6")]
|
|
public void Reseed(byte[] additionalInput)
|
|
{
|
|
byte[] entropy = this.GetEntropy();
|
|
byte[][] array = new byte[4][];
|
|
byte[] one = HashSP800Drbg.ONE;
|
|
if (one != 0)
|
|
{
|
|
}
|
|
array[0] = one;
|
|
byte[] array2 = this.mV;
|
|
if (array2 != 0)
|
|
{
|
|
}
|
|
array[1] = array2;
|
|
if (entropy != 0)
|
|
{
|
|
}
|
|
array[2] = entropy;
|
|
if (additionalInput != 0)
|
|
{
|
|
}
|
|
array[3] = additionalInput;
|
|
byte[] array3 = Arrays.ConcatenateAll(array);
|
|
IDigest digest = this.mDigest;
|
|
int num = this.mSeedLength;
|
|
byte[] array4 = DrbgUtilities.HashDF(digest, array3, num);
|
|
this.mV = array4;
|
|
int num2 = array4.Length;
|
|
num2++;
|
|
byte[] array5 = new byte[num2];
|
|
array5[0] = (byte)((ulong)0L);
|
|
byte[] array6 = this.mV;
|
|
int length = array6.Length;
|
|
int num3 = 0;
|
|
Array.Copy(array6, num3, array5, 1, length);
|
|
int num4 = this.mSeedLength;
|
|
byte[] array7 = DrbgUtilities.HashDF(this.mDigest, array5, num4);
|
|
this.mC = array7;
|
|
this.mReseedCounter = (long)((ulong)1L);
|
|
}
|
|
|
|
// Token: 0x0600B605 RID: 46597 RVA: 0x00276BD8 File Offset: 0x00274DD8
|
|
[Token(Token = "0x600B605")]
|
|
[Address(RVA = "0x235DF10", Offset = "0x235CF10", VA = "0x18235DF10")]
|
|
private byte[] Hash(byte[] input)
|
|
{
|
|
IDigest digest = this.mDigest;
|
|
byte[] array = new byte[0];
|
|
this.DoHash(input, array);
|
|
return array;
|
|
}
|
|
|
|
// Token: 0x0600B606 RID: 46598 RVA: 0x00276C04 File Offset: 0x00274E04
|
|
[Token(Token = "0x600B606")]
|
|
[Address(RVA = "0x235D870", Offset = "0x235C870", VA = "0x18235D870")]
|
|
private void DoHash(byte[] input, byte[] output)
|
|
{
|
|
IDigest digest = this.mDigest;
|
|
int length = input.Length;
|
|
IDigest digest2 = this.mDigest;
|
|
}
|
|
|
|
// Token: 0x0600B607 RID: 46599 RVA: 0x00276C2C File Offset: 0x00274E2C
|
|
[Token(Token = "0x600B607")]
|
|
[Address(RVA = "0x235EA60", Offset = "0x235DA60", VA = "0x18235EA60")]
|
|
private byte[] hashgen(byte[] input, int lengthInBits)
|
|
{
|
|
IDigest digest = this.mDigest;
|
|
byte[] array = new byte[input.Length];
|
|
int length = input.Length;
|
|
int i = 0;
|
|
int num = 0;
|
|
int num2 = 0;
|
|
Array.Copy(input, num2, array, num, length);
|
|
byte[] array2 = new byte[lengthInBits];
|
|
IDigest digest2 = this.mDigest;
|
|
byte[] array3 = new byte[array2];
|
|
this.DoHash(array, array3);
|
|
int num3 = array3.Length;
|
|
int num4 = array2.Length;
|
|
int num5 = num3 * i;
|
|
num4 -= num5;
|
|
if (num4 <= num3)
|
|
{
|
|
num3 = num4;
|
|
}
|
|
int num6 = 0;
|
|
Array.Copy(array3, num6, array2, num5, num3);
|
|
byte[] one = HashSP800Drbg.ONE;
|
|
this.AddTo(array, one);
|
|
i++;
|
|
while (i <= lengthInBits)
|
|
{
|
|
}
|
|
return array2;
|
|
}
|
|
|
|
// Token: 0x04007343 RID: 29507
|
|
[Token(Token = "0x4007343")]
|
|
private static readonly byte[] ONE = new byte[] { (byte)((ulong)1L) };
|
|
|
|
// Token: 0x04007344 RID: 29508
|
|
[Token(Token = "0x4007344")]
|
|
private static readonly long RESEED_MAX = (long)((ulong)140737488355328L);
|
|
|
|
// Token: 0x04007345 RID: 29509
|
|
[Token(Token = "0x4007345")]
|
|
private static readonly int MAX_BITS_REQUEST;
|
|
|
|
// Token: 0x04007346 RID: 29510
|
|
[Token(Token = "0x4007346")]
|
|
private static readonly IDictionary seedlens = Platform.CreateHashtable();
|
|
|
|
// Token: 0x04007347 RID: 29511
|
|
[FieldOffset(Offset = "0x10")]
|
|
[Token(Token = "0x4007347")]
|
|
private readonly IDigest mDigest;
|
|
|
|
// Token: 0x04007348 RID: 29512
|
|
[FieldOffset(Offset = "0x18")]
|
|
[Token(Token = "0x4007348")]
|
|
private readonly IEntropySource mEntropySource;
|
|
|
|
// Token: 0x04007349 RID: 29513
|
|
[FieldOffset(Offset = "0x20")]
|
|
[Token(Token = "0x4007349")]
|
|
private readonly int mSecurityStrength;
|
|
|
|
// Token: 0x0400734A RID: 29514
|
|
[FieldOffset(Offset = "0x24")]
|
|
[Token(Token = "0x400734A")]
|
|
private readonly int mSeedLength;
|
|
|
|
// Token: 0x0400734B RID: 29515
|
|
[FieldOffset(Offset = "0x28")]
|
|
[Token(Token = "0x400734B")]
|
|
private byte[] mV;
|
|
|
|
// Token: 0x0400734C RID: 29516
|
|
[FieldOffset(Offset = "0x30")]
|
|
[Token(Token = "0x400734C")]
|
|
private byte[] mC;
|
|
|
|
// Token: 0x0400734D RID: 29517
|
|
[FieldOffset(Offset = "0x38")]
|
|
[Token(Token = "0x400734D")]
|
|
private long mReseedCounter;
|
|
}
|
|
}
|