Merge pull request #733 from amoiseev-softheme/bugfix/monofix
[mono.git] / mcs / class / corlib / Test / System.Security.Cryptography / SymmetricAlgorithmTest.cs
1 // !!! DO NOT EDIT - This file is generated automatically - DO NOT EDIT !!!
2 // Note: Key and IV will be different each time the file is generated
3
4 //
5 // SymmetricAlgorithmTest.cs - NUnit Test Cases for SymmetricAlgorithmTest
6 //
7 // Author:
8 //      Sebastien Pouliot (spouliot@motus.com)
9 //
10 // (C) 2002 Motus Technologies Inc. (http://www.motus.com)
11 //
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 [TestFixture]
21 public class SymmetricAlgorithmTest {
22 public void AssertEquals (string msg, byte[] array1, byte[] array2)
23 {
24         AllTests.AssertEquals (msg, array1, array2);
25 }
26
27 //--8<-- NON GENERATED CODE STARTS HERE --8<----8<----8<----8<----8<----8<--
28
29 //-->8-- NON GENERATED CODE ENDS HERE   -->8---->8---->8---->8---->8---->8--
30
31 private void Encrypt (ICryptoTransform trans, byte[] input, byte[] output)
32 {
33         int bs = trans.InputBlockSize;
34         int full = input.Length / bs;
35         int partial = input.Length % bs;
36         int pos = 0;
37         for (int i=0; i < full; i++) {
38                 trans.TransformBlock (input, pos, bs, output, pos);
39                 pos += bs;
40         }
41         if (partial > 0) {
42                 byte[] final = trans.TransformFinalBlock (input, pos, partial);
43                 Array.Copy (final, 0, output, pos, bs);
44         }
45 }
46
47 private void Decrypt (ICryptoTransform trans, byte[] input, byte[] output)
48 {
49         int bs = trans.InputBlockSize;
50         int full = input.Length / bs;
51         int partial = input.Length % bs;
52         int pos = 0;
53         for (int i=0; i < full; i++) {
54                 trans.TransformBlock (input, pos, bs, output, pos);
55                 pos += bs;
56         }
57         if (partial > 0) {
58                 byte[] final = trans.TransformFinalBlock (input, pos, partial);
59                 Array.Copy (final, 0, output, pos, partial);
60         }
61 }
62
63 [Test]
64 public void TestDES_k64b64_ECB_None ()
65 {
66         byte[] key = { 0x12, 0xE7, 0x7B, 0xBF, 0x11, 0x90, 0x9D, 0xB0 };
67         // not used for ECB but make the code more uniform
68         byte[] iv = { 0xD2, 0x0E, 0xA7, 0xA4, 0x00, 0xF3, 0x17, 0x69 };
69         byte[] expected = { 0x4B, 0x63, 0x6D, 0x2C, 0xA7, 0x0B, 0x77, 0x1C, 0x4B, 0x63, 0x6D, 0x2C, 0xA7, 0x0B, 0x77, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
70
71         SymmetricAlgorithm algo = DES.Create ();
72         algo.Mode = CipherMode.ECB;
73         algo.Padding = PaddingMode.None;
74         algo.BlockSize = 64;
75         int blockLength = (algo.BlockSize >> 3);
76         byte[] input = new byte [blockLength * 2];
77         byte[] output = new byte [blockLength * 3];
78         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
79         Encrypt (encryptor, input, output);
80         AssertEquals ("DES_k64b64_ECB_None Encrypt", expected, output);
81
82         // in ECB the first 2 blocks should be equals (as the IV is not used)
83         byte[] block1 = new byte[blockLength];
84         Array.Copy (output, 0, block1, 0, blockLength);
85         byte[] block2 = new byte[blockLength];
86         Array.Copy (output, blockLength, block2, 0, blockLength);
87         AssertEquals ("DES_k64b64_ECB_None b1==b2", block1, block2);
88         byte[] reverse = new byte [blockLength * 3];
89         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
90         Decrypt (decryptor, output, reverse);
91         byte[] original = new byte [input.Length];
92         Array.Copy (reverse, 0, original, 0, original.Length);
93         AssertEquals ("DES_k64b64_ECB_None Decrypt", input, original);
94 }
95
96
97 [Test]
98 public void TestDES_k64b64_ECB_Zeros ()
99 {
100         byte[] key = { 0x2E, 0xCA, 0x2E, 0xC9, 0x1A, 0xB6, 0x9A, 0x5A };
101         // not used for ECB but make the code more uniform
102         byte[] iv = { 0x79, 0x75, 0xD0, 0x3F, 0xFD, 0x1B, 0x12, 0x13 };
103         byte[] expected = { 0x9B, 0x58, 0x07, 0x30, 0xE5, 0xDA, 0x3E, 0x7F, 0x9B, 0x58, 0x07, 0x30, 0xE5, 0xDA, 0x3E, 0x7F, 0x9B, 0x58, 0x07, 0x30, 0xE5, 0xDA, 0x3E, 0x7F };
104
105         SymmetricAlgorithm algo = DES.Create ();
106         algo.Mode = CipherMode.ECB;
107         algo.Padding = PaddingMode.Zeros;
108         algo.BlockSize = 64;
109         int blockLength = (algo.BlockSize >> 3);
110         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
111         byte[] output = new byte [blockLength * 3];
112         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
113         Encrypt (encryptor, input, output);
114         AssertEquals ("DES_k64b64_ECB_Zeros Encrypt", expected, output);
115
116         // in ECB the first 2 blocks should be equals (as the IV is not used)
117         byte[] block1 = new byte[blockLength];
118         Array.Copy (output, 0, block1, 0, blockLength);
119         byte[] block2 = new byte[blockLength];
120         Array.Copy (output, blockLength, block2, 0, blockLength);
121         AssertEquals ("DES_k64b64_ECB_Zeros b1==b2", block1, block2);
122
123         // also if padding is Zeros then all three blocks should be equals
124         byte[] block3 = new byte[blockLength];
125         Array.Copy (output, blockLength, block3, 0, blockLength);
126         AssertEquals ("DES_k64b64_ECB_Zeros b1==b3", block1, block3);
127
128         byte[] reverse = new byte [blockLength * 3];
129         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
130         Decrypt (decryptor, output, reverse);
131         byte[] original = new byte [input.Length];
132         Array.Copy (reverse, 0, original, 0, original.Length);
133         AssertEquals ("DES_k64b64_ECB_Zeros Decrypt", input, original);
134 }
135
136
137 [Test]
138 public void TestDES_k64b64_ECB_PKCS7 ()
139 {
140         byte[] key = { 0x32, 0xE8, 0x8D, 0xF7, 0xDC, 0xFC, 0x6C, 0xCD };
141         // not used for ECB but make the code more uniform
142         byte[] iv = { 0x74, 0xB2, 0x5E, 0x33, 0xBD, 0xA3, 0xC1, 0xB8 };
143         byte[] expected = { 0x0E, 0xB6, 0xA5, 0x6F, 0x4A, 0xAE, 0xED, 0x95, 0x0E, 0xB6, 0xA5, 0x6F, 0x4A, 0xAE, 0xED, 0x95, 0x45, 0xEC, 0x24, 0x40, 0xF4, 0xB3, 0x97, 0xF3 };
144
145         SymmetricAlgorithm algo = DES.Create ();
146         algo.Mode = CipherMode.ECB;
147         algo.Padding = PaddingMode.PKCS7;
148         algo.BlockSize = 64;
149         int blockLength = (algo.BlockSize >> 3);
150         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
151         byte[] output = new byte [blockLength * 3];
152         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
153         Encrypt (encryptor, input, output);
154         AssertEquals ("DES_k64b64_ECB_PKCS7 Encrypt", expected, output);
155
156         // in ECB the first 2 blocks should be equals (as the IV is not used)
157         byte[] block1 = new byte[blockLength];
158         Array.Copy (output, 0, block1, 0, blockLength);
159         byte[] block2 = new byte[blockLength];
160         Array.Copy (output, blockLength, block2, 0, blockLength);
161         AssertEquals ("DES_k64b64_ECB_PKCS7 b1==b2", block1, block2);
162         byte[] reverse = new byte [blockLength * 3];
163         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
164         Decrypt (decryptor, output, reverse);
165         byte[] original = new byte [input.Length];
166         Array.Copy (reverse, 0, original, 0, original.Length);
167         AssertEquals ("DES_k64b64_ECB_PKCS7 Decrypt", input, original);
168 }
169
170
171 [Test]
172 public void TestDES_k64b64_CBC_None ()
173 {
174         byte[] key = { 0x91, 0xB4, 0x33, 0xB9, 0xA3, 0x7C, 0x47, 0x76 };
175         byte[] iv = { 0x96, 0x98, 0xCC, 0x84, 0xDD, 0xC3, 0xA1, 0x14 };
176         byte[] expected = { 0x71, 0x8A, 0xD7, 0xC1, 0x3F, 0xBC, 0x0C, 0xB7, 0xB7, 0x91, 0x96, 0x6A, 0xA9, 0xA6, 0xFC, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
177
178         SymmetricAlgorithm algo = DES.Create ();
179         algo.Mode = CipherMode.CBC;
180         algo.Padding = PaddingMode.None;
181         algo.BlockSize = 64;
182         int blockLength = (algo.BlockSize >> 3);
183         byte[] input = new byte [blockLength * 2];
184         byte[] output = new byte [blockLength * 3];
185         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
186         Encrypt (encryptor, input, output);
187         AssertEquals ("DES_k64b64_CBC_None Encrypt", expected, output);
188         byte[] reverse = new byte [blockLength * 3];
189         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
190         Decrypt (decryptor, output, reverse);
191         byte[] original = new byte [input.Length];
192         Array.Copy (reverse, 0, original, 0, original.Length);
193         AssertEquals ("DES_k64b64_CBC_None Decrypt", input, original);
194 }
195
196
197 [Test]
198 public void TestDES_k64b64_CBC_Zeros ()
199 {
200         byte[] key = { 0x4A, 0x8B, 0xC7, 0xC5, 0x9C, 0x10, 0xB4, 0x6C };
201         byte[] iv = { 0x4B, 0x53, 0x53, 0xEA, 0xAF, 0xCC, 0x5A, 0x2B };
202         byte[] expected = { 0xCA, 0xBC, 0xB7, 0xB9, 0xCF, 0x72, 0x63, 0x1F, 0x83, 0x96, 0xA4, 0xB7, 0x95, 0xF7, 0xFE, 0x13, 0x90, 0x6A, 0x4B, 0x74, 0x9E, 0xE0, 0xF9, 0x30 };
203
204         SymmetricAlgorithm algo = DES.Create ();
205         algo.Mode = CipherMode.CBC;
206         algo.Padding = PaddingMode.Zeros;
207         algo.BlockSize = 64;
208         int blockLength = (algo.BlockSize >> 3);
209         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
210         byte[] output = new byte [blockLength * 3];
211         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
212         Encrypt (encryptor, input, output);
213         AssertEquals ("DES_k64b64_CBC_Zeros Encrypt", expected, output);
214         byte[] reverse = new byte [blockLength * 3];
215         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
216         Decrypt (decryptor, output, reverse);
217         byte[] original = new byte [input.Length];
218         Array.Copy (reverse, 0, original, 0, original.Length);
219         AssertEquals ("DES_k64b64_CBC_Zeros Decrypt", input, original);
220 }
221
222
223 [Test]
224 public void TestDES_k64b64_CBC_PKCS7 ()
225 {
226         byte[] key = { 0xEA, 0x7D, 0x6D, 0x2C, 0xB8, 0x93, 0x33, 0xF4 };
227         byte[] iv = { 0x77, 0xE4, 0xAA, 0x7C, 0xFE, 0xA9, 0x0F, 0x94 };
228         byte[] expected = { 0x83, 0xB0, 0x83, 0xCA, 0xAC, 0x64, 0xE3, 0xDF, 0x1F, 0x5B, 0xE2, 0x9C, 0x16, 0x3E, 0x68, 0x91, 0x9E, 0xE5, 0xB5, 0x67, 0x80, 0xD2, 0x52, 0xC6 };
229
230         SymmetricAlgorithm algo = DES.Create ();
231         algo.Mode = CipherMode.CBC;
232         algo.Padding = PaddingMode.PKCS7;
233         algo.BlockSize = 64;
234         int blockLength = (algo.BlockSize >> 3);
235         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
236         byte[] output = new byte [blockLength * 3];
237         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
238         Encrypt (encryptor, input, output);
239         AssertEquals ("DES_k64b64_CBC_PKCS7 Encrypt", expected, output);
240         byte[] reverse = new byte [blockLength * 3];
241         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
242         Decrypt (decryptor, output, reverse);
243         byte[] original = new byte [input.Length];
244         Array.Copy (reverse, 0, original, 0, original.Length);
245         AssertEquals ("DES_k64b64_CBC_PKCS7 Decrypt", input, original);
246 }
247
248
249 /* Invalid parameters DES_k64b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
250
251 /* Invalid parameters DES_k64b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
252
253 /* Invalid parameters DES_k64b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
254
255 [Test]
256 public void TestDES_k64b64_CFB8_None ()
257 {
258         byte[] key = { 0x52, 0x5E, 0x49, 0x90, 0x10, 0x20, 0x6D, 0x5C };
259         byte[] iv = { 0x00, 0x45, 0x9B, 0x7F, 0xC2, 0x9D, 0x90, 0x37 };
260         byte[] expected = { 0x9C, 0x9F, 0xE0, 0x9F, 0x2E, 0x0C, 0xE0, 0xBA, 0xD3, 0x2F, 0xF4, 0x54, 0x89, 0x83, 0x82, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
261
262         SymmetricAlgorithm algo = DES.Create ();
263         algo.Mode = CipherMode.CFB;
264         algo.Padding = PaddingMode.None;
265         algo.BlockSize = 64;
266         algo.FeedbackSize = 8;
267         int blockLength = (algo.BlockSize >> 3);
268         byte[] input = new byte [blockLength * 2];
269         byte[] output = new byte [blockLength * 3];
270         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
271         Encrypt (encryptor, input, output);
272         AssertEquals ("DES_k64b64_CFB8_None Encrypt", expected, output);
273         byte[] reverse = new byte [blockLength * 3];
274         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
275         Decrypt (decryptor, output, reverse);
276         byte[] original = new byte [input.Length];
277         Array.Copy (reverse, 0, original, 0, original.Length);
278         AssertEquals ("DES_k64b64_CFB8_None Decrypt", input, original);
279 }
280
281
282 [Test]
283 public void TestDES_k64b64_CFB8_Zeros ()
284 {
285         byte[] key = { 0xAF, 0x35, 0x0A, 0x91, 0x8F, 0x45, 0x46, 0xAF };
286         byte[] iv = { 0x3A, 0xF5, 0xCD, 0x22, 0xDC, 0xEF, 0xF4, 0x61 };
287         byte[] expected = { 0xFB, 0x7E, 0xA8, 0xEC, 0xC0, 0x65, 0x30, 0xE3, 0x84, 0xBC, 0x49, 0xB9, 0x1C, 0xFD, 0xF6, 0x81, 0xCE, 0x2A, 0x69, 0x70, 0x73, 0xF0, 0x9A, 0xA8 };
288
289         SymmetricAlgorithm algo = DES.Create ();
290         algo.Mode = CipherMode.CFB;
291         algo.Padding = PaddingMode.Zeros;
292         algo.BlockSize = 64;
293         algo.FeedbackSize = 8;
294         int blockLength = (algo.BlockSize >> 3);
295         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
296         byte[] output = new byte [blockLength * 3];
297         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
298         Encrypt (encryptor, input, output);
299         AssertEquals ("DES_k64b64_CFB8_Zeros Encrypt", expected, output);
300         byte[] reverse = new byte [blockLength * 3];
301         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
302         Decrypt (decryptor, output, reverse);
303         byte[] original = new byte [input.Length];
304         Array.Copy (reverse, 0, original, 0, original.Length);
305         AssertEquals ("DES_k64b64_CFB8_Zeros Decrypt", input, original);
306 }
307
308
309 [Test]
310 public void TestDES_k64b64_CFB8_PKCS7 ()
311 {
312         byte[] key = { 0x5D, 0xAD, 0x6F, 0xFF, 0x48, 0x89, 0x18, 0xE6 };
313         byte[] iv = { 0x98, 0x46, 0xD3, 0xFC, 0x1A, 0x59, 0xF6, 0x20 };
314         byte[] expected = { 0xC3, 0xAC, 0xCF, 0x49, 0xFF, 0x46, 0x82, 0x21, 0xE8, 0x1F, 0x31, 0x4E, 0x1C, 0x33, 0xEA, 0x49, 0x54, 0x67, 0x3E, 0x9C, 0xFD, 0x77, 0x39, 0x69 };
315
316         SymmetricAlgorithm algo = DES.Create ();
317         algo.Mode = CipherMode.CFB;
318         algo.Padding = PaddingMode.PKCS7;
319         algo.BlockSize = 64;
320         algo.FeedbackSize = 8;
321         int blockLength = (algo.BlockSize >> 3);
322         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
323         byte[] output = new byte [blockLength * 3];
324         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
325         Encrypt (encryptor, input, output);
326         AssertEquals ("DES_k64b64_CFB8_PKCS7 Encrypt", expected, output);
327         byte[] reverse = new byte [blockLength * 3];
328         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
329         Decrypt (decryptor, output, reverse);
330         byte[] original = new byte [input.Length];
331         Array.Copy (reverse, 0, original, 0, original.Length);
332         AssertEquals ("DES_k64b64_CFB8_PKCS7 Decrypt", input, original);
333 }
334
335
336 /* Invalid parameters DES_k64b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
337
338 /* Invalid parameters DES_k64b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
339
340 /* Invalid parameters DES_k64b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
341
342 [Test]
343 public void TestRC2_k40b64_ECB_None ()
344 {
345         byte[] key = { 0xC3, 0x69, 0xCB, 0x65, 0x22 };
346         // not used for ECB but make the code more uniform
347         byte[] iv = { 0x5E, 0x8E, 0xDB, 0xFD, 0x10, 0x1F, 0x14, 0x90 };
348         byte[] expected = { 0xCC, 0x71, 0xF5, 0xC1, 0x2F, 0xAF, 0xB8, 0xF4, 0xCC, 0x71, 0xF5, 0xC1, 0x2F, 0xAF, 0xB8, 0xF4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
349
350         SymmetricAlgorithm algo = RC2.Create ();
351         algo.Mode = CipherMode.ECB;
352         algo.Padding = PaddingMode.None;
353         algo.BlockSize = 64;
354         int blockLength = (algo.BlockSize >> 3);
355         byte[] input = new byte [blockLength * 2];
356         byte[] output = new byte [blockLength * 3];
357         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
358         Encrypt (encryptor, input, output);
359         AssertEquals ("RC2_k40b64_ECB_None Encrypt", expected, output);
360
361         // in ECB the first 2 blocks should be equals (as the IV is not used)
362         byte[] block1 = new byte[blockLength];
363         Array.Copy (output, 0, block1, 0, blockLength);
364         byte[] block2 = new byte[blockLength];
365         Array.Copy (output, blockLength, block2, 0, blockLength);
366         AssertEquals ("RC2_k40b64_ECB_None b1==b2", block1, block2);
367         byte[] reverse = new byte [blockLength * 3];
368         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
369         Decrypt (decryptor, output, reverse);
370         byte[] original = new byte [input.Length];
371         Array.Copy (reverse, 0, original, 0, original.Length);
372         AssertEquals ("RC2_k40b64_ECB_None Decrypt", input, original);
373 }
374
375
376 [Test]
377 public void TestRC2_k40b64_ECB_Zeros ()
378 {
379         byte[] key = { 0x12, 0x66, 0x49, 0x15, 0xBC };
380         // not used for ECB but make the code more uniform
381         byte[] iv = { 0x3C, 0x1C, 0x38, 0x12, 0x1C, 0x78, 0x0C, 0x19 };
382         byte[] expected = { 0xDF, 0xD0, 0xD8, 0x24, 0xD8, 0x22, 0x51, 0x7C, 0xDF, 0xD0, 0xD8, 0x24, 0xD8, 0x22, 0x51, 0x7C, 0xDF, 0xD0, 0xD8, 0x24, 0xD8, 0x22, 0x51, 0x7C };
383
384         SymmetricAlgorithm algo = RC2.Create ();
385         algo.Mode = CipherMode.ECB;
386         algo.Padding = PaddingMode.Zeros;
387         algo.BlockSize = 64;
388         int blockLength = (algo.BlockSize >> 3);
389         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
390         byte[] output = new byte [blockLength * 3];
391         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
392         Encrypt (encryptor, input, output);
393         AssertEquals ("RC2_k40b64_ECB_Zeros Encrypt", expected, output);
394
395         // in ECB the first 2 blocks should be equals (as the IV is not used)
396         byte[] block1 = new byte[blockLength];
397         Array.Copy (output, 0, block1, 0, blockLength);
398         byte[] block2 = new byte[blockLength];
399         Array.Copy (output, blockLength, block2, 0, blockLength);
400         AssertEquals ("RC2_k40b64_ECB_Zeros b1==b2", block1, block2);
401
402         // also if padding is Zeros then all three blocks should be equals
403         byte[] block3 = new byte[blockLength];
404         Array.Copy (output, blockLength, block3, 0, blockLength);
405         AssertEquals ("RC2_k40b64_ECB_Zeros b1==b3", block1, block3);
406
407         byte[] reverse = new byte [blockLength * 3];
408         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
409         Decrypt (decryptor, output, reverse);
410         byte[] original = new byte [input.Length];
411         Array.Copy (reverse, 0, original, 0, original.Length);
412         AssertEquals ("RC2_k40b64_ECB_Zeros Decrypt", input, original);
413 }
414
415
416 [Test]
417 public void TestRC2_k40b64_ECB_PKCS7 ()
418 {
419         byte[] key = { 0xC2, 0x76, 0x2F, 0xCE, 0xED };
420         // not used for ECB but make the code more uniform
421         byte[] iv = { 0xB1, 0x88, 0x93, 0x03, 0xDA, 0x23, 0xE6, 0x87 };
422         byte[] expected = { 0xE2, 0x9B, 0x89, 0x15, 0xEC, 0x57, 0x0B, 0x05, 0xE2, 0x9B, 0x89, 0x15, 0xEC, 0x57, 0x0B, 0x05, 0x44, 0x77, 0xF0, 0x47, 0x2A, 0x12, 0xEA, 0xA1 };
423
424         SymmetricAlgorithm algo = RC2.Create ();
425         algo.Mode = CipherMode.ECB;
426         algo.Padding = PaddingMode.PKCS7;
427         algo.BlockSize = 64;
428         int blockLength = (algo.BlockSize >> 3);
429         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
430         byte[] output = new byte [blockLength * 3];
431         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
432         Encrypt (encryptor, input, output);
433         AssertEquals ("RC2_k40b64_ECB_PKCS7 Encrypt", expected, output);
434
435         // in ECB the first 2 blocks should be equals (as the IV is not used)
436         byte[] block1 = new byte[blockLength];
437         Array.Copy (output, 0, block1, 0, blockLength);
438         byte[] block2 = new byte[blockLength];
439         Array.Copy (output, blockLength, block2, 0, blockLength);
440         AssertEquals ("RC2_k40b64_ECB_PKCS7 b1==b2", block1, block2);
441         byte[] reverse = new byte [blockLength * 3];
442         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
443         Decrypt (decryptor, output, reverse);
444         byte[] original = new byte [input.Length];
445         Array.Copy (reverse, 0, original, 0, original.Length);
446         AssertEquals ("RC2_k40b64_ECB_PKCS7 Decrypt", input, original);
447 }
448
449
450 [Test]
451 public void TestRC2_k40b64_CBC_None ()
452 {
453         byte[] key = { 0xD0, 0xE1, 0x4E, 0x9C, 0x58 };
454         byte[] iv = { 0x8E, 0x5E, 0x76, 0x18, 0xB8, 0x76, 0xCF, 0x77 };
455         byte[] expected = { 0x36, 0x1B, 0x18, 0x98, 0xEE, 0xC6, 0x18, 0xB8, 0x67, 0xC0, 0x92, 0x09, 0x22, 0xDC, 0x65, 0xC5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
456
457         SymmetricAlgorithm algo = RC2.Create ();
458         algo.Mode = CipherMode.CBC;
459         algo.Padding = PaddingMode.None;
460         algo.BlockSize = 64;
461         int blockLength = (algo.BlockSize >> 3);
462         byte[] input = new byte [blockLength * 2];
463         byte[] output = new byte [blockLength * 3];
464         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
465         Encrypt (encryptor, input, output);
466         AssertEquals ("RC2_k40b64_CBC_None Encrypt", expected, output);
467         byte[] reverse = new byte [blockLength * 3];
468         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
469         Decrypt (decryptor, output, reverse);
470         byte[] original = new byte [input.Length];
471         Array.Copy (reverse, 0, original, 0, original.Length);
472         AssertEquals ("RC2_k40b64_CBC_None Decrypt", input, original);
473 }
474
475
476 [Test]
477 public void TestRC2_k40b64_CBC_Zeros ()
478 {
479         byte[] key = { 0xB5, 0x6F, 0xC7, 0x4F, 0xF8 };
480         byte[] iv = { 0xB6, 0x95, 0xE9, 0x3E, 0x04, 0x98, 0x39, 0x3D };
481         byte[] expected = { 0x32, 0x10, 0x36, 0x24, 0x9F, 0xB6, 0x87, 0x4E, 0x00, 0xB6, 0xEF, 0x33, 0x52, 0x8B, 0xDE, 0x8A, 0x90, 0xE2, 0x0C, 0x60, 0xD3, 0x1A, 0x72, 0xCC };
482
483         SymmetricAlgorithm algo = RC2.Create ();
484         algo.Mode = CipherMode.CBC;
485         algo.Padding = PaddingMode.Zeros;
486         algo.BlockSize = 64;
487         int blockLength = (algo.BlockSize >> 3);
488         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
489         byte[] output = new byte [blockLength * 3];
490         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
491         Encrypt (encryptor, input, output);
492         AssertEquals ("RC2_k40b64_CBC_Zeros Encrypt", expected, output);
493         byte[] reverse = new byte [blockLength * 3];
494         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
495         Decrypt (decryptor, output, reverse);
496         byte[] original = new byte [input.Length];
497         Array.Copy (reverse, 0, original, 0, original.Length);
498         AssertEquals ("RC2_k40b64_CBC_Zeros Decrypt", input, original);
499 }
500
501
502 [Test]
503 public void TestRC2_k40b64_CBC_PKCS7 ()
504 {
505         byte[] key = { 0x67, 0xB6, 0xEE, 0xF5, 0x21 };
506         byte[] iv = { 0xD3, 0xF1, 0xE7, 0xFF, 0x23, 0x92, 0xDC, 0xD9 };
507         byte[] expected = { 0x24, 0x2F, 0x90, 0xAE, 0x75, 0x8E, 0x0C, 0x7F, 0xCA, 0xE4, 0xE7, 0x87, 0x2D, 0xEE, 0x9E, 0x30, 0x49, 0xF0, 0xBB, 0xC4, 0x4C, 0x8D, 0x44, 0x5C };
508
509         SymmetricAlgorithm algo = RC2.Create ();
510         algo.Mode = CipherMode.CBC;
511         algo.Padding = PaddingMode.PKCS7;
512         algo.BlockSize = 64;
513         int blockLength = (algo.BlockSize >> 3);
514         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
515         byte[] output = new byte [blockLength * 3];
516         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
517         Encrypt (encryptor, input, output);
518         AssertEquals ("RC2_k40b64_CBC_PKCS7 Encrypt", expected, output);
519         byte[] reverse = new byte [blockLength * 3];
520         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
521         Decrypt (decryptor, output, reverse);
522         byte[] original = new byte [input.Length];
523         Array.Copy (reverse, 0, original, 0, original.Length);
524         AssertEquals ("RC2_k40b64_CBC_PKCS7 Decrypt", input, original);
525 }
526
527
528 /* Invalid parameters RC2_k40b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
529
530 /* Invalid parameters RC2_k40b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
531
532 /* Invalid parameters RC2_k40b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
533
534 [Test]
535 public void TestRC2_k40b64_CFB8_None ()
536 {
537         byte[] key = { 0x35, 0xCF, 0xA0, 0x20, 0x56 };
538         byte[] iv = { 0xC5, 0x47, 0xFA, 0x9D, 0x19, 0x4F, 0xA9, 0x06 };
539         byte[] expected = { 0xEF, 0xF9, 0xE1, 0xEE, 0x23, 0x89, 0xF6, 0x6B, 0x1F, 0xA6, 0x07, 0xAC, 0x73, 0x4A, 0xC1, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
540
541         SymmetricAlgorithm algo = RC2.Create ();
542         algo.Mode = CipherMode.CFB;
543         algo.Padding = PaddingMode.None;
544         algo.BlockSize = 64;
545         algo.FeedbackSize = 8;
546         int blockLength = (algo.BlockSize >> 3);
547         byte[] input = new byte [blockLength * 2];
548         byte[] output = new byte [blockLength * 3];
549         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
550         Encrypt (encryptor, input, output);
551         AssertEquals ("RC2_k40b64_CFB8_None Encrypt", expected, output);
552         byte[] reverse = new byte [blockLength * 3];
553         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
554         Decrypt (decryptor, output, reverse);
555         byte[] original = new byte [input.Length];
556         Array.Copy (reverse, 0, original, 0, original.Length);
557         AssertEquals ("RC2_k40b64_CFB8_None Decrypt", input, original);
558 }
559
560
561 [Test]
562 public void TestRC2_k40b64_CFB8_Zeros ()
563 {
564         byte[] key = { 0xDA, 0xD8, 0xF9, 0x76, 0xE4 };
565         byte[] iv = { 0xAA, 0xC5, 0x42, 0xF9, 0x88, 0x42, 0x09, 0xB4 };
566         byte[] expected = { 0x49, 0x08, 0xFD, 0x7B, 0x1A, 0xA2, 0xDB, 0xF3, 0xB7, 0x13, 0x01, 0x4F, 0xB8, 0x79, 0x3A, 0x0E, 0xA0, 0x11, 0x1E, 0x27, 0xA7, 0xFE, 0xFA, 0x48 };
567
568         SymmetricAlgorithm algo = RC2.Create ();
569         algo.Mode = CipherMode.CFB;
570         algo.Padding = PaddingMode.Zeros;
571         algo.BlockSize = 64;
572         algo.FeedbackSize = 8;
573         int blockLength = (algo.BlockSize >> 3);
574         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
575         byte[] output = new byte [blockLength * 3];
576         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
577         Encrypt (encryptor, input, output);
578         AssertEquals ("RC2_k40b64_CFB8_Zeros Encrypt", expected, output);
579         byte[] reverse = new byte [blockLength * 3];
580         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
581         Decrypt (decryptor, output, reverse);
582         byte[] original = new byte [input.Length];
583         Array.Copy (reverse, 0, original, 0, original.Length);
584         AssertEquals ("RC2_k40b64_CFB8_Zeros Decrypt", input, original);
585 }
586
587
588 [Test]
589 public void TestRC2_k40b64_CFB8_PKCS7 ()
590 {
591         byte[] key = { 0xDF, 0x8C, 0xC7, 0x3C, 0xDE };
592         byte[] iv = { 0x1D, 0x0A, 0x92, 0x74, 0xD6, 0xEB, 0x99, 0x0F };
593         byte[] expected = { 0xF9, 0x7A, 0x8E, 0xE1, 0xF2, 0x93, 0xB8, 0xCF, 0xD4, 0x7C, 0xF8, 0x81, 0x7F, 0x53, 0x7C, 0x8F, 0x42, 0x8C, 0xC4, 0xFB, 0x9E, 0x0C, 0x65, 0x53 };
594
595         SymmetricAlgorithm algo = RC2.Create ();
596         algo.Mode = CipherMode.CFB;
597         algo.Padding = PaddingMode.PKCS7;
598         algo.BlockSize = 64;
599         algo.FeedbackSize = 8;
600         int blockLength = (algo.BlockSize >> 3);
601         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
602         byte[] output = new byte [blockLength * 3];
603         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
604         Encrypt (encryptor, input, output);
605         AssertEquals ("RC2_k40b64_CFB8_PKCS7 Encrypt", expected, output);
606         byte[] reverse = new byte [blockLength * 3];
607         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
608         Decrypt (decryptor, output, reverse);
609         byte[] original = new byte [input.Length];
610         Array.Copy (reverse, 0, original, 0, original.Length);
611         AssertEquals ("RC2_k40b64_CFB8_PKCS7 Decrypt", input, original);
612 }
613
614
615 /* Invalid parameters RC2_k40b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
616
617 /* Invalid parameters RC2_k40b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
618
619 /* Invalid parameters RC2_k40b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
620
621 [Test]
622 public void TestRC2_k48b64_ECB_None ()
623 {
624         byte[] key = { 0xAA, 0x37, 0x60, 0x52, 0x8A, 0xBE };
625         // not used for ECB but make the code more uniform
626         byte[] iv = { 0x0D, 0x5B, 0x94, 0x0F, 0x9A, 0x87, 0x08, 0x56 };
627         byte[] expected = { 0xB4, 0xB4, 0x2B, 0x12, 0x9C, 0x07, 0xD4, 0xC9, 0xB4, 0xB4, 0x2B, 0x12, 0x9C, 0x07, 0xD4, 0xC9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
628
629         SymmetricAlgorithm algo = RC2.Create ();
630         algo.Mode = CipherMode.ECB;
631         algo.Padding = PaddingMode.None;
632         algo.BlockSize = 64;
633         int blockLength = (algo.BlockSize >> 3);
634         byte[] input = new byte [blockLength * 2];
635         byte[] output = new byte [blockLength * 3];
636         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
637         Encrypt (encryptor, input, output);
638         AssertEquals ("RC2_k48b64_ECB_None Encrypt", expected, output);
639
640         // in ECB the first 2 blocks should be equals (as the IV is not used)
641         byte[] block1 = new byte[blockLength];
642         Array.Copy (output, 0, block1, 0, blockLength);
643         byte[] block2 = new byte[blockLength];
644         Array.Copy (output, blockLength, block2, 0, blockLength);
645         AssertEquals ("RC2_k48b64_ECB_None b1==b2", block1, block2);
646         byte[] reverse = new byte [blockLength * 3];
647         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
648         Decrypt (decryptor, output, reverse);
649         byte[] original = new byte [input.Length];
650         Array.Copy (reverse, 0, original, 0, original.Length);
651         AssertEquals ("RC2_k48b64_ECB_None Decrypt", input, original);
652 }
653
654
655 [Test]
656 public void TestRC2_k48b64_ECB_Zeros ()
657 {
658         byte[] key = { 0x9B, 0x92, 0x8C, 0xC2, 0x18, 0xA3 };
659         // not used for ECB but make the code more uniform
660         byte[] iv = { 0xB7, 0xC2, 0xAD, 0x13, 0x0A, 0x62, 0x0A, 0x50 };
661         byte[] expected = { 0x24, 0x74, 0x0F, 0x4B, 0xAA, 0xB1, 0xB8, 0xF5, 0x24, 0x74, 0x0F, 0x4B, 0xAA, 0xB1, 0xB8, 0xF5, 0x24, 0x74, 0x0F, 0x4B, 0xAA, 0xB1, 0xB8, 0xF5 };
662
663         SymmetricAlgorithm algo = RC2.Create ();
664         algo.Mode = CipherMode.ECB;
665         algo.Padding = PaddingMode.Zeros;
666         algo.BlockSize = 64;
667         int blockLength = (algo.BlockSize >> 3);
668         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
669         byte[] output = new byte [blockLength * 3];
670         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
671         Encrypt (encryptor, input, output);
672         AssertEquals ("RC2_k48b64_ECB_Zeros Encrypt", expected, output);
673
674         // in ECB the first 2 blocks should be equals (as the IV is not used)
675         byte[] block1 = new byte[blockLength];
676         Array.Copy (output, 0, block1, 0, blockLength);
677         byte[] block2 = new byte[blockLength];
678         Array.Copy (output, blockLength, block2, 0, blockLength);
679         AssertEquals ("RC2_k48b64_ECB_Zeros b1==b2", block1, block2);
680
681         // also if padding is Zeros then all three blocks should be equals
682         byte[] block3 = new byte[blockLength];
683         Array.Copy (output, blockLength, block3, 0, blockLength);
684         AssertEquals ("RC2_k48b64_ECB_Zeros b1==b3", block1, block3);
685
686         byte[] reverse = new byte [blockLength * 3];
687         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
688         Decrypt (decryptor, output, reverse);
689         byte[] original = new byte [input.Length];
690         Array.Copy (reverse, 0, original, 0, original.Length);
691         AssertEquals ("RC2_k48b64_ECB_Zeros Decrypt", input, original);
692 }
693
694
695 [Test]
696 public void TestRC2_k48b64_ECB_PKCS7 ()
697 {
698         byte[] key = { 0x58, 0x1A, 0xD6, 0x96, 0x02, 0x75 };
699         // not used for ECB but make the code more uniform
700         byte[] iv = { 0x56, 0x83, 0x39, 0x7F, 0x3B, 0xD9, 0xB0, 0x33 };
701         byte[] expected = { 0x87, 0x46, 0x9E, 0xFF, 0x4B, 0xE8, 0xDA, 0xF2, 0x87, 0x46, 0x9E, 0xFF, 0x4B, 0xE8, 0xDA, 0xF2, 0x31, 0x54, 0x04, 0x63, 0xE0, 0x76, 0x74, 0x39 };
702
703         SymmetricAlgorithm algo = RC2.Create ();
704         algo.Mode = CipherMode.ECB;
705         algo.Padding = PaddingMode.PKCS7;
706         algo.BlockSize = 64;
707         int blockLength = (algo.BlockSize >> 3);
708         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
709         byte[] output = new byte [blockLength * 3];
710         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
711         Encrypt (encryptor, input, output);
712         AssertEquals ("RC2_k48b64_ECB_PKCS7 Encrypt", expected, output);
713
714         // in ECB the first 2 blocks should be equals (as the IV is not used)
715         byte[] block1 = new byte[blockLength];
716         Array.Copy (output, 0, block1, 0, blockLength);
717         byte[] block2 = new byte[blockLength];
718         Array.Copy (output, blockLength, block2, 0, blockLength);
719         AssertEquals ("RC2_k48b64_ECB_PKCS7 b1==b2", block1, block2);
720         byte[] reverse = new byte [blockLength * 3];
721         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
722         Decrypt (decryptor, output, reverse);
723         byte[] original = new byte [input.Length];
724         Array.Copy (reverse, 0, original, 0, original.Length);
725         AssertEquals ("RC2_k48b64_ECB_PKCS7 Decrypt", input, original);
726 }
727
728
729 [Test]
730 public void TestRC2_k48b64_CBC_None ()
731 {
732         byte[] key = { 0x21, 0x9A, 0xD6, 0x31, 0x99, 0x81 };
733         byte[] iv = { 0x5E, 0x6E, 0xB6, 0x33, 0xC0, 0x25, 0xAE, 0x5C };
734         byte[] expected = { 0x35, 0xFA, 0x8F, 0x4F, 0x75, 0xD1, 0x10, 0x11, 0xC0, 0xA4, 0x73, 0x69, 0xBD, 0xD2, 0xE3, 0x9D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
735
736         SymmetricAlgorithm algo = RC2.Create ();
737         algo.Mode = CipherMode.CBC;
738         algo.Padding = PaddingMode.None;
739         algo.BlockSize = 64;
740         int blockLength = (algo.BlockSize >> 3);
741         byte[] input = new byte [blockLength * 2];
742         byte[] output = new byte [blockLength * 3];
743         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
744         Encrypt (encryptor, input, output);
745         AssertEquals ("RC2_k48b64_CBC_None Encrypt", expected, output);
746         byte[] reverse = new byte [blockLength * 3];
747         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
748         Decrypt (decryptor, output, reverse);
749         byte[] original = new byte [input.Length];
750         Array.Copy (reverse, 0, original, 0, original.Length);
751         AssertEquals ("RC2_k48b64_CBC_None Decrypt", input, original);
752 }
753
754
755 [Test]
756 public void TestRC2_k48b64_CBC_Zeros ()
757 {
758         byte[] key = { 0x59, 0x0A, 0xD4, 0x25, 0xA5, 0xB9 };
759         byte[] iv = { 0x10, 0x2D, 0x42, 0x54, 0xC8, 0x97, 0xD0, 0xA7 };
760         byte[] expected = { 0x4F, 0x1A, 0x5F, 0xD0, 0xA2, 0x54, 0x57, 0x60, 0x55, 0x9B, 0x4D, 0x1B, 0x55, 0xC9, 0x30, 0xA9, 0x7E, 0xF6, 0xAF, 0xFB, 0x50, 0x8B, 0xC0, 0xB6 };
761
762         SymmetricAlgorithm algo = RC2.Create ();
763         algo.Mode = CipherMode.CBC;
764         algo.Padding = PaddingMode.Zeros;
765         algo.BlockSize = 64;
766         int blockLength = (algo.BlockSize >> 3);
767         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
768         byte[] output = new byte [blockLength * 3];
769         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
770         Encrypt (encryptor, input, output);
771         AssertEquals ("RC2_k48b64_CBC_Zeros Encrypt", expected, output);
772         byte[] reverse = new byte [blockLength * 3];
773         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
774         Decrypt (decryptor, output, reverse);
775         byte[] original = new byte [input.Length];
776         Array.Copy (reverse, 0, original, 0, original.Length);
777         AssertEquals ("RC2_k48b64_CBC_Zeros Decrypt", input, original);
778 }
779
780
781 [Test]
782 public void TestRC2_k48b64_CBC_PKCS7 ()
783 {
784         byte[] key = { 0x39, 0x6C, 0xB3, 0x7B, 0xB5, 0xA9 };
785         byte[] iv = { 0x42, 0x56, 0x99, 0x18, 0xA8, 0x96, 0x93, 0x5D };
786         byte[] expected = { 0x92, 0x8B, 0x67, 0xC7, 0xAE, 0xF3, 0xF7, 0x03, 0x24, 0x67, 0xAC, 0xEA, 0xFE, 0xB7, 0x6B, 0x1E, 0x53, 0xB3, 0xF5, 0xDB, 0x64, 0x63, 0xB3, 0xE5 };
787
788         SymmetricAlgorithm algo = RC2.Create ();
789         algo.Mode = CipherMode.CBC;
790         algo.Padding = PaddingMode.PKCS7;
791         algo.BlockSize = 64;
792         int blockLength = (algo.BlockSize >> 3);
793         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
794         byte[] output = new byte [blockLength * 3];
795         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
796         Encrypt (encryptor, input, output);
797         AssertEquals ("RC2_k48b64_CBC_PKCS7 Encrypt", expected, output);
798         byte[] reverse = new byte [blockLength * 3];
799         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
800         Decrypt (decryptor, output, reverse);
801         byte[] original = new byte [input.Length];
802         Array.Copy (reverse, 0, original, 0, original.Length);
803         AssertEquals ("RC2_k48b64_CBC_PKCS7 Decrypt", input, original);
804 }
805
806
807 /* Invalid parameters RC2_k48b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
808
809 /* Invalid parameters RC2_k48b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
810
811 /* Invalid parameters RC2_k48b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
812
813 [Test]
814 public void TestRC2_k48b64_CFB8_None ()
815 {
816         byte[] key = { 0x06, 0xCE, 0x23, 0x86, 0xEC, 0xB3 };
817         byte[] iv = { 0x14, 0xF7, 0xBA, 0xEC, 0xC2, 0x4A, 0x26, 0x6D };
818         byte[] expected = { 0x69, 0x7A, 0x1A, 0xCC, 0x40, 0x41, 0x78, 0xC1, 0xFA, 0x89, 0x90, 0x7F, 0xC1, 0x1C, 0x27, 0x4D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
819
820         SymmetricAlgorithm algo = RC2.Create ();
821         algo.Mode = CipherMode.CFB;
822         algo.Padding = PaddingMode.None;
823         algo.BlockSize = 64;
824         algo.FeedbackSize = 8;
825         int blockLength = (algo.BlockSize >> 3);
826         byte[] input = new byte [blockLength * 2];
827         byte[] output = new byte [blockLength * 3];
828         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
829         Encrypt (encryptor, input, output);
830         AssertEquals ("RC2_k48b64_CFB8_None Encrypt", expected, output);
831         byte[] reverse = new byte [blockLength * 3];
832         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
833         Decrypt (decryptor, output, reverse);
834         byte[] original = new byte [input.Length];
835         Array.Copy (reverse, 0, original, 0, original.Length);
836         AssertEquals ("RC2_k48b64_CFB8_None Decrypt", input, original);
837 }
838
839
840 [Test]
841 public void TestRC2_k48b64_CFB8_Zeros ()
842 {
843         byte[] key = { 0x4B, 0xC8, 0x03, 0x4F, 0x43, 0x27 };
844         byte[] iv = { 0x02, 0x24, 0xB8, 0xE9, 0xF6, 0x19, 0xA1, 0x81 };
845         byte[] expected = { 0xE2, 0xD2, 0x50, 0x68, 0x56, 0x61, 0x30, 0x72, 0xA2, 0xDE, 0x97, 0xF5, 0x5C, 0xE9, 0xD5, 0xA0, 0x35, 0xD2, 0xC3, 0xEB, 0xC9, 0x2A, 0x64, 0x4D };
846
847         SymmetricAlgorithm algo = RC2.Create ();
848         algo.Mode = CipherMode.CFB;
849         algo.Padding = PaddingMode.Zeros;
850         algo.BlockSize = 64;
851         algo.FeedbackSize = 8;
852         int blockLength = (algo.BlockSize >> 3);
853         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
854         byte[] output = new byte [blockLength * 3];
855         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
856         Encrypt (encryptor, input, output);
857         AssertEquals ("RC2_k48b64_CFB8_Zeros Encrypt", expected, output);
858         byte[] reverse = new byte [blockLength * 3];
859         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
860         Decrypt (decryptor, output, reverse);
861         byte[] original = new byte [input.Length];
862         Array.Copy (reverse, 0, original, 0, original.Length);
863         AssertEquals ("RC2_k48b64_CFB8_Zeros Decrypt", input, original);
864 }
865
866
867 [Test]
868 public void TestRC2_k48b64_CFB8_PKCS7 ()
869 {
870         byte[] key = { 0x22, 0x94, 0x8C, 0x13, 0x7F, 0x7A };
871         byte[] iv = { 0x4B, 0xDF, 0xB8, 0xBF, 0x0D, 0xBE, 0x1E, 0x3D };
872         byte[] expected = { 0x24, 0xE9, 0x2B, 0xBF, 0x84, 0x49, 0x4D, 0x2B, 0xC4, 0xD8, 0xEE, 0xAB, 0x52, 0x03, 0xC6, 0xAF, 0x19, 0x0A, 0x5B, 0x38, 0xB6, 0xF1, 0x98, 0x6F };
873
874         SymmetricAlgorithm algo = RC2.Create ();
875         algo.Mode = CipherMode.CFB;
876         algo.Padding = PaddingMode.PKCS7;
877         algo.BlockSize = 64;
878         algo.FeedbackSize = 8;
879         int blockLength = (algo.BlockSize >> 3);
880         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
881         byte[] output = new byte [blockLength * 3];
882         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
883         Encrypt (encryptor, input, output);
884         AssertEquals ("RC2_k48b64_CFB8_PKCS7 Encrypt", expected, output);
885         byte[] reverse = new byte [blockLength * 3];
886         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
887         Decrypt (decryptor, output, reverse);
888         byte[] original = new byte [input.Length];
889         Array.Copy (reverse, 0, original, 0, original.Length);
890         AssertEquals ("RC2_k48b64_CFB8_PKCS7 Decrypt", input, original);
891 }
892
893
894 /* Invalid parameters RC2_k48b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
895
896 /* Invalid parameters RC2_k48b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
897
898 /* Invalid parameters RC2_k48b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
899
900 [Test]
901 public void TestRC2_k56b64_ECB_None ()
902 {
903         byte[] key = { 0xCA, 0x6B, 0x7A, 0xA1, 0xB1, 0x6E, 0x4A };
904         // not used for ECB but make the code more uniform
905         byte[] iv = { 0xF0, 0xA9, 0x35, 0xDB, 0x4F, 0xB5, 0x3D, 0xE4 };
906         byte[] expected = { 0x23, 0x39, 0x2D, 0xD9, 0x7C, 0xC0, 0xFF, 0x64, 0x23, 0x39, 0x2D, 0xD9, 0x7C, 0xC0, 0xFF, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
907
908         SymmetricAlgorithm algo = RC2.Create ();
909         algo.Mode = CipherMode.ECB;
910         algo.Padding = PaddingMode.None;
911         algo.BlockSize = 64;
912         int blockLength = (algo.BlockSize >> 3);
913         byte[] input = new byte [blockLength * 2];
914         byte[] output = new byte [blockLength * 3];
915         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
916         Encrypt (encryptor, input, output);
917         AssertEquals ("RC2_k56b64_ECB_None Encrypt", expected, output);
918
919         // in ECB the first 2 blocks should be equals (as the IV is not used)
920         byte[] block1 = new byte[blockLength];
921         Array.Copy (output, 0, block1, 0, blockLength);
922         byte[] block2 = new byte[blockLength];
923         Array.Copy (output, blockLength, block2, 0, blockLength);
924         AssertEquals ("RC2_k56b64_ECB_None b1==b2", block1, block2);
925         byte[] reverse = new byte [blockLength * 3];
926         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
927         Decrypt (decryptor, output, reverse);
928         byte[] original = new byte [input.Length];
929         Array.Copy (reverse, 0, original, 0, original.Length);
930         AssertEquals ("RC2_k56b64_ECB_None Decrypt", input, original);
931 }
932
933
934 [Test]
935 public void TestRC2_k56b64_ECB_Zeros ()
936 {
937         byte[] key = { 0x96, 0x43, 0x86, 0xAA, 0x0E, 0x66, 0x95 };
938         // not used for ECB but make the code more uniform
939         byte[] iv = { 0xD3, 0xD7, 0x93, 0xED, 0xAF, 0xD6, 0x83, 0x3F };
940         byte[] expected = { 0x1C, 0x72, 0x96, 0xCF, 0x7D, 0x18, 0xDB, 0x4B, 0x1C, 0x72, 0x96, 0xCF, 0x7D, 0x18, 0xDB, 0x4B, 0x1C, 0x72, 0x96, 0xCF, 0x7D, 0x18, 0xDB, 0x4B };
941
942         SymmetricAlgorithm algo = RC2.Create ();
943         algo.Mode = CipherMode.ECB;
944         algo.Padding = PaddingMode.Zeros;
945         algo.BlockSize = 64;
946         int blockLength = (algo.BlockSize >> 3);
947         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
948         byte[] output = new byte [blockLength * 3];
949         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
950         Encrypt (encryptor, input, output);
951         AssertEquals ("RC2_k56b64_ECB_Zeros Encrypt", expected, output);
952
953         // in ECB the first 2 blocks should be equals (as the IV is not used)
954         byte[] block1 = new byte[blockLength];
955         Array.Copy (output, 0, block1, 0, blockLength);
956         byte[] block2 = new byte[blockLength];
957         Array.Copy (output, blockLength, block2, 0, blockLength);
958         AssertEquals ("RC2_k56b64_ECB_Zeros b1==b2", block1, block2);
959
960         // also if padding is Zeros then all three blocks should be equals
961         byte[] block3 = new byte[blockLength];
962         Array.Copy (output, blockLength, block3, 0, blockLength);
963         AssertEquals ("RC2_k56b64_ECB_Zeros b1==b3", block1, block3);
964
965         byte[] reverse = new byte [blockLength * 3];
966         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
967         Decrypt (decryptor, output, reverse);
968         byte[] original = new byte [input.Length];
969         Array.Copy (reverse, 0, original, 0, original.Length);
970         AssertEquals ("RC2_k56b64_ECB_Zeros Decrypt", input, original);
971 }
972
973
974 [Test]
975 public void TestRC2_k56b64_ECB_PKCS7 ()
976 {
977         byte[] key = { 0x5A, 0x29, 0xE4, 0x77, 0x99, 0x9D, 0x5B };
978         // not used for ECB but make the code more uniform
979         byte[] iv = { 0xA6, 0x7B, 0x92, 0x40, 0x74, 0x9E, 0x0D, 0xAD };
980         byte[] expected = { 0xE1, 0xBB, 0xAA, 0x43, 0x54, 0x2E, 0xFF, 0x3A, 0xE1, 0xBB, 0xAA, 0x43, 0x54, 0x2E, 0xFF, 0x3A, 0x2E, 0xA1, 0x81, 0xF1, 0x85, 0x86, 0x35, 0x97 };
981
982         SymmetricAlgorithm algo = RC2.Create ();
983         algo.Mode = CipherMode.ECB;
984         algo.Padding = PaddingMode.PKCS7;
985         algo.BlockSize = 64;
986         int blockLength = (algo.BlockSize >> 3);
987         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
988         byte[] output = new byte [blockLength * 3];
989         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
990         Encrypt (encryptor, input, output);
991         AssertEquals ("RC2_k56b64_ECB_PKCS7 Encrypt", expected, output);
992
993         // in ECB the first 2 blocks should be equals (as the IV is not used)
994         byte[] block1 = new byte[blockLength];
995         Array.Copy (output, 0, block1, 0, blockLength);
996         byte[] block2 = new byte[blockLength];
997         Array.Copy (output, blockLength, block2, 0, blockLength);
998         AssertEquals ("RC2_k56b64_ECB_PKCS7 b1==b2", block1, block2);
999         byte[] reverse = new byte [blockLength * 3];
1000         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1001         Decrypt (decryptor, output, reverse);
1002         byte[] original = new byte [input.Length];
1003         Array.Copy (reverse, 0, original, 0, original.Length);
1004         AssertEquals ("RC2_k56b64_ECB_PKCS7 Decrypt", input, original);
1005 }
1006
1007
1008 [Test]
1009 public void TestRC2_k56b64_CBC_None ()
1010 {
1011         byte[] key = { 0xDD, 0x2F, 0x84, 0x9F, 0xBA, 0xB1, 0xF3 };
1012         byte[] iv = { 0x97, 0xB2, 0xCD, 0x3F, 0x1E, 0x53, 0xE8, 0xA9 };
1013         byte[] expected = { 0x63, 0x6E, 0x62, 0xE5, 0x0F, 0x58, 0x86, 0x4A, 0xEF, 0x64, 0x4C, 0xDC, 0x36, 0x5D, 0x29, 0xC6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1014
1015         SymmetricAlgorithm algo = RC2.Create ();
1016         algo.Mode = CipherMode.CBC;
1017         algo.Padding = PaddingMode.None;
1018         algo.BlockSize = 64;
1019         int blockLength = (algo.BlockSize >> 3);
1020         byte[] input = new byte [blockLength * 2];
1021         byte[] output = new byte [blockLength * 3];
1022         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1023         Encrypt (encryptor, input, output);
1024         AssertEquals ("RC2_k56b64_CBC_None Encrypt", expected, output);
1025         byte[] reverse = new byte [blockLength * 3];
1026         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1027         Decrypt (decryptor, output, reverse);
1028         byte[] original = new byte [input.Length];
1029         Array.Copy (reverse, 0, original, 0, original.Length);
1030         AssertEquals ("RC2_k56b64_CBC_None Decrypt", input, original);
1031 }
1032
1033
1034 [Test]
1035 public void TestRC2_k56b64_CBC_Zeros ()
1036 {
1037         byte[] key = { 0xED, 0xEE, 0x33, 0x8E, 0x97, 0x20, 0x58 };
1038         byte[] iv = { 0x0B, 0xAB, 0xAB, 0xED, 0xCC, 0x1C, 0x77, 0xA4 };
1039         byte[] expected = { 0x8B, 0x2F, 0x52, 0x93, 0x48, 0x7A, 0x54, 0x03, 0x58, 0x6A, 0x9B, 0xC4, 0x13, 0x99, 0xCD, 0xE2, 0x18, 0x31, 0x67, 0x05, 0x27, 0x90, 0x1D, 0xFE };
1040
1041         SymmetricAlgorithm algo = RC2.Create ();
1042         algo.Mode = CipherMode.CBC;
1043         algo.Padding = PaddingMode.Zeros;
1044         algo.BlockSize = 64;
1045         int blockLength = (algo.BlockSize >> 3);
1046         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1047         byte[] output = new byte [blockLength * 3];
1048         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1049         Encrypt (encryptor, input, output);
1050         AssertEquals ("RC2_k56b64_CBC_Zeros Encrypt", expected, output);
1051         byte[] reverse = new byte [blockLength * 3];
1052         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1053         Decrypt (decryptor, output, reverse);
1054         byte[] original = new byte [input.Length];
1055         Array.Copy (reverse, 0, original, 0, original.Length);
1056         AssertEquals ("RC2_k56b64_CBC_Zeros Decrypt", input, original);
1057 }
1058
1059
1060 [Test]
1061 public void TestRC2_k56b64_CBC_PKCS7 ()
1062 {
1063         byte[] key = { 0x52, 0xF6, 0xC3, 0xC3, 0x13, 0x9E, 0xF7 };
1064         byte[] iv = { 0x8E, 0xF8, 0xE5, 0x66, 0x64, 0x1C, 0xE6, 0xE3 };
1065         byte[] expected = { 0x7B, 0xD1, 0x1A, 0xD0, 0x62, 0x1B, 0x66, 0x5B, 0x92, 0xB0, 0x42, 0xC7, 0x63, 0x3A, 0x95, 0xED, 0x87, 0x6B, 0xA0, 0x88, 0x18, 0xC2, 0x92, 0xB4 };
1066
1067         SymmetricAlgorithm algo = RC2.Create ();
1068         algo.Mode = CipherMode.CBC;
1069         algo.Padding = PaddingMode.PKCS7;
1070         algo.BlockSize = 64;
1071         int blockLength = (algo.BlockSize >> 3);
1072         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1073         byte[] output = new byte [blockLength * 3];
1074         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1075         Encrypt (encryptor, input, output);
1076         AssertEquals ("RC2_k56b64_CBC_PKCS7 Encrypt", expected, output);
1077         byte[] reverse = new byte [blockLength * 3];
1078         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1079         Decrypt (decryptor, output, reverse);
1080         byte[] original = new byte [input.Length];
1081         Array.Copy (reverse, 0, original, 0, original.Length);
1082         AssertEquals ("RC2_k56b64_CBC_PKCS7 Decrypt", input, original);
1083 }
1084
1085
1086 /* Invalid parameters RC2_k56b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
1087
1088 /* Invalid parameters RC2_k56b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
1089
1090 /* Invalid parameters RC2_k56b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
1091
1092 [Test]
1093 public void TestRC2_k56b64_CFB8_None ()
1094 {
1095         byte[] key = { 0xEA, 0x1D, 0xB2, 0x0E, 0x17, 0xF0, 0x4A };
1096         byte[] iv = { 0xB7, 0xEE, 0xEE, 0xFF, 0x36, 0x8C, 0x9B, 0xBB };
1097         byte[] expected = { 0x49, 0x1D, 0x32, 0xB4, 0x93, 0xEC, 0x96, 0xC9, 0xDC, 0x3B, 0x26, 0x4B, 0x3C, 0xA2, 0xE8, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1098
1099         SymmetricAlgorithm algo = RC2.Create ();
1100         algo.Mode = CipherMode.CFB;
1101         algo.Padding = PaddingMode.None;
1102         algo.BlockSize = 64;
1103         algo.FeedbackSize = 8;
1104         int blockLength = (algo.BlockSize >> 3);
1105         byte[] input = new byte [blockLength * 2];
1106         byte[] output = new byte [blockLength * 3];
1107         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1108         Encrypt (encryptor, input, output);
1109         AssertEquals ("RC2_k56b64_CFB8_None Encrypt", expected, output);
1110         byte[] reverse = new byte [blockLength * 3];
1111         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1112         Decrypt (decryptor, output, reverse);
1113         byte[] original = new byte [input.Length];
1114         Array.Copy (reverse, 0, original, 0, original.Length);
1115         AssertEquals ("RC2_k56b64_CFB8_None Decrypt", input, original);
1116 }
1117
1118
1119 [Test]
1120 public void TestRC2_k56b64_CFB8_Zeros ()
1121 {
1122         byte[] key = { 0x24, 0x6F, 0xE0, 0xC7, 0x3C, 0xC0, 0x4B };
1123         byte[] iv = { 0xD7, 0x83, 0xCA, 0xB7, 0x9C, 0x6D, 0xC3, 0x25 };
1124         byte[] expected = { 0x37, 0xF7, 0x35, 0xF4, 0xB2, 0x0C, 0xCB, 0xC4, 0xAE, 0x42, 0x83, 0x99, 0x55, 0xF6, 0x51, 0x5A, 0x1A, 0xE7, 0x7B, 0xFD, 0x4E, 0x78, 0xD7, 0x80 };
1125
1126         SymmetricAlgorithm algo = RC2.Create ();
1127         algo.Mode = CipherMode.CFB;
1128         algo.Padding = PaddingMode.Zeros;
1129         algo.BlockSize = 64;
1130         algo.FeedbackSize = 8;
1131         int blockLength = (algo.BlockSize >> 3);
1132         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1133         byte[] output = new byte [blockLength * 3];
1134         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1135         Encrypt (encryptor, input, output);
1136         AssertEquals ("RC2_k56b64_CFB8_Zeros Encrypt", expected, output);
1137         byte[] reverse = new byte [blockLength * 3];
1138         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1139         Decrypt (decryptor, output, reverse);
1140         byte[] original = new byte [input.Length];
1141         Array.Copy (reverse, 0, original, 0, original.Length);
1142         AssertEquals ("RC2_k56b64_CFB8_Zeros Decrypt", input, original);
1143 }
1144
1145
1146 [Test]
1147 public void TestRC2_k56b64_CFB8_PKCS7 ()
1148 {
1149         byte[] key = { 0x58, 0xE4, 0xC8, 0x6F, 0xB4, 0x14, 0xAC };
1150         byte[] iv = { 0xA1, 0xBC, 0x94, 0xB5, 0xF5, 0x4F, 0x78, 0x19 };
1151         byte[] expected = { 0xBA, 0x15, 0xE2, 0x73, 0x56, 0x5E, 0xB6, 0x30, 0xA8, 0x50, 0xA2, 0x61, 0x52, 0x2F, 0x61, 0xCC, 0x97, 0x9A, 0x91, 0xB1, 0xF0, 0x87, 0x3F, 0xA7 };
1152
1153         SymmetricAlgorithm algo = RC2.Create ();
1154         algo.Mode = CipherMode.CFB;
1155         algo.Padding = PaddingMode.PKCS7;
1156         algo.BlockSize = 64;
1157         algo.FeedbackSize = 8;
1158         int blockLength = (algo.BlockSize >> 3);
1159         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1160         byte[] output = new byte [blockLength * 3];
1161         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1162         Encrypt (encryptor, input, output);
1163         AssertEquals ("RC2_k56b64_CFB8_PKCS7 Encrypt", expected, output);
1164         byte[] reverse = new byte [blockLength * 3];
1165         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1166         Decrypt (decryptor, output, reverse);
1167         byte[] original = new byte [input.Length];
1168         Array.Copy (reverse, 0, original, 0, original.Length);
1169         AssertEquals ("RC2_k56b64_CFB8_PKCS7 Decrypt", input, original);
1170 }
1171
1172
1173 /* Invalid parameters RC2_k56b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
1174
1175 /* Invalid parameters RC2_k56b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
1176
1177 /* Invalid parameters RC2_k56b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
1178
1179 [Test]
1180 public void TestRC2_k64b64_ECB_None ()
1181 {
1182         byte[] key = { 0x2C, 0x52, 0xB4, 0x93, 0xF1, 0xEA, 0xC8, 0x8F };
1183         // not used for ECB but make the code more uniform
1184         byte[] iv = { 0xDE, 0x10, 0xA1, 0x1C, 0x5E, 0x43, 0x5F, 0x97 };
1185         byte[] expected = { 0xDB, 0x1D, 0x72, 0x2C, 0x7C, 0x4A, 0x31, 0xDB, 0xDB, 0x1D, 0x72, 0x2C, 0x7C, 0x4A, 0x31, 0xDB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1186
1187         SymmetricAlgorithm algo = RC2.Create ();
1188         algo.Mode = CipherMode.ECB;
1189         algo.Padding = PaddingMode.None;
1190         algo.BlockSize = 64;
1191         int blockLength = (algo.BlockSize >> 3);
1192         byte[] input = new byte [blockLength * 2];
1193         byte[] output = new byte [blockLength * 3];
1194         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1195         Encrypt (encryptor, input, output);
1196         AssertEquals ("RC2_k64b64_ECB_None Encrypt", expected, output);
1197
1198         // in ECB the first 2 blocks should be equals (as the IV is not used)
1199         byte[] block1 = new byte[blockLength];
1200         Array.Copy (output, 0, block1, 0, blockLength);
1201         byte[] block2 = new byte[blockLength];
1202         Array.Copy (output, blockLength, block2, 0, blockLength);
1203         AssertEquals ("RC2_k64b64_ECB_None b1==b2", block1, block2);
1204         byte[] reverse = new byte [blockLength * 3];
1205         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1206         Decrypt (decryptor, output, reverse);
1207         byte[] original = new byte [input.Length];
1208         Array.Copy (reverse, 0, original, 0, original.Length);
1209         AssertEquals ("RC2_k64b64_ECB_None Decrypt", input, original);
1210 }
1211
1212
1213 [Test]
1214 public void TestRC2_k64b64_ECB_Zeros ()
1215 {
1216         byte[] key = { 0x05, 0x0C, 0x49, 0xE3, 0x25, 0x49, 0xFA, 0x35 };
1217         // not used for ECB but make the code more uniform
1218         byte[] iv = { 0x4D, 0x94, 0x32, 0xD2, 0x8B, 0xB6, 0x52, 0x9C };
1219         byte[] expected = { 0x39, 0x35, 0xCE, 0x5C, 0x75, 0xF5, 0xB7, 0xA1, 0x39, 0x35, 0xCE, 0x5C, 0x75, 0xF5, 0xB7, 0xA1, 0x39, 0x35, 0xCE, 0x5C, 0x75, 0xF5, 0xB7, 0xA1 };
1220
1221         SymmetricAlgorithm algo = RC2.Create ();
1222         algo.Mode = CipherMode.ECB;
1223         algo.Padding = PaddingMode.Zeros;
1224         algo.BlockSize = 64;
1225         int blockLength = (algo.BlockSize >> 3);
1226         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1227         byte[] output = new byte [blockLength * 3];
1228         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1229         Encrypt (encryptor, input, output);
1230         AssertEquals ("RC2_k64b64_ECB_Zeros Encrypt", expected, output);
1231
1232         // in ECB the first 2 blocks should be equals (as the IV is not used)
1233         byte[] block1 = new byte[blockLength];
1234         Array.Copy (output, 0, block1, 0, blockLength);
1235         byte[] block2 = new byte[blockLength];
1236         Array.Copy (output, blockLength, block2, 0, blockLength);
1237         AssertEquals ("RC2_k64b64_ECB_Zeros b1==b2", block1, block2);
1238
1239         // also if padding is Zeros then all three blocks should be equals
1240         byte[] block3 = new byte[blockLength];
1241         Array.Copy (output, blockLength, block3, 0, blockLength);
1242         AssertEquals ("RC2_k64b64_ECB_Zeros b1==b3", block1, block3);
1243
1244         byte[] reverse = new byte [blockLength * 3];
1245         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1246         Decrypt (decryptor, output, reverse);
1247         byte[] original = new byte [input.Length];
1248         Array.Copy (reverse, 0, original, 0, original.Length);
1249         AssertEquals ("RC2_k64b64_ECB_Zeros Decrypt", input, original);
1250 }
1251
1252
1253 [Test]
1254 public void TestRC2_k64b64_ECB_PKCS7 ()
1255 {
1256         byte[] key = { 0xE6, 0x57, 0xF2, 0x73, 0x3A, 0x20, 0xB0, 0x7E };
1257         // not used for ECB but make the code more uniform
1258         byte[] iv = { 0x34, 0x25, 0xD2, 0x35, 0x1C, 0xE4, 0x9D, 0xC6 };
1259         byte[] expected = { 0x7A, 0x3F, 0x95, 0xA0, 0xA1, 0x70, 0xBD, 0xC3, 0x7A, 0x3F, 0x95, 0xA0, 0xA1, 0x70, 0xBD, 0xC3, 0xDA, 0xE7, 0x0C, 0xC3, 0xAD, 0xC3, 0xEA, 0xE9 };
1260
1261         SymmetricAlgorithm algo = RC2.Create ();
1262         algo.Mode = CipherMode.ECB;
1263         algo.Padding = PaddingMode.PKCS7;
1264         algo.BlockSize = 64;
1265         int blockLength = (algo.BlockSize >> 3);
1266         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1267         byte[] output = new byte [blockLength * 3];
1268         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1269         Encrypt (encryptor, input, output);
1270         AssertEquals ("RC2_k64b64_ECB_PKCS7 Encrypt", expected, output);
1271
1272         // in ECB the first 2 blocks should be equals (as the IV is not used)
1273         byte[] block1 = new byte[blockLength];
1274         Array.Copy (output, 0, block1, 0, blockLength);
1275         byte[] block2 = new byte[blockLength];
1276         Array.Copy (output, blockLength, block2, 0, blockLength);
1277         AssertEquals ("RC2_k64b64_ECB_PKCS7 b1==b2", block1, block2);
1278         byte[] reverse = new byte [blockLength * 3];
1279         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1280         Decrypt (decryptor, output, reverse);
1281         byte[] original = new byte [input.Length];
1282         Array.Copy (reverse, 0, original, 0, original.Length);
1283         AssertEquals ("RC2_k64b64_ECB_PKCS7 Decrypt", input, original);
1284 }
1285
1286
1287 [Test]
1288 public void TestRC2_k64b64_CBC_None ()
1289 {
1290         byte[] key = { 0x91, 0x14, 0x49, 0xC4, 0x0D, 0xF9, 0x90, 0x77 };
1291         byte[] iv = { 0xB9, 0xBD, 0x6B, 0x9E, 0x52, 0xC9, 0x8C, 0xA5 };
1292         byte[] expected = { 0xF1, 0x7C, 0xDF, 0x18, 0x54, 0xC2, 0xDE, 0x3B, 0x05, 0x20, 0x99, 0x94, 0x8A, 0x5E, 0x29, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1293
1294         SymmetricAlgorithm algo = RC2.Create ();
1295         algo.Mode = CipherMode.CBC;
1296         algo.Padding = PaddingMode.None;
1297         algo.BlockSize = 64;
1298         int blockLength = (algo.BlockSize >> 3);
1299         byte[] input = new byte [blockLength * 2];
1300         byte[] output = new byte [blockLength * 3];
1301         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1302         Encrypt (encryptor, input, output);
1303         AssertEquals ("RC2_k64b64_CBC_None Encrypt", expected, output);
1304         byte[] reverse = new byte [blockLength * 3];
1305         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1306         Decrypt (decryptor, output, reverse);
1307         byte[] original = new byte [input.Length];
1308         Array.Copy (reverse, 0, original, 0, original.Length);
1309         AssertEquals ("RC2_k64b64_CBC_None Decrypt", input, original);
1310 }
1311
1312
1313 [Test]
1314 public void TestRC2_k64b64_CBC_Zeros ()
1315 {
1316         byte[] key = { 0x0E, 0xE0, 0xAD, 0xFD, 0x86, 0x22, 0x1D, 0x05 };
1317         byte[] iv = { 0xDF, 0x41, 0x2B, 0x6E, 0x82, 0x00, 0xCB, 0x38 };
1318         byte[] expected = { 0x98, 0x43, 0x84, 0x05, 0x68, 0xAE, 0x99, 0x3B, 0xB1, 0xCD, 0x2F, 0x69, 0xD9, 0xDD, 0x54, 0x79, 0x37, 0x36, 0x96, 0xE9, 0xC3, 0x62, 0xC2, 0x35 };
1319
1320         SymmetricAlgorithm algo = RC2.Create ();
1321         algo.Mode = CipherMode.CBC;
1322         algo.Padding = PaddingMode.Zeros;
1323         algo.BlockSize = 64;
1324         int blockLength = (algo.BlockSize >> 3);
1325         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1326         byte[] output = new byte [blockLength * 3];
1327         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1328         Encrypt (encryptor, input, output);
1329         AssertEquals ("RC2_k64b64_CBC_Zeros Encrypt", expected, output);
1330         byte[] reverse = new byte [blockLength * 3];
1331         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1332         Decrypt (decryptor, output, reverse);
1333         byte[] original = new byte [input.Length];
1334         Array.Copy (reverse, 0, original, 0, original.Length);
1335         AssertEquals ("RC2_k64b64_CBC_Zeros Decrypt", input, original);
1336 }
1337
1338
1339 [Test]
1340 public void TestRC2_k64b64_CBC_PKCS7 ()
1341 {
1342         byte[] key = { 0x2D, 0x70, 0x15, 0xFF, 0x15, 0xEB, 0xDC, 0x33 };
1343         byte[] iv = { 0x04, 0x33, 0x63, 0x52, 0x5B, 0xA1, 0xAB, 0xAC };
1344         byte[] expected = { 0x07, 0x9B, 0x58, 0x27, 0xB4, 0x36, 0xDD, 0x9D, 0x7C, 0xC5, 0xE0, 0x83, 0x6A, 0x76, 0x87, 0x08, 0xF1, 0xEF, 0xCB, 0xE2, 0xA1, 0xF6, 0xA9, 0xBE };
1345
1346         SymmetricAlgorithm algo = RC2.Create ();
1347         algo.Mode = CipherMode.CBC;
1348         algo.Padding = PaddingMode.PKCS7;
1349         algo.BlockSize = 64;
1350         int blockLength = (algo.BlockSize >> 3);
1351         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1352         byte[] output = new byte [blockLength * 3];
1353         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1354         Encrypt (encryptor, input, output);
1355         AssertEquals ("RC2_k64b64_CBC_PKCS7 Encrypt", expected, output);
1356         byte[] reverse = new byte [blockLength * 3];
1357         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1358         Decrypt (decryptor, output, reverse);
1359         byte[] original = new byte [input.Length];
1360         Array.Copy (reverse, 0, original, 0, original.Length);
1361         AssertEquals ("RC2_k64b64_CBC_PKCS7 Decrypt", input, original);
1362 }
1363
1364
1365 /* Invalid parameters RC2_k64b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
1366
1367 /* Invalid parameters RC2_k64b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
1368
1369 /* Invalid parameters RC2_k64b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
1370
1371 [Test]
1372 public void TestRC2_k64b64_CFB8_None ()
1373 {
1374         byte[] key = { 0x1B, 0x23, 0x16, 0xEA, 0x19, 0xF0, 0x53, 0xEE };
1375         byte[] iv = { 0x60, 0x8D, 0x23, 0x2B, 0x0D, 0x56, 0x6F, 0x92 };
1376         byte[] expected = { 0x0C, 0xE2, 0x26, 0xA8, 0x0A, 0xB8, 0xFE, 0x03, 0x71, 0x2B, 0x56, 0x59, 0xA3, 0x45, 0xC0, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1377
1378         SymmetricAlgorithm algo = RC2.Create ();
1379         algo.Mode = CipherMode.CFB;
1380         algo.Padding = PaddingMode.None;
1381         algo.BlockSize = 64;
1382         algo.FeedbackSize = 8;
1383         int blockLength = (algo.BlockSize >> 3);
1384         byte[] input = new byte [blockLength * 2];
1385         byte[] output = new byte [blockLength * 3];
1386         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1387         Encrypt (encryptor, input, output);
1388         AssertEquals ("RC2_k64b64_CFB8_None Encrypt", expected, output);
1389         byte[] reverse = new byte [blockLength * 3];
1390         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1391         Decrypt (decryptor, output, reverse);
1392         byte[] original = new byte [input.Length];
1393         Array.Copy (reverse, 0, original, 0, original.Length);
1394         AssertEquals ("RC2_k64b64_CFB8_None Decrypt", input, original);
1395 }
1396
1397
1398 [Test]
1399 public void TestRC2_k64b64_CFB8_Zeros ()
1400 {
1401         byte[] key = { 0x49, 0xAD, 0xCD, 0xF8, 0xB6, 0x44, 0xA1, 0x86 };
1402         byte[] iv = { 0xCA, 0x6A, 0x96, 0xA8, 0x18, 0xA8, 0xF6, 0x77 };
1403         byte[] expected = { 0x12, 0x88, 0x7D, 0xC4, 0x8A, 0x04, 0x86, 0x09, 0x4A, 0x64, 0xBE, 0x31, 0xD2, 0x1F, 0xF9, 0xA1, 0x80, 0x5D, 0x0B, 0x5A, 0x01, 0x9F, 0x10, 0x6D };
1404
1405         SymmetricAlgorithm algo = RC2.Create ();
1406         algo.Mode = CipherMode.CFB;
1407         algo.Padding = PaddingMode.Zeros;
1408         algo.BlockSize = 64;
1409         algo.FeedbackSize = 8;
1410         int blockLength = (algo.BlockSize >> 3);
1411         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1412         byte[] output = new byte [blockLength * 3];
1413         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1414         Encrypt (encryptor, input, output);
1415         AssertEquals ("RC2_k64b64_CFB8_Zeros Encrypt", expected, output);
1416         byte[] reverse = new byte [blockLength * 3];
1417         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1418         Decrypt (decryptor, output, reverse);
1419         byte[] original = new byte [input.Length];
1420         Array.Copy (reverse, 0, original, 0, original.Length);
1421         AssertEquals ("RC2_k64b64_CFB8_Zeros Decrypt", input, original);
1422 }
1423
1424
1425 [Test]
1426 public void TestRC2_k64b64_CFB8_PKCS7 ()
1427 {
1428         byte[] key = { 0xF6, 0xE6, 0xA0, 0x33, 0xD3, 0x77, 0x0C, 0x28 };
1429         byte[] iv = { 0x50, 0x31, 0x14, 0xAF, 0x27, 0x92, 0xFC, 0x57 };
1430         byte[] expected = { 0xFF, 0x4B, 0xA2, 0x37, 0x56, 0xFB, 0x37, 0x4A, 0xB5, 0x6A, 0xCB, 0x27, 0x06, 0xED, 0xC2, 0x38, 0x7C, 0x4B, 0xBE, 0xC0, 0xD5, 0xD7, 0x6A, 0x79 };
1431
1432         SymmetricAlgorithm algo = RC2.Create ();
1433         algo.Mode = CipherMode.CFB;
1434         algo.Padding = PaddingMode.PKCS7;
1435         algo.BlockSize = 64;
1436         algo.FeedbackSize = 8;
1437         int blockLength = (algo.BlockSize >> 3);
1438         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1439         byte[] output = new byte [blockLength * 3];
1440         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1441         Encrypt (encryptor, input, output);
1442         AssertEquals ("RC2_k64b64_CFB8_PKCS7 Encrypt", expected, output);
1443         byte[] reverse = new byte [blockLength * 3];
1444         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1445         Decrypt (decryptor, output, reverse);
1446         byte[] original = new byte [input.Length];
1447         Array.Copy (reverse, 0, original, 0, original.Length);
1448         AssertEquals ("RC2_k64b64_CFB8_PKCS7 Decrypt", input, original);
1449 }
1450
1451
1452 /* Invalid parameters RC2_k64b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
1453
1454 /* Invalid parameters RC2_k64b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
1455
1456 /* Invalid parameters RC2_k64b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
1457
1458 [Test]
1459 public void TestRC2_k72b64_ECB_None ()
1460 {
1461         byte[] key = { 0xEC, 0x93, 0x9A, 0xF0, 0x51, 0x69, 0x59, 0x0B, 0x15 };
1462         // not used for ECB but make the code more uniform
1463         byte[] iv = { 0x36, 0xDB, 0xE8, 0x7F, 0xB5, 0x43, 0x4C, 0xF6 };
1464         byte[] expected = { 0xD6, 0x8A, 0x11, 0x59, 0x38, 0x6B, 0x93, 0x8F, 0xD6, 0x8A, 0x11, 0x59, 0x38, 0x6B, 0x93, 0x8F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1465
1466         SymmetricAlgorithm algo = RC2.Create ();
1467         algo.Mode = CipherMode.ECB;
1468         algo.Padding = PaddingMode.None;
1469         algo.BlockSize = 64;
1470         int blockLength = (algo.BlockSize >> 3);
1471         byte[] input = new byte [blockLength * 2];
1472         byte[] output = new byte [blockLength * 3];
1473         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1474         Encrypt (encryptor, input, output);
1475         AssertEquals ("RC2_k72b64_ECB_None Encrypt", expected, output);
1476
1477         // in ECB the first 2 blocks should be equals (as the IV is not used)
1478         byte[] block1 = new byte[blockLength];
1479         Array.Copy (output, 0, block1, 0, blockLength);
1480         byte[] block2 = new byte[blockLength];
1481         Array.Copy (output, blockLength, block2, 0, blockLength);
1482         AssertEquals ("RC2_k72b64_ECB_None b1==b2", block1, block2);
1483         byte[] reverse = new byte [blockLength * 3];
1484         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1485         Decrypt (decryptor, output, reverse);
1486         byte[] original = new byte [input.Length];
1487         Array.Copy (reverse, 0, original, 0, original.Length);
1488         AssertEquals ("RC2_k72b64_ECB_None Decrypt", input, original);
1489 }
1490
1491
1492 [Test]
1493 public void TestRC2_k72b64_ECB_Zeros ()
1494 {
1495         byte[] key = { 0x19, 0x14, 0x2D, 0xF6, 0x48, 0xED, 0x5A, 0xF3, 0x1F };
1496         // not used for ECB but make the code more uniform
1497         byte[] iv = { 0x8C, 0x1D, 0x0D, 0xC7, 0xE3, 0x77, 0x68, 0x40 };
1498         byte[] expected = { 0x38, 0xD4, 0x18, 0x61, 0xF6, 0x8E, 0x55, 0xD7, 0x38, 0xD4, 0x18, 0x61, 0xF6, 0x8E, 0x55, 0xD7, 0x38, 0xD4, 0x18, 0x61, 0xF6, 0x8E, 0x55, 0xD7 };
1499
1500         SymmetricAlgorithm algo = RC2.Create ();
1501         algo.Mode = CipherMode.ECB;
1502         algo.Padding = PaddingMode.Zeros;
1503         algo.BlockSize = 64;
1504         int blockLength = (algo.BlockSize >> 3);
1505         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1506         byte[] output = new byte [blockLength * 3];
1507         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1508         Encrypt (encryptor, input, output);
1509         AssertEquals ("RC2_k72b64_ECB_Zeros Encrypt", expected, output);
1510
1511         // in ECB the first 2 blocks should be equals (as the IV is not used)
1512         byte[] block1 = new byte[blockLength];
1513         Array.Copy (output, 0, block1, 0, blockLength);
1514         byte[] block2 = new byte[blockLength];
1515         Array.Copy (output, blockLength, block2, 0, blockLength);
1516         AssertEquals ("RC2_k72b64_ECB_Zeros b1==b2", block1, block2);
1517
1518         // also if padding is Zeros then all three blocks should be equals
1519         byte[] block3 = new byte[blockLength];
1520         Array.Copy (output, blockLength, block3, 0, blockLength);
1521         AssertEquals ("RC2_k72b64_ECB_Zeros b1==b3", block1, block3);
1522
1523         byte[] reverse = new byte [blockLength * 3];
1524         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1525         Decrypt (decryptor, output, reverse);
1526         byte[] original = new byte [input.Length];
1527         Array.Copy (reverse, 0, original, 0, original.Length);
1528         AssertEquals ("RC2_k72b64_ECB_Zeros Decrypt", input, original);
1529 }
1530
1531
1532 [Test]
1533 public void TestRC2_k72b64_ECB_PKCS7 ()
1534 {
1535         byte[] key = { 0x1C, 0xAA, 0x46, 0xE7, 0x37, 0x23, 0x14, 0xC9, 0x31 };
1536         // not used for ECB but make the code more uniform
1537         byte[] iv = { 0x3B, 0x0B, 0x1D, 0xE0, 0x3A, 0x6E, 0xF3, 0x1C };
1538         byte[] expected = { 0x71, 0x04, 0xA2, 0x66, 0xFC, 0xB9, 0x0F, 0x48, 0x71, 0x04, 0xA2, 0x66, 0xFC, 0xB9, 0x0F, 0x48, 0xFA, 0xF7, 0x6F, 0xA9, 0xA0, 0x23, 0xF8, 0x7E };
1539
1540         SymmetricAlgorithm algo = RC2.Create ();
1541         algo.Mode = CipherMode.ECB;
1542         algo.Padding = PaddingMode.PKCS7;
1543         algo.BlockSize = 64;
1544         int blockLength = (algo.BlockSize >> 3);
1545         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1546         byte[] output = new byte [blockLength * 3];
1547         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1548         Encrypt (encryptor, input, output);
1549         AssertEquals ("RC2_k72b64_ECB_PKCS7 Encrypt", expected, output);
1550
1551         // in ECB the first 2 blocks should be equals (as the IV is not used)
1552         byte[] block1 = new byte[blockLength];
1553         Array.Copy (output, 0, block1, 0, blockLength);
1554         byte[] block2 = new byte[blockLength];
1555         Array.Copy (output, blockLength, block2, 0, blockLength);
1556         AssertEquals ("RC2_k72b64_ECB_PKCS7 b1==b2", block1, block2);
1557         byte[] reverse = new byte [blockLength * 3];
1558         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1559         Decrypt (decryptor, output, reverse);
1560         byte[] original = new byte [input.Length];
1561         Array.Copy (reverse, 0, original, 0, original.Length);
1562         AssertEquals ("RC2_k72b64_ECB_PKCS7 Decrypt", input, original);
1563 }
1564
1565
1566 [Test]
1567 public void TestRC2_k72b64_CBC_None ()
1568 {
1569         byte[] key = { 0xF7, 0x60, 0xC5, 0x87, 0x4E, 0x36, 0xCE, 0x3C, 0xE6 };
1570         byte[] iv = { 0x60, 0x0E, 0xAC, 0x58, 0x1C, 0x91, 0x1D, 0xAC };
1571         byte[] expected = { 0xF7, 0xFE, 0xC3, 0x0E, 0x68, 0x6C, 0x15, 0x38, 0xDC, 0x06, 0xD9, 0x3A, 0x02, 0x08, 0xE2, 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1572
1573         SymmetricAlgorithm algo = RC2.Create ();
1574         algo.Mode = CipherMode.CBC;
1575         algo.Padding = PaddingMode.None;
1576         algo.BlockSize = 64;
1577         int blockLength = (algo.BlockSize >> 3);
1578         byte[] input = new byte [blockLength * 2];
1579         byte[] output = new byte [blockLength * 3];
1580         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1581         Encrypt (encryptor, input, output);
1582         AssertEquals ("RC2_k72b64_CBC_None Encrypt", expected, output);
1583         byte[] reverse = new byte [blockLength * 3];
1584         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1585         Decrypt (decryptor, output, reverse);
1586         byte[] original = new byte [input.Length];
1587         Array.Copy (reverse, 0, original, 0, original.Length);
1588         AssertEquals ("RC2_k72b64_CBC_None Decrypt", input, original);
1589 }
1590
1591
1592 [Test]
1593 public void TestRC2_k72b64_CBC_Zeros ()
1594 {
1595         byte[] key = { 0xD2, 0x3C, 0xD2, 0x40, 0xF1, 0x1D, 0x2E, 0xF4, 0x92 };
1596         byte[] iv = { 0xBE, 0x7C, 0xF7, 0xBE, 0x35, 0x11, 0x94, 0x46 };
1597         byte[] expected = { 0x7B, 0x6C, 0x73, 0xE4, 0x19, 0x69, 0x32, 0x61, 0x48, 0xE0, 0x21, 0x03, 0xAF, 0xC4, 0x54, 0x61, 0xE7, 0xB7, 0x00, 0x55, 0xDB, 0x57, 0x3C, 0x40 };
1598
1599         SymmetricAlgorithm algo = RC2.Create ();
1600         algo.Mode = CipherMode.CBC;
1601         algo.Padding = PaddingMode.Zeros;
1602         algo.BlockSize = 64;
1603         int blockLength = (algo.BlockSize >> 3);
1604         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1605         byte[] output = new byte [blockLength * 3];
1606         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1607         Encrypt (encryptor, input, output);
1608         AssertEquals ("RC2_k72b64_CBC_Zeros Encrypt", expected, output);
1609         byte[] reverse = new byte [blockLength * 3];
1610         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1611         Decrypt (decryptor, output, reverse);
1612         byte[] original = new byte [input.Length];
1613         Array.Copy (reverse, 0, original, 0, original.Length);
1614         AssertEquals ("RC2_k72b64_CBC_Zeros Decrypt", input, original);
1615 }
1616
1617
1618 [Test]
1619 public void TestRC2_k72b64_CBC_PKCS7 ()
1620 {
1621         byte[] key = { 0xE6, 0x09, 0x99, 0x96, 0x84, 0x2D, 0x9B, 0xE9, 0x34 };
1622         byte[] iv = { 0x00, 0xE9, 0x3B, 0x59, 0x6C, 0x5E, 0xF3, 0x8A };
1623         byte[] expected = { 0xA9, 0x4E, 0x30, 0x5F, 0xEF, 0xF5, 0x77, 0xC5, 0x26, 0x96, 0xDA, 0x3E, 0x53, 0xF5, 0xCB, 0xEC, 0xBC, 0xF9, 0x85, 0x00, 0xF2, 0x0D, 0x32, 0x2D };
1624
1625         SymmetricAlgorithm algo = RC2.Create ();
1626         algo.Mode = CipherMode.CBC;
1627         algo.Padding = PaddingMode.PKCS7;
1628         algo.BlockSize = 64;
1629         int blockLength = (algo.BlockSize >> 3);
1630         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1631         byte[] output = new byte [blockLength * 3];
1632         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1633         Encrypt (encryptor, input, output);
1634         AssertEquals ("RC2_k72b64_CBC_PKCS7 Encrypt", expected, output);
1635         byte[] reverse = new byte [blockLength * 3];
1636         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1637         Decrypt (decryptor, output, reverse);
1638         byte[] original = new byte [input.Length];
1639         Array.Copy (reverse, 0, original, 0, original.Length);
1640         AssertEquals ("RC2_k72b64_CBC_PKCS7 Decrypt", input, original);
1641 }
1642
1643
1644 /* Invalid parameters RC2_k72b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
1645
1646 /* Invalid parameters RC2_k72b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
1647
1648 /* Invalid parameters RC2_k72b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
1649
1650 [Test]
1651 public void TestRC2_k72b64_CFB8_None ()
1652 {
1653         byte[] key = { 0x65, 0x6B, 0x23, 0x3F, 0xB3, 0xE5, 0x6F, 0x30, 0x01 };
1654         byte[] iv = { 0x10, 0x16, 0x28, 0x20, 0xAB, 0x77, 0x74, 0x46 };
1655         byte[] expected = { 0x5A, 0x35, 0x9B, 0x9E, 0x7A, 0xD6, 0xED, 0x1D, 0x36, 0xC9, 0x95, 0x0E, 0x04, 0xE1, 0x9C, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1656
1657         SymmetricAlgorithm algo = RC2.Create ();
1658         algo.Mode = CipherMode.CFB;
1659         algo.Padding = PaddingMode.None;
1660         algo.BlockSize = 64;
1661         algo.FeedbackSize = 8;
1662         int blockLength = (algo.BlockSize >> 3);
1663         byte[] input = new byte [blockLength * 2];
1664         byte[] output = new byte [blockLength * 3];
1665         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1666         Encrypt (encryptor, input, output);
1667         AssertEquals ("RC2_k72b64_CFB8_None Encrypt", expected, output);
1668         byte[] reverse = new byte [blockLength * 3];
1669         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1670         Decrypt (decryptor, output, reverse);
1671         byte[] original = new byte [input.Length];
1672         Array.Copy (reverse, 0, original, 0, original.Length);
1673         AssertEquals ("RC2_k72b64_CFB8_None Decrypt", input, original);
1674 }
1675
1676
1677 [Test]
1678 public void TestRC2_k72b64_CFB8_Zeros ()
1679 {
1680         byte[] key = { 0x87, 0xC1, 0x80, 0x41, 0xD6, 0xF1, 0x33, 0xC7, 0x78 };
1681         byte[] iv = { 0x21, 0x55, 0xCF, 0x6E, 0xF5, 0x3B, 0xF0, 0x6B };
1682         byte[] expected = { 0x83, 0xFC, 0xD7, 0x43, 0xC0, 0x4F, 0x9F, 0xE0, 0x60, 0xAD, 0x3B, 0x0D, 0x5A, 0xF3, 0xF3, 0x0B, 0x96, 0x25, 0x97, 0x6D, 0x58, 0x8B, 0x5A, 0x26 };
1683
1684         SymmetricAlgorithm algo = RC2.Create ();
1685         algo.Mode = CipherMode.CFB;
1686         algo.Padding = PaddingMode.Zeros;
1687         algo.BlockSize = 64;
1688         algo.FeedbackSize = 8;
1689         int blockLength = (algo.BlockSize >> 3);
1690         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1691         byte[] output = new byte [blockLength * 3];
1692         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1693         Encrypt (encryptor, input, output);
1694         AssertEquals ("RC2_k72b64_CFB8_Zeros Encrypt", expected, output);
1695         byte[] reverse = new byte [blockLength * 3];
1696         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1697         Decrypt (decryptor, output, reverse);
1698         byte[] original = new byte [input.Length];
1699         Array.Copy (reverse, 0, original, 0, original.Length);
1700         AssertEquals ("RC2_k72b64_CFB8_Zeros Decrypt", input, original);
1701 }
1702
1703
1704 [Test]
1705 public void TestRC2_k72b64_CFB8_PKCS7 ()
1706 {
1707         byte[] key = { 0xAE, 0xE0, 0x44, 0x66, 0xDA, 0x34, 0xFD, 0xD4, 0x71 };
1708         byte[] iv = { 0xFA, 0x66, 0x5F, 0x55, 0xBC, 0x1B, 0xC7, 0x83 };
1709         byte[] expected = { 0xF3, 0xAB, 0x63, 0x11, 0xA0, 0x27, 0x05, 0x42, 0x0A, 0xCD, 0x16, 0xCA, 0x22, 0x4E, 0x0B, 0xCB, 0x96, 0xCA, 0xD9, 0x38, 0x6D, 0x5E, 0x5E, 0x55 };
1710
1711         SymmetricAlgorithm algo = RC2.Create ();
1712         algo.Mode = CipherMode.CFB;
1713         algo.Padding = PaddingMode.PKCS7;
1714         algo.BlockSize = 64;
1715         algo.FeedbackSize = 8;
1716         int blockLength = (algo.BlockSize >> 3);
1717         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1718         byte[] output = new byte [blockLength * 3];
1719         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1720         Encrypt (encryptor, input, output);
1721         AssertEquals ("RC2_k72b64_CFB8_PKCS7 Encrypt", expected, output);
1722         byte[] reverse = new byte [blockLength * 3];
1723         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1724         Decrypt (decryptor, output, reverse);
1725         byte[] original = new byte [input.Length];
1726         Array.Copy (reverse, 0, original, 0, original.Length);
1727         AssertEquals ("RC2_k72b64_CFB8_PKCS7 Decrypt", input, original);
1728 }
1729
1730
1731 /* Invalid parameters RC2_k72b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
1732
1733 /* Invalid parameters RC2_k72b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
1734
1735 /* Invalid parameters RC2_k72b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
1736
1737 [Test]
1738 public void TestRC2_k80b64_ECB_None ()
1739 {
1740         byte[] key = { 0xB8, 0xA4, 0x76, 0xF8, 0x59, 0x86, 0x40, 0x53, 0x33, 0x68 };
1741         // not used for ECB but make the code more uniform
1742         byte[] iv = { 0xFF, 0x5F, 0x8B, 0x5E, 0xCF, 0xB8, 0xA5, 0xCB };
1743         byte[] expected = { 0x7A, 0x56, 0x73, 0x0A, 0x72, 0x69, 0x95, 0x16, 0x7A, 0x56, 0x73, 0x0A, 0x72, 0x69, 0x95, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1744
1745         SymmetricAlgorithm algo = RC2.Create ();
1746         algo.Mode = CipherMode.ECB;
1747         algo.Padding = PaddingMode.None;
1748         algo.BlockSize = 64;
1749         int blockLength = (algo.BlockSize >> 3);
1750         byte[] input = new byte [blockLength * 2];
1751         byte[] output = new byte [blockLength * 3];
1752         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1753         Encrypt (encryptor, input, output);
1754         AssertEquals ("RC2_k80b64_ECB_None Encrypt", expected, output);
1755
1756         // in ECB the first 2 blocks should be equals (as the IV is not used)
1757         byte[] block1 = new byte[blockLength];
1758         Array.Copy (output, 0, block1, 0, blockLength);
1759         byte[] block2 = new byte[blockLength];
1760         Array.Copy (output, blockLength, block2, 0, blockLength);
1761         AssertEquals ("RC2_k80b64_ECB_None b1==b2", block1, block2);
1762         byte[] reverse = new byte [blockLength * 3];
1763         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1764         Decrypt (decryptor, output, reverse);
1765         byte[] original = new byte [input.Length];
1766         Array.Copy (reverse, 0, original, 0, original.Length);
1767         AssertEquals ("RC2_k80b64_ECB_None Decrypt", input, original);
1768 }
1769
1770
1771 [Test]
1772 public void TestRC2_k80b64_ECB_Zeros ()
1773 {
1774         byte[] key = { 0x9A, 0xE1, 0xE1, 0x17, 0xCB, 0x2B, 0x9C, 0x5D, 0x5D, 0x28 };
1775         // not used for ECB but make the code more uniform
1776         byte[] iv = { 0x71, 0x29, 0x89, 0x9C, 0x66, 0xF5, 0x90, 0x63 };
1777         byte[] expected = { 0x38, 0x83, 0x30, 0xE0, 0xC6, 0x8A, 0x0B, 0x11, 0x38, 0x83, 0x30, 0xE0, 0xC6, 0x8A, 0x0B, 0x11, 0x38, 0x83, 0x30, 0xE0, 0xC6, 0x8A, 0x0B, 0x11 };
1778
1779         SymmetricAlgorithm algo = RC2.Create ();
1780         algo.Mode = CipherMode.ECB;
1781         algo.Padding = PaddingMode.Zeros;
1782         algo.BlockSize = 64;
1783         int blockLength = (algo.BlockSize >> 3);
1784         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1785         byte[] output = new byte [blockLength * 3];
1786         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1787         Encrypt (encryptor, input, output);
1788         AssertEquals ("RC2_k80b64_ECB_Zeros Encrypt", expected, output);
1789
1790         // in ECB the first 2 blocks should be equals (as the IV is not used)
1791         byte[] block1 = new byte[blockLength];
1792         Array.Copy (output, 0, block1, 0, blockLength);
1793         byte[] block2 = new byte[blockLength];
1794         Array.Copy (output, blockLength, block2, 0, blockLength);
1795         AssertEquals ("RC2_k80b64_ECB_Zeros b1==b2", block1, block2);
1796
1797         // also if padding is Zeros then all three blocks should be equals
1798         byte[] block3 = new byte[blockLength];
1799         Array.Copy (output, blockLength, block3, 0, blockLength);
1800         AssertEquals ("RC2_k80b64_ECB_Zeros b1==b3", block1, block3);
1801
1802         byte[] reverse = new byte [blockLength * 3];
1803         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1804         Decrypt (decryptor, output, reverse);
1805         byte[] original = new byte [input.Length];
1806         Array.Copy (reverse, 0, original, 0, original.Length);
1807         AssertEquals ("RC2_k80b64_ECB_Zeros Decrypt", input, original);
1808 }
1809
1810
1811 [Test]
1812 public void TestRC2_k80b64_ECB_PKCS7 ()
1813 {
1814         byte[] key = { 0x8D, 0xF8, 0xDA, 0xA2, 0x31, 0xEA, 0x86, 0x92, 0x52, 0xBB };
1815         // not used for ECB but make the code more uniform
1816         byte[] iv = { 0xD3, 0x1C, 0x57, 0x72, 0xDE, 0xFD, 0xCA, 0xC7 };
1817         byte[] expected = { 0x51, 0xD4, 0x00, 0x54, 0x58, 0xE5, 0xED, 0x5C, 0x51, 0xD4, 0x00, 0x54, 0x58, 0xE5, 0xED, 0x5C, 0xCE, 0xF6, 0xDB, 0x31, 0x10, 0xE9, 0x0E, 0xD8 };
1818
1819         SymmetricAlgorithm algo = RC2.Create ();
1820         algo.Mode = CipherMode.ECB;
1821         algo.Padding = PaddingMode.PKCS7;
1822         algo.BlockSize = 64;
1823         int blockLength = (algo.BlockSize >> 3);
1824         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1825         byte[] output = new byte [blockLength * 3];
1826         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1827         Encrypt (encryptor, input, output);
1828         AssertEquals ("RC2_k80b64_ECB_PKCS7 Encrypt", expected, output);
1829
1830         // in ECB the first 2 blocks should be equals (as the IV is not used)
1831         byte[] block1 = new byte[blockLength];
1832         Array.Copy (output, 0, block1, 0, blockLength);
1833         byte[] block2 = new byte[blockLength];
1834         Array.Copy (output, blockLength, block2, 0, blockLength);
1835         AssertEquals ("RC2_k80b64_ECB_PKCS7 b1==b2", block1, block2);
1836         byte[] reverse = new byte [blockLength * 3];
1837         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1838         Decrypt (decryptor, output, reverse);
1839         byte[] original = new byte [input.Length];
1840         Array.Copy (reverse, 0, original, 0, original.Length);
1841         AssertEquals ("RC2_k80b64_ECB_PKCS7 Decrypt", input, original);
1842 }
1843
1844
1845 [Test]
1846 public void TestRC2_k80b64_CBC_None ()
1847 {
1848         byte[] key = { 0x5B, 0x45, 0x99, 0x10, 0x47, 0x42, 0x89, 0xC8, 0x2A, 0x6C };
1849         byte[] iv = { 0xE4, 0x8F, 0x2A, 0x4D, 0x25, 0x38, 0x01, 0x04 };
1850         byte[] expected = { 0xA3, 0x23, 0xE7, 0xCD, 0xC1, 0x5E, 0x4E, 0x1D, 0x2F, 0x7F, 0x8B, 0xA7, 0xD0, 0x42, 0xF2, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1851
1852         SymmetricAlgorithm algo = RC2.Create ();
1853         algo.Mode = CipherMode.CBC;
1854         algo.Padding = PaddingMode.None;
1855         algo.BlockSize = 64;
1856         int blockLength = (algo.BlockSize >> 3);
1857         byte[] input = new byte [blockLength * 2];
1858         byte[] output = new byte [blockLength * 3];
1859         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1860         Encrypt (encryptor, input, output);
1861         AssertEquals ("RC2_k80b64_CBC_None Encrypt", expected, output);
1862         byte[] reverse = new byte [blockLength * 3];
1863         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1864         Decrypt (decryptor, output, reverse);
1865         byte[] original = new byte [input.Length];
1866         Array.Copy (reverse, 0, original, 0, original.Length);
1867         AssertEquals ("RC2_k80b64_CBC_None Decrypt", input, original);
1868 }
1869
1870
1871 [Test]
1872 public void TestRC2_k80b64_CBC_Zeros ()
1873 {
1874         byte[] key = { 0xD4, 0x47, 0xFF, 0x5A, 0x70, 0xE8, 0x48, 0x0F, 0x23, 0xD1 };
1875         byte[] iv = { 0x8B, 0xF8, 0x94, 0x02, 0xB3, 0xFB, 0xB0, 0x0D };
1876         byte[] expected = { 0x88, 0x5C, 0x72, 0x4C, 0x35, 0x7F, 0x73, 0x1C, 0x8A, 0x06, 0x6B, 0x90, 0x82, 0xC5, 0xBC, 0x46, 0x75, 0xC1, 0x87, 0xD9, 0xED, 0x29, 0x1D, 0xB8 };
1877
1878         SymmetricAlgorithm algo = RC2.Create ();
1879         algo.Mode = CipherMode.CBC;
1880         algo.Padding = PaddingMode.Zeros;
1881         algo.BlockSize = 64;
1882         int blockLength = (algo.BlockSize >> 3);
1883         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1884         byte[] output = new byte [blockLength * 3];
1885         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1886         Encrypt (encryptor, input, output);
1887         AssertEquals ("RC2_k80b64_CBC_Zeros Encrypt", expected, output);
1888         byte[] reverse = new byte [blockLength * 3];
1889         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1890         Decrypt (decryptor, output, reverse);
1891         byte[] original = new byte [input.Length];
1892         Array.Copy (reverse, 0, original, 0, original.Length);
1893         AssertEquals ("RC2_k80b64_CBC_Zeros Decrypt", input, original);
1894 }
1895
1896
1897 [Test]
1898 public void TestRC2_k80b64_CBC_PKCS7 ()
1899 {
1900         byte[] key = { 0x8D, 0x77, 0xC5, 0x6E, 0xC2, 0x8F, 0x10, 0x51, 0xD2, 0x20 };
1901         byte[] iv = { 0x43, 0xC5, 0x4E, 0x58, 0xF0, 0xD7, 0xB3, 0x92 };
1902         byte[] expected = { 0xE9, 0xB0, 0x67, 0x7C, 0x6C, 0x77, 0x68, 0x4D, 0xD0, 0xA5, 0x93, 0x9F, 0x84, 0xE0, 0xA0, 0xA9, 0x36, 0x21, 0xD7, 0x07, 0x0B, 0x8D, 0xD7, 0xB9 };
1903
1904         SymmetricAlgorithm algo = RC2.Create ();
1905         algo.Mode = CipherMode.CBC;
1906         algo.Padding = PaddingMode.PKCS7;
1907         algo.BlockSize = 64;
1908         int blockLength = (algo.BlockSize >> 3);
1909         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1910         byte[] output = new byte [blockLength * 3];
1911         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1912         Encrypt (encryptor, input, output);
1913         AssertEquals ("RC2_k80b64_CBC_PKCS7 Encrypt", expected, output);
1914         byte[] reverse = new byte [blockLength * 3];
1915         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1916         Decrypt (decryptor, output, reverse);
1917         byte[] original = new byte [input.Length];
1918         Array.Copy (reverse, 0, original, 0, original.Length);
1919         AssertEquals ("RC2_k80b64_CBC_PKCS7 Decrypt", input, original);
1920 }
1921
1922
1923 /* Invalid parameters RC2_k80b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
1924
1925 /* Invalid parameters RC2_k80b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
1926
1927 /* Invalid parameters RC2_k80b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
1928
1929 [Test]
1930 public void TestRC2_k80b64_CFB8_None ()
1931 {
1932         byte[] key = { 0x2A, 0x44, 0xD9, 0x1C, 0x5E, 0x7C, 0x79, 0x3D, 0x88, 0x55 };
1933         byte[] iv = { 0xA0, 0x48, 0x00, 0x04, 0xA8, 0xB8, 0x83, 0x9F };
1934         byte[] expected = { 0xEA, 0xD0, 0x3D, 0x9A, 0x62, 0xEA, 0x9C, 0x59, 0xAC, 0xD4, 0xA1, 0xDE, 0xDB, 0x3D, 0xF8, 0x4E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1935
1936         SymmetricAlgorithm algo = RC2.Create ();
1937         algo.Mode = CipherMode.CFB;
1938         algo.Padding = PaddingMode.None;
1939         algo.BlockSize = 64;
1940         algo.FeedbackSize = 8;
1941         int blockLength = (algo.BlockSize >> 3);
1942         byte[] input = new byte [blockLength * 2];
1943         byte[] output = new byte [blockLength * 3];
1944         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1945         Encrypt (encryptor, input, output);
1946         AssertEquals ("RC2_k80b64_CFB8_None Encrypt", expected, output);
1947         byte[] reverse = new byte [blockLength * 3];
1948         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1949         Decrypt (decryptor, output, reverse);
1950         byte[] original = new byte [input.Length];
1951         Array.Copy (reverse, 0, original, 0, original.Length);
1952         AssertEquals ("RC2_k80b64_CFB8_None Decrypt", input, original);
1953 }
1954
1955
1956 [Test]
1957 public void TestRC2_k80b64_CFB8_Zeros ()
1958 {
1959         byte[] key = { 0x30, 0x51, 0xCD, 0x3B, 0x8A, 0x8A, 0x8C, 0xF4, 0x76, 0x64 };
1960         byte[] iv = { 0xD9, 0x5F, 0xEB, 0x11, 0x8F, 0x0A, 0x7D, 0xDC };
1961         byte[] expected = { 0x02, 0xB4, 0x0F, 0xB5, 0x79, 0x81, 0xAC, 0xFD, 0xBA, 0x40, 0xF1, 0x61, 0x96, 0x70, 0x09, 0x5B, 0xFF, 0x0D, 0x90, 0xB4, 0x54, 0x27, 0x4A, 0x3C };
1962
1963         SymmetricAlgorithm algo = RC2.Create ();
1964         algo.Mode = CipherMode.CFB;
1965         algo.Padding = PaddingMode.Zeros;
1966         algo.BlockSize = 64;
1967         algo.FeedbackSize = 8;
1968         int blockLength = (algo.BlockSize >> 3);
1969         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1970         byte[] output = new byte [blockLength * 3];
1971         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1972         Encrypt (encryptor, input, output);
1973         AssertEquals ("RC2_k80b64_CFB8_Zeros Encrypt", expected, output);
1974         byte[] reverse = new byte [blockLength * 3];
1975         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1976         Decrypt (decryptor, output, reverse);
1977         byte[] original = new byte [input.Length];
1978         Array.Copy (reverse, 0, original, 0, original.Length);
1979         AssertEquals ("RC2_k80b64_CFB8_Zeros Decrypt", input, original);
1980 }
1981
1982
1983 [Test]
1984 public void TestRC2_k80b64_CFB8_PKCS7 ()
1985 {
1986         byte[] key = { 0xA7, 0x24, 0xA0, 0x14, 0x78, 0xDC, 0x8B, 0x99, 0x77, 0xCD };
1987         byte[] iv = { 0xB8, 0x68, 0xD0, 0x5A, 0x13, 0x3C, 0xBA, 0x59 };
1988         byte[] expected = { 0x3B, 0x35, 0xF6, 0x3F, 0x36, 0x7B, 0xF1, 0x7D, 0xCE, 0xC8, 0x62, 0xF8, 0x34, 0xC6, 0x42, 0x6F, 0x77, 0xCF, 0x32, 0x41, 0xF3, 0x0B, 0x28, 0x37 };
1989
1990         SymmetricAlgorithm algo = RC2.Create ();
1991         algo.Mode = CipherMode.CFB;
1992         algo.Padding = PaddingMode.PKCS7;
1993         algo.BlockSize = 64;
1994         algo.FeedbackSize = 8;
1995         int blockLength = (algo.BlockSize >> 3);
1996         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1997         byte[] output = new byte [blockLength * 3];
1998         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1999         Encrypt (encryptor, input, output);
2000         AssertEquals ("RC2_k80b64_CFB8_PKCS7 Encrypt", expected, output);
2001         byte[] reverse = new byte [blockLength * 3];
2002         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2003         Decrypt (decryptor, output, reverse);
2004         byte[] original = new byte [input.Length];
2005         Array.Copy (reverse, 0, original, 0, original.Length);
2006         AssertEquals ("RC2_k80b64_CFB8_PKCS7 Decrypt", input, original);
2007 }
2008
2009
2010 /* Invalid parameters RC2_k80b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
2011
2012 /* Invalid parameters RC2_k80b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
2013
2014 /* Invalid parameters RC2_k80b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
2015
2016 [Test]
2017 public void TestRC2_k88b64_ECB_None ()
2018 {
2019         byte[] key = { 0xCE, 0x12, 0x59, 0x88, 0x7A, 0xCD, 0x57, 0x4C, 0xCD, 0xA9, 0xD2 };
2020         // not used for ECB but make the code more uniform
2021         byte[] iv = { 0x91, 0x4C, 0x2D, 0xB4, 0x6E, 0x19, 0x3F, 0x6F };
2022         byte[] expected = { 0x74, 0x25, 0xAD, 0x2E, 0x88, 0xA9, 0x3E, 0x1F, 0x74, 0x25, 0xAD, 0x2E, 0x88, 0xA9, 0x3E, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2023
2024         SymmetricAlgorithm algo = RC2.Create ();
2025         algo.Mode = CipherMode.ECB;
2026         algo.Padding = PaddingMode.None;
2027         algo.BlockSize = 64;
2028         int blockLength = (algo.BlockSize >> 3);
2029         byte[] input = new byte [blockLength * 2];
2030         byte[] output = new byte [blockLength * 3];
2031         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2032         Encrypt (encryptor, input, output);
2033         AssertEquals ("RC2_k88b64_ECB_None Encrypt", expected, output);
2034
2035         // in ECB the first 2 blocks should be equals (as the IV is not used)
2036         byte[] block1 = new byte[blockLength];
2037         Array.Copy (output, 0, block1, 0, blockLength);
2038         byte[] block2 = new byte[blockLength];
2039         Array.Copy (output, blockLength, block2, 0, blockLength);
2040         AssertEquals ("RC2_k88b64_ECB_None b1==b2", block1, block2);
2041         byte[] reverse = new byte [blockLength * 3];
2042         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2043         Decrypt (decryptor, output, reverse);
2044         byte[] original = new byte [input.Length];
2045         Array.Copy (reverse, 0, original, 0, original.Length);
2046         AssertEquals ("RC2_k88b64_ECB_None Decrypt", input, original);
2047 }
2048
2049
2050 [Test]
2051 public void TestRC2_k88b64_ECB_Zeros ()
2052 {
2053         byte[] key = { 0x28, 0xDC, 0x09, 0x80, 0x85, 0x25, 0x95, 0x41, 0x7B, 0xD4, 0x06 };
2054         // not used for ECB but make the code more uniform
2055         byte[] iv = { 0xAE, 0x0D, 0xC1, 0x42, 0x01, 0x1C, 0x6E, 0x5A };
2056         byte[] expected = { 0x48, 0xD6, 0x9F, 0x9A, 0x7C, 0x93, 0x89, 0x5F, 0x48, 0xD6, 0x9F, 0x9A, 0x7C, 0x93, 0x89, 0x5F, 0x48, 0xD6, 0x9F, 0x9A, 0x7C, 0x93, 0x89, 0x5F };
2057
2058         SymmetricAlgorithm algo = RC2.Create ();
2059         algo.Mode = CipherMode.ECB;
2060         algo.Padding = PaddingMode.Zeros;
2061         algo.BlockSize = 64;
2062         int blockLength = (algo.BlockSize >> 3);
2063         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2064         byte[] output = new byte [blockLength * 3];
2065         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2066         Encrypt (encryptor, input, output);
2067         AssertEquals ("RC2_k88b64_ECB_Zeros Encrypt", expected, output);
2068
2069         // in ECB the first 2 blocks should be equals (as the IV is not used)
2070         byte[] block1 = new byte[blockLength];
2071         Array.Copy (output, 0, block1, 0, blockLength);
2072         byte[] block2 = new byte[blockLength];
2073         Array.Copy (output, blockLength, block2, 0, blockLength);
2074         AssertEquals ("RC2_k88b64_ECB_Zeros b1==b2", block1, block2);
2075
2076         // also if padding is Zeros then all three blocks should be equals
2077         byte[] block3 = new byte[blockLength];
2078         Array.Copy (output, blockLength, block3, 0, blockLength);
2079         AssertEquals ("RC2_k88b64_ECB_Zeros b1==b3", block1, block3);
2080
2081         byte[] reverse = new byte [blockLength * 3];
2082         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2083         Decrypt (decryptor, output, reverse);
2084         byte[] original = new byte [input.Length];
2085         Array.Copy (reverse, 0, original, 0, original.Length);
2086         AssertEquals ("RC2_k88b64_ECB_Zeros Decrypt", input, original);
2087 }
2088
2089
2090 [Test]
2091 public void TestRC2_k88b64_ECB_PKCS7 ()
2092 {
2093         byte[] key = { 0xAB, 0x26, 0x7E, 0xD3, 0x3A, 0x0A, 0x3F, 0x50, 0x0B, 0x84, 0x5F };
2094         // not used for ECB but make the code more uniform
2095         byte[] iv = { 0x28, 0x3C, 0x18, 0x06, 0x3C, 0xF7, 0x83, 0x51 };
2096         byte[] expected = { 0xE0, 0x60, 0x29, 0xC5, 0xE5, 0xFE, 0x75, 0x95, 0xE0, 0x60, 0x29, 0xC5, 0xE5, 0xFE, 0x75, 0x95, 0xE8, 0x61, 0x0A, 0x2A, 0x79, 0x3F, 0x0A, 0xB7 };
2097
2098         SymmetricAlgorithm algo = RC2.Create ();
2099         algo.Mode = CipherMode.ECB;
2100         algo.Padding = PaddingMode.PKCS7;
2101         algo.BlockSize = 64;
2102         int blockLength = (algo.BlockSize >> 3);
2103         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2104         byte[] output = new byte [blockLength * 3];
2105         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2106         Encrypt (encryptor, input, output);
2107         AssertEquals ("RC2_k88b64_ECB_PKCS7 Encrypt", expected, output);
2108
2109         // in ECB the first 2 blocks should be equals (as the IV is not used)
2110         byte[] block1 = new byte[blockLength];
2111         Array.Copy (output, 0, block1, 0, blockLength);
2112         byte[] block2 = new byte[blockLength];
2113         Array.Copy (output, blockLength, block2, 0, blockLength);
2114         AssertEquals ("RC2_k88b64_ECB_PKCS7 b1==b2", block1, block2);
2115         byte[] reverse = new byte [blockLength * 3];
2116         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2117         Decrypt (decryptor, output, reverse);
2118         byte[] original = new byte [input.Length];
2119         Array.Copy (reverse, 0, original, 0, original.Length);
2120         AssertEquals ("RC2_k88b64_ECB_PKCS7 Decrypt", input, original);
2121 }
2122
2123
2124 [Test]
2125 public void TestRC2_k88b64_CBC_None ()
2126 {
2127         byte[] key = { 0x01, 0x2F, 0x45, 0x5F, 0x2D, 0x9E, 0xDB, 0x29, 0x6C, 0x54, 0xF5 };
2128         byte[] iv = { 0x4C, 0x6A, 0x4D, 0x77, 0x7E, 0x34, 0xB4, 0x75 };
2129         byte[] expected = { 0x66, 0x58, 0x7F, 0xE7, 0x6D, 0x3B, 0x6A, 0x97, 0xFC, 0x65, 0x15, 0x8D, 0xAC, 0xB0, 0xB1, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2130
2131         SymmetricAlgorithm algo = RC2.Create ();
2132         algo.Mode = CipherMode.CBC;
2133         algo.Padding = PaddingMode.None;
2134         algo.BlockSize = 64;
2135         int blockLength = (algo.BlockSize >> 3);
2136         byte[] input = new byte [blockLength * 2];
2137         byte[] output = new byte [blockLength * 3];
2138         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2139         Encrypt (encryptor, input, output);
2140         AssertEquals ("RC2_k88b64_CBC_None Encrypt", expected, output);
2141         byte[] reverse = new byte [blockLength * 3];
2142         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2143         Decrypt (decryptor, output, reverse);
2144         byte[] original = new byte [input.Length];
2145         Array.Copy (reverse, 0, original, 0, original.Length);
2146         AssertEquals ("RC2_k88b64_CBC_None Decrypt", input, original);
2147 }
2148
2149
2150 [Test]
2151 public void TestRC2_k88b64_CBC_Zeros ()
2152 {
2153         byte[] key = { 0xA9, 0xD1, 0xDA, 0xCB, 0x4C, 0xA7, 0xD3, 0x35, 0x70, 0x1E, 0x15 };
2154         byte[] iv = { 0xF2, 0x17, 0x14, 0x41, 0x36, 0x58, 0x27, 0x48 };
2155         byte[] expected = { 0x41, 0xDD, 0xFE, 0x10, 0x56, 0xE2, 0x86, 0xDC, 0xC6, 0x53, 0x69, 0x1A, 0x2D, 0x66, 0x1D, 0x1C, 0xAD, 0x3C, 0x1F, 0xCE, 0xE3, 0xE2, 0x52, 0x13 };
2156
2157         SymmetricAlgorithm algo = RC2.Create ();
2158         algo.Mode = CipherMode.CBC;
2159         algo.Padding = PaddingMode.Zeros;
2160         algo.BlockSize = 64;
2161         int blockLength = (algo.BlockSize >> 3);
2162         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2163         byte[] output = new byte [blockLength * 3];
2164         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2165         Encrypt (encryptor, input, output);
2166         AssertEquals ("RC2_k88b64_CBC_Zeros Encrypt", expected, output);
2167         byte[] reverse = new byte [blockLength * 3];
2168         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2169         Decrypt (decryptor, output, reverse);
2170         byte[] original = new byte [input.Length];
2171         Array.Copy (reverse, 0, original, 0, original.Length);
2172         AssertEquals ("RC2_k88b64_CBC_Zeros Decrypt", input, original);
2173 }
2174
2175
2176 [Test]
2177 public void TestRC2_k88b64_CBC_PKCS7 ()
2178 {
2179         byte[] key = { 0x07, 0x97, 0xCB, 0xA3, 0xB6, 0xFF, 0x57, 0x30, 0x5A, 0x2E, 0x3E };
2180         byte[] iv = { 0x78, 0x44, 0xCE, 0xBA, 0xC6, 0xCD, 0x0C, 0xB7 };
2181         byte[] expected = { 0x07, 0xCC, 0xFD, 0x12, 0x0D, 0x07, 0xED, 0xB2, 0x8C, 0xDA, 0xB9, 0xC3, 0xE7, 0x04, 0x41, 0x5A, 0xA3, 0x9C, 0x50, 0x8B, 0x8F, 0x9D, 0x2E, 0x65 };
2182
2183         SymmetricAlgorithm algo = RC2.Create ();
2184         algo.Mode = CipherMode.CBC;
2185         algo.Padding = PaddingMode.PKCS7;
2186         algo.BlockSize = 64;
2187         int blockLength = (algo.BlockSize >> 3);
2188         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2189         byte[] output = new byte [blockLength * 3];
2190         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2191         Encrypt (encryptor, input, output);
2192         AssertEquals ("RC2_k88b64_CBC_PKCS7 Encrypt", expected, output);
2193         byte[] reverse = new byte [blockLength * 3];
2194         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2195         Decrypt (decryptor, output, reverse);
2196         byte[] original = new byte [input.Length];
2197         Array.Copy (reverse, 0, original, 0, original.Length);
2198         AssertEquals ("RC2_k88b64_CBC_PKCS7 Decrypt", input, original);
2199 }
2200
2201
2202 /* Invalid parameters RC2_k88b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
2203
2204 /* Invalid parameters RC2_k88b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
2205
2206 /* Invalid parameters RC2_k88b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
2207
2208 [Test]
2209 public void TestRC2_k88b64_CFB8_None ()
2210 {
2211         byte[] key = { 0x6E, 0x73, 0x03, 0xFD, 0x20, 0xAB, 0x21, 0x9D, 0x54, 0x0C, 0xB9 };
2212         byte[] iv = { 0x69, 0x6B, 0xF5, 0xD0, 0x10, 0xB5, 0xFE, 0xEF };
2213         byte[] expected = { 0x12, 0x2B, 0xF0, 0x54, 0xFF, 0x2F, 0xE2, 0xF0, 0x36, 0x9A, 0x3E, 0xFE, 0x57, 0x56, 0x0E, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2214
2215         SymmetricAlgorithm algo = RC2.Create ();
2216         algo.Mode = CipherMode.CFB;
2217         algo.Padding = PaddingMode.None;
2218         algo.BlockSize = 64;
2219         algo.FeedbackSize = 8;
2220         int blockLength = (algo.BlockSize >> 3);
2221         byte[] input = new byte [blockLength * 2];
2222         byte[] output = new byte [blockLength * 3];
2223         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2224         Encrypt (encryptor, input, output);
2225         AssertEquals ("RC2_k88b64_CFB8_None Encrypt", expected, output);
2226         byte[] reverse = new byte [blockLength * 3];
2227         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2228         Decrypt (decryptor, output, reverse);
2229         byte[] original = new byte [input.Length];
2230         Array.Copy (reverse, 0, original, 0, original.Length);
2231         AssertEquals ("RC2_k88b64_CFB8_None Decrypt", input, original);
2232 }
2233
2234
2235 [Test]
2236 public void TestRC2_k88b64_CFB8_Zeros ()
2237 {
2238         byte[] key = { 0x8B, 0x1D, 0xD0, 0x5C, 0x3E, 0xF4, 0x5B, 0xA5, 0x56, 0x87, 0xE8 };
2239         byte[] iv = { 0x14, 0x01, 0x4B, 0x90, 0x67, 0x02, 0x79, 0x3F };
2240         byte[] expected = { 0xA1, 0x7D, 0x02, 0x58, 0xBC, 0x3E, 0x56, 0x3E, 0xF6, 0x08, 0x08, 0xB0, 0xD0, 0xD1, 0xAC, 0x9F, 0x29, 0x65, 0x18, 0x76, 0x2C, 0x96, 0xCC, 0x8C };
2241
2242         SymmetricAlgorithm algo = RC2.Create ();
2243         algo.Mode = CipherMode.CFB;
2244         algo.Padding = PaddingMode.Zeros;
2245         algo.BlockSize = 64;
2246         algo.FeedbackSize = 8;
2247         int blockLength = (algo.BlockSize >> 3);
2248         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2249         byte[] output = new byte [blockLength * 3];
2250         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2251         Encrypt (encryptor, input, output);
2252         AssertEquals ("RC2_k88b64_CFB8_Zeros Encrypt", expected, output);
2253         byte[] reverse = new byte [blockLength * 3];
2254         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2255         Decrypt (decryptor, output, reverse);
2256         byte[] original = new byte [input.Length];
2257         Array.Copy (reverse, 0, original, 0, original.Length);
2258         AssertEquals ("RC2_k88b64_CFB8_Zeros Decrypt", input, original);
2259 }
2260
2261
2262 [Test]
2263 public void TestRC2_k88b64_CFB8_PKCS7 ()
2264 {
2265         byte[] key = { 0xCB, 0xD9, 0xE0, 0xD8, 0x82, 0xA0, 0x06, 0xD1, 0x6C, 0x5F, 0x8F };
2266         byte[] iv = { 0x73, 0x14, 0x81, 0x8C, 0x59, 0xE4, 0x33, 0xDF };
2267         byte[] expected = { 0x31, 0xA2, 0xA9, 0xCE, 0xAF, 0xF1, 0x8F, 0xA5, 0x02, 0xD8, 0xF5, 0xDC, 0x2C, 0x41, 0x8E, 0x64, 0x81, 0xCA, 0xBE, 0x89, 0xC3, 0x19, 0x24, 0x78 };
2268
2269         SymmetricAlgorithm algo = RC2.Create ();
2270         algo.Mode = CipherMode.CFB;
2271         algo.Padding = PaddingMode.PKCS7;
2272         algo.BlockSize = 64;
2273         algo.FeedbackSize = 8;
2274         int blockLength = (algo.BlockSize >> 3);
2275         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2276         byte[] output = new byte [blockLength * 3];
2277         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2278         Encrypt (encryptor, input, output);
2279         AssertEquals ("RC2_k88b64_CFB8_PKCS7 Encrypt", expected, output);
2280         byte[] reverse = new byte [blockLength * 3];
2281         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2282         Decrypt (decryptor, output, reverse);
2283         byte[] original = new byte [input.Length];
2284         Array.Copy (reverse, 0, original, 0, original.Length);
2285         AssertEquals ("RC2_k88b64_CFB8_PKCS7 Decrypt", input, original);
2286 }
2287
2288
2289 /* Invalid parameters RC2_k88b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
2290
2291 /* Invalid parameters RC2_k88b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
2292
2293 /* Invalid parameters RC2_k88b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
2294
2295 [Test]
2296 public void TestRC2_k96b64_ECB_None ()
2297 {
2298         byte[] key = { 0x72, 0xD8, 0x0A, 0x9D, 0xDA, 0x9D, 0xB1, 0x78, 0x61, 0x9C, 0xD8, 0x57 };
2299         // not used for ECB but make the code more uniform
2300         byte[] iv = { 0x31, 0x21, 0x9D, 0xD9, 0x12, 0x95, 0x79, 0x30 };
2301         byte[] expected = { 0x41, 0xA6, 0x5B, 0x2D, 0x51, 0x55, 0x1B, 0xE2, 0x41, 0xA6, 0x5B, 0x2D, 0x51, 0x55, 0x1B, 0xE2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2302
2303         SymmetricAlgorithm algo = RC2.Create ();
2304         algo.Mode = CipherMode.ECB;
2305         algo.Padding = PaddingMode.None;
2306         algo.BlockSize = 64;
2307         int blockLength = (algo.BlockSize >> 3);
2308         byte[] input = new byte [blockLength * 2];
2309         byte[] output = new byte [blockLength * 3];
2310         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2311         Encrypt (encryptor, input, output);
2312         AssertEquals ("RC2_k96b64_ECB_None Encrypt", expected, output);
2313
2314         // in ECB the first 2 blocks should be equals (as the IV is not used)
2315         byte[] block1 = new byte[blockLength];
2316         Array.Copy (output, 0, block1, 0, blockLength);
2317         byte[] block2 = new byte[blockLength];
2318         Array.Copy (output, blockLength, block2, 0, blockLength);
2319         AssertEquals ("RC2_k96b64_ECB_None b1==b2", block1, block2);
2320         byte[] reverse = new byte [blockLength * 3];
2321         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2322         Decrypt (decryptor, output, reverse);
2323         byte[] original = new byte [input.Length];
2324         Array.Copy (reverse, 0, original, 0, original.Length);
2325         AssertEquals ("RC2_k96b64_ECB_None Decrypt", input, original);
2326 }
2327
2328
2329 [Test]
2330 public void TestRC2_k96b64_ECB_Zeros ()
2331 {
2332         byte[] key = { 0x5D, 0x07, 0x3C, 0x15, 0x3F, 0xE1, 0xB2, 0x72, 0x9F, 0x1A, 0xBE, 0x21 };
2333         // not used for ECB but make the code more uniform
2334         byte[] iv = { 0x76, 0xE9, 0x93, 0x9F, 0xD1, 0x6A, 0xCE, 0x79 };
2335         byte[] expected = { 0x56, 0xF6, 0xF3, 0xAE, 0xCD, 0x73, 0x4F, 0x12, 0x56, 0xF6, 0xF3, 0xAE, 0xCD, 0x73, 0x4F, 0x12, 0x56, 0xF6, 0xF3, 0xAE, 0xCD, 0x73, 0x4F, 0x12 };
2336
2337         SymmetricAlgorithm algo = RC2.Create ();
2338         algo.Mode = CipherMode.ECB;
2339         algo.Padding = PaddingMode.Zeros;
2340         algo.BlockSize = 64;
2341         int blockLength = (algo.BlockSize >> 3);
2342         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2343         byte[] output = new byte [blockLength * 3];
2344         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2345         Encrypt (encryptor, input, output);
2346         AssertEquals ("RC2_k96b64_ECB_Zeros Encrypt", expected, output);
2347
2348         // in ECB the first 2 blocks should be equals (as the IV is not used)
2349         byte[] block1 = new byte[blockLength];
2350         Array.Copy (output, 0, block1, 0, blockLength);
2351         byte[] block2 = new byte[blockLength];
2352         Array.Copy (output, blockLength, block2, 0, blockLength);
2353         AssertEquals ("RC2_k96b64_ECB_Zeros b1==b2", block1, block2);
2354
2355         // also if padding is Zeros then all three blocks should be equals
2356         byte[] block3 = new byte[blockLength];
2357         Array.Copy (output, blockLength, block3, 0, blockLength);
2358         AssertEquals ("RC2_k96b64_ECB_Zeros b1==b3", block1, block3);
2359
2360         byte[] reverse = new byte [blockLength * 3];
2361         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2362         Decrypt (decryptor, output, reverse);
2363         byte[] original = new byte [input.Length];
2364         Array.Copy (reverse, 0, original, 0, original.Length);
2365         AssertEquals ("RC2_k96b64_ECB_Zeros Decrypt", input, original);
2366 }
2367
2368
2369 [Test]
2370 public void TestRC2_k96b64_ECB_PKCS7 ()
2371 {
2372         byte[] key = { 0x79, 0xCA, 0xDB, 0xBE, 0x8C, 0x10, 0x1E, 0xEB, 0x8B, 0x16, 0x00, 0x1B };
2373         // not used for ECB but make the code more uniform
2374         byte[] iv = { 0x17, 0x42, 0x68, 0x21, 0xBC, 0x52, 0x6A, 0xF6 };
2375         byte[] expected = { 0x86, 0xB2, 0x84, 0xAA, 0x58, 0xCB, 0x3F, 0x19, 0x86, 0xB2, 0x84, 0xAA, 0x58, 0xCB, 0x3F, 0x19, 0x75, 0xB8, 0x91, 0xC8, 0x17, 0xE2, 0x1C, 0x4A };
2376
2377         SymmetricAlgorithm algo = RC2.Create ();
2378         algo.Mode = CipherMode.ECB;
2379         algo.Padding = PaddingMode.PKCS7;
2380         algo.BlockSize = 64;
2381         int blockLength = (algo.BlockSize >> 3);
2382         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2383         byte[] output = new byte [blockLength * 3];
2384         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2385         Encrypt (encryptor, input, output);
2386         AssertEquals ("RC2_k96b64_ECB_PKCS7 Encrypt", expected, output);
2387
2388         // in ECB the first 2 blocks should be equals (as the IV is not used)
2389         byte[] block1 = new byte[blockLength];
2390         Array.Copy (output, 0, block1, 0, blockLength);
2391         byte[] block2 = new byte[blockLength];
2392         Array.Copy (output, blockLength, block2, 0, blockLength);
2393         AssertEquals ("RC2_k96b64_ECB_PKCS7 b1==b2", block1, block2);
2394         byte[] reverse = new byte [blockLength * 3];
2395         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2396         Decrypt (decryptor, output, reverse);
2397         byte[] original = new byte [input.Length];
2398         Array.Copy (reverse, 0, original, 0, original.Length);
2399         AssertEquals ("RC2_k96b64_ECB_PKCS7 Decrypt", input, original);
2400 }
2401
2402
2403 [Test]
2404 public void TestRC2_k96b64_CBC_None ()
2405 {
2406         byte[] key = { 0x68, 0xC6, 0xF2, 0x13, 0xEA, 0x3D, 0x68, 0x09, 0xAC, 0x07, 0x21, 0x1F };
2407         byte[] iv = { 0x42, 0x47, 0xE6, 0x98, 0xF8, 0xFE, 0xCD, 0xFE };
2408         byte[] expected = { 0x7F, 0x9C, 0xCE, 0xC5, 0x2C, 0xB6, 0x60, 0xC3, 0xF3, 0x5F, 0x7E, 0x95, 0x6F, 0xFE, 0x8E, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2409
2410         SymmetricAlgorithm algo = RC2.Create ();
2411         algo.Mode = CipherMode.CBC;
2412         algo.Padding = PaddingMode.None;
2413         algo.BlockSize = 64;
2414         int blockLength = (algo.BlockSize >> 3);
2415         byte[] input = new byte [blockLength * 2];
2416         byte[] output = new byte [blockLength * 3];
2417         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2418         Encrypt (encryptor, input, output);
2419         AssertEquals ("RC2_k96b64_CBC_None Encrypt", expected, output);
2420         byte[] reverse = new byte [blockLength * 3];
2421         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2422         Decrypt (decryptor, output, reverse);
2423         byte[] original = new byte [input.Length];
2424         Array.Copy (reverse, 0, original, 0, original.Length);
2425         AssertEquals ("RC2_k96b64_CBC_None Decrypt", input, original);
2426 }
2427
2428
2429 [Test]
2430 public void TestRC2_k96b64_CBC_Zeros ()
2431 {
2432         byte[] key = { 0xDF, 0x00, 0x49, 0x93, 0xA1, 0x49, 0x50, 0x03, 0x52, 0x9C, 0x86, 0xF6 };
2433         byte[] iv = { 0x69, 0xFC, 0x72, 0xA2, 0x60, 0xF7, 0x4C, 0xB0 };
2434         byte[] expected = { 0x16, 0x07, 0x45, 0x07, 0xF8, 0xAE, 0xD3, 0xEA, 0x94, 0x1E, 0xC9, 0x1A, 0xEF, 0x8D, 0x3E, 0xF7, 0x88, 0x7D, 0x8D, 0xF8, 0xC6, 0x0A, 0xFA, 0x82 };
2435
2436         SymmetricAlgorithm algo = RC2.Create ();
2437         algo.Mode = CipherMode.CBC;
2438         algo.Padding = PaddingMode.Zeros;
2439         algo.BlockSize = 64;
2440         int blockLength = (algo.BlockSize >> 3);
2441         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2442         byte[] output = new byte [blockLength * 3];
2443         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2444         Encrypt (encryptor, input, output);
2445         AssertEquals ("RC2_k96b64_CBC_Zeros Encrypt", expected, output);
2446         byte[] reverse = new byte [blockLength * 3];
2447         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2448         Decrypt (decryptor, output, reverse);
2449         byte[] original = new byte [input.Length];
2450         Array.Copy (reverse, 0, original, 0, original.Length);
2451         AssertEquals ("RC2_k96b64_CBC_Zeros Decrypt", input, original);
2452 }
2453
2454
2455 [Test]
2456 public void TestRC2_k96b64_CBC_PKCS7 ()
2457 {
2458         byte[] key = { 0x04, 0x2B, 0x2E, 0x98, 0x97, 0x84, 0x72, 0x0A, 0x78, 0x61, 0x02, 0xA9 };
2459         byte[] iv = { 0x16, 0x0A, 0x00, 0x48, 0xC3, 0x4F, 0x63, 0x05 };
2460         byte[] expected = { 0xD2, 0xC4, 0xC7, 0x02, 0xC7, 0xDB, 0xFB, 0xF6, 0xC1, 0x4D, 0x2D, 0x62, 0xF6, 0x57, 0x84, 0x84, 0xF2, 0x9B, 0x5C, 0x42, 0x66, 0x9B, 0x33, 0x1D };
2461
2462         SymmetricAlgorithm algo = RC2.Create ();
2463         algo.Mode = CipherMode.CBC;
2464         algo.Padding = PaddingMode.PKCS7;
2465         algo.BlockSize = 64;
2466         int blockLength = (algo.BlockSize >> 3);
2467         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2468         byte[] output = new byte [blockLength * 3];
2469         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2470         Encrypt (encryptor, input, output);
2471         AssertEquals ("RC2_k96b64_CBC_PKCS7 Encrypt", expected, output);
2472         byte[] reverse = new byte [blockLength * 3];
2473         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2474         Decrypt (decryptor, output, reverse);
2475         byte[] original = new byte [input.Length];
2476         Array.Copy (reverse, 0, original, 0, original.Length);
2477         AssertEquals ("RC2_k96b64_CBC_PKCS7 Decrypt", input, original);
2478 }
2479
2480
2481 /* Invalid parameters RC2_k96b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
2482
2483 /* Invalid parameters RC2_k96b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
2484
2485 /* Invalid parameters RC2_k96b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
2486
2487 [Test]
2488 public void TestRC2_k96b64_CFB8_None ()
2489 {
2490         byte[] key = { 0xDE, 0x6E, 0x40, 0xC3, 0x7D, 0x71, 0x0D, 0xCB, 0xA3, 0x62, 0x14, 0x76 };
2491         byte[] iv = { 0x72, 0x9E, 0xB4, 0xEE, 0x9B, 0x87, 0xAF, 0x12 };
2492         byte[] expected = { 0x14, 0x20, 0x3B, 0x35, 0xE2, 0x81, 0x84, 0x15, 0x6C, 0xA5, 0x4A, 0x94, 0xB3, 0xC0, 0x8D, 0x6A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2493
2494         SymmetricAlgorithm algo = RC2.Create ();
2495         algo.Mode = CipherMode.CFB;
2496         algo.Padding = PaddingMode.None;
2497         algo.BlockSize = 64;
2498         algo.FeedbackSize = 8;
2499         int blockLength = (algo.BlockSize >> 3);
2500         byte[] input = new byte [blockLength * 2];
2501         byte[] output = new byte [blockLength * 3];
2502         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2503         Encrypt (encryptor, input, output);
2504         AssertEquals ("RC2_k96b64_CFB8_None Encrypt", expected, output);
2505         byte[] reverse = new byte [blockLength * 3];
2506         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2507         Decrypt (decryptor, output, reverse);
2508         byte[] original = new byte [input.Length];
2509         Array.Copy (reverse, 0, original, 0, original.Length);
2510         AssertEquals ("RC2_k96b64_CFB8_None Decrypt", input, original);
2511 }
2512
2513
2514 [Test]
2515 public void TestRC2_k96b64_CFB8_Zeros ()
2516 {
2517         byte[] key = { 0xCF, 0x64, 0x81, 0x8F, 0x7D, 0x75, 0x8D, 0xB2, 0x9D, 0xE7, 0x39, 0xE3 };
2518         byte[] iv = { 0x30, 0xF2, 0x9E, 0x76, 0x96, 0x13, 0xCB, 0xDF };
2519         byte[] expected = { 0xC4, 0x0E, 0xE8, 0x61, 0x92, 0xB8, 0x9D, 0xDE, 0x0B, 0x39, 0x47, 0xD4, 0xD8, 0x05, 0x35, 0xF9, 0x0A, 0xAF, 0x63, 0x30, 0x4A, 0x82, 0x8C, 0xF2 };
2520
2521         SymmetricAlgorithm algo = RC2.Create ();
2522         algo.Mode = CipherMode.CFB;
2523         algo.Padding = PaddingMode.Zeros;
2524         algo.BlockSize = 64;
2525         algo.FeedbackSize = 8;
2526         int blockLength = (algo.BlockSize >> 3);
2527         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2528         byte[] output = new byte [blockLength * 3];
2529         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2530         Encrypt (encryptor, input, output);
2531         AssertEquals ("RC2_k96b64_CFB8_Zeros Encrypt", expected, output);
2532         byte[] reverse = new byte [blockLength * 3];
2533         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2534         Decrypt (decryptor, output, reverse);
2535         byte[] original = new byte [input.Length];
2536         Array.Copy (reverse, 0, original, 0, original.Length);
2537         AssertEquals ("RC2_k96b64_CFB8_Zeros Decrypt", input, original);
2538 }
2539
2540
2541 [Test]
2542 public void TestRC2_k96b64_CFB8_PKCS7 ()
2543 {
2544         byte[] key = { 0xC5, 0xF4, 0x44, 0xF2, 0xA0, 0xC3, 0xA7, 0x87, 0x64, 0x36, 0x5A, 0xFA };
2545         byte[] iv = { 0x20, 0xC5, 0x5E, 0x57, 0x5E, 0x0E, 0x2D, 0xDD };
2546         byte[] expected = { 0x66, 0x93, 0x1E, 0x15, 0x17, 0x5C, 0x3C, 0x07, 0xDB, 0x2F, 0xD9, 0x00, 0x0C, 0x3F, 0x9E, 0xBB, 0xB9, 0x32, 0xDD, 0x2D, 0x57, 0x69, 0x3D, 0xC3 };
2547
2548         SymmetricAlgorithm algo = RC2.Create ();
2549         algo.Mode = CipherMode.CFB;
2550         algo.Padding = PaddingMode.PKCS7;
2551         algo.BlockSize = 64;
2552         algo.FeedbackSize = 8;
2553         int blockLength = (algo.BlockSize >> 3);
2554         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2555         byte[] output = new byte [blockLength * 3];
2556         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2557         Encrypt (encryptor, input, output);
2558         AssertEquals ("RC2_k96b64_CFB8_PKCS7 Encrypt", expected, output);
2559         byte[] reverse = new byte [blockLength * 3];
2560         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2561         Decrypt (decryptor, output, reverse);
2562         byte[] original = new byte [input.Length];
2563         Array.Copy (reverse, 0, original, 0, original.Length);
2564         AssertEquals ("RC2_k96b64_CFB8_PKCS7 Decrypt", input, original);
2565 }
2566
2567
2568 /* Invalid parameters RC2_k96b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
2569
2570 /* Invalid parameters RC2_k96b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
2571
2572 /* Invalid parameters RC2_k96b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
2573
2574 [Test]
2575 public void TestRC2_k104b64_ECB_None ()
2576 {
2577         byte[] key = { 0x04, 0x5B, 0x99, 0xD3, 0xBC, 0x00, 0x27, 0xA3, 0xDC, 0x57, 0x4C, 0x82, 0xD6 };
2578         // not used for ECB but make the code more uniform
2579         byte[] iv = { 0x70, 0x3D, 0xE7, 0xBC, 0x82, 0xFD, 0x8F, 0x03 };
2580         byte[] expected = { 0x5D, 0xEA, 0x9F, 0x1F, 0x19, 0xBB, 0x3D, 0x26, 0x5D, 0xEA, 0x9F, 0x1F, 0x19, 0xBB, 0x3D, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2581
2582         SymmetricAlgorithm algo = RC2.Create ();
2583         algo.Mode = CipherMode.ECB;
2584         algo.Padding = PaddingMode.None;
2585         algo.BlockSize = 64;
2586         int blockLength = (algo.BlockSize >> 3);
2587         byte[] input = new byte [blockLength * 2];
2588         byte[] output = new byte [blockLength * 3];
2589         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2590         Encrypt (encryptor, input, output);
2591         AssertEquals ("RC2_k104b64_ECB_None Encrypt", expected, output);
2592
2593         // in ECB the first 2 blocks should be equals (as the IV is not used)
2594         byte[] block1 = new byte[blockLength];
2595         Array.Copy (output, 0, block1, 0, blockLength);
2596         byte[] block2 = new byte[blockLength];
2597         Array.Copy (output, blockLength, block2, 0, blockLength);
2598         AssertEquals ("RC2_k104b64_ECB_None b1==b2", block1, block2);
2599         byte[] reverse = new byte [blockLength * 3];
2600         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2601         Decrypt (decryptor, output, reverse);
2602         byte[] original = new byte [input.Length];
2603         Array.Copy (reverse, 0, original, 0, original.Length);
2604         AssertEquals ("RC2_k104b64_ECB_None Decrypt", input, original);
2605 }
2606
2607
2608 [Test]
2609 public void TestRC2_k104b64_ECB_Zeros ()
2610 {
2611         byte[] key = { 0xA1, 0x3B, 0xDF, 0x6F, 0x6D, 0x2B, 0x7B, 0x0B, 0x13, 0x3E, 0x84, 0x35, 0x3C };
2612         // not used for ECB but make the code more uniform
2613         byte[] iv = { 0xE6, 0x74, 0x41, 0xB6, 0xB4, 0x31, 0xB2, 0x6A };
2614         byte[] expected = { 0xAF, 0x46, 0x98, 0xF8, 0xC1, 0x4B, 0x45, 0x09, 0xAF, 0x46, 0x98, 0xF8, 0xC1, 0x4B, 0x45, 0x09, 0xAF, 0x46, 0x98, 0xF8, 0xC1, 0x4B, 0x45, 0x09 };
2615
2616         SymmetricAlgorithm algo = RC2.Create ();
2617         algo.Mode = CipherMode.ECB;
2618         algo.Padding = PaddingMode.Zeros;
2619         algo.BlockSize = 64;
2620         int blockLength = (algo.BlockSize >> 3);
2621         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2622         byte[] output = new byte [blockLength * 3];
2623         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2624         Encrypt (encryptor, input, output);
2625         AssertEquals ("RC2_k104b64_ECB_Zeros Encrypt", expected, output);
2626
2627         // in ECB the first 2 blocks should be equals (as the IV is not used)
2628         byte[] block1 = new byte[blockLength];
2629         Array.Copy (output, 0, block1, 0, blockLength);
2630         byte[] block2 = new byte[blockLength];
2631         Array.Copy (output, blockLength, block2, 0, blockLength);
2632         AssertEquals ("RC2_k104b64_ECB_Zeros b1==b2", block1, block2);
2633
2634         // also if padding is Zeros then all three blocks should be equals
2635         byte[] block3 = new byte[blockLength];
2636         Array.Copy (output, blockLength, block3, 0, blockLength);
2637         AssertEquals ("RC2_k104b64_ECB_Zeros b1==b3", block1, block3);
2638
2639         byte[] reverse = new byte [blockLength * 3];
2640         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2641         Decrypt (decryptor, output, reverse);
2642         byte[] original = new byte [input.Length];
2643         Array.Copy (reverse, 0, original, 0, original.Length);
2644         AssertEquals ("RC2_k104b64_ECB_Zeros Decrypt", input, original);
2645 }
2646
2647
2648 [Test]
2649 public void TestRC2_k104b64_ECB_PKCS7 ()
2650 {
2651         byte[] key = { 0x28, 0xDF, 0x8C, 0x1B, 0x7E, 0x04, 0xB2, 0x89, 0x72, 0xDA, 0x19, 0x57, 0x81 };
2652         // not used for ECB but make the code more uniform
2653         byte[] iv = { 0xB8, 0x82, 0xA7, 0xBF, 0x99, 0xE9, 0x39, 0x02 };
2654         byte[] expected = { 0x5D, 0xEB, 0xD8, 0x26, 0x51, 0x86, 0xFB, 0x0E, 0x5D, 0xEB, 0xD8, 0x26, 0x51, 0x86, 0xFB, 0x0E, 0x1C, 0xFD, 0xE2, 0x77, 0xB6, 0x74, 0x55, 0x9C };
2655
2656         SymmetricAlgorithm algo = RC2.Create ();
2657         algo.Mode = CipherMode.ECB;
2658         algo.Padding = PaddingMode.PKCS7;
2659         algo.BlockSize = 64;
2660         int blockLength = (algo.BlockSize >> 3);
2661         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2662         byte[] output = new byte [blockLength * 3];
2663         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2664         Encrypt (encryptor, input, output);
2665         AssertEquals ("RC2_k104b64_ECB_PKCS7 Encrypt", expected, output);
2666
2667         // in ECB the first 2 blocks should be equals (as the IV is not used)
2668         byte[] block1 = new byte[blockLength];
2669         Array.Copy (output, 0, block1, 0, blockLength);
2670         byte[] block2 = new byte[blockLength];
2671         Array.Copy (output, blockLength, block2, 0, blockLength);
2672         AssertEquals ("RC2_k104b64_ECB_PKCS7 b1==b2", block1, block2);
2673         byte[] reverse = new byte [blockLength * 3];
2674         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2675         Decrypt (decryptor, output, reverse);
2676         byte[] original = new byte [input.Length];
2677         Array.Copy (reverse, 0, original, 0, original.Length);
2678         AssertEquals ("RC2_k104b64_ECB_PKCS7 Decrypt", input, original);
2679 }
2680
2681
2682 [Test]
2683 public void TestRC2_k104b64_CBC_None ()
2684 {
2685         byte[] key = { 0xF8, 0xCE, 0xA2, 0x33, 0xE5, 0x7D, 0x43, 0x72, 0xA9, 0xF5, 0xF1, 0x80, 0xBC };
2686         byte[] iv = { 0x12, 0xFF, 0x74, 0x3A, 0x36, 0x42, 0xBE, 0x78 };
2687         byte[] expected = { 0x64, 0xCD, 0x86, 0xA1, 0x1B, 0xB1, 0xD3, 0x9F, 0x8E, 0xFC, 0x42, 0xB8, 0x56, 0x96, 0x56, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2688
2689         SymmetricAlgorithm algo = RC2.Create ();
2690         algo.Mode = CipherMode.CBC;
2691         algo.Padding = PaddingMode.None;
2692         algo.BlockSize = 64;
2693         int blockLength = (algo.BlockSize >> 3);
2694         byte[] input = new byte [blockLength * 2];
2695         byte[] output = new byte [blockLength * 3];
2696         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2697         Encrypt (encryptor, input, output);
2698         AssertEquals ("RC2_k104b64_CBC_None Encrypt", expected, output);
2699         byte[] reverse = new byte [blockLength * 3];
2700         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2701         Decrypt (decryptor, output, reverse);
2702         byte[] original = new byte [input.Length];
2703         Array.Copy (reverse, 0, original, 0, original.Length);
2704         AssertEquals ("RC2_k104b64_CBC_None Decrypt", input, original);
2705 }
2706
2707
2708 [Test]
2709 public void TestRC2_k104b64_CBC_Zeros ()
2710 {
2711         byte[] key = { 0xEF, 0x4E, 0x02, 0x86, 0x5F, 0xE5, 0x94, 0x05, 0xEF, 0x8D, 0x8D, 0x5D, 0x04 };
2712         byte[] iv = { 0x98, 0x23, 0x93, 0xF7, 0x6D, 0x02, 0xB1, 0x73 };
2713         byte[] expected = { 0x50, 0x08, 0xAB, 0x8B, 0x26, 0x0D, 0x5B, 0x73, 0x3F, 0xE7, 0x75, 0x55, 0x4F, 0x9C, 0xDC, 0xFC, 0x17, 0x58, 0x2A, 0xB2, 0xFC, 0x54, 0x15, 0x97 };
2714
2715         SymmetricAlgorithm algo = RC2.Create ();
2716         algo.Mode = CipherMode.CBC;
2717         algo.Padding = PaddingMode.Zeros;
2718         algo.BlockSize = 64;
2719         int blockLength = (algo.BlockSize >> 3);
2720         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2721         byte[] output = new byte [blockLength * 3];
2722         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2723         Encrypt (encryptor, input, output);
2724         AssertEquals ("RC2_k104b64_CBC_Zeros Encrypt", expected, output);
2725         byte[] reverse = new byte [blockLength * 3];
2726         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2727         Decrypt (decryptor, output, reverse);
2728         byte[] original = new byte [input.Length];
2729         Array.Copy (reverse, 0, original, 0, original.Length);
2730         AssertEquals ("RC2_k104b64_CBC_Zeros Decrypt", input, original);
2731 }
2732
2733
2734 [Test]
2735 public void TestRC2_k104b64_CBC_PKCS7 ()
2736 {
2737         byte[] key = { 0xE3, 0xD2, 0xC2, 0xA0, 0x54, 0xF5, 0xFC, 0xFC, 0x94, 0xA2, 0x6F, 0x6F, 0x52 };
2738         byte[] iv = { 0xBA, 0x5D, 0x0D, 0xBA, 0x0D, 0x0C, 0x4E, 0x5B };
2739         byte[] expected = { 0x6C, 0x5B, 0x74, 0x54, 0x0F, 0x86, 0x62, 0x06, 0x11, 0x65, 0xAA, 0x0B, 0x4F, 0x65, 0x34, 0x26, 0xAF, 0x26, 0x0D, 0xF4, 0xCE, 0xB6, 0xEE, 0xF0 };
2740
2741         SymmetricAlgorithm algo = RC2.Create ();
2742         algo.Mode = CipherMode.CBC;
2743         algo.Padding = PaddingMode.PKCS7;
2744         algo.BlockSize = 64;
2745         int blockLength = (algo.BlockSize >> 3);
2746         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2747         byte[] output = new byte [blockLength * 3];
2748         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2749         Encrypt (encryptor, input, output);
2750         AssertEquals ("RC2_k104b64_CBC_PKCS7 Encrypt", expected, output);
2751         byte[] reverse = new byte [blockLength * 3];
2752         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2753         Decrypt (decryptor, output, reverse);
2754         byte[] original = new byte [input.Length];
2755         Array.Copy (reverse, 0, original, 0, original.Length);
2756         AssertEquals ("RC2_k104b64_CBC_PKCS7 Decrypt", input, original);
2757 }
2758
2759
2760 /* Invalid parameters RC2_k104b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
2761
2762 /* Invalid parameters RC2_k104b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
2763
2764 /* Invalid parameters RC2_k104b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
2765
2766 [Test]
2767 public void TestRC2_k104b64_CFB8_None ()
2768 {
2769         byte[] key = { 0xB3, 0xE2, 0x4D, 0x91, 0xE9, 0xF8, 0x72, 0xA4, 0x2E, 0x00, 0x0C, 0x08, 0x96 };
2770         byte[] iv = { 0x48, 0xF8, 0xDD, 0x61, 0xD5, 0x00, 0xD0, 0xE1 };
2771         byte[] expected = { 0xB9, 0xAA, 0x53, 0xD8, 0xCB, 0x23, 0xA6, 0x41, 0x69, 0x84, 0x2D, 0xD5, 0x4F, 0x45, 0xC2, 0x8D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2772
2773         SymmetricAlgorithm algo = RC2.Create ();
2774         algo.Mode = CipherMode.CFB;
2775         algo.Padding = PaddingMode.None;
2776         algo.BlockSize = 64;
2777         algo.FeedbackSize = 8;
2778         int blockLength = (algo.BlockSize >> 3);
2779         byte[] input = new byte [blockLength * 2];
2780         byte[] output = new byte [blockLength * 3];
2781         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2782         Encrypt (encryptor, input, output);
2783         AssertEquals ("RC2_k104b64_CFB8_None Encrypt", expected, output);
2784         byte[] reverse = new byte [blockLength * 3];
2785         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2786         Decrypt (decryptor, output, reverse);
2787         byte[] original = new byte [input.Length];
2788         Array.Copy (reverse, 0, original, 0, original.Length);
2789         AssertEquals ("RC2_k104b64_CFB8_None Decrypt", input, original);
2790 }
2791
2792
2793 [Test]
2794 public void TestRC2_k104b64_CFB8_Zeros ()
2795 {
2796         byte[] key = { 0xD4, 0x9C, 0x6B, 0x12, 0x41, 0x93, 0xEB, 0xDA, 0xDF, 0x7A, 0x81, 0x23, 0x1F };
2797         byte[] iv = { 0x3C, 0x0E, 0x48, 0xAA, 0xD8, 0x48, 0xE9, 0xC8 };
2798         byte[] expected = { 0x66, 0x39, 0x26, 0x0B, 0x81, 0xD8, 0x9A, 0x2F, 0xF1, 0x2C, 0xCF, 0x75, 0x8C, 0x01, 0x4D, 0x6E, 0x2A, 0x67, 0x9D, 0x0D, 0xA5, 0x56, 0x15, 0x41 };
2799
2800         SymmetricAlgorithm algo = RC2.Create ();
2801         algo.Mode = CipherMode.CFB;
2802         algo.Padding = PaddingMode.Zeros;
2803         algo.BlockSize = 64;
2804         algo.FeedbackSize = 8;
2805         int blockLength = (algo.BlockSize >> 3);
2806         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2807         byte[] output = new byte [blockLength * 3];
2808         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2809         Encrypt (encryptor, input, output);
2810         AssertEquals ("RC2_k104b64_CFB8_Zeros Encrypt", expected, output);
2811         byte[] reverse = new byte [blockLength * 3];
2812         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2813         Decrypt (decryptor, output, reverse);
2814         byte[] original = new byte [input.Length];
2815         Array.Copy (reverse, 0, original, 0, original.Length);
2816         AssertEquals ("RC2_k104b64_CFB8_Zeros Decrypt", input, original);
2817 }
2818
2819
2820 [Test]
2821 public void TestRC2_k104b64_CFB8_PKCS7 ()
2822 {
2823         byte[] key = { 0x2C, 0x38, 0x19, 0x43, 0x93, 0x38, 0x85, 0xC4, 0xF2, 0x19, 0xC7, 0x1B, 0x76 };
2824         byte[] iv = { 0xB4, 0x1B, 0x9C, 0x82, 0xB5, 0x6E, 0x42, 0xAF };
2825         byte[] expected = { 0xC5, 0x56, 0x04, 0x85, 0x0A, 0x52, 0x8B, 0x02, 0x69, 0xB6, 0xCF, 0xC7, 0xA9, 0x35, 0x63, 0xF7, 0x4B, 0x48, 0xF3, 0xD0, 0xFF, 0x74, 0xA7, 0xB5 };
2826
2827         SymmetricAlgorithm algo = RC2.Create ();
2828         algo.Mode = CipherMode.CFB;
2829         algo.Padding = PaddingMode.PKCS7;
2830         algo.BlockSize = 64;
2831         algo.FeedbackSize = 8;
2832         int blockLength = (algo.BlockSize >> 3);
2833         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2834         byte[] output = new byte [blockLength * 3];
2835         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2836         Encrypt (encryptor, input, output);
2837         AssertEquals ("RC2_k104b64_CFB8_PKCS7 Encrypt", expected, output);
2838         byte[] reverse = new byte [blockLength * 3];
2839         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2840         Decrypt (decryptor, output, reverse);
2841         byte[] original = new byte [input.Length];
2842         Array.Copy (reverse, 0, original, 0, original.Length);
2843         AssertEquals ("RC2_k104b64_CFB8_PKCS7 Decrypt", input, original);
2844 }
2845
2846
2847 /* Invalid parameters RC2_k104b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
2848
2849 /* Invalid parameters RC2_k104b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
2850
2851 /* Invalid parameters RC2_k104b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
2852
2853 [Test]
2854 public void TestRC2_k112b64_ECB_None ()
2855 {
2856         byte[] key = { 0xB7, 0x95, 0xA4, 0x42, 0x21, 0x3D, 0x30, 0x51, 0x98, 0x01, 0xA0, 0x6C, 0x45, 0x68 };
2857         // not used for ECB but make the code more uniform
2858         byte[] iv = { 0x3B, 0x36, 0x51, 0x24, 0xF4, 0x1A, 0xC1, 0x91 };
2859         byte[] expected = { 0x31, 0xAE, 0xBA, 0xFB, 0xB4, 0xFA, 0x78, 0x30, 0x31, 0xAE, 0xBA, 0xFB, 0xB4, 0xFA, 0x78, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2860
2861         SymmetricAlgorithm algo = RC2.Create ();
2862         algo.Mode = CipherMode.ECB;
2863         algo.Padding = PaddingMode.None;
2864         algo.BlockSize = 64;
2865         int blockLength = (algo.BlockSize >> 3);
2866         byte[] input = new byte [blockLength * 2];
2867         byte[] output = new byte [blockLength * 3];
2868         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2869         Encrypt (encryptor, input, output);
2870         AssertEquals ("RC2_k112b64_ECB_None Encrypt", expected, output);
2871
2872         // in ECB the first 2 blocks should be equals (as the IV is not used)
2873         byte[] block1 = new byte[blockLength];
2874         Array.Copy (output, 0, block1, 0, blockLength);
2875         byte[] block2 = new byte[blockLength];
2876         Array.Copy (output, blockLength, block2, 0, blockLength);
2877         AssertEquals ("RC2_k112b64_ECB_None b1==b2", block1, block2);
2878         byte[] reverse = new byte [blockLength * 3];
2879         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2880         Decrypt (decryptor, output, reverse);
2881         byte[] original = new byte [input.Length];
2882         Array.Copy (reverse, 0, original, 0, original.Length);
2883         AssertEquals ("RC2_k112b64_ECB_None Decrypt", input, original);
2884 }
2885
2886
2887 [Test]
2888 public void TestRC2_k112b64_ECB_Zeros ()
2889 {
2890         byte[] key = { 0xB1, 0x8E, 0x09, 0xFB, 0x70, 0x03, 0x6A, 0xF2, 0xCF, 0x9D, 0x9B, 0xD7, 0x10, 0xD4 };
2891         // not used for ECB but make the code more uniform
2892         byte[] iv = { 0x64, 0x15, 0x78, 0xB8, 0x25, 0x15, 0xFA, 0xC8 };
2893         byte[] expected = { 0xB1, 0xC2, 0x27, 0xA8, 0x32, 0xBA, 0x34, 0x06, 0xB1, 0xC2, 0x27, 0xA8, 0x32, 0xBA, 0x34, 0x06, 0xB1, 0xC2, 0x27, 0xA8, 0x32, 0xBA, 0x34, 0x06 };
2894
2895         SymmetricAlgorithm algo = RC2.Create ();
2896         algo.Mode = CipherMode.ECB;
2897         algo.Padding = PaddingMode.Zeros;
2898         algo.BlockSize = 64;
2899         int blockLength = (algo.BlockSize >> 3);
2900         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2901         byte[] output = new byte [blockLength * 3];
2902         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2903         Encrypt (encryptor, input, output);
2904         AssertEquals ("RC2_k112b64_ECB_Zeros Encrypt", expected, output);
2905
2906         // in ECB the first 2 blocks should be equals (as the IV is not used)
2907         byte[] block1 = new byte[blockLength];
2908         Array.Copy (output, 0, block1, 0, blockLength);
2909         byte[] block2 = new byte[blockLength];
2910         Array.Copy (output, blockLength, block2, 0, blockLength);
2911         AssertEquals ("RC2_k112b64_ECB_Zeros b1==b2", block1, block2);
2912
2913         // also if padding is Zeros then all three blocks should be equals
2914         byte[] block3 = new byte[blockLength];
2915         Array.Copy (output, blockLength, block3, 0, blockLength);
2916         AssertEquals ("RC2_k112b64_ECB_Zeros b1==b3", block1, block3);
2917
2918         byte[] reverse = new byte [blockLength * 3];
2919         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2920         Decrypt (decryptor, output, reverse);
2921         byte[] original = new byte [input.Length];
2922         Array.Copy (reverse, 0, original, 0, original.Length);
2923         AssertEquals ("RC2_k112b64_ECB_Zeros Decrypt", input, original);
2924 }
2925
2926
2927 [Test]
2928 public void TestRC2_k112b64_ECB_PKCS7 ()
2929 {
2930         byte[] key = { 0x4F, 0xE8, 0x2C, 0x62, 0x98, 0x89, 0xEF, 0x11, 0x29, 0xB2, 0xDD, 0x4D, 0xE1, 0x39 };
2931         // not used for ECB but make the code more uniform
2932         byte[] iv = { 0x15, 0xE0, 0x95, 0x29, 0xEB, 0xE5, 0xC7, 0x8E };
2933         byte[] expected = { 0x43, 0x79, 0x6E, 0xCF, 0x63, 0x68, 0xF0, 0x55, 0x43, 0x79, 0x6E, 0xCF, 0x63, 0x68, 0xF0, 0x55, 0x80, 0x64, 0x15, 0x36, 0x08, 0xD0, 0x76, 0x58 };
2934
2935         SymmetricAlgorithm algo = RC2.Create ();
2936         algo.Mode = CipherMode.ECB;
2937         algo.Padding = PaddingMode.PKCS7;
2938         algo.BlockSize = 64;
2939         int blockLength = (algo.BlockSize >> 3);
2940         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2941         byte[] output = new byte [blockLength * 3];
2942         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2943         Encrypt (encryptor, input, output);
2944         AssertEquals ("RC2_k112b64_ECB_PKCS7 Encrypt", expected, output);
2945
2946         // in ECB the first 2 blocks should be equals (as the IV is not used)
2947         byte[] block1 = new byte[blockLength];
2948         Array.Copy (output, 0, block1, 0, blockLength);
2949         byte[] block2 = new byte[blockLength];
2950         Array.Copy (output, blockLength, block2, 0, blockLength);
2951         AssertEquals ("RC2_k112b64_ECB_PKCS7 b1==b2", block1, block2);
2952         byte[] reverse = new byte [blockLength * 3];
2953         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2954         Decrypt (decryptor, output, reverse);
2955         byte[] original = new byte [input.Length];
2956         Array.Copy (reverse, 0, original, 0, original.Length);
2957         AssertEquals ("RC2_k112b64_ECB_PKCS7 Decrypt", input, original);
2958 }
2959
2960
2961 [Test]
2962 public void TestRC2_k112b64_CBC_None ()
2963 {
2964         byte[] key = { 0xC0, 0x04, 0xA9, 0x3C, 0x94, 0xA1, 0x78, 0xA2, 0x4B, 0x94, 0x6F, 0x19, 0xD1, 0xE1 };
2965         byte[] iv = { 0x28, 0x94, 0x16, 0x28, 0x69, 0x64, 0xF6, 0x83 };
2966         byte[] expected = { 0xB7, 0x2F, 0x20, 0x02, 0xAD, 0x97, 0x21, 0x45, 0xDA, 0xC2, 0x0D, 0xD9, 0xEB, 0xCC, 0xA0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2967
2968         SymmetricAlgorithm algo = RC2.Create ();
2969         algo.Mode = CipherMode.CBC;
2970         algo.Padding = PaddingMode.None;
2971         algo.BlockSize = 64;
2972         int blockLength = (algo.BlockSize >> 3);
2973         byte[] input = new byte [blockLength * 2];
2974         byte[] output = new byte [blockLength * 3];
2975         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2976         Encrypt (encryptor, input, output);
2977         AssertEquals ("RC2_k112b64_CBC_None Encrypt", expected, output);
2978         byte[] reverse = new byte [blockLength * 3];
2979         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2980         Decrypt (decryptor, output, reverse);
2981         byte[] original = new byte [input.Length];
2982         Array.Copy (reverse, 0, original, 0, original.Length);
2983         AssertEquals ("RC2_k112b64_CBC_None Decrypt", input, original);
2984 }
2985
2986
2987 [Test]
2988 public void TestRC2_k112b64_CBC_Zeros ()
2989 {
2990         byte[] key = { 0x59, 0xFF, 0xC2, 0xB5, 0x62, 0x84, 0x27, 0x49, 0x4B, 0xFF, 0xFF, 0xCE, 0xBB, 0xBD };
2991         byte[] iv = { 0x2E, 0x9E, 0xD3, 0xF6, 0xFC, 0xD7, 0xC6, 0x1C };
2992         byte[] expected = { 0x38, 0xE4, 0x4D, 0xD5, 0x3F, 0x74, 0x44, 0x90, 0x11, 0xCD, 0x6E, 0x13, 0x7A, 0x9A, 0x82, 0xBB, 0xBD, 0xD1, 0x0F, 0x38, 0x0F, 0x5F, 0x97, 0x14 };
2993
2994         SymmetricAlgorithm algo = RC2.Create ();
2995         algo.Mode = CipherMode.CBC;
2996         algo.Padding = PaddingMode.Zeros;
2997         algo.BlockSize = 64;
2998         int blockLength = (algo.BlockSize >> 3);
2999         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3000         byte[] output = new byte [blockLength * 3];
3001         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3002         Encrypt (encryptor, input, output);
3003         AssertEquals ("RC2_k112b64_CBC_Zeros Encrypt", expected, output);
3004         byte[] reverse = new byte [blockLength * 3];
3005         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3006         Decrypt (decryptor, output, reverse);
3007         byte[] original = new byte [input.Length];
3008         Array.Copy (reverse, 0, original, 0, original.Length);
3009         AssertEquals ("RC2_k112b64_CBC_Zeros Decrypt", input, original);
3010 }
3011
3012
3013 [Test]
3014 public void TestRC2_k112b64_CBC_PKCS7 ()
3015 {
3016         byte[] key = { 0xE4, 0x49, 0xA4, 0xBE, 0x30, 0xE1, 0xB5, 0x21, 0x33, 0xC6, 0x37, 0x88, 0x30, 0xEC };
3017         byte[] iv = { 0x74, 0xAC, 0x28, 0x92, 0xA5, 0xF1, 0x31, 0xC9 };
3018         byte[] expected = { 0xE5, 0x7B, 0x53, 0x65, 0x37, 0xD8, 0x29, 0xBD, 0x4B, 0x73, 0x3B, 0x1B, 0x5B, 0x00, 0x04, 0xE2, 0x11, 0x5B, 0x24, 0x6F, 0x6D, 0x7F, 0x1C, 0xE8 };
3019
3020         SymmetricAlgorithm algo = RC2.Create ();
3021         algo.Mode = CipherMode.CBC;
3022         algo.Padding = PaddingMode.PKCS7;
3023         algo.BlockSize = 64;
3024         int blockLength = (algo.BlockSize >> 3);
3025         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3026         byte[] output = new byte [blockLength * 3];
3027         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3028         Encrypt (encryptor, input, output);
3029         AssertEquals ("RC2_k112b64_CBC_PKCS7 Encrypt", expected, output);
3030         byte[] reverse = new byte [blockLength * 3];
3031         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3032         Decrypt (decryptor, output, reverse);
3033         byte[] original = new byte [input.Length];
3034         Array.Copy (reverse, 0, original, 0, original.Length);
3035         AssertEquals ("RC2_k112b64_CBC_PKCS7 Decrypt", input, original);
3036 }
3037
3038
3039 /* Invalid parameters RC2_k112b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
3040
3041 /* Invalid parameters RC2_k112b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
3042
3043 /* Invalid parameters RC2_k112b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
3044
3045 [Test]
3046 public void TestRC2_k112b64_CFB8_None ()
3047 {
3048         byte[] key = { 0x70, 0x12, 0xEC, 0xAB, 0x6E, 0x1D, 0xEF, 0x51, 0xEE, 0xA8, 0x81, 0xE1, 0x21, 0xFF };
3049         byte[] iv = { 0x0E, 0x56, 0xA2, 0xA3, 0x8C, 0x5D, 0x9C, 0x1F };
3050         byte[] expected = { 0x71, 0x1C, 0x76, 0xB1, 0x61, 0x32, 0x77, 0xB7, 0x98, 0x42, 0x31, 0xF1, 0x0A, 0xE4, 0xC3, 0x83, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3051
3052         SymmetricAlgorithm algo = RC2.Create ();
3053         algo.Mode = CipherMode.CFB;
3054         algo.Padding = PaddingMode.None;
3055         algo.BlockSize = 64;
3056         algo.FeedbackSize = 8;
3057         int blockLength = (algo.BlockSize >> 3);
3058         byte[] input = new byte [blockLength * 2];
3059         byte[] output = new byte [blockLength * 3];
3060         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3061         Encrypt (encryptor, input, output);
3062         AssertEquals ("RC2_k112b64_CFB8_None Encrypt", expected, output);
3063         byte[] reverse = new byte [blockLength * 3];
3064         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3065         Decrypt (decryptor, output, reverse);
3066         byte[] original = new byte [input.Length];
3067         Array.Copy (reverse, 0, original, 0, original.Length);
3068         AssertEquals ("RC2_k112b64_CFB8_None Decrypt", input, original);
3069 }
3070
3071
3072 [Test]
3073 public void TestRC2_k112b64_CFB8_Zeros ()
3074 {
3075         byte[] key = { 0x48, 0x66, 0x16, 0xD6, 0x57, 0xBF, 0x38, 0xB7, 0x22, 0x81, 0x9F, 0x75, 0xE0, 0x88 };
3076         byte[] iv = { 0x51, 0x2C, 0x6A, 0x59, 0xAB, 0xD2, 0xAE, 0x6E };
3077         byte[] expected = { 0xF1, 0x9E, 0x85, 0x7A, 0x7D, 0xF0, 0x39, 0x0D, 0x11, 0x47, 0x11, 0xC0, 0x1A, 0x19, 0x21, 0x85, 0x95, 0x40, 0xDA, 0x4A, 0xEE, 0x49, 0xC7, 0x54 };
3078
3079         SymmetricAlgorithm algo = RC2.Create ();
3080         algo.Mode = CipherMode.CFB;
3081         algo.Padding = PaddingMode.Zeros;
3082         algo.BlockSize = 64;
3083         algo.FeedbackSize = 8;
3084         int blockLength = (algo.BlockSize >> 3);
3085         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3086         byte[] output = new byte [blockLength * 3];
3087         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3088         Encrypt (encryptor, input, output);
3089         AssertEquals ("RC2_k112b64_CFB8_Zeros Encrypt", expected, output);
3090         byte[] reverse = new byte [blockLength * 3];
3091         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3092         Decrypt (decryptor, output, reverse);
3093         byte[] original = new byte [input.Length];
3094         Array.Copy (reverse, 0, original, 0, original.Length);
3095         AssertEquals ("RC2_k112b64_CFB8_Zeros Decrypt", input, original);
3096 }
3097
3098
3099 [Test]
3100 public void TestRC2_k112b64_CFB8_PKCS7 ()
3101 {
3102         byte[] key = { 0x55, 0x20, 0xA1, 0xD8, 0xFA, 0xE7, 0x0D, 0xF9, 0xB6, 0x4B, 0x90, 0x10, 0xDE, 0xB1 };
3103         byte[] iv = { 0x26, 0x6C, 0xB0, 0xB4, 0x4D, 0x7F, 0x5C, 0x18 };
3104         byte[] expected = { 0xC8, 0x00, 0x9F, 0x21, 0x2C, 0xB0, 0x75, 0x6C, 0x62, 0xD8, 0xD0, 0x30, 0x11, 0x93, 0x73, 0x2F, 0xC5, 0xBC, 0xB1, 0xED, 0x2E, 0xBE, 0xCF, 0xBC };
3105
3106         SymmetricAlgorithm algo = RC2.Create ();
3107         algo.Mode = CipherMode.CFB;
3108         algo.Padding = PaddingMode.PKCS7;
3109         algo.BlockSize = 64;
3110         algo.FeedbackSize = 8;
3111         int blockLength = (algo.BlockSize >> 3);
3112         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3113         byte[] output = new byte [blockLength * 3];
3114         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3115         Encrypt (encryptor, input, output);
3116         AssertEquals ("RC2_k112b64_CFB8_PKCS7 Encrypt", expected, output);
3117         byte[] reverse = new byte [blockLength * 3];
3118         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3119         Decrypt (decryptor, output, reverse);
3120         byte[] original = new byte [input.Length];
3121         Array.Copy (reverse, 0, original, 0, original.Length);
3122         AssertEquals ("RC2_k112b64_CFB8_PKCS7 Decrypt", input, original);
3123 }
3124
3125
3126 /* Invalid parameters RC2_k112b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
3127
3128 /* Invalid parameters RC2_k112b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
3129
3130 /* Invalid parameters RC2_k112b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
3131
3132 [Test]
3133 public void TestRC2_k120b64_ECB_None ()
3134 {
3135         byte[] key = { 0x5D, 0x08, 0xC7, 0xB8, 0xB1, 0xEB, 0x89, 0x1C, 0xC0, 0x3F, 0xE6, 0x2F, 0xC4, 0x79, 0x11 };
3136         // not used for ECB but make the code more uniform
3137         byte[] iv = { 0x76, 0x1C, 0xAC, 0x0F, 0x39, 0x6C, 0x1A, 0x44 };
3138         byte[] expected = { 0xA4, 0xC1, 0x60, 0x59, 0x6B, 0x45, 0xE0, 0x4C, 0xA4, 0xC1, 0x60, 0x59, 0x6B, 0x45, 0xE0, 0x4C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3139
3140         SymmetricAlgorithm algo = RC2.Create ();
3141         algo.Mode = CipherMode.ECB;
3142         algo.Padding = PaddingMode.None;
3143         algo.BlockSize = 64;
3144         int blockLength = (algo.BlockSize >> 3);
3145         byte[] input = new byte [blockLength * 2];
3146         byte[] output = new byte [blockLength * 3];
3147         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3148         Encrypt (encryptor, input, output);
3149         AssertEquals ("RC2_k120b64_ECB_None Encrypt", expected, output);
3150
3151         // in ECB the first 2 blocks should be equals (as the IV is not used)
3152         byte[] block1 = new byte[blockLength];
3153         Array.Copy (output, 0, block1, 0, blockLength);
3154         byte[] block2 = new byte[blockLength];
3155         Array.Copy (output, blockLength, block2, 0, blockLength);
3156         AssertEquals ("RC2_k120b64_ECB_None b1==b2", block1, block2);
3157         byte[] reverse = new byte [blockLength * 3];
3158         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3159         Decrypt (decryptor, output, reverse);
3160         byte[] original = new byte [input.Length];
3161         Array.Copy (reverse, 0, original, 0, original.Length);
3162         AssertEquals ("RC2_k120b64_ECB_None Decrypt", input, original);
3163 }
3164
3165
3166 [Test]
3167 public void TestRC2_k120b64_ECB_Zeros ()
3168 {
3169         byte[] key = { 0x1D, 0x13, 0x51, 0x02, 0x28, 0xF4, 0xF0, 0x13, 0x90, 0xFD, 0xE4, 0xC0, 0xE5, 0x57, 0x9A };
3170         // not used for ECB but make the code more uniform
3171         byte[] iv = { 0x9E, 0xC9, 0xA7, 0x52, 0xD2, 0x6E, 0x9B, 0xE4 };
3172         byte[] expected = { 0x23, 0x58, 0x1C, 0x66, 0x7D, 0x2F, 0x71, 0x4F, 0x23, 0x58, 0x1C, 0x66, 0x7D, 0x2F, 0x71, 0x4F, 0x23, 0x58, 0x1C, 0x66, 0x7D, 0x2F, 0x71, 0x4F };
3173
3174         SymmetricAlgorithm algo = RC2.Create ();
3175         algo.Mode = CipherMode.ECB;
3176         algo.Padding = PaddingMode.Zeros;
3177         algo.BlockSize = 64;
3178         int blockLength = (algo.BlockSize >> 3);
3179         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3180         byte[] output = new byte [blockLength * 3];
3181         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3182         Encrypt (encryptor, input, output);
3183         AssertEquals ("RC2_k120b64_ECB_Zeros Encrypt", expected, output);
3184
3185         // in ECB the first 2 blocks should be equals (as the IV is not used)
3186         byte[] block1 = new byte[blockLength];
3187         Array.Copy (output, 0, block1, 0, blockLength);
3188         byte[] block2 = new byte[blockLength];
3189         Array.Copy (output, blockLength, block2, 0, blockLength);
3190         AssertEquals ("RC2_k120b64_ECB_Zeros b1==b2", block1, block2);
3191
3192         // also if padding is Zeros then all three blocks should be equals
3193         byte[] block3 = new byte[blockLength];
3194         Array.Copy (output, blockLength, block3, 0, blockLength);
3195         AssertEquals ("RC2_k120b64_ECB_Zeros b1==b3", block1, block3);
3196
3197         byte[] reverse = new byte [blockLength * 3];
3198         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3199         Decrypt (decryptor, output, reverse);
3200         byte[] original = new byte [input.Length];
3201         Array.Copy (reverse, 0, original, 0, original.Length);
3202         AssertEquals ("RC2_k120b64_ECB_Zeros Decrypt", input, original);
3203 }
3204
3205
3206 [Test]
3207 public void TestRC2_k120b64_ECB_PKCS7 ()
3208 {
3209         byte[] key = { 0x23, 0xF2, 0xFB, 0x09, 0xC1, 0xEF, 0xC1, 0xFF, 0x16, 0xFF, 0x60, 0xC1, 0x3A, 0x94, 0x3E };
3210         // not used for ECB but make the code more uniform
3211         byte[] iv = { 0xB6, 0x10, 0xE3, 0xE9, 0x24, 0x03, 0xCA, 0xAA };
3212         byte[] expected = { 0x92, 0xF3, 0xF0, 0x81, 0x13, 0x40, 0x19, 0x61, 0x92, 0xF3, 0xF0, 0x81, 0x13, 0x40, 0x19, 0x61, 0x36, 0xCC, 0xEC, 0x80, 0xF6, 0xF4, 0xCC, 0xB7 };
3213
3214         SymmetricAlgorithm algo = RC2.Create ();
3215         algo.Mode = CipherMode.ECB;
3216         algo.Padding = PaddingMode.PKCS7;
3217         algo.BlockSize = 64;
3218         int blockLength = (algo.BlockSize >> 3);
3219         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3220         byte[] output = new byte [blockLength * 3];
3221         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3222         Encrypt (encryptor, input, output);
3223         AssertEquals ("RC2_k120b64_ECB_PKCS7 Encrypt", expected, output);
3224
3225         // in ECB the first 2 blocks should be equals (as the IV is not used)
3226         byte[] block1 = new byte[blockLength];
3227         Array.Copy (output, 0, block1, 0, blockLength);
3228         byte[] block2 = new byte[blockLength];
3229         Array.Copy (output, blockLength, block2, 0, blockLength);
3230         AssertEquals ("RC2_k120b64_ECB_PKCS7 b1==b2", block1, block2);
3231         byte[] reverse = new byte [blockLength * 3];
3232         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3233         Decrypt (decryptor, output, reverse);
3234         byte[] original = new byte [input.Length];
3235         Array.Copy (reverse, 0, original, 0, original.Length);
3236         AssertEquals ("RC2_k120b64_ECB_PKCS7 Decrypt", input, original);
3237 }
3238
3239
3240 [Test]
3241 public void TestRC2_k120b64_CBC_None ()
3242 {
3243         byte[] key = { 0x12, 0x43, 0xEE, 0x74, 0xE8, 0x4E, 0x3A, 0xF7, 0x24, 0x58, 0x10, 0xC9, 0x41, 0x7E, 0x46 };
3244         byte[] iv = { 0x7B, 0x57, 0x22, 0x19, 0xFB, 0x30, 0xED, 0x48 };
3245         byte[] expected = { 0x75, 0xB0, 0x41, 0x19, 0x7F, 0x80, 0x91, 0x4A, 0xCD, 0x03, 0x41, 0x59, 0xE4, 0xC0, 0x92, 0xE7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3246
3247         SymmetricAlgorithm algo = RC2.Create ();
3248         algo.Mode = CipherMode.CBC;
3249         algo.Padding = PaddingMode.None;
3250         algo.BlockSize = 64;
3251         int blockLength = (algo.BlockSize >> 3);
3252         byte[] input = new byte [blockLength * 2];
3253         byte[] output = new byte [blockLength * 3];
3254         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3255         Encrypt (encryptor, input, output);
3256         AssertEquals ("RC2_k120b64_CBC_None Encrypt", expected, output);
3257         byte[] reverse = new byte [blockLength * 3];
3258         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3259         Decrypt (decryptor, output, reverse);
3260         byte[] original = new byte [input.Length];
3261         Array.Copy (reverse, 0, original, 0, original.Length);
3262         AssertEquals ("RC2_k120b64_CBC_None Decrypt", input, original);
3263 }
3264
3265
3266 [Test]
3267 public void TestRC2_k120b64_CBC_Zeros ()
3268 {
3269         byte[] key = { 0x2A, 0xCC, 0xFF, 0xD0, 0x46, 0xAF, 0x74, 0xB2, 0x0E, 0x64, 0xBD, 0xE9, 0x6D, 0xC5, 0xE8 };
3270         byte[] iv = { 0x10, 0x21, 0xE3, 0xCB, 0x46, 0x02, 0x33, 0x4F };
3271         byte[] expected = { 0x88, 0x71, 0x0D, 0x01, 0xE9, 0xD3, 0xC7, 0x3F, 0x7E, 0xCA, 0xA7, 0x9A, 0x2D, 0x95, 0xC6, 0xED, 0xDA, 0xAA, 0xE9, 0x23, 0x01, 0x70, 0x6E, 0x59 };
3272
3273         SymmetricAlgorithm algo = RC2.Create ();
3274         algo.Mode = CipherMode.CBC;
3275         algo.Padding = PaddingMode.Zeros;
3276         algo.BlockSize = 64;
3277         int blockLength = (algo.BlockSize >> 3);
3278         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3279         byte[] output = new byte [blockLength * 3];
3280         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3281         Encrypt (encryptor, input, output);
3282         AssertEquals ("RC2_k120b64_CBC_Zeros Encrypt", expected, output);
3283         byte[] reverse = new byte [blockLength * 3];
3284         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3285         Decrypt (decryptor, output, reverse);
3286         byte[] original = new byte [input.Length];
3287         Array.Copy (reverse, 0, original, 0, original.Length);
3288         AssertEquals ("RC2_k120b64_CBC_Zeros Decrypt", input, original);
3289 }
3290
3291
3292 [Test]
3293 public void TestRC2_k120b64_CBC_PKCS7 ()
3294 {
3295         byte[] key = { 0xE8, 0xE8, 0x44, 0x9D, 0xEA, 0x33, 0x10, 0xCB, 0xEA, 0xEF, 0x69, 0x94, 0xE4, 0x31, 0xF0 };
3296         byte[] iv = { 0xC7, 0x0F, 0xE1, 0x79, 0x2B, 0x57, 0x5D, 0xA7 };
3297         byte[] expected = { 0x7E, 0x1F, 0xD6, 0xCF, 0xB1, 0xAE, 0xC0, 0x2C, 0xD6, 0x02, 0x01, 0x62, 0x77, 0x95, 0x02, 0xE8, 0x8D, 0xEC, 0x8D, 0xCC, 0xB2, 0x6B, 0x92, 0x7A };
3298
3299         SymmetricAlgorithm algo = RC2.Create ();
3300         algo.Mode = CipherMode.CBC;
3301         algo.Padding = PaddingMode.PKCS7;
3302         algo.BlockSize = 64;
3303         int blockLength = (algo.BlockSize >> 3);
3304         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3305         byte[] output = new byte [blockLength * 3];
3306         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3307         Encrypt (encryptor, input, output);
3308         AssertEquals ("RC2_k120b64_CBC_PKCS7 Encrypt", expected, output);
3309         byte[] reverse = new byte [blockLength * 3];
3310         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3311         Decrypt (decryptor, output, reverse);
3312         byte[] original = new byte [input.Length];
3313         Array.Copy (reverse, 0, original, 0, original.Length);
3314         AssertEquals ("RC2_k120b64_CBC_PKCS7 Decrypt", input, original);
3315 }
3316
3317
3318 /* Invalid parameters RC2_k120b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
3319
3320 /* Invalid parameters RC2_k120b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
3321
3322 /* Invalid parameters RC2_k120b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
3323
3324 [Test]
3325 public void TestRC2_k120b64_CFB8_None ()
3326 {
3327         byte[] key = { 0x0F, 0x0D, 0x1F, 0x09, 0xC2, 0xEA, 0xC5, 0xFE, 0xD1, 0x5A, 0x4C, 0x39, 0x2E, 0x62, 0xED };
3328         byte[] iv = { 0xCA, 0x90, 0x74, 0xAD, 0x6B, 0xD5, 0x42, 0xCF };
3329         byte[] expected = { 0xEB, 0xC3, 0xF4, 0x08, 0xCF, 0x11, 0x3E, 0xC4, 0x98, 0x8A, 0xAB, 0x6F, 0xEE, 0x32, 0xFC, 0x2B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3330
3331         SymmetricAlgorithm algo = RC2.Create ();
3332         algo.Mode = CipherMode.CFB;
3333         algo.Padding = PaddingMode.None;
3334         algo.BlockSize = 64;
3335         algo.FeedbackSize = 8;
3336         int blockLength = (algo.BlockSize >> 3);
3337         byte[] input = new byte [blockLength * 2];
3338         byte[] output = new byte [blockLength * 3];
3339         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3340         Encrypt (encryptor, input, output);
3341         AssertEquals ("RC2_k120b64_CFB8_None Encrypt", expected, output);
3342         byte[] reverse = new byte [blockLength * 3];
3343         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3344         Decrypt (decryptor, output, reverse);
3345         byte[] original = new byte [input.Length];
3346         Array.Copy (reverse, 0, original, 0, original.Length);
3347         AssertEquals ("RC2_k120b64_CFB8_None Decrypt", input, original);
3348 }
3349
3350
3351 [Test]
3352 public void TestRC2_k120b64_CFB8_Zeros ()
3353 {
3354         byte[] key = { 0xDA, 0xAD, 0xD7, 0xFB, 0x36, 0x64, 0x3B, 0xE8, 0x35, 0x64, 0xC8, 0xAF, 0x0D, 0xB3, 0xAC };
3355         byte[] iv = { 0x6B, 0x99, 0x8D, 0xCA, 0x51, 0xD8, 0x26, 0x48 };
3356         byte[] expected = { 0xDE, 0xED, 0xF4, 0xA8, 0x9D, 0x5C, 0xCE, 0x22, 0x7A, 0xD5, 0x1B, 0x3F, 0x89, 0x6E, 0x91, 0x61, 0xE1, 0x44, 0x1E, 0x5C, 0xFA, 0xC1, 0x40, 0x97 };
3357
3358         SymmetricAlgorithm algo = RC2.Create ();
3359         algo.Mode = CipherMode.CFB;
3360         algo.Padding = PaddingMode.Zeros;
3361         algo.BlockSize = 64;
3362         algo.FeedbackSize = 8;
3363         int blockLength = (algo.BlockSize >> 3);
3364         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3365         byte[] output = new byte [blockLength * 3];
3366         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3367         Encrypt (encryptor, input, output);
3368         AssertEquals ("RC2_k120b64_CFB8_Zeros Encrypt", expected, output);
3369         byte[] reverse = new byte [blockLength * 3];
3370         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3371         Decrypt (decryptor, output, reverse);
3372         byte[] original = new byte [input.Length];
3373         Array.Copy (reverse, 0, original, 0, original.Length);
3374         AssertEquals ("RC2_k120b64_CFB8_Zeros Decrypt", input, original);
3375 }
3376
3377
3378 [Test]
3379 public void TestRC2_k120b64_CFB8_PKCS7 ()
3380 {
3381         byte[] key = { 0x26, 0xA9, 0xE5, 0xE2, 0xE4, 0x48, 0xB5, 0x9F, 0xAC, 0x3E, 0x77, 0xB0, 0xEF, 0x1B, 0x00 };
3382         byte[] iv = { 0x0E, 0x98, 0x7F, 0xC4, 0xAC, 0x08, 0x94, 0x03 };
3383         byte[] expected = { 0xAD, 0xEC, 0xD6, 0x71, 0xDF, 0x36, 0x69, 0x80, 0xE6, 0x74, 0x79, 0xC2, 0xE0, 0xDF, 0xCF, 0xD8, 0xB4, 0x3A, 0x22, 0x6F, 0x41, 0xAD, 0x77, 0x4D };
3384
3385         SymmetricAlgorithm algo = RC2.Create ();
3386         algo.Mode = CipherMode.CFB;
3387         algo.Padding = PaddingMode.PKCS7;
3388         algo.BlockSize = 64;
3389         algo.FeedbackSize = 8;
3390         int blockLength = (algo.BlockSize >> 3);
3391         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3392         byte[] output = new byte [blockLength * 3];
3393         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3394         Encrypt (encryptor, input, output);
3395         AssertEquals ("RC2_k120b64_CFB8_PKCS7 Encrypt", expected, output);
3396         byte[] reverse = new byte [blockLength * 3];
3397         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3398         Decrypt (decryptor, output, reverse);
3399         byte[] original = new byte [input.Length];
3400         Array.Copy (reverse, 0, original, 0, original.Length);
3401         AssertEquals ("RC2_k120b64_CFB8_PKCS7 Decrypt", input, original);
3402 }
3403
3404
3405 /* Invalid parameters RC2_k120b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
3406
3407 /* Invalid parameters RC2_k120b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
3408
3409 /* Invalid parameters RC2_k120b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
3410
3411 [Test]
3412 public void TestRC2_k128b64_ECB_None ()
3413 {
3414         byte[] key = { 0x4F, 0x02, 0xB1, 0xA6, 0x5E, 0xAE, 0xB9, 0x0C, 0x3A, 0x96, 0xFF, 0x62, 0x90, 0x9A, 0xD8, 0x1B };
3415         // not used for ECB but make the code more uniform
3416         byte[] iv = { 0xC7, 0x89, 0x19, 0x4F, 0x3C, 0xC3, 0x05, 0x83 };
3417         byte[] expected = { 0xC8, 0x83, 0x4D, 0xE2, 0x6A, 0xFA, 0x75, 0x41, 0xC8, 0x83, 0x4D, 0xE2, 0x6A, 0xFA, 0x75, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3418
3419         SymmetricAlgorithm algo = RC2.Create ();
3420         algo.Mode = CipherMode.ECB;
3421         algo.Padding = PaddingMode.None;
3422         algo.BlockSize = 64;
3423         int blockLength = (algo.BlockSize >> 3);
3424         byte[] input = new byte [blockLength * 2];
3425         byte[] output = new byte [blockLength * 3];
3426         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3427         Encrypt (encryptor, input, output);
3428         AssertEquals ("RC2_k128b64_ECB_None Encrypt", expected, output);
3429
3430         // in ECB the first 2 blocks should be equals (as the IV is not used)
3431         byte[] block1 = new byte[blockLength];
3432         Array.Copy (output, 0, block1, 0, blockLength);
3433         byte[] block2 = new byte[blockLength];
3434         Array.Copy (output, blockLength, block2, 0, blockLength);
3435         AssertEquals ("RC2_k128b64_ECB_None b1==b2", block1, block2);
3436         byte[] reverse = new byte [blockLength * 3];
3437         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3438         Decrypt (decryptor, output, reverse);
3439         byte[] original = new byte [input.Length];
3440         Array.Copy (reverse, 0, original, 0, original.Length);
3441         AssertEquals ("RC2_k128b64_ECB_None Decrypt", input, original);
3442 }
3443
3444
3445 [Test]
3446 public void TestRC2_k128b64_ECB_Zeros ()
3447 {
3448         byte[] key = { 0x45, 0xBE, 0xD8, 0x8E, 0x0A, 0xE7, 0xF9, 0xE2, 0x3C, 0x33, 0xE7, 0x93, 0xD4, 0x9D, 0xAE, 0x2B };
3449         // not used for ECB but make the code more uniform
3450         byte[] iv = { 0x83, 0x27, 0x57, 0x97, 0x06, 0x4F, 0xFE, 0xB3 };
3451         byte[] expected = { 0x28, 0x59, 0x45, 0xF6, 0x5E, 0x4F, 0x97, 0xF3, 0x28, 0x59, 0x45, 0xF6, 0x5E, 0x4F, 0x97, 0xF3, 0x28, 0x59, 0x45, 0xF6, 0x5E, 0x4F, 0x97, 0xF3 };
3452
3453         SymmetricAlgorithm algo = RC2.Create ();
3454         algo.Mode = CipherMode.ECB;
3455         algo.Padding = PaddingMode.Zeros;
3456         algo.BlockSize = 64;
3457         int blockLength = (algo.BlockSize >> 3);
3458         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3459         byte[] output = new byte [blockLength * 3];
3460         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3461         Encrypt (encryptor, input, output);
3462         AssertEquals ("RC2_k128b64_ECB_Zeros Encrypt", expected, output);
3463
3464         // in ECB the first 2 blocks should be equals (as the IV is not used)
3465         byte[] block1 = new byte[blockLength];
3466         Array.Copy (output, 0, block1, 0, blockLength);
3467         byte[] block2 = new byte[blockLength];
3468         Array.Copy (output, blockLength, block2, 0, blockLength);
3469         AssertEquals ("RC2_k128b64_ECB_Zeros b1==b2", block1, block2);
3470
3471         // also if padding is Zeros then all three blocks should be equals
3472         byte[] block3 = new byte[blockLength];
3473         Array.Copy (output, blockLength, block3, 0, blockLength);
3474         AssertEquals ("RC2_k128b64_ECB_Zeros b1==b3", block1, block3);
3475
3476         byte[] reverse = new byte [blockLength * 3];
3477         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3478         Decrypt (decryptor, output, reverse);
3479         byte[] original = new byte [input.Length];
3480         Array.Copy (reverse, 0, original, 0, original.Length);
3481         AssertEquals ("RC2_k128b64_ECB_Zeros Decrypt", input, original);
3482 }
3483
3484
3485 [Test]
3486 public void TestRC2_k128b64_ECB_PKCS7 ()
3487 {
3488         byte[] key = { 0x6F, 0x04, 0x76, 0x7D, 0x88, 0x01, 0x29, 0x6A, 0xD5, 0x1E, 0x38, 0x9D, 0xED, 0x56, 0xAC, 0x9C };
3489         // not used for ECB but make the code more uniform
3490         byte[] iv = { 0x82, 0x74, 0xAC, 0xAA, 0x42, 0x29, 0x35, 0x8D };
3491         byte[] expected = { 0xCB, 0xE5, 0xBB, 0xCC, 0x99, 0x8D, 0x1D, 0xA6, 0xCB, 0xE5, 0xBB, 0xCC, 0x99, 0x8D, 0x1D, 0xA6, 0x5B, 0x35, 0x28, 0xE7, 0xAC, 0xFE, 0xF0, 0xD1 };
3492
3493         SymmetricAlgorithm algo = RC2.Create ();
3494         algo.Mode = CipherMode.ECB;
3495         algo.Padding = PaddingMode.PKCS7;
3496         algo.BlockSize = 64;
3497         int blockLength = (algo.BlockSize >> 3);
3498         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3499         byte[] output = new byte [blockLength * 3];
3500         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3501         Encrypt (encryptor, input, output);
3502         AssertEquals ("RC2_k128b64_ECB_PKCS7 Encrypt", expected, output);
3503
3504         // in ECB the first 2 blocks should be equals (as the IV is not used)
3505         byte[] block1 = new byte[blockLength];
3506         Array.Copy (output, 0, block1, 0, blockLength);
3507         byte[] block2 = new byte[blockLength];
3508         Array.Copy (output, blockLength, block2, 0, blockLength);
3509         AssertEquals ("RC2_k128b64_ECB_PKCS7 b1==b2", block1, block2);
3510         byte[] reverse = new byte [blockLength * 3];
3511         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3512         Decrypt (decryptor, output, reverse);
3513         byte[] original = new byte [input.Length];
3514         Array.Copy (reverse, 0, original, 0, original.Length);
3515         AssertEquals ("RC2_k128b64_ECB_PKCS7 Decrypt", input, original);
3516 }
3517
3518
3519 [Test]
3520 public void TestRC2_k128b64_CBC_None ()
3521 {
3522         byte[] key = { 0x17, 0x3F, 0x40, 0xF3, 0xDC, 0xFF, 0x8F, 0xF2, 0x71, 0x2E, 0x8B, 0x6A, 0xE0, 0x2E, 0x3F, 0x82 };
3523         byte[] iv = { 0xFA, 0xB4, 0x41, 0x91, 0x34, 0xFC, 0x9B, 0x49 };
3524         byte[] expected = { 0x05, 0x1B, 0x27, 0x78, 0xF0, 0x3D, 0xC4, 0x77, 0x9E, 0x59, 0x27, 0xEC, 0x2D, 0x1D, 0x7F, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3525
3526         SymmetricAlgorithm algo = RC2.Create ();
3527         algo.Mode = CipherMode.CBC;
3528         algo.Padding = PaddingMode.None;
3529         algo.BlockSize = 64;
3530         int blockLength = (algo.BlockSize >> 3);
3531         byte[] input = new byte [blockLength * 2];
3532         byte[] output = new byte [blockLength * 3];
3533         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3534         Encrypt (encryptor, input, output);
3535         AssertEquals ("RC2_k128b64_CBC_None Encrypt", expected, output);
3536         byte[] reverse = new byte [blockLength * 3];
3537         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3538         Decrypt (decryptor, output, reverse);
3539         byte[] original = new byte [input.Length];
3540         Array.Copy (reverse, 0, original, 0, original.Length);
3541         AssertEquals ("RC2_k128b64_CBC_None Decrypt", input, original);
3542 }
3543
3544
3545 [Test]
3546 public void TestRC2_k128b64_CBC_Zeros ()
3547 {
3548         byte[] key = { 0x49, 0x89, 0x3E, 0x29, 0xCB, 0xB9, 0x06, 0x85, 0x7F, 0x8B, 0x86, 0xEB, 0xD7, 0x47, 0x91, 0x1D };
3549         byte[] iv = { 0xCB, 0xA1, 0x0F, 0x53, 0x7B, 0x71, 0x04, 0x89 };
3550         byte[] expected = { 0x17, 0x58, 0xD1, 0xF4, 0x1E, 0x58, 0xB0, 0x10, 0x31, 0x17, 0x40, 0x3F, 0x40, 0x22, 0x75, 0x32, 0x4F, 0xDE, 0x64, 0xE0, 0x66, 0xF4, 0xF7, 0xA0 };
3551
3552         SymmetricAlgorithm algo = RC2.Create ();
3553         algo.Mode = CipherMode.CBC;
3554         algo.Padding = PaddingMode.Zeros;
3555         algo.BlockSize = 64;
3556         int blockLength = (algo.BlockSize >> 3);
3557         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3558         byte[] output = new byte [blockLength * 3];
3559         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3560         Encrypt (encryptor, input, output);
3561         AssertEquals ("RC2_k128b64_CBC_Zeros Encrypt", expected, output);
3562         byte[] reverse = new byte [blockLength * 3];
3563         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3564         Decrypt (decryptor, output, reverse);
3565         byte[] original = new byte [input.Length];
3566         Array.Copy (reverse, 0, original, 0, original.Length);
3567         AssertEquals ("RC2_k128b64_CBC_Zeros Decrypt", input, original);
3568 }
3569
3570
3571 [Test]
3572 public void TestRC2_k128b64_CBC_PKCS7 ()
3573 {
3574         byte[] key = { 0x22, 0x04, 0xDB, 0x15, 0xD6, 0x2E, 0xEF, 0x6D, 0x5D, 0x6A, 0xDA, 0x55, 0x67, 0x41, 0x4E, 0xFD };
3575         byte[] iv = { 0xB8, 0xD1, 0xD8, 0x23, 0x00, 0x39, 0x89, 0x83 };
3576         byte[] expected = { 0xC8, 0x4F, 0xCC, 0x05, 0x7F, 0x44, 0x49, 0xBE, 0x73, 0x78, 0xE8, 0x7B, 0xD9, 0xB1, 0x56, 0xC3, 0x37, 0x1E, 0xBE, 0x4D, 0x2B, 0x2F, 0xC7, 0x9E };
3577
3578         SymmetricAlgorithm algo = RC2.Create ();
3579         algo.Mode = CipherMode.CBC;
3580         algo.Padding = PaddingMode.PKCS7;
3581         algo.BlockSize = 64;
3582         int blockLength = (algo.BlockSize >> 3);
3583         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3584         byte[] output = new byte [blockLength * 3];
3585         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3586         Encrypt (encryptor, input, output);
3587         AssertEquals ("RC2_k128b64_CBC_PKCS7 Encrypt", expected, output);
3588         byte[] reverse = new byte [blockLength * 3];
3589         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3590         Decrypt (decryptor, output, reverse);
3591         byte[] original = new byte [input.Length];
3592         Array.Copy (reverse, 0, original, 0, original.Length);
3593         AssertEquals ("RC2_k128b64_CBC_PKCS7 Decrypt", input, original);
3594 }
3595
3596
3597 /* Invalid parameters RC2_k128b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
3598
3599 /* Invalid parameters RC2_k128b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
3600
3601 /* Invalid parameters RC2_k128b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
3602
3603 [Test]
3604 public void TestRC2_k128b64_CFB8_None ()
3605 {
3606         byte[] key = { 0x61, 0x93, 0x31, 0x3A, 0xC2, 0x9B, 0x53, 0xB1, 0x26, 0x64, 0x36, 0x03, 0x16, 0x4A, 0xE3, 0x99 };
3607         byte[] iv = { 0xDD, 0xAD, 0xA4, 0x57, 0xC1, 0x21, 0xF1, 0xA8 };
3608         byte[] expected = { 0x94, 0xD9, 0x62, 0x83, 0x80, 0x4C, 0x91, 0x90, 0x63, 0x41, 0xBC, 0xBD, 0x8B, 0x7F, 0xD9, 0xB1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3609
3610         SymmetricAlgorithm algo = RC2.Create ();
3611         algo.Mode = CipherMode.CFB;
3612         algo.Padding = PaddingMode.None;
3613         algo.BlockSize = 64;
3614         algo.FeedbackSize = 8;
3615         int blockLength = (algo.BlockSize >> 3);
3616         byte[] input = new byte [blockLength * 2];
3617         byte[] output = new byte [blockLength * 3];
3618         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3619         Encrypt (encryptor, input, output);
3620         AssertEquals ("RC2_k128b64_CFB8_None Encrypt", expected, output);
3621         byte[] reverse = new byte [blockLength * 3];
3622         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3623         Decrypt (decryptor, output, reverse);
3624         byte[] original = new byte [input.Length];
3625         Array.Copy (reverse, 0, original, 0, original.Length);
3626         AssertEquals ("RC2_k128b64_CFB8_None Decrypt", input, original);
3627 }
3628
3629
3630 [Test]
3631 public void TestRC2_k128b64_CFB8_Zeros ()
3632 {
3633         byte[] key = { 0x64, 0x09, 0x9A, 0xF0, 0xD2, 0x52, 0x8C, 0x03, 0xF3, 0xBF, 0x1B, 0x9B, 0x92, 0x0E, 0xBA, 0x33 };
3634         byte[] iv = { 0x15, 0x64, 0xE4, 0xFA, 0xFA, 0x58, 0x54, 0x7B };
3635         byte[] expected = { 0xC8, 0x8F, 0xCC, 0x77, 0xA3, 0x82, 0x31, 0xD4, 0x7A, 0x68, 0x05, 0x8F, 0xF2, 0x1B, 0x9E, 0xCC, 0xDA, 0x6F, 0x74, 0x1D, 0x43, 0xE0, 0x90, 0x8B };
3636
3637         SymmetricAlgorithm algo = RC2.Create ();
3638         algo.Mode = CipherMode.CFB;
3639         algo.Padding = PaddingMode.Zeros;
3640         algo.BlockSize = 64;
3641         algo.FeedbackSize = 8;
3642         int blockLength = (algo.BlockSize >> 3);
3643         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3644         byte[] output = new byte [blockLength * 3];
3645         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3646         Encrypt (encryptor, input, output);
3647         AssertEquals ("RC2_k128b64_CFB8_Zeros Encrypt", expected, output);
3648         byte[] reverse = new byte [blockLength * 3];
3649         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3650         Decrypt (decryptor, output, reverse);
3651         byte[] original = new byte [input.Length];
3652         Array.Copy (reverse, 0, original, 0, original.Length);
3653         AssertEquals ("RC2_k128b64_CFB8_Zeros Decrypt", input, original);
3654 }
3655
3656
3657 [Test]
3658 public void TestRC2_k128b64_CFB8_PKCS7 ()
3659 {
3660         byte[] key = { 0x1F, 0x09, 0xF8, 0x1B, 0xA9, 0xA4, 0x70, 0x8D, 0x53, 0x76, 0x19, 0x4A, 0xAA, 0x62, 0x84, 0x94 };
3661         byte[] iv = { 0xCC, 0x7B, 0xBE, 0xE9, 0xEE, 0x8E, 0x9C, 0x02 };
3662         byte[] expected = { 0xA7, 0x1B, 0xD5, 0x4E, 0xDB, 0xF7, 0x84, 0xC2, 0xAA, 0x89, 0xAA, 0x3C, 0x3A, 0x63, 0x8A, 0xB2, 0xEF, 0x0C, 0x5B, 0xB0, 0xF4, 0xD9, 0x0A, 0x46 };
3663
3664         SymmetricAlgorithm algo = RC2.Create ();
3665         algo.Mode = CipherMode.CFB;
3666         algo.Padding = PaddingMode.PKCS7;
3667         algo.BlockSize = 64;
3668         algo.FeedbackSize = 8;
3669         int blockLength = (algo.BlockSize >> 3);
3670         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3671         byte[] output = new byte [blockLength * 3];
3672         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3673         Encrypt (encryptor, input, output);
3674         AssertEquals ("RC2_k128b64_CFB8_PKCS7 Encrypt", expected, output);
3675         byte[] reverse = new byte [blockLength * 3];
3676         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3677         Decrypt (decryptor, output, reverse);
3678         byte[] original = new byte [input.Length];
3679         Array.Copy (reverse, 0, original, 0, original.Length);
3680         AssertEquals ("RC2_k128b64_CFB8_PKCS7 Decrypt", input, original);
3681 }
3682
3683
3684 /* Invalid parameters RC2_k128b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
3685
3686 /* Invalid parameters RC2_k128b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
3687
3688 /* Invalid parameters RC2_k128b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
3689
3690 [Test]
3691 public void TestRijndael_k128b128_ECB_None ()
3692 {
3693         byte[] key = { 0xAF, 0x4D, 0xFE, 0x58, 0x33, 0xAC, 0x91, 0xB2, 0xFA, 0xA3, 0x96, 0x54, 0x0B, 0x68, 0xDD, 0xA1 };
3694         // not used for ECB but make the code more uniform
3695         byte[] iv = { 0xAF, 0x70, 0xC2, 0x2E, 0x2D, 0xF1, 0x0D, 0x7F, 0x52, 0xF4, 0x65, 0x79, 0x78, 0xAC, 0x80, 0xEF };
3696         byte[] expected = { 0x6D, 0xC2, 0x4A, 0x51, 0x2D, 0xAB, 0x67, 0xCB, 0xD8, 0xD4, 0xD5, 0xE6, 0x0B, 0x24, 0x02, 0x90, 0x6D, 0xC2, 0x4A, 0x51, 0x2D, 0xAB, 0x67, 0xCB, 0xD8, 0xD4, 0xD5, 0xE6, 0x0B, 0x24, 0x02, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3697
3698         SymmetricAlgorithm algo = Rijndael.Create ();
3699         algo.Mode = CipherMode.ECB;
3700         algo.Padding = PaddingMode.None;
3701         algo.BlockSize = 128;
3702         int blockLength = (algo.BlockSize >> 3);
3703         byte[] input = new byte [blockLength * 2];
3704         byte[] output = new byte [blockLength * 3];
3705         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3706         Encrypt (encryptor, input, output);
3707         AssertEquals ("Rijndael_k128b128_ECB_None Encrypt", expected, output);
3708
3709         // in ECB the first 2 blocks should be equals (as the IV is not used)
3710         byte[] block1 = new byte[blockLength];
3711         Array.Copy (output, 0, block1, 0, blockLength);
3712         byte[] block2 = new byte[blockLength];
3713         Array.Copy (output, blockLength, block2, 0, blockLength);
3714         AssertEquals ("Rijndael_k128b128_ECB_None b1==b2", block1, block2);
3715         byte[] reverse = new byte [blockLength * 3];
3716         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3717         Decrypt (decryptor, output, reverse);
3718         byte[] original = new byte [input.Length];
3719         Array.Copy (reverse, 0, original, 0, original.Length);
3720         AssertEquals ("Rijndael_k128b128_ECB_None Decrypt", input, original);
3721 }
3722
3723
3724 [Test]
3725 public void TestRijndael_k128b128_ECB_Zeros ()
3726 {
3727         byte[] key = { 0xA4, 0x39, 0x01, 0x00, 0xDB, 0x0A, 0x47, 0xD8, 0xD8, 0xDC, 0x01, 0xF4, 0xBE, 0x96, 0xF4, 0xBB };
3728         // not used for ECB but make the code more uniform
3729         byte[] iv = { 0xEA, 0xBD, 0x55, 0x85, 0x3F, 0xC1, 0x5F, 0xCB, 0x06, 0x26, 0x3F, 0x88, 0x6A, 0x2D, 0x69, 0x45 };
3730         byte[] expected = { 0x19, 0x32, 0x7E, 0x79, 0xE3, 0xC1, 0xFE, 0xA0, 0xFD, 0x26, 0x27, 0x61, 0xC0, 0xB8, 0x06, 0xC2, 0x19, 0x32, 0x7E, 0x79, 0xE3, 0xC1, 0xFE, 0xA0, 0xFD, 0x26, 0x27, 0x61, 0xC0, 0xB8, 0x06, 0xC2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3731
3732         SymmetricAlgorithm algo = Rijndael.Create ();
3733         algo.Mode = CipherMode.ECB;
3734         algo.Padding = PaddingMode.Zeros;
3735         algo.BlockSize = 128;
3736         int blockLength = (algo.BlockSize >> 3);
3737         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3738         byte[] output = new byte [blockLength * 3];
3739         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3740         // some exception can be normal... other not so!
3741         try {
3742                 Encrypt (encryptor, input, output);
3743         }
3744         catch (Exception e) {
3745                 if (e.Message != "Input buffer contains insufficient data. ")
3746                         Assert.Fail ("Rijndael_k128b128_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
3747         }
3748 }
3749
3750
3751 [Test]
3752 public void TestRijndael_k128b128_ECB_PKCS7 ()
3753 {
3754         byte[] key = { 0x5C, 0x58, 0x03, 0x1D, 0x05, 0x07, 0xDE, 0x93, 0x8D, 0x85, 0xFD, 0x50, 0x68, 0xA3, 0xD7, 0x6B };
3755         // not used for ECB but make the code more uniform
3756         byte[] iv = { 0x1C, 0x32, 0xFE, 0x99, 0x95, 0x16, 0x74, 0xC0, 0x6F, 0xE6, 0x01, 0x2C, 0x1F, 0x07, 0x54, 0xE8 };
3757         byte[] expected = { 0xEE, 0x1C, 0x0B, 0x2F, 0x1E, 0xCE, 0x69, 0xBC, 0xEA, 0xF6, 0xED, 0xA9, 0xF0, 0xE3, 0xE7, 0xC3, 0xEE, 0x1C, 0x0B, 0x2F, 0x1E, 0xCE, 0x69, 0xBC, 0xEA, 0xF6, 0xED, 0xA9, 0xF0, 0xE3, 0xE7, 0xC3, 0x2E, 0xB4, 0x6F, 0x8C, 0xD3, 0x37, 0xF4, 0x8E, 0x6D, 0x08, 0x35, 0x47, 0xD1, 0x1A, 0xB2, 0xA0 };
3758
3759         SymmetricAlgorithm algo = Rijndael.Create ();
3760         algo.Mode = CipherMode.ECB;
3761         algo.Padding = PaddingMode.PKCS7;
3762         algo.BlockSize = 128;
3763         int blockLength = (algo.BlockSize >> 3);
3764         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3765         byte[] output = new byte [blockLength * 3];
3766         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3767         Encrypt (encryptor, input, output);
3768         AssertEquals ("Rijndael_k128b128_ECB_PKCS7 Encrypt", expected, output);
3769
3770         // in ECB the first 2 blocks should be equals (as the IV is not used)
3771         byte[] block1 = new byte[blockLength];
3772         Array.Copy (output, 0, block1, 0, blockLength);
3773         byte[] block2 = new byte[blockLength];
3774         Array.Copy (output, blockLength, block2, 0, blockLength);
3775         AssertEquals ("Rijndael_k128b128_ECB_PKCS7 b1==b2", block1, block2);
3776         byte[] reverse = new byte [blockLength * 3];
3777         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3778         Decrypt (decryptor, output, reverse);
3779         byte[] original = new byte [input.Length];
3780         Array.Copy (reverse, 0, original, 0, original.Length);
3781         AssertEquals ("Rijndael_k128b128_ECB_PKCS7 Decrypt", input, original);
3782 }
3783
3784
3785 [Test]
3786 public void TestRijndael_k128b128_CBC_None ()
3787 {
3788         byte[] key = { 0xED, 0xE4, 0xD9, 0x97, 0x8E, 0x5C, 0xF8, 0x86, 0xFE, 0x6B, 0xF4, 0xA7, 0x26, 0xDA, 0x70, 0x47 };
3789         byte[] iv = { 0x06, 0xE1, 0xA5, 0x97, 0x7E, 0x20, 0x0C, 0x47, 0xA4, 0xAF, 0xB8, 0xF3, 0x8D, 0x2E, 0xA9, 0xAC };
3790         byte[] expected = { 0xB1, 0x73, 0xDA, 0x05, 0x4C, 0x0D, 0x6C, 0x5D, 0x60, 0x72, 0x76, 0x79, 0x64, 0xA6, 0x45, 0x89, 0xA5, 0xCD, 0x35, 0x2C, 0x56, 0x12, 0x7D, 0xA6, 0x84, 0x36, 0xEB, 0xCC, 0xDF, 0x5C, 0xCB, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3791
3792         SymmetricAlgorithm algo = Rijndael.Create ();
3793         algo.Mode = CipherMode.CBC;
3794         algo.Padding = PaddingMode.None;
3795         algo.BlockSize = 128;
3796         int blockLength = (algo.BlockSize >> 3);
3797         byte[] input = new byte [blockLength * 2];
3798         byte[] output = new byte [blockLength * 3];
3799         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3800         Encrypt (encryptor, input, output);
3801         AssertEquals ("Rijndael_k128b128_CBC_None Encrypt", expected, output);
3802         byte[] reverse = new byte [blockLength * 3];
3803         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3804         Decrypt (decryptor, output, reverse);
3805         byte[] original = new byte [input.Length];
3806         Array.Copy (reverse, 0, original, 0, original.Length);
3807         AssertEquals ("Rijndael_k128b128_CBC_None Decrypt", input, original);
3808 }
3809
3810
3811 [Test]
3812 public void TestRijndael_k128b128_CBC_Zeros ()
3813 {
3814         byte[] key = { 0x7F, 0x03, 0x95, 0x4E, 0x42, 0x9E, 0x83, 0x85, 0x4B, 0x1A, 0x87, 0x36, 0xA1, 0x5B, 0xA8, 0x24 };
3815         byte[] iv = { 0x75, 0x49, 0x7B, 0xBE, 0x78, 0x55, 0x5F, 0xE9, 0x67, 0xCB, 0x7E, 0x30, 0x71, 0xD1, 0x36, 0x49 };
3816         byte[] expected = { 0xC8, 0xE2, 0xE5, 0x14, 0x17, 0x10, 0x14, 0xA5, 0x14, 0x8E, 0x59, 0x82, 0x7C, 0x92, 0x12, 0x91, 0x49, 0xE4, 0x24, 0x2C, 0x38, 0x98, 0x91, 0x0B, 0xD8, 0x5C, 0xD0, 0x79, 0xCD, 0x35, 0x85, 0x6B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3817
3818         SymmetricAlgorithm algo = Rijndael.Create ();
3819         algo.Mode = CipherMode.CBC;
3820         algo.Padding = PaddingMode.Zeros;
3821         algo.BlockSize = 128;
3822         int blockLength = (algo.BlockSize >> 3);
3823         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3824         byte[] output = new byte [blockLength * 3];
3825         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3826         // some exception can be normal... other not so!
3827         try {
3828                 Encrypt (encryptor, input, output);
3829         }
3830         catch (Exception e) {
3831                 if (e.Message != "Input buffer contains insufficient data. ")
3832                         Assert.Fail ("Rijndael_k128b128_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
3833         }
3834 }
3835
3836
3837 [Test]
3838 public void TestRijndael_k128b128_CBC_PKCS7 ()
3839 {
3840         byte[] key = { 0x02, 0xE6, 0xC1, 0xE2, 0x7E, 0x89, 0xB9, 0x04, 0xE7, 0x9A, 0xB8, 0x83, 0xA4, 0xF8, 0x1B, 0x64 };
3841         byte[] iv = { 0xBC, 0xE4, 0x47, 0x1E, 0xD0, 0xDD, 0x09, 0x0D, 0xFC, 0xA1, 0x44, 0xCD, 0x88, 0x92, 0x41, 0xA5 };
3842         byte[] expected = { 0xEA, 0xB3, 0x9D, 0xCC, 0xE6, 0x74, 0x22, 0xE5, 0x15, 0xEE, 0x1C, 0xA9, 0x48, 0xB9, 0x55, 0x01, 0xEA, 0x9F, 0x98, 0x8D, 0x5D, 0x59, 0xB1, 0x1C, 0xEC, 0xE5, 0x68, 0xEE, 0x86, 0x22, 0x17, 0xBA, 0x95, 0x7D, 0xEC, 0x06, 0x4B, 0x48, 0x90, 0x0E, 0x75, 0x38, 0xC0, 0x28, 0x7D, 0x72, 0x32, 0xF8 };
3843
3844         SymmetricAlgorithm algo = Rijndael.Create ();
3845         algo.Mode = CipherMode.CBC;
3846         algo.Padding = PaddingMode.PKCS7;
3847         algo.BlockSize = 128;
3848         int blockLength = (algo.BlockSize >> 3);
3849         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3850         byte[] output = new byte [blockLength * 3];
3851         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3852         Encrypt (encryptor, input, output);
3853         AssertEquals ("Rijndael_k128b128_CBC_PKCS7 Encrypt", expected, output);
3854         byte[] reverse = new byte [blockLength * 3];
3855         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3856         Decrypt (decryptor, output, reverse);
3857         byte[] original = new byte [input.Length];
3858         Array.Copy (reverse, 0, original, 0, original.Length);
3859         AssertEquals ("Rijndael_k128b128_CBC_PKCS7 Decrypt", input, original);
3860 }
3861
3862
3863 /* Invalid parameters Rijndael_k128b128_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
3864
3865 /* Invalid parameters Rijndael_k128b128_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
3866
3867 /* Invalid parameters Rijndael_k128b128_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
3868
3869 /* Invalid parameters Rijndael_k128b128_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
3870
3871 /* Invalid parameters Rijndael_k128b128_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
3872
3873 /* Invalid parameters Rijndael_k128b128_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
3874
3875 /* Invalid parameters Rijndael_k128b128_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
3876
3877 /* Invalid parameters Rijndael_k128b128_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
3878
3879 /* Invalid parameters Rijndael_k128b128_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
3880
3881 [Test]
3882 public void TestRijndael_k128b192_ECB_None ()
3883 {
3884         byte[] key = { 0xA5, 0x7F, 0xA2, 0x9F, 0xDA, 0xEE, 0x56, 0x2E, 0xF9, 0x3A, 0xEE, 0x1E, 0x30, 0x46, 0x80, 0x66 };
3885         // not used for ECB but make the code more uniform
3886         byte[] iv = { 0x81, 0xE8, 0x4F, 0x8A, 0xFC, 0xD0, 0x12, 0xB3, 0xF8, 0x1F, 0x30, 0xE2, 0x40, 0x90, 0xFB, 0x96, 0x88, 0xC0, 0xC8, 0xF7, 0x4A, 0x3E, 0xC0, 0x73 };
3887         byte[] expected = { 0xC1, 0xC5, 0x13, 0x1B, 0x11, 0x93, 0x52, 0xE6, 0x4A, 0xA3, 0xF8, 0xE7, 0x28, 0xDE, 0x02, 0x9A, 0x5D, 0x2B, 0x14, 0x6A, 0x5D, 0x0F, 0x24, 0x8F, 0xC1, 0xC5, 0x13, 0x1B, 0x11, 0x93, 0x52, 0xE6, 0x4A, 0xA3, 0xF8, 0xE7, 0x28, 0xDE, 0x02, 0x9A, 0x5D, 0x2B, 0x14, 0x6A, 0x5D, 0x0F, 0x24, 0x8F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3888
3889         SymmetricAlgorithm algo = Rijndael.Create ();
3890         algo.Mode = CipherMode.ECB;
3891         algo.Padding = PaddingMode.None;
3892         algo.BlockSize = 192;
3893         int blockLength = (algo.BlockSize >> 3);
3894         byte[] input = new byte [blockLength * 2];
3895         byte[] output = new byte [blockLength * 3];
3896         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3897         Encrypt (encryptor, input, output);
3898         AssertEquals ("Rijndael_k128b192_ECB_None Encrypt", expected, output);
3899
3900         // in ECB the first 2 blocks should be equals (as the IV is not used)
3901         byte[] block1 = new byte[blockLength];
3902         Array.Copy (output, 0, block1, 0, blockLength);
3903         byte[] block2 = new byte[blockLength];
3904         Array.Copy (output, blockLength, block2, 0, blockLength);
3905         AssertEquals ("Rijndael_k128b192_ECB_None b1==b2", block1, block2);
3906         byte[] reverse = new byte [blockLength * 3];
3907         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3908         Decrypt (decryptor, output, reverse);
3909         byte[] original = new byte [input.Length];
3910         Array.Copy (reverse, 0, original, 0, original.Length);
3911         AssertEquals ("Rijndael_k128b192_ECB_None Decrypt", input, original);
3912 }
3913
3914
3915 [Test]
3916 public void TestRijndael_k128b192_ECB_Zeros ()
3917 {
3918         byte[] key = { 0xDF, 0x1B, 0x73, 0xA3, 0xE3, 0x53, 0x75, 0x92, 0x2B, 0xD0, 0x44, 0x35, 0x94, 0xF5, 0xB2, 0xE7 };
3919         // not used for ECB but make the code more uniform
3920         byte[] iv = { 0x21, 0x82, 0x61, 0x4A, 0x57, 0xC0, 0x7D, 0x96, 0xFF, 0xC2, 0x08, 0xC1, 0x6C, 0xDF, 0x7C, 0x65, 0xC1, 0x8B, 0xFE, 0x5E, 0xD5, 0x82, 0xAD, 0x98 };
3921         byte[] expected = { 0xC9, 0x4E, 0xE0, 0x8F, 0x95, 0x55, 0x52, 0x1A, 0x75, 0xA9, 0x92, 0x1D, 0xFA, 0x30, 0xBD, 0xB8, 0x55, 0xA7, 0x8B, 0xF9, 0x58, 0xE9, 0x1B, 0x4C, 0xC9, 0x4E, 0xE0, 0x8F, 0x95, 0x55, 0x52, 0x1A, 0x75, 0xA9, 0x92, 0x1D, 0xFA, 0x30, 0xBD, 0xB8, 0x55, 0xA7, 0x8B, 0xF9, 0x58, 0xE9, 0x1B, 0x4C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3922
3923         SymmetricAlgorithm algo = Rijndael.Create ();
3924         algo.Mode = CipherMode.ECB;
3925         algo.Padding = PaddingMode.Zeros;
3926         algo.BlockSize = 192;
3927         int blockLength = (algo.BlockSize >> 3);
3928         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3929         byte[] output = new byte [blockLength * 3];
3930         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3931         // some exception can be normal... other not so!
3932         try {
3933                 Encrypt (encryptor, input, output);
3934         }
3935         catch (Exception e) {
3936                 if (e.Message != "Input buffer contains insufficient data. ")
3937                         Assert.Fail ("Rijndael_k128b192_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
3938         }
3939 }
3940
3941
3942 [Test]
3943 public void TestRijndael_k128b192_ECB_PKCS7 ()
3944 {
3945         byte[] key = { 0x78, 0x75, 0x1F, 0xE7, 0xFA, 0x1F, 0xF4, 0x2D, 0x31, 0x36, 0x14, 0xA5, 0xB8, 0x31, 0x97, 0x47 };
3946         // not used for ECB but make the code more uniform
3947         byte[] iv = { 0x91, 0x2F, 0xDC, 0x19, 0xC7, 0x6C, 0x67, 0x4A, 0x51, 0xE7, 0x08, 0xA5, 0xF9, 0xC6, 0xC3, 0x56, 0xF2, 0xED, 0xBD, 0xC9, 0x71, 0x9F, 0x02, 0xAF };
3948         byte[] expected = { 0xB1, 0x0D, 0xFD, 0xB0, 0x89, 0x3C, 0xF5, 0x52, 0x62, 0x22, 0x41, 0x20, 0xE4, 0x34, 0x03, 0x78, 0x37, 0xC2, 0xB1, 0xF9, 0x26, 0x0A, 0x7F, 0x0E, 0xB1, 0x0D, 0xFD, 0xB0, 0x89, 0x3C, 0xF5, 0x52, 0x62, 0x22, 0x41, 0x20, 0xE4, 0x34, 0x03, 0x78, 0x37, 0xC2, 0xB1, 0xF9, 0x26, 0x0A, 0x7F, 0x0E, 0xF9, 0x7A, 0x2D, 0xF9, 0x5C, 0xD5, 0xEA, 0x06, 0x18, 0xC9, 0x06, 0xD4, 0xD0, 0x0B, 0xD6, 0x19, 0x4E, 0x7E, 0x9C, 0x5F, 0xDE, 0x3D, 0xB4, 0x2A };
3949
3950         SymmetricAlgorithm algo = Rijndael.Create ();
3951         algo.Mode = CipherMode.ECB;
3952         algo.Padding = PaddingMode.PKCS7;
3953         algo.BlockSize = 192;
3954         int blockLength = (algo.BlockSize >> 3);
3955         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3956         byte[] output = new byte [blockLength * 3];
3957         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3958         Encrypt (encryptor, input, output);
3959         AssertEquals ("Rijndael_k128b192_ECB_PKCS7 Encrypt", expected, output);
3960
3961         // in ECB the first 2 blocks should be equals (as the IV is not used)
3962         byte[] block1 = new byte[blockLength];
3963         Array.Copy (output, 0, block1, 0, blockLength);
3964         byte[] block2 = new byte[blockLength];
3965         Array.Copy (output, blockLength, block2, 0, blockLength);
3966         AssertEquals ("Rijndael_k128b192_ECB_PKCS7 b1==b2", block1, block2);
3967         byte[] reverse = new byte [blockLength * 3];
3968         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3969         Decrypt (decryptor, output, reverse);
3970         byte[] original = new byte [input.Length];
3971         Array.Copy (reverse, 0, original, 0, original.Length);
3972         AssertEquals ("Rijndael_k128b192_ECB_PKCS7 Decrypt", input, original);
3973 }
3974
3975
3976 [Test]
3977 public void TestRijndael_k128b192_CBC_None ()
3978 {
3979         byte[] key = { 0xBD, 0x01, 0x0F, 0x53, 0x53, 0x14, 0x90, 0x58, 0x22, 0x81, 0x6F, 0x79, 0x8C, 0x68, 0x21, 0x21 };
3980         byte[] iv = { 0xEE, 0x7B, 0xC0, 0x5F, 0x32, 0x59, 0x56, 0xB6, 0x7C, 0x17, 0x04, 0xC5, 0x64, 0x6A, 0xA1, 0x35, 0x6F, 0xAC, 0xB8, 0xCE, 0xFA, 0xCC, 0x76, 0xBE };
3981         byte[] expected = { 0x5D, 0xF5, 0x03, 0xD7, 0x17, 0xEE, 0x05, 0x18, 0x63, 0x99, 0xAB, 0x58, 0xBB, 0xC0, 0x04, 0x0A, 0x52, 0x1D, 0x4E, 0xA4, 0x8B, 0x68, 0xA3, 0x63, 0x7A, 0xBD, 0xAF, 0x0C, 0x85, 0x5D, 0xF8, 0x0D, 0x7A, 0x01, 0xF0, 0x76, 0x24, 0xF1, 0x8A, 0x95, 0x8B, 0xB2, 0xC0, 0xF7, 0x1D, 0xC5, 0x0E, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3982
3983         SymmetricAlgorithm algo = Rijndael.Create ();
3984         algo.Mode = CipherMode.CBC;
3985         algo.Padding = PaddingMode.None;
3986         algo.BlockSize = 192;
3987         int blockLength = (algo.BlockSize >> 3);
3988         byte[] input = new byte [blockLength * 2];
3989         byte[] output = new byte [blockLength * 3];
3990         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3991         Encrypt (encryptor, input, output);
3992         AssertEquals ("Rijndael_k128b192_CBC_None Encrypt", expected, output);
3993         byte[] reverse = new byte [blockLength * 3];
3994         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3995         Decrypt (decryptor, output, reverse);
3996         byte[] original = new byte [input.Length];
3997         Array.Copy (reverse, 0, original, 0, original.Length);
3998         AssertEquals ("Rijndael_k128b192_CBC_None Decrypt", input, original);
3999 }
4000
4001
4002 [Test]
4003 public void TestRijndael_k128b192_CBC_Zeros ()
4004 {
4005         byte[] key = { 0xE2, 0x9C, 0x2A, 0xAA, 0xD0, 0x02, 0xDD, 0xDF, 0xFE, 0xD7, 0xB0, 0x21, 0x1E, 0x52, 0xE5, 0x25 };
4006         byte[] iv = { 0xED, 0xF5, 0xD7, 0xF7, 0x8D, 0xB6, 0x91, 0x00, 0x81, 0x88, 0x75, 0x8C, 0x61, 0x13, 0x84, 0x46, 0x2A, 0x53, 0x02, 0xE9, 0xBB, 0x01, 0xF8, 0x24 };
4007         byte[] expected = { 0x55, 0x48, 0x90, 0x63, 0x5B, 0x93, 0x09, 0xA7, 0xF7, 0xB2, 0xC0, 0x4D, 0xB1, 0x1A, 0xF7, 0xC7, 0xF7, 0xC0, 0xB6, 0x29, 0x7A, 0x50, 0x4E, 0x52, 0x2F, 0x68, 0x49, 0x92, 0x80, 0x0D, 0xBD, 0x89, 0x34, 0x84, 0x60, 0x87, 0x2C, 0x50, 0x65, 0xFF, 0xAE, 0x0E, 0x7B, 0x30, 0x3D, 0xFA, 0x93, 0xE6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4008
4009         SymmetricAlgorithm algo = Rijndael.Create ();
4010         algo.Mode = CipherMode.CBC;
4011         algo.Padding = PaddingMode.Zeros;
4012         algo.BlockSize = 192;
4013         int blockLength = (algo.BlockSize >> 3);
4014         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4015         byte[] output = new byte [blockLength * 3];
4016         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4017         // some exception can be normal... other not so!
4018         try {
4019                 Encrypt (encryptor, input, output);
4020         }
4021         catch (Exception e) {
4022                 if (e.Message != "Input buffer contains insufficient data. ")
4023                         Assert.Fail ("Rijndael_k128b192_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
4024         }
4025 }
4026
4027
4028 [Test]
4029 public void TestRijndael_k128b192_CBC_PKCS7 ()
4030 {
4031         byte[] key = { 0x14, 0x6C, 0x36, 0x5E, 0x22, 0xE9, 0x25, 0x1E, 0xC9, 0x1F, 0xA7, 0xC9, 0xA5, 0x19, 0x2C, 0x09 };
4032         byte[] iv = { 0xE2, 0x6F, 0xA7, 0xDC, 0x36, 0x32, 0xF7, 0x28, 0x8B, 0x09, 0x78, 0xB9, 0x30, 0x6A, 0x3F, 0xD0, 0xA8, 0x5E, 0x1F, 0x7D, 0x8F, 0xDE, 0x5B, 0xA4 };
4033         byte[] expected = { 0x9D, 0x08, 0xFD, 0xDE, 0x64, 0x97, 0x1D, 0x88, 0xB4, 0xCD, 0x70, 0xDD, 0xCC, 0x95, 0x1C, 0xAE, 0x01, 0x4B, 0x14, 0x19, 0x69, 0x58, 0xCE, 0x14, 0xA6, 0xF6, 0xD0, 0x25, 0xCE, 0xD6, 0xBB, 0xD5, 0x8C, 0xF6, 0xBF, 0x54, 0x66, 0x1D, 0xAE, 0x03, 0x6C, 0x81, 0xBF, 0xC6, 0x06, 0xB3, 0x64, 0x39, 0x73, 0x0A, 0x54, 0xB8, 0x3F, 0x3D, 0x1D, 0xFA, 0xB8, 0xBB, 0x53, 0x34, 0xEC, 0x69, 0xBD, 0xC3, 0xC1, 0xB2, 0x8D, 0x7D, 0x08, 0xE4, 0xFA, 0x82 };
4034
4035         SymmetricAlgorithm algo = Rijndael.Create ();
4036         algo.Mode = CipherMode.CBC;
4037         algo.Padding = PaddingMode.PKCS7;
4038         algo.BlockSize = 192;
4039         int blockLength = (algo.BlockSize >> 3);
4040         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4041         byte[] output = new byte [blockLength * 3];
4042         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4043         Encrypt (encryptor, input, output);
4044         AssertEquals ("Rijndael_k128b192_CBC_PKCS7 Encrypt", expected, output);
4045         byte[] reverse = new byte [blockLength * 3];
4046         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4047         Decrypt (decryptor, output, reverse);
4048         byte[] original = new byte [input.Length];
4049         Array.Copy (reverse, 0, original, 0, original.Length);
4050         AssertEquals ("Rijndael_k128b192_CBC_PKCS7 Decrypt", input, original);
4051 }
4052
4053
4054 /* Invalid parameters Rijndael_k128b192_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
4055
4056 /* Invalid parameters Rijndael_k128b192_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
4057
4058 /* Invalid parameters Rijndael_k128b192_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
4059
4060 /* Invalid parameters Rijndael_k128b192_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
4061
4062 /* Invalid parameters Rijndael_k128b192_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
4063
4064 /* Invalid parameters Rijndael_k128b192_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
4065
4066 /* Invalid parameters Rijndael_k128b192_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
4067
4068 /* Invalid parameters Rijndael_k128b192_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
4069
4070 /* Invalid parameters Rijndael_k128b192_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
4071
4072 [Test]
4073 public void TestRijndael_k128b256_ECB_None ()
4074 {
4075         byte[] key = { 0xD5, 0xB9, 0x92, 0x27, 0xC0, 0xBB, 0x86, 0x06, 0x19, 0xD9, 0xA4, 0x1B, 0x9E, 0x7A, 0xF0, 0x3D };
4076         // not used for ECB but make the code more uniform
4077         byte[] iv = { 0x3C, 0x72, 0xD4, 0xBA, 0xC8, 0xCA, 0xAD, 0x8B, 0x94, 0x00, 0xF3, 0x4E, 0xE9, 0xAC, 0xFB, 0x15, 0xA2, 0x06, 0xFE, 0xA3, 0x33, 0x18, 0x48, 0x55, 0xD5, 0x6B, 0x8F, 0x13, 0xEF, 0xB6, 0x34, 0xF8 };
4078         byte[] expected = { 0x9A, 0x86, 0x3A, 0xE6, 0x23, 0x50, 0x4D, 0xBD, 0x4B, 0xD3, 0x1A, 0xDE, 0x83, 0x13, 0x4A, 0x82, 0xEF, 0x99, 0x7D, 0x19, 0xB0, 0x01, 0x4E, 0x46, 0x4B, 0xCF, 0x99, 0x66, 0x10, 0x23, 0x6E, 0x6C, 0x9A, 0x86, 0x3A, 0xE6, 0x23, 0x50, 0x4D, 0xBD, 0x4B, 0xD3, 0x1A, 0xDE, 0x83, 0x13, 0x4A, 0x82, 0xEF, 0x99, 0x7D, 0x19, 0xB0, 0x01, 0x4E, 0x46, 0x4B, 0xCF, 0x99, 0x66, 0x10, 0x23, 0x6E, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4079
4080         SymmetricAlgorithm algo = Rijndael.Create ();
4081         algo.Mode = CipherMode.ECB;
4082         algo.Padding = PaddingMode.None;
4083         algo.BlockSize = 256;
4084         int blockLength = (algo.BlockSize >> 3);
4085         byte[] input = new byte [blockLength * 2];
4086         byte[] output = new byte [blockLength * 3];
4087         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4088         Encrypt (encryptor, input, output);
4089         AssertEquals ("Rijndael_k128b256_ECB_None Encrypt", expected, output);
4090
4091         // in ECB the first 2 blocks should be equals (as the IV is not used)
4092         byte[] block1 = new byte[blockLength];
4093         Array.Copy (output, 0, block1, 0, blockLength);
4094         byte[] block2 = new byte[blockLength];
4095         Array.Copy (output, blockLength, block2, 0, blockLength);
4096         AssertEquals ("Rijndael_k128b256_ECB_None b1==b2", block1, block2);
4097         byte[] reverse = new byte [blockLength * 3];
4098         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4099         Decrypt (decryptor, output, reverse);
4100         byte[] original = new byte [input.Length];
4101         Array.Copy (reverse, 0, original, 0, original.Length);
4102         AssertEquals ("Rijndael_k128b256_ECB_None Decrypt", input, original);
4103 }
4104
4105
4106 [Test]
4107 public void TestRijndael_k128b256_ECB_Zeros ()
4108 {
4109         byte[] key = { 0x3C, 0xA6, 0xD7, 0xDA, 0xE3, 0x4D, 0x32, 0x67, 0xA8, 0xF5, 0xFF, 0xFF, 0xEE, 0xE8, 0xD4, 0xB2 };
4110         // not used for ECB but make the code more uniform
4111         byte[] iv = { 0xC8, 0x0A, 0x40, 0x30, 0x7C, 0x7E, 0x75, 0xDE, 0x71, 0x64, 0x59, 0xCE, 0x03, 0x40, 0x8F, 0x50, 0xC7, 0x5E, 0xA2, 0x27, 0x5F, 0x12, 0x57, 0xF4, 0xB7, 0xAD, 0x95, 0xAD, 0x95, 0x84, 0xBE, 0x3C };
4112         byte[] expected = { 0x6D, 0x57, 0xCA, 0xED, 0x29, 0xBA, 0xA6, 0x3A, 0x3D, 0x02, 0xE1, 0x21, 0x39, 0xB0, 0x34, 0x41, 0xFC, 0xAC, 0x55, 0x8C, 0x61, 0xAE, 0x18, 0x7D, 0x7A, 0x41, 0x81, 0x1C, 0x53, 0x5F, 0x3D, 0xB1, 0x6D, 0x57, 0xCA, 0xED, 0x29, 0xBA, 0xA6, 0x3A, 0x3D, 0x02, 0xE1, 0x21, 0x39, 0xB0, 0x34, 0x41, 0xFC, 0xAC, 0x55, 0x8C, 0x61, 0xAE, 0x18, 0x7D, 0x7A, 0x41, 0x81, 0x1C, 0x53, 0x5F, 0x3D, 0xB1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4113
4114         SymmetricAlgorithm algo = Rijndael.Create ();
4115         algo.Mode = CipherMode.ECB;
4116         algo.Padding = PaddingMode.Zeros;
4117         algo.BlockSize = 256;
4118         int blockLength = (algo.BlockSize >> 3);
4119         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4120         byte[] output = new byte [blockLength * 3];
4121         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4122         // some exception can be normal... other not so!
4123         try {
4124                 Encrypt (encryptor, input, output);
4125         }
4126         catch (Exception e) {
4127                 if (e.Message != "Input buffer contains insufficient data. ")
4128                         Assert.Fail ("Rijndael_k128b256_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
4129         }
4130 }
4131
4132
4133 [Test]
4134 public void TestRijndael_k128b256_ECB_PKCS7 ()
4135 {
4136         byte[] key = { 0xED, 0xBA, 0x84, 0x92, 0x50, 0x93, 0x9B, 0xE4, 0xC4, 0x83, 0x31, 0x8E, 0x11, 0x86, 0xAE, 0xC9 };
4137         // not used for ECB but make the code more uniform
4138         byte[] iv = { 0x43, 0x98, 0x73, 0xFE, 0x77, 0x4D, 0x75, 0x79, 0xC7, 0xEF, 0x5C, 0x89, 0xFA, 0x5E, 0x07, 0x85, 0x0B, 0x21, 0x59, 0x8B, 0x8A, 0x1D, 0x11, 0x07, 0xA0, 0xC4, 0x3E, 0x11, 0x7F, 0x5D, 0xFE, 0xEE };
4139         byte[] expected = { 0xA0, 0x56, 0xD6, 0x6B, 0x48, 0x77, 0xCC, 0x51, 0x0F, 0x04, 0x58, 0x16, 0x46, 0x04, 0x36, 0x66, 0xBB, 0x4D, 0x88, 0x71, 0xFF, 0x65, 0x0B, 0xFD, 0x52, 0x8D, 0xE8, 0xAF, 0x97, 0x78, 0xBD, 0x82, 0xA0, 0x56, 0xD6, 0x6B, 0x48, 0x77, 0xCC, 0x51, 0x0F, 0x04, 0x58, 0x16, 0x46, 0x04, 0x36, 0x66, 0xBB, 0x4D, 0x88, 0x71, 0xFF, 0x65, 0x0B, 0xFD, 0x52, 0x8D, 0xE8, 0xAF, 0x97, 0x78, 0xBD, 0x82, 0x66, 0x2C, 0x2B, 0x59, 0xC8, 0x47, 0x3E, 0xE0, 0xC4, 0xA5, 0x22, 0x79, 0x6C, 0xCF, 0x18, 0x10, 0xDA, 0xB5, 0xE9, 0xB1, 0x21, 0xCA, 0xCC, 0xD6, 0xF7, 0xDC, 0xA5, 0xD4, 0x29, 0x10, 0x8A, 0xA4 };
4140
4141         SymmetricAlgorithm algo = Rijndael.Create ();
4142         algo.Mode = CipherMode.ECB;
4143         algo.Padding = PaddingMode.PKCS7;
4144         algo.BlockSize = 256;
4145         int blockLength = (algo.BlockSize >> 3);
4146         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4147         byte[] output = new byte [blockLength * 3];
4148         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4149         Encrypt (encryptor, input, output);
4150         AssertEquals ("Rijndael_k128b256_ECB_PKCS7 Encrypt", expected, output);
4151
4152         // in ECB the first 2 blocks should be equals (as the IV is not used)
4153         byte[] block1 = new byte[blockLength];
4154         Array.Copy (output, 0, block1, 0, blockLength);
4155         byte[] block2 = new byte[blockLength];
4156         Array.Copy (output, blockLength, block2, 0, blockLength);
4157         AssertEquals ("Rijndael_k128b256_ECB_PKCS7 b1==b2", block1, block2);
4158         byte[] reverse = new byte [blockLength * 3];
4159         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4160         Decrypt (decryptor, output, reverse);
4161         byte[] original = new byte [input.Length];
4162         Array.Copy (reverse, 0, original, 0, original.Length);
4163         AssertEquals ("Rijndael_k128b256_ECB_PKCS7 Decrypt", input, original);
4164 }
4165
4166
4167 [Test]
4168 public void TestRijndael_k128b256_CBC_None ()
4169 {
4170         byte[] key = { 0x23, 0x09, 0x30, 0xC7, 0x01, 0x81, 0x1D, 0x2E, 0xD6, 0x6A, 0xC9, 0x99, 0x0D, 0x3D, 0x99, 0x79 };
4171         byte[] iv = { 0x24, 0x2B, 0xCF, 0xFF, 0x81, 0x8C, 0xBE, 0x55, 0x1D, 0x8A, 0xDA, 0xF8, 0x81, 0xA7, 0x5A, 0xD1, 0xA6, 0x88, 0xC6, 0x90, 0xC4, 0x33, 0xCD, 0x37, 0x11, 0xCC, 0x64, 0x42, 0xD8, 0x2C, 0xA6, 0xE0 };
4172         byte[] expected = { 0xEF, 0xA5, 0xAB, 0xDB, 0x71, 0xE3, 0x9A, 0x33, 0x45, 0x74, 0xB7, 0x90, 0xED, 0xD8, 0xDE, 0x33, 0x56, 0xEA, 0x75, 0xE0, 0x42, 0x51, 0xAD, 0xEE, 0x9C, 0x74, 0xC8, 0x6B, 0x99, 0x88, 0xD2, 0x13, 0xB2, 0x80, 0x5E, 0xB3, 0xDC, 0xE3, 0x49, 0x43, 0x86, 0x10, 0xC7, 0xCC, 0xE2, 0xE8, 0xCD, 0x79, 0x5C, 0x69, 0x19, 0xD0, 0xE2, 0x70, 0xB1, 0x25, 0x21, 0xB5, 0xC0, 0x69, 0xAB, 0x3D, 0x25, 0x9A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4173
4174         SymmetricAlgorithm algo = Rijndael.Create ();
4175         algo.Mode = CipherMode.CBC;
4176         algo.Padding = PaddingMode.None;
4177         algo.BlockSize = 256;
4178         int blockLength = (algo.BlockSize >> 3);
4179         byte[] input = new byte [blockLength * 2];
4180         byte[] output = new byte [blockLength * 3];
4181         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4182         Encrypt (encryptor, input, output);
4183         AssertEquals ("Rijndael_k128b256_CBC_None Encrypt", expected, output);
4184         byte[] reverse = new byte [blockLength * 3];
4185         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4186         Decrypt (decryptor, output, reverse);
4187         byte[] original = new byte [input.Length];
4188         Array.Copy (reverse, 0, original, 0, original.Length);
4189         AssertEquals ("Rijndael_k128b256_CBC_None Decrypt", input, original);
4190 }
4191
4192
4193 [Test]
4194 public void TestRijndael_k128b256_CBC_Zeros ()
4195 {
4196         byte[] key = { 0xB6, 0xE5, 0xA0, 0x6F, 0x35, 0xA9, 0x25, 0x31, 0x5B, 0x8C, 0x52, 0x87, 0x26, 0x80, 0xB1, 0x42 };
4197         byte[] iv = { 0xFD, 0x8E, 0xD8, 0x17, 0xEB, 0x9F, 0xC6, 0x5B, 0xD7, 0x42, 0xF4, 0x79, 0x68, 0x38, 0xEE, 0xC6, 0x15, 0x83, 0xFF, 0x18, 0xA5, 0x24, 0x80, 0x65, 0xCE, 0xF3, 0xED, 0xA8, 0x0E, 0x60, 0xB4, 0xA0 };
4198         byte[] expected = { 0xC6, 0x0C, 0xE3, 0x6A, 0x8A, 0x98, 0xC2, 0xF7, 0x77, 0x59, 0x2C, 0x77, 0x88, 0x3F, 0xCE, 0x12, 0xFB, 0xFB, 0xB0, 0x20, 0xE5, 0xBC, 0xDB, 0x30, 0xE8, 0x1C, 0x19, 0xEA, 0x4C, 0x3A, 0x2E, 0xAF, 0x57, 0x4B, 0x05, 0xE8, 0xD4, 0xC9, 0xB2, 0xC4, 0x00, 0x35, 0xE0, 0x57, 0x7D, 0xAF, 0x11, 0xB4, 0xB2, 0x84, 0xCD, 0x7F, 0x6C, 0x6E, 0xD0, 0xDA, 0x58, 0x90, 0xF6, 0x9A, 0x51, 0x2C, 0x74, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4199
4200         SymmetricAlgorithm algo = Rijndael.Create ();
4201         algo.Mode = CipherMode.CBC;
4202         algo.Padding = PaddingMode.Zeros;
4203         algo.BlockSize = 256;
4204         int blockLength = (algo.BlockSize >> 3);
4205         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4206         byte[] output = new byte [blockLength * 3];
4207         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4208         // some exception can be normal... other not so!
4209         try {
4210                 Encrypt (encryptor, input, output);
4211         }
4212         catch (Exception e) {
4213                 if (e.Message != "Input buffer contains insufficient data. ")
4214                         Assert.Fail ("Rijndael_k128b256_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
4215         }
4216 }
4217
4218
4219 [Test]
4220 public void TestRijndael_k128b256_CBC_PKCS7 ()
4221 {
4222         byte[] key = { 0xAE, 0x7A, 0xD9, 0x55, 0xBF, 0x55, 0xB2, 0x40, 0x4A, 0x48, 0x5F, 0x06, 0xAA, 0x04, 0x45, 0x0A };
4223         byte[] iv = { 0xB9, 0xD7, 0xC5, 0x09, 0x93, 0xED, 0x68, 0xC4, 0x5A, 0x82, 0x8F, 0xBD, 0x2F, 0xB4, 0x3B, 0x84, 0xBA, 0xE4, 0x46, 0x51, 0xAD, 0xAB, 0xA5, 0xCC, 0xB7, 0x59, 0x31, 0x9E, 0xBB, 0xFA, 0x54, 0x10 };
4224         byte[] expected = { 0xAC, 0xD7, 0x42, 0x01, 0x60, 0x36, 0xD3, 0xE1, 0xAE, 0x60, 0xC1, 0x5E, 0xAD, 0x4E, 0x81, 0xE1, 0x65, 0xFB, 0xF0, 0x06, 0x89, 0xC5, 0xAD, 0x71, 0x62, 0x81, 0x41, 0xC7, 0xC7, 0xC2, 0xAA, 0x1E, 0x76, 0x88, 0x41, 0x23, 0xFB, 0xFF, 0x44, 0x01, 0xA4, 0xB9, 0x61, 0xC0, 0x1B, 0x54, 0x09, 0x45, 0x1C, 0x17, 0xE3, 0x0A, 0x4A, 0x0A, 0xC5, 0x6F, 0x77, 0xB0, 0xDB, 0xE1, 0xD4, 0xCD, 0x28, 0xD6, 0xA6, 0x40, 0x8F, 0x2B, 0x49, 0x2C, 0xDF, 0x4D, 0x6D, 0x78, 0x24, 0x65, 0x37, 0x61, 0x05, 0xCD, 0xBC, 0x15, 0x37, 0x67, 0x65, 0xEF, 0xCB, 0x8A, 0xEE, 0x53, 0x9D, 0x29, 0x62, 0x73, 0x51, 0xD2 };
4225
4226         SymmetricAlgorithm algo = Rijndael.Create ();
4227         algo.Mode = CipherMode.CBC;
4228         algo.Padding = PaddingMode.PKCS7;
4229         algo.BlockSize = 256;
4230         int blockLength = (algo.BlockSize >> 3);
4231         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4232         byte[] output = new byte [blockLength * 3];
4233         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4234         Encrypt (encryptor, input, output);
4235         AssertEquals ("Rijndael_k128b256_CBC_PKCS7 Encrypt", expected, output);
4236         byte[] reverse = new byte [blockLength * 3];
4237         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4238         Decrypt (decryptor, output, reverse);
4239         byte[] original = new byte [input.Length];
4240         Array.Copy (reverse, 0, original, 0, original.Length);
4241         AssertEquals ("Rijndael_k128b256_CBC_PKCS7 Decrypt", input, original);
4242 }
4243
4244
4245 /* Invalid parameters Rijndael_k128b256_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
4246
4247 /* Invalid parameters Rijndael_k128b256_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
4248
4249 /* Invalid parameters Rijndael_k128b256_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
4250
4251 /* Invalid parameters Rijndael_k128b256_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
4252
4253 /* Invalid parameters Rijndael_k128b256_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
4254
4255 /* Invalid parameters Rijndael_k128b256_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
4256
4257 /* Invalid parameters Rijndael_k128b256_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
4258
4259 /* Invalid parameters Rijndael_k128b256_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
4260
4261 /* Invalid parameters Rijndael_k128b256_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
4262
4263 [Test]
4264 public void TestRijndael_k192b128_ECB_None ()
4265 {
4266         byte[] key = { 0xA4, 0x51, 0x15, 0x32, 0xE7, 0xFC, 0x6F, 0x22, 0x73, 0x72, 0xB0, 0xAD, 0x67, 0x4C, 0x84, 0xB4, 0xB2, 0xAF, 0x50, 0x74, 0x5A, 0x4D, 0xB7, 0x2A };
4267         // not used for ECB but make the code more uniform
4268         byte[] iv = { 0x83, 0x22, 0x1B, 0x6C, 0x66, 0x1F, 0x4A, 0xB7, 0x55, 0xAF, 0x5B, 0xBF, 0x4A, 0x05, 0x73, 0x24 };
4269         byte[] expected = { 0x6A, 0x1D, 0xA5, 0xBE, 0x7F, 0x6C, 0x0A, 0x98, 0x2A, 0x09, 0x4B, 0x70, 0xC1, 0xA1, 0xBC, 0x75, 0x6A, 0x1D, 0xA5, 0xBE, 0x7F, 0x6C, 0x0A, 0x98, 0x2A, 0x09, 0x4B, 0x70, 0xC1, 0xA1, 0xBC, 0x75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4270
4271         SymmetricAlgorithm algo = Rijndael.Create ();
4272         algo.Mode = CipherMode.ECB;
4273         algo.Padding = PaddingMode.None;
4274         algo.BlockSize = 128;
4275         int blockLength = (algo.BlockSize >> 3);
4276         byte[] input = new byte [blockLength * 2];
4277         byte[] output = new byte [blockLength * 3];
4278         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4279         Encrypt (encryptor, input, output);
4280         AssertEquals ("Rijndael_k192b128_ECB_None Encrypt", expected, output);
4281
4282         // in ECB the first 2 blocks should be equals (as the IV is not used)
4283         byte[] block1 = new byte[blockLength];
4284         Array.Copy (output, 0, block1, 0, blockLength);
4285         byte[] block2 = new byte[blockLength];
4286         Array.Copy (output, blockLength, block2, 0, blockLength);
4287         AssertEquals ("Rijndael_k192b128_ECB_None b1==b2", block1, block2);
4288         byte[] reverse = new byte [blockLength * 3];
4289         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4290         Decrypt (decryptor, output, reverse);
4291         byte[] original = new byte [input.Length];
4292         Array.Copy (reverse, 0, original, 0, original.Length);
4293         AssertEquals ("Rijndael_k192b128_ECB_None Decrypt", input, original);
4294 }
4295
4296
4297 [Test]
4298 public void TestRijndael_k192b128_ECB_Zeros ()
4299 {
4300         byte[] key = { 0xB4, 0x65, 0x79, 0x30, 0x92, 0x6A, 0xEC, 0x78, 0xBA, 0x9B, 0x8B, 0x36, 0x7C, 0x8F, 0x6B, 0x8A, 0x79, 0x7F, 0x8A, 0xDA, 0xB4, 0x06, 0x23, 0x4C };
4301         // not used for ECB but make the code more uniform
4302         byte[] iv = { 0x43, 0xBA, 0x1C, 0xFB, 0x33, 0xB4, 0x3B, 0x38, 0x5C, 0x21, 0x13, 0xDD, 0x9A, 0x3A, 0xF1, 0xEE };
4303         byte[] expected = { 0xB1, 0x45, 0x70, 0xFC, 0xB5, 0x82, 0x49, 0x9F, 0xEA, 0x50, 0x0C, 0xEA, 0xFD, 0x13, 0xA8, 0xE8, 0xB1, 0x45, 0x70, 0xFC, 0xB5, 0x82, 0x49, 0x9F, 0xEA, 0x50, 0x0C, 0xEA, 0xFD, 0x13, 0xA8, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4304
4305         SymmetricAlgorithm algo = Rijndael.Create ();
4306         algo.Mode = CipherMode.ECB;
4307         algo.Padding = PaddingMode.Zeros;
4308         algo.BlockSize = 128;
4309         int blockLength = (algo.BlockSize >> 3);
4310         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4311         byte[] output = new byte [blockLength * 3];
4312         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4313         // some exception can be normal... other not so!
4314         try {
4315                 Encrypt (encryptor, input, output);
4316         }
4317         catch (Exception e) {
4318                 if (e.Message != "Input buffer contains insufficient data. ")
4319                         Assert.Fail ("Rijndael_k192b128_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
4320         }
4321 }
4322
4323
4324 [Test]
4325 public void TestRijndael_k192b128_ECB_PKCS7 ()
4326 {
4327         byte[] key = { 0x06, 0xC3, 0x07, 0x6A, 0x36, 0xE5, 0xF3, 0xCF, 0x33, 0x87, 0x22, 0x03, 0x5A, 0xFA, 0x4F, 0x25, 0x9D, 0xE4, 0x81, 0xA4, 0x9E, 0xB4, 0x5D, 0x84 };
4328         // not used for ECB but make the code more uniform
4329         byte[] iv = { 0xB0, 0xF9, 0x9F, 0x2D, 0x8D, 0xD0, 0x2D, 0xA1, 0x51, 0xDB, 0x07, 0xA3, 0x34, 0x28, 0x4F, 0x25 };
4330         byte[] expected = { 0xE9, 0xB9, 0xE5, 0x89, 0x0E, 0xF7, 0x3C, 0xCF, 0x63, 0x6B, 0xCD, 0x33, 0x85, 0x81, 0x02, 0x75, 0xE9, 0xB9, 0xE5, 0x89, 0x0E, 0xF7, 0x3C, 0xCF, 0x63, 0x6B, 0xCD, 0x33, 0x85, 0x81, 0x02, 0x75, 0xE8, 0x31, 0x03, 0x87, 0xFF, 0x9D, 0x7A, 0xAB, 0x81, 0x82, 0x63, 0x6B, 0xAA, 0x6F, 0x20, 0x21 };
4331
4332         SymmetricAlgorithm algo = Rijndael.Create ();
4333         algo.Mode = CipherMode.ECB;
4334         algo.Padding = PaddingMode.PKCS7;
4335         algo.BlockSize = 128;
4336         int blockLength = (algo.BlockSize >> 3);
4337         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4338         byte[] output = new byte [blockLength * 3];
4339         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4340         Encrypt (encryptor, input, output);
4341         AssertEquals ("Rijndael_k192b128_ECB_PKCS7 Encrypt", expected, output);
4342
4343         // in ECB the first 2 blocks should be equals (as the IV is not used)
4344         byte[] block1 = new byte[blockLength];
4345         Array.Copy (output, 0, block1, 0, blockLength);
4346         byte[] block2 = new byte[blockLength];
4347         Array.Copy (output, blockLength, block2, 0, blockLength);
4348         AssertEquals ("Rijndael_k192b128_ECB_PKCS7 b1==b2", block1, block2);
4349         byte[] reverse = new byte [blockLength * 3];
4350         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4351         Decrypt (decryptor, output, reverse);
4352         byte[] original = new byte [input.Length];
4353         Array.Copy (reverse, 0, original, 0, original.Length);
4354         AssertEquals ("Rijndael_k192b128_ECB_PKCS7 Decrypt", input, original);
4355 }
4356
4357
4358 [Test]
4359 public void TestRijndael_k192b128_CBC_None ()
4360 {
4361         byte[] key = { 0x8F, 0x85, 0x39, 0xC2, 0xAC, 0x25, 0xBD, 0x54, 0xDE, 0x89, 0x2A, 0x67, 0x2C, 0xF0, 0xE5, 0x7E, 0xAA, 0x7E, 0xC4, 0xFB, 0xCD, 0x31, 0xD9, 0xFA };
4362         byte[] iv = { 0xCA, 0xC4, 0x8D, 0x38, 0x28, 0x29, 0xC2, 0xBF, 0xD8, 0x7A, 0xCA, 0x56, 0xBF, 0x59, 0x6B, 0xCE };
4363         byte[] expected = { 0x22, 0x66, 0xB0, 0x6C, 0xC1, 0x18, 0xBB, 0x43, 0x6B, 0xB9, 0x42, 0x16, 0x4D, 0xFB, 0x96, 0x7C, 0xEC, 0xCA, 0xB8, 0x09, 0x02, 0x8C, 0x2E, 0x4D, 0x4D, 0x90, 0x03, 0xEA, 0x0F, 0x69, 0x20, 0xA2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4364
4365         SymmetricAlgorithm algo = Rijndael.Create ();
4366         algo.Mode = CipherMode.CBC;
4367         algo.Padding = PaddingMode.None;
4368         algo.BlockSize = 128;
4369         int blockLength = (algo.BlockSize >> 3);
4370         byte[] input = new byte [blockLength * 2];
4371         byte[] output = new byte [blockLength * 3];
4372         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4373         Encrypt (encryptor, input, output);
4374         AssertEquals ("Rijndael_k192b128_CBC_None Encrypt", expected, output);
4375         byte[] reverse = new byte [blockLength * 3];
4376         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4377         Decrypt (decryptor, output, reverse);
4378         byte[] original = new byte [input.Length];
4379         Array.Copy (reverse, 0, original, 0, original.Length);
4380         AssertEquals ("Rijndael_k192b128_CBC_None Decrypt", input, original);
4381 }
4382
4383
4384 [Test]
4385 public void TestRijndael_k192b128_CBC_Zeros ()
4386 {
4387         byte[] key = { 0xA7, 0x3E, 0xEE, 0x4B, 0xF5, 0x0E, 0x05, 0x03, 0xE2, 0x50, 0xF1, 0xBC, 0xEB, 0x57, 0x60, 0x79, 0x83, 0x5D, 0xFC, 0x42, 0x65, 0x41, 0xCF, 0x48 };
4388         byte[] iv = { 0xC9, 0x76, 0xCE, 0x21, 0xDF, 0x46, 0xB0, 0x23, 0x19, 0xB6, 0xD5, 0x80, 0x1F, 0xBA, 0x15, 0xDB };
4389         byte[] expected = { 0x63, 0xED, 0x15, 0xBE, 0xB9, 0x4E, 0x9E, 0x30, 0xB1, 0xC5, 0x31, 0xCB, 0x02, 0x88, 0xB4, 0x8F, 0xF5, 0xB0, 0x53, 0x8D, 0xD1, 0x35, 0xB7, 0x85, 0xED, 0x02, 0x79, 0x03, 0xC1, 0x13, 0xCE, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4390
4391         SymmetricAlgorithm algo = Rijndael.Create ();
4392         algo.Mode = CipherMode.CBC;
4393         algo.Padding = PaddingMode.Zeros;
4394         algo.BlockSize = 128;
4395         int blockLength = (algo.BlockSize >> 3);
4396         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4397         byte[] output = new byte [blockLength * 3];
4398         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4399         // some exception can be normal... other not so!
4400         try {
4401                 Encrypt (encryptor, input, output);
4402         }
4403         catch (Exception e) {
4404                 if (e.Message != "Input buffer contains insufficient data. ")
4405                         Assert.Fail ("Rijndael_k192b128_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
4406         }
4407 }
4408
4409
4410 [Test]
4411 public void TestRijndael_k192b128_CBC_PKCS7 ()
4412 {
4413         byte[] key = { 0x0F, 0x00, 0x54, 0xCD, 0x2A, 0x66, 0x21, 0xF0, 0x74, 0x64, 0x65, 0xC6, 0xE1, 0xC6, 0xCD, 0x11, 0x05, 0x04, 0xA7, 0x23, 0x48, 0x4E, 0xB3, 0x84 };
4414         byte[] iv = { 0xDA, 0xE6, 0x7F, 0x27, 0x8A, 0xE6, 0x8E, 0x13, 0x9D, 0x15, 0x0D, 0x80, 0x4B, 0xC4, 0x9F, 0x08 };
4415         byte[] expected = { 0x0D, 0x7E, 0x32, 0xE0, 0xFA, 0x25, 0xB1, 0x52, 0x37, 0x27, 0xF3, 0x99, 0xA7, 0x08, 0x7F, 0x8E, 0xAA, 0x98, 0x36, 0x42, 0x21, 0xCF, 0x3B, 0xF1, 0x95, 0x99, 0xF4, 0x00, 0x36, 0x47, 0x0F, 0x25, 0x43, 0x36, 0x43, 0x68, 0x40, 0xB1, 0x1A, 0xFA, 0xDC, 0x43, 0x94, 0xD7, 0x16, 0x28, 0xFD, 0xDD };
4416
4417         SymmetricAlgorithm algo = Rijndael.Create ();
4418         algo.Mode = CipherMode.CBC;
4419         algo.Padding = PaddingMode.PKCS7;
4420         algo.BlockSize = 128;
4421         int blockLength = (algo.BlockSize >> 3);
4422         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4423         byte[] output = new byte [blockLength * 3];
4424         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4425         Encrypt (encryptor, input, output);
4426         AssertEquals ("Rijndael_k192b128_CBC_PKCS7 Encrypt", expected, output);
4427         byte[] reverse = new byte [blockLength * 3];
4428         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4429         Decrypt (decryptor, output, reverse);
4430         byte[] original = new byte [input.Length];
4431         Array.Copy (reverse, 0, original, 0, original.Length);
4432         AssertEquals ("Rijndael_k192b128_CBC_PKCS7 Decrypt", input, original);
4433 }
4434
4435
4436 /* Invalid parameters Rijndael_k192b128_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
4437
4438 /* Invalid parameters Rijndael_k192b128_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
4439
4440 /* Invalid parameters Rijndael_k192b128_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
4441
4442 /* Invalid parameters Rijndael_k192b128_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
4443
4444 /* Invalid parameters Rijndael_k192b128_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
4445
4446 /* Invalid parameters Rijndael_k192b128_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
4447
4448 /* Invalid parameters Rijndael_k192b128_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
4449
4450 /* Invalid parameters Rijndael_k192b128_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
4451
4452 /* Invalid parameters Rijndael_k192b128_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
4453
4454 [Test]
4455 public void TestRijndael_k192b192_ECB_None ()
4456 {
4457         byte[] key = { 0x33, 0x09, 0x20, 0xF4, 0x69, 0x76, 0x98, 0x57, 0x93, 0x1A, 0x37, 0x31, 0xFA, 0x2D, 0x49, 0xEA, 0xE4, 0xD4, 0x6C, 0xA5, 0x91, 0x2A, 0xD8, 0x54 };
4458         // not used for ECB but make the code more uniform
4459         byte[] iv = { 0x7F, 0x2E, 0xE0, 0x80, 0x52, 0x2F, 0x63, 0x3F, 0x8F, 0x09, 0x85, 0x3D, 0x21, 0x73, 0x40, 0x45, 0xB0, 0x85, 0xDE, 0xB9, 0xC0, 0xA1, 0x06, 0xB2 };
4460         byte[] expected = { 0x93, 0x0B, 0xF0, 0xA0, 0x0C, 0x79, 0x99, 0x40, 0x17, 0x62, 0xD6, 0xD8, 0x1C, 0x3B, 0xB3, 0x18, 0x57, 0xA6, 0x01, 0x68, 0xEA, 0x73, 0x9A, 0x0A, 0x93, 0x0B, 0xF0, 0xA0, 0x0C, 0x79, 0x99, 0x40, 0x17, 0x62, 0xD6, 0xD8, 0x1C, 0x3B, 0xB3, 0x18, 0x57, 0xA6, 0x01, 0x68, 0xEA, 0x73, 0x9A, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4461
4462         SymmetricAlgorithm algo = Rijndael.Create ();
4463         algo.Mode = CipherMode.ECB;
4464         algo.Padding = PaddingMode.None;
4465         algo.BlockSize = 192;
4466         int blockLength = (algo.BlockSize >> 3);
4467         byte[] input = new byte [blockLength * 2];
4468         byte[] output = new byte [blockLength * 3];
4469         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4470         Encrypt (encryptor, input, output);
4471         AssertEquals ("Rijndael_k192b192_ECB_None Encrypt", expected, output);
4472
4473         // in ECB the first 2 blocks should be equals (as the IV is not used)
4474         byte[] block1 = new byte[blockLength];
4475         Array.Copy (output, 0, block1, 0, blockLength);
4476         byte[] block2 = new byte[blockLength];
4477         Array.Copy (output, blockLength, block2, 0, blockLength);
4478         AssertEquals ("Rijndael_k192b192_ECB_None b1==b2", block1, block2);
4479         byte[] reverse = new byte [blockLength * 3];
4480         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4481         Decrypt (decryptor, output, reverse);
4482         byte[] original = new byte [input.Length];
4483         Array.Copy (reverse, 0, original, 0, original.Length);
4484         AssertEquals ("Rijndael_k192b192_ECB_None Decrypt", input, original);
4485 }
4486
4487
4488 [Test]
4489 public void TestRijndael_k192b192_ECB_Zeros ()
4490 {
4491         byte[] key = { 0xB5, 0x06, 0x72, 0x5F, 0x4E, 0x37, 0x62, 0x8F, 0x68, 0xE5, 0x0A, 0x80, 0xC6, 0x39, 0xB9, 0x13, 0xC7, 0xD8, 0x74, 0x1F, 0xE8, 0xD1, 0x99, 0x9E };
4492         // not used for ECB but make the code more uniform
4493         byte[] iv = { 0x11, 0x49, 0xA6, 0x58, 0x8F, 0xF1, 0x8E, 0xB3, 0x19, 0x81, 0xFE, 0xB8, 0x09, 0x69, 0x3D, 0x01, 0x21, 0x08, 0xCD, 0x1D, 0xEB, 0x98, 0xA7, 0xF1 };
4494         byte[] expected = { 0x42, 0xD5, 0xF0, 0x37, 0xFF, 0xBB, 0x81, 0xC1, 0x6F, 0x12, 0xCF, 0x65, 0x29, 0xC5, 0x88, 0xBE, 0x08, 0x88, 0xBF, 0x6F, 0xDF, 0x23, 0x82, 0x5E, 0x42, 0xD5, 0xF0, 0x37, 0xFF, 0xBB, 0x81, 0xC1, 0x6F, 0x12, 0xCF, 0x65, 0x29, 0xC5, 0x88, 0xBE, 0x08, 0x88, 0xBF, 0x6F, 0xDF, 0x23, 0x82, 0x5E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4495
4496         SymmetricAlgorithm algo = Rijndael.Create ();
4497         algo.Mode = CipherMode.ECB;
4498         algo.Padding = PaddingMode.Zeros;
4499         algo.BlockSize = 192;
4500         int blockLength = (algo.BlockSize >> 3);
4501         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4502         byte[] output = new byte [blockLength * 3];
4503         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4504         // some exception can be normal... other not so!
4505         try {
4506                 Encrypt (encryptor, input, output);
4507         }
4508         catch (Exception e) {
4509                 if (e.Message != "Input buffer contains insufficient data. ")
4510                         Assert.Fail ("Rijndael_k192b192_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
4511         }
4512 }
4513
4514
4515 [Test]
4516 public void TestRijndael_k192b192_ECB_PKCS7 ()
4517 {
4518         byte[] key = { 0x40, 0xE3, 0xF1, 0x90, 0xC2, 0xA9, 0x59, 0xB8, 0x01, 0x72, 0x01, 0x1F, 0x10, 0x11, 0x0E, 0x8F, 0xA1, 0xF2, 0x62, 0xD7, 0x0A, 0x65, 0xCD, 0xC4 };
4519         // not used for ECB but make the code more uniform
4520         byte[] iv = { 0x06, 0x08, 0x07, 0xB3, 0x8F, 0x84, 0xD9, 0xB3, 0xF9, 0x11, 0xFC, 0x0B, 0x9C, 0xC4, 0x6E, 0x41, 0xE1, 0xCC, 0x6F, 0x26, 0x6D, 0x70, 0xC6, 0x47 };
4521         byte[] expected = { 0xCD, 0x70, 0x93, 0x83, 0x82, 0xB1, 0xA3, 0x74, 0x8A, 0xBD, 0x0C, 0x0D, 0x8B, 0x9F, 0x3C, 0xDF, 0xBC, 0x8E, 0x64, 0x6E, 0xF7, 0xF5, 0x10, 0x0E, 0xCD, 0x70, 0x93, 0x83, 0x82, 0xB1, 0xA3, 0x74, 0x8A, 0xBD, 0x0C, 0x0D, 0x8B, 0x9F, 0x3C, 0xDF, 0xBC, 0x8E, 0x64, 0x6E, 0xF7, 0xF5, 0x10, 0x0E, 0x2D, 0xB2, 0xBD, 0xA1, 0x21, 0x56, 0xD1, 0x33, 0x00, 0x1C, 0x71, 0xAF, 0x9A, 0x48, 0x24, 0x00, 0xED, 0xA1, 0xE4, 0x2B, 0xF4, 0xF3, 0xD2, 0x5F };
4522
4523         SymmetricAlgorithm algo = Rijndael.Create ();
4524         algo.Mode = CipherMode.ECB;
4525         algo.Padding = PaddingMode.PKCS7;
4526         algo.BlockSize = 192;
4527         int blockLength = (algo.BlockSize >> 3);
4528         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4529         byte[] output = new byte [blockLength * 3];
4530         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4531         Encrypt (encryptor, input, output);
4532         AssertEquals ("Rijndael_k192b192_ECB_PKCS7 Encrypt", expected, output);
4533
4534         // in ECB the first 2 blocks should be equals (as the IV is not used)
4535         byte[] block1 = new byte[blockLength];
4536         Array.Copy (output, 0, block1, 0, blockLength);
4537         byte[] block2 = new byte[blockLength];
4538         Array.Copy (output, blockLength, block2, 0, blockLength);
4539         AssertEquals ("Rijndael_k192b192_ECB_PKCS7 b1==b2", block1, block2);
4540         byte[] reverse = new byte [blockLength * 3];
4541         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4542         Decrypt (decryptor, output, reverse);
4543         byte[] original = new byte [input.Length];
4544         Array.Copy (reverse, 0, original, 0, original.Length);
4545         AssertEquals ("Rijndael_k192b192_ECB_PKCS7 Decrypt", input, original);
4546 }
4547
4548
4549 [Test]
4550 public void TestRijndael_k192b192_CBC_None ()
4551 {
4552         byte[] key = { 0x21, 0x15, 0x8D, 0x66, 0x7D, 0x81, 0xD6, 0xBD, 0xFF, 0x6D, 0x3F, 0x44, 0x43, 0x0E, 0xD7, 0x07, 0xC9, 0x5F, 0xFF, 0x0A, 0x88, 0x2D, 0xC1, 0xC4 };
4553         byte[] iv = { 0x43, 0x68, 0xF9, 0x7E, 0xD4, 0x6D, 0xB9, 0xA7, 0x9D, 0xFF, 0x68, 0x7F, 0x4F, 0xBB, 0x14, 0x4D, 0x29, 0x4F, 0x94, 0x8A, 0x83, 0x02, 0x77, 0x1E };
4554         byte[] expected = { 0x13, 0xD5, 0x9A, 0x4A, 0x96, 0x7E, 0x4F, 0x67, 0x12, 0x31, 0x9B, 0xF5, 0xC5, 0x5A, 0x81, 0xC2, 0x43, 0x51, 0x57, 0x6D, 0xA2, 0xFC, 0x5F, 0x00, 0x49, 0x5A, 0x4E, 0x82, 0x3C, 0xE0, 0x7A, 0x89, 0x2F, 0x36, 0xB3, 0x84, 0x6E, 0x9B, 0x9A, 0xAA, 0x48, 0x1B, 0x0D, 0xA1, 0x42, 0xAD, 0x6F, 0x75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4555
4556         SymmetricAlgorithm algo = Rijndael.Create ();
4557         algo.Mode = CipherMode.CBC;
4558         algo.Padding = PaddingMode.None;
4559         algo.BlockSize = 192;
4560         int blockLength = (algo.BlockSize >> 3);
4561         byte[] input = new byte [blockLength * 2];
4562         byte[] output = new byte [blockLength * 3];
4563         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4564         Encrypt (encryptor, input, output);
4565         AssertEquals ("Rijndael_k192b192_CBC_None Encrypt", expected, output);
4566         byte[] reverse = new byte [blockLength * 3];
4567         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4568         Decrypt (decryptor, output, reverse);
4569         byte[] original = new byte [input.Length];
4570         Array.Copy (reverse, 0, original, 0, original.Length);
4571         AssertEquals ("Rijndael_k192b192_CBC_None Decrypt", input, original);
4572 }
4573
4574
4575 [Test]
4576 public void TestRijndael_k192b192_CBC_Zeros ()
4577 {
4578         byte[] key = { 0x81, 0x6F, 0xD7, 0x01, 0xCF, 0x7E, 0x73, 0x8E, 0x18, 0xB7, 0x91, 0x85, 0x70, 0x3B, 0x87, 0xCE, 0xA7, 0xB5, 0xB9, 0xFA, 0x30, 0x3D, 0x26, 0x28 };
4579         byte[] iv = { 0x5B, 0x34, 0x00, 0xA3, 0x3F, 0xEA, 0x2C, 0xAF, 0x87, 0xA3, 0xB9, 0x15, 0xF8, 0x61, 0x4A, 0x5C, 0x23, 0x2A, 0xF3, 0xA6, 0x7B, 0xFB, 0xEA, 0x1E };
4580         byte[] expected = { 0xF4, 0x87, 0x7B, 0xC8, 0x41, 0x2C, 0x8E, 0x2C, 0x58, 0x50, 0x6E, 0xE5, 0x79, 0xD1, 0xE8, 0x54, 0xE2, 0x13, 0x55, 0x91, 0x60, 0xF0, 0x35, 0x2D, 0xDB, 0x3A, 0x69, 0x92, 0x3B, 0xD1, 0x6D, 0x89, 0x57, 0x17, 0x2F, 0x31, 0xA1, 0xD9, 0xB1, 0x00, 0x41, 0x54, 0x0C, 0xFC, 0xA4, 0xE0, 0x7F, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4581
4582         SymmetricAlgorithm algo = Rijndael.Create ();
4583         algo.Mode = CipherMode.CBC;
4584         algo.Padding = PaddingMode.Zeros;
4585         algo.BlockSize = 192;
4586         int blockLength = (algo.BlockSize >> 3);
4587         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4588         byte[] output = new byte [blockLength * 3];
4589         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4590         // some exception can be normal... other not so!
4591         try {
4592                 Encrypt (encryptor, input, output);
4593         }
4594         catch (Exception e) {
4595                 if (e.Message != "Input buffer contains insufficient data. ")
4596                         Assert.Fail ("Rijndael_k192b192_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
4597         }
4598 }
4599
4600
4601 [Test]
4602 public void TestRijndael_k192b192_CBC_PKCS7 ()
4603 {
4604         byte[] key = { 0xF4, 0x68, 0x87, 0x59, 0x32, 0x8D, 0x10, 0xA8, 0xC1, 0x32, 0xD0, 0xEC, 0xE5, 0x4A, 0x8A, 0x11, 0x3E, 0x8E, 0x11, 0x48, 0x88, 0xE9, 0xC1, 0x1A };
4605         byte[] iv = { 0x72, 0xD8, 0x59, 0x64, 0xD0, 0x23, 0x1E, 0x6F, 0xF9, 0x16, 0x98, 0x61, 0x09, 0xE1, 0x33, 0xE2, 0x62, 0xB7, 0x9D, 0xD2, 0xCD, 0x5B, 0x47, 0xD8 };
4606         byte[] expected = { 0x0B, 0x3C, 0xDD, 0x1F, 0xCA, 0x36, 0x1C, 0x44, 0x0D, 0xC6, 0xC9, 0xF8, 0xE9, 0x96, 0x33, 0x52, 0x89, 0x66, 0x73, 0x9C, 0x43, 0x27, 0x76, 0xE4, 0x84, 0x4F, 0xEF, 0x68, 0x04, 0x83, 0x68, 0x1A, 0x08, 0xA5, 0x6C, 0x22, 0x83, 0x64, 0xD5, 0x9E, 0x58, 0x00, 0x5F, 0xEB, 0x6A, 0xEF, 0x36, 0xDD, 0xD4, 0xF4, 0x21, 0x9F, 0xAB, 0x87, 0xB3, 0xD0, 0x29, 0x04, 0x19, 0x14, 0xD1, 0xD1, 0x66, 0x37, 0x54, 0xBC, 0x40, 0x43, 0xF6, 0xF1, 0x8A, 0x67 };
4607
4608         SymmetricAlgorithm algo = Rijndael.Create ();
4609         algo.Mode = CipherMode.CBC;
4610         algo.Padding = PaddingMode.PKCS7;
4611         algo.BlockSize = 192;
4612         int blockLength = (algo.BlockSize >> 3);
4613         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4614         byte[] output = new byte [blockLength * 3];
4615         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4616         Encrypt (encryptor, input, output);
4617         AssertEquals ("Rijndael_k192b192_CBC_PKCS7 Encrypt", expected, output);
4618         byte[] reverse = new byte [blockLength * 3];
4619         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4620         Decrypt (decryptor, output, reverse);
4621         byte[] original = new byte [input.Length];
4622         Array.Copy (reverse, 0, original, 0, original.Length);
4623         AssertEquals ("Rijndael_k192b192_CBC_PKCS7 Decrypt", input, original);
4624 }
4625
4626
4627 /* Invalid parameters Rijndael_k192b192_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
4628
4629 /* Invalid parameters Rijndael_k192b192_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
4630
4631 /* Invalid parameters Rijndael_k192b192_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
4632
4633 /* Invalid parameters Rijndael_k192b192_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
4634
4635 /* Invalid parameters Rijndael_k192b192_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
4636
4637 /* Invalid parameters Rijndael_k192b192_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
4638
4639 /* Invalid parameters Rijndael_k192b192_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
4640
4641 /* Invalid parameters Rijndael_k192b192_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
4642
4643 /* Invalid parameters Rijndael_k192b192_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
4644
4645 [Test]
4646 public void TestRijndael_k192b256_ECB_None ()
4647 {
4648         byte[] key = { 0x07, 0xD5, 0xDE, 0x67, 0xAA, 0x99, 0x89, 0x35, 0x41, 0xAA, 0x04, 0x7B, 0xBB, 0x25, 0x91, 0x88, 0xDA, 0xA9, 0x5F, 0xD6, 0x05, 0xA4, 0xF4, 0x7B };
4649         // not used for ECB but make the code more uniform
4650         byte[] iv = { 0x21, 0x43, 0xAF, 0xF7, 0x20, 0x60, 0x95, 0x40, 0x42, 0x57, 0x2E, 0x1D, 0xAC, 0x95, 0x39, 0x71, 0x88, 0xDA, 0xC2, 0x22, 0xF4, 0xEA, 0xC8, 0x6F, 0x3B, 0x73, 0xBC, 0xA5, 0xC9, 0x56, 0x2B, 0x38 };
4651         byte[] expected = { 0xDA, 0xB8, 0xB7, 0xA7, 0x7D, 0x50, 0x08, 0x6A, 0x57, 0x3C, 0x1E, 0xA4, 0xED, 0xDD, 0x3F, 0x93, 0x99, 0x7E, 0xFC, 0x06, 0x3A, 0x9E, 0xAC, 0x82, 0x16, 0xCA, 0xE5, 0x79, 0x2C, 0xA1, 0xAC, 0x5D, 0xDA, 0xB8, 0xB7, 0xA7, 0x7D, 0x50, 0x08, 0x6A, 0x57, 0x3C, 0x1E, 0xA4, 0xED, 0xDD, 0x3F, 0x93, 0x99, 0x7E, 0xFC, 0x06, 0x3A, 0x9E, 0xAC, 0x82, 0x16, 0xCA, 0xE5, 0x79, 0x2C, 0xA1, 0xAC, 0x5D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4652
4653         SymmetricAlgorithm algo = Rijndael.Create ();
4654         algo.Mode = CipherMode.ECB;
4655         algo.Padding = PaddingMode.None;
4656         algo.BlockSize = 256;
4657         int blockLength = (algo.BlockSize >> 3);
4658         byte[] input = new byte [blockLength * 2];
4659         byte[] output = new byte [blockLength * 3];
4660         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4661         Encrypt (encryptor, input, output);
4662         AssertEquals ("Rijndael_k192b256_ECB_None Encrypt", expected, output);
4663
4664         // in ECB the first 2 blocks should be equals (as the IV is not used)
4665         byte[] block1 = new byte[blockLength];
4666         Array.Copy (output, 0, block1, 0, blockLength);
4667         byte[] block2 = new byte[blockLength];
4668         Array.Copy (output, blockLength, block2, 0, blockLength);
4669         AssertEquals ("Rijndael_k192b256_ECB_None b1==b2", block1, block2);
4670         byte[] reverse = new byte [blockLength * 3];
4671         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4672         Decrypt (decryptor, output, reverse);
4673         byte[] original = new byte [input.Length];
4674         Array.Copy (reverse, 0, original, 0, original.Length);
4675         AssertEquals ("Rijndael_k192b256_ECB_None Decrypt", input, original);
4676 }
4677
4678
4679 [Test]
4680 public void TestRijndael_k192b256_ECB_Zeros ()
4681 {
4682         byte[] key = { 0xE4, 0x87, 0x99, 0x8B, 0xD1, 0x33, 0x03, 0x25, 0x1A, 0xE4, 0x10, 0x6F, 0xC7, 0x7F, 0xC2, 0xDA, 0xAC, 0x99, 0x02, 0xFF, 0x34, 0xEF, 0x10, 0xC0 };
4683         // not used for ECB but make the code more uniform
4684         byte[] iv = { 0x67, 0xA7, 0x6E, 0xF5, 0xD8, 0xE2, 0xC3, 0xCB, 0x03, 0xF4, 0x6A, 0x01, 0x71, 0x8E, 0x02, 0xC7, 0x71, 0x73, 0xCF, 0x22, 0x76, 0x15, 0x87, 0x4F, 0x0D, 0x07, 0x43, 0xA6, 0x26, 0xAD, 0x15, 0xDA };
4685         byte[] expected = { 0xAB, 0x82, 0x14, 0x0D, 0x94, 0x36, 0x61, 0x9D, 0xF9, 0x39, 0xDA, 0x44, 0x34, 0xBA, 0x0D, 0xF5, 0xE6, 0xD2, 0x68, 0x53, 0x60, 0xC6, 0x98, 0x39, 0x4C, 0x90, 0xBE, 0xF6, 0x6E, 0xD8, 0xCB, 0xAA, 0xAB, 0x82, 0x14, 0x0D, 0x94, 0x36, 0x61, 0x9D, 0xF9, 0x39, 0xDA, 0x44, 0x34, 0xBA, 0x0D, 0xF5, 0xE6, 0xD2, 0x68, 0x53, 0x60, 0xC6, 0x98, 0x39, 0x4C, 0x90, 0xBE, 0xF6, 0x6E, 0xD8, 0xCB, 0xAA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4686
4687         SymmetricAlgorithm algo = Rijndael.Create ();
4688         algo.Mode = CipherMode.ECB;
4689         algo.Padding = PaddingMode.Zeros;
4690         algo.BlockSize = 256;
4691         int blockLength = (algo.BlockSize >> 3);
4692         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4693         byte[] output = new byte [blockLength * 3];
4694         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4695         // some exception can be normal... other not so!
4696         try {
4697                 Encrypt (encryptor, input, output);
4698         }
4699         catch (Exception e) {
4700                 if (e.Message != "Input buffer contains insufficient data. ")
4701                         Assert.Fail ("Rijndael_k192b256_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
4702         }
4703 }
4704
4705
4706 [Test]
4707 public void TestRijndael_k192b256_ECB_PKCS7 ()
4708 {
4709         byte[] key = { 0x15, 0x40, 0x0B, 0xA3, 0xFC, 0x69, 0xF7, 0x2B, 0x55, 0x6F, 0xE9, 0x2C, 0xDA, 0xF8, 0x49, 0xAA, 0x41, 0xB3, 0x3B, 0x61, 0xCA, 0x88, 0x58, 0x19 };
4710         // not used for ECB but make the code more uniform
4711         byte[] iv = { 0xCB, 0x37, 0xA1, 0x13, 0x44, 0x0D, 0x72, 0xC0, 0x8B, 0x0E, 0x62, 0xDB, 0xAF, 0x8D, 0x00, 0xC1, 0xF6, 0xF7, 0x2B, 0x60, 0x58, 0x09, 0x46, 0x95, 0x28, 0x9C, 0x87, 0x30, 0xE9, 0xA2, 0x95, 0x80 };
4712         byte[] expected = { 0xBE, 0x93, 0xB9, 0xEF, 0xC7, 0x57, 0x71, 0xD9, 0xFA, 0x17, 0x6F, 0x9D, 0xBE, 0x2A, 0xF2, 0xE8, 0x17, 0x39, 0x61, 0x6A, 0xEE, 0x51, 0x6D, 0x65, 0xEE, 0x27, 0x50, 0x82, 0xFB, 0x91, 0xFC, 0xDB, 0xBE, 0x93, 0xB9, 0xEF, 0xC7, 0x57, 0x71, 0xD9, 0xFA, 0x17, 0x6F, 0x9D, 0xBE, 0x2A, 0xF2, 0xE8, 0x17, 0x39, 0x61, 0x6A, 0xEE, 0x51, 0x6D, 0x65, 0xEE, 0x27, 0x50, 0x82, 0xFB, 0x91, 0xFC, 0xDB, 0x72, 0x86, 0xCA, 0xC3, 0x5C, 0x0F, 0x55, 0x79, 0x32, 0x96, 0x07, 0x86, 0xD7, 0xF3, 0x23, 0x53, 0xFC, 0x63, 0xBC, 0xD1, 0x76, 0x33, 0x7F, 0x72, 0xF1, 0x0A, 0x60, 0x7F, 0xB2, 0x6A, 0xBA, 0x0B };
4713
4714         SymmetricAlgorithm algo = Rijndael.Create ();
4715         algo.Mode = CipherMode.ECB;
4716         algo.Padding = PaddingMode.PKCS7;
4717         algo.BlockSize = 256;
4718         int blockLength = (algo.BlockSize >> 3);
4719         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4720         byte[] output = new byte [blockLength * 3];
4721         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4722         Encrypt (encryptor, input, output);
4723         AssertEquals ("Rijndael_k192b256_ECB_PKCS7 Encrypt", expected, output);
4724
4725         // in ECB the first 2 blocks should be equals (as the IV is not used)
4726         byte[] block1 = new byte[blockLength];
4727         Array.Copy (output, 0, block1, 0, blockLength);
4728         byte[] block2 = new byte[blockLength];
4729         Array.Copy (output, blockLength, block2, 0, blockLength);
4730         AssertEquals ("Rijndael_k192b256_ECB_PKCS7 b1==b2", block1, block2);
4731         byte[] reverse = new byte [blockLength * 3];
4732         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4733         Decrypt (decryptor, output, reverse);
4734         byte[] original = new byte [input.Length];
4735         Array.Copy (reverse, 0, original, 0, original.Length);
4736         AssertEquals ("Rijndael_k192b256_ECB_PKCS7 Decrypt", input, original);
4737 }
4738
4739
4740 [Test]
4741 public void TestRijndael_k192b256_CBC_None ()
4742 {
4743         byte[] key = { 0x3E, 0xFE, 0x6E, 0xF9, 0x4A, 0xCE, 0x96, 0xB7, 0xDD, 0x34, 0x15, 0x20, 0x85, 0xEA, 0x4B, 0x41, 0xEC, 0xFC, 0xDD, 0x37, 0xD9, 0xF1, 0x9A, 0xE4 };
4744         byte[] iv = { 0x04, 0x89, 0x29, 0x3F, 0x6A, 0x54, 0xED, 0xF3, 0x8D, 0x1F, 0x62, 0xC8, 0x8C, 0x05, 0x89, 0x62, 0xC2, 0x5E, 0xDB, 0xCA, 0x60, 0xE0, 0x17, 0x03, 0xE5, 0x69, 0x6B, 0x84, 0x44, 0x2C, 0x68, 0xB0 };
4745         byte[] expected = { 0xA5, 0xCB, 0x68, 0xA8, 0x8A, 0xE0, 0xFD, 0x68, 0xB3, 0x75, 0x51, 0xB8, 0x46, 0x08, 0xEC, 0xE3, 0xDA, 0xE9, 0xBF, 0x49, 0x65, 0x74, 0x84, 0xB7, 0x9A, 0x60, 0x89, 0x43, 0xF2, 0x35, 0xC2, 0xAB, 0x3F, 0xD3, 0x0A, 0x9A, 0x6A, 0x3D, 0xB4, 0x2C, 0xB0, 0x8B, 0x32, 0x28, 0x2B, 0x57, 0x8F, 0x2E, 0xCF, 0x37, 0x24, 0x9B, 0xB5, 0x3B, 0xE6, 0x5E, 0xA7, 0xB9, 0x10, 0x99, 0x36, 0xA7, 0x9C, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4746
4747         SymmetricAlgorithm algo = Rijndael.Create ();
4748         algo.Mode = CipherMode.CBC;
4749         algo.Padding = PaddingMode.None;
4750         algo.BlockSize = 256;
4751         int blockLength = (algo.BlockSize >> 3);
4752         byte[] input = new byte [blockLength * 2];
4753         byte[] output = new byte [blockLength * 3];
4754         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4755         Encrypt (encryptor, input, output);
4756         AssertEquals ("Rijndael_k192b256_CBC_None Encrypt", expected, output);
4757         byte[] reverse = new byte [blockLength * 3];
4758         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4759         Decrypt (decryptor, output, reverse);
4760         byte[] original = new byte [input.Length];
4761         Array.Copy (reverse, 0, original, 0, original.Length);
4762         AssertEquals ("Rijndael_k192b256_CBC_None Decrypt", input, original);
4763 }
4764
4765
4766 [Test]
4767 public void TestRijndael_k192b256_CBC_Zeros ()
4768 {
4769         byte[] key = { 0xB6, 0x93, 0x96, 0xA4, 0xD3, 0xE5, 0x73, 0x81, 0x17, 0x7B, 0x68, 0x92, 0x3A, 0xAF, 0x20, 0x45, 0x75, 0xBA, 0x43, 0x3C, 0x5E, 0x46, 0xF6, 0x15 };
4770         byte[] iv = { 0x17, 0x23, 0x3C, 0x0C, 0x51, 0xE2, 0x02, 0x8C, 0xC8, 0xD5, 0x5B, 0x00, 0x20, 0xE0, 0x2A, 0xC4, 0x4F, 0xCF, 0x4C, 0x1A, 0xCD, 0x59, 0x6C, 0x2D, 0x50, 0x8E, 0xF9, 0xA0, 0x3F, 0xFD, 0x81, 0xB5 };
4771         byte[] expected = { 0x93, 0xF0, 0xFC, 0x25, 0x3D, 0x6D, 0x74, 0x1F, 0x88, 0xC9, 0x9F, 0xE6, 0x3A, 0x24, 0x13, 0xE1, 0x7C, 0xEF, 0x79, 0xC6, 0x56, 0x87, 0xCB, 0xD0, 0xB7, 0x15, 0x91, 0x21, 0x7E, 0x17, 0xA2, 0xF1, 0xA6, 0xDA, 0xCA, 0xDF, 0x14, 0x88, 0x5C, 0x35, 0x13, 0x1E, 0xCD, 0x2E, 0xB0, 0xC8, 0x7E, 0x4A, 0xBE, 0xD9, 0x3B, 0x15, 0x8D, 0xC9, 0x2A, 0xC5, 0x2D, 0x7C, 0x24, 0xF3, 0xB4, 0x43, 0xDE, 0xBB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4772
4773         SymmetricAlgorithm algo = Rijndael.Create ();
4774         algo.Mode = CipherMode.CBC;
4775         algo.Padding = PaddingMode.Zeros;
4776         algo.BlockSize = 256;
4777         int blockLength = (algo.BlockSize >> 3);
4778         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4779         byte[] output = new byte [blockLength * 3];
4780         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4781         // some exception can be normal... other not so!
4782         try {
4783                 Encrypt (encryptor, input, output);
4784         }
4785         catch (Exception e) {
4786                 if (e.Message != "Input buffer contains insufficient data. ")
4787                         Assert.Fail ("Rijndael_k192b256_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
4788         }
4789 }
4790
4791
4792 [Test]
4793 public void TestRijndael_k192b256_CBC_PKCS7 ()
4794 {
4795         byte[] key = { 0x5B, 0x58, 0xA2, 0xF7, 0x12, 0x9B, 0xF1, 0x09, 0x14, 0x98, 0x6F, 0x75, 0x69, 0xF0, 0xB5, 0x02, 0xDE, 0x7E, 0xF3, 0xBF, 0x56, 0x69, 0xEC, 0x5C };
4796         byte[] iv = { 0x2E, 0x75, 0x1D, 0x3D, 0x2C, 0x01, 0x0B, 0x7A, 0xE6, 0x7C, 0x63, 0xB4, 0x1A, 0xF2, 0x48, 0x62, 0xF2, 0x7A, 0xF0, 0xFA, 0xC9, 0xAD, 0xFF, 0x88, 0x45, 0xE4, 0xFE, 0x5A, 0xA2, 0x87, 0x7A, 0x16 };
4797         byte[] expected = { 0xD2, 0x9B, 0x71, 0x41, 0xAF, 0xD2, 0x66, 0x52, 0xB1, 0x45, 0xEA, 0x7C, 0xFD, 0xF8, 0xD5, 0x13, 0xAE, 0x3E, 0xCE, 0x84, 0x5B, 0x2A, 0xBB, 0xEA, 0x11, 0xFC, 0x45, 0x98, 0x71, 0xC0, 0x2A, 0x9B, 0xD4, 0x4B, 0xDA, 0xC9, 0xED, 0x8A, 0x86, 0x0B, 0xC4, 0x53, 0x32, 0x46, 0x00, 0x59, 0x12, 0x58, 0x12, 0x8E, 0x95, 0x20, 0xA8, 0xE0, 0x96, 0xEB, 0x62, 0xAF, 0x09, 0x04, 0xE7, 0x00, 0xCE, 0x14, 0x7D, 0x62, 0xE2, 0xE8, 0x85, 0x35, 0x7B, 0x11, 0xCD, 0xA9, 0xA4, 0x48, 0x28, 0x9A, 0xA1, 0x5A, 0x3A, 0x0D, 0x24, 0x00, 0x14, 0xEE, 0x1D, 0x99, 0x46, 0x29, 0x57, 0x56, 0x12, 0x63, 0x08, 0xB1 };
4798
4799         SymmetricAlgorithm algo = Rijndael.Create ();
4800         algo.Mode = CipherMode.CBC;
4801         algo.Padding = PaddingMode.PKCS7;
4802         algo.BlockSize = 256;
4803         int blockLength = (algo.BlockSize >> 3);
4804         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4805         byte[] output = new byte [blockLength * 3];
4806         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4807         Encrypt (encryptor, input, output);
4808         AssertEquals ("Rijndael_k192b256_CBC_PKCS7 Encrypt", expected, output);
4809         byte[] reverse = new byte [blockLength * 3];
4810         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4811         Decrypt (decryptor, output, reverse);
4812         byte[] original = new byte [input.Length];
4813         Array.Copy (reverse, 0, original, 0, original.Length);
4814         AssertEquals ("Rijndael_k192b256_CBC_PKCS7 Decrypt", input, original);
4815 }
4816
4817
4818 /* Invalid parameters Rijndael_k192b256_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
4819
4820 /* Invalid parameters Rijndael_k192b256_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
4821
4822 /* Invalid parameters Rijndael_k192b256_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
4823
4824 /* Invalid parameters Rijndael_k192b256_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
4825
4826 /* Invalid parameters Rijndael_k192b256_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
4827
4828 /* Invalid parameters Rijndael_k192b256_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
4829
4830 /* Invalid parameters Rijndael_k192b256_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
4831
4832 /* Invalid parameters Rijndael_k192b256_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
4833
4834 /* Invalid parameters Rijndael_k192b256_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
4835
4836 [Test]
4837 public void TestRijndael_k256b128_ECB_None ()
4838 {
4839         byte[] key = { 0x5B, 0xA0, 0xA9, 0x6B, 0x20, 0x14, 0xF4, 0x4E, 0x2E, 0x9A, 0x34, 0x84, 0xD3, 0xB9, 0x62, 0x45, 0xB1, 0x98, 0x35, 0xAE, 0xA7, 0xED, 0x80, 0x67, 0xE2, 0x77, 0xC4, 0xD5, 0x6B, 0xBD, 0x6E, 0xCF };
4840         // not used for ECB but make the code more uniform
4841         byte[] iv = { 0xF5, 0xBD, 0x6D, 0xDF, 0x0C, 0x8E, 0xC5, 0x39, 0x25, 0xBE, 0x1A, 0x80, 0xF8, 0x79, 0xEC, 0x93 };
4842         byte[] expected = { 0x54, 0xF5, 0x87, 0xE7, 0x73, 0xB7, 0x04, 0xBF, 0xBB, 0x16, 0x3D, 0x5A, 0xC0, 0x68, 0x7C, 0x17, 0x54, 0xF5, 0x87, 0xE7, 0x73, 0xB7, 0x04, 0xBF, 0xBB, 0x16, 0x3D, 0x5A, 0xC0, 0x68, 0x7C, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4843
4844         SymmetricAlgorithm algo = Rijndael.Create ();
4845         algo.Mode = CipherMode.ECB;
4846         algo.Padding = PaddingMode.None;
4847         algo.BlockSize = 128;
4848         int blockLength = (algo.BlockSize >> 3);
4849         byte[] input = new byte [blockLength * 2];
4850         byte[] output = new byte [blockLength * 3];
4851         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4852         Encrypt (encryptor, input, output);
4853         AssertEquals ("Rijndael_k256b128_ECB_None Encrypt", expected, output);
4854
4855         // in ECB the first 2 blocks should be equals (as the IV is not used)
4856         byte[] block1 = new byte[blockLength];
4857         Array.Copy (output, 0, block1, 0, blockLength);
4858         byte[] block2 = new byte[blockLength];
4859         Array.Copy (output, blockLength, block2, 0, blockLength);
4860         AssertEquals ("Rijndael_k256b128_ECB_None b1==b2", block1, block2);
4861         byte[] reverse = new byte [blockLength * 3];
4862         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4863         Decrypt (decryptor, output, reverse);
4864         byte[] original = new byte [input.Length];
4865         Array.Copy (reverse, 0, original, 0, original.Length);
4866         AssertEquals ("Rijndael_k256b128_ECB_None Decrypt", input, original);
4867 }
4868
4869
4870 [Test]
4871 public void TestRijndael_k256b128_ECB_Zeros ()
4872 {
4873         byte[] key = { 0x77, 0xE1, 0xB2, 0xF9, 0x14, 0xF0, 0x77, 0xCE, 0xDB, 0x28, 0xD4, 0xA5, 0x0E, 0xA6, 0x73, 0x23, 0xD8, 0x46, 0xB7, 0x1A, 0x16, 0x92, 0xDB, 0x7E, 0x80, 0xDF, 0x5E, 0x9A, 0x16, 0x08, 0xFF, 0x6D };
4874         // not used for ECB but make the code more uniform
4875         byte[] iv = { 0x48, 0xEC, 0x4A, 0x12, 0xAC, 0x9C, 0xB5, 0x72, 0xEB, 0x12, 0x14, 0xFB, 0xE1, 0x6D, 0xCF, 0xA3 };
4876         byte[] expected = { 0x82, 0x6C, 0xC7, 0xA6, 0xC2, 0x57, 0x07, 0xF9, 0x2F, 0x92, 0x95, 0x90, 0x65, 0xFA, 0x1D, 0xFA, 0x82, 0x6C, 0xC7, 0xA6, 0xC2, 0x57, 0x07, 0xF9, 0x2F, 0x92, 0x95, 0x90, 0x65, 0xFA, 0x1D, 0xFA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4877
4878         SymmetricAlgorithm algo = Rijndael.Create ();
4879         algo.Mode = CipherMode.ECB;
4880         algo.Padding = PaddingMode.Zeros;
4881         algo.BlockSize = 128;
4882         int blockLength = (algo.BlockSize >> 3);
4883         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4884         byte[] output = new byte [blockLength * 3];
4885         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4886         // some exception can be normal... other not so!
4887         try {
4888                 Encrypt (encryptor, input, output);
4889         }
4890         catch (Exception e) {
4891                 if (e.Message != "Input buffer contains insufficient data. ")
4892                         Assert.Fail ("Rijndael_k256b128_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
4893         }
4894 }
4895
4896
4897 [Test]
4898 public void TestRijndael_k256b128_ECB_PKCS7 ()
4899 {
4900         byte[] key = { 0x19, 0xC2, 0x2D, 0x12, 0x57, 0x2B, 0xEF, 0x0C, 0xA2, 0xC7, 0x26, 0x7E, 0x35, 0xAD, 0xC5, 0x12, 0x53, 0x5D, 0xEE, 0xD7, 0x69, 0xC3, 0xB4, 0x0D, 0x9B, 0xEF, 0x36, 0xF7, 0xB2, 0xF2, 0xB0, 0x37 };
4901         // not used for ECB but make the code more uniform
4902         byte[] iv = { 0xCF, 0x8D, 0xBE, 0xE0, 0x41, 0xC6, 0xB9, 0xB5, 0x2D, 0x8A, 0x59, 0x92, 0x82, 0xF4, 0xE8, 0x74 };
4903         byte[] expected = { 0xAD, 0x99, 0x9A, 0xE2, 0x5B, 0xE7, 0xFB, 0x74, 0xE8, 0xAB, 0xEE, 0x5D, 0xCA, 0x0F, 0x0A, 0x7A, 0xAD, 0x99, 0x9A, 0xE2, 0x5B, 0xE7, 0xFB, 0x74, 0xE8, 0xAB, 0xEE, 0x5D, 0xCA, 0x0F, 0x0A, 0x7A, 0x8F, 0xAD, 0xBB, 0xC2, 0x18, 0xB8, 0xF0, 0xFF, 0x59, 0x7D, 0xF8, 0xF1, 0x6A, 0x21, 0x9C, 0xF3 };
4904
4905         SymmetricAlgorithm algo = Rijndael.Create ();
4906         algo.Mode = CipherMode.ECB;
4907         algo.Padding = PaddingMode.PKCS7;
4908         algo.BlockSize = 128;
4909         int blockLength = (algo.BlockSize >> 3);
4910         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4911         byte[] output = new byte [blockLength * 3];
4912         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4913         Encrypt (encryptor, input, output);
4914         AssertEquals ("Rijndael_k256b128_ECB_PKCS7 Encrypt", expected, output);
4915
4916         // in ECB the first 2 blocks should be equals (as the IV is not used)
4917         byte[] block1 = new byte[blockLength];
4918         Array.Copy (output, 0, block1, 0, blockLength);
4919         byte[] block2 = new byte[blockLength];
4920         Array.Copy (output, blockLength, block2, 0, blockLength);
4921         AssertEquals ("Rijndael_k256b128_ECB_PKCS7 b1==b2", block1, block2);
4922         byte[] reverse = new byte [blockLength * 3];
4923         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4924         Decrypt (decryptor, output, reverse);
4925         byte[] original = new byte [input.Length];
4926         Array.Copy (reverse, 0, original, 0, original.Length);
4927         AssertEquals ("Rijndael_k256b128_ECB_PKCS7 Decrypt", input, original);
4928 }
4929
4930
4931 [Test]
4932 public void TestRijndael_k256b128_CBC_None ()
4933 {
4934         byte[] key = { 0xE8, 0x74, 0x24, 0x77, 0x2B, 0xBE, 0x6C, 0x99, 0x2E, 0xFC, 0xB5, 0x85, 0xC9, 0xA1, 0xD7, 0x9C, 0x24, 0xF1, 0x86, 0x0B, 0xEA, 0xAB, 0xCB, 0x06, 0x47, 0x2E, 0x26, 0x6C, 0xAF, 0x24, 0x87, 0xA7 };
4935         byte[] iv = { 0x15, 0x7E, 0xA5, 0xE5, 0x47, 0xFA, 0x40, 0x30, 0x0A, 0xAA, 0x9E, 0x68, 0x8E, 0x4D, 0x2D, 0xA4 };
4936         byte[] expected = { 0xEF, 0x05, 0x1C, 0x5C, 0xEA, 0xED, 0x34, 0x28, 0x9E, 0x21, 0x9C, 0x2C, 0x96, 0xF5, 0xF7, 0xDA, 0x55, 0xD4, 0x88, 0x0A, 0x73, 0xF1, 0x8D, 0xBC, 0x8F, 0x17, 0x26, 0x86, 0x8A, 0xC1, 0x4B, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4937
4938         SymmetricAlgorithm algo = Rijndael.Create ();
4939         algo.Mode = CipherMode.CBC;
4940         algo.Padding = PaddingMode.None;
4941         algo.BlockSize = 128;
4942         int blockLength = (algo.BlockSize >> 3);
4943         byte[] input = new byte [blockLength * 2];
4944         byte[] output = new byte [blockLength * 3];
4945         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4946         Encrypt (encryptor, input, output);
4947         AssertEquals ("Rijndael_k256b128_CBC_None Encrypt", expected, output);
4948         byte[] reverse = new byte [blockLength * 3];
4949         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4950         Decrypt (decryptor, output, reverse);
4951         byte[] original = new byte [input.Length];
4952         Array.Copy (reverse, 0, original, 0, original.Length);
4953         AssertEquals ("Rijndael_k256b128_CBC_None Decrypt", input, original);
4954 }
4955
4956
4957 [Test]
4958 public void TestRijndael_k256b128_CBC_Zeros ()
4959 {
4960         byte[] key = { 0x50, 0x54, 0x8C, 0x92, 0xE5, 0xFD, 0x08, 0x03, 0xEA, 0x15, 0xBB, 0xB9, 0x39, 0x8B, 0x6E, 0xF0, 0xF5, 0x64, 0x49, 0x0E, 0x0F, 0x8F, 0x41, 0xF9, 0xA6, 0x1E, 0xD4, 0xD2, 0xB6, 0xF2, 0xB6, 0x4B };
4961         byte[] iv = { 0x32, 0x9B, 0x60, 0xF7, 0xBE, 0x0F, 0x5F, 0xA5, 0xD2, 0x7A, 0x1F, 0xB4, 0x01, 0x76, 0xD1, 0xCD };
4962         byte[] expected = { 0x6C, 0x55, 0xAD, 0x57, 0xEE, 0x78, 0x1D, 0x69, 0x82, 0x8D, 0xE5, 0x52, 0x4C, 0x76, 0xD7, 0xF1, 0xFA, 0xFC, 0xD1, 0x2D, 0xDC, 0x0F, 0xE4, 0x4F, 0xF0, 0xE5, 0xB0, 0x2B, 0x28, 0xBF, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4963
4964         SymmetricAlgorithm algo = Rijndael.Create ();
4965         algo.Mode = CipherMode.CBC;
4966         algo.Padding = PaddingMode.Zeros;
4967         algo.BlockSize = 128;
4968         int blockLength = (algo.BlockSize >> 3);
4969         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4970         byte[] output = new byte [blockLength * 3];
4971         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4972         // some exception can be normal... other not so!
4973         try {
4974                 Encrypt (encryptor, input, output);
4975         }
4976         catch (Exception e) {
4977                 if (e.Message != "Input buffer contains insufficient data. ")
4978                         Assert.Fail ("Rijndael_k256b128_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
4979         }
4980 }
4981
4982
4983 [Test]
4984 public void TestRijndael_k256b128_CBC_PKCS7 ()
4985 {
4986         byte[] key = { 0x8B, 0x8B, 0x4C, 0x04, 0x8C, 0x16, 0x16, 0x91, 0xBE, 0x79, 0x35, 0xF6, 0x26, 0x01, 0xF8, 0x06, 0x8F, 0xC7, 0x6D, 0xD6, 0xFE, 0xDE, 0xCF, 0xD8, 0xDC, 0xE1, 0x97, 0x9D, 0xA9, 0xD0, 0x96, 0x86 };
4987         byte[] iv = { 0xA0, 0xF5, 0x25, 0xE5, 0x17, 0xEA, 0x37, 0x18, 0x17, 0x56, 0x26, 0x1C, 0x63, 0x95, 0xC3, 0xAD };
4988         byte[] expected = { 0x42, 0x33, 0x8E, 0xDE, 0x2E, 0xDA, 0xC9, 0xC6, 0x97, 0xA2, 0xAE, 0xE1, 0x15, 0x00, 0xDE, 0x4A, 0x39, 0x0B, 0xEB, 0xC8, 0xF9, 0x9F, 0x00, 0x05, 0xCF, 0xB5, 0x32, 0x46, 0x91, 0xFC, 0x28, 0x23, 0xF4, 0xC5, 0xCE, 0x42, 0x63, 0x3F, 0x82, 0x7D, 0x2A, 0xC4, 0xB5, 0x09, 0x67, 0xC7, 0x33, 0x3F };
4989
4990         SymmetricAlgorithm algo = Rijndael.Create ();
4991         algo.Mode = CipherMode.CBC;
4992         algo.Padding = PaddingMode.PKCS7;
4993         algo.BlockSize = 128;
4994         int blockLength = (algo.BlockSize >> 3);
4995         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4996         byte[] output = new byte [blockLength * 3];
4997         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4998         Encrypt (encryptor, input, output);
4999         AssertEquals ("Rijndael_k256b128_CBC_PKCS7 Encrypt", expected, output);
5000         byte[] reverse = new byte [blockLength * 3];
5001         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5002         Decrypt (decryptor, output, reverse);
5003         byte[] original = new byte [input.Length];
5004         Array.Copy (reverse, 0, original, 0, original.Length);
5005         AssertEquals ("Rijndael_k256b128_CBC_PKCS7 Decrypt", input, original);
5006 }
5007
5008
5009 /* Invalid parameters Rijndael_k256b128_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
5010
5011 /* Invalid parameters Rijndael_k256b128_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
5012
5013 /* Invalid parameters Rijndael_k256b128_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
5014
5015 /* Invalid parameters Rijndael_k256b128_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
5016
5017 /* Invalid parameters Rijndael_k256b128_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
5018
5019 /* Invalid parameters Rijndael_k256b128_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
5020
5021 /* Invalid parameters Rijndael_k256b128_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
5022
5023 /* Invalid parameters Rijndael_k256b128_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
5024
5025 /* Invalid parameters Rijndael_k256b128_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
5026
5027 [Test]
5028 public void TestRijndael_k256b192_ECB_None ()
5029 {
5030         byte[] key = { 0xE3, 0x43, 0x35, 0xDB, 0xB7, 0xC8, 0x24, 0xBF, 0x25, 0xD2, 0xA3, 0xCD, 0x70, 0xEB, 0x6B, 0xB7, 0x6D, 0x64, 0xF4, 0xB8, 0xA0, 0x56, 0x52, 0xFB, 0x3A, 0x09, 0xD4, 0xD9, 0x4F, 0x09, 0x19, 0xAF };
5031         // not used for ECB but make the code more uniform
5032         byte[] iv = { 0xDB, 0x11, 0xE4, 0x50, 0x12, 0x29, 0xC8, 0x63, 0x61, 0xEC, 0xFE, 0xD3, 0xFE, 0xA2, 0x19, 0xE0, 0xEC, 0x2F, 0x56, 0x69, 0xB7, 0x41, 0x56, 0xB0 };
5033         byte[] expected = { 0x66, 0xD0, 0x72, 0x3B, 0xFA, 0x3F, 0x27, 0x81, 0xB6, 0x91, 0x78, 0x7A, 0x4C, 0xD0, 0xA0, 0x4C, 0x93, 0x56, 0x51, 0xA3, 0xE0, 0x69, 0x63, 0xAF, 0x66, 0xD0, 0x72, 0x3B, 0xFA, 0x3F, 0x27, 0x81, 0xB6, 0x91, 0x78, 0x7A, 0x4C, 0xD0, 0xA0, 0x4C, 0x93, 0x56, 0x51, 0xA3, 0xE0, 0x69, 0x63, 0xAF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5034
5035         SymmetricAlgorithm algo = Rijndael.Create ();
5036         algo.Mode = CipherMode.ECB;
5037         algo.Padding = PaddingMode.None;
5038         algo.BlockSize = 192;
5039         int blockLength = (algo.BlockSize >> 3);
5040         byte[] input = new byte [blockLength * 2];
5041         byte[] output = new byte [blockLength * 3];
5042         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5043         Encrypt (encryptor, input, output);
5044         AssertEquals ("Rijndael_k256b192_ECB_None Encrypt", expected, output);
5045
5046         // in ECB the first 2 blocks should be equals (as the IV is not used)
5047         byte[] block1 = new byte[blockLength];
5048         Array.Copy (output, 0, block1, 0, blockLength);
5049         byte[] block2 = new byte[blockLength];
5050         Array.Copy (output, blockLength, block2, 0, blockLength);
5051         AssertEquals ("Rijndael_k256b192_ECB_None b1==b2", block1, block2);
5052         byte[] reverse = new byte [blockLength * 3];
5053         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5054         Decrypt (decryptor, output, reverse);
5055         byte[] original = new byte [input.Length];
5056         Array.Copy (reverse, 0, original, 0, original.Length);
5057         AssertEquals ("Rijndael_k256b192_ECB_None Decrypt", input, original);
5058 }
5059
5060
5061 [Test]
5062 public void TestRijndael_k256b192_ECB_Zeros ()
5063 {
5064         byte[] key = { 0xCF, 0xAC, 0xFC, 0x30, 0x6C, 0x01, 0x16, 0x8A, 0x82, 0x52, 0x52, 0xC0, 0xC6, 0xAC, 0x1E, 0x60, 0x93, 0x17, 0x0A, 0x0C, 0x87, 0xE1, 0x4A, 0x78, 0xD9, 0xA6, 0x6B, 0xAF, 0x24, 0xF7, 0x8F, 0xED };
5065         // not used for ECB but make the code more uniform
5066         byte[] iv = { 0x99, 0x2B, 0x6B, 0x30, 0x56, 0x13, 0x2E, 0xE3, 0x3B, 0x2B, 0xC1, 0xA9, 0x4B, 0x3B, 0xD9, 0xC3, 0x7B, 0xA7, 0x4F, 0x26, 0xC9, 0x62, 0xC9, 0x66 };
5067         byte[] expected = { 0x22, 0x6B, 0xFA, 0x34, 0x8E, 0x09, 0xC2, 0xDF, 0xCA, 0x6C, 0xF5, 0x1F, 0xD2, 0xDC, 0x01, 0xC6, 0x3B, 0x73, 0x3F, 0x64, 0x91, 0x9F, 0xF6, 0xD3, 0x22, 0x6B, 0xFA, 0x34, 0x8E, 0x09, 0xC2, 0xDF, 0xCA, 0x6C, 0xF5, 0x1F, 0xD2, 0xDC, 0x01, 0xC6, 0x3B, 0x73, 0x3F, 0x64, 0x91, 0x9F, 0xF6, 0xD3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5068
5069         SymmetricAlgorithm algo = Rijndael.Create ();
5070         algo.Mode = CipherMode.ECB;
5071         algo.Padding = PaddingMode.Zeros;
5072         algo.BlockSize = 192;
5073         int blockLength = (algo.BlockSize >> 3);
5074         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5075         byte[] output = new byte [blockLength * 3];
5076         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5077         // some exception can be normal... other not so!
5078         try {
5079                 Encrypt (encryptor, input, output);
5080         }
5081         catch (Exception e) {
5082                 if (e.Message != "Input buffer contains insufficient data. ")
5083                         Assert.Fail ("Rijndael_k256b192_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
5084         }
5085 }
5086
5087
5088 [Test]
5089 public void TestRijndael_k256b192_ECB_PKCS7 ()
5090 {
5091         byte[] key = { 0x17, 0xF9, 0x4A, 0x56, 0x22, 0x77, 0x20, 0x33, 0x48, 0xCB, 0x06, 0x86, 0x44, 0x02, 0xCF, 0x52, 0xDA, 0x22, 0x36, 0x07, 0xE9, 0x9F, 0x3A, 0x28, 0x3E, 0xCB, 0x49, 0x51, 0xA4, 0x67, 0x60, 0xF3 };
5092         // not used for ECB but make the code more uniform
5093         byte[] iv = { 0x07, 0x77, 0x47, 0xC3, 0x49, 0x85, 0x7D, 0xB7, 0xED, 0xF3, 0x0D, 0x3F, 0x0F, 0xDC, 0xA6, 0x3E, 0x01, 0x53, 0x4D, 0x61, 0xEC, 0x06, 0xB4, 0xA0 };
5094         byte[] expected = { 0xA0, 0x34, 0x6F, 0xFD, 0x84, 0xA3, 0x54, 0xC0, 0x7E, 0xCC, 0x7D, 0x02, 0xE5, 0xDA, 0x79, 0x4E, 0xC6, 0xEB, 0xCE, 0x42, 0xD2, 0xBE, 0x68, 0x0F, 0xA0, 0x34, 0x6F, 0xFD, 0x84, 0xA3, 0x54, 0xC0, 0x7E, 0xCC, 0x7D, 0x02, 0xE5, 0xDA, 0x79, 0x4E, 0xC6, 0xEB, 0xCE, 0x42, 0xD2, 0xBE, 0x68, 0x0F, 0xBC, 0x22, 0x09, 0x5B, 0xFA, 0x92, 0x7E, 0xD8, 0xFF, 0x6A, 0xDD, 0x43, 0x63, 0x72, 0x23, 0xBA, 0xF9, 0xC8, 0x06, 0x3F, 0x51, 0xE8, 0x14, 0xE7 };
5095
5096         SymmetricAlgorithm algo = Rijndael.Create ();
5097         algo.Mode = CipherMode.ECB;
5098         algo.Padding = PaddingMode.PKCS7;
5099         algo.BlockSize = 192;
5100         int blockLength = (algo.BlockSize >> 3);
5101         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5102         byte[] output = new byte [blockLength * 3];
5103         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5104         Encrypt (encryptor, input, output);
5105         AssertEquals ("Rijndael_k256b192_ECB_PKCS7 Encrypt", expected, output);
5106
5107         // in ECB the first 2 blocks should be equals (as the IV is not used)
5108         byte[] block1 = new byte[blockLength];
5109         Array.Copy (output, 0, block1, 0, blockLength);
5110         byte[] block2 = new byte[blockLength];
5111         Array.Copy (output, blockLength, block2, 0, blockLength);
5112         AssertEquals ("Rijndael_k256b192_ECB_PKCS7 b1==b2", block1, block2);
5113         byte[] reverse = new byte [blockLength * 3];
5114         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5115         Decrypt (decryptor, output, reverse);
5116         byte[] original = new byte [input.Length];
5117         Array.Copy (reverse, 0, original, 0, original.Length);
5118         AssertEquals ("Rijndael_k256b192_ECB_PKCS7 Decrypt", input, original);
5119 }
5120
5121
5122 [Test]
5123 public void TestRijndael_k256b192_CBC_None ()
5124 {
5125         byte[] key = { 0x7A, 0x26, 0xAB, 0x32, 0x31, 0x49, 0x69, 0x3D, 0x68, 0x5A, 0xAC, 0x1B, 0x63, 0x85, 0x5A, 0x3D, 0xC4, 0xDE, 0xA8, 0x76, 0x00, 0x26, 0x78, 0x31, 0xB6, 0x30, 0xD8, 0xCB, 0x7E, 0xE7, 0xE9, 0x5B };
5126         byte[] iv = { 0x9D, 0x7B, 0xD5, 0x59, 0xCA, 0x42, 0xCB, 0x2F, 0x02, 0x65, 0xFE, 0x85, 0x63, 0xAE, 0x14, 0x4F, 0x69, 0xAA, 0xC2, 0xAF, 0x06, 0xF0, 0x48, 0x4F };
5127         byte[] expected = { 0x6C, 0x03, 0x84, 0x1C, 0x4E, 0xE0, 0x05, 0x67, 0xEA, 0x8D, 0x1C, 0x41, 0xFD, 0xC2, 0x90, 0x0E, 0xB9, 0xAA, 0xE5, 0xA0, 0x41, 0x62, 0xFE, 0xD8, 0x57, 0xA1, 0xCE, 0x33, 0x22, 0x09, 0xDB, 0x3B, 0xD7, 0x0A, 0x68, 0x61, 0x76, 0xB9, 0x8F, 0x7E, 0xE8, 0xD9, 0xA0, 0x46, 0x2B, 0x15, 0xC3, 0xF9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5128
5129         SymmetricAlgorithm algo = Rijndael.Create ();
5130         algo.Mode = CipherMode.CBC;
5131         algo.Padding = PaddingMode.None;
5132         algo.BlockSize = 192;
5133         int blockLength = (algo.BlockSize >> 3);
5134         byte[] input = new byte [blockLength * 2];
5135         byte[] output = new byte [blockLength * 3];
5136         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5137         Encrypt (encryptor, input, output);
5138         AssertEquals ("Rijndael_k256b192_CBC_None Encrypt", expected, output);
5139         byte[] reverse = new byte [blockLength * 3];
5140         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5141         Decrypt (decryptor, output, reverse);
5142         byte[] original = new byte [input.Length];
5143         Array.Copy (reverse, 0, original, 0, original.Length);
5144         AssertEquals ("Rijndael_k256b192_CBC_None Decrypt", input, original);
5145 }
5146
5147
5148 [Test]
5149 public void TestRijndael_k256b192_CBC_Zeros ()
5150 {
5151         byte[] key = { 0x35, 0x14, 0xF8, 0xDB, 0xB0, 0x84, 0x94, 0xD3, 0xDD, 0xE1, 0xB3, 0x21, 0x44, 0xE2, 0x9C, 0x65, 0x0A, 0x4A, 0x28, 0x7C, 0xD7, 0xD4, 0x9F, 0x49, 0x05, 0x23, 0x2C, 0xB2, 0x65, 0x17, 0x44, 0x2E };
5152         byte[] iv = { 0xD8, 0xA5, 0x77, 0x5C, 0x54, 0x79, 0x57, 0xE2, 0xBD, 0xF7, 0xD1, 0xF1, 0x6F, 0x52, 0x99, 0xBE, 0x04, 0x5E, 0x75, 0x51, 0xA6, 0x7D, 0xB9, 0x88 };
5153         byte[] expected = { 0xC8, 0x93, 0x1E, 0xED, 0x3F, 0x9F, 0x79, 0x34, 0x6C, 0x3F, 0x99, 0x4A, 0x25, 0xAF, 0x86, 0xDF, 0xDF, 0x19, 0x65, 0xE8, 0xAD, 0x75, 0x43, 0x1B, 0xCD, 0x1B, 0x15, 0x23, 0xC4, 0x49, 0x07, 0x31, 0x3E, 0xA2, 0x34, 0x58, 0xA0, 0x82, 0x9F, 0xF8, 0xB7, 0xB1, 0xBE, 0x59, 0xF1, 0x09, 0x5E, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5154
5155         SymmetricAlgorithm algo = Rijndael.Create ();
5156         algo.Mode = CipherMode.CBC;
5157         algo.Padding = PaddingMode.Zeros;
5158         algo.BlockSize = 192;
5159         int blockLength = (algo.BlockSize >> 3);
5160         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5161         byte[] output = new byte [blockLength * 3];
5162         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5163         // some exception can be normal... other not so!
5164         try {
5165                 Encrypt (encryptor, input, output);
5166         }
5167         catch (Exception e) {
5168                 if (e.Message != "Input buffer contains insufficient data. ")
5169                         Assert.Fail ("Rijndael_k256b192_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
5170         }
5171 }
5172
5173
5174 [Test]
5175 public void TestRijndael_k256b192_CBC_PKCS7 ()
5176 {
5177         byte[] key = { 0x18, 0x60, 0x4C, 0x76, 0x3D, 0x08, 0x05, 0x18, 0x66, 0xA8, 0xA5, 0x59, 0x9E, 0xB1, 0x12, 0x83, 0x70, 0x81, 0x40, 0x82, 0x09, 0xE4, 0x36, 0x41, 0xBB, 0x72, 0x53, 0xF3, 0xB6, 0x23, 0xAE, 0xB9 };
5178         byte[] iv = { 0xA9, 0xC1, 0x7A, 0x1D, 0xAF, 0x14, 0xFA, 0x7D, 0xEF, 0x7F, 0xDE, 0x9E, 0xE9, 0xD6, 0x1D, 0x61, 0x46, 0x2B, 0xC9, 0x24, 0x40, 0x0A, 0xE9, 0x9C };
5179         byte[] expected = { 0x9B, 0xE4, 0x1F, 0x94, 0xB2, 0x6B, 0x3E, 0x70, 0x69, 0x18, 0xCD, 0x65, 0xB7, 0xD9, 0xD9, 0x8E, 0xBB, 0xDA, 0xED, 0x5C, 0x84, 0xBA, 0x52, 0x4C, 0xA2, 0x66, 0xB8, 0x20, 0xEC, 0xB4, 0x16, 0xF1, 0x4C, 0xA2, 0xD0, 0x5F, 0x48, 0xDF, 0xA1, 0xDA, 0xEF, 0x75, 0xA8, 0x02, 0xCA, 0x57, 0x2E, 0x61, 0x94, 0x6A, 0x63, 0xFF, 0xBF, 0x2D, 0x44, 0x29, 0x38, 0x24, 0x50, 0x16, 0xE4, 0x41, 0x12, 0xBB, 0xF6, 0x67, 0x0A, 0xCF, 0x0A, 0xC9, 0x89, 0x55 };
5180
5181         SymmetricAlgorithm algo = Rijndael.Create ();
5182         algo.Mode = CipherMode.CBC;
5183         algo.Padding = PaddingMode.PKCS7;
5184         algo.BlockSize = 192;
5185         int blockLength = (algo.BlockSize >> 3);
5186         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5187         byte[] output = new byte [blockLength * 3];
5188         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5189         Encrypt (encryptor, input, output);
5190         AssertEquals ("Rijndael_k256b192_CBC_PKCS7 Encrypt", expected, output);
5191         byte[] reverse = new byte [blockLength * 3];
5192         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5193         Decrypt (decryptor, output, reverse);
5194         byte[] original = new byte [input.Length];
5195         Array.Copy (reverse, 0, original, 0, original.Length);
5196         AssertEquals ("Rijndael_k256b192_CBC_PKCS7 Decrypt", input, original);
5197 }
5198
5199
5200 /* Invalid parameters Rijndael_k256b192_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
5201
5202 /* Invalid parameters Rijndael_k256b192_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
5203
5204 /* Invalid parameters Rijndael_k256b192_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
5205
5206 /* Invalid parameters Rijndael_k256b192_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
5207
5208 /* Invalid parameters Rijndael_k256b192_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
5209
5210 /* Invalid parameters Rijndael_k256b192_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
5211
5212 /* Invalid parameters Rijndael_k256b192_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
5213
5214 /* Invalid parameters Rijndael_k256b192_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
5215
5216 /* Invalid parameters Rijndael_k256b192_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
5217
5218 [Test]
5219 public void TestRijndael_k256b256_ECB_None ()
5220 {
5221         byte[] key = { 0x04, 0x93, 0xC7, 0x1A, 0x3A, 0x62, 0x1E, 0x8B, 0x82, 0x6A, 0x20, 0x26, 0x5E, 0x29, 0x15, 0x0D, 0xCB, 0xD9, 0x49, 0x8A, 0x3E, 0x91, 0xE0, 0x8C, 0xE0, 0x9D, 0x8E, 0x15, 0x43, 0xE3, 0x1F, 0x9A };
5222         // not used for ECB but make the code more uniform
5223         byte[] iv = { 0x41, 0x3B, 0xE7, 0x01, 0x40, 0xB6, 0xB9, 0x54, 0x24, 0x38, 0x38, 0xB5, 0x8C, 0x90, 0x8D, 0x90, 0x9D, 0x68, 0xE6, 0x9C, 0x92, 0xCD, 0x95, 0x77, 0x96, 0xC6, 0xE8, 0xD5, 0xA5, 0x3E, 0xBD, 0xB9 };
5224         byte[] expected = { 0x2F, 0x30, 0x0F, 0xA2, 0x9C, 0x0E, 0xCA, 0x38, 0xD5, 0x43, 0xB6, 0xD4, 0xF9, 0x16, 0x65, 0xB8, 0xAA, 0x29, 0xB8, 0x16, 0xB7, 0x62, 0xE5, 0xFD, 0xC3, 0x4C, 0xA7, 0x7B, 0xC7, 0xF5, 0x5C, 0x1E, 0x2F, 0x30, 0x0F, 0xA2, 0x9C, 0x0E, 0xCA, 0x38, 0xD5, 0x43, 0xB6, 0xD4, 0xF9, 0x16, 0x65, 0xB8, 0xAA, 0x29, 0xB8, 0x16, 0xB7, 0x62, 0xE5, 0xFD, 0xC3, 0x4C, 0xA7, 0x7B, 0xC7, 0xF5, 0x5C, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5225
5226         SymmetricAlgorithm algo = Rijndael.Create ();
5227         algo.Mode = CipherMode.ECB;
5228         algo.Padding = PaddingMode.None;
5229         algo.BlockSize = 256;
5230         int blockLength = (algo.BlockSize >> 3);
5231         byte[] input = new byte [blockLength * 2];
5232         byte[] output = new byte [blockLength * 3];
5233         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5234         Encrypt (encryptor, input, output);
5235         AssertEquals ("Rijndael_k256b256_ECB_None Encrypt", expected, output);
5236
5237         // in ECB the first 2 blocks should be equals (as the IV is not used)
5238         byte[] block1 = new byte[blockLength];
5239         Array.Copy (output, 0, block1, 0, blockLength);
5240         byte[] block2 = new byte[blockLength];
5241         Array.Copy (output, blockLength, block2, 0, blockLength);
5242         AssertEquals ("Rijndael_k256b256_ECB_None b1==b2", block1, block2);
5243         byte[] reverse = new byte [blockLength * 3];
5244         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5245         Decrypt (decryptor, output, reverse);
5246         byte[] original = new byte [input.Length];
5247         Array.Copy (reverse, 0, original, 0, original.Length);
5248         AssertEquals ("Rijndael_k256b256_ECB_None Decrypt", input, original);
5249 }
5250
5251
5252 [Test]
5253 public void TestRijndael_k256b256_ECB_Zeros ()
5254 {
5255         byte[] key = { 0x52, 0x21, 0xDF, 0x3C, 0x96, 0x67, 0x86, 0x28, 0x80, 0x97, 0x12, 0xBB, 0xDD, 0x80, 0xE1, 0x04, 0xC8, 0x4B, 0x12, 0x3E, 0x28, 0x3F, 0x32, 0x38, 0xC8, 0xA0, 0x12, 0xFA, 0xFE, 0x8C, 0x0C, 0xEC };
5256         // not used for ECB but make the code more uniform
5257         byte[] iv = { 0xA9, 0x41, 0xB0, 0xE2, 0x23, 0x9A, 0x75, 0x56, 0x5F, 0x5D, 0xB8, 0x0B, 0xB1, 0xF1, 0x0F, 0xC2, 0x50, 0xBF, 0xA7, 0x3B, 0x8A, 0x26, 0xD4, 0x82, 0x33, 0xE1, 0x77, 0x84, 0xCC, 0x47, 0xCB, 0x85 };
5258         byte[] expected = { 0xB0, 0xC4, 0x5A, 0xDA, 0x21, 0x69, 0x9A, 0x80, 0xFC, 0xF4, 0xD1, 0xA5, 0xEE, 0x43, 0x44, 0x27, 0x4F, 0x42, 0x38, 0xFE, 0xC4, 0x2C, 0x75, 0x00, 0x60, 0x66, 0x1E, 0x86, 0xD0, 0xFC, 0x4B, 0x23, 0xB0, 0xC4, 0x5A, 0xDA, 0x21, 0x69, 0x9A, 0x80, 0xFC, 0xF4, 0xD1, 0xA5, 0xEE, 0x43, 0x44, 0x27, 0x4F, 0x42, 0x38, 0xFE, 0xC4, 0x2C, 0x75, 0x00, 0x60, 0x66, 0x1E, 0x86, 0xD0, 0xFC, 0x4B, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5259
5260         SymmetricAlgorithm algo = Rijndael.Create ();
5261         algo.Mode = CipherMode.ECB;
5262         algo.Padding = PaddingMode.Zeros;
5263         algo.BlockSize = 256;
5264         int blockLength = (algo.BlockSize >> 3);
5265         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5266         byte[] output = new byte [blockLength * 3];
5267         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5268         // some exception can be normal... other not so!
5269         try {
5270                 Encrypt (encryptor, input, output);
5271         }
5272         catch (Exception e) {
5273                 if (e.Message != "Input buffer contains insufficient data. ")
5274                         Assert.Fail ("Rijndael_k256b256_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
5275         }
5276 }
5277
5278
5279 [Test]
5280 public void TestRijndael_k256b256_ECB_PKCS7 ()
5281 {
5282         byte[] key = { 0xC6, 0x74, 0x58, 0xA6, 0xE0, 0xAD, 0xA2, 0x2F, 0x36, 0xC1, 0xD7, 0xAC, 0xAD, 0x8E, 0x66, 0x18, 0x8B, 0xEF, 0xBF, 0x1B, 0x75, 0xF0, 0xB0, 0x96, 0xBB, 0x07, 0xE9, 0x67, 0x25, 0x1B, 0xD0, 0x46 };
5283         // not used for ECB but make the code more uniform
5284         byte[] iv = { 0x3B, 0x34, 0x5E, 0x47, 0xE3, 0x51, 0xC4, 0xE4, 0x9A, 0x66, 0xD6, 0x42, 0x1B, 0x45, 0xAB, 0x03, 0x35, 0x9A, 0x52, 0xD8, 0x1E, 0xA3, 0xC8, 0xD8, 0xBB, 0x3E, 0xD1, 0x35, 0x2C, 0x90, 0xB1, 0xC7 };
5285         byte[] expected = { 0x48, 0xD6, 0xD0, 0x25, 0xC7, 0x71, 0x0E, 0x10, 0xB9, 0x05, 0xE4, 0xC9, 0xEF, 0xAD, 0xB8, 0x2B, 0x14, 0xAF, 0x10, 0x53, 0x27, 0x8F, 0x32, 0x2C, 0x25, 0x9D, 0xCE, 0x64, 0x22, 0x52, 0x29, 0xCB, 0x48, 0xD6, 0xD0, 0x25, 0xC7, 0x71, 0x0E, 0x10, 0xB9, 0x05, 0xE4, 0xC9, 0xEF, 0xAD, 0xB8, 0x2B, 0x14, 0xAF, 0x10, 0x53, 0x27, 0x8F, 0x32, 0x2C, 0x25, 0x9D, 0xCE, 0x64, 0x22, 0x52, 0x29, 0xCB, 0xDF, 0x29, 0xD6, 0xDD, 0xFB, 0x89, 0x4B, 0xD7, 0x24, 0x88, 0x8E, 0x74, 0x95, 0x79, 0xBD, 0xFB, 0x80, 0xCF, 0x34, 0x7C, 0xEC, 0x2A, 0xDF, 0xBB, 0x18, 0xF6, 0xB6, 0x41, 0x00, 0xA5, 0x00, 0x55 };
5286
5287         SymmetricAlgorithm algo = Rijndael.Create ();
5288         algo.Mode = CipherMode.ECB;
5289         algo.Padding = PaddingMode.PKCS7;
5290         algo.BlockSize = 256;
5291         int blockLength = (algo.BlockSize >> 3);
5292         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5293         byte[] output = new byte [blockLength * 3];
5294         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5295         Encrypt (encryptor, input, output);
5296         AssertEquals ("Rijndael_k256b256_ECB_PKCS7 Encrypt", expected, output);
5297
5298         // in ECB the first 2 blocks should be equals (as the IV is not used)
5299         byte[] block1 = new byte[blockLength];
5300         Array.Copy (output, 0, block1, 0, blockLength);
5301         byte[] block2 = new byte[blockLength];
5302         Array.Copy (output, blockLength, block2, 0, blockLength);
5303         AssertEquals ("Rijndael_k256b256_ECB_PKCS7 b1==b2", block1, block2);
5304         byte[] reverse = new byte [blockLength * 3];
5305         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5306         Decrypt (decryptor, output, reverse);
5307         byte[] original = new byte [input.Length];
5308         Array.Copy (reverse, 0, original, 0, original.Length);
5309         AssertEquals ("Rijndael_k256b256_ECB_PKCS7 Decrypt", input, original);
5310 }
5311
5312
5313 [Test]
5314 public void TestRijndael_k256b256_CBC_None ()
5315 {
5316         byte[] key = { 0x2E, 0x1E, 0x55, 0x9B, 0xA8, 0x5A, 0x1D, 0x2A, 0x6B, 0x4D, 0x95, 0x8E, 0x7C, 0xFC, 0x33, 0xCE, 0x00, 0xA3, 0xFA, 0xCE, 0x9F, 0xF6, 0xED, 0x0C, 0xD5, 0x3C, 0xB0, 0xF4, 0x87, 0x26, 0x1E, 0x12 };
5317         byte[] iv = { 0xB2, 0xCC, 0xA6, 0x99, 0x96, 0x9C, 0xC1, 0x20, 0x2A, 0xB1, 0x00, 0x28, 0x85, 0xE1, 0xB7, 0x74, 0x66, 0x02, 0xF5, 0x69, 0xE3, 0x1F, 0xA4, 0xF4, 0xFB, 0x90, 0x3F, 0xB2, 0x7E, 0x56, 0xC9, 0x6E };
5318         byte[] expected = { 0x4D, 0x77, 0x53, 0xBE, 0xDB, 0xB7, 0x4D, 0x1B, 0x9B, 0x1F, 0x65, 0x7A, 0xF1, 0x8F, 0x40, 0x0D, 0x60, 0x46, 0x08, 0x8B, 0x36, 0x83, 0x91, 0x8E, 0xDC, 0x23, 0x48, 0x1F, 0x4B, 0xCB, 0x09, 0x31, 0xDB, 0x73, 0xA6, 0xF3, 0xDB, 0x98, 0x06, 0xE9, 0xFA, 0x72, 0x4F, 0xDC, 0x3A, 0xF1, 0x08, 0x7B, 0x42, 0x1E, 0xD3, 0xDB, 0x91, 0xC3, 0x2C, 0x3D, 0xD7, 0x79, 0x17, 0x2A, 0xE1, 0x3C, 0x21, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5319
5320         SymmetricAlgorithm algo = Rijndael.Create ();
5321         algo.Mode = CipherMode.CBC;
5322         algo.Padding = PaddingMode.None;
5323         algo.BlockSize = 256;
5324         int blockLength = (algo.BlockSize >> 3);
5325         byte[] input = new byte [blockLength * 2];
5326         byte[] output = new byte [blockLength * 3];
5327         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5328         Encrypt (encryptor, input, output);
5329         AssertEquals ("Rijndael_k256b256_CBC_None Encrypt", expected, output);
5330         byte[] reverse = new byte [blockLength * 3];
5331         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5332         Decrypt (decryptor, output, reverse);
5333         byte[] original = new byte [input.Length];
5334         Array.Copy (reverse, 0, original, 0, original.Length);
5335         AssertEquals ("Rijndael_k256b256_CBC_None Decrypt", input, original);
5336 }
5337
5338
5339 [Test]
5340 public void TestRijndael_k256b256_CBC_Zeros ()
5341 {
5342         byte[] key = { 0xEE, 0x9F, 0xAB, 0x79, 0x11, 0x3F, 0x53, 0x56, 0x4C, 0xB4, 0xC3, 0x70, 0x29, 0x03, 0xB8, 0x26, 0x8C, 0x30, 0x2A, 0xD3, 0xF2, 0x1E, 0xA3, 0x42, 0xF4, 0xE6, 0x79, 0x5B, 0x0D, 0x93, 0xCF, 0x1B };
5343         byte[] iv = { 0xB0, 0x2A, 0x0F, 0x47, 0x4E, 0x47, 0xDB, 0x4A, 0xF2, 0xC7, 0xEB, 0xC3, 0xFA, 0xD3, 0x89, 0x0B, 0x46, 0x17, 0xDE, 0xB9, 0x18, 0x37, 0x6E, 0x83, 0x95, 0xD6, 0xF9, 0x25, 0xB5, 0xAC, 0x86, 0x9B };
5344         byte[] expected = { 0x6F, 0x0B, 0x2F, 0x3E, 0x9B, 0x07, 0xDE, 0x8B, 0xE9, 0xE7, 0xD7, 0x10, 0x09, 0xAF, 0x8E, 0x84, 0xB7, 0xBA, 0xD1, 0x79, 0x37, 0xF1, 0x25, 0xB6, 0xD7, 0xFC, 0xFB, 0x62, 0x83, 0x86, 0x8A, 0xD1, 0xC6, 0xDD, 0x98, 0x59, 0xE3, 0xEE, 0x9C, 0xA6, 0x73, 0x03, 0xE6, 0xB2, 0x72, 0xD0, 0x35, 0x39, 0xBB, 0x1C, 0x8F, 0x08, 0x8C, 0x70, 0x4C, 0x0C, 0xAD, 0xCB, 0x4F, 0x9D, 0xB7, 0x6A, 0x5F, 0xE9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5345
5346         SymmetricAlgorithm algo = Rijndael.Create ();
5347         algo.Mode = CipherMode.CBC;
5348         algo.Padding = PaddingMode.Zeros;
5349         algo.BlockSize = 256;
5350         int blockLength = (algo.BlockSize >> 3);
5351         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5352         byte[] output = new byte [blockLength * 3];
5353         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5354         // some exception can be normal... other not so!
5355         try {
5356                 Encrypt (encryptor, input, output);
5357         }
5358         catch (Exception e) {
5359                 if (e.Message != "Input buffer contains insufficient data. ")
5360                         Assert.Fail ("Rijndael_k256b256_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
5361         }
5362 }
5363
5364
5365 [Test]
5366 public void TestRijndael_k256b256_CBC_PKCS7 ()
5367 {
5368         byte[] key = { 0x63, 0x95, 0x5F, 0x23, 0xFE, 0x8B, 0x49, 0x09, 0xBD, 0x05, 0x0D, 0x47, 0xCE, 0x48, 0x86, 0x02, 0x58, 0x44, 0x78, 0x21, 0x28, 0x75, 0x2E, 0x3A, 0x80, 0xE4, 0x41, 0x97, 0x0F, 0xB8, 0xA4, 0xB1 };
5369         byte[] iv = { 0xE1, 0xC3, 0x6B, 0x5D, 0x4F, 0x86, 0x0D, 0x44, 0xD6, 0x73, 0x21, 0x50, 0x11, 0xD3, 0x41, 0x61, 0x33, 0x04, 0x1A, 0xF8, 0x50, 0x33, 0x93, 0x4A, 0x7F, 0x9F, 0x48, 0x27, 0x8C, 0x25, 0x90, 0x93 };
5370         byte[] expected = { 0x1F, 0x18, 0x81, 0x2B, 0xEA, 0xE1, 0x05, 0x56, 0xF5, 0x71, 0x73, 0x8C, 0x84, 0x9C, 0x46, 0xF9, 0x18, 0xEE, 0x08, 0xB1, 0x4B, 0x96, 0xC9, 0xC9, 0x70, 0xC8, 0x3B, 0xEC, 0x15, 0x40, 0x5C, 0xA0, 0x3A, 0xD1, 0x09, 0x0C, 0xD8, 0x6F, 0xAA, 0xF5, 0x34, 0x52, 0x3A, 0x51, 0x8F, 0x3A, 0xB0, 0x3E, 0xFB, 0x31, 0x43, 0x97, 0xA3, 0x05, 0xC6, 0xF2, 0x7F, 0x2A, 0xF0, 0x4F, 0xA8, 0x64, 0xE7, 0x06, 0xFB, 0x59, 0xD3, 0xFB, 0x9E, 0x72, 0x3B, 0x11, 0xEE, 0x88, 0xEC, 0x29, 0xB2, 0x51, 0xD9, 0x58, 0x42, 0x79, 0xFC, 0x35, 0xE2, 0xF1, 0x81, 0x45, 0x8F, 0x7E, 0xE1, 0xBA, 0x95, 0xC9, 0xDD, 0x76 };
5371
5372         SymmetricAlgorithm algo = Rijndael.Create ();
5373         algo.Mode = CipherMode.CBC;
5374         algo.Padding = PaddingMode.PKCS7;
5375         algo.BlockSize = 256;
5376         int blockLength = (algo.BlockSize >> 3);
5377         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5378         byte[] output = new byte [blockLength * 3];
5379         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5380         Encrypt (encryptor, input, output);
5381         AssertEquals ("Rijndael_k256b256_CBC_PKCS7 Encrypt", expected, output);
5382         byte[] reverse = new byte [blockLength * 3];
5383         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5384         Decrypt (decryptor, output, reverse);
5385         byte[] original = new byte [input.Length];
5386         Array.Copy (reverse, 0, original, 0, original.Length);
5387         AssertEquals ("Rijndael_k256b256_CBC_PKCS7 Decrypt", input, original);
5388 }
5389
5390
5391 /* Invalid parameters Rijndael_k256b256_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
5392
5393 /* Invalid parameters Rijndael_k256b256_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
5394
5395 /* Invalid parameters Rijndael_k256b256_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
5396
5397 /* Invalid parameters Rijndael_k256b256_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
5398
5399 /* Invalid parameters Rijndael_k256b256_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
5400
5401 /* Invalid parameters Rijndael_k256b256_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
5402
5403 /* Invalid parameters Rijndael_k256b256_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
5404
5405 /* Invalid parameters Rijndael_k256b256_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
5406
5407 /* Invalid parameters Rijndael_k256b256_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
5408
5409 [Test]
5410 public void TestTripleDES_k128b64_ECB_None ()
5411 {
5412         byte[] key = { 0x31, 0x29, 0x5A, 0x2D, 0x18, 0xDF, 0x78, 0xB1, 0xB3, 0x30, 0xB4, 0x2E, 0x08, 0x2A, 0xB5, 0x00 };
5413         // not used for ECB but make the code more uniform
5414         byte[] iv = { 0xDE, 0x87, 0xFF, 0xA6, 0x30, 0x76, 0x39, 0x89 };
5415         byte[] expected = { 0x74, 0xD2, 0x61, 0x01, 0xF0, 0x86, 0x74, 0xE8, 0x74, 0xD2, 0x61, 0x01, 0xF0, 0x86, 0x74, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5416
5417         SymmetricAlgorithm algo = TripleDES.Create ();
5418         algo.Mode = CipherMode.ECB;
5419         algo.Padding = PaddingMode.None;
5420         algo.BlockSize = 64;
5421         int blockLength = (algo.BlockSize >> 3);
5422         byte[] input = new byte [blockLength * 2];
5423         byte[] output = new byte [blockLength * 3];
5424         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5425         Encrypt (encryptor, input, output);
5426         AssertEquals ("TripleDES_k128b64_ECB_None Encrypt", expected, output);
5427
5428         // in ECB the first 2 blocks should be equals (as the IV is not used)
5429         byte[] block1 = new byte[blockLength];
5430         Array.Copy (output, 0, block1, 0, blockLength);
5431         byte[] block2 = new byte[blockLength];
5432         Array.Copy (output, blockLength, block2, 0, blockLength);
5433         AssertEquals ("TripleDES_k128b64_ECB_None b1==b2", block1, block2);
5434         byte[] reverse = new byte [blockLength * 3];
5435         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5436         Decrypt (decryptor, output, reverse);
5437         byte[] original = new byte [input.Length];
5438         Array.Copy (reverse, 0, original, 0, original.Length);
5439         AssertEquals ("TripleDES_k128b64_ECB_None Decrypt", input, original);
5440 }
5441
5442
5443 [Test]
5444 public void TestTripleDES_k128b64_ECB_Zeros ()
5445 {
5446         byte[] key = { 0xFB, 0xC1, 0xA8, 0x04, 0x47, 0x10, 0x09, 0x09, 0xA8, 0x3D, 0x97, 0x18, 0x11, 0x3C, 0x28, 0x80 };
5447         // not used for ECB but make the code more uniform
5448         byte[] iv = { 0xA2, 0x1F, 0x63, 0x49, 0x33, 0xCA, 0xEE, 0xDA };
5449         byte[] expected = { 0xDB, 0x4E, 0x92, 0x3D, 0xE3, 0x26, 0x0B, 0x16, 0xDB, 0x4E, 0x92, 0x3D, 0xE3, 0x26, 0x0B, 0x16, 0xDB, 0x4E, 0x92, 0x3D, 0xE3, 0x26, 0x0B, 0x16 };
5450
5451         SymmetricAlgorithm algo = TripleDES.Create ();
5452         algo.Mode = CipherMode.ECB;
5453         algo.Padding = PaddingMode.Zeros;
5454         algo.BlockSize = 64;
5455         int blockLength = (algo.BlockSize >> 3);
5456         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5457         byte[] output = new byte [blockLength * 3];
5458         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5459         Encrypt (encryptor, input, output);
5460         AssertEquals ("TripleDES_k128b64_ECB_Zeros Encrypt", expected, output);
5461
5462         // in ECB the first 2 blocks should be equals (as the IV is not used)
5463         byte[] block1 = new byte[blockLength];
5464         Array.Copy (output, 0, block1, 0, blockLength);
5465         byte[] block2 = new byte[blockLength];
5466         Array.Copy (output, blockLength, block2, 0, blockLength);
5467         AssertEquals ("TripleDES_k128b64_ECB_Zeros b1==b2", block1, block2);
5468
5469         // also if padding is Zeros then all three blocks should be equals
5470         byte[] block3 = new byte[blockLength];
5471         Array.Copy (output, blockLength, block3, 0, blockLength);
5472         AssertEquals ("TripleDES_k128b64_ECB_Zeros b1==b3", block1, block3);
5473
5474         byte[] reverse = new byte [blockLength * 3];
5475         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5476         Decrypt (decryptor, output, reverse);
5477         byte[] original = new byte [input.Length];
5478         Array.Copy (reverse, 0, original, 0, original.Length);
5479         AssertEquals ("TripleDES_k128b64_ECB_Zeros Decrypt", input, original);
5480 }
5481
5482
5483 [Test]
5484 public void TestTripleDES_k128b64_ECB_PKCS7 ()
5485 {
5486         byte[] key = { 0x78, 0x52, 0xAE, 0x73, 0x24, 0x0A, 0xDF, 0x80, 0x1A, 0xDE, 0x32, 0x90, 0x3C, 0x01, 0xBA, 0x12 };
5487         // not used for ECB but make the code more uniform
5488         byte[] iv = { 0xF6, 0x11, 0x79, 0x5E, 0xEC, 0xDC, 0x5E, 0x19 };
5489         byte[] expected = { 0x83, 0xDE, 0x8A, 0xDA, 0x7A, 0x46, 0xDC, 0x07, 0x83, 0xDE, 0x8A, 0xDA, 0x7A, 0x46, 0xDC, 0x07, 0x4B, 0x79, 0x8C, 0x46, 0x0A, 0xB7, 0x40, 0x6C };
5490
5491         SymmetricAlgorithm algo = TripleDES.Create ();
5492         algo.Mode = CipherMode.ECB;
5493         algo.Padding = PaddingMode.PKCS7;
5494         algo.BlockSize = 64;
5495         int blockLength = (algo.BlockSize >> 3);
5496         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5497         byte[] output = new byte [blockLength * 3];
5498         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5499         Encrypt (encryptor, input, output);
5500         AssertEquals ("TripleDES_k128b64_ECB_PKCS7 Encrypt", expected, output);
5501
5502         // in ECB the first 2 blocks should be equals (as the IV is not used)
5503         byte[] block1 = new byte[blockLength];
5504         Array.Copy (output, 0, block1, 0, blockLength);
5505         byte[] block2 = new byte[blockLength];
5506         Array.Copy (output, blockLength, block2, 0, blockLength);
5507         AssertEquals ("TripleDES_k128b64_ECB_PKCS7 b1==b2", block1, block2);
5508         byte[] reverse = new byte [blockLength * 3];
5509         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5510         Decrypt (decryptor, output, reverse);
5511         byte[] original = new byte [input.Length];
5512         Array.Copy (reverse, 0, original, 0, original.Length);
5513         AssertEquals ("TripleDES_k128b64_ECB_PKCS7 Decrypt", input, original);
5514 }
5515
5516
5517 [Test]
5518 public void TestTripleDES_k128b64_CBC_None ()
5519 {
5520         byte[] key = { 0x9B, 0x97, 0x95, 0xA2, 0x6D, 0x90, 0x1D, 0xAE, 0xE8, 0xFC, 0xA1, 0xA2, 0x06, 0x6E, 0x75, 0xE8 };
5521         byte[] iv = { 0x52, 0xF8, 0x0E, 0xA9, 0x8C, 0xD9, 0x46, 0x63 };
5522         byte[] expected = { 0xD3, 0x37, 0x2D, 0x9B, 0x69, 0x35, 0xB7, 0x80, 0xD1, 0x13, 0xBB, 0xEB, 0x47, 0xB6, 0xDA, 0xF2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5523
5524         SymmetricAlgorithm algo = TripleDES.Create ();
5525         algo.Mode = CipherMode.CBC;
5526         algo.Padding = PaddingMode.None;
5527         algo.BlockSize = 64;
5528         int blockLength = (algo.BlockSize >> 3);
5529         byte[] input = new byte [blockLength * 2];
5530         byte[] output = new byte [blockLength * 3];
5531         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5532         Encrypt (encryptor, input, output);
5533         AssertEquals ("TripleDES_k128b64_CBC_None Encrypt", expected, output);
5534         byte[] reverse = new byte [blockLength * 3];
5535         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5536         Decrypt (decryptor, output, reverse);
5537         byte[] original = new byte [input.Length];
5538         Array.Copy (reverse, 0, original, 0, original.Length);
5539         AssertEquals ("TripleDES_k128b64_CBC_None Decrypt", input, original);
5540 }
5541
5542
5543 [Test]
5544 public void TestTripleDES_k128b64_CBC_Zeros ()
5545 {
5546         byte[] key = { 0x21, 0x87, 0x57, 0xF4, 0xE5, 0xE9, 0x91, 0xC7, 0x3A, 0x64, 0x14, 0xF2, 0x2B, 0x06, 0x0E, 0x2E };
5547         byte[] iv = { 0x23, 0x86, 0x58, 0x7B, 0x49, 0x23, 0xF6, 0x7F };
5548         byte[] expected = { 0xEF, 0x1B, 0x0B, 0xDD, 0xD0, 0x07, 0x5E, 0x22, 0x9D, 0xB9, 0xCC, 0x52, 0xB4, 0xD9, 0x88, 0x1F, 0x5D, 0xE3, 0x51, 0x51, 0xBF, 0x7C, 0xB5, 0xB3 };
5549
5550         SymmetricAlgorithm algo = TripleDES.Create ();
5551         algo.Mode = CipherMode.CBC;
5552         algo.Padding = PaddingMode.Zeros;
5553         algo.BlockSize = 64;
5554         int blockLength = (algo.BlockSize >> 3);
5555         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5556         byte[] output = new byte [blockLength * 3];
5557         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5558         Encrypt (encryptor, input, output);
5559         AssertEquals ("TripleDES_k128b64_CBC_Zeros Encrypt", expected, output);
5560         byte[] reverse = new byte [blockLength * 3];
5561         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5562         Decrypt (decryptor, output, reverse);
5563         byte[] original = new byte [input.Length];
5564         Array.Copy (reverse, 0, original, 0, original.Length);
5565         AssertEquals ("TripleDES_k128b64_CBC_Zeros Decrypt", input, original);
5566 }
5567
5568
5569 [Test]
5570 public void TestTripleDES_k128b64_CBC_PKCS7 ()
5571 {
5572         byte[] key = { 0x06, 0x33, 0x4B, 0x5A, 0xF0, 0xC6, 0xAE, 0x71, 0x8C, 0x41, 0xB3, 0x72, 0x43, 0x4B, 0x82, 0x31 };
5573         byte[] iv = { 0x40, 0x7F, 0x60, 0x5B, 0x5C, 0x22, 0x8D, 0x5D };
5574         byte[] expected = { 0x9C, 0x3F, 0x6A, 0x1D, 0xBD, 0x92, 0x1A, 0xFA, 0xD4, 0xA5, 0xEA, 0xB3, 0x77, 0xA0, 0x8B, 0xB0, 0x7E, 0x11, 0xFA, 0xA9, 0x45, 0x46, 0x16, 0x33 };
5575
5576         SymmetricAlgorithm algo = TripleDES.Create ();
5577         algo.Mode = CipherMode.CBC;
5578         algo.Padding = PaddingMode.PKCS7;
5579         algo.BlockSize = 64;
5580         int blockLength = (algo.BlockSize >> 3);
5581         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5582         byte[] output = new byte [blockLength * 3];
5583         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5584         Encrypt (encryptor, input, output);
5585         AssertEquals ("TripleDES_k128b64_CBC_PKCS7 Encrypt", expected, output);
5586         byte[] reverse = new byte [blockLength * 3];
5587         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5588         Decrypt (decryptor, output, reverse);
5589         byte[] original = new byte [input.Length];
5590         Array.Copy (reverse, 0, original, 0, original.Length);
5591         AssertEquals ("TripleDES_k128b64_CBC_PKCS7 Decrypt", input, original);
5592 }
5593
5594
5595 /* Invalid parameters TripleDES_k128b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
5596
5597 /* Invalid parameters TripleDES_k128b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
5598
5599 /* Invalid parameters TripleDES_k128b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
5600
5601 [Test]
5602 public void TestTripleDES_k128b64_CFB8_None ()
5603 {
5604         byte[] key = { 0x49, 0x9D, 0x94, 0x9C, 0x79, 0xD9, 0xEE, 0x92, 0x75, 0xE8, 0x8C, 0x78, 0xE3, 0xB5, 0x49, 0x81 };
5605         byte[] iv = { 0x80, 0x0A, 0x45, 0x55, 0xCB, 0xC7, 0x17, 0xA1 };
5606         byte[] expected = { 0xA5, 0x0F, 0xFF, 0xE6, 0xA0, 0x59, 0x58, 0x81, 0xB0, 0xFE, 0x19, 0x40, 0xF4, 0x04, 0x0B, 0xE7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5607
5608         SymmetricAlgorithm algo = TripleDES.Create ();
5609         algo.Mode = CipherMode.CFB;
5610         algo.Padding = PaddingMode.None;
5611         algo.BlockSize = 64;
5612         algo.FeedbackSize = 8;
5613         int blockLength = (algo.BlockSize >> 3);
5614         byte[] input = new byte [blockLength * 2];
5615         byte[] output = new byte [blockLength * 3];
5616         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5617         Encrypt (encryptor, input, output);
5618         AssertEquals ("TripleDES_k128b64_CFB8_None Encrypt", expected, output);
5619         byte[] reverse = new byte [blockLength * 3];
5620         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5621         Decrypt (decryptor, output, reverse);
5622         byte[] original = new byte [input.Length];
5623         Array.Copy (reverse, 0, original, 0, original.Length);
5624         AssertEquals ("TripleDES_k128b64_CFB8_None Decrypt", input, original);
5625 }
5626
5627
5628 [Test]
5629 public void TestTripleDES_k128b64_CFB8_Zeros ()
5630 {
5631         byte[] key = { 0x47, 0xD4, 0x00, 0xC6, 0x0B, 0xCE, 0x0D, 0x6B, 0xD6, 0xEB, 0xBF, 0x74, 0xE3, 0xB9, 0x61, 0x14 };
5632         byte[] iv = { 0x63, 0xB1, 0xCE, 0xEF, 0x06, 0x14, 0xD6, 0x4B };
5633         byte[] expected = { 0x02, 0xB8, 0xB8, 0x49, 0xA8, 0x3B, 0x6B, 0x05, 0x74, 0x79, 0x91, 0xFE, 0x7B, 0x74, 0x0A, 0xF8, 0x95, 0x80, 0x5A, 0xF1, 0xE9, 0xD7, 0xD3, 0x32 };
5634
5635         SymmetricAlgorithm algo = TripleDES.Create ();
5636         algo.Mode = CipherMode.CFB;
5637         algo.Padding = PaddingMode.Zeros;
5638         algo.BlockSize = 64;
5639         algo.FeedbackSize = 8;
5640         int blockLength = (algo.BlockSize >> 3);
5641         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5642         byte[] output = new byte [blockLength * 3];
5643         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5644         Encrypt (encryptor, input, output);
5645         AssertEquals ("TripleDES_k128b64_CFB8_Zeros Encrypt", expected, output);
5646         byte[] reverse = new byte [blockLength * 3];
5647         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5648         Decrypt (decryptor, output, reverse);
5649         byte[] original = new byte [input.Length];
5650         Array.Copy (reverse, 0, original, 0, original.Length);
5651         AssertEquals ("TripleDES_k128b64_CFB8_Zeros Decrypt", input, original);
5652 }
5653
5654
5655 [Test]
5656 public void TestTripleDES_k128b64_CFB8_PKCS7 ()
5657 {
5658         byte[] key = { 0x70, 0x9E, 0x39, 0x1A, 0x45, 0xA4, 0x18, 0x30, 0xAC, 0xE6, 0x1E, 0x0E, 0xD7, 0x43, 0x39, 0x5F };
5659         byte[] iv = { 0x26, 0xF3, 0x46, 0x6A, 0x35, 0xC8, 0xBF, 0x03 };
5660         byte[] expected = { 0x88, 0x21, 0x01, 0x82, 0x88, 0x2E, 0x93, 0xC5, 0xCD, 0xA2, 0xC9, 0x38, 0x45, 0x68, 0x91, 0x82, 0xA5, 0x78, 0x6B, 0x08, 0x3F, 0x7C, 0xB8, 0x5F };
5661
5662         SymmetricAlgorithm algo = TripleDES.Create ();
5663         algo.Mode = CipherMode.CFB;
5664         algo.Padding = PaddingMode.PKCS7;
5665         algo.BlockSize = 64;
5666         algo.FeedbackSize = 8;
5667         int blockLength = (algo.BlockSize >> 3);
5668         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5669         byte[] output = new byte [blockLength * 3];
5670         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5671         Encrypt (encryptor, input, output);
5672         AssertEquals ("TripleDES_k128b64_CFB8_PKCS7 Encrypt", expected, output);
5673         byte[] reverse = new byte [blockLength * 3];
5674         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5675         Decrypt (decryptor, output, reverse);
5676         byte[] original = new byte [input.Length];
5677         Array.Copy (reverse, 0, original, 0, original.Length);
5678         AssertEquals ("TripleDES_k128b64_CFB8_PKCS7 Decrypt", input, original);
5679 }
5680
5681
5682 /* Invalid parameters TripleDES_k128b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
5683
5684 /* Invalid parameters TripleDES_k128b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
5685
5686 /* Invalid parameters TripleDES_k128b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
5687
5688 [Test]
5689 public void TestTripleDES_k192b64_ECB_None ()
5690 {
5691         byte[] key = { 0x02, 0xFE, 0x15, 0x59, 0xD7, 0xE9, 0xB5, 0x2A, 0xA7, 0x9B, 0xB3, 0xA6, 0xFA, 0xAA, 0xC7, 0x97, 0xD4, 0x1B, 0xE4, 0x2D, 0xE4, 0xC5, 0x89, 0xC2 };
5692         // not used for ECB but make the code more uniform
5693         byte[] iv = { 0x13, 0xBF, 0xF3, 0xA0, 0xD3, 0xA1, 0x2F, 0x23 };
5694         byte[] expected = { 0xC8, 0x09, 0x6E, 0xD6, 0xC8, 0xD8, 0xF3, 0x6A, 0xC8, 0x09, 0x6E, 0xD6, 0xC8, 0xD8, 0xF3, 0x6A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5695
5696         SymmetricAlgorithm algo = TripleDES.Create ();
5697         algo.Mode = CipherMode.ECB;
5698         algo.Padding = PaddingMode.None;
5699         algo.BlockSize = 64;
5700         int blockLength = (algo.BlockSize >> 3);
5701         byte[] input = new byte [blockLength * 2];
5702         byte[] output = new byte [blockLength * 3];
5703         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5704         Encrypt (encryptor, input, output);
5705         AssertEquals ("TripleDES_k192b64_ECB_None Encrypt", expected, output);
5706
5707         // in ECB the first 2 blocks should be equals (as the IV is not used)
5708         byte[] block1 = new byte[blockLength];
5709         Array.Copy (output, 0, block1, 0, blockLength);
5710         byte[] block2 = new byte[blockLength];
5711         Array.Copy (output, blockLength, block2, 0, blockLength);
5712         AssertEquals ("TripleDES_k192b64_ECB_None b1==b2", block1, block2);
5713         byte[] reverse = new byte [blockLength * 3];
5714         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5715         Decrypt (decryptor, output, reverse);
5716         byte[] original = new byte [input.Length];
5717         Array.Copy (reverse, 0, original, 0, original.Length);
5718         AssertEquals ("TripleDES_k192b64_ECB_None Decrypt", input, original);
5719 }
5720
5721
5722 [Test]
5723 public void TestTripleDES_k192b64_ECB_Zeros ()
5724 {
5725         byte[] key = { 0x0B, 0xB5, 0x02, 0xE8, 0xC3, 0x2E, 0x24, 0xD9, 0xF0, 0x29, 0x15, 0x10, 0x19, 0x88, 0xFC, 0xD2, 0x60, 0xCA, 0x30, 0x51, 0x0D, 0xD6, 0x80, 0xAC };
5726         // not used for ECB but make the code more uniform
5727         byte[] iv = { 0xF6, 0xC5, 0xBD, 0xA2, 0x4D, 0xA8, 0x19, 0x78 };
5728         byte[] expected = { 0xE0, 0x52, 0xCB, 0xC6, 0xBB, 0x43, 0x8F, 0x3B, 0xE0, 0x52, 0xCB, 0xC6, 0xBB, 0x43, 0x8F, 0x3B, 0xE0, 0x52, 0xCB, 0xC6, 0xBB, 0x43, 0x8F, 0x3B };
5729
5730         SymmetricAlgorithm algo = TripleDES.Create ();
5731         algo.Mode = CipherMode.ECB;
5732         algo.Padding = PaddingMode.Zeros;
5733         algo.BlockSize = 64;
5734         int blockLength = (algo.BlockSize >> 3);
5735         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5736         byte[] output = new byte [blockLength * 3];
5737         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5738         Encrypt (encryptor, input, output);
5739         AssertEquals ("TripleDES_k192b64_ECB_Zeros Encrypt", expected, output);
5740
5741         // in ECB the first 2 blocks should be equals (as the IV is not used)
5742         byte[] block1 = new byte[blockLength];
5743         Array.Copy (output, 0, block1, 0, blockLength);
5744         byte[] block2 = new byte[blockLength];
5745         Array.Copy (output, blockLength, block2, 0, blockLength);
5746         AssertEquals ("TripleDES_k192b64_ECB_Zeros b1==b2", block1, block2);
5747
5748         // also if padding is Zeros then all three blocks should be equals
5749         byte[] block3 = new byte[blockLength];
5750         Array.Copy (output, blockLength, block3, 0, blockLength);
5751         AssertEquals ("TripleDES_k192b64_ECB_Zeros b1==b3", block1, block3);
5752
5753         byte[] reverse = new byte [blockLength * 3];
5754         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5755         Decrypt (decryptor, output, reverse);
5756         byte[] original = new byte [input.Length];
5757         Array.Copy (reverse, 0, original, 0, original.Length);
5758         AssertEquals ("TripleDES_k192b64_ECB_Zeros Decrypt", input, original);
5759 }
5760
5761
5762 [Test]
5763 public void TestTripleDES_k192b64_ECB_PKCS7 ()
5764 {
5765         byte[] key = { 0x41, 0xAD, 0x00, 0xE4, 0x53, 0x0A, 0x09, 0x8C, 0x1F, 0x86, 0x91, 0x46, 0x41, 0xEC, 0xE3, 0x70, 0x35, 0xE5, 0x65, 0x10, 0x0D, 0x38, 0x4F, 0xE3 };
5766         // not used for ECB but make the code more uniform
5767         byte[] iv = { 0xB0, 0x71, 0x70, 0xFC, 0x57, 0xC2, 0x26, 0xF9 };
5768         byte[] expected = { 0xA3, 0xB3, 0x91, 0x00, 0x99, 0x7A, 0x15, 0xB4, 0xA3, 0xB3, 0x91, 0x00, 0x99, 0x7A, 0x15, 0xB4, 0x53, 0x35, 0xE6, 0x2D, 0x0D, 0xD1, 0x16, 0xE6 };
5769
5770         SymmetricAlgorithm algo = TripleDES.Create ();
5771         algo.Mode = CipherMode.ECB;
5772         algo.Padding = PaddingMode.PKCS7;
5773         algo.BlockSize = 64;
5774         int blockLength = (algo.BlockSize >> 3);
5775         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5776         byte[] output = new byte [blockLength * 3];
5777         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5778         Encrypt (encryptor, input, output);
5779         AssertEquals ("TripleDES_k192b64_ECB_PKCS7 Encrypt", expected, output);
5780
5781         // in ECB the first 2 blocks should be equals (as the IV is not used)
5782         byte[] block1 = new byte[blockLength];
5783         Array.Copy (output, 0, block1, 0, blockLength);
5784         byte[] block2 = new byte[blockLength];
5785         Array.Copy (output, blockLength, block2, 0, blockLength);
5786         AssertEquals ("TripleDES_k192b64_ECB_PKCS7 b1==b2", block1, block2);
5787         byte[] reverse = new byte [blockLength * 3];
5788         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5789         Decrypt (decryptor, output, reverse);
5790         byte[] original = new byte [input.Length];
5791         Array.Copy (reverse, 0, original, 0, original.Length);
5792         AssertEquals ("TripleDES_k192b64_ECB_PKCS7 Decrypt", input, original);
5793 }
5794
5795
5796 [Test]
5797 public void TestTripleDES_k192b64_CBC_None ()
5798 {
5799         byte[] key = { 0xA5, 0xA5, 0x3B, 0x8E, 0x59, 0x5B, 0xDD, 0xEC, 0x15, 0x22, 0x95, 0x53, 0xCB, 0xEC, 0xE3, 0x63, 0x78, 0x25, 0xF5, 0xE5, 0x52, 0xAD, 0x50, 0x1A };
5800         byte[] iv = { 0xBD, 0x69, 0xAC, 0xA6, 0xCF, 0x17, 0xFC, 0x8A };
5801         byte[] expected = { 0xA6, 0xA8, 0x8E, 0x09, 0xCF, 0xD2, 0x66, 0x4A, 0x20, 0xE8, 0xC3, 0x56, 0x8F, 0x2F, 0x42, 0x75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5802
5803         SymmetricAlgorithm algo = TripleDES.Create ();
5804         algo.Mode = CipherMode.CBC;
5805         algo.Padding = PaddingMode.None;
5806         algo.BlockSize = 64;
5807         int blockLength = (algo.BlockSize >> 3);
5808         byte[] input = new byte [blockLength * 2];
5809         byte[] output = new byte [blockLength * 3];
5810         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5811         Encrypt (encryptor, input, output);
5812         AssertEquals ("TripleDES_k192b64_CBC_None Encrypt", expected, output);
5813         byte[] reverse = new byte [blockLength * 3];
5814         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5815         Decrypt (decryptor, output, reverse);
5816         byte[] original = new byte [input.Length];
5817         Array.Copy (reverse, 0, original, 0, original.Length);
5818         AssertEquals ("TripleDES_k192b64_CBC_None Decrypt", input, original);
5819 }
5820
5821
5822 [Test]
5823 public void TestTripleDES_k192b64_CBC_Zeros ()
5824 {
5825         byte[] key = { 0x40, 0x3D, 0xEC, 0xE5, 0xB4, 0x2A, 0x4B, 0x5E, 0x81, 0x88, 0x3A, 0x53, 0x3F, 0xFD, 0xE7, 0x55, 0x50, 0x21, 0xAA, 0x0A, 0xB4, 0x3B, 0x26, 0xC0 };
5826         byte[] iv = { 0x09, 0x50, 0xF5, 0x6F, 0x18, 0xD1, 0x4C, 0x9E };
5827         byte[] expected = { 0x85, 0xFA, 0xBF, 0x39, 0x5C, 0x17, 0x13, 0xF1, 0x27, 0x47, 0x17, 0x97, 0xBA, 0xCD, 0x69, 0x8E, 0x0D, 0x7D, 0xC5, 0xE2, 0x8F, 0xDF, 0xFC, 0x2B };
5828
5829         SymmetricAlgorithm algo = TripleDES.Create ();
5830         algo.Mode = CipherMode.CBC;
5831         algo.Padding = PaddingMode.Zeros;
5832         algo.BlockSize = 64;
5833         int blockLength = (algo.BlockSize >> 3);
5834         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5835         byte[] output = new byte [blockLength * 3];
5836         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5837         Encrypt (encryptor, input, output);
5838         AssertEquals ("TripleDES_k192b64_CBC_Zeros Encrypt", expected, output);
5839         byte[] reverse = new byte [blockLength * 3];
5840         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5841         Decrypt (decryptor, output, reverse);
5842         byte[] original = new byte [input.Length];
5843         Array.Copy (reverse, 0, original, 0, original.Length);
5844         AssertEquals ("TripleDES_k192b64_CBC_Zeros Decrypt", input, original);
5845 }
5846
5847
5848 [Test]
5849 public void TestTripleDES_k192b64_CBC_PKCS7 ()
5850 {
5851         byte[] key = { 0x31, 0x9E, 0x55, 0x57, 0x3F, 0x77, 0xBC, 0x27, 0x79, 0x45, 0x7E, 0xAA, 0x4F, 0xF1, 0x2E, 0xBB, 0x98, 0xAE, 0xFD, 0xBE, 0x22, 0xB8, 0x69, 0xD9 };
5852         byte[] iv = { 0xF7, 0xD8, 0x8E, 0xB2, 0xC5, 0x5F, 0x49, 0x91 };
5853         byte[] expected = { 0x0D, 0xB8, 0xC7, 0x8F, 0x89, 0x26, 0x42, 0x50, 0x5E, 0x3A, 0x3B, 0x4D, 0xC8, 0x0E, 0x7E, 0x0F, 0xDA, 0x79, 0x37, 0x89, 0x2A, 0xF6, 0x10, 0x76 };
5854
5855         SymmetricAlgorithm algo = TripleDES.Create ();
5856         algo.Mode = CipherMode.CBC;
5857         algo.Padding = PaddingMode.PKCS7;
5858         algo.BlockSize = 64;
5859         int blockLength = (algo.BlockSize >> 3);
5860         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5861         byte[] output = new byte [blockLength * 3];
5862         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5863         Encrypt (encryptor, input, output);
5864         AssertEquals ("TripleDES_k192b64_CBC_PKCS7 Encrypt", expected, output);
5865         byte[] reverse = new byte [blockLength * 3];
5866         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5867         Decrypt (decryptor, output, reverse);
5868         byte[] original = new byte [input.Length];
5869         Array.Copy (reverse, 0, original, 0, original.Length);
5870         AssertEquals ("TripleDES_k192b64_CBC_PKCS7 Decrypt", input, original);
5871 }
5872
5873
5874 /* Invalid parameters TripleDES_k192b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
5875
5876 /* Invalid parameters TripleDES_k192b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
5877
5878 /* Invalid parameters TripleDES_k192b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
5879
5880 [Test]
5881 public void TestTripleDES_k192b64_CFB8_None ()
5882 {
5883         byte[] key = { 0x6C, 0x11, 0xA9, 0xC8, 0x04, 0xB3, 0x74, 0x8A, 0xA0, 0xC7, 0x43, 0x9A, 0x1F, 0x4C, 0x79, 0x08, 0x4D, 0xB4, 0x7B, 0xAC, 0xA2, 0xF8, 0x2C, 0x22 };
5884         byte[] iv = { 0x2E, 0xF8, 0x02, 0x62, 0x15, 0xE2, 0x8F, 0xB1 };
5885         byte[] expected = { 0x95, 0x55, 0x48, 0xF1, 0x6D, 0x6F, 0x36, 0x25, 0xAE, 0x02, 0x0B, 0x6E, 0xC3, 0x04, 0xC5, 0x93, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5886
5887         SymmetricAlgorithm algo = TripleDES.Create ();
5888         algo.Mode = CipherMode.CFB;
5889         algo.Padding = PaddingMode.None;
5890         algo.BlockSize = 64;
5891         algo.FeedbackSize = 8;
5892         int blockLength = (algo.BlockSize >> 3);
5893         byte[] input = new byte [blockLength * 2];
5894         byte[] output = new byte [blockLength * 3];
5895         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5896         Encrypt (encryptor, input, output);
5897         AssertEquals ("TripleDES_k192b64_CFB8_None Encrypt", expected, output);
5898         byte[] reverse = new byte [blockLength * 3];
5899         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5900         Decrypt (decryptor, output, reverse);
5901         byte[] original = new byte [input.Length];
5902         Array.Copy (reverse, 0, original, 0, original.Length);
5903         AssertEquals ("TripleDES_k192b64_CFB8_None Decrypt", input, original);
5904 }
5905
5906
5907 [Test]
5908 public void TestTripleDES_k192b64_CFB8_Zeros ()
5909 {
5910         byte[] key = { 0x34, 0x38, 0x7F, 0x40, 0xBA, 0x64, 0x88, 0xAC, 0x50, 0xE5, 0x0D, 0x9D, 0xC4, 0x0B, 0xDF, 0xE8, 0xB7, 0xCB, 0x9D, 0x38, 0xFD, 0x4E, 0x17, 0xDA };
5911         byte[] iv = { 0xC0, 0x32, 0xAE, 0xA8, 0xEB, 0x67, 0x74, 0xC4 };
5912         byte[] expected = { 0x8A, 0xE3, 0xAD, 0x43, 0x06, 0xAC, 0xC7, 0xE7, 0xCC, 0x03, 0xCE, 0xB1, 0x8F, 0x9F, 0x7A, 0x9E, 0xEB, 0x05, 0x74, 0x04, 0xF4, 0xFD, 0x76, 0x51 };
5913
5914         SymmetricAlgorithm algo = TripleDES.Create ();
5915         algo.Mode = CipherMode.CFB;
5916         algo.Padding = PaddingMode.Zeros;
5917         algo.BlockSize = 64;
5918         algo.FeedbackSize = 8;
5919         int blockLength = (algo.BlockSize >> 3);
5920         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5921         byte[] output = new byte [blockLength * 3];
5922         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5923         Encrypt (encryptor, input, output);
5924         AssertEquals ("TripleDES_k192b64_CFB8_Zeros Encrypt", expected, output);
5925         byte[] reverse = new byte [blockLength * 3];
5926         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5927         Decrypt (decryptor, output, reverse);
5928         byte[] original = new byte [input.Length];
5929         Array.Copy (reverse, 0, original, 0, original.Length);
5930         AssertEquals ("TripleDES_k192b64_CFB8_Zeros Decrypt", input, original);
5931 }
5932
5933
5934 [Test]
5935 public void TestTripleDES_k192b64_CFB8_PKCS7 ()
5936 {
5937         byte[] key = { 0xBC, 0x48, 0x95, 0x9F, 0x13, 0xFF, 0xCB, 0x33, 0x6D, 0xA5, 0x84, 0x93, 0x33, 0x54, 0xAD, 0xF4, 0x5F, 0x99, 0xA3, 0x0F, 0x0E, 0x91, 0x88, 0x0E };
5938         byte[] iv = { 0x0E, 0xC5, 0xA8, 0xB2, 0xDD, 0x83, 0xAE, 0x8C };
5939         byte[] expected = { 0xB5, 0x72, 0x20, 0x82, 0x45, 0x70, 0x83, 0xE5, 0xF0, 0xA6, 0xFC, 0xFC, 0xB6, 0xF4, 0x7D, 0x3B, 0x71, 0x94, 0x2A, 0x9F, 0x01, 0x46, 0x90, 0x56 };
5940
5941         SymmetricAlgorithm algo = TripleDES.Create ();
5942         algo.Mode = CipherMode.CFB;
5943         algo.Padding = PaddingMode.PKCS7;
5944         algo.BlockSize = 64;
5945         algo.FeedbackSize = 8;
5946         int blockLength = (algo.BlockSize >> 3);
5947         byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5948         byte[] output = new byte [blockLength * 3];
5949         ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5950         Encrypt (encryptor, input, output);
5951         AssertEquals ("TripleDES_k192b64_CFB8_PKCS7 Encrypt", expected, output);
5952         byte[] reverse = new byte [blockLength * 3];
5953         ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5954         Decrypt (decryptor, output, reverse);
5955         byte[] original = new byte [input.Length];
5956         Array.Copy (reverse, 0, original, 0, original.Length);
5957         AssertEquals ("TripleDES_k192b64_CFB8_PKCS7 Decrypt", input, original);
5958 }
5959
5960
5961 /* Invalid parameters TripleDES_k192b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
5962
5963 /* Invalid parameters TripleDES_k192b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
5964
5965 /* Invalid parameters TripleDES_k192b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
5966
5967
5968 // Number of test cases: 189
5969 // Number of invalid (non-generated) test cases: 171
5970 }
5971 }
5972