(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / corlib / Test / System.Security.Cryptography / TripleDESTest.cs
blobc4b81a7d91e6a3dd1fb2176a39f337280eeb1ef7
1 //
2 // TripleDESTest.cs - NUnit Test Cases for TripleDES
3 //
4 // Author:
5 // Sebastien Pouliot (sebastien@ximian.com)
6 //
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using NUnit.Framework;
30 using System;
31 using System.Security.Cryptography;
33 namespace MonoTests.System.Security.Cryptography {
35 [TestFixture]
36 public class TripleDESTest {
38 [Test]
39 public void DefaultProperties ()
41 TripleDES algo = TripleDES.Create ();
42 Assert.AreEqual (64, algo.BlockSize, "BlockSize");
43 Assert.AreEqual (8, algo.FeedbackSize, "FeedbackSize");
44 Assert.AreEqual (192, algo.KeySize, "KeySize");
45 Assert.AreEqual (CipherMode.CBC, algo.Mode, "Mode");
46 Assert.AreEqual (PaddingMode.PKCS7, algo.Padding, "Padding");
47 Assert.AreEqual (1, algo.LegalBlockSizes.Length, "LegalBlockSizes");
48 Assert.AreEqual (64, algo.LegalBlockSizes [0].MaxSize, "LegalBlockSizes.MaxSize");
49 Assert.AreEqual (64, algo.LegalBlockSizes [0].MinSize, "LegalBlockSizes.MinSize");
50 Assert.AreEqual (0, algo.LegalBlockSizes [0].SkipSize, "LegalBlockSizes.SkipSize");
51 Assert.AreEqual (1, algo.LegalKeySizes.Length, "LegalKeySizes");
52 Assert.AreEqual (192, algo.LegalKeySizes [0].MaxSize, "LegalKeySizes.MaxSize");
53 Assert.AreEqual (128, algo.LegalKeySizes [0].MinSize, "LegalKeySizes.MinSize");
54 Assert.AreEqual (64, algo.LegalKeySizes [0].SkipSize, "LegalKeySizes.SkipSize");
57 [Test]
58 public void Key ()
60 TripleDES algo = TripleDES.Create ();
61 algo.GenerateKey ();
62 algo.GenerateIV ();
63 Assert.AreEqual (192, algo.KeySize, "Key Size");
64 Assert.AreEqual (24, algo.Key.Length, "Key Length");
65 Assert.AreEqual (8, algo.IV.Length, "IV Length");
68 [Test]
69 [ExpectedException (typeof (ArgumentNullException))]
70 public void KeyNull ()
72 TripleDES algo = TripleDES.Create ();
73 algo.Key = null;
76 [Test]
77 [ExpectedException (typeof (CryptographicException))]
78 public void KeyWeak128bits ()
80 byte[] wk128 = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
81 TripleDES algo = TripleDES.Create ();
82 algo.Key = wk128;
85 [Test]
86 [ExpectedException (typeof (CryptographicException))]
87 public void KeyWeak192bits_AB ()
89 byte[] wk192 = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD };
90 TripleDES algo = TripleDES.Create ();
91 algo.Key = wk192;
94 [Test]
95 [ExpectedException (typeof (CryptographicException))]
96 public void KeyWeak192bits_BC ()
98 byte[] wk192 = { 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
99 TripleDES algo = TripleDES.Create ();
100 algo.Key = wk192;
103 [Test]
104 [ExpectedException (typeof (CryptographicException))]
105 public void KeyWrongLength ()
107 byte[] wk64 = { 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD };
108 TripleDES algo = TripleDES.Create ();
109 algo.Key = wk64;