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
5 // SymmetricAlgorithmTest.cs - NUnit Test Cases for SymmetricAlgorithmTest
8 // Sebastien Pouliot (spouliot@motus.com)
10 // (C) 2002 Motus Technologies Inc. (http://www.motus.com)
13 using NUnit.Framework;
15 using System.Security.Cryptography;
18 namespace MonoTests.System.Security.Cryptography {
20 public class SymmetricAlgorithmTest : TestCase {
21 public void AssertEquals (string msg, byte[] array1, byte[] array2)
23 AllTests.AssertEquals (msg, array1, array2);
26 //--8<-- NON GENERATED CODE STARTS HERE --8<----8<----8<----8<----8<----8<--
28 //-->8-- NON GENERATED CODE ENDS HERE -->8---->8---->8---->8---->8---->8--
30 private void Encrypt (ICryptoTransform trans, byte[] input, byte[] output)
32 int bs = trans.InputBlockSize;
33 int full = input.Length / bs;
34 int partial = input.Length % bs;
36 for (int i=0; i < full; i++) {
37 trans.TransformBlock (input, pos, bs, output, pos);
41 byte[] final = trans.TransformFinalBlock (input, pos, partial);
42 Array.Copy (final, 0, output, pos, bs);
46 private void Decrypt (ICryptoTransform trans, byte[] input, byte[] output)
48 int bs = trans.InputBlockSize;
49 int full = input.Length / bs;
50 int partial = input.Length % bs;
52 for (int i=0; i < full; i++) {
53 trans.TransformBlock (input, pos, bs, output, pos);
57 byte[] final = trans.TransformFinalBlock (input, pos, partial);
58 Array.Copy (final, 0, output, pos, partial);
62 public void TestDES_k64b64_ECB_None ()
64 byte[] key = { 0x12, 0xE7, 0x7B, 0xBF, 0x11, 0x90, 0x9D, 0xB0 };
65 // not used for ECB but make the code more uniform
66 byte[] iv = { 0xD2, 0x0E, 0xA7, 0xA4, 0x00, 0xF3, 0x17, 0x69 };
67 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 };
69 SymmetricAlgorithm algo = DES.Create ();
70 algo.Mode = CipherMode.ECB;
71 algo.Padding = PaddingMode.None;
73 int blockLength = (algo.BlockSize >> 3);
74 byte[] input = new byte [blockLength * 2];
75 byte[] output = new byte [blockLength * 3];
76 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
77 Encrypt (encryptor, input, output);
78 AssertEquals ("DES_k64b64_ECB_None Encrypt", expected, output);
80 // in ECB the first 2 blocks should be equals (as the IV is not used)
81 byte[] block1 = new byte[blockLength];
82 Array.Copy (output, 0, block1, 0, blockLength);
83 byte[] block2 = new byte[blockLength];
84 Array.Copy (output, blockLength, block2, 0, blockLength);
85 AssertEquals ("DES_k64b64_ECB_None b1==b2", block1, block2);
86 byte[] reverse = new byte [blockLength * 3];
87 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
88 Decrypt (decryptor, output, reverse);
89 byte[] original = new byte [input.Length];
90 Array.Copy (reverse, 0, original, 0, original.Length);
91 AssertEquals ("DES_k64b64_ECB_None Decrypt", input, original);
95 public void TestDES_k64b64_ECB_Zeros ()
97 byte[] key = { 0x2E, 0xCA, 0x2E, 0xC9, 0x1A, 0xB6, 0x9A, 0x5A };
98 // not used for ECB but make the code more uniform
99 byte[] iv = { 0x79, 0x75, 0xD0, 0x3F, 0xFD, 0x1B, 0x12, 0x13 };
100 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 };
102 SymmetricAlgorithm algo = DES.Create ();
103 algo.Mode = CipherMode.ECB;
104 algo.Padding = PaddingMode.Zeros;
106 int blockLength = (algo.BlockSize >> 3);
107 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
108 byte[] output = new byte [blockLength * 3];
109 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
110 Encrypt (encryptor, input, output);
111 AssertEquals ("DES_k64b64_ECB_Zeros Encrypt", expected, output);
113 // in ECB the first 2 blocks should be equals (as the IV is not used)
114 byte[] block1 = new byte[blockLength];
115 Array.Copy (output, 0, block1, 0, blockLength);
116 byte[] block2 = new byte[blockLength];
117 Array.Copy (output, blockLength, block2, 0, blockLength);
118 AssertEquals ("DES_k64b64_ECB_Zeros b1==b2", block1, block2);
120 // also if padding is Zeros then all three blocks should be equals
121 byte[] block3 = new byte[blockLength];
122 Array.Copy (output, blockLength, block3, 0, blockLength);
123 AssertEquals ("DES_k64b64_ECB_Zeros b1==b3", block1, block3);
125 byte[] reverse = new byte [blockLength * 3];
126 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
127 Decrypt (decryptor, output, reverse);
128 byte[] original = new byte [input.Length];
129 Array.Copy (reverse, 0, original, 0, original.Length);
130 AssertEquals ("DES_k64b64_ECB_Zeros Decrypt", input, original);
134 public void TestDES_k64b64_ECB_PKCS7 ()
136 byte[] key = { 0x32, 0xE8, 0x8D, 0xF7, 0xDC, 0xFC, 0x6C, 0xCD };
137 // not used for ECB but make the code more uniform
138 byte[] iv = { 0x74, 0xB2, 0x5E, 0x33, 0xBD, 0xA3, 0xC1, 0xB8 };
139 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 };
141 SymmetricAlgorithm algo = DES.Create ();
142 algo.Mode = CipherMode.ECB;
143 algo.Padding = PaddingMode.PKCS7;
145 int blockLength = (algo.BlockSize >> 3);
146 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
147 byte[] output = new byte [blockLength * 3];
148 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
149 Encrypt (encryptor, input, output);
150 AssertEquals ("DES_k64b64_ECB_PKCS7 Encrypt", expected, output);
152 // in ECB the first 2 blocks should be equals (as the IV is not used)
153 byte[] block1 = new byte[blockLength];
154 Array.Copy (output, 0, block1, 0, blockLength);
155 byte[] block2 = new byte[blockLength];
156 Array.Copy (output, blockLength, block2, 0, blockLength);
157 AssertEquals ("DES_k64b64_ECB_PKCS7 b1==b2", block1, block2);
158 byte[] reverse = new byte [blockLength * 3];
159 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
160 Decrypt (decryptor, output, reverse);
161 byte[] original = new byte [input.Length];
162 Array.Copy (reverse, 0, original, 0, original.Length);
163 AssertEquals ("DES_k64b64_ECB_PKCS7 Decrypt", input, original);
167 public void TestDES_k64b64_CBC_None ()
169 byte[] key = { 0x91, 0xB4, 0x33, 0xB9, 0xA3, 0x7C, 0x47, 0x76 };
170 byte[] iv = { 0x96, 0x98, 0xCC, 0x84, 0xDD, 0xC3, 0xA1, 0x14 };
171 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 };
173 SymmetricAlgorithm algo = DES.Create ();
174 algo.Mode = CipherMode.CBC;
175 algo.Padding = PaddingMode.None;
177 int blockLength = (algo.BlockSize >> 3);
178 byte[] input = new byte [blockLength * 2];
179 byte[] output = new byte [blockLength * 3];
180 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
181 Encrypt (encryptor, input, output);
182 AssertEquals ("DES_k64b64_CBC_None Encrypt", expected, output);
183 byte[] reverse = new byte [blockLength * 3];
184 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
185 Decrypt (decryptor, output, reverse);
186 byte[] original = new byte [input.Length];
187 Array.Copy (reverse, 0, original, 0, original.Length);
188 AssertEquals ("DES_k64b64_CBC_None Decrypt", input, original);
192 public void TestDES_k64b64_CBC_Zeros ()
194 byte[] key = { 0x4A, 0x8B, 0xC7, 0xC5, 0x9C, 0x10, 0xB4, 0x6C };
195 byte[] iv = { 0x4B, 0x53, 0x53, 0xEA, 0xAF, 0xCC, 0x5A, 0x2B };
196 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 };
198 SymmetricAlgorithm algo = DES.Create ();
199 algo.Mode = CipherMode.CBC;
200 algo.Padding = PaddingMode.Zeros;
202 int blockLength = (algo.BlockSize >> 3);
203 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
204 byte[] output = new byte [blockLength * 3];
205 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
206 Encrypt (encryptor, input, output);
207 AssertEquals ("DES_k64b64_CBC_Zeros Encrypt", expected, output);
208 byte[] reverse = new byte [blockLength * 3];
209 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
210 Decrypt (decryptor, output, reverse);
211 byte[] original = new byte [input.Length];
212 Array.Copy (reverse, 0, original, 0, original.Length);
213 AssertEquals ("DES_k64b64_CBC_Zeros Decrypt", input, original);
217 public void TestDES_k64b64_CBC_PKCS7 ()
219 byte[] key = { 0xEA, 0x7D, 0x6D, 0x2C, 0xB8, 0x93, 0x33, 0xF4 };
220 byte[] iv = { 0x77, 0xE4, 0xAA, 0x7C, 0xFE, 0xA9, 0x0F, 0x94 };
221 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 };
223 SymmetricAlgorithm algo = DES.Create ();
224 algo.Mode = CipherMode.CBC;
225 algo.Padding = PaddingMode.PKCS7;
227 int blockLength = (algo.BlockSize >> 3);
228 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
229 byte[] output = new byte [blockLength * 3];
230 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
231 Encrypt (encryptor, input, output);
232 AssertEquals ("DES_k64b64_CBC_PKCS7 Encrypt", expected, output);
233 byte[] reverse = new byte [blockLength * 3];
234 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
235 Decrypt (decryptor, output, reverse);
236 byte[] original = new byte [input.Length];
237 Array.Copy (reverse, 0, original, 0, original.Length);
238 AssertEquals ("DES_k64b64_CBC_PKCS7 Decrypt", input, original);
242 /* Invalid parameters DES_k64b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
244 /* Invalid parameters DES_k64b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
246 /* Invalid parameters DES_k64b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
248 public void TestDES_k64b64_CFB8_None ()
250 byte[] key = { 0x52, 0x5E, 0x49, 0x90, 0x10, 0x20, 0x6D, 0x5C };
251 byte[] iv = { 0x00, 0x45, 0x9B, 0x7F, 0xC2, 0x9D, 0x90, 0x37 };
252 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 };
254 SymmetricAlgorithm algo = DES.Create ();
255 algo.Mode = CipherMode.CFB;
256 algo.Padding = PaddingMode.None;
258 algo.FeedbackSize = 8;
259 int blockLength = (algo.BlockSize >> 3);
260 byte[] input = new byte [blockLength * 2];
261 byte[] output = new byte [blockLength * 3];
262 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
263 Encrypt (encryptor, input, output);
264 AssertEquals ("DES_k64b64_CFB8_None Encrypt", expected, output);
265 byte[] reverse = new byte [blockLength * 3];
266 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
267 Decrypt (decryptor, output, reverse);
268 byte[] original = new byte [input.Length];
269 Array.Copy (reverse, 0, original, 0, original.Length);
270 AssertEquals ("DES_k64b64_CFB8_None Decrypt", input, original);
274 public void TestDES_k64b64_CFB8_Zeros ()
276 byte[] key = { 0xAF, 0x35, 0x0A, 0x91, 0x8F, 0x45, 0x46, 0xAF };
277 byte[] iv = { 0x3A, 0xF5, 0xCD, 0x22, 0xDC, 0xEF, 0xF4, 0x61 };
278 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 };
280 SymmetricAlgorithm algo = DES.Create ();
281 algo.Mode = CipherMode.CFB;
282 algo.Padding = PaddingMode.Zeros;
284 algo.FeedbackSize = 8;
285 int blockLength = (algo.BlockSize >> 3);
286 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
287 byte[] output = new byte [blockLength * 3];
288 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
289 Encrypt (encryptor, input, output);
290 AssertEquals ("DES_k64b64_CFB8_Zeros Encrypt", expected, output);
291 byte[] reverse = new byte [blockLength * 3];
292 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
293 Decrypt (decryptor, output, reverse);
294 byte[] original = new byte [input.Length];
295 Array.Copy (reverse, 0, original, 0, original.Length);
296 AssertEquals ("DES_k64b64_CFB8_Zeros Decrypt", input, original);
300 public void TestDES_k64b64_CFB8_PKCS7 ()
302 byte[] key = { 0x5D, 0xAD, 0x6F, 0xFF, 0x48, 0x89, 0x18, 0xE6 };
303 byte[] iv = { 0x98, 0x46, 0xD3, 0xFC, 0x1A, 0x59, 0xF6, 0x20 };
304 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 };
306 SymmetricAlgorithm algo = DES.Create ();
307 algo.Mode = CipherMode.CFB;
308 algo.Padding = PaddingMode.PKCS7;
310 algo.FeedbackSize = 8;
311 int blockLength = (algo.BlockSize >> 3);
312 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
313 byte[] output = new byte [blockLength * 3];
314 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
315 Encrypt (encryptor, input, output);
316 AssertEquals ("DES_k64b64_CFB8_PKCS7 Encrypt", expected, output);
317 byte[] reverse = new byte [blockLength * 3];
318 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
319 Decrypt (decryptor, output, reverse);
320 byte[] original = new byte [input.Length];
321 Array.Copy (reverse, 0, original, 0, original.Length);
322 AssertEquals ("DES_k64b64_CFB8_PKCS7 Decrypt", input, original);
326 /* Invalid parameters DES_k64b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
328 /* Invalid parameters DES_k64b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
330 /* Invalid parameters DES_k64b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
332 public void TestRC2_k40b64_ECB_None ()
334 byte[] key = { 0xC3, 0x69, 0xCB, 0x65, 0x22 };
335 // not used for ECB but make the code more uniform
336 byte[] iv = { 0x5E, 0x8E, 0xDB, 0xFD, 0x10, 0x1F, 0x14, 0x90 };
337 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 };
339 SymmetricAlgorithm algo = RC2.Create ();
340 algo.Mode = CipherMode.ECB;
341 algo.Padding = PaddingMode.None;
343 int blockLength = (algo.BlockSize >> 3);
344 byte[] input = new byte [blockLength * 2];
345 byte[] output = new byte [blockLength * 3];
346 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
347 Encrypt (encryptor, input, output);
348 AssertEquals ("RC2_k40b64_ECB_None Encrypt", expected, output);
350 // in ECB the first 2 blocks should be equals (as the IV is not used)
351 byte[] block1 = new byte[blockLength];
352 Array.Copy (output, 0, block1, 0, blockLength);
353 byte[] block2 = new byte[blockLength];
354 Array.Copy (output, blockLength, block2, 0, blockLength);
355 AssertEquals ("RC2_k40b64_ECB_None b1==b2", block1, block2);
356 byte[] reverse = new byte [blockLength * 3];
357 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
358 Decrypt (decryptor, output, reverse);
359 byte[] original = new byte [input.Length];
360 Array.Copy (reverse, 0, original, 0, original.Length);
361 AssertEquals ("RC2_k40b64_ECB_None Decrypt", input, original);
365 public void TestRC2_k40b64_ECB_Zeros ()
367 byte[] key = { 0x12, 0x66, 0x49, 0x15, 0xBC };
368 // not used for ECB but make the code more uniform
369 byte[] iv = { 0x3C, 0x1C, 0x38, 0x12, 0x1C, 0x78, 0x0C, 0x19 };
370 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 };
372 SymmetricAlgorithm algo = RC2.Create ();
373 algo.Mode = CipherMode.ECB;
374 algo.Padding = PaddingMode.Zeros;
376 int blockLength = (algo.BlockSize >> 3);
377 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
378 byte[] output = new byte [blockLength * 3];
379 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
380 Encrypt (encryptor, input, output);
381 AssertEquals ("RC2_k40b64_ECB_Zeros Encrypt", expected, output);
383 // in ECB the first 2 blocks should be equals (as the IV is not used)
384 byte[] block1 = new byte[blockLength];
385 Array.Copy (output, 0, block1, 0, blockLength);
386 byte[] block2 = new byte[blockLength];
387 Array.Copy (output, blockLength, block2, 0, blockLength);
388 AssertEquals ("RC2_k40b64_ECB_Zeros b1==b2", block1, block2);
390 // also if padding is Zeros then all three blocks should be equals
391 byte[] block3 = new byte[blockLength];
392 Array.Copy (output, blockLength, block3, 0, blockLength);
393 AssertEquals ("RC2_k40b64_ECB_Zeros b1==b3", block1, block3);
395 byte[] reverse = new byte [blockLength * 3];
396 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
397 Decrypt (decryptor, output, reverse);
398 byte[] original = new byte [input.Length];
399 Array.Copy (reverse, 0, original, 0, original.Length);
400 AssertEquals ("RC2_k40b64_ECB_Zeros Decrypt", input, original);
404 public void TestRC2_k40b64_ECB_PKCS7 ()
406 byte[] key = { 0xC2, 0x76, 0x2F, 0xCE, 0xED };
407 // not used for ECB but make the code more uniform
408 byte[] iv = { 0xB1, 0x88, 0x93, 0x03, 0xDA, 0x23, 0xE6, 0x87 };
409 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 };
411 SymmetricAlgorithm algo = RC2.Create ();
412 algo.Mode = CipherMode.ECB;
413 algo.Padding = PaddingMode.PKCS7;
415 int blockLength = (algo.BlockSize >> 3);
416 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
417 byte[] output = new byte [blockLength * 3];
418 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
419 Encrypt (encryptor, input, output);
420 AssertEquals ("RC2_k40b64_ECB_PKCS7 Encrypt", expected, output);
422 // in ECB the first 2 blocks should be equals (as the IV is not used)
423 byte[] block1 = new byte[blockLength];
424 Array.Copy (output, 0, block1, 0, blockLength);
425 byte[] block2 = new byte[blockLength];
426 Array.Copy (output, blockLength, block2, 0, blockLength);
427 AssertEquals ("RC2_k40b64_ECB_PKCS7 b1==b2", block1, block2);
428 byte[] reverse = new byte [blockLength * 3];
429 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
430 Decrypt (decryptor, output, reverse);
431 byte[] original = new byte [input.Length];
432 Array.Copy (reverse, 0, original, 0, original.Length);
433 AssertEquals ("RC2_k40b64_ECB_PKCS7 Decrypt", input, original);
437 public void TestRC2_k40b64_CBC_None ()
439 byte[] key = { 0xD0, 0xE1, 0x4E, 0x9C, 0x58 };
440 byte[] iv = { 0x8E, 0x5E, 0x76, 0x18, 0xB8, 0x76, 0xCF, 0x77 };
441 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 };
443 SymmetricAlgorithm algo = RC2.Create ();
444 algo.Mode = CipherMode.CBC;
445 algo.Padding = PaddingMode.None;
447 int blockLength = (algo.BlockSize >> 3);
448 byte[] input = new byte [blockLength * 2];
449 byte[] output = new byte [blockLength * 3];
450 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
451 Encrypt (encryptor, input, output);
452 AssertEquals ("RC2_k40b64_CBC_None Encrypt", expected, output);
453 byte[] reverse = new byte [blockLength * 3];
454 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
455 Decrypt (decryptor, output, reverse);
456 byte[] original = new byte [input.Length];
457 Array.Copy (reverse, 0, original, 0, original.Length);
458 AssertEquals ("RC2_k40b64_CBC_None Decrypt", input, original);
462 public void TestRC2_k40b64_CBC_Zeros ()
464 byte[] key = { 0xB5, 0x6F, 0xC7, 0x4F, 0xF8 };
465 byte[] iv = { 0xB6, 0x95, 0xE9, 0x3E, 0x04, 0x98, 0x39, 0x3D };
466 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 };
468 SymmetricAlgorithm algo = RC2.Create ();
469 algo.Mode = CipherMode.CBC;
470 algo.Padding = PaddingMode.Zeros;
472 int blockLength = (algo.BlockSize >> 3);
473 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
474 byte[] output = new byte [blockLength * 3];
475 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
476 Encrypt (encryptor, input, output);
477 AssertEquals ("RC2_k40b64_CBC_Zeros Encrypt", expected, output);
478 byte[] reverse = new byte [blockLength * 3];
479 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
480 Decrypt (decryptor, output, reverse);
481 byte[] original = new byte [input.Length];
482 Array.Copy (reverse, 0, original, 0, original.Length);
483 AssertEquals ("RC2_k40b64_CBC_Zeros Decrypt", input, original);
487 public void TestRC2_k40b64_CBC_PKCS7 ()
489 byte[] key = { 0x67, 0xB6, 0xEE, 0xF5, 0x21 };
490 byte[] iv = { 0xD3, 0xF1, 0xE7, 0xFF, 0x23, 0x92, 0xDC, 0xD9 };
491 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 };
493 SymmetricAlgorithm algo = RC2.Create ();
494 algo.Mode = CipherMode.CBC;
495 algo.Padding = PaddingMode.PKCS7;
497 int blockLength = (algo.BlockSize >> 3);
498 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
499 byte[] output = new byte [blockLength * 3];
500 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
501 Encrypt (encryptor, input, output);
502 AssertEquals ("RC2_k40b64_CBC_PKCS7 Encrypt", expected, output);
503 byte[] reverse = new byte [blockLength * 3];
504 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
505 Decrypt (decryptor, output, reverse);
506 byte[] original = new byte [input.Length];
507 Array.Copy (reverse, 0, original, 0, original.Length);
508 AssertEquals ("RC2_k40b64_CBC_PKCS7 Decrypt", input, original);
512 /* Invalid parameters RC2_k40b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
514 /* Invalid parameters RC2_k40b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
516 /* Invalid parameters RC2_k40b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
518 public void TestRC2_k40b64_CFB8_None ()
520 byte[] key = { 0x35, 0xCF, 0xA0, 0x20, 0x56 };
521 byte[] iv = { 0xC5, 0x47, 0xFA, 0x9D, 0x19, 0x4F, 0xA9, 0x06 };
522 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 };
524 SymmetricAlgorithm algo = RC2.Create ();
525 algo.Mode = CipherMode.CFB;
526 algo.Padding = PaddingMode.None;
528 algo.FeedbackSize = 8;
529 int blockLength = (algo.BlockSize >> 3);
530 byte[] input = new byte [blockLength * 2];
531 byte[] output = new byte [blockLength * 3];
532 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
533 Encrypt (encryptor, input, output);
534 AssertEquals ("RC2_k40b64_CFB8_None Encrypt", expected, output);
535 byte[] reverse = new byte [blockLength * 3];
536 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
537 Decrypt (decryptor, output, reverse);
538 byte[] original = new byte [input.Length];
539 Array.Copy (reverse, 0, original, 0, original.Length);
540 AssertEquals ("RC2_k40b64_CFB8_None Decrypt", input, original);
544 public void TestRC2_k40b64_CFB8_Zeros ()
546 byte[] key = { 0xDA, 0xD8, 0xF9, 0x76, 0xE4 };
547 byte[] iv = { 0xAA, 0xC5, 0x42, 0xF9, 0x88, 0x42, 0x09, 0xB4 };
548 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 };
550 SymmetricAlgorithm algo = RC2.Create ();
551 algo.Mode = CipherMode.CFB;
552 algo.Padding = PaddingMode.Zeros;
554 algo.FeedbackSize = 8;
555 int blockLength = (algo.BlockSize >> 3);
556 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
557 byte[] output = new byte [blockLength * 3];
558 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
559 Encrypt (encryptor, input, output);
560 AssertEquals ("RC2_k40b64_CFB8_Zeros Encrypt", expected, output);
561 byte[] reverse = new byte [blockLength * 3];
562 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
563 Decrypt (decryptor, output, reverse);
564 byte[] original = new byte [input.Length];
565 Array.Copy (reverse, 0, original, 0, original.Length);
566 AssertEquals ("RC2_k40b64_CFB8_Zeros Decrypt", input, original);
570 public void TestRC2_k40b64_CFB8_PKCS7 ()
572 byte[] key = { 0xDF, 0x8C, 0xC7, 0x3C, 0xDE };
573 byte[] iv = { 0x1D, 0x0A, 0x92, 0x74, 0xD6, 0xEB, 0x99, 0x0F };
574 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 };
576 SymmetricAlgorithm algo = RC2.Create ();
577 algo.Mode = CipherMode.CFB;
578 algo.Padding = PaddingMode.PKCS7;
580 algo.FeedbackSize = 8;
581 int blockLength = (algo.BlockSize >> 3);
582 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
583 byte[] output = new byte [blockLength * 3];
584 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
585 Encrypt (encryptor, input, output);
586 AssertEquals ("RC2_k40b64_CFB8_PKCS7 Encrypt", expected, output);
587 byte[] reverse = new byte [blockLength * 3];
588 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
589 Decrypt (decryptor, output, reverse);
590 byte[] original = new byte [input.Length];
591 Array.Copy (reverse, 0, original, 0, original.Length);
592 AssertEquals ("RC2_k40b64_CFB8_PKCS7 Decrypt", input, original);
596 /* Invalid parameters RC2_k40b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
598 /* Invalid parameters RC2_k40b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
600 /* Invalid parameters RC2_k40b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
602 public void TestRC2_k48b64_ECB_None ()
604 byte[] key = { 0xAA, 0x37, 0x60, 0x52, 0x8A, 0xBE };
605 // not used for ECB but make the code more uniform
606 byte[] iv = { 0x0D, 0x5B, 0x94, 0x0F, 0x9A, 0x87, 0x08, 0x56 };
607 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 };
609 SymmetricAlgorithm algo = RC2.Create ();
610 algo.Mode = CipherMode.ECB;
611 algo.Padding = PaddingMode.None;
613 int blockLength = (algo.BlockSize >> 3);
614 byte[] input = new byte [blockLength * 2];
615 byte[] output = new byte [blockLength * 3];
616 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
617 Encrypt (encryptor, input, output);
618 AssertEquals ("RC2_k48b64_ECB_None Encrypt", expected, output);
620 // in ECB the first 2 blocks should be equals (as the IV is not used)
621 byte[] block1 = new byte[blockLength];
622 Array.Copy (output, 0, block1, 0, blockLength);
623 byte[] block2 = new byte[blockLength];
624 Array.Copy (output, blockLength, block2, 0, blockLength);
625 AssertEquals ("RC2_k48b64_ECB_None b1==b2", block1, block2);
626 byte[] reverse = new byte [blockLength * 3];
627 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
628 Decrypt (decryptor, output, reverse);
629 byte[] original = new byte [input.Length];
630 Array.Copy (reverse, 0, original, 0, original.Length);
631 AssertEquals ("RC2_k48b64_ECB_None Decrypt", input, original);
635 public void TestRC2_k48b64_ECB_Zeros ()
637 byte[] key = { 0x9B, 0x92, 0x8C, 0xC2, 0x18, 0xA3 };
638 // not used for ECB but make the code more uniform
639 byte[] iv = { 0xB7, 0xC2, 0xAD, 0x13, 0x0A, 0x62, 0x0A, 0x50 };
640 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 };
642 SymmetricAlgorithm algo = RC2.Create ();
643 algo.Mode = CipherMode.ECB;
644 algo.Padding = PaddingMode.Zeros;
646 int blockLength = (algo.BlockSize >> 3);
647 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
648 byte[] output = new byte [blockLength * 3];
649 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
650 Encrypt (encryptor, input, output);
651 AssertEquals ("RC2_k48b64_ECB_Zeros Encrypt", expected, output);
653 // in ECB the first 2 blocks should be equals (as the IV is not used)
654 byte[] block1 = new byte[blockLength];
655 Array.Copy (output, 0, block1, 0, blockLength);
656 byte[] block2 = new byte[blockLength];
657 Array.Copy (output, blockLength, block2, 0, blockLength);
658 AssertEquals ("RC2_k48b64_ECB_Zeros b1==b2", block1, block2);
660 // also if padding is Zeros then all three blocks should be equals
661 byte[] block3 = new byte[blockLength];
662 Array.Copy (output, blockLength, block3, 0, blockLength);
663 AssertEquals ("RC2_k48b64_ECB_Zeros b1==b3", block1, block3);
665 byte[] reverse = new byte [blockLength * 3];
666 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
667 Decrypt (decryptor, output, reverse);
668 byte[] original = new byte [input.Length];
669 Array.Copy (reverse, 0, original, 0, original.Length);
670 AssertEquals ("RC2_k48b64_ECB_Zeros Decrypt", input, original);
674 public void TestRC2_k48b64_ECB_PKCS7 ()
676 byte[] key = { 0x58, 0x1A, 0xD6, 0x96, 0x02, 0x75 };
677 // not used for ECB but make the code more uniform
678 byte[] iv = { 0x56, 0x83, 0x39, 0x7F, 0x3B, 0xD9, 0xB0, 0x33 };
679 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 };
681 SymmetricAlgorithm algo = RC2.Create ();
682 algo.Mode = CipherMode.ECB;
683 algo.Padding = PaddingMode.PKCS7;
685 int blockLength = (algo.BlockSize >> 3);
686 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
687 byte[] output = new byte [blockLength * 3];
688 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
689 Encrypt (encryptor, input, output);
690 AssertEquals ("RC2_k48b64_ECB_PKCS7 Encrypt", expected, output);
692 // in ECB the first 2 blocks should be equals (as the IV is not used)
693 byte[] block1 = new byte[blockLength];
694 Array.Copy (output, 0, block1, 0, blockLength);
695 byte[] block2 = new byte[blockLength];
696 Array.Copy (output, blockLength, block2, 0, blockLength);
697 AssertEquals ("RC2_k48b64_ECB_PKCS7 b1==b2", block1, block2);
698 byte[] reverse = new byte [blockLength * 3];
699 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
700 Decrypt (decryptor, output, reverse);
701 byte[] original = new byte [input.Length];
702 Array.Copy (reverse, 0, original, 0, original.Length);
703 AssertEquals ("RC2_k48b64_ECB_PKCS7 Decrypt", input, original);
707 public void TestRC2_k48b64_CBC_None ()
709 byte[] key = { 0x21, 0x9A, 0xD6, 0x31, 0x99, 0x81 };
710 byte[] iv = { 0x5E, 0x6E, 0xB6, 0x33, 0xC0, 0x25, 0xAE, 0x5C };
711 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 };
713 SymmetricAlgorithm algo = RC2.Create ();
714 algo.Mode = CipherMode.CBC;
715 algo.Padding = PaddingMode.None;
717 int blockLength = (algo.BlockSize >> 3);
718 byte[] input = new byte [blockLength * 2];
719 byte[] output = new byte [blockLength * 3];
720 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
721 Encrypt (encryptor, input, output);
722 AssertEquals ("RC2_k48b64_CBC_None Encrypt", expected, output);
723 byte[] reverse = new byte [blockLength * 3];
724 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
725 Decrypt (decryptor, output, reverse);
726 byte[] original = new byte [input.Length];
727 Array.Copy (reverse, 0, original, 0, original.Length);
728 AssertEquals ("RC2_k48b64_CBC_None Decrypt", input, original);
732 public void TestRC2_k48b64_CBC_Zeros ()
734 byte[] key = { 0x59, 0x0A, 0xD4, 0x25, 0xA5, 0xB9 };
735 byte[] iv = { 0x10, 0x2D, 0x42, 0x54, 0xC8, 0x97, 0xD0, 0xA7 };
736 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 };
738 SymmetricAlgorithm algo = RC2.Create ();
739 algo.Mode = CipherMode.CBC;
740 algo.Padding = PaddingMode.Zeros;
742 int blockLength = (algo.BlockSize >> 3);
743 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
744 byte[] output = new byte [blockLength * 3];
745 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
746 Encrypt (encryptor, input, output);
747 AssertEquals ("RC2_k48b64_CBC_Zeros Encrypt", expected, output);
748 byte[] reverse = new byte [blockLength * 3];
749 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
750 Decrypt (decryptor, output, reverse);
751 byte[] original = new byte [input.Length];
752 Array.Copy (reverse, 0, original, 0, original.Length);
753 AssertEquals ("RC2_k48b64_CBC_Zeros Decrypt", input, original);
757 public void TestRC2_k48b64_CBC_PKCS7 ()
759 byte[] key = { 0x39, 0x6C, 0xB3, 0x7B, 0xB5, 0xA9 };
760 byte[] iv = { 0x42, 0x56, 0x99, 0x18, 0xA8, 0x96, 0x93, 0x5D };
761 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 };
763 SymmetricAlgorithm algo = RC2.Create ();
764 algo.Mode = CipherMode.CBC;
765 algo.Padding = PaddingMode.PKCS7;
767 int blockLength = (algo.BlockSize >> 3);
768 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
769 byte[] output = new byte [blockLength * 3];
770 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
771 Encrypt (encryptor, input, output);
772 AssertEquals ("RC2_k48b64_CBC_PKCS7 Encrypt", expected, output);
773 byte[] reverse = new byte [blockLength * 3];
774 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
775 Decrypt (decryptor, output, reverse);
776 byte[] original = new byte [input.Length];
777 Array.Copy (reverse, 0, original, 0, original.Length);
778 AssertEquals ("RC2_k48b64_CBC_PKCS7 Decrypt", input, original);
782 /* Invalid parameters RC2_k48b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
784 /* Invalid parameters RC2_k48b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
786 /* Invalid parameters RC2_k48b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
788 public void TestRC2_k48b64_CFB8_None ()
790 byte[] key = { 0x06, 0xCE, 0x23, 0x86, 0xEC, 0xB3 };
791 byte[] iv = { 0x14, 0xF7, 0xBA, 0xEC, 0xC2, 0x4A, 0x26, 0x6D };
792 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 };
794 SymmetricAlgorithm algo = RC2.Create ();
795 algo.Mode = CipherMode.CFB;
796 algo.Padding = PaddingMode.None;
798 algo.FeedbackSize = 8;
799 int blockLength = (algo.BlockSize >> 3);
800 byte[] input = new byte [blockLength * 2];
801 byte[] output = new byte [blockLength * 3];
802 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
803 Encrypt (encryptor, input, output);
804 AssertEquals ("RC2_k48b64_CFB8_None Encrypt", expected, output);
805 byte[] reverse = new byte [blockLength * 3];
806 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
807 Decrypt (decryptor, output, reverse);
808 byte[] original = new byte [input.Length];
809 Array.Copy (reverse, 0, original, 0, original.Length);
810 AssertEquals ("RC2_k48b64_CFB8_None Decrypt", input, original);
814 public void TestRC2_k48b64_CFB8_Zeros ()
816 byte[] key = { 0x4B, 0xC8, 0x03, 0x4F, 0x43, 0x27 };
817 byte[] iv = { 0x02, 0x24, 0xB8, 0xE9, 0xF6, 0x19, 0xA1, 0x81 };
818 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 };
820 SymmetricAlgorithm algo = RC2.Create ();
821 algo.Mode = CipherMode.CFB;
822 algo.Padding = PaddingMode.Zeros;
824 algo.FeedbackSize = 8;
825 int blockLength = (algo.BlockSize >> 3);
826 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
827 byte[] output = new byte [blockLength * 3];
828 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
829 Encrypt (encryptor, input, output);
830 AssertEquals ("RC2_k48b64_CFB8_Zeros 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_Zeros Decrypt", input, original);
840 public void TestRC2_k48b64_CFB8_PKCS7 ()
842 byte[] key = { 0x22, 0x94, 0x8C, 0x13, 0x7F, 0x7A };
843 byte[] iv = { 0x4B, 0xDF, 0xB8, 0xBF, 0x0D, 0xBE, 0x1E, 0x3D };
844 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 };
846 SymmetricAlgorithm algo = RC2.Create ();
847 algo.Mode = CipherMode.CFB;
848 algo.Padding = PaddingMode.PKCS7;
850 algo.FeedbackSize = 8;
851 int blockLength = (algo.BlockSize >> 3);
852 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
853 byte[] output = new byte [blockLength * 3];
854 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
855 Encrypt (encryptor, input, output);
856 AssertEquals ("RC2_k48b64_CFB8_PKCS7 Encrypt", expected, output);
857 byte[] reverse = new byte [blockLength * 3];
858 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
859 Decrypt (decryptor, output, reverse);
860 byte[] original = new byte [input.Length];
861 Array.Copy (reverse, 0, original, 0, original.Length);
862 AssertEquals ("RC2_k48b64_CFB8_PKCS7 Decrypt", input, original);
866 /* Invalid parameters RC2_k48b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
868 /* Invalid parameters RC2_k48b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
870 /* Invalid parameters RC2_k48b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
872 public void TestRC2_k56b64_ECB_None ()
874 byte[] key = { 0xCA, 0x6B, 0x7A, 0xA1, 0xB1, 0x6E, 0x4A };
875 // not used for ECB but make the code more uniform
876 byte[] iv = { 0xF0, 0xA9, 0x35, 0xDB, 0x4F, 0xB5, 0x3D, 0xE4 };
877 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 };
879 SymmetricAlgorithm algo = RC2.Create ();
880 algo.Mode = CipherMode.ECB;
881 algo.Padding = PaddingMode.None;
883 int blockLength = (algo.BlockSize >> 3);
884 byte[] input = new byte [blockLength * 2];
885 byte[] output = new byte [blockLength * 3];
886 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
887 Encrypt (encryptor, input, output);
888 AssertEquals ("RC2_k56b64_ECB_None Encrypt", expected, output);
890 // in ECB the first 2 blocks should be equals (as the IV is not used)
891 byte[] block1 = new byte[blockLength];
892 Array.Copy (output, 0, block1, 0, blockLength);
893 byte[] block2 = new byte[blockLength];
894 Array.Copy (output, blockLength, block2, 0, blockLength);
895 AssertEquals ("RC2_k56b64_ECB_None b1==b2", block1, block2);
896 byte[] reverse = new byte [blockLength * 3];
897 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
898 Decrypt (decryptor, output, reverse);
899 byte[] original = new byte [input.Length];
900 Array.Copy (reverse, 0, original, 0, original.Length);
901 AssertEquals ("RC2_k56b64_ECB_None Decrypt", input, original);
905 public void TestRC2_k56b64_ECB_Zeros ()
907 byte[] key = { 0x96, 0x43, 0x86, 0xAA, 0x0E, 0x66, 0x95 };
908 // not used for ECB but make the code more uniform
909 byte[] iv = { 0xD3, 0xD7, 0x93, 0xED, 0xAF, 0xD6, 0x83, 0x3F };
910 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 };
912 SymmetricAlgorithm algo = RC2.Create ();
913 algo.Mode = CipherMode.ECB;
914 algo.Padding = PaddingMode.Zeros;
916 int blockLength = (algo.BlockSize >> 3);
917 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
918 byte[] output = new byte [blockLength * 3];
919 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
920 Encrypt (encryptor, input, output);
921 AssertEquals ("RC2_k56b64_ECB_Zeros Encrypt", expected, output);
923 // in ECB the first 2 blocks should be equals (as the IV is not used)
924 byte[] block1 = new byte[blockLength];
925 Array.Copy (output, 0, block1, 0, blockLength);
926 byte[] block2 = new byte[blockLength];
927 Array.Copy (output, blockLength, block2, 0, blockLength);
928 AssertEquals ("RC2_k56b64_ECB_Zeros b1==b2", block1, block2);
930 // also if padding is Zeros then all three blocks should be equals
931 byte[] block3 = new byte[blockLength];
932 Array.Copy (output, blockLength, block3, 0, blockLength);
933 AssertEquals ("RC2_k56b64_ECB_Zeros b1==b3", block1, block3);
935 byte[] reverse = new byte [blockLength * 3];
936 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
937 Decrypt (decryptor, output, reverse);
938 byte[] original = new byte [input.Length];
939 Array.Copy (reverse, 0, original, 0, original.Length);
940 AssertEquals ("RC2_k56b64_ECB_Zeros Decrypt", input, original);
944 public void TestRC2_k56b64_ECB_PKCS7 ()
946 byte[] key = { 0x5A, 0x29, 0xE4, 0x77, 0x99, 0x9D, 0x5B };
947 // not used for ECB but make the code more uniform
948 byte[] iv = { 0xA6, 0x7B, 0x92, 0x40, 0x74, 0x9E, 0x0D, 0xAD };
949 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 };
951 SymmetricAlgorithm algo = RC2.Create ();
952 algo.Mode = CipherMode.ECB;
953 algo.Padding = PaddingMode.PKCS7;
955 int blockLength = (algo.BlockSize >> 3);
956 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
957 byte[] output = new byte [blockLength * 3];
958 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
959 Encrypt (encryptor, input, output);
960 AssertEquals ("RC2_k56b64_ECB_PKCS7 Encrypt", expected, output);
962 // in ECB the first 2 blocks should be equals (as the IV is not used)
963 byte[] block1 = new byte[blockLength];
964 Array.Copy (output, 0, block1, 0, blockLength);
965 byte[] block2 = new byte[blockLength];
966 Array.Copy (output, blockLength, block2, 0, blockLength);
967 AssertEquals ("RC2_k56b64_ECB_PKCS7 b1==b2", block1, block2);
968 byte[] reverse = new byte [blockLength * 3];
969 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
970 Decrypt (decryptor, output, reverse);
971 byte[] original = new byte [input.Length];
972 Array.Copy (reverse, 0, original, 0, original.Length);
973 AssertEquals ("RC2_k56b64_ECB_PKCS7 Decrypt", input, original);
977 public void TestRC2_k56b64_CBC_None ()
979 byte[] key = { 0xDD, 0x2F, 0x84, 0x9F, 0xBA, 0xB1, 0xF3 };
980 byte[] iv = { 0x97, 0xB2, 0xCD, 0x3F, 0x1E, 0x53, 0xE8, 0xA9 };
981 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 };
983 SymmetricAlgorithm algo = RC2.Create ();
984 algo.Mode = CipherMode.CBC;
985 algo.Padding = PaddingMode.None;
987 int blockLength = (algo.BlockSize >> 3);
988 byte[] input = new byte [blockLength * 2];
989 byte[] output = new byte [blockLength * 3];
990 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
991 Encrypt (encryptor, input, output);
992 AssertEquals ("RC2_k56b64_CBC_None Encrypt", expected, output);
993 byte[] reverse = new byte [blockLength * 3];
994 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
995 Decrypt (decryptor, output, reverse);
996 byte[] original = new byte [input.Length];
997 Array.Copy (reverse, 0, original, 0, original.Length);
998 AssertEquals ("RC2_k56b64_CBC_None Decrypt", input, original);
1002 public void TestRC2_k56b64_CBC_Zeros ()
1004 byte[] key = { 0xED, 0xEE, 0x33, 0x8E, 0x97, 0x20, 0x58 };
1005 byte[] iv = { 0x0B, 0xAB, 0xAB, 0xED, 0xCC, 0x1C, 0x77, 0xA4 };
1006 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 };
1008 SymmetricAlgorithm algo = RC2.Create ();
1009 algo.Mode = CipherMode.CBC;
1010 algo.Padding = PaddingMode.Zeros;
1011 algo.BlockSize = 64;
1012 int blockLength = (algo.BlockSize >> 3);
1013 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1014 byte[] output = new byte [blockLength * 3];
1015 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1016 Encrypt (encryptor, input, output);
1017 AssertEquals ("RC2_k56b64_CBC_Zeros Encrypt", expected, output);
1018 byte[] reverse = new byte [blockLength * 3];
1019 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1020 Decrypt (decryptor, output, reverse);
1021 byte[] original = new byte [input.Length];
1022 Array.Copy (reverse, 0, original, 0, original.Length);
1023 AssertEquals ("RC2_k56b64_CBC_Zeros Decrypt", input, original);
1027 public void TestRC2_k56b64_CBC_PKCS7 ()
1029 byte[] key = { 0x52, 0xF6, 0xC3, 0xC3, 0x13, 0x9E, 0xF7 };
1030 byte[] iv = { 0x8E, 0xF8, 0xE5, 0x66, 0x64, 0x1C, 0xE6, 0xE3 };
1031 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 };
1033 SymmetricAlgorithm algo = RC2.Create ();
1034 algo.Mode = CipherMode.CBC;
1035 algo.Padding = PaddingMode.PKCS7;
1036 algo.BlockSize = 64;
1037 int blockLength = (algo.BlockSize >> 3);
1038 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1039 byte[] output = new byte [blockLength * 3];
1040 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1041 Encrypt (encryptor, input, output);
1042 AssertEquals ("RC2_k56b64_CBC_PKCS7 Encrypt", expected, output);
1043 byte[] reverse = new byte [blockLength * 3];
1044 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1045 Decrypt (decryptor, output, reverse);
1046 byte[] original = new byte [input.Length];
1047 Array.Copy (reverse, 0, original, 0, original.Length);
1048 AssertEquals ("RC2_k56b64_CBC_PKCS7 Decrypt", input, original);
1052 /* Invalid parameters RC2_k56b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
1054 /* Invalid parameters RC2_k56b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
1056 /* Invalid parameters RC2_k56b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
1058 public void TestRC2_k56b64_CFB8_None ()
1060 byte[] key = { 0xEA, 0x1D, 0xB2, 0x0E, 0x17, 0xF0, 0x4A };
1061 byte[] iv = { 0xB7, 0xEE, 0xEE, 0xFF, 0x36, 0x8C, 0x9B, 0xBB };
1062 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 };
1064 SymmetricAlgorithm algo = RC2.Create ();
1065 algo.Mode = CipherMode.CFB;
1066 algo.Padding = PaddingMode.None;
1067 algo.BlockSize = 64;
1068 algo.FeedbackSize = 8;
1069 int blockLength = (algo.BlockSize >> 3);
1070 byte[] input = new byte [blockLength * 2];
1071 byte[] output = new byte [blockLength * 3];
1072 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1073 Encrypt (encryptor, input, output);
1074 AssertEquals ("RC2_k56b64_CFB8_None Encrypt", expected, output);
1075 byte[] reverse = new byte [blockLength * 3];
1076 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1077 Decrypt (decryptor, output, reverse);
1078 byte[] original = new byte [input.Length];
1079 Array.Copy (reverse, 0, original, 0, original.Length);
1080 AssertEquals ("RC2_k56b64_CFB8_None Decrypt", input, original);
1084 public void TestRC2_k56b64_CFB8_Zeros ()
1086 byte[] key = { 0x24, 0x6F, 0xE0, 0xC7, 0x3C, 0xC0, 0x4B };
1087 byte[] iv = { 0xD7, 0x83, 0xCA, 0xB7, 0x9C, 0x6D, 0xC3, 0x25 };
1088 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 };
1090 SymmetricAlgorithm algo = RC2.Create ();
1091 algo.Mode = CipherMode.CFB;
1092 algo.Padding = PaddingMode.Zeros;
1093 algo.BlockSize = 64;
1094 algo.FeedbackSize = 8;
1095 int blockLength = (algo.BlockSize >> 3);
1096 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1097 byte[] output = new byte [blockLength * 3];
1098 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1099 Encrypt (encryptor, input, output);
1100 AssertEquals ("RC2_k56b64_CFB8_Zeros Encrypt", expected, output);
1101 byte[] reverse = new byte [blockLength * 3];
1102 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1103 Decrypt (decryptor, output, reverse);
1104 byte[] original = new byte [input.Length];
1105 Array.Copy (reverse, 0, original, 0, original.Length);
1106 AssertEquals ("RC2_k56b64_CFB8_Zeros Decrypt", input, original);
1110 public void TestRC2_k56b64_CFB8_PKCS7 ()
1112 byte[] key = { 0x58, 0xE4, 0xC8, 0x6F, 0xB4, 0x14, 0xAC };
1113 byte[] iv = { 0xA1, 0xBC, 0x94, 0xB5, 0xF5, 0x4F, 0x78, 0x19 };
1114 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 };
1116 SymmetricAlgorithm algo = RC2.Create ();
1117 algo.Mode = CipherMode.CFB;
1118 algo.Padding = PaddingMode.PKCS7;
1119 algo.BlockSize = 64;
1120 algo.FeedbackSize = 8;
1121 int blockLength = (algo.BlockSize >> 3);
1122 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1123 byte[] output = new byte [blockLength * 3];
1124 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1125 Encrypt (encryptor, input, output);
1126 AssertEquals ("RC2_k56b64_CFB8_PKCS7 Encrypt", expected, output);
1127 byte[] reverse = new byte [blockLength * 3];
1128 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1129 Decrypt (decryptor, output, reverse);
1130 byte[] original = new byte [input.Length];
1131 Array.Copy (reverse, 0, original, 0, original.Length);
1132 AssertEquals ("RC2_k56b64_CFB8_PKCS7 Decrypt", input, original);
1136 /* Invalid parameters RC2_k56b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
1138 /* Invalid parameters RC2_k56b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
1140 /* Invalid parameters RC2_k56b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
1142 public void TestRC2_k64b64_ECB_None ()
1144 byte[] key = { 0x2C, 0x52, 0xB4, 0x93, 0xF1, 0xEA, 0xC8, 0x8F };
1145 // not used for ECB but make the code more uniform
1146 byte[] iv = { 0xDE, 0x10, 0xA1, 0x1C, 0x5E, 0x43, 0x5F, 0x97 };
1147 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 };
1149 SymmetricAlgorithm algo = RC2.Create ();
1150 algo.Mode = CipherMode.ECB;
1151 algo.Padding = PaddingMode.None;
1152 algo.BlockSize = 64;
1153 int blockLength = (algo.BlockSize >> 3);
1154 byte[] input = new byte [blockLength * 2];
1155 byte[] output = new byte [blockLength * 3];
1156 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1157 Encrypt (encryptor, input, output);
1158 AssertEquals ("RC2_k64b64_ECB_None Encrypt", expected, output);
1160 // in ECB the first 2 blocks should be equals (as the IV is not used)
1161 byte[] block1 = new byte[blockLength];
1162 Array.Copy (output, 0, block1, 0, blockLength);
1163 byte[] block2 = new byte[blockLength];
1164 Array.Copy (output, blockLength, block2, 0, blockLength);
1165 AssertEquals ("RC2_k64b64_ECB_None b1==b2", block1, block2);
1166 byte[] reverse = new byte [blockLength * 3];
1167 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1168 Decrypt (decryptor, output, reverse);
1169 byte[] original = new byte [input.Length];
1170 Array.Copy (reverse, 0, original, 0, original.Length);
1171 AssertEquals ("RC2_k64b64_ECB_None Decrypt", input, original);
1175 public void TestRC2_k64b64_ECB_Zeros ()
1177 byte[] key = { 0x05, 0x0C, 0x49, 0xE3, 0x25, 0x49, 0xFA, 0x35 };
1178 // not used for ECB but make the code more uniform
1179 byte[] iv = { 0x4D, 0x94, 0x32, 0xD2, 0x8B, 0xB6, 0x52, 0x9C };
1180 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 };
1182 SymmetricAlgorithm algo = RC2.Create ();
1183 algo.Mode = CipherMode.ECB;
1184 algo.Padding = PaddingMode.Zeros;
1185 algo.BlockSize = 64;
1186 int blockLength = (algo.BlockSize >> 3);
1187 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1188 byte[] output = new byte [blockLength * 3];
1189 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1190 Encrypt (encryptor, input, output);
1191 AssertEquals ("RC2_k64b64_ECB_Zeros Encrypt", expected, output);
1193 // in ECB the first 2 blocks should be equals (as the IV is not used)
1194 byte[] block1 = new byte[blockLength];
1195 Array.Copy (output, 0, block1, 0, blockLength);
1196 byte[] block2 = new byte[blockLength];
1197 Array.Copy (output, blockLength, block2, 0, blockLength);
1198 AssertEquals ("RC2_k64b64_ECB_Zeros b1==b2", block1, block2);
1200 // also if padding is Zeros then all three blocks should be equals
1201 byte[] block3 = new byte[blockLength];
1202 Array.Copy (output, blockLength, block3, 0, blockLength);
1203 AssertEquals ("RC2_k64b64_ECB_Zeros b1==b3", block1, block3);
1205 byte[] reverse = new byte [blockLength * 3];
1206 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1207 Decrypt (decryptor, output, reverse);
1208 byte[] original = new byte [input.Length];
1209 Array.Copy (reverse, 0, original, 0, original.Length);
1210 AssertEquals ("RC2_k64b64_ECB_Zeros Decrypt", input, original);
1214 public void TestRC2_k64b64_ECB_PKCS7 ()
1216 byte[] key = { 0xE6, 0x57, 0xF2, 0x73, 0x3A, 0x20, 0xB0, 0x7E };
1217 // not used for ECB but make the code more uniform
1218 byte[] iv = { 0x34, 0x25, 0xD2, 0x35, 0x1C, 0xE4, 0x9D, 0xC6 };
1219 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 };
1221 SymmetricAlgorithm algo = RC2.Create ();
1222 algo.Mode = CipherMode.ECB;
1223 algo.Padding = PaddingMode.PKCS7;
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_PKCS7 Encrypt", expected, output);
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_PKCS7 b1==b2", block1, block2);
1238 byte[] reverse = new byte [blockLength * 3];
1239 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1240 Decrypt (decryptor, output, reverse);
1241 byte[] original = new byte [input.Length];
1242 Array.Copy (reverse, 0, original, 0, original.Length);
1243 AssertEquals ("RC2_k64b64_ECB_PKCS7 Decrypt", input, original);
1247 public void TestRC2_k64b64_CBC_None ()
1249 byte[] key = { 0x91, 0x14, 0x49, 0xC4, 0x0D, 0xF9, 0x90, 0x77 };
1250 byte[] iv = { 0xB9, 0xBD, 0x6B, 0x9E, 0x52, 0xC9, 0x8C, 0xA5 };
1251 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 };
1253 SymmetricAlgorithm algo = RC2.Create ();
1254 algo.Mode = CipherMode.CBC;
1255 algo.Padding = PaddingMode.None;
1256 algo.BlockSize = 64;
1257 int blockLength = (algo.BlockSize >> 3);
1258 byte[] input = new byte [blockLength * 2];
1259 byte[] output = new byte [blockLength * 3];
1260 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1261 Encrypt (encryptor, input, output);
1262 AssertEquals ("RC2_k64b64_CBC_None Encrypt", expected, output);
1263 byte[] reverse = new byte [blockLength * 3];
1264 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1265 Decrypt (decryptor, output, reverse);
1266 byte[] original = new byte [input.Length];
1267 Array.Copy (reverse, 0, original, 0, original.Length);
1268 AssertEquals ("RC2_k64b64_CBC_None Decrypt", input, original);
1272 public void TestRC2_k64b64_CBC_Zeros ()
1274 byte[] key = { 0x0E, 0xE0, 0xAD, 0xFD, 0x86, 0x22, 0x1D, 0x05 };
1275 byte[] iv = { 0xDF, 0x41, 0x2B, 0x6E, 0x82, 0x00, 0xCB, 0x38 };
1276 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 };
1278 SymmetricAlgorithm algo = RC2.Create ();
1279 algo.Mode = CipherMode.CBC;
1280 algo.Padding = PaddingMode.Zeros;
1281 algo.BlockSize = 64;
1282 int blockLength = (algo.BlockSize >> 3);
1283 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1284 byte[] output = new byte [blockLength * 3];
1285 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1286 Encrypt (encryptor, input, output);
1287 AssertEquals ("RC2_k64b64_CBC_Zeros Encrypt", expected, output);
1288 byte[] reverse = new byte [blockLength * 3];
1289 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1290 Decrypt (decryptor, output, reverse);
1291 byte[] original = new byte [input.Length];
1292 Array.Copy (reverse, 0, original, 0, original.Length);
1293 AssertEquals ("RC2_k64b64_CBC_Zeros Decrypt", input, original);
1297 public void TestRC2_k64b64_CBC_PKCS7 ()
1299 byte[] key = { 0x2D, 0x70, 0x15, 0xFF, 0x15, 0xEB, 0xDC, 0x33 };
1300 byte[] iv = { 0x04, 0x33, 0x63, 0x52, 0x5B, 0xA1, 0xAB, 0xAC };
1301 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 };
1303 SymmetricAlgorithm algo = RC2.Create ();
1304 algo.Mode = CipherMode.CBC;
1305 algo.Padding = PaddingMode.PKCS7;
1306 algo.BlockSize = 64;
1307 int blockLength = (algo.BlockSize >> 3);
1308 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1309 byte[] output = new byte [blockLength * 3];
1310 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1311 Encrypt (encryptor, input, output);
1312 AssertEquals ("RC2_k64b64_CBC_PKCS7 Encrypt", expected, output);
1313 byte[] reverse = new byte [blockLength * 3];
1314 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1315 Decrypt (decryptor, output, reverse);
1316 byte[] original = new byte [input.Length];
1317 Array.Copy (reverse, 0, original, 0, original.Length);
1318 AssertEquals ("RC2_k64b64_CBC_PKCS7 Decrypt", input, original);
1322 /* Invalid parameters RC2_k64b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
1324 /* Invalid parameters RC2_k64b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
1326 /* Invalid parameters RC2_k64b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
1328 public void TestRC2_k64b64_CFB8_None ()
1330 byte[] key = { 0x1B, 0x23, 0x16, 0xEA, 0x19, 0xF0, 0x53, 0xEE };
1331 byte[] iv = { 0x60, 0x8D, 0x23, 0x2B, 0x0D, 0x56, 0x6F, 0x92 };
1332 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 };
1334 SymmetricAlgorithm algo = RC2.Create ();
1335 algo.Mode = CipherMode.CFB;
1336 algo.Padding = PaddingMode.None;
1337 algo.BlockSize = 64;
1338 algo.FeedbackSize = 8;
1339 int blockLength = (algo.BlockSize >> 3);
1340 byte[] input = new byte [blockLength * 2];
1341 byte[] output = new byte [blockLength * 3];
1342 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1343 Encrypt (encryptor, input, output);
1344 AssertEquals ("RC2_k64b64_CFB8_None Encrypt", expected, output);
1345 byte[] reverse = new byte [blockLength * 3];
1346 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1347 Decrypt (decryptor, output, reverse);
1348 byte[] original = new byte [input.Length];
1349 Array.Copy (reverse, 0, original, 0, original.Length);
1350 AssertEquals ("RC2_k64b64_CFB8_None Decrypt", input, original);
1354 public void TestRC2_k64b64_CFB8_Zeros ()
1356 byte[] key = { 0x49, 0xAD, 0xCD, 0xF8, 0xB6, 0x44, 0xA1, 0x86 };
1357 byte[] iv = { 0xCA, 0x6A, 0x96, 0xA8, 0x18, 0xA8, 0xF6, 0x77 };
1358 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 };
1360 SymmetricAlgorithm algo = RC2.Create ();
1361 algo.Mode = CipherMode.CFB;
1362 algo.Padding = PaddingMode.Zeros;
1363 algo.BlockSize = 64;
1364 algo.FeedbackSize = 8;
1365 int blockLength = (algo.BlockSize >> 3);
1366 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1367 byte[] output = new byte [blockLength * 3];
1368 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1369 Encrypt (encryptor, input, output);
1370 AssertEquals ("RC2_k64b64_CFB8_Zeros Encrypt", expected, output);
1371 byte[] reverse = new byte [blockLength * 3];
1372 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1373 Decrypt (decryptor, output, reverse);
1374 byte[] original = new byte [input.Length];
1375 Array.Copy (reverse, 0, original, 0, original.Length);
1376 AssertEquals ("RC2_k64b64_CFB8_Zeros Decrypt", input, original);
1380 public void TestRC2_k64b64_CFB8_PKCS7 ()
1382 byte[] key = { 0xF6, 0xE6, 0xA0, 0x33, 0xD3, 0x77, 0x0C, 0x28 };
1383 byte[] iv = { 0x50, 0x31, 0x14, 0xAF, 0x27, 0x92, 0xFC, 0x57 };
1384 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 };
1386 SymmetricAlgorithm algo = RC2.Create ();
1387 algo.Mode = CipherMode.CFB;
1388 algo.Padding = PaddingMode.PKCS7;
1389 algo.BlockSize = 64;
1390 algo.FeedbackSize = 8;
1391 int blockLength = (algo.BlockSize >> 3);
1392 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1393 byte[] output = new byte [blockLength * 3];
1394 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1395 Encrypt (encryptor, input, output);
1396 AssertEquals ("RC2_k64b64_CFB8_PKCS7 Encrypt", expected, output);
1397 byte[] reverse = new byte [blockLength * 3];
1398 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1399 Decrypt (decryptor, output, reverse);
1400 byte[] original = new byte [input.Length];
1401 Array.Copy (reverse, 0, original, 0, original.Length);
1402 AssertEquals ("RC2_k64b64_CFB8_PKCS7 Decrypt", input, original);
1406 /* Invalid parameters RC2_k64b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
1408 /* Invalid parameters RC2_k64b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
1410 /* Invalid parameters RC2_k64b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
1412 public void TestRC2_k72b64_ECB_None ()
1414 byte[] key = { 0xEC, 0x93, 0x9A, 0xF0, 0x51, 0x69, 0x59, 0x0B, 0x15 };
1415 // not used for ECB but make the code more uniform
1416 byte[] iv = { 0x36, 0xDB, 0xE8, 0x7F, 0xB5, 0x43, 0x4C, 0xF6 };
1417 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 };
1419 SymmetricAlgorithm algo = RC2.Create ();
1420 algo.Mode = CipherMode.ECB;
1421 algo.Padding = PaddingMode.None;
1422 algo.BlockSize = 64;
1423 int blockLength = (algo.BlockSize >> 3);
1424 byte[] input = new byte [blockLength * 2];
1425 byte[] output = new byte [blockLength * 3];
1426 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1427 Encrypt (encryptor, input, output);
1428 AssertEquals ("RC2_k72b64_ECB_None Encrypt", expected, output);
1430 // in ECB the first 2 blocks should be equals (as the IV is not used)
1431 byte[] block1 = new byte[blockLength];
1432 Array.Copy (output, 0, block1, 0, blockLength);
1433 byte[] block2 = new byte[blockLength];
1434 Array.Copy (output, blockLength, block2, 0, blockLength);
1435 AssertEquals ("RC2_k72b64_ECB_None b1==b2", block1, block2);
1436 byte[] reverse = new byte [blockLength * 3];
1437 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1438 Decrypt (decryptor, output, reverse);
1439 byte[] original = new byte [input.Length];
1440 Array.Copy (reverse, 0, original, 0, original.Length);
1441 AssertEquals ("RC2_k72b64_ECB_None Decrypt", input, original);
1445 public void TestRC2_k72b64_ECB_Zeros ()
1447 byte[] key = { 0x19, 0x14, 0x2D, 0xF6, 0x48, 0xED, 0x5A, 0xF3, 0x1F };
1448 // not used for ECB but make the code more uniform
1449 byte[] iv = { 0x8C, 0x1D, 0x0D, 0xC7, 0xE3, 0x77, 0x68, 0x40 };
1450 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 };
1452 SymmetricAlgorithm algo = RC2.Create ();
1453 algo.Mode = CipherMode.ECB;
1454 algo.Padding = PaddingMode.Zeros;
1455 algo.BlockSize = 64;
1456 int blockLength = (algo.BlockSize >> 3);
1457 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1458 byte[] output = new byte [blockLength * 3];
1459 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1460 Encrypt (encryptor, input, output);
1461 AssertEquals ("RC2_k72b64_ECB_Zeros Encrypt", expected, output);
1463 // in ECB the first 2 blocks should be equals (as the IV is not used)
1464 byte[] block1 = new byte[blockLength];
1465 Array.Copy (output, 0, block1, 0, blockLength);
1466 byte[] block2 = new byte[blockLength];
1467 Array.Copy (output, blockLength, block2, 0, blockLength);
1468 AssertEquals ("RC2_k72b64_ECB_Zeros b1==b2", block1, block2);
1470 // also if padding is Zeros then all three blocks should be equals
1471 byte[] block3 = new byte[blockLength];
1472 Array.Copy (output, blockLength, block3, 0, blockLength);
1473 AssertEquals ("RC2_k72b64_ECB_Zeros b1==b3", block1, block3);
1475 byte[] reverse = new byte [blockLength * 3];
1476 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1477 Decrypt (decryptor, output, reverse);
1478 byte[] original = new byte [input.Length];
1479 Array.Copy (reverse, 0, original, 0, original.Length);
1480 AssertEquals ("RC2_k72b64_ECB_Zeros Decrypt", input, original);
1484 public void TestRC2_k72b64_ECB_PKCS7 ()
1486 byte[] key = { 0x1C, 0xAA, 0x46, 0xE7, 0x37, 0x23, 0x14, 0xC9, 0x31 };
1487 // not used for ECB but make the code more uniform
1488 byte[] iv = { 0x3B, 0x0B, 0x1D, 0xE0, 0x3A, 0x6E, 0xF3, 0x1C };
1489 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 };
1491 SymmetricAlgorithm algo = RC2.Create ();
1492 algo.Mode = CipherMode.ECB;
1493 algo.Padding = PaddingMode.PKCS7;
1494 algo.BlockSize = 64;
1495 int blockLength = (algo.BlockSize >> 3);
1496 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1497 byte[] output = new byte [blockLength * 3];
1498 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1499 Encrypt (encryptor, input, output);
1500 AssertEquals ("RC2_k72b64_ECB_PKCS7 Encrypt", expected, output);
1502 // in ECB the first 2 blocks should be equals (as the IV is not used)
1503 byte[] block1 = new byte[blockLength];
1504 Array.Copy (output, 0, block1, 0, blockLength);
1505 byte[] block2 = new byte[blockLength];
1506 Array.Copy (output, blockLength, block2, 0, blockLength);
1507 AssertEquals ("RC2_k72b64_ECB_PKCS7 b1==b2", block1, block2);
1508 byte[] reverse = new byte [blockLength * 3];
1509 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1510 Decrypt (decryptor, output, reverse);
1511 byte[] original = new byte [input.Length];
1512 Array.Copy (reverse, 0, original, 0, original.Length);
1513 AssertEquals ("RC2_k72b64_ECB_PKCS7 Decrypt", input, original);
1517 public void TestRC2_k72b64_CBC_None ()
1519 byte[] key = { 0xF7, 0x60, 0xC5, 0x87, 0x4E, 0x36, 0xCE, 0x3C, 0xE6 };
1520 byte[] iv = { 0x60, 0x0E, 0xAC, 0x58, 0x1C, 0x91, 0x1D, 0xAC };
1521 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 };
1523 SymmetricAlgorithm algo = RC2.Create ();
1524 algo.Mode = CipherMode.CBC;
1525 algo.Padding = PaddingMode.None;
1526 algo.BlockSize = 64;
1527 int blockLength = (algo.BlockSize >> 3);
1528 byte[] input = new byte [blockLength * 2];
1529 byte[] output = new byte [blockLength * 3];
1530 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1531 Encrypt (encryptor, input, output);
1532 AssertEquals ("RC2_k72b64_CBC_None Encrypt", expected, output);
1533 byte[] reverse = new byte [blockLength * 3];
1534 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1535 Decrypt (decryptor, output, reverse);
1536 byte[] original = new byte [input.Length];
1537 Array.Copy (reverse, 0, original, 0, original.Length);
1538 AssertEquals ("RC2_k72b64_CBC_None Decrypt", input, original);
1542 public void TestRC2_k72b64_CBC_Zeros ()
1544 byte[] key = { 0xD2, 0x3C, 0xD2, 0x40, 0xF1, 0x1D, 0x2E, 0xF4, 0x92 };
1545 byte[] iv = { 0xBE, 0x7C, 0xF7, 0xBE, 0x35, 0x11, 0x94, 0x46 };
1546 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 };
1548 SymmetricAlgorithm algo = RC2.Create ();
1549 algo.Mode = CipherMode.CBC;
1550 algo.Padding = PaddingMode.Zeros;
1551 algo.BlockSize = 64;
1552 int blockLength = (algo.BlockSize >> 3);
1553 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1554 byte[] output = new byte [blockLength * 3];
1555 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1556 Encrypt (encryptor, input, output);
1557 AssertEquals ("RC2_k72b64_CBC_Zeros Encrypt", expected, output);
1558 byte[] reverse = new byte [blockLength * 3];
1559 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1560 Decrypt (decryptor, output, reverse);
1561 byte[] original = new byte [input.Length];
1562 Array.Copy (reverse, 0, original, 0, original.Length);
1563 AssertEquals ("RC2_k72b64_CBC_Zeros Decrypt", input, original);
1567 public void TestRC2_k72b64_CBC_PKCS7 ()
1569 byte[] key = { 0xE6, 0x09, 0x99, 0x96, 0x84, 0x2D, 0x9B, 0xE9, 0x34 };
1570 byte[] iv = { 0x00, 0xE9, 0x3B, 0x59, 0x6C, 0x5E, 0xF3, 0x8A };
1571 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 };
1573 SymmetricAlgorithm algo = RC2.Create ();
1574 algo.Mode = CipherMode.CBC;
1575 algo.Padding = PaddingMode.PKCS7;
1576 algo.BlockSize = 64;
1577 int blockLength = (algo.BlockSize >> 3);
1578 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1579 byte[] output = new byte [blockLength * 3];
1580 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1581 Encrypt (encryptor, input, output);
1582 AssertEquals ("RC2_k72b64_CBC_PKCS7 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_PKCS7 Decrypt", input, original);
1592 /* Invalid parameters RC2_k72b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
1594 /* Invalid parameters RC2_k72b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
1596 /* Invalid parameters RC2_k72b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
1598 public void TestRC2_k72b64_CFB8_None ()
1600 byte[] key = { 0x65, 0x6B, 0x23, 0x3F, 0xB3, 0xE5, 0x6F, 0x30, 0x01 };
1601 byte[] iv = { 0x10, 0x16, 0x28, 0x20, 0xAB, 0x77, 0x74, 0x46 };
1602 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 };
1604 SymmetricAlgorithm algo = RC2.Create ();
1605 algo.Mode = CipherMode.CFB;
1606 algo.Padding = PaddingMode.None;
1607 algo.BlockSize = 64;
1608 algo.FeedbackSize = 8;
1609 int blockLength = (algo.BlockSize >> 3);
1610 byte[] input = new byte [blockLength * 2];
1611 byte[] output = new byte [blockLength * 3];
1612 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1613 Encrypt (encryptor, input, output);
1614 AssertEquals ("RC2_k72b64_CFB8_None Encrypt", expected, output);
1615 byte[] reverse = new byte [blockLength * 3];
1616 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1617 Decrypt (decryptor, output, reverse);
1618 byte[] original = new byte [input.Length];
1619 Array.Copy (reverse, 0, original, 0, original.Length);
1620 AssertEquals ("RC2_k72b64_CFB8_None Decrypt", input, original);
1624 public void TestRC2_k72b64_CFB8_Zeros ()
1626 byte[] key = { 0x87, 0xC1, 0x80, 0x41, 0xD6, 0xF1, 0x33, 0xC7, 0x78 };
1627 byte[] iv = { 0x21, 0x55, 0xCF, 0x6E, 0xF5, 0x3B, 0xF0, 0x6B };
1628 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 };
1630 SymmetricAlgorithm algo = RC2.Create ();
1631 algo.Mode = CipherMode.CFB;
1632 algo.Padding = PaddingMode.Zeros;
1633 algo.BlockSize = 64;
1634 algo.FeedbackSize = 8;
1635 int blockLength = (algo.BlockSize >> 3);
1636 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1637 byte[] output = new byte [blockLength * 3];
1638 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1639 Encrypt (encryptor, input, output);
1640 AssertEquals ("RC2_k72b64_CFB8_Zeros Encrypt", expected, output);
1641 byte[] reverse = new byte [blockLength * 3];
1642 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1643 Decrypt (decryptor, output, reverse);
1644 byte[] original = new byte [input.Length];
1645 Array.Copy (reverse, 0, original, 0, original.Length);
1646 AssertEquals ("RC2_k72b64_CFB8_Zeros Decrypt", input, original);
1650 public void TestRC2_k72b64_CFB8_PKCS7 ()
1652 byte[] key = { 0xAE, 0xE0, 0x44, 0x66, 0xDA, 0x34, 0xFD, 0xD4, 0x71 };
1653 byte[] iv = { 0xFA, 0x66, 0x5F, 0x55, 0xBC, 0x1B, 0xC7, 0x83 };
1654 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 };
1656 SymmetricAlgorithm algo = RC2.Create ();
1657 algo.Mode = CipherMode.CFB;
1658 algo.Padding = PaddingMode.PKCS7;
1659 algo.BlockSize = 64;
1660 algo.FeedbackSize = 8;
1661 int blockLength = (algo.BlockSize >> 3);
1662 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1663 byte[] output = new byte [blockLength * 3];
1664 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1665 Encrypt (encryptor, input, output);
1666 AssertEquals ("RC2_k72b64_CFB8_PKCS7 Encrypt", expected, output);
1667 byte[] reverse = new byte [blockLength * 3];
1668 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1669 Decrypt (decryptor, output, reverse);
1670 byte[] original = new byte [input.Length];
1671 Array.Copy (reverse, 0, original, 0, original.Length);
1672 AssertEquals ("RC2_k72b64_CFB8_PKCS7 Decrypt", input, original);
1676 /* Invalid parameters RC2_k72b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
1678 /* Invalid parameters RC2_k72b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
1680 /* Invalid parameters RC2_k72b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
1682 public void TestRC2_k80b64_ECB_None ()
1684 byte[] key = { 0xB8, 0xA4, 0x76, 0xF8, 0x59, 0x86, 0x40, 0x53, 0x33, 0x68 };
1685 // not used for ECB but make the code more uniform
1686 byte[] iv = { 0xFF, 0x5F, 0x8B, 0x5E, 0xCF, 0xB8, 0xA5, 0xCB };
1687 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 };
1689 SymmetricAlgorithm algo = RC2.Create ();
1690 algo.Mode = CipherMode.ECB;
1691 algo.Padding = PaddingMode.None;
1692 algo.BlockSize = 64;
1693 int blockLength = (algo.BlockSize >> 3);
1694 byte[] input = new byte [blockLength * 2];
1695 byte[] output = new byte [blockLength * 3];
1696 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1697 Encrypt (encryptor, input, output);
1698 AssertEquals ("RC2_k80b64_ECB_None Encrypt", expected, output);
1700 // in ECB the first 2 blocks should be equals (as the IV is not used)
1701 byte[] block1 = new byte[blockLength];
1702 Array.Copy (output, 0, block1, 0, blockLength);
1703 byte[] block2 = new byte[blockLength];
1704 Array.Copy (output, blockLength, block2, 0, blockLength);
1705 AssertEquals ("RC2_k80b64_ECB_None b1==b2", block1, block2);
1706 byte[] reverse = new byte [blockLength * 3];
1707 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1708 Decrypt (decryptor, output, reverse);
1709 byte[] original = new byte [input.Length];
1710 Array.Copy (reverse, 0, original, 0, original.Length);
1711 AssertEquals ("RC2_k80b64_ECB_None Decrypt", input, original);
1715 public void TestRC2_k80b64_ECB_Zeros ()
1717 byte[] key = { 0x9A, 0xE1, 0xE1, 0x17, 0xCB, 0x2B, 0x9C, 0x5D, 0x5D, 0x28 };
1718 // not used for ECB but make the code more uniform
1719 byte[] iv = { 0x71, 0x29, 0x89, 0x9C, 0x66, 0xF5, 0x90, 0x63 };
1720 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 };
1722 SymmetricAlgorithm algo = RC2.Create ();
1723 algo.Mode = CipherMode.ECB;
1724 algo.Padding = PaddingMode.Zeros;
1725 algo.BlockSize = 64;
1726 int blockLength = (algo.BlockSize >> 3);
1727 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1728 byte[] output = new byte [blockLength * 3];
1729 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1730 Encrypt (encryptor, input, output);
1731 AssertEquals ("RC2_k80b64_ECB_Zeros Encrypt", expected, output);
1733 // in ECB the first 2 blocks should be equals (as the IV is not used)
1734 byte[] block1 = new byte[blockLength];
1735 Array.Copy (output, 0, block1, 0, blockLength);
1736 byte[] block2 = new byte[blockLength];
1737 Array.Copy (output, blockLength, block2, 0, blockLength);
1738 AssertEquals ("RC2_k80b64_ECB_Zeros b1==b2", block1, block2);
1740 // also if padding is Zeros then all three blocks should be equals
1741 byte[] block3 = new byte[blockLength];
1742 Array.Copy (output, blockLength, block3, 0, blockLength);
1743 AssertEquals ("RC2_k80b64_ECB_Zeros b1==b3", block1, block3);
1745 byte[] reverse = new byte [blockLength * 3];
1746 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1747 Decrypt (decryptor, output, reverse);
1748 byte[] original = new byte [input.Length];
1749 Array.Copy (reverse, 0, original, 0, original.Length);
1750 AssertEquals ("RC2_k80b64_ECB_Zeros Decrypt", input, original);
1754 public void TestRC2_k80b64_ECB_PKCS7 ()
1756 byte[] key = { 0x8D, 0xF8, 0xDA, 0xA2, 0x31, 0xEA, 0x86, 0x92, 0x52, 0xBB };
1757 // not used for ECB but make the code more uniform
1758 byte[] iv = { 0xD3, 0x1C, 0x57, 0x72, 0xDE, 0xFD, 0xCA, 0xC7 };
1759 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 };
1761 SymmetricAlgorithm algo = RC2.Create ();
1762 algo.Mode = CipherMode.ECB;
1763 algo.Padding = PaddingMode.PKCS7;
1764 algo.BlockSize = 64;
1765 int blockLength = (algo.BlockSize >> 3);
1766 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1767 byte[] output = new byte [blockLength * 3];
1768 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1769 Encrypt (encryptor, input, output);
1770 AssertEquals ("RC2_k80b64_ECB_PKCS7 Encrypt", expected, output);
1772 // in ECB the first 2 blocks should be equals (as the IV is not used)
1773 byte[] block1 = new byte[blockLength];
1774 Array.Copy (output, 0, block1, 0, blockLength);
1775 byte[] block2 = new byte[blockLength];
1776 Array.Copy (output, blockLength, block2, 0, blockLength);
1777 AssertEquals ("RC2_k80b64_ECB_PKCS7 b1==b2", block1, block2);
1778 byte[] reverse = new byte [blockLength * 3];
1779 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1780 Decrypt (decryptor, output, reverse);
1781 byte[] original = new byte [input.Length];
1782 Array.Copy (reverse, 0, original, 0, original.Length);
1783 AssertEquals ("RC2_k80b64_ECB_PKCS7 Decrypt", input, original);
1787 public void TestRC2_k80b64_CBC_None ()
1789 byte[] key = { 0x5B, 0x45, 0x99, 0x10, 0x47, 0x42, 0x89, 0xC8, 0x2A, 0x6C };
1790 byte[] iv = { 0xE4, 0x8F, 0x2A, 0x4D, 0x25, 0x38, 0x01, 0x04 };
1791 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 };
1793 SymmetricAlgorithm algo = RC2.Create ();
1794 algo.Mode = CipherMode.CBC;
1795 algo.Padding = PaddingMode.None;
1796 algo.BlockSize = 64;
1797 int blockLength = (algo.BlockSize >> 3);
1798 byte[] input = new byte [blockLength * 2];
1799 byte[] output = new byte [blockLength * 3];
1800 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1801 Encrypt (encryptor, input, output);
1802 AssertEquals ("RC2_k80b64_CBC_None Encrypt", expected, output);
1803 byte[] reverse = new byte [blockLength * 3];
1804 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1805 Decrypt (decryptor, output, reverse);
1806 byte[] original = new byte [input.Length];
1807 Array.Copy (reverse, 0, original, 0, original.Length);
1808 AssertEquals ("RC2_k80b64_CBC_None Decrypt", input, original);
1812 public void TestRC2_k80b64_CBC_Zeros ()
1814 byte[] key = { 0xD4, 0x47, 0xFF, 0x5A, 0x70, 0xE8, 0x48, 0x0F, 0x23, 0xD1 };
1815 byte[] iv = { 0x8B, 0xF8, 0x94, 0x02, 0xB3, 0xFB, 0xB0, 0x0D };
1816 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 };
1818 SymmetricAlgorithm algo = RC2.Create ();
1819 algo.Mode = CipherMode.CBC;
1820 algo.Padding = PaddingMode.Zeros;
1821 algo.BlockSize = 64;
1822 int blockLength = (algo.BlockSize >> 3);
1823 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1824 byte[] output = new byte [blockLength * 3];
1825 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1826 Encrypt (encryptor, input, output);
1827 AssertEquals ("RC2_k80b64_CBC_Zeros Encrypt", expected, output);
1828 byte[] reverse = new byte [blockLength * 3];
1829 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1830 Decrypt (decryptor, output, reverse);
1831 byte[] original = new byte [input.Length];
1832 Array.Copy (reverse, 0, original, 0, original.Length);
1833 AssertEquals ("RC2_k80b64_CBC_Zeros Decrypt", input, original);
1837 public void TestRC2_k80b64_CBC_PKCS7 ()
1839 byte[] key = { 0x8D, 0x77, 0xC5, 0x6E, 0xC2, 0x8F, 0x10, 0x51, 0xD2, 0x20 };
1840 byte[] iv = { 0x43, 0xC5, 0x4E, 0x58, 0xF0, 0xD7, 0xB3, 0x92 };
1841 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 };
1843 SymmetricAlgorithm algo = RC2.Create ();
1844 algo.Mode = CipherMode.CBC;
1845 algo.Padding = PaddingMode.PKCS7;
1846 algo.BlockSize = 64;
1847 int blockLength = (algo.BlockSize >> 3);
1848 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1849 byte[] output = new byte [blockLength * 3];
1850 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1851 Encrypt (encryptor, input, output);
1852 AssertEquals ("RC2_k80b64_CBC_PKCS7 Encrypt", expected, output);
1853 byte[] reverse = new byte [blockLength * 3];
1854 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1855 Decrypt (decryptor, output, reverse);
1856 byte[] original = new byte [input.Length];
1857 Array.Copy (reverse, 0, original, 0, original.Length);
1858 AssertEquals ("RC2_k80b64_CBC_PKCS7 Decrypt", input, original);
1862 /* Invalid parameters RC2_k80b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
1864 /* Invalid parameters RC2_k80b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
1866 /* Invalid parameters RC2_k80b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
1868 public void TestRC2_k80b64_CFB8_None ()
1870 byte[] key = { 0x2A, 0x44, 0xD9, 0x1C, 0x5E, 0x7C, 0x79, 0x3D, 0x88, 0x55 };
1871 byte[] iv = { 0xA0, 0x48, 0x00, 0x04, 0xA8, 0xB8, 0x83, 0x9F };
1872 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 };
1874 SymmetricAlgorithm algo = RC2.Create ();
1875 algo.Mode = CipherMode.CFB;
1876 algo.Padding = PaddingMode.None;
1877 algo.BlockSize = 64;
1878 algo.FeedbackSize = 8;
1879 int blockLength = (algo.BlockSize >> 3);
1880 byte[] input = new byte [blockLength * 2];
1881 byte[] output = new byte [blockLength * 3];
1882 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1883 Encrypt (encryptor, input, output);
1884 AssertEquals ("RC2_k80b64_CFB8_None Encrypt", expected, output);
1885 byte[] reverse = new byte [blockLength * 3];
1886 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1887 Decrypt (decryptor, output, reverse);
1888 byte[] original = new byte [input.Length];
1889 Array.Copy (reverse, 0, original, 0, original.Length);
1890 AssertEquals ("RC2_k80b64_CFB8_None Decrypt", input, original);
1894 public void TestRC2_k80b64_CFB8_Zeros ()
1896 byte[] key = { 0x30, 0x51, 0xCD, 0x3B, 0x8A, 0x8A, 0x8C, 0xF4, 0x76, 0x64 };
1897 byte[] iv = { 0xD9, 0x5F, 0xEB, 0x11, 0x8F, 0x0A, 0x7D, 0xDC };
1898 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 };
1900 SymmetricAlgorithm algo = RC2.Create ();
1901 algo.Mode = CipherMode.CFB;
1902 algo.Padding = PaddingMode.Zeros;
1903 algo.BlockSize = 64;
1904 algo.FeedbackSize = 8;
1905 int blockLength = (algo.BlockSize >> 3);
1906 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1907 byte[] output = new byte [blockLength * 3];
1908 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1909 Encrypt (encryptor, input, output);
1910 AssertEquals ("RC2_k80b64_CFB8_Zeros Encrypt", expected, output);
1911 byte[] reverse = new byte [blockLength * 3];
1912 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1913 Decrypt (decryptor, output, reverse);
1914 byte[] original = new byte [input.Length];
1915 Array.Copy (reverse, 0, original, 0, original.Length);
1916 AssertEquals ("RC2_k80b64_CFB8_Zeros Decrypt", input, original);
1920 public void TestRC2_k80b64_CFB8_PKCS7 ()
1922 byte[] key = { 0xA7, 0x24, 0xA0, 0x14, 0x78, 0xDC, 0x8B, 0x99, 0x77, 0xCD };
1923 byte[] iv = { 0xB8, 0x68, 0xD0, 0x5A, 0x13, 0x3C, 0xBA, 0x59 };
1924 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 };
1926 SymmetricAlgorithm algo = RC2.Create ();
1927 algo.Mode = CipherMode.CFB;
1928 algo.Padding = PaddingMode.PKCS7;
1929 algo.BlockSize = 64;
1930 algo.FeedbackSize = 8;
1931 int blockLength = (algo.BlockSize >> 3);
1932 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1933 byte[] output = new byte [blockLength * 3];
1934 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1935 Encrypt (encryptor, input, output);
1936 AssertEquals ("RC2_k80b64_CFB8_PKCS7 Encrypt", expected, output);
1937 byte[] reverse = new byte [blockLength * 3];
1938 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1939 Decrypt (decryptor, output, reverse);
1940 byte[] original = new byte [input.Length];
1941 Array.Copy (reverse, 0, original, 0, original.Length);
1942 AssertEquals ("RC2_k80b64_CFB8_PKCS7 Decrypt", input, original);
1946 /* Invalid parameters RC2_k80b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
1948 /* Invalid parameters RC2_k80b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
1950 /* Invalid parameters RC2_k80b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
1952 public void TestRC2_k88b64_ECB_None ()
1954 byte[] key = { 0xCE, 0x12, 0x59, 0x88, 0x7A, 0xCD, 0x57, 0x4C, 0xCD, 0xA9, 0xD2 };
1955 // not used for ECB but make the code more uniform
1956 byte[] iv = { 0x91, 0x4C, 0x2D, 0xB4, 0x6E, 0x19, 0x3F, 0x6F };
1957 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 };
1959 SymmetricAlgorithm algo = RC2.Create ();
1960 algo.Mode = CipherMode.ECB;
1961 algo.Padding = PaddingMode.None;
1962 algo.BlockSize = 64;
1963 int blockLength = (algo.BlockSize >> 3);
1964 byte[] input = new byte [blockLength * 2];
1965 byte[] output = new byte [blockLength * 3];
1966 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
1967 Encrypt (encryptor, input, output);
1968 AssertEquals ("RC2_k88b64_ECB_None Encrypt", expected, output);
1970 // in ECB the first 2 blocks should be equals (as the IV is not used)
1971 byte[] block1 = new byte[blockLength];
1972 Array.Copy (output, 0, block1, 0, blockLength);
1973 byte[] block2 = new byte[blockLength];
1974 Array.Copy (output, blockLength, block2, 0, blockLength);
1975 AssertEquals ("RC2_k88b64_ECB_None b1==b2", block1, block2);
1976 byte[] reverse = new byte [blockLength * 3];
1977 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
1978 Decrypt (decryptor, output, reverse);
1979 byte[] original = new byte [input.Length];
1980 Array.Copy (reverse, 0, original, 0, original.Length);
1981 AssertEquals ("RC2_k88b64_ECB_None Decrypt", input, original);
1985 public void TestRC2_k88b64_ECB_Zeros ()
1987 byte[] key = { 0x28, 0xDC, 0x09, 0x80, 0x85, 0x25, 0x95, 0x41, 0x7B, 0xD4, 0x06 };
1988 // not used for ECB but make the code more uniform
1989 byte[] iv = { 0xAE, 0x0D, 0xC1, 0x42, 0x01, 0x1C, 0x6E, 0x5A };
1990 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 };
1992 SymmetricAlgorithm algo = RC2.Create ();
1993 algo.Mode = CipherMode.ECB;
1994 algo.Padding = PaddingMode.Zeros;
1995 algo.BlockSize = 64;
1996 int blockLength = (algo.BlockSize >> 3);
1997 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
1998 byte[] output = new byte [blockLength * 3];
1999 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2000 Encrypt (encryptor, input, output);
2001 AssertEquals ("RC2_k88b64_ECB_Zeros Encrypt", expected, output);
2003 // in ECB the first 2 blocks should be equals (as the IV is not used)
2004 byte[] block1 = new byte[blockLength];
2005 Array.Copy (output, 0, block1, 0, blockLength);
2006 byte[] block2 = new byte[blockLength];
2007 Array.Copy (output, blockLength, block2, 0, blockLength);
2008 AssertEquals ("RC2_k88b64_ECB_Zeros b1==b2", block1, block2);
2010 // also if padding is Zeros then all three blocks should be equals
2011 byte[] block3 = new byte[blockLength];
2012 Array.Copy (output, blockLength, block3, 0, blockLength);
2013 AssertEquals ("RC2_k88b64_ECB_Zeros b1==b3", block1, block3);
2015 byte[] reverse = new byte [blockLength * 3];
2016 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2017 Decrypt (decryptor, output, reverse);
2018 byte[] original = new byte [input.Length];
2019 Array.Copy (reverse, 0, original, 0, original.Length);
2020 AssertEquals ("RC2_k88b64_ECB_Zeros Decrypt", input, original);
2024 public void TestRC2_k88b64_ECB_PKCS7 ()
2026 byte[] key = { 0xAB, 0x26, 0x7E, 0xD3, 0x3A, 0x0A, 0x3F, 0x50, 0x0B, 0x84, 0x5F };
2027 // not used for ECB but make the code more uniform
2028 byte[] iv = { 0x28, 0x3C, 0x18, 0x06, 0x3C, 0xF7, 0x83, 0x51 };
2029 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 };
2031 SymmetricAlgorithm algo = RC2.Create ();
2032 algo.Mode = CipherMode.ECB;
2033 algo.Padding = PaddingMode.PKCS7;
2034 algo.BlockSize = 64;
2035 int blockLength = (algo.BlockSize >> 3);
2036 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2037 byte[] output = new byte [blockLength * 3];
2038 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2039 Encrypt (encryptor, input, output);
2040 AssertEquals ("RC2_k88b64_ECB_PKCS7 Encrypt", expected, output);
2042 // in ECB the first 2 blocks should be equals (as the IV is not used)
2043 byte[] block1 = new byte[blockLength];
2044 Array.Copy (output, 0, block1, 0, blockLength);
2045 byte[] block2 = new byte[blockLength];
2046 Array.Copy (output, blockLength, block2, 0, blockLength);
2047 AssertEquals ("RC2_k88b64_ECB_PKCS7 b1==b2", block1, block2);
2048 byte[] reverse = new byte [blockLength * 3];
2049 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2050 Decrypt (decryptor, output, reverse);
2051 byte[] original = new byte [input.Length];
2052 Array.Copy (reverse, 0, original, 0, original.Length);
2053 AssertEquals ("RC2_k88b64_ECB_PKCS7 Decrypt", input, original);
2057 public void TestRC2_k88b64_CBC_None ()
2059 byte[] key = { 0x01, 0x2F, 0x45, 0x5F, 0x2D, 0x9E, 0xDB, 0x29, 0x6C, 0x54, 0xF5 };
2060 byte[] iv = { 0x4C, 0x6A, 0x4D, 0x77, 0x7E, 0x34, 0xB4, 0x75 };
2061 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 };
2063 SymmetricAlgorithm algo = RC2.Create ();
2064 algo.Mode = CipherMode.CBC;
2065 algo.Padding = PaddingMode.None;
2066 algo.BlockSize = 64;
2067 int blockLength = (algo.BlockSize >> 3);
2068 byte[] input = new byte [blockLength * 2];
2069 byte[] output = new byte [blockLength * 3];
2070 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2071 Encrypt (encryptor, input, output);
2072 AssertEquals ("RC2_k88b64_CBC_None Encrypt", expected, output);
2073 byte[] reverse = new byte [blockLength * 3];
2074 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2075 Decrypt (decryptor, output, reverse);
2076 byte[] original = new byte [input.Length];
2077 Array.Copy (reverse, 0, original, 0, original.Length);
2078 AssertEquals ("RC2_k88b64_CBC_None Decrypt", input, original);
2082 public void TestRC2_k88b64_CBC_Zeros ()
2084 byte[] key = { 0xA9, 0xD1, 0xDA, 0xCB, 0x4C, 0xA7, 0xD3, 0x35, 0x70, 0x1E, 0x15 };
2085 byte[] iv = { 0xF2, 0x17, 0x14, 0x41, 0x36, 0x58, 0x27, 0x48 };
2086 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 };
2088 SymmetricAlgorithm algo = RC2.Create ();
2089 algo.Mode = CipherMode.CBC;
2090 algo.Padding = PaddingMode.Zeros;
2091 algo.BlockSize = 64;
2092 int blockLength = (algo.BlockSize >> 3);
2093 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2094 byte[] output = new byte [blockLength * 3];
2095 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2096 Encrypt (encryptor, input, output);
2097 AssertEquals ("RC2_k88b64_CBC_Zeros Encrypt", expected, output);
2098 byte[] reverse = new byte [blockLength * 3];
2099 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2100 Decrypt (decryptor, output, reverse);
2101 byte[] original = new byte [input.Length];
2102 Array.Copy (reverse, 0, original, 0, original.Length);
2103 AssertEquals ("RC2_k88b64_CBC_Zeros Decrypt", input, original);
2107 public void TestRC2_k88b64_CBC_PKCS7 ()
2109 byte[] key = { 0x07, 0x97, 0xCB, 0xA3, 0xB6, 0xFF, 0x57, 0x30, 0x5A, 0x2E, 0x3E };
2110 byte[] iv = { 0x78, 0x44, 0xCE, 0xBA, 0xC6, 0xCD, 0x0C, 0xB7 };
2111 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 };
2113 SymmetricAlgorithm algo = RC2.Create ();
2114 algo.Mode = CipherMode.CBC;
2115 algo.Padding = PaddingMode.PKCS7;
2116 algo.BlockSize = 64;
2117 int blockLength = (algo.BlockSize >> 3);
2118 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2119 byte[] output = new byte [blockLength * 3];
2120 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2121 Encrypt (encryptor, input, output);
2122 AssertEquals ("RC2_k88b64_CBC_PKCS7 Encrypt", expected, output);
2123 byte[] reverse = new byte [blockLength * 3];
2124 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2125 Decrypt (decryptor, output, reverse);
2126 byte[] original = new byte [input.Length];
2127 Array.Copy (reverse, 0, original, 0, original.Length);
2128 AssertEquals ("RC2_k88b64_CBC_PKCS7 Decrypt", input, original);
2132 /* Invalid parameters RC2_k88b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
2134 /* Invalid parameters RC2_k88b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
2136 /* Invalid parameters RC2_k88b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
2138 public void TestRC2_k88b64_CFB8_None ()
2140 byte[] key = { 0x6E, 0x73, 0x03, 0xFD, 0x20, 0xAB, 0x21, 0x9D, 0x54, 0x0C, 0xB9 };
2141 byte[] iv = { 0x69, 0x6B, 0xF5, 0xD0, 0x10, 0xB5, 0xFE, 0xEF };
2142 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 };
2144 SymmetricAlgorithm algo = RC2.Create ();
2145 algo.Mode = CipherMode.CFB;
2146 algo.Padding = PaddingMode.None;
2147 algo.BlockSize = 64;
2148 algo.FeedbackSize = 8;
2149 int blockLength = (algo.BlockSize >> 3);
2150 byte[] input = new byte [blockLength * 2];
2151 byte[] output = new byte [blockLength * 3];
2152 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2153 Encrypt (encryptor, input, output);
2154 AssertEquals ("RC2_k88b64_CFB8_None Encrypt", expected, output);
2155 byte[] reverse = new byte [blockLength * 3];
2156 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2157 Decrypt (decryptor, output, reverse);
2158 byte[] original = new byte [input.Length];
2159 Array.Copy (reverse, 0, original, 0, original.Length);
2160 AssertEquals ("RC2_k88b64_CFB8_None Decrypt", input, original);
2164 public void TestRC2_k88b64_CFB8_Zeros ()
2166 byte[] key = { 0x8B, 0x1D, 0xD0, 0x5C, 0x3E, 0xF4, 0x5B, 0xA5, 0x56, 0x87, 0xE8 };
2167 byte[] iv = { 0x14, 0x01, 0x4B, 0x90, 0x67, 0x02, 0x79, 0x3F };
2168 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 };
2170 SymmetricAlgorithm algo = RC2.Create ();
2171 algo.Mode = CipherMode.CFB;
2172 algo.Padding = PaddingMode.Zeros;
2173 algo.BlockSize = 64;
2174 algo.FeedbackSize = 8;
2175 int blockLength = (algo.BlockSize >> 3);
2176 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2177 byte[] output = new byte [blockLength * 3];
2178 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2179 Encrypt (encryptor, input, output);
2180 AssertEquals ("RC2_k88b64_CFB8_Zeros Encrypt", expected, output);
2181 byte[] reverse = new byte [blockLength * 3];
2182 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2183 Decrypt (decryptor, output, reverse);
2184 byte[] original = new byte [input.Length];
2185 Array.Copy (reverse, 0, original, 0, original.Length);
2186 AssertEquals ("RC2_k88b64_CFB8_Zeros Decrypt", input, original);
2190 public void TestRC2_k88b64_CFB8_PKCS7 ()
2192 byte[] key = { 0xCB, 0xD9, 0xE0, 0xD8, 0x82, 0xA0, 0x06, 0xD1, 0x6C, 0x5F, 0x8F };
2193 byte[] iv = { 0x73, 0x14, 0x81, 0x8C, 0x59, 0xE4, 0x33, 0xDF };
2194 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 };
2196 SymmetricAlgorithm algo = RC2.Create ();
2197 algo.Mode = CipherMode.CFB;
2198 algo.Padding = PaddingMode.PKCS7;
2199 algo.BlockSize = 64;
2200 algo.FeedbackSize = 8;
2201 int blockLength = (algo.BlockSize >> 3);
2202 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2203 byte[] output = new byte [blockLength * 3];
2204 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2205 Encrypt (encryptor, input, output);
2206 AssertEquals ("RC2_k88b64_CFB8_PKCS7 Encrypt", expected, output);
2207 byte[] reverse = new byte [blockLength * 3];
2208 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2209 Decrypt (decryptor, output, reverse);
2210 byte[] original = new byte [input.Length];
2211 Array.Copy (reverse, 0, original, 0, original.Length);
2212 AssertEquals ("RC2_k88b64_CFB8_PKCS7 Decrypt", input, original);
2216 /* Invalid parameters RC2_k88b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
2218 /* Invalid parameters RC2_k88b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
2220 /* Invalid parameters RC2_k88b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
2222 public void TestRC2_k96b64_ECB_None ()
2224 byte[] key = { 0x72, 0xD8, 0x0A, 0x9D, 0xDA, 0x9D, 0xB1, 0x78, 0x61, 0x9C, 0xD8, 0x57 };
2225 // not used for ECB but make the code more uniform
2226 byte[] iv = { 0x31, 0x21, 0x9D, 0xD9, 0x12, 0x95, 0x79, 0x30 };
2227 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 };
2229 SymmetricAlgorithm algo = RC2.Create ();
2230 algo.Mode = CipherMode.ECB;
2231 algo.Padding = PaddingMode.None;
2232 algo.BlockSize = 64;
2233 int blockLength = (algo.BlockSize >> 3);
2234 byte[] input = new byte [blockLength * 2];
2235 byte[] output = new byte [blockLength * 3];
2236 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2237 Encrypt (encryptor, input, output);
2238 AssertEquals ("RC2_k96b64_ECB_None Encrypt", expected, output);
2240 // in ECB the first 2 blocks should be equals (as the IV is not used)
2241 byte[] block1 = new byte[blockLength];
2242 Array.Copy (output, 0, block1, 0, blockLength);
2243 byte[] block2 = new byte[blockLength];
2244 Array.Copy (output, blockLength, block2, 0, blockLength);
2245 AssertEquals ("RC2_k96b64_ECB_None b1==b2", block1, block2);
2246 byte[] reverse = new byte [blockLength * 3];
2247 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2248 Decrypt (decryptor, output, reverse);
2249 byte[] original = new byte [input.Length];
2250 Array.Copy (reverse, 0, original, 0, original.Length);
2251 AssertEquals ("RC2_k96b64_ECB_None Decrypt", input, original);
2255 public void TestRC2_k96b64_ECB_Zeros ()
2257 byte[] key = { 0x5D, 0x07, 0x3C, 0x15, 0x3F, 0xE1, 0xB2, 0x72, 0x9F, 0x1A, 0xBE, 0x21 };
2258 // not used for ECB but make the code more uniform
2259 byte[] iv = { 0x76, 0xE9, 0x93, 0x9F, 0xD1, 0x6A, 0xCE, 0x79 };
2260 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 };
2262 SymmetricAlgorithm algo = RC2.Create ();
2263 algo.Mode = CipherMode.ECB;
2264 algo.Padding = PaddingMode.Zeros;
2265 algo.BlockSize = 64;
2266 int blockLength = (algo.BlockSize >> 3);
2267 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2268 byte[] output = new byte [blockLength * 3];
2269 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2270 Encrypt (encryptor, input, output);
2271 AssertEquals ("RC2_k96b64_ECB_Zeros Encrypt", expected, output);
2273 // in ECB the first 2 blocks should be equals (as the IV is not used)
2274 byte[] block1 = new byte[blockLength];
2275 Array.Copy (output, 0, block1, 0, blockLength);
2276 byte[] block2 = new byte[blockLength];
2277 Array.Copy (output, blockLength, block2, 0, blockLength);
2278 AssertEquals ("RC2_k96b64_ECB_Zeros b1==b2", block1, block2);
2280 // also if padding is Zeros then all three blocks should be equals
2281 byte[] block3 = new byte[blockLength];
2282 Array.Copy (output, blockLength, block3, 0, blockLength);
2283 AssertEquals ("RC2_k96b64_ECB_Zeros b1==b3", block1, block3);
2285 byte[] reverse = new byte [blockLength * 3];
2286 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2287 Decrypt (decryptor, output, reverse);
2288 byte[] original = new byte [input.Length];
2289 Array.Copy (reverse, 0, original, 0, original.Length);
2290 AssertEquals ("RC2_k96b64_ECB_Zeros Decrypt", input, original);
2294 public void TestRC2_k96b64_ECB_PKCS7 ()
2296 byte[] key = { 0x79, 0xCA, 0xDB, 0xBE, 0x8C, 0x10, 0x1E, 0xEB, 0x8B, 0x16, 0x00, 0x1B };
2297 // not used for ECB but make the code more uniform
2298 byte[] iv = { 0x17, 0x42, 0x68, 0x21, 0xBC, 0x52, 0x6A, 0xF6 };
2299 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 };
2301 SymmetricAlgorithm algo = RC2.Create ();
2302 algo.Mode = CipherMode.ECB;
2303 algo.Padding = PaddingMode.PKCS7;
2304 algo.BlockSize = 64;
2305 int blockLength = (algo.BlockSize >> 3);
2306 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2307 byte[] output = new byte [blockLength * 3];
2308 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2309 Encrypt (encryptor, input, output);
2310 AssertEquals ("RC2_k96b64_ECB_PKCS7 Encrypt", expected, output);
2312 // in ECB the first 2 blocks should be equals (as the IV is not used)
2313 byte[] block1 = new byte[blockLength];
2314 Array.Copy (output, 0, block1, 0, blockLength);
2315 byte[] block2 = new byte[blockLength];
2316 Array.Copy (output, blockLength, block2, 0, blockLength);
2317 AssertEquals ("RC2_k96b64_ECB_PKCS7 b1==b2", block1, block2);
2318 byte[] reverse = new byte [blockLength * 3];
2319 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2320 Decrypt (decryptor, output, reverse);
2321 byte[] original = new byte [input.Length];
2322 Array.Copy (reverse, 0, original, 0, original.Length);
2323 AssertEquals ("RC2_k96b64_ECB_PKCS7 Decrypt", input, original);
2327 public void TestRC2_k96b64_CBC_None ()
2329 byte[] key = { 0x68, 0xC6, 0xF2, 0x13, 0xEA, 0x3D, 0x68, 0x09, 0xAC, 0x07, 0x21, 0x1F };
2330 byte[] iv = { 0x42, 0x47, 0xE6, 0x98, 0xF8, 0xFE, 0xCD, 0xFE };
2331 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 };
2333 SymmetricAlgorithm algo = RC2.Create ();
2334 algo.Mode = CipherMode.CBC;
2335 algo.Padding = PaddingMode.None;
2336 algo.BlockSize = 64;
2337 int blockLength = (algo.BlockSize >> 3);
2338 byte[] input = new byte [blockLength * 2];
2339 byte[] output = new byte [blockLength * 3];
2340 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2341 Encrypt (encryptor, input, output);
2342 AssertEquals ("RC2_k96b64_CBC_None Encrypt", expected, output);
2343 byte[] reverse = new byte [blockLength * 3];
2344 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2345 Decrypt (decryptor, output, reverse);
2346 byte[] original = new byte [input.Length];
2347 Array.Copy (reverse, 0, original, 0, original.Length);
2348 AssertEquals ("RC2_k96b64_CBC_None Decrypt", input, original);
2352 public void TestRC2_k96b64_CBC_Zeros ()
2354 byte[] key = { 0xDF, 0x00, 0x49, 0x93, 0xA1, 0x49, 0x50, 0x03, 0x52, 0x9C, 0x86, 0xF6 };
2355 byte[] iv = { 0x69, 0xFC, 0x72, 0xA2, 0x60, 0xF7, 0x4C, 0xB0 };
2356 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 };
2358 SymmetricAlgorithm algo = RC2.Create ();
2359 algo.Mode = CipherMode.CBC;
2360 algo.Padding = PaddingMode.Zeros;
2361 algo.BlockSize = 64;
2362 int blockLength = (algo.BlockSize >> 3);
2363 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2364 byte[] output = new byte [blockLength * 3];
2365 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2366 Encrypt (encryptor, input, output);
2367 AssertEquals ("RC2_k96b64_CBC_Zeros Encrypt", expected, output);
2368 byte[] reverse = new byte [blockLength * 3];
2369 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2370 Decrypt (decryptor, output, reverse);
2371 byte[] original = new byte [input.Length];
2372 Array.Copy (reverse, 0, original, 0, original.Length);
2373 AssertEquals ("RC2_k96b64_CBC_Zeros Decrypt", input, original);
2377 public void TestRC2_k96b64_CBC_PKCS7 ()
2379 byte[] key = { 0x04, 0x2B, 0x2E, 0x98, 0x97, 0x84, 0x72, 0x0A, 0x78, 0x61, 0x02, 0xA9 };
2380 byte[] iv = { 0x16, 0x0A, 0x00, 0x48, 0xC3, 0x4F, 0x63, 0x05 };
2381 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 };
2383 SymmetricAlgorithm algo = RC2.Create ();
2384 algo.Mode = CipherMode.CBC;
2385 algo.Padding = PaddingMode.PKCS7;
2386 algo.BlockSize = 64;
2387 int blockLength = (algo.BlockSize >> 3);
2388 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2389 byte[] output = new byte [blockLength * 3];
2390 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2391 Encrypt (encryptor, input, output);
2392 AssertEquals ("RC2_k96b64_CBC_PKCS7 Encrypt", expected, output);
2393 byte[] reverse = new byte [blockLength * 3];
2394 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2395 Decrypt (decryptor, output, reverse);
2396 byte[] original = new byte [input.Length];
2397 Array.Copy (reverse, 0, original, 0, original.Length);
2398 AssertEquals ("RC2_k96b64_CBC_PKCS7 Decrypt", input, original);
2402 /* Invalid parameters RC2_k96b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
2404 /* Invalid parameters RC2_k96b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
2406 /* Invalid parameters RC2_k96b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
2408 public void TestRC2_k96b64_CFB8_None ()
2410 byte[] key = { 0xDE, 0x6E, 0x40, 0xC3, 0x7D, 0x71, 0x0D, 0xCB, 0xA3, 0x62, 0x14, 0x76 };
2411 byte[] iv = { 0x72, 0x9E, 0xB4, 0xEE, 0x9B, 0x87, 0xAF, 0x12 };
2412 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 };
2414 SymmetricAlgorithm algo = RC2.Create ();
2415 algo.Mode = CipherMode.CFB;
2416 algo.Padding = PaddingMode.None;
2417 algo.BlockSize = 64;
2418 algo.FeedbackSize = 8;
2419 int blockLength = (algo.BlockSize >> 3);
2420 byte[] input = new byte [blockLength * 2];
2421 byte[] output = new byte [blockLength * 3];
2422 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2423 Encrypt (encryptor, input, output);
2424 AssertEquals ("RC2_k96b64_CFB8_None Encrypt", expected, output);
2425 byte[] reverse = new byte [blockLength * 3];
2426 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2427 Decrypt (decryptor, output, reverse);
2428 byte[] original = new byte [input.Length];
2429 Array.Copy (reverse, 0, original, 0, original.Length);
2430 AssertEquals ("RC2_k96b64_CFB8_None Decrypt", input, original);
2434 public void TestRC2_k96b64_CFB8_Zeros ()
2436 byte[] key = { 0xCF, 0x64, 0x81, 0x8F, 0x7D, 0x75, 0x8D, 0xB2, 0x9D, 0xE7, 0x39, 0xE3 };
2437 byte[] iv = { 0x30, 0xF2, 0x9E, 0x76, 0x96, 0x13, 0xCB, 0xDF };
2438 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 };
2440 SymmetricAlgorithm algo = RC2.Create ();
2441 algo.Mode = CipherMode.CFB;
2442 algo.Padding = PaddingMode.Zeros;
2443 algo.BlockSize = 64;
2444 algo.FeedbackSize = 8;
2445 int blockLength = (algo.BlockSize >> 3);
2446 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2447 byte[] output = new byte [blockLength * 3];
2448 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2449 Encrypt (encryptor, input, output);
2450 AssertEquals ("RC2_k96b64_CFB8_Zeros Encrypt", expected, output);
2451 byte[] reverse = new byte [blockLength * 3];
2452 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2453 Decrypt (decryptor, output, reverse);
2454 byte[] original = new byte [input.Length];
2455 Array.Copy (reverse, 0, original, 0, original.Length);
2456 AssertEquals ("RC2_k96b64_CFB8_Zeros Decrypt", input, original);
2460 public void TestRC2_k96b64_CFB8_PKCS7 ()
2462 byte[] key = { 0xC5, 0xF4, 0x44, 0xF2, 0xA0, 0xC3, 0xA7, 0x87, 0x64, 0x36, 0x5A, 0xFA };
2463 byte[] iv = { 0x20, 0xC5, 0x5E, 0x57, 0x5E, 0x0E, 0x2D, 0xDD };
2464 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 };
2466 SymmetricAlgorithm algo = RC2.Create ();
2467 algo.Mode = CipherMode.CFB;
2468 algo.Padding = PaddingMode.PKCS7;
2469 algo.BlockSize = 64;
2470 algo.FeedbackSize = 8;
2471 int blockLength = (algo.BlockSize >> 3);
2472 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2473 byte[] output = new byte [blockLength * 3];
2474 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2475 Encrypt (encryptor, input, output);
2476 AssertEquals ("RC2_k96b64_CFB8_PKCS7 Encrypt", expected, output);
2477 byte[] reverse = new byte [blockLength * 3];
2478 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2479 Decrypt (decryptor, output, reverse);
2480 byte[] original = new byte [input.Length];
2481 Array.Copy (reverse, 0, original, 0, original.Length);
2482 AssertEquals ("RC2_k96b64_CFB8_PKCS7 Decrypt", input, original);
2486 /* Invalid parameters RC2_k96b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
2488 /* Invalid parameters RC2_k96b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
2490 /* Invalid parameters RC2_k96b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
2492 public void TestRC2_k104b64_ECB_None ()
2494 byte[] key = { 0x04, 0x5B, 0x99, 0xD3, 0xBC, 0x00, 0x27, 0xA3, 0xDC, 0x57, 0x4C, 0x82, 0xD6 };
2495 // not used for ECB but make the code more uniform
2496 byte[] iv = { 0x70, 0x3D, 0xE7, 0xBC, 0x82, 0xFD, 0x8F, 0x03 };
2497 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 };
2499 SymmetricAlgorithm algo = RC2.Create ();
2500 algo.Mode = CipherMode.ECB;
2501 algo.Padding = PaddingMode.None;
2502 algo.BlockSize = 64;
2503 int blockLength = (algo.BlockSize >> 3);
2504 byte[] input = new byte [blockLength * 2];
2505 byte[] output = new byte [blockLength * 3];
2506 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2507 Encrypt (encryptor, input, output);
2508 AssertEquals ("RC2_k104b64_ECB_None Encrypt", expected, output);
2510 // in ECB the first 2 blocks should be equals (as the IV is not used)
2511 byte[] block1 = new byte[blockLength];
2512 Array.Copy (output, 0, block1, 0, blockLength);
2513 byte[] block2 = new byte[blockLength];
2514 Array.Copy (output, blockLength, block2, 0, blockLength);
2515 AssertEquals ("RC2_k104b64_ECB_None b1==b2", block1, block2);
2516 byte[] reverse = new byte [blockLength * 3];
2517 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2518 Decrypt (decryptor, output, reverse);
2519 byte[] original = new byte [input.Length];
2520 Array.Copy (reverse, 0, original, 0, original.Length);
2521 AssertEquals ("RC2_k104b64_ECB_None Decrypt", input, original);
2525 public void TestRC2_k104b64_ECB_Zeros ()
2527 byte[] key = { 0xA1, 0x3B, 0xDF, 0x6F, 0x6D, 0x2B, 0x7B, 0x0B, 0x13, 0x3E, 0x84, 0x35, 0x3C };
2528 // not used for ECB but make the code more uniform
2529 byte[] iv = { 0xE6, 0x74, 0x41, 0xB6, 0xB4, 0x31, 0xB2, 0x6A };
2530 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 };
2532 SymmetricAlgorithm algo = RC2.Create ();
2533 algo.Mode = CipherMode.ECB;
2534 algo.Padding = PaddingMode.Zeros;
2535 algo.BlockSize = 64;
2536 int blockLength = (algo.BlockSize >> 3);
2537 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2538 byte[] output = new byte [blockLength * 3];
2539 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2540 Encrypt (encryptor, input, output);
2541 AssertEquals ("RC2_k104b64_ECB_Zeros Encrypt", expected, output);
2543 // in ECB the first 2 blocks should be equals (as the IV is not used)
2544 byte[] block1 = new byte[blockLength];
2545 Array.Copy (output, 0, block1, 0, blockLength);
2546 byte[] block2 = new byte[blockLength];
2547 Array.Copy (output, blockLength, block2, 0, blockLength);
2548 AssertEquals ("RC2_k104b64_ECB_Zeros b1==b2", block1, block2);
2550 // also if padding is Zeros then all three blocks should be equals
2551 byte[] block3 = new byte[blockLength];
2552 Array.Copy (output, blockLength, block3, 0, blockLength);
2553 AssertEquals ("RC2_k104b64_ECB_Zeros b1==b3", block1, block3);
2555 byte[] reverse = new byte [blockLength * 3];
2556 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2557 Decrypt (decryptor, output, reverse);
2558 byte[] original = new byte [input.Length];
2559 Array.Copy (reverse, 0, original, 0, original.Length);
2560 AssertEquals ("RC2_k104b64_ECB_Zeros Decrypt", input, original);
2564 public void TestRC2_k104b64_ECB_PKCS7 ()
2566 byte[] key = { 0x28, 0xDF, 0x8C, 0x1B, 0x7E, 0x04, 0xB2, 0x89, 0x72, 0xDA, 0x19, 0x57, 0x81 };
2567 // not used for ECB but make the code more uniform
2568 byte[] iv = { 0xB8, 0x82, 0xA7, 0xBF, 0x99, 0xE9, 0x39, 0x02 };
2569 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 };
2571 SymmetricAlgorithm algo = RC2.Create ();
2572 algo.Mode = CipherMode.ECB;
2573 algo.Padding = PaddingMode.PKCS7;
2574 algo.BlockSize = 64;
2575 int blockLength = (algo.BlockSize >> 3);
2576 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2577 byte[] output = new byte [blockLength * 3];
2578 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2579 Encrypt (encryptor, input, output);
2580 AssertEquals ("RC2_k104b64_ECB_PKCS7 Encrypt", expected, output);
2582 // in ECB the first 2 blocks should be equals (as the IV is not used)
2583 byte[] block1 = new byte[blockLength];
2584 Array.Copy (output, 0, block1, 0, blockLength);
2585 byte[] block2 = new byte[blockLength];
2586 Array.Copy (output, blockLength, block2, 0, blockLength);
2587 AssertEquals ("RC2_k104b64_ECB_PKCS7 b1==b2", block1, block2);
2588 byte[] reverse = new byte [blockLength * 3];
2589 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2590 Decrypt (decryptor, output, reverse);
2591 byte[] original = new byte [input.Length];
2592 Array.Copy (reverse, 0, original, 0, original.Length);
2593 AssertEquals ("RC2_k104b64_ECB_PKCS7 Decrypt", input, original);
2597 public void TestRC2_k104b64_CBC_None ()
2599 byte[] key = { 0xF8, 0xCE, 0xA2, 0x33, 0xE5, 0x7D, 0x43, 0x72, 0xA9, 0xF5, 0xF1, 0x80, 0xBC };
2600 byte[] iv = { 0x12, 0xFF, 0x74, 0x3A, 0x36, 0x42, 0xBE, 0x78 };
2601 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 };
2603 SymmetricAlgorithm algo = RC2.Create ();
2604 algo.Mode = CipherMode.CBC;
2605 algo.Padding = PaddingMode.None;
2606 algo.BlockSize = 64;
2607 int blockLength = (algo.BlockSize >> 3);
2608 byte[] input = new byte [blockLength * 2];
2609 byte[] output = new byte [blockLength * 3];
2610 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2611 Encrypt (encryptor, input, output);
2612 AssertEquals ("RC2_k104b64_CBC_None Encrypt", expected, output);
2613 byte[] reverse = new byte [blockLength * 3];
2614 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2615 Decrypt (decryptor, output, reverse);
2616 byte[] original = new byte [input.Length];
2617 Array.Copy (reverse, 0, original, 0, original.Length);
2618 AssertEquals ("RC2_k104b64_CBC_None Decrypt", input, original);
2622 public void TestRC2_k104b64_CBC_Zeros ()
2624 byte[] key = { 0xEF, 0x4E, 0x02, 0x86, 0x5F, 0xE5, 0x94, 0x05, 0xEF, 0x8D, 0x8D, 0x5D, 0x04 };
2625 byte[] iv = { 0x98, 0x23, 0x93, 0xF7, 0x6D, 0x02, 0xB1, 0x73 };
2626 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 };
2628 SymmetricAlgorithm algo = RC2.Create ();
2629 algo.Mode = CipherMode.CBC;
2630 algo.Padding = PaddingMode.Zeros;
2631 algo.BlockSize = 64;
2632 int blockLength = (algo.BlockSize >> 3);
2633 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2634 byte[] output = new byte [blockLength * 3];
2635 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2636 Encrypt (encryptor, input, output);
2637 AssertEquals ("RC2_k104b64_CBC_Zeros Encrypt", expected, output);
2638 byte[] reverse = new byte [blockLength * 3];
2639 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2640 Decrypt (decryptor, output, reverse);
2641 byte[] original = new byte [input.Length];
2642 Array.Copy (reverse, 0, original, 0, original.Length);
2643 AssertEquals ("RC2_k104b64_CBC_Zeros Decrypt", input, original);
2647 public void TestRC2_k104b64_CBC_PKCS7 ()
2649 byte[] key = { 0xE3, 0xD2, 0xC2, 0xA0, 0x54, 0xF5, 0xFC, 0xFC, 0x94, 0xA2, 0x6F, 0x6F, 0x52 };
2650 byte[] iv = { 0xBA, 0x5D, 0x0D, 0xBA, 0x0D, 0x0C, 0x4E, 0x5B };
2651 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 };
2653 SymmetricAlgorithm algo = RC2.Create ();
2654 algo.Mode = CipherMode.CBC;
2655 algo.Padding = PaddingMode.PKCS7;
2656 algo.BlockSize = 64;
2657 int blockLength = (algo.BlockSize >> 3);
2658 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2659 byte[] output = new byte [blockLength * 3];
2660 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2661 Encrypt (encryptor, input, output);
2662 AssertEquals ("RC2_k104b64_CBC_PKCS7 Encrypt", expected, output);
2663 byte[] reverse = new byte [blockLength * 3];
2664 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2665 Decrypt (decryptor, output, reverse);
2666 byte[] original = new byte [input.Length];
2667 Array.Copy (reverse, 0, original, 0, original.Length);
2668 AssertEquals ("RC2_k104b64_CBC_PKCS7 Decrypt", input, original);
2672 /* Invalid parameters RC2_k104b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
2674 /* Invalid parameters RC2_k104b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
2676 /* Invalid parameters RC2_k104b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
2678 public void TestRC2_k104b64_CFB8_None ()
2680 byte[] key = { 0xB3, 0xE2, 0x4D, 0x91, 0xE9, 0xF8, 0x72, 0xA4, 0x2E, 0x00, 0x0C, 0x08, 0x96 };
2681 byte[] iv = { 0x48, 0xF8, 0xDD, 0x61, 0xD5, 0x00, 0xD0, 0xE1 };
2682 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 };
2684 SymmetricAlgorithm algo = RC2.Create ();
2685 algo.Mode = CipherMode.CFB;
2686 algo.Padding = PaddingMode.None;
2687 algo.BlockSize = 64;
2688 algo.FeedbackSize = 8;
2689 int blockLength = (algo.BlockSize >> 3);
2690 byte[] input = new byte [blockLength * 2];
2691 byte[] output = new byte [blockLength * 3];
2692 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2693 Encrypt (encryptor, input, output);
2694 AssertEquals ("RC2_k104b64_CFB8_None Encrypt", expected, output);
2695 byte[] reverse = new byte [blockLength * 3];
2696 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2697 Decrypt (decryptor, output, reverse);
2698 byte[] original = new byte [input.Length];
2699 Array.Copy (reverse, 0, original, 0, original.Length);
2700 AssertEquals ("RC2_k104b64_CFB8_None Decrypt", input, original);
2704 public void TestRC2_k104b64_CFB8_Zeros ()
2706 byte[] key = { 0xD4, 0x9C, 0x6B, 0x12, 0x41, 0x93, 0xEB, 0xDA, 0xDF, 0x7A, 0x81, 0x23, 0x1F };
2707 byte[] iv = { 0x3C, 0x0E, 0x48, 0xAA, 0xD8, 0x48, 0xE9, 0xC8 };
2708 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 };
2710 SymmetricAlgorithm algo = RC2.Create ();
2711 algo.Mode = CipherMode.CFB;
2712 algo.Padding = PaddingMode.Zeros;
2713 algo.BlockSize = 64;
2714 algo.FeedbackSize = 8;
2715 int blockLength = (algo.BlockSize >> 3);
2716 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2717 byte[] output = new byte [blockLength * 3];
2718 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2719 Encrypt (encryptor, input, output);
2720 AssertEquals ("RC2_k104b64_CFB8_Zeros Encrypt", expected, output);
2721 byte[] reverse = new byte [blockLength * 3];
2722 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2723 Decrypt (decryptor, output, reverse);
2724 byte[] original = new byte [input.Length];
2725 Array.Copy (reverse, 0, original, 0, original.Length);
2726 AssertEquals ("RC2_k104b64_CFB8_Zeros Decrypt", input, original);
2730 public void TestRC2_k104b64_CFB8_PKCS7 ()
2732 byte[] key = { 0x2C, 0x38, 0x19, 0x43, 0x93, 0x38, 0x85, 0xC4, 0xF2, 0x19, 0xC7, 0x1B, 0x76 };
2733 byte[] iv = { 0xB4, 0x1B, 0x9C, 0x82, 0xB5, 0x6E, 0x42, 0xAF };
2734 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 };
2736 SymmetricAlgorithm algo = RC2.Create ();
2737 algo.Mode = CipherMode.CFB;
2738 algo.Padding = PaddingMode.PKCS7;
2739 algo.BlockSize = 64;
2740 algo.FeedbackSize = 8;
2741 int blockLength = (algo.BlockSize >> 3);
2742 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2743 byte[] output = new byte [blockLength * 3];
2744 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2745 Encrypt (encryptor, input, output);
2746 AssertEquals ("RC2_k104b64_CFB8_PKCS7 Encrypt", expected, output);
2747 byte[] reverse = new byte [blockLength * 3];
2748 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2749 Decrypt (decryptor, output, reverse);
2750 byte[] original = new byte [input.Length];
2751 Array.Copy (reverse, 0, original, 0, original.Length);
2752 AssertEquals ("RC2_k104b64_CFB8_PKCS7 Decrypt", input, original);
2756 /* Invalid parameters RC2_k104b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
2758 /* Invalid parameters RC2_k104b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
2760 /* Invalid parameters RC2_k104b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
2762 public void TestRC2_k112b64_ECB_None ()
2764 byte[] key = { 0xB7, 0x95, 0xA4, 0x42, 0x21, 0x3D, 0x30, 0x51, 0x98, 0x01, 0xA0, 0x6C, 0x45, 0x68 };
2765 // not used for ECB but make the code more uniform
2766 byte[] iv = { 0x3B, 0x36, 0x51, 0x24, 0xF4, 0x1A, 0xC1, 0x91 };
2767 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 };
2769 SymmetricAlgorithm algo = RC2.Create ();
2770 algo.Mode = CipherMode.ECB;
2771 algo.Padding = PaddingMode.None;
2772 algo.BlockSize = 64;
2773 int blockLength = (algo.BlockSize >> 3);
2774 byte[] input = new byte [blockLength * 2];
2775 byte[] output = new byte [blockLength * 3];
2776 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2777 Encrypt (encryptor, input, output);
2778 AssertEquals ("RC2_k112b64_ECB_None Encrypt", expected, output);
2780 // in ECB the first 2 blocks should be equals (as the IV is not used)
2781 byte[] block1 = new byte[blockLength];
2782 Array.Copy (output, 0, block1, 0, blockLength);
2783 byte[] block2 = new byte[blockLength];
2784 Array.Copy (output, blockLength, block2, 0, blockLength);
2785 AssertEquals ("RC2_k112b64_ECB_None b1==b2", block1, block2);
2786 byte[] reverse = new byte [blockLength * 3];
2787 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2788 Decrypt (decryptor, output, reverse);
2789 byte[] original = new byte [input.Length];
2790 Array.Copy (reverse, 0, original, 0, original.Length);
2791 AssertEquals ("RC2_k112b64_ECB_None Decrypt", input, original);
2795 public void TestRC2_k112b64_ECB_Zeros ()
2797 byte[] key = { 0xB1, 0x8E, 0x09, 0xFB, 0x70, 0x03, 0x6A, 0xF2, 0xCF, 0x9D, 0x9B, 0xD7, 0x10, 0xD4 };
2798 // not used for ECB but make the code more uniform
2799 byte[] iv = { 0x64, 0x15, 0x78, 0xB8, 0x25, 0x15, 0xFA, 0xC8 };
2800 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 };
2802 SymmetricAlgorithm algo = RC2.Create ();
2803 algo.Mode = CipherMode.ECB;
2804 algo.Padding = PaddingMode.Zeros;
2805 algo.BlockSize = 64;
2806 int blockLength = (algo.BlockSize >> 3);
2807 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2808 byte[] output = new byte [blockLength * 3];
2809 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2810 Encrypt (encryptor, input, output);
2811 AssertEquals ("RC2_k112b64_ECB_Zeros Encrypt", expected, output);
2813 // in ECB the first 2 blocks should be equals (as the IV is not used)
2814 byte[] block1 = new byte[blockLength];
2815 Array.Copy (output, 0, block1, 0, blockLength);
2816 byte[] block2 = new byte[blockLength];
2817 Array.Copy (output, blockLength, block2, 0, blockLength);
2818 AssertEquals ("RC2_k112b64_ECB_Zeros b1==b2", block1, block2);
2820 // also if padding is Zeros then all three blocks should be equals
2821 byte[] block3 = new byte[blockLength];
2822 Array.Copy (output, blockLength, block3, 0, blockLength);
2823 AssertEquals ("RC2_k112b64_ECB_Zeros b1==b3", block1, block3);
2825 byte[] reverse = new byte [blockLength * 3];
2826 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2827 Decrypt (decryptor, output, reverse);
2828 byte[] original = new byte [input.Length];
2829 Array.Copy (reverse, 0, original, 0, original.Length);
2830 AssertEquals ("RC2_k112b64_ECB_Zeros Decrypt", input, original);
2834 public void TestRC2_k112b64_ECB_PKCS7 ()
2836 byte[] key = { 0x4F, 0xE8, 0x2C, 0x62, 0x98, 0x89, 0xEF, 0x11, 0x29, 0xB2, 0xDD, 0x4D, 0xE1, 0x39 };
2837 // not used for ECB but make the code more uniform
2838 byte[] iv = { 0x15, 0xE0, 0x95, 0x29, 0xEB, 0xE5, 0xC7, 0x8E };
2839 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 };
2841 SymmetricAlgorithm algo = RC2.Create ();
2842 algo.Mode = CipherMode.ECB;
2843 algo.Padding = PaddingMode.PKCS7;
2844 algo.BlockSize = 64;
2845 int blockLength = (algo.BlockSize >> 3);
2846 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2847 byte[] output = new byte [blockLength * 3];
2848 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2849 Encrypt (encryptor, input, output);
2850 AssertEquals ("RC2_k112b64_ECB_PKCS7 Encrypt", expected, output);
2852 // in ECB the first 2 blocks should be equals (as the IV is not used)
2853 byte[] block1 = new byte[blockLength];
2854 Array.Copy (output, 0, block1, 0, blockLength);
2855 byte[] block2 = new byte[blockLength];
2856 Array.Copy (output, blockLength, block2, 0, blockLength);
2857 AssertEquals ("RC2_k112b64_ECB_PKCS7 b1==b2", block1, block2);
2858 byte[] reverse = new byte [blockLength * 3];
2859 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2860 Decrypt (decryptor, output, reverse);
2861 byte[] original = new byte [input.Length];
2862 Array.Copy (reverse, 0, original, 0, original.Length);
2863 AssertEquals ("RC2_k112b64_ECB_PKCS7 Decrypt", input, original);
2867 public void TestRC2_k112b64_CBC_None ()
2869 byte[] key = { 0xC0, 0x04, 0xA9, 0x3C, 0x94, 0xA1, 0x78, 0xA2, 0x4B, 0x94, 0x6F, 0x19, 0xD1, 0xE1 };
2870 byte[] iv = { 0x28, 0x94, 0x16, 0x28, 0x69, 0x64, 0xF6, 0x83 };
2871 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 };
2873 SymmetricAlgorithm algo = RC2.Create ();
2874 algo.Mode = CipherMode.CBC;
2875 algo.Padding = PaddingMode.None;
2876 algo.BlockSize = 64;
2877 int blockLength = (algo.BlockSize >> 3);
2878 byte[] input = new byte [blockLength * 2];
2879 byte[] output = new byte [blockLength * 3];
2880 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2881 Encrypt (encryptor, input, output);
2882 AssertEquals ("RC2_k112b64_CBC_None Encrypt", expected, output);
2883 byte[] reverse = new byte [blockLength * 3];
2884 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2885 Decrypt (decryptor, output, reverse);
2886 byte[] original = new byte [input.Length];
2887 Array.Copy (reverse, 0, original, 0, original.Length);
2888 AssertEquals ("RC2_k112b64_CBC_None Decrypt", input, original);
2892 public void TestRC2_k112b64_CBC_Zeros ()
2894 byte[] key = { 0x59, 0xFF, 0xC2, 0xB5, 0x62, 0x84, 0x27, 0x49, 0x4B, 0xFF, 0xFF, 0xCE, 0xBB, 0xBD };
2895 byte[] iv = { 0x2E, 0x9E, 0xD3, 0xF6, 0xFC, 0xD7, 0xC6, 0x1C };
2896 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 };
2898 SymmetricAlgorithm algo = RC2.Create ();
2899 algo.Mode = CipherMode.CBC;
2900 algo.Padding = PaddingMode.Zeros;
2901 algo.BlockSize = 64;
2902 int blockLength = (algo.BlockSize >> 3);
2903 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2904 byte[] output = new byte [blockLength * 3];
2905 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2906 Encrypt (encryptor, input, output);
2907 AssertEquals ("RC2_k112b64_CBC_Zeros Encrypt", expected, output);
2908 byte[] reverse = new byte [blockLength * 3];
2909 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2910 Decrypt (decryptor, output, reverse);
2911 byte[] original = new byte [input.Length];
2912 Array.Copy (reverse, 0, original, 0, original.Length);
2913 AssertEquals ("RC2_k112b64_CBC_Zeros Decrypt", input, original);
2917 public void TestRC2_k112b64_CBC_PKCS7 ()
2919 byte[] key = { 0xE4, 0x49, 0xA4, 0xBE, 0x30, 0xE1, 0xB5, 0x21, 0x33, 0xC6, 0x37, 0x88, 0x30, 0xEC };
2920 byte[] iv = { 0x74, 0xAC, 0x28, 0x92, 0xA5, 0xF1, 0x31, 0xC9 };
2921 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 };
2923 SymmetricAlgorithm algo = RC2.Create ();
2924 algo.Mode = CipherMode.CBC;
2925 algo.Padding = PaddingMode.PKCS7;
2926 algo.BlockSize = 64;
2927 int blockLength = (algo.BlockSize >> 3);
2928 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2929 byte[] output = new byte [blockLength * 3];
2930 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2931 Encrypt (encryptor, input, output);
2932 AssertEquals ("RC2_k112b64_CBC_PKCS7 Encrypt", expected, output);
2933 byte[] reverse = new byte [blockLength * 3];
2934 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2935 Decrypt (decryptor, output, reverse);
2936 byte[] original = new byte [input.Length];
2937 Array.Copy (reverse, 0, original, 0, original.Length);
2938 AssertEquals ("RC2_k112b64_CBC_PKCS7 Decrypt", input, original);
2942 /* Invalid parameters RC2_k112b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
2944 /* Invalid parameters RC2_k112b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
2946 /* Invalid parameters RC2_k112b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
2948 public void TestRC2_k112b64_CFB8_None ()
2950 byte[] key = { 0x70, 0x12, 0xEC, 0xAB, 0x6E, 0x1D, 0xEF, 0x51, 0xEE, 0xA8, 0x81, 0xE1, 0x21, 0xFF };
2951 byte[] iv = { 0x0E, 0x56, 0xA2, 0xA3, 0x8C, 0x5D, 0x9C, 0x1F };
2952 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 };
2954 SymmetricAlgorithm algo = RC2.Create ();
2955 algo.Mode = CipherMode.CFB;
2956 algo.Padding = PaddingMode.None;
2957 algo.BlockSize = 64;
2958 algo.FeedbackSize = 8;
2959 int blockLength = (algo.BlockSize >> 3);
2960 byte[] input = new byte [blockLength * 2];
2961 byte[] output = new byte [blockLength * 3];
2962 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2963 Encrypt (encryptor, input, output);
2964 AssertEquals ("RC2_k112b64_CFB8_None Encrypt", expected, output);
2965 byte[] reverse = new byte [blockLength * 3];
2966 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2967 Decrypt (decryptor, output, reverse);
2968 byte[] original = new byte [input.Length];
2969 Array.Copy (reverse, 0, original, 0, original.Length);
2970 AssertEquals ("RC2_k112b64_CFB8_None Decrypt", input, original);
2974 public void TestRC2_k112b64_CFB8_Zeros ()
2976 byte[] key = { 0x48, 0x66, 0x16, 0xD6, 0x57, 0xBF, 0x38, 0xB7, 0x22, 0x81, 0x9F, 0x75, 0xE0, 0x88 };
2977 byte[] iv = { 0x51, 0x2C, 0x6A, 0x59, 0xAB, 0xD2, 0xAE, 0x6E };
2978 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 };
2980 SymmetricAlgorithm algo = RC2.Create ();
2981 algo.Mode = CipherMode.CFB;
2982 algo.Padding = PaddingMode.Zeros;
2983 algo.BlockSize = 64;
2984 algo.FeedbackSize = 8;
2985 int blockLength = (algo.BlockSize >> 3);
2986 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
2987 byte[] output = new byte [blockLength * 3];
2988 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
2989 Encrypt (encryptor, input, output);
2990 AssertEquals ("RC2_k112b64_CFB8_Zeros Encrypt", expected, output);
2991 byte[] reverse = new byte [blockLength * 3];
2992 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
2993 Decrypt (decryptor, output, reverse);
2994 byte[] original = new byte [input.Length];
2995 Array.Copy (reverse, 0, original, 0, original.Length);
2996 AssertEquals ("RC2_k112b64_CFB8_Zeros Decrypt", input, original);
3000 public void TestRC2_k112b64_CFB8_PKCS7 ()
3002 byte[] key = { 0x55, 0x20, 0xA1, 0xD8, 0xFA, 0xE7, 0x0D, 0xF9, 0xB6, 0x4B, 0x90, 0x10, 0xDE, 0xB1 };
3003 byte[] iv = { 0x26, 0x6C, 0xB0, 0xB4, 0x4D, 0x7F, 0x5C, 0x18 };
3004 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 };
3006 SymmetricAlgorithm algo = RC2.Create ();
3007 algo.Mode = CipherMode.CFB;
3008 algo.Padding = PaddingMode.PKCS7;
3009 algo.BlockSize = 64;
3010 algo.FeedbackSize = 8;
3011 int blockLength = (algo.BlockSize >> 3);
3012 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3013 byte[] output = new byte [blockLength * 3];
3014 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3015 Encrypt (encryptor, input, output);
3016 AssertEquals ("RC2_k112b64_CFB8_PKCS7 Encrypt", expected, output);
3017 byte[] reverse = new byte [blockLength * 3];
3018 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3019 Decrypt (decryptor, output, reverse);
3020 byte[] original = new byte [input.Length];
3021 Array.Copy (reverse, 0, original, 0, original.Length);
3022 AssertEquals ("RC2_k112b64_CFB8_PKCS7 Decrypt", input, original);
3026 /* Invalid parameters RC2_k112b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
3028 /* Invalid parameters RC2_k112b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
3030 /* Invalid parameters RC2_k112b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
3032 public void TestRC2_k120b64_ECB_None ()
3034 byte[] key = { 0x5D, 0x08, 0xC7, 0xB8, 0xB1, 0xEB, 0x89, 0x1C, 0xC0, 0x3F, 0xE6, 0x2F, 0xC4, 0x79, 0x11 };
3035 // not used for ECB but make the code more uniform
3036 byte[] iv = { 0x76, 0x1C, 0xAC, 0x0F, 0x39, 0x6C, 0x1A, 0x44 };
3037 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 };
3039 SymmetricAlgorithm algo = RC2.Create ();
3040 algo.Mode = CipherMode.ECB;
3041 algo.Padding = PaddingMode.None;
3042 algo.BlockSize = 64;
3043 int blockLength = (algo.BlockSize >> 3);
3044 byte[] input = new byte [blockLength * 2];
3045 byte[] output = new byte [blockLength * 3];
3046 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3047 Encrypt (encryptor, input, output);
3048 AssertEquals ("RC2_k120b64_ECB_None Encrypt", expected, output);
3050 // in ECB the first 2 blocks should be equals (as the IV is not used)
3051 byte[] block1 = new byte[blockLength];
3052 Array.Copy (output, 0, block1, 0, blockLength);
3053 byte[] block2 = new byte[blockLength];
3054 Array.Copy (output, blockLength, block2, 0, blockLength);
3055 AssertEquals ("RC2_k120b64_ECB_None b1==b2", block1, block2);
3056 byte[] reverse = new byte [blockLength * 3];
3057 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3058 Decrypt (decryptor, output, reverse);
3059 byte[] original = new byte [input.Length];
3060 Array.Copy (reverse, 0, original, 0, original.Length);
3061 AssertEquals ("RC2_k120b64_ECB_None Decrypt", input, original);
3065 public void TestRC2_k120b64_ECB_Zeros ()
3067 byte[] key = { 0x1D, 0x13, 0x51, 0x02, 0x28, 0xF4, 0xF0, 0x13, 0x90, 0xFD, 0xE4, 0xC0, 0xE5, 0x57, 0x9A };
3068 // not used for ECB but make the code more uniform
3069 byte[] iv = { 0x9E, 0xC9, 0xA7, 0x52, 0xD2, 0x6E, 0x9B, 0xE4 };
3070 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 };
3072 SymmetricAlgorithm algo = RC2.Create ();
3073 algo.Mode = CipherMode.ECB;
3074 algo.Padding = PaddingMode.Zeros;
3075 algo.BlockSize = 64;
3076 int blockLength = (algo.BlockSize >> 3);
3077 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3078 byte[] output = new byte [blockLength * 3];
3079 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3080 Encrypt (encryptor, input, output);
3081 AssertEquals ("RC2_k120b64_ECB_Zeros Encrypt", expected, output);
3083 // in ECB the first 2 blocks should be equals (as the IV is not used)
3084 byte[] block1 = new byte[blockLength];
3085 Array.Copy (output, 0, block1, 0, blockLength);
3086 byte[] block2 = new byte[blockLength];
3087 Array.Copy (output, blockLength, block2, 0, blockLength);
3088 AssertEquals ("RC2_k120b64_ECB_Zeros b1==b2", block1, block2);
3090 // also if padding is Zeros then all three blocks should be equals
3091 byte[] block3 = new byte[blockLength];
3092 Array.Copy (output, blockLength, block3, 0, blockLength);
3093 AssertEquals ("RC2_k120b64_ECB_Zeros b1==b3", block1, block3);
3095 byte[] reverse = new byte [blockLength * 3];
3096 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3097 Decrypt (decryptor, output, reverse);
3098 byte[] original = new byte [input.Length];
3099 Array.Copy (reverse, 0, original, 0, original.Length);
3100 AssertEquals ("RC2_k120b64_ECB_Zeros Decrypt", input, original);
3104 public void TestRC2_k120b64_ECB_PKCS7 ()
3106 byte[] key = { 0x23, 0xF2, 0xFB, 0x09, 0xC1, 0xEF, 0xC1, 0xFF, 0x16, 0xFF, 0x60, 0xC1, 0x3A, 0x94, 0x3E };
3107 // not used for ECB but make the code more uniform
3108 byte[] iv = { 0xB6, 0x10, 0xE3, 0xE9, 0x24, 0x03, 0xCA, 0xAA };
3109 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 };
3111 SymmetricAlgorithm algo = RC2.Create ();
3112 algo.Mode = CipherMode.ECB;
3113 algo.Padding = PaddingMode.PKCS7;
3114 algo.BlockSize = 64;
3115 int blockLength = (algo.BlockSize >> 3);
3116 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3117 byte[] output = new byte [blockLength * 3];
3118 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3119 Encrypt (encryptor, input, output);
3120 AssertEquals ("RC2_k120b64_ECB_PKCS7 Encrypt", expected, output);
3122 // in ECB the first 2 blocks should be equals (as the IV is not used)
3123 byte[] block1 = new byte[blockLength];
3124 Array.Copy (output, 0, block1, 0, blockLength);
3125 byte[] block2 = new byte[blockLength];
3126 Array.Copy (output, blockLength, block2, 0, blockLength);
3127 AssertEquals ("RC2_k120b64_ECB_PKCS7 b1==b2", block1, block2);
3128 byte[] reverse = new byte [blockLength * 3];
3129 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3130 Decrypt (decryptor, output, reverse);
3131 byte[] original = new byte [input.Length];
3132 Array.Copy (reverse, 0, original, 0, original.Length);
3133 AssertEquals ("RC2_k120b64_ECB_PKCS7 Decrypt", input, original);
3137 public void TestRC2_k120b64_CBC_None ()
3139 byte[] key = { 0x12, 0x43, 0xEE, 0x74, 0xE8, 0x4E, 0x3A, 0xF7, 0x24, 0x58, 0x10, 0xC9, 0x41, 0x7E, 0x46 };
3140 byte[] iv = { 0x7B, 0x57, 0x22, 0x19, 0xFB, 0x30, 0xED, 0x48 };
3141 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 };
3143 SymmetricAlgorithm algo = RC2.Create ();
3144 algo.Mode = CipherMode.CBC;
3145 algo.Padding = PaddingMode.None;
3146 algo.BlockSize = 64;
3147 int blockLength = (algo.BlockSize >> 3);
3148 byte[] input = new byte [blockLength * 2];
3149 byte[] output = new byte [blockLength * 3];
3150 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3151 Encrypt (encryptor, input, output);
3152 AssertEquals ("RC2_k120b64_CBC_None Encrypt", expected, output);
3153 byte[] reverse = new byte [blockLength * 3];
3154 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3155 Decrypt (decryptor, output, reverse);
3156 byte[] original = new byte [input.Length];
3157 Array.Copy (reverse, 0, original, 0, original.Length);
3158 AssertEquals ("RC2_k120b64_CBC_None Decrypt", input, original);
3162 public void TestRC2_k120b64_CBC_Zeros ()
3164 byte[] key = { 0x2A, 0xCC, 0xFF, 0xD0, 0x46, 0xAF, 0x74, 0xB2, 0x0E, 0x64, 0xBD, 0xE9, 0x6D, 0xC5, 0xE8 };
3165 byte[] iv = { 0x10, 0x21, 0xE3, 0xCB, 0x46, 0x02, 0x33, 0x4F };
3166 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 };
3168 SymmetricAlgorithm algo = RC2.Create ();
3169 algo.Mode = CipherMode.CBC;
3170 algo.Padding = PaddingMode.Zeros;
3171 algo.BlockSize = 64;
3172 int blockLength = (algo.BlockSize >> 3);
3173 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3174 byte[] output = new byte [blockLength * 3];
3175 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3176 Encrypt (encryptor, input, output);
3177 AssertEquals ("RC2_k120b64_CBC_Zeros Encrypt", expected, output);
3178 byte[] reverse = new byte [blockLength * 3];
3179 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3180 Decrypt (decryptor, output, reverse);
3181 byte[] original = new byte [input.Length];
3182 Array.Copy (reverse, 0, original, 0, original.Length);
3183 AssertEquals ("RC2_k120b64_CBC_Zeros Decrypt", input, original);
3187 public void TestRC2_k120b64_CBC_PKCS7 ()
3189 byte[] key = { 0xE8, 0xE8, 0x44, 0x9D, 0xEA, 0x33, 0x10, 0xCB, 0xEA, 0xEF, 0x69, 0x94, 0xE4, 0x31, 0xF0 };
3190 byte[] iv = { 0xC7, 0x0F, 0xE1, 0x79, 0x2B, 0x57, 0x5D, 0xA7 };
3191 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 };
3193 SymmetricAlgorithm algo = RC2.Create ();
3194 algo.Mode = CipherMode.CBC;
3195 algo.Padding = PaddingMode.PKCS7;
3196 algo.BlockSize = 64;
3197 int blockLength = (algo.BlockSize >> 3);
3198 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3199 byte[] output = new byte [blockLength * 3];
3200 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3201 Encrypt (encryptor, input, output);
3202 AssertEquals ("RC2_k120b64_CBC_PKCS7 Encrypt", expected, output);
3203 byte[] reverse = new byte [blockLength * 3];
3204 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3205 Decrypt (decryptor, output, reverse);
3206 byte[] original = new byte [input.Length];
3207 Array.Copy (reverse, 0, original, 0, original.Length);
3208 AssertEquals ("RC2_k120b64_CBC_PKCS7 Decrypt", input, original);
3212 /* Invalid parameters RC2_k120b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
3214 /* Invalid parameters RC2_k120b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
3216 /* Invalid parameters RC2_k120b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
3218 public void TestRC2_k120b64_CFB8_None ()
3220 byte[] key = { 0x0F, 0x0D, 0x1F, 0x09, 0xC2, 0xEA, 0xC5, 0xFE, 0xD1, 0x5A, 0x4C, 0x39, 0x2E, 0x62, 0xED };
3221 byte[] iv = { 0xCA, 0x90, 0x74, 0xAD, 0x6B, 0xD5, 0x42, 0xCF };
3222 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 };
3224 SymmetricAlgorithm algo = RC2.Create ();
3225 algo.Mode = CipherMode.CFB;
3226 algo.Padding = PaddingMode.None;
3227 algo.BlockSize = 64;
3228 algo.FeedbackSize = 8;
3229 int blockLength = (algo.BlockSize >> 3);
3230 byte[] input = new byte [blockLength * 2];
3231 byte[] output = new byte [blockLength * 3];
3232 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3233 Encrypt (encryptor, input, output);
3234 AssertEquals ("RC2_k120b64_CFB8_None Encrypt", expected, output);
3235 byte[] reverse = new byte [blockLength * 3];
3236 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3237 Decrypt (decryptor, output, reverse);
3238 byte[] original = new byte [input.Length];
3239 Array.Copy (reverse, 0, original, 0, original.Length);
3240 AssertEquals ("RC2_k120b64_CFB8_None Decrypt", input, original);
3244 public void TestRC2_k120b64_CFB8_Zeros ()
3246 byte[] key = { 0xDA, 0xAD, 0xD7, 0xFB, 0x36, 0x64, 0x3B, 0xE8, 0x35, 0x64, 0xC8, 0xAF, 0x0D, 0xB3, 0xAC };
3247 byte[] iv = { 0x6B, 0x99, 0x8D, 0xCA, 0x51, 0xD8, 0x26, 0x48 };
3248 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 };
3250 SymmetricAlgorithm algo = RC2.Create ();
3251 algo.Mode = CipherMode.CFB;
3252 algo.Padding = PaddingMode.Zeros;
3253 algo.BlockSize = 64;
3254 algo.FeedbackSize = 8;
3255 int blockLength = (algo.BlockSize >> 3);
3256 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3257 byte[] output = new byte [blockLength * 3];
3258 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3259 Encrypt (encryptor, input, output);
3260 AssertEquals ("RC2_k120b64_CFB8_Zeros Encrypt", expected, output);
3261 byte[] reverse = new byte [blockLength * 3];
3262 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3263 Decrypt (decryptor, output, reverse);
3264 byte[] original = new byte [input.Length];
3265 Array.Copy (reverse, 0, original, 0, original.Length);
3266 AssertEquals ("RC2_k120b64_CFB8_Zeros Decrypt", input, original);
3270 public void TestRC2_k120b64_CFB8_PKCS7 ()
3272 byte[] key = { 0x26, 0xA9, 0xE5, 0xE2, 0xE4, 0x48, 0xB5, 0x9F, 0xAC, 0x3E, 0x77, 0xB0, 0xEF, 0x1B, 0x00 };
3273 byte[] iv = { 0x0E, 0x98, 0x7F, 0xC4, 0xAC, 0x08, 0x94, 0x03 };
3274 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 };
3276 SymmetricAlgorithm algo = RC2.Create ();
3277 algo.Mode = CipherMode.CFB;
3278 algo.Padding = PaddingMode.PKCS7;
3279 algo.BlockSize = 64;
3280 algo.FeedbackSize = 8;
3281 int blockLength = (algo.BlockSize >> 3);
3282 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3283 byte[] output = new byte [blockLength * 3];
3284 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3285 Encrypt (encryptor, input, output);
3286 AssertEquals ("RC2_k120b64_CFB8_PKCS7 Encrypt", expected, output);
3287 byte[] reverse = new byte [blockLength * 3];
3288 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3289 Decrypt (decryptor, output, reverse);
3290 byte[] original = new byte [input.Length];
3291 Array.Copy (reverse, 0, original, 0, original.Length);
3292 AssertEquals ("RC2_k120b64_CFB8_PKCS7 Decrypt", input, original);
3296 /* Invalid parameters RC2_k120b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
3298 /* Invalid parameters RC2_k120b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
3300 /* Invalid parameters RC2_k120b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
3302 public void TestRC2_k128b64_ECB_None ()
3304 byte[] key = { 0x4F, 0x02, 0xB1, 0xA6, 0x5E, 0xAE, 0xB9, 0x0C, 0x3A, 0x96, 0xFF, 0x62, 0x90, 0x9A, 0xD8, 0x1B };
3305 // not used for ECB but make the code more uniform
3306 byte[] iv = { 0xC7, 0x89, 0x19, 0x4F, 0x3C, 0xC3, 0x05, 0x83 };
3307 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 };
3309 SymmetricAlgorithm algo = RC2.Create ();
3310 algo.Mode = CipherMode.ECB;
3311 algo.Padding = PaddingMode.None;
3312 algo.BlockSize = 64;
3313 int blockLength = (algo.BlockSize >> 3);
3314 byte[] input = new byte [blockLength * 2];
3315 byte[] output = new byte [blockLength * 3];
3316 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3317 Encrypt (encryptor, input, output);
3318 AssertEquals ("RC2_k128b64_ECB_None Encrypt", expected, output);
3320 // in ECB the first 2 blocks should be equals (as the IV is not used)
3321 byte[] block1 = new byte[blockLength];
3322 Array.Copy (output, 0, block1, 0, blockLength);
3323 byte[] block2 = new byte[blockLength];
3324 Array.Copy (output, blockLength, block2, 0, blockLength);
3325 AssertEquals ("RC2_k128b64_ECB_None b1==b2", block1, block2);
3326 byte[] reverse = new byte [blockLength * 3];
3327 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3328 Decrypt (decryptor, output, reverse);
3329 byte[] original = new byte [input.Length];
3330 Array.Copy (reverse, 0, original, 0, original.Length);
3331 AssertEquals ("RC2_k128b64_ECB_None Decrypt", input, original);
3335 public void TestRC2_k128b64_ECB_Zeros ()
3337 byte[] key = { 0x45, 0xBE, 0xD8, 0x8E, 0x0A, 0xE7, 0xF9, 0xE2, 0x3C, 0x33, 0xE7, 0x93, 0xD4, 0x9D, 0xAE, 0x2B };
3338 // not used for ECB but make the code more uniform
3339 byte[] iv = { 0x83, 0x27, 0x57, 0x97, 0x06, 0x4F, 0xFE, 0xB3 };
3340 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 };
3342 SymmetricAlgorithm algo = RC2.Create ();
3343 algo.Mode = CipherMode.ECB;
3344 algo.Padding = PaddingMode.Zeros;
3345 algo.BlockSize = 64;
3346 int blockLength = (algo.BlockSize >> 3);
3347 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3348 byte[] output = new byte [blockLength * 3];
3349 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3350 Encrypt (encryptor, input, output);
3351 AssertEquals ("RC2_k128b64_ECB_Zeros Encrypt", expected, output);
3353 // in ECB the first 2 blocks should be equals (as the IV is not used)
3354 byte[] block1 = new byte[blockLength];
3355 Array.Copy (output, 0, block1, 0, blockLength);
3356 byte[] block2 = new byte[blockLength];
3357 Array.Copy (output, blockLength, block2, 0, blockLength);
3358 AssertEquals ("RC2_k128b64_ECB_Zeros b1==b2", block1, block2);
3360 // also if padding is Zeros then all three blocks should be equals
3361 byte[] block3 = new byte[blockLength];
3362 Array.Copy (output, blockLength, block3, 0, blockLength);
3363 AssertEquals ("RC2_k128b64_ECB_Zeros b1==b3", block1, block3);
3365 byte[] reverse = new byte [blockLength * 3];
3366 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3367 Decrypt (decryptor, output, reverse);
3368 byte[] original = new byte [input.Length];
3369 Array.Copy (reverse, 0, original, 0, original.Length);
3370 AssertEquals ("RC2_k128b64_ECB_Zeros Decrypt", input, original);
3374 public void TestRC2_k128b64_ECB_PKCS7 ()
3376 byte[] key = { 0x6F, 0x04, 0x76, 0x7D, 0x88, 0x01, 0x29, 0x6A, 0xD5, 0x1E, 0x38, 0x9D, 0xED, 0x56, 0xAC, 0x9C };
3377 // not used for ECB but make the code more uniform
3378 byte[] iv = { 0x82, 0x74, 0xAC, 0xAA, 0x42, 0x29, 0x35, 0x8D };
3379 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 };
3381 SymmetricAlgorithm algo = RC2.Create ();
3382 algo.Mode = CipherMode.ECB;
3383 algo.Padding = PaddingMode.PKCS7;
3384 algo.BlockSize = 64;
3385 int blockLength = (algo.BlockSize >> 3);
3386 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3387 byte[] output = new byte [blockLength * 3];
3388 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3389 Encrypt (encryptor, input, output);
3390 AssertEquals ("RC2_k128b64_ECB_PKCS7 Encrypt", expected, output);
3392 // in ECB the first 2 blocks should be equals (as the IV is not used)
3393 byte[] block1 = new byte[blockLength];
3394 Array.Copy (output, 0, block1, 0, blockLength);
3395 byte[] block2 = new byte[blockLength];
3396 Array.Copy (output, blockLength, block2, 0, blockLength);
3397 AssertEquals ("RC2_k128b64_ECB_PKCS7 b1==b2", block1, block2);
3398 byte[] reverse = new byte [blockLength * 3];
3399 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3400 Decrypt (decryptor, output, reverse);
3401 byte[] original = new byte [input.Length];
3402 Array.Copy (reverse, 0, original, 0, original.Length);
3403 AssertEquals ("RC2_k128b64_ECB_PKCS7 Decrypt", input, original);
3407 public void TestRC2_k128b64_CBC_None ()
3409 byte[] key = { 0x17, 0x3F, 0x40, 0xF3, 0xDC, 0xFF, 0x8F, 0xF2, 0x71, 0x2E, 0x8B, 0x6A, 0xE0, 0x2E, 0x3F, 0x82 };
3410 byte[] iv = { 0xFA, 0xB4, 0x41, 0x91, 0x34, 0xFC, 0x9B, 0x49 };
3411 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 };
3413 SymmetricAlgorithm algo = RC2.Create ();
3414 algo.Mode = CipherMode.CBC;
3415 algo.Padding = PaddingMode.None;
3416 algo.BlockSize = 64;
3417 int blockLength = (algo.BlockSize >> 3);
3418 byte[] input = new byte [blockLength * 2];
3419 byte[] output = new byte [blockLength * 3];
3420 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3421 Encrypt (encryptor, input, output);
3422 AssertEquals ("RC2_k128b64_CBC_None Encrypt", expected, output);
3423 byte[] reverse = new byte [blockLength * 3];
3424 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3425 Decrypt (decryptor, output, reverse);
3426 byte[] original = new byte [input.Length];
3427 Array.Copy (reverse, 0, original, 0, original.Length);
3428 AssertEquals ("RC2_k128b64_CBC_None Decrypt", input, original);
3432 public void TestRC2_k128b64_CBC_Zeros ()
3434 byte[] key = { 0x49, 0x89, 0x3E, 0x29, 0xCB, 0xB9, 0x06, 0x85, 0x7F, 0x8B, 0x86, 0xEB, 0xD7, 0x47, 0x91, 0x1D };
3435 byte[] iv = { 0xCB, 0xA1, 0x0F, 0x53, 0x7B, 0x71, 0x04, 0x89 };
3436 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 };
3438 SymmetricAlgorithm algo = RC2.Create ();
3439 algo.Mode = CipherMode.CBC;
3440 algo.Padding = PaddingMode.Zeros;
3441 algo.BlockSize = 64;
3442 int blockLength = (algo.BlockSize >> 3);
3443 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3444 byte[] output = new byte [blockLength * 3];
3445 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3446 Encrypt (encryptor, input, output);
3447 AssertEquals ("RC2_k128b64_CBC_Zeros Encrypt", expected, output);
3448 byte[] reverse = new byte [blockLength * 3];
3449 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3450 Decrypt (decryptor, output, reverse);
3451 byte[] original = new byte [input.Length];
3452 Array.Copy (reverse, 0, original, 0, original.Length);
3453 AssertEquals ("RC2_k128b64_CBC_Zeros Decrypt", input, original);
3457 public void TestRC2_k128b64_CBC_PKCS7 ()
3459 byte[] key = { 0x22, 0x04, 0xDB, 0x15, 0xD6, 0x2E, 0xEF, 0x6D, 0x5D, 0x6A, 0xDA, 0x55, 0x67, 0x41, 0x4E, 0xFD };
3460 byte[] iv = { 0xB8, 0xD1, 0xD8, 0x23, 0x00, 0x39, 0x89, 0x83 };
3461 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 };
3463 SymmetricAlgorithm algo = RC2.Create ();
3464 algo.Mode = CipherMode.CBC;
3465 algo.Padding = PaddingMode.PKCS7;
3466 algo.BlockSize = 64;
3467 int blockLength = (algo.BlockSize >> 3);
3468 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3469 byte[] output = new byte [blockLength * 3];
3470 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3471 Encrypt (encryptor, input, output);
3472 AssertEquals ("RC2_k128b64_CBC_PKCS7 Encrypt", expected, output);
3473 byte[] reverse = new byte [blockLength * 3];
3474 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3475 Decrypt (decryptor, output, reverse);
3476 byte[] original = new byte [input.Length];
3477 Array.Copy (reverse, 0, original, 0, original.Length);
3478 AssertEquals ("RC2_k128b64_CBC_PKCS7 Decrypt", input, original);
3482 /* Invalid parameters RC2_k128b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
3484 /* Invalid parameters RC2_k128b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
3486 /* Invalid parameters RC2_k128b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
3488 public void TestRC2_k128b64_CFB8_None ()
3490 byte[] key = { 0x61, 0x93, 0x31, 0x3A, 0xC2, 0x9B, 0x53, 0xB1, 0x26, 0x64, 0x36, 0x03, 0x16, 0x4A, 0xE3, 0x99 };
3491 byte[] iv = { 0xDD, 0xAD, 0xA4, 0x57, 0xC1, 0x21, 0xF1, 0xA8 };
3492 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 };
3494 SymmetricAlgorithm algo = RC2.Create ();
3495 algo.Mode = CipherMode.CFB;
3496 algo.Padding = PaddingMode.None;
3497 algo.BlockSize = 64;
3498 algo.FeedbackSize = 8;
3499 int blockLength = (algo.BlockSize >> 3);
3500 byte[] input = new byte [blockLength * 2];
3501 byte[] output = new byte [blockLength * 3];
3502 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3503 Encrypt (encryptor, input, output);
3504 AssertEquals ("RC2_k128b64_CFB8_None Encrypt", expected, output);
3505 byte[] reverse = new byte [blockLength * 3];
3506 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3507 Decrypt (decryptor, output, reverse);
3508 byte[] original = new byte [input.Length];
3509 Array.Copy (reverse, 0, original, 0, original.Length);
3510 AssertEquals ("RC2_k128b64_CFB8_None Decrypt", input, original);
3514 public void TestRC2_k128b64_CFB8_Zeros ()
3516 byte[] key = { 0x64, 0x09, 0x9A, 0xF0, 0xD2, 0x52, 0x8C, 0x03, 0xF3, 0xBF, 0x1B, 0x9B, 0x92, 0x0E, 0xBA, 0x33 };
3517 byte[] iv = { 0x15, 0x64, 0xE4, 0xFA, 0xFA, 0x58, 0x54, 0x7B };
3518 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 };
3520 SymmetricAlgorithm algo = RC2.Create ();
3521 algo.Mode = CipherMode.CFB;
3522 algo.Padding = PaddingMode.Zeros;
3523 algo.BlockSize = 64;
3524 algo.FeedbackSize = 8;
3525 int blockLength = (algo.BlockSize >> 3);
3526 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3527 byte[] output = new byte [blockLength * 3];
3528 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3529 Encrypt (encryptor, input, output);
3530 AssertEquals ("RC2_k128b64_CFB8_Zeros Encrypt", expected, output);
3531 byte[] reverse = new byte [blockLength * 3];
3532 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3533 Decrypt (decryptor, output, reverse);
3534 byte[] original = new byte [input.Length];
3535 Array.Copy (reverse, 0, original, 0, original.Length);
3536 AssertEquals ("RC2_k128b64_CFB8_Zeros Decrypt", input, original);
3540 public void TestRC2_k128b64_CFB8_PKCS7 ()
3542 byte[] key = { 0x1F, 0x09, 0xF8, 0x1B, 0xA9, 0xA4, 0x70, 0x8D, 0x53, 0x76, 0x19, 0x4A, 0xAA, 0x62, 0x84, 0x94 };
3543 byte[] iv = { 0xCC, 0x7B, 0xBE, 0xE9, 0xEE, 0x8E, 0x9C, 0x02 };
3544 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 };
3546 SymmetricAlgorithm algo = RC2.Create ();
3547 algo.Mode = CipherMode.CFB;
3548 algo.Padding = PaddingMode.PKCS7;
3549 algo.BlockSize = 64;
3550 algo.FeedbackSize = 8;
3551 int blockLength = (algo.BlockSize >> 3);
3552 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3553 byte[] output = new byte [blockLength * 3];
3554 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3555 Encrypt (encryptor, input, output);
3556 AssertEquals ("RC2_k128b64_CFB8_PKCS7 Encrypt", expected, output);
3557 byte[] reverse = new byte [blockLength * 3];
3558 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3559 Decrypt (decryptor, output, reverse);
3560 byte[] original = new byte [input.Length];
3561 Array.Copy (reverse, 0, original, 0, original.Length);
3562 AssertEquals ("RC2_k128b64_CFB8_PKCS7 Decrypt", input, original);
3566 /* Invalid parameters RC2_k128b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
3568 /* Invalid parameters RC2_k128b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
3570 /* Invalid parameters RC2_k128b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
3572 public void TestRijndael_k128b128_ECB_None ()
3574 byte[] key = { 0xAF, 0x4D, 0xFE, 0x58, 0x33, 0xAC, 0x91, 0xB2, 0xFA, 0xA3, 0x96, 0x54, 0x0B, 0x68, 0xDD, 0xA1 };
3575 // not used for ECB but make the code more uniform
3576 byte[] iv = { 0xAF, 0x70, 0xC2, 0x2E, 0x2D, 0xF1, 0x0D, 0x7F, 0x52, 0xF4, 0x65, 0x79, 0x78, 0xAC, 0x80, 0xEF };
3577 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 };
3579 SymmetricAlgorithm algo = Rijndael.Create ();
3580 algo.Mode = CipherMode.ECB;
3581 algo.Padding = PaddingMode.None;
3582 algo.BlockSize = 128;
3583 int blockLength = (algo.BlockSize >> 3);
3584 byte[] input = new byte [blockLength * 2];
3585 byte[] output = new byte [blockLength * 3];
3586 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3587 Encrypt (encryptor, input, output);
3588 AssertEquals ("Rijndael_k128b128_ECB_None Encrypt", expected, output);
3590 // in ECB the first 2 blocks should be equals (as the IV is not used)
3591 byte[] block1 = new byte[blockLength];
3592 Array.Copy (output, 0, block1, 0, blockLength);
3593 byte[] block2 = new byte[blockLength];
3594 Array.Copy (output, blockLength, block2, 0, blockLength);
3595 AssertEquals ("Rijndael_k128b128_ECB_None b1==b2", block1, block2);
3596 byte[] reverse = new byte [blockLength * 3];
3597 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3598 Decrypt (decryptor, output, reverse);
3599 byte[] original = new byte [input.Length];
3600 Array.Copy (reverse, 0, original, 0, original.Length);
3601 AssertEquals ("Rijndael_k128b128_ECB_None Decrypt", input, original);
3605 public void TestRijndael_k128b128_ECB_Zeros ()
3607 byte[] key = { 0xA4, 0x39, 0x01, 0x00, 0xDB, 0x0A, 0x47, 0xD8, 0xD8, 0xDC, 0x01, 0xF4, 0xBE, 0x96, 0xF4, 0xBB };
3608 // not used for ECB but make the code more uniform
3609 byte[] iv = { 0xEA, 0xBD, 0x55, 0x85, 0x3F, 0xC1, 0x5F, 0xCB, 0x06, 0x26, 0x3F, 0x88, 0x6A, 0x2D, 0x69, 0x45 };
3610 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 };
3612 SymmetricAlgorithm algo = Rijndael.Create ();
3613 algo.Mode = CipherMode.ECB;
3614 algo.Padding = PaddingMode.Zeros;
3615 algo.BlockSize = 128;
3616 int blockLength = (algo.BlockSize >> 3);
3617 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3618 byte[] output = new byte [blockLength * 3];
3619 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3620 // some exception can be normal... other not so!
3622 Encrypt (encryptor, input, output);
3624 catch (Exception e) {
3625 if (e.Message != "Input buffer contains insufficient data. ")
3626 Fail ("Rijndael_k128b128_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
3631 public void TestRijndael_k128b128_ECB_PKCS7 ()
3633 byte[] key = { 0x5C, 0x58, 0x03, 0x1D, 0x05, 0x07, 0xDE, 0x93, 0x8D, 0x85, 0xFD, 0x50, 0x68, 0xA3, 0xD7, 0x6B };
3634 // not used for ECB but make the code more uniform
3635 byte[] iv = { 0x1C, 0x32, 0xFE, 0x99, 0x95, 0x16, 0x74, 0xC0, 0x6F, 0xE6, 0x01, 0x2C, 0x1F, 0x07, 0x54, 0xE8 };
3636 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 };
3638 SymmetricAlgorithm algo = Rijndael.Create ();
3639 algo.Mode = CipherMode.ECB;
3640 algo.Padding = PaddingMode.PKCS7;
3641 algo.BlockSize = 128;
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 ("Rijndael_k128b128_ECB_PKCS7 Encrypt", expected, output);
3649 // in ECB the first 2 blocks should be equals (as the IV is not used)
3650 byte[] block1 = new byte[blockLength];
3651 Array.Copy (output, 0, block1, 0, blockLength);
3652 byte[] block2 = new byte[blockLength];
3653 Array.Copy (output, blockLength, block2, 0, blockLength);
3654 AssertEquals ("Rijndael_k128b128_ECB_PKCS7 b1==b2", block1, block2);
3655 byte[] reverse = new byte [blockLength * 3];
3656 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3657 Decrypt (decryptor, output, reverse);
3658 byte[] original = new byte [input.Length];
3659 Array.Copy (reverse, 0, original, 0, original.Length);
3660 AssertEquals ("Rijndael_k128b128_ECB_PKCS7 Decrypt", input, original);
3664 public void TestRijndael_k128b128_CBC_None ()
3666 byte[] key = { 0xED, 0xE4, 0xD9, 0x97, 0x8E, 0x5C, 0xF8, 0x86, 0xFE, 0x6B, 0xF4, 0xA7, 0x26, 0xDA, 0x70, 0x47 };
3667 byte[] iv = { 0x06, 0xE1, 0xA5, 0x97, 0x7E, 0x20, 0x0C, 0x47, 0xA4, 0xAF, 0xB8, 0xF3, 0x8D, 0x2E, 0xA9, 0xAC };
3668 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 };
3670 SymmetricAlgorithm algo = Rijndael.Create ();
3671 algo.Mode = CipherMode.CBC;
3672 algo.Padding = PaddingMode.None;
3673 algo.BlockSize = 128;
3674 int blockLength = (algo.BlockSize >> 3);
3675 byte[] input = new byte [blockLength * 2];
3676 byte[] output = new byte [blockLength * 3];
3677 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3678 Encrypt (encryptor, input, output);
3679 AssertEquals ("Rijndael_k128b128_CBC_None Encrypt", expected, output);
3680 byte[] reverse = new byte [blockLength * 3];
3681 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3682 Decrypt (decryptor, output, reverse);
3683 byte[] original = new byte [input.Length];
3684 Array.Copy (reverse, 0, original, 0, original.Length);
3685 AssertEquals ("Rijndael_k128b128_CBC_None Decrypt", input, original);
3689 public void TestRijndael_k128b128_CBC_Zeros ()
3691 byte[] key = { 0x7F, 0x03, 0x95, 0x4E, 0x42, 0x9E, 0x83, 0x85, 0x4B, 0x1A, 0x87, 0x36, 0xA1, 0x5B, 0xA8, 0x24 };
3692 byte[] iv = { 0x75, 0x49, 0x7B, 0xBE, 0x78, 0x55, 0x5F, 0xE9, 0x67, 0xCB, 0x7E, 0x30, 0x71, 0xD1, 0x36, 0x49 };
3693 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 };
3695 SymmetricAlgorithm algo = Rijndael.Create ();
3696 algo.Mode = CipherMode.CBC;
3697 algo.Padding = PaddingMode.Zeros;
3698 algo.BlockSize = 128;
3699 int blockLength = (algo.BlockSize >> 3);
3700 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3701 byte[] output = new byte [blockLength * 3];
3702 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3703 // some exception can be normal... other not so!
3705 Encrypt (encryptor, input, output);
3707 catch (Exception e) {
3708 if (e.Message != "Input buffer contains insufficient data. ")
3709 Fail ("Rijndael_k128b128_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
3714 public void TestRijndael_k128b128_CBC_PKCS7 ()
3716 byte[] key = { 0x02, 0xE6, 0xC1, 0xE2, 0x7E, 0x89, 0xB9, 0x04, 0xE7, 0x9A, 0xB8, 0x83, 0xA4, 0xF8, 0x1B, 0x64 };
3717 byte[] iv = { 0xBC, 0xE4, 0x47, 0x1E, 0xD0, 0xDD, 0x09, 0x0D, 0xFC, 0xA1, 0x44, 0xCD, 0x88, 0x92, 0x41, 0xA5 };
3718 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 };
3720 SymmetricAlgorithm algo = Rijndael.Create ();
3721 algo.Mode = CipherMode.CBC;
3722 algo.Padding = PaddingMode.PKCS7;
3723 algo.BlockSize = 128;
3724 int blockLength = (algo.BlockSize >> 3);
3725 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3726 byte[] output = new byte [blockLength * 3];
3727 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3728 Encrypt (encryptor, input, output);
3729 AssertEquals ("Rijndael_k128b128_CBC_PKCS7 Encrypt", expected, output);
3730 byte[] reverse = new byte [blockLength * 3];
3731 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3732 Decrypt (decryptor, output, reverse);
3733 byte[] original = new byte [input.Length];
3734 Array.Copy (reverse, 0, original, 0, original.Length);
3735 AssertEquals ("Rijndael_k128b128_CBC_PKCS7 Decrypt", input, original);
3739 /* Invalid parameters Rijndael_k128b128_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
3741 /* Invalid parameters Rijndael_k128b128_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
3743 /* Invalid parameters Rijndael_k128b128_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
3745 /* Invalid parameters Rijndael_k128b128_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
3747 /* Invalid parameters Rijndael_k128b128_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
3749 /* Invalid parameters Rijndael_k128b128_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
3751 /* Invalid parameters Rijndael_k128b128_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
3753 /* Invalid parameters Rijndael_k128b128_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
3755 /* Invalid parameters Rijndael_k128b128_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
3757 public void TestRijndael_k128b192_ECB_None ()
3759 byte[] key = { 0xA5, 0x7F, 0xA2, 0x9F, 0xDA, 0xEE, 0x56, 0x2E, 0xF9, 0x3A, 0xEE, 0x1E, 0x30, 0x46, 0x80, 0x66 };
3760 // not used for ECB but make the code more uniform
3761 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 };
3762 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 };
3764 SymmetricAlgorithm algo = Rijndael.Create ();
3765 algo.Mode = CipherMode.ECB;
3766 algo.Padding = PaddingMode.None;
3767 algo.BlockSize = 192;
3768 int blockLength = (algo.BlockSize >> 3);
3769 byte[] input = new byte [blockLength * 2];
3770 byte[] output = new byte [blockLength * 3];
3771 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3772 Encrypt (encryptor, input, output);
3773 AssertEquals ("Rijndael_k128b192_ECB_None Encrypt", expected, output);
3775 // in ECB the first 2 blocks should be equals (as the IV is not used)
3776 byte[] block1 = new byte[blockLength];
3777 Array.Copy (output, 0, block1, 0, blockLength);
3778 byte[] block2 = new byte[blockLength];
3779 Array.Copy (output, blockLength, block2, 0, blockLength);
3780 AssertEquals ("Rijndael_k128b192_ECB_None b1==b2", block1, block2);
3781 byte[] reverse = new byte [blockLength * 3];
3782 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3783 Decrypt (decryptor, output, reverse);
3784 byte[] original = new byte [input.Length];
3785 Array.Copy (reverse, 0, original, 0, original.Length);
3786 AssertEquals ("Rijndael_k128b192_ECB_None Decrypt", input, original);
3790 public void TestRijndael_k128b192_ECB_Zeros ()
3792 byte[] key = { 0xDF, 0x1B, 0x73, 0xA3, 0xE3, 0x53, 0x75, 0x92, 0x2B, 0xD0, 0x44, 0x35, 0x94, 0xF5, 0xB2, 0xE7 };
3793 // not used for ECB but make the code more uniform
3794 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 };
3795 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 };
3797 SymmetricAlgorithm algo = Rijndael.Create ();
3798 algo.Mode = CipherMode.ECB;
3799 algo.Padding = PaddingMode.Zeros;
3800 algo.BlockSize = 192;
3801 int blockLength = (algo.BlockSize >> 3);
3802 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3803 byte[] output = new byte [blockLength * 3];
3804 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3805 // some exception can be normal... other not so!
3807 Encrypt (encryptor, input, output);
3809 catch (Exception e) {
3810 if (e.Message != "Input buffer contains insufficient data. ")
3811 Fail ("Rijndael_k128b192_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
3816 public void TestRijndael_k128b192_ECB_PKCS7 ()
3818 byte[] key = { 0x78, 0x75, 0x1F, 0xE7, 0xFA, 0x1F, 0xF4, 0x2D, 0x31, 0x36, 0x14, 0xA5, 0xB8, 0x31, 0x97, 0x47 };
3819 // not used for ECB but make the code more uniform
3820 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 };
3821 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 };
3823 SymmetricAlgorithm algo = Rijndael.Create ();
3824 algo.Mode = CipherMode.ECB;
3825 algo.Padding = PaddingMode.PKCS7;
3826 algo.BlockSize = 192;
3827 int blockLength = (algo.BlockSize >> 3);
3828 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3829 byte[] output = new byte [blockLength * 3];
3830 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3831 Encrypt (encryptor, input, output);
3832 AssertEquals ("Rijndael_k128b192_ECB_PKCS7 Encrypt", expected, output);
3834 // in ECB the first 2 blocks should be equals (as the IV is not used)
3835 byte[] block1 = new byte[blockLength];
3836 Array.Copy (output, 0, block1, 0, blockLength);
3837 byte[] block2 = new byte[blockLength];
3838 Array.Copy (output, blockLength, block2, 0, blockLength);
3839 AssertEquals ("Rijndael_k128b192_ECB_PKCS7 b1==b2", block1, block2);
3840 byte[] reverse = new byte [blockLength * 3];
3841 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3842 Decrypt (decryptor, output, reverse);
3843 byte[] original = new byte [input.Length];
3844 Array.Copy (reverse, 0, original, 0, original.Length);
3845 AssertEquals ("Rijndael_k128b192_ECB_PKCS7 Decrypt", input, original);
3849 public void TestRijndael_k128b192_CBC_None ()
3851 byte[] key = { 0xBD, 0x01, 0x0F, 0x53, 0x53, 0x14, 0x90, 0x58, 0x22, 0x81, 0x6F, 0x79, 0x8C, 0x68, 0x21, 0x21 };
3852 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 };
3853 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 };
3855 SymmetricAlgorithm algo = Rijndael.Create ();
3856 algo.Mode = CipherMode.CBC;
3857 algo.Padding = PaddingMode.None;
3858 algo.BlockSize = 192;
3859 int blockLength = (algo.BlockSize >> 3);
3860 byte[] input = new byte [blockLength * 2];
3861 byte[] output = new byte [blockLength * 3];
3862 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3863 Encrypt (encryptor, input, output);
3864 AssertEquals ("Rijndael_k128b192_CBC_None Encrypt", expected, output);
3865 byte[] reverse = new byte [blockLength * 3];
3866 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3867 Decrypt (decryptor, output, reverse);
3868 byte[] original = new byte [input.Length];
3869 Array.Copy (reverse, 0, original, 0, original.Length);
3870 AssertEquals ("Rijndael_k128b192_CBC_None Decrypt", input, original);
3874 public void TestRijndael_k128b192_CBC_Zeros ()
3876 byte[] key = { 0xE2, 0x9C, 0x2A, 0xAA, 0xD0, 0x02, 0xDD, 0xDF, 0xFE, 0xD7, 0xB0, 0x21, 0x1E, 0x52, 0xE5, 0x25 };
3877 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 };
3878 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 };
3880 SymmetricAlgorithm algo = Rijndael.Create ();
3881 algo.Mode = CipherMode.CBC;
3882 algo.Padding = PaddingMode.Zeros;
3883 algo.BlockSize = 192;
3884 int blockLength = (algo.BlockSize >> 3);
3885 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3886 byte[] output = new byte [blockLength * 3];
3887 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3888 // some exception can be normal... other not so!
3890 Encrypt (encryptor, input, output);
3892 catch (Exception e) {
3893 if (e.Message != "Input buffer contains insufficient data. ")
3894 Fail ("Rijndael_k128b192_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
3899 public void TestRijndael_k128b192_CBC_PKCS7 ()
3901 byte[] key = { 0x14, 0x6C, 0x36, 0x5E, 0x22, 0xE9, 0x25, 0x1E, 0xC9, 0x1F, 0xA7, 0xC9, 0xA5, 0x19, 0x2C, 0x09 };
3902 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 };
3903 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 };
3905 SymmetricAlgorithm algo = Rijndael.Create ();
3906 algo.Mode = CipherMode.CBC;
3907 algo.Padding = PaddingMode.PKCS7;
3908 algo.BlockSize = 192;
3909 int blockLength = (algo.BlockSize >> 3);
3910 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3911 byte[] output = new byte [blockLength * 3];
3912 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3913 Encrypt (encryptor, input, output);
3914 AssertEquals ("Rijndael_k128b192_CBC_PKCS7 Encrypt", expected, output);
3915 byte[] reverse = new byte [blockLength * 3];
3916 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3917 Decrypt (decryptor, output, reverse);
3918 byte[] original = new byte [input.Length];
3919 Array.Copy (reverse, 0, original, 0, original.Length);
3920 AssertEquals ("Rijndael_k128b192_CBC_PKCS7 Decrypt", input, original);
3924 /* Invalid parameters Rijndael_k128b192_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
3926 /* Invalid parameters Rijndael_k128b192_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
3928 /* Invalid parameters Rijndael_k128b192_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
3930 /* Invalid parameters Rijndael_k128b192_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
3932 /* Invalid parameters Rijndael_k128b192_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
3934 /* Invalid parameters Rijndael_k128b192_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
3936 /* Invalid parameters Rijndael_k128b192_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
3938 /* Invalid parameters Rijndael_k128b192_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
3940 /* Invalid parameters Rijndael_k128b192_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
3942 public void TestRijndael_k128b256_ECB_None ()
3944 byte[] key = { 0xD5, 0xB9, 0x92, 0x27, 0xC0, 0xBB, 0x86, 0x06, 0x19, 0xD9, 0xA4, 0x1B, 0x9E, 0x7A, 0xF0, 0x3D };
3945 // not used for ECB but make the code more uniform
3946 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 };
3947 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 };
3949 SymmetricAlgorithm algo = Rijndael.Create ();
3950 algo.Mode = CipherMode.ECB;
3951 algo.Padding = PaddingMode.None;
3952 algo.BlockSize = 256;
3953 int blockLength = (algo.BlockSize >> 3);
3954 byte[] input = new byte [blockLength * 2];
3955 byte[] output = new byte [blockLength * 3];
3956 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3957 Encrypt (encryptor, input, output);
3958 AssertEquals ("Rijndael_k128b256_ECB_None Encrypt", expected, output);
3960 // in ECB the first 2 blocks should be equals (as the IV is not used)
3961 byte[] block1 = new byte[blockLength];
3962 Array.Copy (output, 0, block1, 0, blockLength);
3963 byte[] block2 = new byte[blockLength];
3964 Array.Copy (output, blockLength, block2, 0, blockLength);
3965 AssertEquals ("Rijndael_k128b256_ECB_None b1==b2", block1, block2);
3966 byte[] reverse = new byte [blockLength * 3];
3967 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
3968 Decrypt (decryptor, output, reverse);
3969 byte[] original = new byte [input.Length];
3970 Array.Copy (reverse, 0, original, 0, original.Length);
3971 AssertEquals ("Rijndael_k128b256_ECB_None Decrypt", input, original);
3975 public void TestRijndael_k128b256_ECB_Zeros ()
3977 byte[] key = { 0x3C, 0xA6, 0xD7, 0xDA, 0xE3, 0x4D, 0x32, 0x67, 0xA8, 0xF5, 0xFF, 0xFF, 0xEE, 0xE8, 0xD4, 0xB2 };
3978 // not used for ECB but make the code more uniform
3979 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 };
3980 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 };
3982 SymmetricAlgorithm algo = Rijndael.Create ();
3983 algo.Mode = CipherMode.ECB;
3984 algo.Padding = PaddingMode.Zeros;
3985 algo.BlockSize = 256;
3986 int blockLength = (algo.BlockSize >> 3);
3987 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
3988 byte[] output = new byte [blockLength * 3];
3989 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
3990 // some exception can be normal... other not so!
3992 Encrypt (encryptor, input, output);
3994 catch (Exception e) {
3995 if (e.Message != "Input buffer contains insufficient data. ")
3996 Fail ("Rijndael_k128b256_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
4001 public void TestRijndael_k128b256_ECB_PKCS7 ()
4003 byte[] key = { 0xED, 0xBA, 0x84, 0x92, 0x50, 0x93, 0x9B, 0xE4, 0xC4, 0x83, 0x31, 0x8E, 0x11, 0x86, 0xAE, 0xC9 };
4004 // not used for ECB but make the code more uniform
4005 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 };
4006 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 };
4008 SymmetricAlgorithm algo = Rijndael.Create ();
4009 algo.Mode = CipherMode.ECB;
4010 algo.Padding = PaddingMode.PKCS7;
4011 algo.BlockSize = 256;
4012 int blockLength = (algo.BlockSize >> 3);
4013 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4014 byte[] output = new byte [blockLength * 3];
4015 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4016 Encrypt (encryptor, input, output);
4017 AssertEquals ("Rijndael_k128b256_ECB_PKCS7 Encrypt", expected, output);
4019 // in ECB the first 2 blocks should be equals (as the IV is not used)
4020 byte[] block1 = new byte[blockLength];
4021 Array.Copy (output, 0, block1, 0, blockLength);
4022 byte[] block2 = new byte[blockLength];
4023 Array.Copy (output, blockLength, block2, 0, blockLength);
4024 AssertEquals ("Rijndael_k128b256_ECB_PKCS7 b1==b2", block1, block2);
4025 byte[] reverse = new byte [blockLength * 3];
4026 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4027 Decrypt (decryptor, output, reverse);
4028 byte[] original = new byte [input.Length];
4029 Array.Copy (reverse, 0, original, 0, original.Length);
4030 AssertEquals ("Rijndael_k128b256_ECB_PKCS7 Decrypt", input, original);
4034 public void TestRijndael_k128b256_CBC_None ()
4036 byte[] key = { 0x23, 0x09, 0x30, 0xC7, 0x01, 0x81, 0x1D, 0x2E, 0xD6, 0x6A, 0xC9, 0x99, 0x0D, 0x3D, 0x99, 0x79 };
4037 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 };
4038 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 };
4040 SymmetricAlgorithm algo = Rijndael.Create ();
4041 algo.Mode = CipherMode.CBC;
4042 algo.Padding = PaddingMode.None;
4043 algo.BlockSize = 256;
4044 int blockLength = (algo.BlockSize >> 3);
4045 byte[] input = new byte [blockLength * 2];
4046 byte[] output = new byte [blockLength * 3];
4047 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4048 Encrypt (encryptor, input, output);
4049 AssertEquals ("Rijndael_k128b256_CBC_None Encrypt", expected, output);
4050 byte[] reverse = new byte [blockLength * 3];
4051 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4052 Decrypt (decryptor, output, reverse);
4053 byte[] original = new byte [input.Length];
4054 Array.Copy (reverse, 0, original, 0, original.Length);
4055 AssertEquals ("Rijndael_k128b256_CBC_None Decrypt", input, original);
4059 public void TestRijndael_k128b256_CBC_Zeros ()
4061 byte[] key = { 0xB6, 0xE5, 0xA0, 0x6F, 0x35, 0xA9, 0x25, 0x31, 0x5B, 0x8C, 0x52, 0x87, 0x26, 0x80, 0xB1, 0x42 };
4062 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 };
4063 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 };
4065 SymmetricAlgorithm algo = Rijndael.Create ();
4066 algo.Mode = CipherMode.CBC;
4067 algo.Padding = PaddingMode.Zeros;
4068 algo.BlockSize = 256;
4069 int blockLength = (algo.BlockSize >> 3);
4070 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4071 byte[] output = new byte [blockLength * 3];
4072 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4073 // some exception can be normal... other not so!
4075 Encrypt (encryptor, input, output);
4077 catch (Exception e) {
4078 if (e.Message != "Input buffer contains insufficient data. ")
4079 Fail ("Rijndael_k128b256_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
4084 public void TestRijndael_k128b256_CBC_PKCS7 ()
4086 byte[] key = { 0xAE, 0x7A, 0xD9, 0x55, 0xBF, 0x55, 0xB2, 0x40, 0x4A, 0x48, 0x5F, 0x06, 0xAA, 0x04, 0x45, 0x0A };
4087 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 };
4088 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 };
4090 SymmetricAlgorithm algo = Rijndael.Create ();
4091 algo.Mode = CipherMode.CBC;
4092 algo.Padding = PaddingMode.PKCS7;
4093 algo.BlockSize = 256;
4094 int blockLength = (algo.BlockSize >> 3);
4095 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4096 byte[] output = new byte [blockLength * 3];
4097 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4098 Encrypt (encryptor, input, output);
4099 AssertEquals ("Rijndael_k128b256_CBC_PKCS7 Encrypt", expected, output);
4100 byte[] reverse = new byte [blockLength * 3];
4101 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4102 Decrypt (decryptor, output, reverse);
4103 byte[] original = new byte [input.Length];
4104 Array.Copy (reverse, 0, original, 0, original.Length);
4105 AssertEquals ("Rijndael_k128b256_CBC_PKCS7 Decrypt", input, original);
4109 /* Invalid parameters Rijndael_k128b256_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
4111 /* Invalid parameters Rijndael_k128b256_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
4113 /* Invalid parameters Rijndael_k128b256_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
4115 /* Invalid parameters Rijndael_k128b256_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
4117 /* Invalid parameters Rijndael_k128b256_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
4119 /* Invalid parameters Rijndael_k128b256_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
4121 /* Invalid parameters Rijndael_k128b256_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
4123 /* Invalid parameters Rijndael_k128b256_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
4125 /* Invalid parameters Rijndael_k128b256_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
4127 public void TestRijndael_k192b128_ECB_None ()
4129 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 };
4130 // not used for ECB but make the code more uniform
4131 byte[] iv = { 0x83, 0x22, 0x1B, 0x6C, 0x66, 0x1F, 0x4A, 0xB7, 0x55, 0xAF, 0x5B, 0xBF, 0x4A, 0x05, 0x73, 0x24 };
4132 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 };
4134 SymmetricAlgorithm algo = Rijndael.Create ();
4135 algo.Mode = CipherMode.ECB;
4136 algo.Padding = PaddingMode.None;
4137 algo.BlockSize = 128;
4138 int blockLength = (algo.BlockSize >> 3);
4139 byte[] input = new byte [blockLength * 2];
4140 byte[] output = new byte [blockLength * 3];
4141 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4142 Encrypt (encryptor, input, output);
4143 AssertEquals ("Rijndael_k192b128_ECB_None Encrypt", expected, output);
4145 // in ECB the first 2 blocks should be equals (as the IV is not used)
4146 byte[] block1 = new byte[blockLength];
4147 Array.Copy (output, 0, block1, 0, blockLength);
4148 byte[] block2 = new byte[blockLength];
4149 Array.Copy (output, blockLength, block2, 0, blockLength);
4150 AssertEquals ("Rijndael_k192b128_ECB_None b1==b2", block1, block2);
4151 byte[] reverse = new byte [blockLength * 3];
4152 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4153 Decrypt (decryptor, output, reverse);
4154 byte[] original = new byte [input.Length];
4155 Array.Copy (reverse, 0, original, 0, original.Length);
4156 AssertEquals ("Rijndael_k192b128_ECB_None Decrypt", input, original);
4160 public void TestRijndael_k192b128_ECB_Zeros ()
4162 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 };
4163 // not used for ECB but make the code more uniform
4164 byte[] iv = { 0x43, 0xBA, 0x1C, 0xFB, 0x33, 0xB4, 0x3B, 0x38, 0x5C, 0x21, 0x13, 0xDD, 0x9A, 0x3A, 0xF1, 0xEE };
4165 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 };
4167 SymmetricAlgorithm algo = Rijndael.Create ();
4168 algo.Mode = CipherMode.ECB;
4169 algo.Padding = PaddingMode.Zeros;
4170 algo.BlockSize = 128;
4171 int blockLength = (algo.BlockSize >> 3);
4172 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4173 byte[] output = new byte [blockLength * 3];
4174 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4175 // some exception can be normal... other not so!
4177 Encrypt (encryptor, input, output);
4179 catch (Exception e) {
4180 if (e.Message != "Input buffer contains insufficient data. ")
4181 Fail ("Rijndael_k192b128_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
4186 public void TestRijndael_k192b128_ECB_PKCS7 ()
4188 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 };
4189 // not used for ECB but make the code more uniform
4190 byte[] iv = { 0xB0, 0xF9, 0x9F, 0x2D, 0x8D, 0xD0, 0x2D, 0xA1, 0x51, 0xDB, 0x07, 0xA3, 0x34, 0x28, 0x4F, 0x25 };
4191 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 };
4193 SymmetricAlgorithm algo = Rijndael.Create ();
4194 algo.Mode = CipherMode.ECB;
4195 algo.Padding = PaddingMode.PKCS7;
4196 algo.BlockSize = 128;
4197 int blockLength = (algo.BlockSize >> 3);
4198 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4199 byte[] output = new byte [blockLength * 3];
4200 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4201 Encrypt (encryptor, input, output);
4202 AssertEquals ("Rijndael_k192b128_ECB_PKCS7 Encrypt", expected, output);
4204 // in ECB the first 2 blocks should be equals (as the IV is not used)
4205 byte[] block1 = new byte[blockLength];
4206 Array.Copy (output, 0, block1, 0, blockLength);
4207 byte[] block2 = new byte[blockLength];
4208 Array.Copy (output, blockLength, block2, 0, blockLength);
4209 AssertEquals ("Rijndael_k192b128_ECB_PKCS7 b1==b2", block1, block2);
4210 byte[] reverse = new byte [blockLength * 3];
4211 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4212 Decrypt (decryptor, output, reverse);
4213 byte[] original = new byte [input.Length];
4214 Array.Copy (reverse, 0, original, 0, original.Length);
4215 AssertEquals ("Rijndael_k192b128_ECB_PKCS7 Decrypt", input, original);
4219 public void TestRijndael_k192b128_CBC_None ()
4221 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 };
4222 byte[] iv = { 0xCA, 0xC4, 0x8D, 0x38, 0x28, 0x29, 0xC2, 0xBF, 0xD8, 0x7A, 0xCA, 0x56, 0xBF, 0x59, 0x6B, 0xCE };
4223 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 };
4225 SymmetricAlgorithm algo = Rijndael.Create ();
4226 algo.Mode = CipherMode.CBC;
4227 algo.Padding = PaddingMode.None;
4228 algo.BlockSize = 128;
4229 int blockLength = (algo.BlockSize >> 3);
4230 byte[] input = new byte [blockLength * 2];
4231 byte[] output = new byte [blockLength * 3];
4232 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4233 Encrypt (encryptor, input, output);
4234 AssertEquals ("Rijndael_k192b128_CBC_None Encrypt", expected, output);
4235 byte[] reverse = new byte [blockLength * 3];
4236 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4237 Decrypt (decryptor, output, reverse);
4238 byte[] original = new byte [input.Length];
4239 Array.Copy (reverse, 0, original, 0, original.Length);
4240 AssertEquals ("Rijndael_k192b128_CBC_None Decrypt", input, original);
4244 public void TestRijndael_k192b128_CBC_Zeros ()
4246 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 };
4247 byte[] iv = { 0xC9, 0x76, 0xCE, 0x21, 0xDF, 0x46, 0xB0, 0x23, 0x19, 0xB6, 0xD5, 0x80, 0x1F, 0xBA, 0x15, 0xDB };
4248 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 };
4250 SymmetricAlgorithm algo = Rijndael.Create ();
4251 algo.Mode = CipherMode.CBC;
4252 algo.Padding = PaddingMode.Zeros;
4253 algo.BlockSize = 128;
4254 int blockLength = (algo.BlockSize >> 3);
4255 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4256 byte[] output = new byte [blockLength * 3];
4257 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4258 // some exception can be normal... other not so!
4260 Encrypt (encryptor, input, output);
4262 catch (Exception e) {
4263 if (e.Message != "Input buffer contains insufficient data. ")
4264 Fail ("Rijndael_k192b128_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
4269 public void TestRijndael_k192b128_CBC_PKCS7 ()
4271 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 };
4272 byte[] iv = { 0xDA, 0xE6, 0x7F, 0x27, 0x8A, 0xE6, 0x8E, 0x13, 0x9D, 0x15, 0x0D, 0x80, 0x4B, 0xC4, 0x9F, 0x08 };
4273 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 };
4275 SymmetricAlgorithm algo = Rijndael.Create ();
4276 algo.Mode = CipherMode.CBC;
4277 algo.Padding = PaddingMode.PKCS7;
4278 algo.BlockSize = 128;
4279 int blockLength = (algo.BlockSize >> 3);
4280 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4281 byte[] output = new byte [blockLength * 3];
4282 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4283 Encrypt (encryptor, input, output);
4284 AssertEquals ("Rijndael_k192b128_CBC_PKCS7 Encrypt", expected, output);
4285 byte[] reverse = new byte [blockLength * 3];
4286 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4287 Decrypt (decryptor, output, reverse);
4288 byte[] original = new byte [input.Length];
4289 Array.Copy (reverse, 0, original, 0, original.Length);
4290 AssertEquals ("Rijndael_k192b128_CBC_PKCS7 Decrypt", input, original);
4294 /* Invalid parameters Rijndael_k192b128_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
4296 /* Invalid parameters Rijndael_k192b128_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
4298 /* Invalid parameters Rijndael_k192b128_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
4300 /* Invalid parameters Rijndael_k192b128_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
4302 /* Invalid parameters Rijndael_k192b128_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
4304 /* Invalid parameters Rijndael_k192b128_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
4306 /* Invalid parameters Rijndael_k192b128_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
4308 /* Invalid parameters Rijndael_k192b128_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
4310 /* Invalid parameters Rijndael_k192b128_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
4312 public void TestRijndael_k192b192_ECB_None ()
4314 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 };
4315 // not used for ECB but make the code more uniform
4316 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 };
4317 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 };
4319 SymmetricAlgorithm algo = Rijndael.Create ();
4320 algo.Mode = CipherMode.ECB;
4321 algo.Padding = PaddingMode.None;
4322 algo.BlockSize = 192;
4323 int blockLength = (algo.BlockSize >> 3);
4324 byte[] input = new byte [blockLength * 2];
4325 byte[] output = new byte [blockLength * 3];
4326 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4327 Encrypt (encryptor, input, output);
4328 AssertEquals ("Rijndael_k192b192_ECB_None Encrypt", expected, output);
4330 // in ECB the first 2 blocks should be equals (as the IV is not used)
4331 byte[] block1 = new byte[blockLength];
4332 Array.Copy (output, 0, block1, 0, blockLength);
4333 byte[] block2 = new byte[blockLength];
4334 Array.Copy (output, blockLength, block2, 0, blockLength);
4335 AssertEquals ("Rijndael_k192b192_ECB_None b1==b2", block1, block2);
4336 byte[] reverse = new byte [blockLength * 3];
4337 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4338 Decrypt (decryptor, output, reverse);
4339 byte[] original = new byte [input.Length];
4340 Array.Copy (reverse, 0, original, 0, original.Length);
4341 AssertEquals ("Rijndael_k192b192_ECB_None Decrypt", input, original);
4345 public void TestRijndael_k192b192_ECB_Zeros ()
4347 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 };
4348 // not used for ECB but make the code more uniform
4349 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 };
4350 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 };
4352 SymmetricAlgorithm algo = Rijndael.Create ();
4353 algo.Mode = CipherMode.ECB;
4354 algo.Padding = PaddingMode.Zeros;
4355 algo.BlockSize = 192;
4356 int blockLength = (algo.BlockSize >> 3);
4357 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4358 byte[] output = new byte [blockLength * 3];
4359 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4360 // some exception can be normal... other not so!
4362 Encrypt (encryptor, input, output);
4364 catch (Exception e) {
4365 if (e.Message != "Input buffer contains insufficient data. ")
4366 Fail ("Rijndael_k192b192_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
4371 public void TestRijndael_k192b192_ECB_PKCS7 ()
4373 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 };
4374 // not used for ECB but make the code more uniform
4375 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 };
4376 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 };
4378 SymmetricAlgorithm algo = Rijndael.Create ();
4379 algo.Mode = CipherMode.ECB;
4380 algo.Padding = PaddingMode.PKCS7;
4381 algo.BlockSize = 192;
4382 int blockLength = (algo.BlockSize >> 3);
4383 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4384 byte[] output = new byte [blockLength * 3];
4385 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4386 Encrypt (encryptor, input, output);
4387 AssertEquals ("Rijndael_k192b192_ECB_PKCS7 Encrypt", expected, output);
4389 // in ECB the first 2 blocks should be equals (as the IV is not used)
4390 byte[] block1 = new byte[blockLength];
4391 Array.Copy (output, 0, block1, 0, blockLength);
4392 byte[] block2 = new byte[blockLength];
4393 Array.Copy (output, blockLength, block2, 0, blockLength);
4394 AssertEquals ("Rijndael_k192b192_ECB_PKCS7 b1==b2", block1, block2);
4395 byte[] reverse = new byte [blockLength * 3];
4396 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4397 Decrypt (decryptor, output, reverse);
4398 byte[] original = new byte [input.Length];
4399 Array.Copy (reverse, 0, original, 0, original.Length);
4400 AssertEquals ("Rijndael_k192b192_ECB_PKCS7 Decrypt", input, original);
4404 public void TestRijndael_k192b192_CBC_None ()
4406 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 };
4407 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 };
4408 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 };
4410 SymmetricAlgorithm algo = Rijndael.Create ();
4411 algo.Mode = CipherMode.CBC;
4412 algo.Padding = PaddingMode.None;
4413 algo.BlockSize = 192;
4414 int blockLength = (algo.BlockSize >> 3);
4415 byte[] input = new byte [blockLength * 2];
4416 byte[] output = new byte [blockLength * 3];
4417 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4418 Encrypt (encryptor, input, output);
4419 AssertEquals ("Rijndael_k192b192_CBC_None Encrypt", expected, output);
4420 byte[] reverse = new byte [blockLength * 3];
4421 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4422 Decrypt (decryptor, output, reverse);
4423 byte[] original = new byte [input.Length];
4424 Array.Copy (reverse, 0, original, 0, original.Length);
4425 AssertEquals ("Rijndael_k192b192_CBC_None Decrypt", input, original);
4429 public void TestRijndael_k192b192_CBC_Zeros ()
4431 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 };
4432 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 };
4433 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 };
4435 SymmetricAlgorithm algo = Rijndael.Create ();
4436 algo.Mode = CipherMode.CBC;
4437 algo.Padding = PaddingMode.Zeros;
4438 algo.BlockSize = 192;
4439 int blockLength = (algo.BlockSize >> 3);
4440 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4441 byte[] output = new byte [blockLength * 3];
4442 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4443 // some exception can be normal... other not so!
4445 Encrypt (encryptor, input, output);
4447 catch (Exception e) {
4448 if (e.Message != "Input buffer contains insufficient data. ")
4449 Fail ("Rijndael_k192b192_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
4454 public void TestRijndael_k192b192_CBC_PKCS7 ()
4456 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 };
4457 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 };
4458 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 };
4460 SymmetricAlgorithm algo = Rijndael.Create ();
4461 algo.Mode = CipherMode.CBC;
4462 algo.Padding = PaddingMode.PKCS7;
4463 algo.BlockSize = 192;
4464 int blockLength = (algo.BlockSize >> 3);
4465 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4466 byte[] output = new byte [blockLength * 3];
4467 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4468 Encrypt (encryptor, input, output);
4469 AssertEquals ("Rijndael_k192b192_CBC_PKCS7 Encrypt", expected, output);
4470 byte[] reverse = new byte [blockLength * 3];
4471 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4472 Decrypt (decryptor, output, reverse);
4473 byte[] original = new byte [input.Length];
4474 Array.Copy (reverse, 0, original, 0, original.Length);
4475 AssertEquals ("Rijndael_k192b192_CBC_PKCS7 Decrypt", input, original);
4479 /* Invalid parameters Rijndael_k192b192_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
4481 /* Invalid parameters Rijndael_k192b192_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
4483 /* Invalid parameters Rijndael_k192b192_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
4485 /* Invalid parameters Rijndael_k192b192_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
4487 /* Invalid parameters Rijndael_k192b192_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
4489 /* Invalid parameters Rijndael_k192b192_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
4491 /* Invalid parameters Rijndael_k192b192_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
4493 /* Invalid parameters Rijndael_k192b192_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
4495 /* Invalid parameters Rijndael_k192b192_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
4497 public void TestRijndael_k192b256_ECB_None ()
4499 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 };
4500 // not used for ECB but make the code more uniform
4501 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 };
4502 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 };
4504 SymmetricAlgorithm algo = Rijndael.Create ();
4505 algo.Mode = CipherMode.ECB;
4506 algo.Padding = PaddingMode.None;
4507 algo.BlockSize = 256;
4508 int blockLength = (algo.BlockSize >> 3);
4509 byte[] input = new byte [blockLength * 2];
4510 byte[] output = new byte [blockLength * 3];
4511 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4512 Encrypt (encryptor, input, output);
4513 AssertEquals ("Rijndael_k192b256_ECB_None Encrypt", expected, output);
4515 // in ECB the first 2 blocks should be equals (as the IV is not used)
4516 byte[] block1 = new byte[blockLength];
4517 Array.Copy (output, 0, block1, 0, blockLength);
4518 byte[] block2 = new byte[blockLength];
4519 Array.Copy (output, blockLength, block2, 0, blockLength);
4520 AssertEquals ("Rijndael_k192b256_ECB_None b1==b2", block1, block2);
4521 byte[] reverse = new byte [blockLength * 3];
4522 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4523 Decrypt (decryptor, output, reverse);
4524 byte[] original = new byte [input.Length];
4525 Array.Copy (reverse, 0, original, 0, original.Length);
4526 AssertEquals ("Rijndael_k192b256_ECB_None Decrypt", input, original);
4530 public void TestRijndael_k192b256_ECB_Zeros ()
4532 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 };
4533 // not used for ECB but make the code more uniform
4534 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 };
4535 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 };
4537 SymmetricAlgorithm algo = Rijndael.Create ();
4538 algo.Mode = CipherMode.ECB;
4539 algo.Padding = PaddingMode.Zeros;
4540 algo.BlockSize = 256;
4541 int blockLength = (algo.BlockSize >> 3);
4542 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4543 byte[] output = new byte [blockLength * 3];
4544 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4545 // some exception can be normal... other not so!
4547 Encrypt (encryptor, input, output);
4549 catch (Exception e) {
4550 if (e.Message != "Input buffer contains insufficient data. ")
4551 Fail ("Rijndael_k192b256_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
4556 public void TestRijndael_k192b256_ECB_PKCS7 ()
4558 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 };
4559 // not used for ECB but make the code more uniform
4560 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 };
4561 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 };
4563 SymmetricAlgorithm algo = Rijndael.Create ();
4564 algo.Mode = CipherMode.ECB;
4565 algo.Padding = PaddingMode.PKCS7;
4566 algo.BlockSize = 256;
4567 int blockLength = (algo.BlockSize >> 3);
4568 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4569 byte[] output = new byte [blockLength * 3];
4570 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4571 Encrypt (encryptor, input, output);
4572 AssertEquals ("Rijndael_k192b256_ECB_PKCS7 Encrypt", expected, output);
4574 // in ECB the first 2 blocks should be equals (as the IV is not used)
4575 byte[] block1 = new byte[blockLength];
4576 Array.Copy (output, 0, block1, 0, blockLength);
4577 byte[] block2 = new byte[blockLength];
4578 Array.Copy (output, blockLength, block2, 0, blockLength);
4579 AssertEquals ("Rijndael_k192b256_ECB_PKCS7 b1==b2", block1, block2);
4580 byte[] reverse = new byte [blockLength * 3];
4581 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4582 Decrypt (decryptor, output, reverse);
4583 byte[] original = new byte [input.Length];
4584 Array.Copy (reverse, 0, original, 0, original.Length);
4585 AssertEquals ("Rijndael_k192b256_ECB_PKCS7 Decrypt", input, original);
4589 public void TestRijndael_k192b256_CBC_None ()
4591 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 };
4592 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 };
4593 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 };
4595 SymmetricAlgorithm algo = Rijndael.Create ();
4596 algo.Mode = CipherMode.CBC;
4597 algo.Padding = PaddingMode.None;
4598 algo.BlockSize = 256;
4599 int blockLength = (algo.BlockSize >> 3);
4600 byte[] input = new byte [blockLength * 2];
4601 byte[] output = new byte [blockLength * 3];
4602 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4603 Encrypt (encryptor, input, output);
4604 AssertEquals ("Rijndael_k192b256_CBC_None Encrypt", expected, output);
4605 byte[] reverse = new byte [blockLength * 3];
4606 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4607 Decrypt (decryptor, output, reverse);
4608 byte[] original = new byte [input.Length];
4609 Array.Copy (reverse, 0, original, 0, original.Length);
4610 AssertEquals ("Rijndael_k192b256_CBC_None Decrypt", input, original);
4614 public void TestRijndael_k192b256_CBC_Zeros ()
4616 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 };
4617 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 };
4618 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 };
4620 SymmetricAlgorithm algo = Rijndael.Create ();
4621 algo.Mode = CipherMode.CBC;
4622 algo.Padding = PaddingMode.Zeros;
4623 algo.BlockSize = 256;
4624 int blockLength = (algo.BlockSize >> 3);
4625 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4626 byte[] output = new byte [blockLength * 3];
4627 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4628 // some exception can be normal... other not so!
4630 Encrypt (encryptor, input, output);
4632 catch (Exception e) {
4633 if (e.Message != "Input buffer contains insufficient data. ")
4634 Fail ("Rijndael_k192b256_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
4639 public void TestRijndael_k192b256_CBC_PKCS7 ()
4641 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 };
4642 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 };
4643 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 };
4645 SymmetricAlgorithm algo = Rijndael.Create ();
4646 algo.Mode = CipherMode.CBC;
4647 algo.Padding = PaddingMode.PKCS7;
4648 algo.BlockSize = 256;
4649 int blockLength = (algo.BlockSize >> 3);
4650 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4651 byte[] output = new byte [blockLength * 3];
4652 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4653 Encrypt (encryptor, input, output);
4654 AssertEquals ("Rijndael_k192b256_CBC_PKCS7 Encrypt", expected, output);
4655 byte[] reverse = new byte [blockLength * 3];
4656 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4657 Decrypt (decryptor, output, reverse);
4658 byte[] original = new byte [input.Length];
4659 Array.Copy (reverse, 0, original, 0, original.Length);
4660 AssertEquals ("Rijndael_k192b256_CBC_PKCS7 Decrypt", input, original);
4664 /* Invalid parameters Rijndael_k192b256_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
4666 /* Invalid parameters Rijndael_k192b256_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
4668 /* Invalid parameters Rijndael_k192b256_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
4670 /* Invalid parameters Rijndael_k192b256_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
4672 /* Invalid parameters Rijndael_k192b256_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
4674 /* Invalid parameters Rijndael_k192b256_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
4676 /* Invalid parameters Rijndael_k192b256_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
4678 /* Invalid parameters Rijndael_k192b256_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
4680 /* Invalid parameters Rijndael_k192b256_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
4682 public void TestRijndael_k256b128_ECB_None ()
4684 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 };
4685 // not used for ECB but make the code more uniform
4686 byte[] iv = { 0xF5, 0xBD, 0x6D, 0xDF, 0x0C, 0x8E, 0xC5, 0x39, 0x25, 0xBE, 0x1A, 0x80, 0xF8, 0x79, 0xEC, 0x93 };
4687 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 };
4689 SymmetricAlgorithm algo = Rijndael.Create ();
4690 algo.Mode = CipherMode.ECB;
4691 algo.Padding = PaddingMode.None;
4692 algo.BlockSize = 128;
4693 int blockLength = (algo.BlockSize >> 3);
4694 byte[] input = new byte [blockLength * 2];
4695 byte[] output = new byte [blockLength * 3];
4696 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4697 Encrypt (encryptor, input, output);
4698 AssertEquals ("Rijndael_k256b128_ECB_None Encrypt", expected, output);
4700 // in ECB the first 2 blocks should be equals (as the IV is not used)
4701 byte[] block1 = new byte[blockLength];
4702 Array.Copy (output, 0, block1, 0, blockLength);
4703 byte[] block2 = new byte[blockLength];
4704 Array.Copy (output, blockLength, block2, 0, blockLength);
4705 AssertEquals ("Rijndael_k256b128_ECB_None b1==b2", block1, block2);
4706 byte[] reverse = new byte [blockLength * 3];
4707 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4708 Decrypt (decryptor, output, reverse);
4709 byte[] original = new byte [input.Length];
4710 Array.Copy (reverse, 0, original, 0, original.Length);
4711 AssertEquals ("Rijndael_k256b128_ECB_None Decrypt", input, original);
4715 public void TestRijndael_k256b128_ECB_Zeros ()
4717 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 };
4718 // not used for ECB but make the code more uniform
4719 byte[] iv = { 0x48, 0xEC, 0x4A, 0x12, 0xAC, 0x9C, 0xB5, 0x72, 0xEB, 0x12, 0x14, 0xFB, 0xE1, 0x6D, 0xCF, 0xA3 };
4720 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 };
4722 SymmetricAlgorithm algo = Rijndael.Create ();
4723 algo.Mode = CipherMode.ECB;
4724 algo.Padding = PaddingMode.Zeros;
4725 algo.BlockSize = 128;
4726 int blockLength = (algo.BlockSize >> 3);
4727 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4728 byte[] output = new byte [blockLength * 3];
4729 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4730 // some exception can be normal... other not so!
4732 Encrypt (encryptor, input, output);
4734 catch (Exception e) {
4735 if (e.Message != "Input buffer contains insufficient data. ")
4736 Fail ("Rijndael_k256b128_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
4741 public void TestRijndael_k256b128_ECB_PKCS7 ()
4743 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 };
4744 // not used for ECB but make the code more uniform
4745 byte[] iv = { 0xCF, 0x8D, 0xBE, 0xE0, 0x41, 0xC6, 0xB9, 0xB5, 0x2D, 0x8A, 0x59, 0x92, 0x82, 0xF4, 0xE8, 0x74 };
4746 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 };
4748 SymmetricAlgorithm algo = Rijndael.Create ();
4749 algo.Mode = CipherMode.ECB;
4750 algo.Padding = PaddingMode.PKCS7;
4751 algo.BlockSize = 128;
4752 int blockLength = (algo.BlockSize >> 3);
4753 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4754 byte[] output = new byte [blockLength * 3];
4755 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4756 Encrypt (encryptor, input, output);
4757 AssertEquals ("Rijndael_k256b128_ECB_PKCS7 Encrypt", expected, output);
4759 // in ECB the first 2 blocks should be equals (as the IV is not used)
4760 byte[] block1 = new byte[blockLength];
4761 Array.Copy (output, 0, block1, 0, blockLength);
4762 byte[] block2 = new byte[blockLength];
4763 Array.Copy (output, blockLength, block2, 0, blockLength);
4764 AssertEquals ("Rijndael_k256b128_ECB_PKCS7 b1==b2", block1, block2);
4765 byte[] reverse = new byte [blockLength * 3];
4766 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4767 Decrypt (decryptor, output, reverse);
4768 byte[] original = new byte [input.Length];
4769 Array.Copy (reverse, 0, original, 0, original.Length);
4770 AssertEquals ("Rijndael_k256b128_ECB_PKCS7 Decrypt", input, original);
4774 public void TestRijndael_k256b128_CBC_None ()
4776 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 };
4777 byte[] iv = { 0x15, 0x7E, 0xA5, 0xE5, 0x47, 0xFA, 0x40, 0x30, 0x0A, 0xAA, 0x9E, 0x68, 0x8E, 0x4D, 0x2D, 0xA4 };
4778 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 };
4780 SymmetricAlgorithm algo = Rijndael.Create ();
4781 algo.Mode = CipherMode.CBC;
4782 algo.Padding = PaddingMode.None;
4783 algo.BlockSize = 128;
4784 int blockLength = (algo.BlockSize >> 3);
4785 byte[] input = new byte [blockLength * 2];
4786 byte[] output = new byte [blockLength * 3];
4787 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4788 Encrypt (encryptor, input, output);
4789 AssertEquals ("Rijndael_k256b128_CBC_None Encrypt", expected, output);
4790 byte[] reverse = new byte [blockLength * 3];
4791 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4792 Decrypt (decryptor, output, reverse);
4793 byte[] original = new byte [input.Length];
4794 Array.Copy (reverse, 0, original, 0, original.Length);
4795 AssertEquals ("Rijndael_k256b128_CBC_None Decrypt", input, original);
4799 public void TestRijndael_k256b128_CBC_Zeros ()
4801 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 };
4802 byte[] iv = { 0x32, 0x9B, 0x60, 0xF7, 0xBE, 0x0F, 0x5F, 0xA5, 0xD2, 0x7A, 0x1F, 0xB4, 0x01, 0x76, 0xD1, 0xCD };
4803 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 };
4805 SymmetricAlgorithm algo = Rijndael.Create ();
4806 algo.Mode = CipherMode.CBC;
4807 algo.Padding = PaddingMode.Zeros;
4808 algo.BlockSize = 128;
4809 int blockLength = (algo.BlockSize >> 3);
4810 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4811 byte[] output = new byte [blockLength * 3];
4812 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4813 // some exception can be normal... other not so!
4815 Encrypt (encryptor, input, output);
4817 catch (Exception e) {
4818 if (e.Message != "Input buffer contains insufficient data. ")
4819 Fail ("Rijndael_k256b128_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
4824 public void TestRijndael_k256b128_CBC_PKCS7 ()
4826 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 };
4827 byte[] iv = { 0xA0, 0xF5, 0x25, 0xE5, 0x17, 0xEA, 0x37, 0x18, 0x17, 0x56, 0x26, 0x1C, 0x63, 0x95, 0xC3, 0xAD };
4828 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 };
4830 SymmetricAlgorithm algo = Rijndael.Create ();
4831 algo.Mode = CipherMode.CBC;
4832 algo.Padding = PaddingMode.PKCS7;
4833 algo.BlockSize = 128;
4834 int blockLength = (algo.BlockSize >> 3);
4835 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4836 byte[] output = new byte [blockLength * 3];
4837 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4838 Encrypt (encryptor, input, output);
4839 AssertEquals ("Rijndael_k256b128_CBC_PKCS7 Encrypt", expected, output);
4840 byte[] reverse = new byte [blockLength * 3];
4841 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4842 Decrypt (decryptor, output, reverse);
4843 byte[] original = new byte [input.Length];
4844 Array.Copy (reverse, 0, original, 0, original.Length);
4845 AssertEquals ("Rijndael_k256b128_CBC_PKCS7 Decrypt", input, original);
4849 /* Invalid parameters Rijndael_k256b128_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
4851 /* Invalid parameters Rijndael_k256b128_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
4853 /* Invalid parameters Rijndael_k256b128_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
4855 /* Invalid parameters Rijndael_k256b128_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
4857 /* Invalid parameters Rijndael_k256b128_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
4859 /* Invalid parameters Rijndael_k256b128_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
4861 /* Invalid parameters Rijndael_k256b128_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
4863 /* Invalid parameters Rijndael_k256b128_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
4865 /* Invalid parameters Rijndael_k256b128_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
4867 public void TestRijndael_k256b192_ECB_None ()
4869 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 };
4870 // not used for ECB but make the code more uniform
4871 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 };
4872 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 };
4874 SymmetricAlgorithm algo = Rijndael.Create ();
4875 algo.Mode = CipherMode.ECB;
4876 algo.Padding = PaddingMode.None;
4877 algo.BlockSize = 192;
4878 int blockLength = (algo.BlockSize >> 3);
4879 byte[] input = new byte [blockLength * 2];
4880 byte[] output = new byte [blockLength * 3];
4881 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4882 Encrypt (encryptor, input, output);
4883 AssertEquals ("Rijndael_k256b192_ECB_None Encrypt", expected, output);
4885 // in ECB the first 2 blocks should be equals (as the IV is not used)
4886 byte[] block1 = new byte[blockLength];
4887 Array.Copy (output, 0, block1, 0, blockLength);
4888 byte[] block2 = new byte[blockLength];
4889 Array.Copy (output, blockLength, block2, 0, blockLength);
4890 AssertEquals ("Rijndael_k256b192_ECB_None b1==b2", block1, block2);
4891 byte[] reverse = new byte [blockLength * 3];
4892 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4893 Decrypt (decryptor, output, reverse);
4894 byte[] original = new byte [input.Length];
4895 Array.Copy (reverse, 0, original, 0, original.Length);
4896 AssertEquals ("Rijndael_k256b192_ECB_None Decrypt", input, original);
4900 public void TestRijndael_k256b192_ECB_Zeros ()
4902 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 };
4903 // not used for ECB but make the code more uniform
4904 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 };
4905 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 };
4907 SymmetricAlgorithm algo = Rijndael.Create ();
4908 algo.Mode = CipherMode.ECB;
4909 algo.Padding = PaddingMode.Zeros;
4910 algo.BlockSize = 192;
4911 int blockLength = (algo.BlockSize >> 3);
4912 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4913 byte[] output = new byte [blockLength * 3];
4914 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4915 // some exception can be normal... other not so!
4917 Encrypt (encryptor, input, output);
4919 catch (Exception e) {
4920 if (e.Message != "Input buffer contains insufficient data. ")
4921 Fail ("Rijndael_k256b192_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
4926 public void TestRijndael_k256b192_ECB_PKCS7 ()
4928 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 };
4929 // not used for ECB but make the code more uniform
4930 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 };
4931 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 };
4933 SymmetricAlgorithm algo = Rijndael.Create ();
4934 algo.Mode = CipherMode.ECB;
4935 algo.Padding = PaddingMode.PKCS7;
4936 algo.BlockSize = 192;
4937 int blockLength = (algo.BlockSize >> 3);
4938 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
4939 byte[] output = new byte [blockLength * 3];
4940 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4941 Encrypt (encryptor, input, output);
4942 AssertEquals ("Rijndael_k256b192_ECB_PKCS7 Encrypt", expected, output);
4944 // in ECB the first 2 blocks should be equals (as the IV is not used)
4945 byte[] block1 = new byte[blockLength];
4946 Array.Copy (output, 0, block1, 0, blockLength);
4947 byte[] block2 = new byte[blockLength];
4948 Array.Copy (output, blockLength, block2, 0, blockLength);
4949 AssertEquals ("Rijndael_k256b192_ECB_PKCS7 b1==b2", block1, block2);
4950 byte[] reverse = new byte [blockLength * 3];
4951 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4952 Decrypt (decryptor, output, reverse);
4953 byte[] original = new byte [input.Length];
4954 Array.Copy (reverse, 0, original, 0, original.Length);
4955 AssertEquals ("Rijndael_k256b192_ECB_PKCS7 Decrypt", input, original);
4959 public void TestRijndael_k256b192_CBC_None ()
4961 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 };
4962 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 };
4963 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 };
4965 SymmetricAlgorithm algo = Rijndael.Create ();
4966 algo.Mode = CipherMode.CBC;
4967 algo.Padding = PaddingMode.None;
4968 algo.BlockSize = 192;
4969 int blockLength = (algo.BlockSize >> 3);
4970 byte[] input = new byte [blockLength * 2];
4971 byte[] output = new byte [blockLength * 3];
4972 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
4973 Encrypt (encryptor, input, output);
4974 AssertEquals ("Rijndael_k256b192_CBC_None Encrypt", expected, output);
4975 byte[] reverse = new byte [blockLength * 3];
4976 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
4977 Decrypt (decryptor, output, reverse);
4978 byte[] original = new byte [input.Length];
4979 Array.Copy (reverse, 0, original, 0, original.Length);
4980 AssertEquals ("Rijndael_k256b192_CBC_None Decrypt", input, original);
4984 public void TestRijndael_k256b192_CBC_Zeros ()
4986 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 };
4987 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 };
4988 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 };
4990 SymmetricAlgorithm algo = Rijndael.Create ();
4991 algo.Mode = CipherMode.CBC;
4992 algo.Padding = PaddingMode.Zeros;
4993 algo.BlockSize = 192;
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 // some exception can be normal... other not so!
5000 Encrypt (encryptor, input, output);
5002 catch (Exception e) {
5003 if (e.Message != "Input buffer contains insufficient data. ")
5004 Fail ("Rijndael_k256b192_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
5009 public void TestRijndael_k256b192_CBC_PKCS7 ()
5011 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 };
5012 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 };
5013 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 };
5015 SymmetricAlgorithm algo = Rijndael.Create ();
5016 algo.Mode = CipherMode.CBC;
5017 algo.Padding = PaddingMode.PKCS7;
5018 algo.BlockSize = 192;
5019 int blockLength = (algo.BlockSize >> 3);
5020 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5021 byte[] output = new byte [blockLength * 3];
5022 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5023 Encrypt (encryptor, input, output);
5024 AssertEquals ("Rijndael_k256b192_CBC_PKCS7 Encrypt", expected, output);
5025 byte[] reverse = new byte [blockLength * 3];
5026 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5027 Decrypt (decryptor, output, reverse);
5028 byte[] original = new byte [input.Length];
5029 Array.Copy (reverse, 0, original, 0, original.Length);
5030 AssertEquals ("Rijndael_k256b192_CBC_PKCS7 Decrypt", input, original);
5034 /* Invalid parameters Rijndael_k256b192_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
5036 /* Invalid parameters Rijndael_k256b192_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
5038 /* Invalid parameters Rijndael_k256b192_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
5040 /* Invalid parameters Rijndael_k256b192_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
5042 /* Invalid parameters Rijndael_k256b192_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
5044 /* Invalid parameters Rijndael_k256b192_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
5046 /* Invalid parameters Rijndael_k256b192_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
5048 /* Invalid parameters Rijndael_k256b192_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
5050 /* Invalid parameters Rijndael_k256b192_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
5052 public void TestRijndael_k256b256_ECB_None ()
5054 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 };
5055 // not used for ECB but make the code more uniform
5056 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 };
5057 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 };
5059 SymmetricAlgorithm algo = Rijndael.Create ();
5060 algo.Mode = CipherMode.ECB;
5061 algo.Padding = PaddingMode.None;
5062 algo.BlockSize = 256;
5063 int blockLength = (algo.BlockSize >> 3);
5064 byte[] input = new byte [blockLength * 2];
5065 byte[] output = new byte [blockLength * 3];
5066 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5067 Encrypt (encryptor, input, output);
5068 AssertEquals ("Rijndael_k256b256_ECB_None Encrypt", expected, output);
5070 // in ECB the first 2 blocks should be equals (as the IV is not used)
5071 byte[] block1 = new byte[blockLength];
5072 Array.Copy (output, 0, block1, 0, blockLength);
5073 byte[] block2 = new byte[blockLength];
5074 Array.Copy (output, blockLength, block2, 0, blockLength);
5075 AssertEquals ("Rijndael_k256b256_ECB_None b1==b2", block1, block2);
5076 byte[] reverse = new byte [blockLength * 3];
5077 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5078 Decrypt (decryptor, output, reverse);
5079 byte[] original = new byte [input.Length];
5080 Array.Copy (reverse, 0, original, 0, original.Length);
5081 AssertEquals ("Rijndael_k256b256_ECB_None Decrypt", input, original);
5085 public void TestRijndael_k256b256_ECB_Zeros ()
5087 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 };
5088 // not used for ECB but make the code more uniform
5089 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 };
5090 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 };
5092 SymmetricAlgorithm algo = Rijndael.Create ();
5093 algo.Mode = CipherMode.ECB;
5094 algo.Padding = PaddingMode.Zeros;
5095 algo.BlockSize = 256;
5096 int blockLength = (algo.BlockSize >> 3);
5097 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5098 byte[] output = new byte [blockLength * 3];
5099 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5100 // some exception can be normal... other not so!
5102 Encrypt (encryptor, input, output);
5104 catch (Exception e) {
5105 if (e.Message != "Input buffer contains insufficient data. ")
5106 Fail ("Rijndael_k256b256_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
5111 public void TestRijndael_k256b256_ECB_PKCS7 ()
5113 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 };
5114 // not used for ECB but make the code more uniform
5115 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 };
5116 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 };
5118 SymmetricAlgorithm algo = Rijndael.Create ();
5119 algo.Mode = CipherMode.ECB;
5120 algo.Padding = PaddingMode.PKCS7;
5121 algo.BlockSize = 256;
5122 int blockLength = (algo.BlockSize >> 3);
5123 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5124 byte[] output = new byte [blockLength * 3];
5125 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5126 Encrypt (encryptor, input, output);
5127 AssertEquals ("Rijndael_k256b256_ECB_PKCS7 Encrypt", expected, output);
5129 // in ECB the first 2 blocks should be equals (as the IV is not used)
5130 byte[] block1 = new byte[blockLength];
5131 Array.Copy (output, 0, block1, 0, blockLength);
5132 byte[] block2 = new byte[blockLength];
5133 Array.Copy (output, blockLength, block2, 0, blockLength);
5134 AssertEquals ("Rijndael_k256b256_ECB_PKCS7 b1==b2", block1, block2);
5135 byte[] reverse = new byte [blockLength * 3];
5136 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5137 Decrypt (decryptor, output, reverse);
5138 byte[] original = new byte [input.Length];
5139 Array.Copy (reverse, 0, original, 0, original.Length);
5140 AssertEquals ("Rijndael_k256b256_ECB_PKCS7 Decrypt", input, original);
5144 public void TestRijndael_k256b256_CBC_None ()
5146 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 };
5147 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 };
5148 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 };
5150 SymmetricAlgorithm algo = Rijndael.Create ();
5151 algo.Mode = CipherMode.CBC;
5152 algo.Padding = PaddingMode.None;
5153 algo.BlockSize = 256;
5154 int blockLength = (algo.BlockSize >> 3);
5155 byte[] input = new byte [blockLength * 2];
5156 byte[] output = new byte [blockLength * 3];
5157 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5158 Encrypt (encryptor, input, output);
5159 AssertEquals ("Rijndael_k256b256_CBC_None Encrypt", expected, output);
5160 byte[] reverse = new byte [blockLength * 3];
5161 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5162 Decrypt (decryptor, output, reverse);
5163 byte[] original = new byte [input.Length];
5164 Array.Copy (reverse, 0, original, 0, original.Length);
5165 AssertEquals ("Rijndael_k256b256_CBC_None Decrypt", input, original);
5169 public void TestRijndael_k256b256_CBC_Zeros ()
5171 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 };
5172 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 };
5173 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 };
5175 SymmetricAlgorithm algo = Rijndael.Create ();
5176 algo.Mode = CipherMode.CBC;
5177 algo.Padding = PaddingMode.Zeros;
5178 algo.BlockSize = 256;
5179 int blockLength = (algo.BlockSize >> 3);
5180 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5181 byte[] output = new byte [blockLength * 3];
5182 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5183 // some exception can be normal... other not so!
5185 Encrypt (encryptor, input, output);
5187 catch (Exception e) {
5188 if (e.Message != "Input buffer contains insufficient data. ")
5189 Fail ("Rijndael_k256b256_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
5194 public void TestRijndael_k256b256_CBC_PKCS7 ()
5196 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 };
5197 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 };
5198 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 };
5200 SymmetricAlgorithm algo = Rijndael.Create ();
5201 algo.Mode = CipherMode.CBC;
5202 algo.Padding = PaddingMode.PKCS7;
5203 algo.BlockSize = 256;
5204 int blockLength = (algo.BlockSize >> 3);
5205 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5206 byte[] output = new byte [blockLength * 3];
5207 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5208 Encrypt (encryptor, input, output);
5209 AssertEquals ("Rijndael_k256b256_CBC_PKCS7 Encrypt", expected, output);
5210 byte[] reverse = new byte [blockLength * 3];
5211 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5212 Decrypt (decryptor, output, reverse);
5213 byte[] original = new byte [input.Length];
5214 Array.Copy (reverse, 0, original, 0, original.Length);
5215 AssertEquals ("Rijndael_k256b256_CBC_PKCS7 Decrypt", input, original);
5219 /* Invalid parameters Rijndael_k256b256_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
5221 /* Invalid parameters Rijndael_k256b256_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
5223 /* Invalid parameters Rijndael_k256b256_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
5225 /* Invalid parameters Rijndael_k256b256_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
5227 /* Invalid parameters Rijndael_k256b256_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
5229 /* Invalid parameters Rijndael_k256b256_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
5231 /* Invalid parameters Rijndael_k256b256_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
5233 /* Invalid parameters Rijndael_k256b256_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
5235 /* Invalid parameters Rijndael_k256b256_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
5237 public void TestTripleDES_k128b64_ECB_None ()
5239 byte[] key = { 0x31, 0x29, 0x5A, 0x2D, 0x18, 0xDF, 0x78, 0xB1, 0xB3, 0x30, 0xB4, 0x2E, 0x08, 0x2A, 0xB5, 0x00 };
5240 // not used for ECB but make the code more uniform
5241 byte[] iv = { 0xDE, 0x87, 0xFF, 0xA6, 0x30, 0x76, 0x39, 0x89 };
5242 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 };
5244 SymmetricAlgorithm algo = TripleDES.Create ();
5245 algo.Mode = CipherMode.ECB;
5246 algo.Padding = PaddingMode.None;
5247 algo.BlockSize = 64;
5248 int blockLength = (algo.BlockSize >> 3);
5249 byte[] input = new byte [blockLength * 2];
5250 byte[] output = new byte [blockLength * 3];
5251 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5252 Encrypt (encryptor, input, output);
5253 AssertEquals ("TripleDES_k128b64_ECB_None Encrypt", expected, output);
5255 // in ECB the first 2 blocks should be equals (as the IV is not used)
5256 byte[] block1 = new byte[blockLength];
5257 Array.Copy (output, 0, block1, 0, blockLength);
5258 byte[] block2 = new byte[blockLength];
5259 Array.Copy (output, blockLength, block2, 0, blockLength);
5260 AssertEquals ("TripleDES_k128b64_ECB_None b1==b2", block1, block2);
5261 byte[] reverse = new byte [blockLength * 3];
5262 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5263 Decrypt (decryptor, output, reverse);
5264 byte[] original = new byte [input.Length];
5265 Array.Copy (reverse, 0, original, 0, original.Length);
5266 AssertEquals ("TripleDES_k128b64_ECB_None Decrypt", input, original);
5270 public void TestTripleDES_k128b64_ECB_Zeros ()
5272 byte[] key = { 0xFB, 0xC1, 0xA8, 0x04, 0x47, 0x10, 0x09, 0x09, 0xA8, 0x3D, 0x97, 0x18, 0x11, 0x3C, 0x28, 0x80 };
5273 // not used for ECB but make the code more uniform
5274 byte[] iv = { 0xA2, 0x1F, 0x63, 0x49, 0x33, 0xCA, 0xEE, 0xDA };
5275 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 };
5277 SymmetricAlgorithm algo = TripleDES.Create ();
5278 algo.Mode = CipherMode.ECB;
5279 algo.Padding = PaddingMode.Zeros;
5280 algo.BlockSize = 64;
5281 int blockLength = (algo.BlockSize >> 3);
5282 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5283 byte[] output = new byte [blockLength * 3];
5284 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5285 Encrypt (encryptor, input, output);
5286 AssertEquals ("TripleDES_k128b64_ECB_Zeros Encrypt", expected, output);
5288 // in ECB the first 2 blocks should be equals (as the IV is not used)
5289 byte[] block1 = new byte[blockLength];
5290 Array.Copy (output, 0, block1, 0, blockLength);
5291 byte[] block2 = new byte[blockLength];
5292 Array.Copy (output, blockLength, block2, 0, blockLength);
5293 AssertEquals ("TripleDES_k128b64_ECB_Zeros b1==b2", block1, block2);
5295 // also if padding is Zeros then all three blocks should be equals
5296 byte[] block3 = new byte[blockLength];
5297 Array.Copy (output, blockLength, block3, 0, blockLength);
5298 AssertEquals ("TripleDES_k128b64_ECB_Zeros b1==b3", block1, block3);
5300 byte[] reverse = new byte [blockLength * 3];
5301 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5302 Decrypt (decryptor, output, reverse);
5303 byte[] original = new byte [input.Length];
5304 Array.Copy (reverse, 0, original, 0, original.Length);
5305 AssertEquals ("TripleDES_k128b64_ECB_Zeros Decrypt", input, original);
5309 public void TestTripleDES_k128b64_ECB_PKCS7 ()
5311 byte[] key = { 0x78, 0x52, 0xAE, 0x73, 0x24, 0x0A, 0xDF, 0x80, 0x1A, 0xDE, 0x32, 0x90, 0x3C, 0x01, 0xBA, 0x12 };
5312 // not used for ECB but make the code more uniform
5313 byte[] iv = { 0xF6, 0x11, 0x79, 0x5E, 0xEC, 0xDC, 0x5E, 0x19 };
5314 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 };
5316 SymmetricAlgorithm algo = TripleDES.Create ();
5317 algo.Mode = CipherMode.ECB;
5318 algo.Padding = PaddingMode.PKCS7;
5319 algo.BlockSize = 64;
5320 int blockLength = (algo.BlockSize >> 3);
5321 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5322 byte[] output = new byte [blockLength * 3];
5323 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5324 Encrypt (encryptor, input, output);
5325 AssertEquals ("TripleDES_k128b64_ECB_PKCS7 Encrypt", expected, output);
5327 // in ECB the first 2 blocks should be equals (as the IV is not used)
5328 byte[] block1 = new byte[blockLength];
5329 Array.Copy (output, 0, block1, 0, blockLength);
5330 byte[] block2 = new byte[blockLength];
5331 Array.Copy (output, blockLength, block2, 0, blockLength);
5332 AssertEquals ("TripleDES_k128b64_ECB_PKCS7 b1==b2", block1, block2);
5333 byte[] reverse = new byte [blockLength * 3];
5334 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5335 Decrypt (decryptor, output, reverse);
5336 byte[] original = new byte [input.Length];
5337 Array.Copy (reverse, 0, original, 0, original.Length);
5338 AssertEquals ("TripleDES_k128b64_ECB_PKCS7 Decrypt", input, original);
5342 public void TestTripleDES_k128b64_CBC_None ()
5344 byte[] key = { 0x9B, 0x97, 0x95, 0xA2, 0x6D, 0x90, 0x1D, 0xAE, 0xE8, 0xFC, 0xA1, 0xA2, 0x06, 0x6E, 0x75, 0xE8 };
5345 byte[] iv = { 0x52, 0xF8, 0x0E, 0xA9, 0x8C, 0xD9, 0x46, 0x63 };
5346 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 };
5348 SymmetricAlgorithm algo = TripleDES.Create ();
5349 algo.Mode = CipherMode.CBC;
5350 algo.Padding = PaddingMode.None;
5351 algo.BlockSize = 64;
5352 int blockLength = (algo.BlockSize >> 3);
5353 byte[] input = new byte [blockLength * 2];
5354 byte[] output = new byte [blockLength * 3];
5355 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5356 Encrypt (encryptor, input, output);
5357 AssertEquals ("TripleDES_k128b64_CBC_None Encrypt", expected, output);
5358 byte[] reverse = new byte [blockLength * 3];
5359 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5360 Decrypt (decryptor, output, reverse);
5361 byte[] original = new byte [input.Length];
5362 Array.Copy (reverse, 0, original, 0, original.Length);
5363 AssertEquals ("TripleDES_k128b64_CBC_None Decrypt", input, original);
5367 public void TestTripleDES_k128b64_CBC_Zeros ()
5369 byte[] key = { 0x21, 0x87, 0x57, 0xF4, 0xE5, 0xE9, 0x91, 0xC7, 0x3A, 0x64, 0x14, 0xF2, 0x2B, 0x06, 0x0E, 0x2E };
5370 byte[] iv = { 0x23, 0x86, 0x58, 0x7B, 0x49, 0x23, 0xF6, 0x7F };
5371 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 };
5373 SymmetricAlgorithm algo = TripleDES.Create ();
5374 algo.Mode = CipherMode.CBC;
5375 algo.Padding = PaddingMode.Zeros;
5376 algo.BlockSize = 64;
5377 int blockLength = (algo.BlockSize >> 3);
5378 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5379 byte[] output = new byte [blockLength * 3];
5380 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5381 Encrypt (encryptor, input, output);
5382 AssertEquals ("TripleDES_k128b64_CBC_Zeros Encrypt", expected, output);
5383 byte[] reverse = new byte [blockLength * 3];
5384 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5385 Decrypt (decryptor, output, reverse);
5386 byte[] original = new byte [input.Length];
5387 Array.Copy (reverse, 0, original, 0, original.Length);
5388 AssertEquals ("TripleDES_k128b64_CBC_Zeros Decrypt", input, original);
5392 public void TestTripleDES_k128b64_CBC_PKCS7 ()
5394 byte[] key = { 0x06, 0x33, 0x4B, 0x5A, 0xF0, 0xC6, 0xAE, 0x71, 0x8C, 0x41, 0xB3, 0x72, 0x43, 0x4B, 0x82, 0x31 };
5395 byte[] iv = { 0x40, 0x7F, 0x60, 0x5B, 0x5C, 0x22, 0x8D, 0x5D };
5396 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 };
5398 SymmetricAlgorithm algo = TripleDES.Create ();
5399 algo.Mode = CipherMode.CBC;
5400 algo.Padding = PaddingMode.PKCS7;
5401 algo.BlockSize = 64;
5402 int blockLength = (algo.BlockSize >> 3);
5403 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5404 byte[] output = new byte [blockLength * 3];
5405 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5406 Encrypt (encryptor, input, output);
5407 AssertEquals ("TripleDES_k128b64_CBC_PKCS7 Encrypt", expected, output);
5408 byte[] reverse = new byte [blockLength * 3];
5409 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5410 Decrypt (decryptor, output, reverse);
5411 byte[] original = new byte [input.Length];
5412 Array.Copy (reverse, 0, original, 0, original.Length);
5413 AssertEquals ("TripleDES_k128b64_CBC_PKCS7 Decrypt", input, original);
5417 /* Invalid parameters TripleDES_k128b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
5419 /* Invalid parameters TripleDES_k128b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
5421 /* Invalid parameters TripleDES_k128b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
5423 public void TestTripleDES_k128b64_CFB8_None ()
5425 byte[] key = { 0x49, 0x9D, 0x94, 0x9C, 0x79, 0xD9, 0xEE, 0x92, 0x75, 0xE8, 0x8C, 0x78, 0xE3, 0xB5, 0x49, 0x81 };
5426 byte[] iv = { 0x80, 0x0A, 0x45, 0x55, 0xCB, 0xC7, 0x17, 0xA1 };
5427 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 };
5429 SymmetricAlgorithm algo = TripleDES.Create ();
5430 algo.Mode = CipherMode.CFB;
5431 algo.Padding = PaddingMode.None;
5432 algo.BlockSize = 64;
5433 algo.FeedbackSize = 8;
5434 int blockLength = (algo.BlockSize >> 3);
5435 byte[] input = new byte [blockLength * 2];
5436 byte[] output = new byte [blockLength * 3];
5437 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5438 Encrypt (encryptor, input, output);
5439 AssertEquals ("TripleDES_k128b64_CFB8_None Encrypt", expected, output);
5440 byte[] reverse = new byte [blockLength * 3];
5441 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5442 Decrypt (decryptor, output, reverse);
5443 byte[] original = new byte [input.Length];
5444 Array.Copy (reverse, 0, original, 0, original.Length);
5445 AssertEquals ("TripleDES_k128b64_CFB8_None Decrypt", input, original);
5449 public void TestTripleDES_k128b64_CFB8_Zeros ()
5451 byte[] key = { 0x47, 0xD4, 0x00, 0xC6, 0x0B, 0xCE, 0x0D, 0x6B, 0xD6, 0xEB, 0xBF, 0x74, 0xE3, 0xB9, 0x61, 0x14 };
5452 byte[] iv = { 0x63, 0xB1, 0xCE, 0xEF, 0x06, 0x14, 0xD6, 0x4B };
5453 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 };
5455 SymmetricAlgorithm algo = TripleDES.Create ();
5456 algo.Mode = CipherMode.CFB;
5457 algo.Padding = PaddingMode.Zeros;
5458 algo.BlockSize = 64;
5459 algo.FeedbackSize = 8;
5460 int blockLength = (algo.BlockSize >> 3);
5461 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5462 byte[] output = new byte [blockLength * 3];
5463 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5464 Encrypt (encryptor, input, output);
5465 AssertEquals ("TripleDES_k128b64_CFB8_Zeros Encrypt", expected, output);
5466 byte[] reverse = new byte [blockLength * 3];
5467 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5468 Decrypt (decryptor, output, reverse);
5469 byte[] original = new byte [input.Length];
5470 Array.Copy (reverse, 0, original, 0, original.Length);
5471 AssertEquals ("TripleDES_k128b64_CFB8_Zeros Decrypt", input, original);
5475 public void TestTripleDES_k128b64_CFB8_PKCS7 ()
5477 byte[] key = { 0x70, 0x9E, 0x39, 0x1A, 0x45, 0xA4, 0x18, 0x30, 0xAC, 0xE6, 0x1E, 0x0E, 0xD7, 0x43, 0x39, 0x5F };
5478 byte[] iv = { 0x26, 0xF3, 0x46, 0x6A, 0x35, 0xC8, 0xBF, 0x03 };
5479 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 };
5481 SymmetricAlgorithm algo = TripleDES.Create ();
5482 algo.Mode = CipherMode.CFB;
5483 algo.Padding = PaddingMode.PKCS7;
5484 algo.BlockSize = 64;
5485 algo.FeedbackSize = 8;
5486 int blockLength = (algo.BlockSize >> 3);
5487 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5488 byte[] output = new byte [blockLength * 3];
5489 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5490 Encrypt (encryptor, input, output);
5491 AssertEquals ("TripleDES_k128b64_CFB8_PKCS7 Encrypt", expected, output);
5492 byte[] reverse = new byte [blockLength * 3];
5493 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5494 Decrypt (decryptor, output, reverse);
5495 byte[] original = new byte [input.Length];
5496 Array.Copy (reverse, 0, original, 0, original.Length);
5497 AssertEquals ("TripleDES_k128b64_CFB8_PKCS7 Decrypt", input, original);
5501 /* Invalid parameters TripleDES_k128b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
5503 /* Invalid parameters TripleDES_k128b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
5505 /* Invalid parameters TripleDES_k128b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
5507 public void TestTripleDES_k192b64_ECB_None ()
5509 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 };
5510 // not used for ECB but make the code more uniform
5511 byte[] iv = { 0x13, 0xBF, 0xF3, 0xA0, 0xD3, 0xA1, 0x2F, 0x23 };
5512 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 };
5514 SymmetricAlgorithm algo = TripleDES.Create ();
5515 algo.Mode = CipherMode.ECB;
5516 algo.Padding = PaddingMode.None;
5517 algo.BlockSize = 64;
5518 int blockLength = (algo.BlockSize >> 3);
5519 byte[] input = new byte [blockLength * 2];
5520 byte[] output = new byte [blockLength * 3];
5521 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5522 Encrypt (encryptor, input, output);
5523 AssertEquals ("TripleDES_k192b64_ECB_None Encrypt", expected, output);
5525 // in ECB the first 2 blocks should be equals (as the IV is not used)
5526 byte[] block1 = new byte[blockLength];
5527 Array.Copy (output, 0, block1, 0, blockLength);
5528 byte[] block2 = new byte[blockLength];
5529 Array.Copy (output, blockLength, block2, 0, blockLength);
5530 AssertEquals ("TripleDES_k192b64_ECB_None b1==b2", block1, block2);
5531 byte[] reverse = new byte [blockLength * 3];
5532 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5533 Decrypt (decryptor, output, reverse);
5534 byte[] original = new byte [input.Length];
5535 Array.Copy (reverse, 0, original, 0, original.Length);
5536 AssertEquals ("TripleDES_k192b64_ECB_None Decrypt", input, original);
5540 public void TestTripleDES_k192b64_ECB_Zeros ()
5542 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 };
5543 // not used for ECB but make the code more uniform
5544 byte[] iv = { 0xF6, 0xC5, 0xBD, 0xA2, 0x4D, 0xA8, 0x19, 0x78 };
5545 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 };
5547 SymmetricAlgorithm algo = TripleDES.Create ();
5548 algo.Mode = CipherMode.ECB;
5549 algo.Padding = PaddingMode.Zeros;
5550 algo.BlockSize = 64;
5551 int blockLength = (algo.BlockSize >> 3);
5552 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5553 byte[] output = new byte [blockLength * 3];
5554 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5555 Encrypt (encryptor, input, output);
5556 AssertEquals ("TripleDES_k192b64_ECB_Zeros Encrypt", expected, output);
5558 // in ECB the first 2 blocks should be equals (as the IV is not used)
5559 byte[] block1 = new byte[blockLength];
5560 Array.Copy (output, 0, block1, 0, blockLength);
5561 byte[] block2 = new byte[blockLength];
5562 Array.Copy (output, blockLength, block2, 0, blockLength);
5563 AssertEquals ("TripleDES_k192b64_ECB_Zeros b1==b2", block1, block2);
5565 // also if padding is Zeros then all three blocks should be equals
5566 byte[] block3 = new byte[blockLength];
5567 Array.Copy (output, blockLength, block3, 0, blockLength);
5568 AssertEquals ("TripleDES_k192b64_ECB_Zeros b1==b3", block1, block3);
5570 byte[] reverse = new byte [blockLength * 3];
5571 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5572 Decrypt (decryptor, output, reverse);
5573 byte[] original = new byte [input.Length];
5574 Array.Copy (reverse, 0, original, 0, original.Length);
5575 AssertEquals ("TripleDES_k192b64_ECB_Zeros Decrypt", input, original);
5579 public void TestTripleDES_k192b64_ECB_PKCS7 ()
5581 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 };
5582 // not used for ECB but make the code more uniform
5583 byte[] iv = { 0xB0, 0x71, 0x70, 0xFC, 0x57, 0xC2, 0x26, 0xF9 };
5584 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 };
5586 SymmetricAlgorithm algo = TripleDES.Create ();
5587 algo.Mode = CipherMode.ECB;
5588 algo.Padding = PaddingMode.PKCS7;
5589 algo.BlockSize = 64;
5590 int blockLength = (algo.BlockSize >> 3);
5591 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5592 byte[] output = new byte [blockLength * 3];
5593 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5594 Encrypt (encryptor, input, output);
5595 AssertEquals ("TripleDES_k192b64_ECB_PKCS7 Encrypt", expected, output);
5597 // in ECB the first 2 blocks should be equals (as the IV is not used)
5598 byte[] block1 = new byte[blockLength];
5599 Array.Copy (output, 0, block1, 0, blockLength);
5600 byte[] block2 = new byte[blockLength];
5601 Array.Copy (output, blockLength, block2, 0, blockLength);
5602 AssertEquals ("TripleDES_k192b64_ECB_PKCS7 b1==b2", block1, block2);
5603 byte[] reverse = new byte [blockLength * 3];
5604 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5605 Decrypt (decryptor, output, reverse);
5606 byte[] original = new byte [input.Length];
5607 Array.Copy (reverse, 0, original, 0, original.Length);
5608 AssertEquals ("TripleDES_k192b64_ECB_PKCS7 Decrypt", input, original);
5612 public void TestTripleDES_k192b64_CBC_None ()
5614 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 };
5615 byte[] iv = { 0xBD, 0x69, 0xAC, 0xA6, 0xCF, 0x17, 0xFC, 0x8A };
5616 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 };
5618 SymmetricAlgorithm algo = TripleDES.Create ();
5619 algo.Mode = CipherMode.CBC;
5620 algo.Padding = PaddingMode.None;
5621 algo.BlockSize = 64;
5622 int blockLength = (algo.BlockSize >> 3);
5623 byte[] input = new byte [blockLength * 2];
5624 byte[] output = new byte [blockLength * 3];
5625 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5626 Encrypt (encryptor, input, output);
5627 AssertEquals ("TripleDES_k192b64_CBC_None Encrypt", expected, output);
5628 byte[] reverse = new byte [blockLength * 3];
5629 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5630 Decrypt (decryptor, output, reverse);
5631 byte[] original = new byte [input.Length];
5632 Array.Copy (reverse, 0, original, 0, original.Length);
5633 AssertEquals ("TripleDES_k192b64_CBC_None Decrypt", input, original);
5637 public void TestTripleDES_k192b64_CBC_Zeros ()
5639 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 };
5640 byte[] iv = { 0x09, 0x50, 0xF5, 0x6F, 0x18, 0xD1, 0x4C, 0x9E };
5641 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 };
5643 SymmetricAlgorithm algo = TripleDES.Create ();
5644 algo.Mode = CipherMode.CBC;
5645 algo.Padding = PaddingMode.Zeros;
5646 algo.BlockSize = 64;
5647 int blockLength = (algo.BlockSize >> 3);
5648 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5649 byte[] output = new byte [blockLength * 3];
5650 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5651 Encrypt (encryptor, input, output);
5652 AssertEquals ("TripleDES_k192b64_CBC_Zeros Encrypt", expected, output);
5653 byte[] reverse = new byte [blockLength * 3];
5654 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5655 Decrypt (decryptor, output, reverse);
5656 byte[] original = new byte [input.Length];
5657 Array.Copy (reverse, 0, original, 0, original.Length);
5658 AssertEquals ("TripleDES_k192b64_CBC_Zeros Decrypt", input, original);
5662 public void TestTripleDES_k192b64_CBC_PKCS7 ()
5664 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 };
5665 byte[] iv = { 0xF7, 0xD8, 0x8E, 0xB2, 0xC5, 0x5F, 0x49, 0x91 };
5666 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 };
5668 SymmetricAlgorithm algo = TripleDES.Create ();
5669 algo.Mode = CipherMode.CBC;
5670 algo.Padding = PaddingMode.PKCS7;
5671 algo.BlockSize = 64;
5672 int blockLength = (algo.BlockSize >> 3);
5673 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5674 byte[] output = new byte [blockLength * 3];
5675 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5676 Encrypt (encryptor, input, output);
5677 AssertEquals ("TripleDES_k192b64_CBC_PKCS7 Encrypt", expected, output);
5678 byte[] reverse = new byte [blockLength * 3];
5679 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5680 Decrypt (decryptor, output, reverse);
5681 byte[] original = new byte [input.Length];
5682 Array.Copy (reverse, 0, original, 0, original.Length);
5683 AssertEquals ("TripleDES_k192b64_CBC_PKCS7 Decrypt", input, original);
5687 /* Invalid parameters TripleDES_k192b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
5689 /* Invalid parameters TripleDES_k192b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
5691 /* Invalid parameters TripleDES_k192b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
5693 public void TestTripleDES_k192b64_CFB8_None ()
5695 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 };
5696 byte[] iv = { 0x2E, 0xF8, 0x02, 0x62, 0x15, 0xE2, 0x8F, 0xB1 };
5697 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 };
5699 SymmetricAlgorithm algo = TripleDES.Create ();
5700 algo.Mode = CipherMode.CFB;
5701 algo.Padding = PaddingMode.None;
5702 algo.BlockSize = 64;
5703 algo.FeedbackSize = 8;
5704 int blockLength = (algo.BlockSize >> 3);
5705 byte[] input = new byte [blockLength * 2];
5706 byte[] output = new byte [blockLength * 3];
5707 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5708 Encrypt (encryptor, input, output);
5709 AssertEquals ("TripleDES_k192b64_CFB8_None Encrypt", expected, output);
5710 byte[] reverse = new byte [blockLength * 3];
5711 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5712 Decrypt (decryptor, output, reverse);
5713 byte[] original = new byte [input.Length];
5714 Array.Copy (reverse, 0, original, 0, original.Length);
5715 AssertEquals ("TripleDES_k192b64_CFB8_None Decrypt", input, original);
5719 public void TestTripleDES_k192b64_CFB8_Zeros ()
5721 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 };
5722 byte[] iv = { 0xC0, 0x32, 0xAE, 0xA8, 0xEB, 0x67, 0x74, 0xC4 };
5723 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 };
5725 SymmetricAlgorithm algo = TripleDES.Create ();
5726 algo.Mode = CipherMode.CFB;
5727 algo.Padding = PaddingMode.Zeros;
5728 algo.BlockSize = 64;
5729 algo.FeedbackSize = 8;
5730 int blockLength = (algo.BlockSize >> 3);
5731 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5732 byte[] output = new byte [blockLength * 3];
5733 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5734 Encrypt (encryptor, input, output);
5735 AssertEquals ("TripleDES_k192b64_CFB8_Zeros Encrypt", expected, output);
5736 byte[] reverse = new byte [blockLength * 3];
5737 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5738 Decrypt (decryptor, output, reverse);
5739 byte[] original = new byte [input.Length];
5740 Array.Copy (reverse, 0, original, 0, original.Length);
5741 AssertEquals ("TripleDES_k192b64_CFB8_Zeros Decrypt", input, original);
5745 public void TestTripleDES_k192b64_CFB8_PKCS7 ()
5747 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 };
5748 byte[] iv = { 0x0E, 0xC5, 0xA8, 0xB2, 0xDD, 0x83, 0xAE, 0x8C };
5749 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 };
5751 SymmetricAlgorithm algo = TripleDES.Create ();
5752 algo.Mode = CipherMode.CFB;
5753 algo.Padding = PaddingMode.PKCS7;
5754 algo.BlockSize = 64;
5755 algo.FeedbackSize = 8;
5756 int blockLength = (algo.BlockSize >> 3);
5757 byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
5758 byte[] output = new byte [blockLength * 3];
5759 ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
5760 Encrypt (encryptor, input, output);
5761 AssertEquals ("TripleDES_k192b64_CFB8_PKCS7 Encrypt", expected, output);
5762 byte[] reverse = new byte [blockLength * 3];
5763 ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
5764 Decrypt (decryptor, output, reverse);
5765 byte[] original = new byte [input.Length];
5766 Array.Copy (reverse, 0, original, 0, original.Length);
5767 AssertEquals ("TripleDES_k192b64_CFB8_PKCS7 Decrypt", input, original);
5771 /* Invalid parameters TripleDES_k192b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
5773 /* Invalid parameters TripleDES_k192b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
5775 /* Invalid parameters TripleDES_k192b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
5778 // Number of test cases: 189
5779 // Number of invalid (non-generated) test cases: 171