comparison dcrypt/crypto/ciphers/XTEA.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 XTEA : BlockCipher 16 class XTEA : 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 uint[] subkeys, 24 uint[] subkeys,
25 sum0, 25 sum0,
26 sum1; 26 sum1;
27 } 27 }
28 28
29 void reset(){} 29 void reset(){}
30 30
31 char[] name() 31 string name()
32 { 32 {
33 return "XTEA"; 33 return "XTEA";
34 } 34 }
35 35
36 uint blockSize() 36 uint blockSize()
113 /** Some XTEA test vectors. */ 113 /** Some XTEA test vectors. */
114 debug (UnitTest) 114 debug (UnitTest)
115 { 115 {
116 unittest 116 unittest
117 { 117 {
118 static const char[][] test_keys = [ 118 static string[] test_keys = [
119 "00000000000000000000000000000000", 119 "00000000000000000000000000000000",
120 "00000000000000000000000000000000", 120 "00000000000000000000000000000000",
121 "0123456712345678234567893456789a", 121 "0123456712345678234567893456789a",
122 "0123456712345678234567893456789a", 122 "0123456712345678234567893456789a",
123 "00000000000000000000000000000001", 123 "00000000000000000000000000000001",
126 "0123456789abcdef0123456789abcdef", 126 "0123456789abcdef0123456789abcdef",
127 "00000000000000000000000000000000", 127 "00000000000000000000000000000000",
128 "00000000000000000000000000000000" 128 "00000000000000000000000000000000"
129 ]; 129 ];
130 130
131 static const char[][] test_plaintexts = [ 131 static string[] test_plaintexts = [
132 "0000000000000000", 132 "0000000000000000",
133 "0102030405060708", 133 "0102030405060708",
134 "0000000000000000", 134 "0000000000000000",
135 "0102030405060708", 135 "0102030405060708",
136 "0000000000000001", 136 "0000000000000001",
139 "0000000000000000", 139 "0000000000000000",
140 "0123456789abcdef", 140 "0123456789abcdef",
141 "4141414141414141" 141 "4141414141414141"
142 ]; 142 ];
143 143
144 static const char[][] test_ciphertexts = [ 144 static string[] test_ciphertexts = [
145 "dee9d4d8f7131ed9", 145 "dee9d4d8f7131ed9",
146 "065c1b8975c6a816", 146 "065c1b8975c6a816",
147 "1ff9a0261ac64264", 147 "1ff9a0261ac64264",
148 "8c67155b2ef91ead", 148 "8c67155b2ef91ead",
149 "9f25fa5b0f86b758", 149 "9f25fa5b0f86b758",
153 "7e66c71c88897221", 153 "7e66c71c88897221",
154 "ed23375a821a8c2d" 154 "ed23375a821a8c2d"
155 ]; 155 ];
156 156
157 XTEA t = new XTEA(); 157 XTEA t = new XTEA();
158 foreach (uint i, char[] test_key; test_keys) 158 foreach (uint i, string test_key; test_keys)
159 { 159 {
160 ubyte[] buffer = new ubyte[t.blockSize]; 160 ubyte[] buffer = new ubyte[t.blockSize];
161 char[] result; 161 string result;
162 SymmetricKey key = new SymmetricKey(ByteConverter.hexDecode(test_key)); 162 SymmetricKey key = new SymmetricKey(ByteConverter.hexDecode(test_key));
163 163
164 // Encryption 164 // Encryption
165 t.init(true, key); 165 t.init(true, key);
166 t.update(ByteConverter.hexDecode(test_plaintexts[i]), buffer); 166 t.update(ByteConverter.hexDecode(test_plaintexts[i]), buffer);