comparison dcrypt/crypto/ciphers/RC6.d @ 6:5cb17e09d685

Minor edits to the unittests of hash functions and ciphers. Added AES and test vectors.
author Thomas Dixon <reikon@reikon.us>
date Sat, 16 Aug 2008 22:43:22 -0400
parents 71aae178f89a
children 23c62e28b3a4
comparison
equal deleted inserted replaced
5:cff9960a019c 6:5cb17e09d685
1 /** 1 /**
2 * This file is part of the dcrypt project. 2 * This file is part of the dcrypt project.
3 * 3 *
4 * Copyright: Copyright (C) dcrypt contributors 2008. All rights reserved.
5 * License: MIT
6 * Authors: Thomas Dixon
7 */
8
9 module dcrypt.crypto.ciphers.RC6;
10
11 import dcrypt.misc.Util;
12 import dcrypt.crypto.BlockCipher;
13
14 /**
15 * Implementation of the RC6-32/20/b cipher designed by
16 * Ron Rivest et al. of RSA Security.
17 *
4 * It should be noted that this algorithm is very similar to RC5. 18 * It should be noted that this algorithm is very similar to RC5.
5 * Currently there are no plans to implement RC5, but should that change 19 * Currently there are no plans to implement RC5, but should that change
6 * in the future, it may be wise to rewrite both RC5 and RC6 to use some 20 * in the future, it may be wise to rewrite both RC5 and RC6 to use some
7 * kind of template or base class. 21 * kind of template or base class.
8 * 22 *
9 * Copyright: Copyright (C) dcrypt contributors 2008. All rights reserved. 23 * This algorithm is patented and trademarked.
10 * License: MIT 24 *
11 * Authors: Thomas Dixon 25 * References: http://people.csail.mit.edu/rivest/Rc6.pdf
12 */
13
14 module dcrypt.crypto.ciphers.RC6;
15
16 import dcrypt.misc.Util;
17 import dcrypt.crypto.BlockCipher;
18
19 /**
20 * Implementation of the RC6-32/20/b cipher designed by
21 * Ron Rivest et al. of RSA Security.
22 *
23 * Note: This algorithm is patented and trademarked.
24 */ 26 */
25 class RC6 : BlockCipher { 27 class RC6 : BlockCipher {
26 private { 28 private {
27 const uint ROUNDS = 20, 29 const uint ROUNDS = 20,
28 BLOCK_SIZE = 16, 30 BLOCK_SIZE = 16,
201 // Decryption 203 // Decryption
202 t.init(false, key); 204 t.init(false, key);
203 t.processBlock(Util.hexToUbytes(test_ciphertexts[i]), 0, buffer, 0); 205 t.processBlock(Util.hexToUbytes(test_ciphertexts[i]), 0, buffer, 0);
204 result = Util.ubytesToHex(buffer); 206 result = Util.ubytesToHex(buffer);
205 assert(result == test_plaintexts[i], 207 assert(result == test_plaintexts[i],
206 t.name~": ("~result~") != ("~test_ciphertexts[i]~")"); 208 t.name~": ("~result~") != ("~test_plaintexts[i]~")");
207 } 209 }
208 } 210 }
209 } 211 }
210 } 212 }