3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 // <OWNER>Microsoft</OWNER>
13 namespace System.Security.Cryptography {
14 [System.Runtime.InteropServices.ComVisible(true)]
15 public class HMACSHA512 : HMAC {
17 private bool m_useLegacyBlockSize = Utils._ProduceLegacyHmacValues();
20 // public constructors
23 public HMACSHA512 () : this (Utils.GenerateRandom(128)) {}
25 [System.Security.SecuritySafeCritical] // auto-generated
26 public HMACSHA512 (byte[] key) {
27 m_hashName = "SHA512";
29 m_hash1 = new SHA512Managed();
30 m_hash2 = new SHA512Managed();
32 m_hash1 = GetHashAlgorithmWithFipsFallback(() => new SHA512Managed(), () => HashAlgorithm.Create("System.Security.Cryptography.SHA512CryptoServiceProvider"));
33 m_hash2 = GetHashAlgorithmWithFipsFallback(() => new SHA512Managed(), () => HashAlgorithm.Create("System.Security.Cryptography.SHA512CryptoServiceProvider"));
36 BlockSizeValue = BlockSize;
37 base.InitializeKey(key);
40 private int BlockSize {
41 get { return m_useLegacyBlockSize ? 64 : 128; }
45 /// In Whidbey we incorrectly used a block size of 64 bytes for HMAC-SHA-384 and HMAC-SHA-512,
46 /// rather than using the correct value of 128 bytes. Setting this to true causes us to fall
47 /// back to the Whidbey mode which produces incorrect HMAC values.
49 /// This value should be set only once, before hashing has begun, since we need to reset the key
50 /// buffer for the block size change to take effect.
52 /// The default vaue is off, however this can be toggled for the application by setting the
53 /// legacyHMACMode config switch.
55 public bool ProduceLegacyHmacValues {
56 get { return m_useLegacyBlockSize; }
59 m_useLegacyBlockSize = value;
61 BlockSizeValue = BlockSize;
62 InitializeKey(KeyValue);