Mercurial > projects > dcrypt
comparison dcrypt/crypto/ciphers/RC6.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 |
---|---|
27 */ | 27 */ |
28 class RC6 : BlockCipher | 28 class RC6 : BlockCipher |
29 { | 29 { |
30 private | 30 private |
31 { | 31 { |
32 const uint ROUNDS = 20, | 32 static const uint ROUNDS = 20, |
33 BLOCK_SIZE = 16, | 33 BLOCK_SIZE = 16, |
34 // Magic constants for a 32 bit word size | 34 // Magic constants for a 32 bit word size |
35 P = 0xb7e15163, | 35 P = 0xb7e15163, |
36 Q = 0x9e3779b9; | 36 Q = 0x9e3779b9; |
37 uint[] S; | 37 uint[] S; |
38 ubyte[] workingKey; | 38 ubyte[] workingKey; |
39 } | 39 } |
40 | 40 |
41 char[] name() | 41 string name() |
42 { | 42 { |
43 return "RC6"; | 43 return "RC6"; |
44 } | 44 } |
45 | 45 |
46 uint blockSize() | 46 uint blockSize() |
170 /** Some RC6 test vectors from the spec. */ | 170 /** Some RC6 test vectors from the spec. */ |
171 debug (UnitTest) | 171 debug (UnitTest) |
172 { | 172 { |
173 unittest | 173 unittest |
174 { | 174 { |
175 static const char[][] test_keys = [ | 175 static string[] test_keys = [ |
176 "00000000000000000000000000000000", | 176 "00000000000000000000000000000000", |
177 "0123456789abcdef0112233445566778", | 177 "0123456789abcdef0112233445566778", |
178 "00000000000000000000000000000000"~ | 178 "00000000000000000000000000000000"~ |
179 "0000000000000000", | 179 "0000000000000000", |
180 "0123456789abcdef0112233445566778"~ | 180 "0123456789abcdef0112233445566778"~ |
183 "00000000000000000000000000000000", | 183 "00000000000000000000000000000000", |
184 "0123456789abcdef0112233445566778"~ | 184 "0123456789abcdef0112233445566778"~ |
185 "899aabbccddeeff01032547698badcfe" | 185 "899aabbccddeeff01032547698badcfe" |
186 ]; | 186 ]; |
187 | 187 |
188 static const char[][] test_plaintexts = [ | 188 static string[] test_plaintexts = [ |
189 "00000000000000000000000000000000", | 189 "00000000000000000000000000000000", |
190 "02132435465768798a9bacbdcedfe0f1", | 190 "02132435465768798a9bacbdcedfe0f1", |
191 "00000000000000000000000000000000", | 191 "00000000000000000000000000000000", |
192 "02132435465768798a9bacbdcedfe0f1", | 192 "02132435465768798a9bacbdcedfe0f1", |
193 "00000000000000000000000000000000", | 193 "00000000000000000000000000000000", |
194 "02132435465768798a9bacbdcedfe0f1" | 194 "02132435465768798a9bacbdcedfe0f1" |
195 ]; | 195 ]; |
196 | 196 |
197 static const char[][] test_ciphertexts = [ | 197 static string[] test_ciphertexts = [ |
198 "8fc3a53656b1f778c129df4e9848a41e", | 198 "8fc3a53656b1f778c129df4e9848a41e", |
199 "524e192f4715c6231f51f6367ea43f18", | 199 "524e192f4715c6231f51f6367ea43f18", |
200 "6cd61bcb190b30384e8a3f168690ae82", | 200 "6cd61bcb190b30384e8a3f168690ae82", |
201 "688329d019e505041e52e92af95291d4", | 201 "688329d019e505041e52e92af95291d4", |
202 "8f5fbd0510d15fa893fa3fda6e857ec2", | 202 "8f5fbd0510d15fa893fa3fda6e857ec2", |
203 "c8241816f0d7e48920ad16a1674e5d48" | 203 "c8241816f0d7e48920ad16a1674e5d48" |
204 ]; | 204 ]; |
205 | 205 |
206 RC6 t = new RC6(); | 206 RC6 t = new RC6(); |
207 foreach (uint i, char[] test_key; test_keys) | 207 foreach (uint i, string test_key; test_keys) |
208 { | 208 { |
209 ubyte[] buffer = new ubyte[t.blockSize]; | 209 ubyte[] buffer = new ubyte[t.blockSize]; |
210 char[] result; | 210 string result; |
211 SymmetricKey key = new SymmetricKey(ByteConverter.hexDecode(test_key)); | 211 SymmetricKey key = new SymmetricKey(ByteConverter.hexDecode(test_key)); |
212 | 212 |
213 // Encryption | 213 // Encryption |
214 t.init(true, key); | 214 t.init(true, key); |
215 t.update(ByteConverter.hexDecode(test_plaintexts[i]), buffer); | 215 t.update(ByteConverter.hexDecode(test_plaintexts[i]), buffer); |