comparison dcrypt/crypto/ciphers/Blowfish.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
201 0x243f6a88u, 0x85a308d3u, 0x13198a2eu, 0x03707344u, 0xa4093822u, 0x299f31d0u, 201 0x243f6a88u, 0x85a308d3u, 0x13198a2eu, 0x03707344u, 0xa4093822u, 0x299f31d0u,
202 0x082efa98u, 0xec4e6c89u, 0x452821e6u, 0x38d01377u, 0xbe5466cfu, 0x34e90c6cu, 202 0x082efa98u, 0xec4e6c89u, 0x452821e6u, 0x38d01377u, 0xbe5466cfu, 0x34e90c6cu,
203 0xc0ac29b7u, 0xc97c50ddu, 0x3f84d5b5u, 0xb5470917u, 0x9216d5d9u, 0x8979fb1bu 203 0xc0ac29b7u, 0xc97c50ddu, 0x3f84d5b5u, 0xb5470917u, 0x9216d5d9u, 0x8979fb1bu
204 ]; 204 ];
205 205
206 const uint BLOCK_SIZE = 8, 206 static const uint BLOCK_SIZE = 8,
207 ROUNDS = 16, 207 ROUNDS = 16,
208 SBOX_SIZE = 256, 208 SBOX_SIZE = 256,
209 PBOX_SIZE = 18, 209 PBOX_SIZE = 18,
210 MAX_KEY_SIZE = 56, // 448 bits 210 MAX_KEY_SIZE = 56, // 448 bits
211 MIN_KEY_SIZE = 4; // 32 bits 211 MIN_KEY_SIZE = 4; // 32 bits
212 uint[18] P; 212 uint[18] P;
213 uint[256] S0, S1, S2, S3; 213 uint[256] S0, S1, S2, S3;
214 ubyte[] workingKey; 214 ubyte[] workingKey;
215 } // end private 215 } // end private
216 216
217 char[] name() 217 string name()
218 { 218 {
219 return "Blowfish"; 219 return "Blowfish";
220 } 220 }
221 221
222 uint blockSize() 222 uint blockSize()
357 /** Some Blowfish test vectors from Schneier's site. */ 357 /** Some Blowfish test vectors from Schneier's site. */
358 debug (UnitTest) 358 debug (UnitTest)
359 { 359 {
360 unittest 360 unittest
361 { 361 {
362 static const char[][] test_keys = [ 362 static string[] test_keys = [
363 "0000000000000000", 363 "0000000000000000",
364 "ffffffffffffffff", 364 "ffffffffffffffff",
365 "57686f206973204a6f686e2047616c743f", // I don't know, do you? 365 "57686f206973204a6f686e2047616c743f", // I don't know, do you?
366 "1111111111111111", 366 "1111111111111111",
367 "0123456789abcdef", 367 "0123456789abcdef",
368 "1111111111111111", 368 "1111111111111111",
369 "fedcba9876543210" 369 "fedcba9876543210"
370 ]; 370 ];
371 371
372 static const char[][] test_plaintexts = [ 372 static string[] test_plaintexts = [
373 "0000000000000000", 373 "0000000000000000",
374 "ffffffffffffffff", 374 "ffffffffffffffff",
375 "fedcba9876543210", 375 "fedcba9876543210",
376 "1111111111111111", 376 "1111111111111111",
377 "1111111111111111", 377 "1111111111111111",
378 "0123456789abcdef", 378 "0123456789abcdef",
379 "0123456789abcdef" 379 "0123456789abcdef"
380 ]; 380 ];
381 381
382 static const char[][] test_ciphertexts = [ 382 static string[] test_ciphertexts = [
383 "4ef997456198dd78", 383 "4ef997456198dd78",
384 "51866fd5b85ecb8a", 384 "51866fd5b85ecb8a",
385 "cc91732b8022f684", 385 "cc91732b8022f684",
386 "2466dd878b963c9d", 386 "2466dd878b963c9d",
387 "61f9c3802281b096", 387 "61f9c3802281b096",
388 "7d0cc630afda1ec7", 388 "7d0cc630afda1ec7",
389 "0aceab0fc6a0a28d" 389 "0aceab0fc6a0a28d"
390 ]; 390 ];
391 391
392 Blowfish t = new Blowfish(); 392 Blowfish t = new Blowfish();
393 foreach (uint i, char[] test_key; test_keys) 393 foreach (uint i, string test_key; test_keys)
394 { 394 {
395 ubyte[] buffer = new ubyte[t.blockSize]; 395 ubyte[] buffer = new ubyte[t.blockSize];
396 char[] result; 396 string result;
397 SymmetricKey key = new SymmetricKey(ByteConverter.hexDecode(test_key)); 397 SymmetricKey key = new SymmetricKey(ByteConverter.hexDecode(test_key));
398 398
399 // Encryption 399 // Encryption
400 t.init(true, key); 400 t.init(true, key);
401 t.update(ByteConverter.hexDecode(test_plaintexts[i]), buffer); 401 t.update(ByteConverter.hexDecode(test_plaintexts[i]), buffer);