423 lines
14 KiB
C#
423 lines
14 KiB
C#
using System;
|
|
using System.Runtime.CompilerServices;
|
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
|
using Cpp2IlInjected;
|
|
|
|
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Macs
|
|
{
|
|
// Token: 0x02001D30 RID: 7472
|
|
[Token(Token = "0x2001D30")]
|
|
public class Gost28147Mac : IMac
|
|
{
|
|
// Token: 0x0600B932 RID: 47410 RVA: 0x00282F50 File Offset: 0x00281150
|
|
[Token(Token = "0x600B932")]
|
|
[Address(RVA = "0x25BC3E0", Offset = "0x25BB3E0", VA = "0x1825BC3E0")]
|
|
public Gost28147Mac()
|
|
{
|
|
byte[] array = new byte[128];
|
|
RuntimeHelpers.InitializeArray(array, fieldof(<PrivateImplementationDetails>.2BA9E4B370D477F8C7FE286262D7ADC69CAF290E).FieldHandle);
|
|
this.S = array;
|
|
base..ctor();
|
|
byte[] array2 = new byte[8];
|
|
this.mac = array2;
|
|
byte[] array3 = new byte[8];
|
|
this.buf = array3;
|
|
this.bufOff = (int)((ulong)0L);
|
|
}
|
|
|
|
// Token: 0x0600B933 RID: 47411 RVA: 0x00282FAC File Offset: 0x002811AC
|
|
[Token(Token = "0x600B933")]
|
|
[Address(RVA = "0x25BBD90", Offset = "0x25BAD90", VA = "0x1825BBD90")]
|
|
private static int[] GenerateWorkingKey(byte[] userKey)
|
|
{
|
|
/*
|
|
An exception occurred when decompiling this method (0600B933)
|
|
|
|
ICSharpCode.Decompiler.DecompilerException: Error decompiling System.Int32[] BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Macs.Gost28147Mac::GenerateWorkingKey(System.Byte[])
|
|
|
|
---> System.Exception: Basic block has to end with unconditional control flow.
|
|
{
|
|
IL_33:
|
|
stloc:ArgumentException(var_3_3D, newobj:ArgumentException(ArgumentException::.ctor, ldstr:string("Key length invalid. Key needs to be 32 byte - 256 bit!!!")))
|
|
}
|
|
|
|
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.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: 0x0600B934 RID: 47412 RVA: 0x00282FF8 File Offset: 0x002811F8
|
|
[Token(Token = "0x600B934")]
|
|
[Address(RVA = "0x25BBE70", Offset = "0x25BAE70", VA = "0x1825BBE70", Slot = "4")]
|
|
public void Init(ICipherParameters parameters)
|
|
{
|
|
for (;;)
|
|
{
|
|
byte[] array = this.buf;
|
|
int length = array.Length;
|
|
int num = 0;
|
|
Array.Clear(array, num, length);
|
|
int num2 = 0;
|
|
this.bufOff = num2;
|
|
byte[] array2 = new byte[0];
|
|
this.buf = array2;
|
|
this.macIV = num2;
|
|
if (parameters != 0)
|
|
{
|
|
if ("{il2cpp array field local7->}" == typeof(ParametersWithSBox).TypeHandle)
|
|
{
|
|
}
|
|
int num3;
|
|
if (parameters == 0)
|
|
{
|
|
if (parameters == 0)
|
|
{
|
|
if (parameters != 0 && parameters != 0)
|
|
{
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
if (parameters == 0)
|
|
{
|
|
continue;
|
|
}
|
|
num3 = 0;
|
|
if (parameters == 0)
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
if (parameters != 0)
|
|
{
|
|
while (num3 == 0)
|
|
{
|
|
}
|
|
if (num3 != 0 && num3 != 0)
|
|
{
|
|
goto Block_8;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
byte[] array4;
|
|
int[] array3 = Gost28147Mac.GenerateWorkingKey(array4);
|
|
this.workingKey = array3;
|
|
byte[] array5 = this.mac;
|
|
int length2 = array5.Length;
|
|
int num4 = 0;
|
|
int num5 = 0;
|
|
byte[] array6;
|
|
Array.Copy(array6, num5, array5, num4, length2);
|
|
byte[] array7;
|
|
this.macIV = array7;
|
|
return;
|
|
Block_8:
|
|
byte[] array9;
|
|
int[] array8 = Gost28147Mac.GenerateWorkingKey(array9);
|
|
throw new NullReferenceException();
|
|
}
|
|
|
|
// Token: 0x17001D2E RID: 7470
|
|
// (get) Token: 0x0600B935 RID: 47413 RVA: 0x002830FC File Offset: 0x002812FC
|
|
[Token(Token = "0x17001D2E")]
|
|
public string AlgorithmName
|
|
{
|
|
[Token(Token = "0x600B935")]
|
|
[Address(RVA = "0x25BC540", Offset = "0x25BB540", VA = "0x1825BC540", Slot = "5")]
|
|
get
|
|
{
|
|
return "Gost28147Mac";
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600B936 RID: 47414 RVA: 0x00283110 File Offset: 0x00281310
|
|
[Token(Token = "0x600B936")]
|
|
[Address(RVA = "0x680C20", Offset = "0x67FC20", VA = "0x180680C20", Slot = "6")]
|
|
public int GetMacSize()
|
|
{
|
|
return 4;
|
|
}
|
|
|
|
// Token: 0x0600B937 RID: 47415 RVA: 0x00283120 File Offset: 0x00281320
|
|
[Token(Token = "0x600B937")]
|
|
[Address(RVA = "0x25BC780", Offset = "0x25BB780", VA = "0x1825BC780")]
|
|
private int gost28147_mainStep(int n1, int key)
|
|
{
|
|
int length = this.S.Length;
|
|
byte b;
|
|
byte b2;
|
|
b += b2;
|
|
b += b2;
|
|
b += b2;
|
|
b += b2;
|
|
b += b2;
|
|
b += b2;
|
|
b += b2;
|
|
b2 = b;
|
|
throw new NullReferenceException();
|
|
}
|
|
|
|
// Token: 0x0600B938 RID: 47416 RVA: 0x0028315C File Offset: 0x0028135C
|
|
[Token(Token = "0x600B938")]
|
|
[Address(RVA = "0x25BC570", Offset = "0x25BB570", VA = "0x1825BC570")]
|
|
private void gost28147MacFunc(int[] workingKey, byte[] input, int inOff, byte[] output, int outOff)
|
|
{
|
|
int num = 0;
|
|
int num2 = 0;
|
|
int num3 = workingKey[num2];
|
|
int num4 = this.gost28147_mainStep(inOff, num3);
|
|
num2++;
|
|
num++;
|
|
}
|
|
|
|
// Token: 0x0600B939 RID: 47417 RVA: 0x0028318C File Offset: 0x0028138C
|
|
[Token(Token = "0x600B939")]
|
|
[Address(RVA = "0x25BC480", Offset = "0x25BB480", VA = "0x1825BC480")]
|
|
private static int bytesToint(byte[] input, int inOff)
|
|
{
|
|
int length = input.Length;
|
|
byte b = input[input];
|
|
byte b2 = input[input];
|
|
int num = inOff + 1;
|
|
b += b2;
|
|
b += b2;
|
|
byte b3;
|
|
b += b3;
|
|
throw new NullReferenceException();
|
|
}
|
|
|
|
// Token: 0x0600B93A RID: 47418 RVA: 0x002831C8 File Offset: 0x002813C8
|
|
[Token(Token = "0x600B93A")]
|
|
[Address(RVA = "0x25BC9C0", Offset = "0x25BB9C0", VA = "0x1825BC9C0")]
|
|
private static void intTobytes(int num, byte[] output, int outOff)
|
|
{
|
|
int num2 = outOff + 1;
|
|
}
|
|
|
|
// Token: 0x0600B93B RID: 47419 RVA: 0x002831E0 File Offset: 0x002813E0
|
|
[Token(Token = "0x600B93B")]
|
|
[Address(RVA = "0x25BBB10", Offset = "0x25BAB10", VA = "0x1825BBB10")]
|
|
private static byte[] CM5func(byte[] buf, int bufOff, byte[] mac)
|
|
{
|
|
int num = buf.Length;
|
|
num -= bufOff;
|
|
byte[] array = new byte[num];
|
|
int length = mac.Length;
|
|
int num2 = 0;
|
|
int num3 = 0;
|
|
Array.Copy(buf, bufOff, array, num3, length);
|
|
int length2 = mac.Length;
|
|
if (num2 != length2)
|
|
{
|
|
num2++;
|
|
}
|
|
return array;
|
|
}
|
|
|
|
// Token: 0x0600B93C RID: 47420 RVA: 0x00283230 File Offset: 0x00281430
|
|
[Token(Token = "0x600B93C")]
|
|
[Address(RVA = "0x25BC2B0", Offset = "0x25BB2B0", VA = "0x1825BC2B0", Slot = "7")]
|
|
public void Update(byte input)
|
|
{
|
|
byte[] array = this.buf;
|
|
int num = this.bufOff;
|
|
int length = array.Length;
|
|
if (num == length)
|
|
{
|
|
byte[] array2 = new byte[length];
|
|
int length2 = this.mac.Length;
|
|
int num2 = 0;
|
|
int num3 = 0;
|
|
byte[] array3 = this.buf;
|
|
int num4 = 0;
|
|
Array.Copy(array3, num4, array2, num3, length2);
|
|
if ((this.firstStep ? 1 : 0) == num2)
|
|
{
|
|
}
|
|
byte[] array4 = this.macIV;
|
|
this.firstStep = num2 != 0;
|
|
byte[] array6;
|
|
if (array4 != 0)
|
|
{
|
|
byte[] array5 = this.buf;
|
|
int num5 = 0;
|
|
array6 = Gost28147Mac.CM5func(array5, num5, array4);
|
|
}
|
|
byte[] array7 = this.mac;
|
|
int num6 = 0;
|
|
int[] array8 = this.workingKey;
|
|
this.gost28147MacFunc(array8, array6, num6, array7, num2);
|
|
}
|
|
int num7 = num + 1;
|
|
this.bufOff = num7;
|
|
}
|
|
|
|
// Token: 0x0600B93D RID: 47421 RVA: 0x002832FC File Offset: 0x002814FC
|
|
[Token(Token = "0x600B93D")]
|
|
[Address(RVA = "0x25BB920", Offset = "0x25BA920", VA = "0x1825BB920", Slot = "8")]
|
|
public void BlockUpdate(byte[] input, int inOff, int len)
|
|
{
|
|
int num = this.bufOff;
|
|
uint num2;
|
|
num2 -= (uint)num;
|
|
int num3 = 0;
|
|
if (len > (int)num2)
|
|
{
|
|
byte[] array = this.buf;
|
|
Array.Copy(input, inOff, array, num, (int)num2);
|
|
byte[] array2 = new byte[this.buf.Length];
|
|
int length = this.mac.Length;
|
|
int num4 = 0;
|
|
int num5 = 0;
|
|
Array.Copy(this.buf, num5, array2, num4, length);
|
|
if ((this.firstStep ? 1 : 0) == num3)
|
|
{
|
|
}
|
|
byte[] array3 = this.macIV;
|
|
this.firstStep = num3 != 0;
|
|
byte[] array5;
|
|
if (array3 != 0)
|
|
{
|
|
byte[] array4 = this.buf;
|
|
int num6 = 0;
|
|
array5 = Gost28147Mac.CM5func(array4, num6, array3);
|
|
}
|
|
byte[] array6 = this.mac;
|
|
int num7 = 0;
|
|
int[] array7 = this.workingKey;
|
|
this.gost28147MacFunc(array7, array5, num7, array6, num3);
|
|
this.bufOff = num3;
|
|
if (len > 8)
|
|
{
|
|
byte[] array8 = this.mac;
|
|
byte[] array9 = Gost28147Mac.CM5func(input, inOff, array8);
|
|
byte[] array10 = this.mac;
|
|
int num8 = 0;
|
|
int[] array11 = this.workingKey;
|
|
this.gost28147MacFunc(array11, array9, num8, array10, num3);
|
|
while (len != 8)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
byte[] array12 = this.buf;
|
|
Array.Copy(input, inOff, array12, num, len);
|
|
}
|
|
|
|
// Token: 0x0600B93E RID: 47422 RVA: 0x00283420 File Offset: 0x00281620
|
|
[Token(Token = "0x600B93E")]
|
|
[Address(RVA = "0x25BBC00", Offset = "0x25BAC00", VA = "0x1825BBC00", Slot = "9")]
|
|
public int DoFinal(byte[] output, int outOff)
|
|
{
|
|
int num = this.bufOff;
|
|
if (num < 8)
|
|
{
|
|
byte[] array = this.buf;
|
|
int num2 = num + 1;
|
|
this.bufOff = num2;
|
|
int num3 = this.bufOff;
|
|
}
|
|
byte[] array2 = new byte[this.buf.Length];
|
|
int length = this.mac.Length;
|
|
int num4 = 0;
|
|
int num5 = 0;
|
|
byte[] array3 = this.buf;
|
|
int num6 = 0;
|
|
Array.Copy(array3, num6, array2, num5, length);
|
|
byte[] array6;
|
|
if ((this.firstStep ? 1 : 0) == num4)
|
|
{
|
|
byte[] array4 = this.mac;
|
|
byte[] array5 = this.buf;
|
|
int num7 = 0;
|
|
array6 = Gost28147Mac.CM5func(array5, num7, array4);
|
|
}
|
|
this.firstStep = num4 != 0;
|
|
byte[] array7 = this.mac;
|
|
int num8 = 0;
|
|
int[] array8 = this.workingKey;
|
|
this.gost28147MacFunc(array8, array6, num8, array7, num4);
|
|
byte[] array9 = this.mac;
|
|
int num9 = array9.Length;
|
|
num9 -= array8;
|
|
ulong num10;
|
|
Array.Copy(array9, array8, output, outOff, (int)num10);
|
|
byte[] array10 = this.buf;
|
|
int length2 = array10.Length;
|
|
int num11 = 0;
|
|
Array.Clear(array10, num11, length2);
|
|
this.bufOff = num4;
|
|
this.firstStep = true;
|
|
throw new NullReferenceException();
|
|
}
|
|
|
|
// Token: 0x0600B93F RID: 47423 RVA: 0x00283540 File Offset: 0x00281740
|
|
[Token(Token = "0x600B93F")]
|
|
[Address(RVA = "0x25BC270", Offset = "0x25BB270", VA = "0x1825BC270", Slot = "10")]
|
|
public void Reset()
|
|
{
|
|
byte[] array = this.buf;
|
|
int length = array.Length;
|
|
int num = 0;
|
|
Array.Clear(array, num, length);
|
|
this.bufOff = (int)((ulong)0L);
|
|
this.firstStep = true;
|
|
}
|
|
|
|
// Token: 0x040074C8 RID: 29896
|
|
[Token(Token = "0x40074C8")]
|
|
private const int blockSize = 8;
|
|
|
|
// Token: 0x040074C9 RID: 29897
|
|
[Token(Token = "0x40074C9")]
|
|
private const int macSize = 4;
|
|
|
|
// Token: 0x040074CA RID: 29898
|
|
[FieldOffset(Offset = "0x10")]
|
|
[Token(Token = "0x40074CA")]
|
|
private int bufOff;
|
|
|
|
// Token: 0x040074CB RID: 29899
|
|
[FieldOffset(Offset = "0x18")]
|
|
[Token(Token = "0x40074CB")]
|
|
private byte[] buf;
|
|
|
|
// Token: 0x040074CC RID: 29900
|
|
[FieldOffset(Offset = "0x20")]
|
|
[Token(Token = "0x40074CC")]
|
|
private byte[] mac;
|
|
|
|
// Token: 0x040074CD RID: 29901
|
|
[FieldOffset(Offset = "0x28")]
|
|
[Token(Token = "0x40074CD")]
|
|
private bool firstStep = true;
|
|
|
|
// Token: 0x040074CE RID: 29902
|
|
[FieldOffset(Offset = "0x30")]
|
|
[Token(Token = "0x40074CE")]
|
|
private int[] workingKey;
|
|
|
|
// Token: 0x040074CF RID: 29903
|
|
[FieldOffset(Offset = "0x38")]
|
|
[Token(Token = "0x40074CF")]
|
|
private byte[] macIV;
|
|
|
|
// Token: 0x040074D0 RID: 29904
|
|
[FieldOffset(Offset = "0x40")]
|
|
[Token(Token = "0x40074D0")]
|
|
private byte[] S;
|
|
}
|
|
}
|