Update for mobile profile
[mono.git] / mcs / class / System.Core / Test / System.Security.Cryptography / SHA256CryptoServiceProviderTest.cs
1 //
2 // SHA256CryptoServiceProviderTest.cs - NUnit Test Cases for SHA256CryptoServiceProvider
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-2008 Novell, Inc (http://www.novell.com)
9 //
10
11 #if !MOBILE
12
13 using NUnit.Framework;
14 using System;
15 using System.Security.Cryptography;
16 using System.Text;
17
18 namespace MonoTests.System.Security.Cryptography {
19
20         // References:
21         // a.   FIPS PUB 180-2: Secure Hash Standard
22         //      http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
23
24         // we inherit from SHA256Test because all SHA256 implementation must return the 
25         // same results (hence should run a common set of unit tests).
26
27         [TestFixture]
28         public class SHA256CryptoServiceProviderTest : SHA256Test {
29
30                 [SetUp]
31                 public override void SetUp ()
32                 {
33                         hash = new SHA256CryptoServiceProvider ();
34                 }
35
36                 [Test]
37                 public override void Create ()
38                 {
39                         // no need to repeat this test
40                 }
41
42                 // none of those values changes for a particuliar implementation of SHA256
43                 [Test]
44                 public override void StaticInfo ()
45                 {
46                         // test all values static for SHA256
47                         base.StaticInfo ();
48                         string className = hash.ToString ();
49                         Assert.IsTrue (hash.CanReuseTransform, className + ".CanReuseTransform");
50                         Assert.IsTrue (hash.CanTransformMultipleBlocks, className + ".CanTransformMultipleBlocks");
51                         Assert.AreEqual ("System.Security.Cryptography.SHA256CryptoServiceProvider", className, className + ".ToString()");
52                 }
53
54                 [Test]
55                 public void FIPSCompliance_Test1 ()
56                 {
57                         SHA256 sha = (SHA256) hash;
58                         // First test, we hash the string "abc"
59                         FIPS186_Test1 (sha);
60                 }
61
62                 [Test]
63                 public void FIPSCompliance_Test2 ()
64                 {
65                         SHA256 sha = (SHA256) hash;
66                         // Second test, we hash the string "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
67                         FIPS186_Test2 (sha);
68                 }
69
70                 [Test]
71                 public void FIPSCompliance_Test3 ()
72                 {
73                         SHA256 sha = (SHA256) hash;
74                         // Third test, we hash 1,000,000 times the character "a"
75                         FIPS186_Test3 (sha);
76                 }
77         }
78 }
79
80 #endif