mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-09-11 01:36:39 +00:00
Add support for hmac-sha2-256, hmac-sha2-256-96, hmac-md5-96 and hmac-sha1-96
This commit is contained in:
@@ -304,15 +304,15 @@ namespace Renci.SshNet
|
||||
{
|
||||
{"hmac-md5", (key) => { return new HMac<MD5Hash>(key.Take(16).ToArray());}},
|
||||
{"hmac-sha1", (key) => { return new HMac<SHA1Hash>(key.Take(20).ToArray());}},
|
||||
//{"hmac-sha2-256", typeof(...)},
|
||||
//{"hmac-sha2-256-96", typeof(...)},
|
||||
{"hmac-sha2-256", (key) => { return new HMac<SHA256Hash>(key.Take(32).ToArray());}},
|
||||
{"hmac-sha2-256-96", (key) => { return new HMac<SHA256Hash>(key.Take(32).ToArray(), 96);}},
|
||||
//{"hmac-sha2-512", typeof(...)},
|
||||
//{"hmac-sha2-512-96", typeof(...)},
|
||||
//{"umac-64@openssh.com", typeof(HMacSha1)},
|
||||
{"hmac-ripemd160", (key) => { return new HMac<RIPEMD160Hash>(key.Take(20).ToArray());}},
|
||||
{"hmac-ripemd160@openssh.com", (key) => { return new HMac<RIPEMD160Hash>(key.Take(20).ToArray());}},
|
||||
//{"hmac-md5-96", (key) => { return new HMac<MD5Hash>(key.Take(12).ToArray());}},
|
||||
//{"hmac-sha1-96", (key) => { return new HMac<SHA1Hash96>(key.Take(12).ToArray());}},
|
||||
{"hmac-ripemd160@openssh.com", (key) => { return new HMac<RIPEMD160Hash>(key.Take(20).ToArray());}},
|
||||
{"hmac-md5-96", (key) => { return new HMac<MD5Hash>(key.Take(16).ToArray(), 96);}},
|
||||
{"hmac-sha1-96", (key) => { return new HMac<SHA1Hash>(key.Take(20).ToArray(), 96);}},
|
||||
//{"none", typeof(...)},
|
||||
};
|
||||
|
||||
|
||||
@@ -32,15 +32,29 @@ namespace Renci.SshNet.Security.Cryptography
|
||||
}
|
||||
}
|
||||
|
||||
private HMac()
|
||||
{
|
||||
// Create the hash algorithms.
|
||||
this._hash = new T();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rfc 2104.
|
||||
/// </summary>
|
||||
/// <param name="key">The key.</param>
|
||||
public HMac(byte[] key)
|
||||
public HMac(byte[] key, int hashSizeValue)
|
||||
: this()
|
||||
{
|
||||
// Create the hash algorithms.
|
||||
this._hash = new T();
|
||||
this.HashSizeValue = hashSizeValue;
|
||||
|
||||
this._key = key;
|
||||
|
||||
this.InternalInitialize();
|
||||
}
|
||||
|
||||
public HMac(byte[] key)
|
||||
: this()
|
||||
{
|
||||
this.HashSizeValue = this._hash.HashSize;
|
||||
|
||||
this._key = key;
|
||||
@@ -48,6 +62,7 @@ namespace Renci.SshNet.Security.Cryptography
|
||||
this.InternalInitialize();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the key to use in the hash algorithm.
|
||||
/// </summary>
|
||||
@@ -115,7 +130,7 @@ namespace Renci.SshNet.Security.Cryptography
|
||||
|
||||
this._isHashing = false;
|
||||
|
||||
return this._hash.Hash;
|
||||
return this._hash.Hash.Take(12).ToArray();
|
||||
}
|
||||
|
||||
private void InternalInitialize()
|
||||
@@ -145,7 +160,7 @@ namespace Renci.SshNet.Security.Cryptography
|
||||
|
||||
// Compute inner and outer padding.
|
||||
int i = 0;
|
||||
for (i = 0; i < 64; i++)
|
||||
for (i = 0; i < this.BlockSize; i++)
|
||||
{
|
||||
this._innerPadding[i] = 0x36;
|
||||
this._outerPadding[i] = 0x5C;
|
||||
|
||||
Reference in New Issue
Block a user