Grasshopper now uses csproj instead of vmwcsproj
[mono.git] / mcs / class / corlib / Test / System.Security.Cryptography / SHA1CryptoServiceProviderTest.cs
1 //
2 // SHA1CryptoServiceProviderTest.cs - NUnit Test Cases for SHA1CryptoServiceProvider
3 //
4 // Author:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // (C) 2002 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004, 2007 Novell, Inc (http://www.novell.com)
9 //
10
11 using NUnit.Framework;
12 using System;
13 using System.Security.Cryptography;
14 using System.Text;
15
16 namespace MonoTests.System.Security.Cryptography {
17
18 // References:
19 // a.   FIPS PUB 180-1: Secure Hash Standard
20 //      http://csrc.nist.gov/publications/fips/fips180-1/fip180-1.txt
21
22 // we inherit from SHA1Test because all SHA1 implementation must return the 
23 // same results (hence should run a common set of unit tests).
24
25 [TestFixture]
26 public class SHA1CryptoServiceProviderTest : SHA1Test {
27
28         [SetUp]
29         protected override void SetUp () 
30         {
31                 hash = new SHA1CryptoServiceProvider ();
32         }
33
34         [Test]
35         public override void Create () 
36         {
37                 // no need to repeat this test
38         }
39
40         // none of those values changes for a particuliar implementation of SHA1
41         [Test]
42         public override void StaticInfo ()
43         {
44                 // test all values static for SHA1
45                 base.StaticInfo();
46                 string className = hash.ToString ();
47                 Assert.IsTrue (hash.CanReuseTransform, className + ".CanReuseTransform");
48                 Assert.IsTrue (hash.CanTransformMultipleBlocks, className + ".CanTransformMultipleBlocks");
49                 Assert.AreEqual ("System.Security.Cryptography.SHA1CryptoServiceProvider", className, className + ".ToString()");
50         }
51
52         public void TestSHA1CSPforFIPSCompliance () 
53         {
54                 SHA1 sha = (SHA1)hash;
55                 // First test, we hash the string "abc"
56                 FIPS186_Test1 (sha);
57                 // Second test, we hash the string "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
58                 FIPS186_Test2 (sha);
59                 // Third test, we hash 1,000,000 times the character "a"
60                 FIPS186_Test3 (sha);
61         }
62
63         // LAMESPEC / MSBUG: Under Windows an Initialize is required after 
64         // TransformFinalBlock/Hash or SHA1CryptoServiceProvider will still return 
65         // the previous Hash. SHA1Managed behavior's is different as it will return
66         // a bad Hash if Initialize isn't called.
67         // FIXME: Do we want to duplicate this bad behaviour ?
68 /*      public void TestInitialize () 
69         {
70                 byte[] expectedDEF = { 0x58, 0x9c, 0x22, 0x33, 0x5a, 0x38, 0x1f, 0x12, 0x2d, 0x12, 0x92, 0x25, 0xf5, 0xc0, 0xba, 0x30, 0x56, 0xed, 0x58, 0x11 };
71                 string className = hash.ToString ();
72                 // hash abc
73                 byte[] inputABC = Encoding.Default.GetBytes ("abc");
74                 hash.TransformFinalBlock (inputABC, 0, inputABC.Length);
75                 byte[] resultABC = hash.Hash;
76                 // hash def
77                 byte[] inputDEF = Encoding.Default.GetBytes ("def");
78                 byte[] resultDEF = hash.ComputeHash (inputDEF); 
79                 // result(abc) == result(def) -> forgot to initialize
80                 AssertEquals (className + ".Initialize ABC=DEF", resultABC, resultDEF);
81                 hash.Initialize ();
82                 resultDEF = hash.ComputeHash (inputDEF);
83                 AssertEquals (className + ".Initialize DEF ok", expectedDEF, resultDEF);
84         }*/
85 }
86
87 }