mirror of
https://github.com/vxunderground/MalwareSourceCode.git
synced 2024-12-19 09:56:10 +00:00
88 lines
3.3 KiB
C#
88 lines
3.3 KiB
C#
|
// Decompiled with JetBrains decompiler
|
|||
|
// Type: Microsoft.InfoCards.Psha1DerivedKeyGenerator
|
|||
|
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
|
|||
|
// MVID: 516D8B44-4448-4D2C-8B8E-FFBB3FFE472B
|
|||
|
// Assembly location: C:\Users\Administrateur\Downloads\Virusshare-00000-msil\Virus.Win32.Expiro.w-69bb73081eac86b8cf86f45e33515d0095855636967076e2b593d7a30cd80a07.exe
|
|||
|
|
|||
|
using Microsoft.InfoCards.Diagnostics;
|
|||
|
using System;
|
|||
|
using System.Security.Cryptography;
|
|||
|
|
|||
|
namespace Microsoft.InfoCards
|
|||
|
{
|
|||
|
internal sealed class Psha1DerivedKeyGenerator
|
|||
|
{
|
|||
|
private byte[] key;
|
|||
|
|
|||
|
public Psha1DerivedKeyGenerator(byte[] key) => this.key = key != null ? key : throw InfoCardTrace.ThrowHelperArgumentNull(nameof (key));
|
|||
|
|
|||
|
public byte[] GenerateDerivedKey(byte[] label, byte[] nonce, int derivedKeySize, int position)
|
|||
|
{
|
|||
|
if (label == null)
|
|||
|
throw InfoCardTrace.ThrowHelperArgumentNull(nameof (label));
|
|||
|
if (nonce == null)
|
|||
|
throw InfoCardTrace.ThrowHelperArgumentNull(nameof (nonce));
|
|||
|
return new Psha1DerivedKeyGenerator.ManagedPsha1(this.key, label, nonce).GetDerivedKey(derivedKeySize, position);
|
|||
|
}
|
|||
|
|
|||
|
private sealed class ManagedPsha1
|
|||
|
{
|
|||
|
private byte[] aValue;
|
|||
|
private byte[] buffer;
|
|||
|
private byte[] chunk;
|
|||
|
private KeyedHashAlgorithm hmac;
|
|||
|
private int index;
|
|||
|
private int position;
|
|||
|
private byte[] secret;
|
|||
|
private byte[] seed;
|
|||
|
|
|||
|
public ManagedPsha1(byte[] secret, byte[] label, byte[] seed)
|
|||
|
{
|
|||
|
this.secret = secret;
|
|||
|
this.seed = new byte[checked (label.Length + seed.Length)];
|
|||
|
label.CopyTo((Array) this.seed, 0);
|
|||
|
seed.CopyTo((Array) this.seed, label.Length);
|
|||
|
this.aValue = this.seed;
|
|||
|
this.chunk = new byte[0];
|
|||
|
this.index = 0;
|
|||
|
this.position = 0;
|
|||
|
this.hmac = (KeyedHashAlgorithm) new HMACSHA1(secret, true);
|
|||
|
this.buffer = new byte[checked (unchecked (this.hmac.HashSize / 8) + this.seed.Length)];
|
|||
|
}
|
|||
|
|
|||
|
public byte[] GetDerivedKey(int derivedKeySize, int position)
|
|||
|
{
|
|||
|
if (derivedKeySize < 0)
|
|||
|
throw InfoCardTrace.ThrowHelperError((Exception) new ArgumentOutOfRangeException(nameof (derivedKeySize), SR.GetString("ValueMustBeNonNegative")));
|
|||
|
if (this.position > position)
|
|||
|
throw InfoCardTrace.ThrowHelperError((Exception) new ArgumentOutOfRangeException(nameof (position), SR.GetString("ValueMustBeInRange", (object) 0, (object) this.position)));
|
|||
|
while (this.position < position)
|
|||
|
{
|
|||
|
int num = (int) this.GetByte();
|
|||
|
}
|
|||
|
int length = derivedKeySize / 8;
|
|||
|
byte[] derivedKey = new byte[length];
|
|||
|
for (int index = 0; index < length; ++index)
|
|||
|
derivedKey[index] = this.GetByte();
|
|||
|
return derivedKey;
|
|||
|
}
|
|||
|
|
|||
|
private byte GetByte()
|
|||
|
{
|
|||
|
if (this.index >= this.chunk.Length)
|
|||
|
{
|
|||
|
this.hmac.Initialize();
|
|||
|
this.aValue = this.hmac.ComputeHash(this.aValue);
|
|||
|
this.aValue.CopyTo((Array) this.buffer, 0);
|
|||
|
this.seed.CopyTo((Array) this.buffer, this.aValue.Length);
|
|||
|
this.hmac.Initialize();
|
|||
|
this.chunk = this.hmac.ComputeHash(this.buffer);
|
|||
|
this.index = 0;
|
|||
|
}
|
|||
|
++this.position;
|
|||
|
return this.chunk[this.index++];
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|