update sharpcifs

This commit is contained in:
Luke Pulverenti
2017-07-08 03:25:24 -04:00
parent a7187180bf
commit 71eb9f143f
220 changed files with 23703 additions and 25613 deletions

View File

@@ -19,99 +19,99 @@ using SharpCifs.Util.Sharpen;
namespace SharpCifs.Util
{
/// <summary>This is an implementation of the HMACT64 keyed hashing algorithm.</summary>
/// <remarks>
/// This is an implementation of the HMACT64 keyed hashing algorithm.
/// HMACT64 is defined by Luke Leighton as a modified HMAC-MD5 (RFC 2104)
/// in which the key is truncated at 64 bytes (rather than being hashed
/// via MD5).
/// </remarks>
public class Hmact64 : MessageDigest
{
private const int BlockLength = 64;
/// <summary>This is an implementation of the HMACT64 keyed hashing algorithm.</summary>
/// <remarks>
/// This is an implementation of the HMACT64 keyed hashing algorithm.
/// HMACT64 is defined by Luke Leighton as a modified HMAC-MD5 (RFC 2104)
/// in which the key is truncated at 64 bytes (rather than being hashed
/// via MD5).
/// </remarks>
public class Hmact64 : MessageDigest
{
private const int BlockLength = 64;
private const byte Ipad = unchecked(unchecked(0x36));
private const byte Ipad = unchecked(unchecked(0x36));
private const byte Opad = unchecked(unchecked(0x5c));
private const byte Opad = unchecked(unchecked(0x5c));
private MessageDigest _md5;
private MessageDigest _md5;
private byte[] _ipad = new byte[BlockLength];
private byte[] _ipad = new byte[BlockLength];
private byte[] _opad = new byte[BlockLength];
private byte[] _opad = new byte[BlockLength];
/// <summary>Creates an HMACT64 instance which uses the given secret key material.</summary>
/// <remarks>Creates an HMACT64 instance which uses the given secret key material.</remarks>
/// <param name="key">The key material to use in hashing.</param>
public Hmact64(byte[] key)
{
int length = Math.Min(key.Length, BlockLength);
for (int i = 0; i < length; i++)
{
_ipad[i] = unchecked((byte)(key[i] ^ Ipad));
_opad[i] = unchecked((byte)(key[i] ^ Opad));
}
for (int i1 = length; i1 < BlockLength; i1++)
{
_ipad[i1] = Ipad;
_opad[i1] = Opad;
}
try
{
_md5 = GetInstance("MD5");
}
catch (Exception ex)
{
throw new InvalidOperationException(ex.Message);
}
EngineReset();
}
/// <summary>Creates an HMACT64 instance which uses the given secret key material.</summary>
/// <remarks>Creates an HMACT64 instance which uses the given secret key material.</remarks>
/// <param name="key">The key material to use in hashing.</param>
public Hmact64(byte[] key)
{
int length = Math.Min(key.Length, BlockLength);
for (int i = 0; i < length; i++)
{
_ipad[i] = unchecked((byte)(key[i] ^ Ipad));
_opad[i] = unchecked((byte)(key[i] ^ Opad));
}
for (int i1 = length; i1 < BlockLength; i1++)
{
_ipad[i1] = Ipad;
_opad[i1] = Opad;
}
try
{
_md5 = GetInstance("MD5");
}
catch (Exception ex)
{
throw new InvalidOperationException(ex.Message);
}
EngineReset();
}
protected byte[] EngineDigest()
{
byte[] digest = _md5.Digest();
_md5.Update(_opad);
return _md5.Digest(digest);
}
protected byte[] EngineDigest()
{
byte[] digest = _md5.Digest();
_md5.Update(_opad);
return _md5.Digest(digest);
}
protected int EngineDigest(byte[] buf, int offset, int len)
{
byte[] digest = _md5.Digest();
_md5.Update(_opad);
_md5.Update(digest);
try
{
_md5.Digest(buf, offset, len);
protected int EngineDigest(byte[] buf, int offset, int len)
{
byte[] digest = _md5.Digest();
_md5.Update(_opad);
_md5.Update(digest);
try
{
_md5.Digest(buf, offset, len);
return len;
}
catch (Exception)
{
throw new InvalidOperationException();
}
}
return len;
}
catch (Exception)
{
throw new InvalidOperationException();
}
}
protected int EngineGetDigestLength()
{
return _md5.GetDigestLength();
}
protected int EngineGetDigestLength()
{
return _md5.GetDigestLength();
}
protected void EngineReset()
{
_md5.Reset();
_md5.Update(_ipad);
}
protected void EngineReset()
{
_md5.Reset();
_md5.Update(_ipad);
}
protected void EngineUpdate(byte b)
{
_md5.Update(b);
}
protected void EngineUpdate(byte b)
{
_md5.Update(b);
}
protected void EngineUpdate(byte[] input, int offset, int len)
{
_md5.Update(input, offset, len);
}
protected void EngineUpdate(byte[] input, int offset, int len)
{
_md5.Update(input, offset, len);
}
public override byte[] Digest()
{