comparison dcrypt/crypto/ciphers/TEA.d @ 28:ad687db713a4

Further reworked the code for hash padding. Replaced all instances of 'char[]' with 'string' and removed a few 'const' modifiers as per Glenn Haecker's patch for D2 compatibility. Updated CONTRIBUTORS file.
author Thomas Dixon <reikon@reikon.us>
date Sun, 10 May 2009 22:38:48 -0400
parents 8b5eaf3c2979
children
comparison
equal deleted inserted replaced
27:8b5eaf3c2979 28:ad687db713a4
15 David Wheeler and Roger Needham. */ 15 David Wheeler and Roger Needham. */
16 class TEA : BlockCipher 16 class TEA : BlockCipher
17 { 17 {
18 private 18 private
19 { 19 {
20 const uint ROUNDS = 32, 20 static const uint ROUNDS = 32,
21 KEY_SIZE = 16, 21 KEY_SIZE = 16,
22 BLOCK_SIZE = 8, 22 BLOCK_SIZE = 8,
23 DELTA = 0x9e3779b9u, 23 DELTA = 0x9e3779b9u,
24 DECRYPT_SUM = 0xc6ef3720u; 24 DECRYPT_SUM = 0xc6ef3720u;
25 uint sk0, sk1, sk2, sk3, sum; 25 uint sk0, sk1, sk2, sk3, sum;
26 } 26 }
27 27
28 void reset(){} 28 void reset(){}
29 29
30 char[] name() 30 string name()
31 { 31 {
32 return "TEA"; 32 return "TEA";
33 } 33 }
34 34
35 uint blockSize() 35 uint blockSize()
101 /** Some TEA test vectors. */ 101 /** Some TEA test vectors. */
102 debug (UnitTest) 102 debug (UnitTest)
103 { 103 {
104 unittest 104 unittest
105 { 105 {
106 static const char[][] test_keys = [ 106 static string[] test_keys = [
107 "00000000000000000000000000000000", 107 "00000000000000000000000000000000",
108 "00000000000000000000000000000000", 108 "00000000000000000000000000000000",
109 "0123456712345678234567893456789a", 109 "0123456712345678234567893456789a",
110 "0123456712345678234567893456789a" 110 "0123456712345678234567893456789a"
111 ]; 111 ];
112 112
113 static const char[][] test_plaintexts = [ 113 static string[] test_plaintexts = [
114 "0000000000000000", 114 "0000000000000000",
115 "0102030405060708", 115 "0102030405060708",
116 "0000000000000000", 116 "0000000000000000",
117 "0102030405060708" 117 "0102030405060708"
118 ]; 118 ];
119 119
120 static const char[][] test_ciphertexts = [ 120 static string[] test_ciphertexts = [
121 "41ea3a0a94baa940", 121 "41ea3a0a94baa940",
122 "6a2f9cf3fccf3c55", 122 "6a2f9cf3fccf3c55",
123 "34e943b0900f5dcb", 123 "34e943b0900f5dcb",
124 "773dc179878a81c0" 124 "773dc179878a81c0"
125 ]; 125 ];
126 126
127 127
128 TEA t = new TEA(); 128 TEA t = new TEA();
129 foreach (uint i, char[] test_key; test_keys) 129 foreach (uint i, string test_key; test_keys)
130 { 130 {
131 ubyte[] buffer = new ubyte[t.blockSize]; 131 ubyte[] buffer = new ubyte[t.blockSize];
132 char[] result; 132 string result;
133 SymmetricKey key = new SymmetricKey(ByteConverter.hexDecode(test_key)); 133 SymmetricKey key = new SymmetricKey(ByteConverter.hexDecode(test_key));
134 134
135 // Encryption 135 // Encryption
136 t.init(true, key); 136 t.init(true, key);
137 t.update(ByteConverter.hexDecode(test_plaintexts[i]), buffer); 137 t.update(ByteConverter.hexDecode(test_plaintexts[i]), buffer);