2 // TripleDESTest.cs - NUnit Test Cases for TripleDES
5 // Sebastien Pouliot (sebastien@ximian.com)
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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
;
31 using System
.Security
.Cryptography
;
33 namespace MonoTests
.System
.Security
.Cryptography
{
36 public class TripleDESTest
{
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");
60 TripleDES algo
= TripleDES
.Create ();
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");
69 [ExpectedException (typeof (ArgumentNullException
))]
70 public void KeyNull ()
72 TripleDES algo
= TripleDES
.Create ();
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 ();
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 ();
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 ();
104 [ExpectedException (typeof (CryptographicException
))]
105 public void KeyWrongLength ()
107 byte[] wk64
= { 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD }
;
108 TripleDES algo
= TripleDES
.Create ();