Fix warnings in mscorlib's Test suite + bring a couple more tests + fix thread rename...
[mono.git] / mcs / class / corlib / Test / System.Security.Cryptography / HMACSHA512Test.cs
index dab2b8841b1a65b3ff1b87a528a3f919a87ba88b..55a7b87589c0a0ac859ef512bd4c46ea4a66fac6 100644 (file)
@@ -8,8 +8,6 @@
 // Copyright (C) 2006, 2007 Novell, Inc (http://www.novell.com)
 //
 
-#if NET_2_0
-
 using NUnit.Framework;
 using System;
 using System.IO;
@@ -28,6 +26,9 @@ namespace MonoTests.System.Security.Cryptography {
 
        public class SelectableHmacSha512: HMAC {
 
+               // Legacy parameter explanation:
+               // http://blogs.msdn.com/shawnfa/archive/2007/01/31/please-do-not-use-the-net-2-0-hmacsha512-and-hmacsha384-classes.aspx
+
                public SelectableHmacSha512 (byte[] key, bool legacy)
                {
                        HashName = "SHA512";
@@ -45,7 +46,6 @@ namespace MonoTests.System.Security.Cryptography {
        public class HMACSHA512Test : KeyedHashAlgorithmTest {
 
                protected HMACSHA512 algo;
-               private bool legacy;
 
                [SetUp]
                public override void SetUp () 
@@ -53,8 +53,6 @@ namespace MonoTests.System.Security.Cryptography {
                        algo = new HMACSHA512 ();
                        algo.Key = new byte [8];
                        hash = algo;
-                       // http://blogs.msdn.com/shawnfa/archive/2007/01/31/please-do-not-use-the-net-2-0-hmacsha512-and-hmacsha384-classes.aspx
-                       legacy = (new HS512 ().BlockSize == 64);
                }
 
                // the hash algorithm only exists as a managed implementation
@@ -389,7 +387,31 @@ namespace MonoTests.System.Security.Cryptography {
                        HMAC hmac = new SelectableHmacSha512 (key, true);
                        Check ("HMACSHA512-L-RFC4231-TC7", hmac, data, digest);
                }
-       }
-}
 
-#endif
+               [Test]
+               public void Bug6510a ()
+               {
+                       byte[] key = Encoding.UTF8.GetBytes ("CA61A777DC1041B2FDCC354820F7F83CE0530C0E019A29BF576F175D314A6D891B35F");
+                       byte[] data = Encoding.UTF8.GetBytes ("123456789");
+                       byte[] digest = { 147, 50, 79, 211, 70, 90, 205, 252, 100, 25, 50, 209, 254, 157,
+                               154, 12, 132, 205, 113, 59, 97, 216, 252, 94, 43, 126, 207, 140, 137, 60, 227,
+                               82, 82, 240, 9, 15, 166, 167, 110, 85, 217, 245, 250, 169, 189, 138, 55, 197,
+                               146, 192, 96, 20, 249, 95, 130, 163, 147, 82, 71, 244, 139, 76, 45, 75 };
+                       HMAC hmac = new SelectableHmacSha512 (key, false);
+                       Check ("HMACSHA512-BUG-6510", hmac, data, digest);
+               }
+
+               [Test]
+               public void Bug6510b ()
+               {
+                       byte[] key = Encoding.UTF8.GetBytes ("CA61A777DC1041B2FDCC354820F7F83CE0530C0E019A29BF576F175D314A6D891");
+                       byte[] data = Encoding.UTF8.GetBytes ("123456789");
+                       byte[] digest = { 254, 159, 56, 218, 66, 110, 74, 135, 209, 81, 166, 150, 241, 194,
+                               171, 228, 143, 228, 16, 198, 171, 53, 40, 211, 229, 160, 158, 2, 102, 99, 11,
+                               49, 70, 53, 70, 32, 32, 219, 119, 14, 2, 149, 197, 220, 166, 38, 128, 25, 255,
+                               227, 25, 20, 229, 54, 217, 57, 143, 224, 251, 1, 202, 24, 245, 133 };
+                       HMAC hmac = new SelectableHmacSha512 (key, false);
+                       Check ("HMACSHA512-BUG-6510", hmac, data, digest);
+               }
+       }
+}
\ No newline at end of file