// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005, 2007 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0
using System.Runtime.InteropServices;
using Mono.Security.Cryptography;
protected HMAC ()
{
_disposed = false;
+ _blockSizeValue = 64;
}
// properties
protected int BlockSizeValue {
get { return _blockSizeValue; }
- set { _blockSizeValue = value; }
+ set { _blockSizeValue = value; }
}
public string HashName {
set {
_hashName = value;
_algo = HashAlgorithm.Create (_hashName);
- _block = new BlockProcessor (_algo, 8);
}
}
public override byte[] Key {
get { return (byte[]) base.Key.Clone (); }
set {
- if ((value != null) && (value.Length > 64))
+ if ((value != null) && (value.Length > BlockSizeValue))
base.Key = _algo.ComputeHash (value);
else
base.Key = (byte[]) value.Clone();
}
}
+ internal BlockProcessor Block {
+ get {
+ if (_block == null)
+ _block = new BlockProcessor (_algo, (BlockSizeValue >> 3));
+ return _block;
+ }
+ }
+
// methods
private byte[] KeySetup (byte[] key, byte padding)
{
- byte[] buf = new byte [64];
+ byte[] buf = new byte [BlockSizeValue];
for (int i = 0; i < key.Length; ++i)
buf [i] = (byte) ((byte) key [i] ^ padding);
- for (int i = key.Length; i < 64; ++i)
+ for (int i = key.Length; i < BlockSizeValue; ++i)
buf [i] = padding;
return buf;
Initialize ();
State = 1;
}
- _block.Core (rgb, ib, cb);
+ Block.Core (rgb, ib, cb);
}
protected override byte[] HashFinal ()
throw new ObjectDisposedException ("HMAC");
State = 0;
- _block.Final ();
+ Block.Final ();
byte[] intermediate = _algo.Hash;
byte[] buf = KeySetup (Key, 0x5C);
throw new ObjectDisposedException ("HMAC");
State = 0;
- _block.Initialize ();
+ Block.Initialize ();
byte[] buf = KeySetup (Key, 0x36);
_algo.Initialize ();
- _block.Core (buf);
+ Block.Core (buf);
// zeroize key
Array.Clear (buf, 0, buf.Length);
}
public static new HMAC Create ()
{
+#if FULL_AOT_RUNTIME
+ return new System.Security.Cryptography.HMACSHA1 ();
+#else
return Create ("System.Security.Cryptography.HMAC");
+#endif
}
- public static new HMAC Create (string algName)
+ public static new HMAC Create (string algorithmName)
{
- return (HMAC) CryptoConfig.CreateFromName (algName);
+ return (HMAC) CryptoConfig.CreateFromName (algorithmName);
}
}
}
-#endif