Mercurial > projects > dcrypt
comparison dcrypt/crypto/ciphers/AES.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 |
---|---|
635 0x1dc37216u, 0xe2250cbcu, 0x3c498b28u, 0x0d9541ffu, | 635 0x1dc37216u, 0xe2250cbcu, 0x3c498b28u, 0x0d9541ffu, |
636 0xa8017139u, 0x0cb3de08u, 0xb4e49cd8u, 0x56c19064u, | 636 0xa8017139u, 0x0cb3de08u, 0xb4e49cd8u, 0x56c19064u, |
637 0xcb84617bu, 0x32b670d5u, 0x6c5c7448u, 0xb85742d0u | 637 0xcb84617bu, 0x32b670d5u, 0x6c5c7448u, 0xb85742d0u |
638 ]; | 638 ]; |
639 | 639 |
640 const uint BLOCK_SIZE = 16; | 640 static const uint BLOCK_SIZE = 16; |
641 | 641 |
642 uint ROUNDS, // Number of rounds depends on keysize | 642 uint ROUNDS, // Number of rounds depends on keysize |
643 s0, s1, s2, s3; // State | 643 s0, s1, s2, s3; // State |
644 uint[] w; // Expanded key | 644 uint[] w; // Expanded key |
645 ubyte[] workingKey; | 645 ubyte[] workingKey; |
646 | 646 |
647 } // end private | 647 } // end private |
648 | 648 |
649 char[] name() | 649 string name() |
650 { | 650 { |
651 return "AES"; | 651 return "AES"; |
652 } | 652 } |
653 | 653 |
654 uint rounds() | 654 uint rounds() |
892 /** Some AES test vectors from the FIPS-197 paper and BC. */ | 892 /** Some AES test vectors from the FIPS-197 paper and BC. */ |
893 debug (UnitTest) | 893 debug (UnitTest) |
894 { | 894 { |
895 unittest | 895 unittest |
896 { | 896 { |
897 static const char[][] test_keys = [ | 897 static string[] test_keys = [ |
898 "000102030405060708090a0b0c0d0e0f", | 898 "000102030405060708090a0b0c0d0e0f", |
899 "000102030405060708090a0b0c0d0e0f1011121314151617", | 899 "000102030405060708090a0b0c0d0e0f1011121314151617", |
900 "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", | 900 "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", |
901 "80000000000000000000000000000000", | 901 "80000000000000000000000000000000", |
902 "000000000000000000000000000000000000000000000000", | 902 "000000000000000000000000000000000000000000000000", |
903 "0000000000000000000000000000000000000000000000000000000000000000" | 903 "0000000000000000000000000000000000000000000000000000000000000000" |
904 ]; | 904 ]; |
905 | 905 |
906 static const char[][] test_plaintexts = [ | 906 static string[] test_plaintexts = [ |
907 "00112233445566778899aabbccddeeff", | 907 "00112233445566778899aabbccddeeff", |
908 "00112233445566778899aabbccddeeff", | 908 "00112233445566778899aabbccddeeff", |
909 "00112233445566778899aabbccddeeff", | 909 "00112233445566778899aabbccddeeff", |
910 "00000000000000000000000000000000", | 910 "00000000000000000000000000000000", |
911 "80000000000000000000000000000000", | 911 "80000000000000000000000000000000", |
912 "80000000000000000000000000000000" | 912 "80000000000000000000000000000000" |
913 ]; | 913 ]; |
914 | 914 |
915 static const char[][] test_ciphertexts = [ | 915 static string[] test_ciphertexts = [ |
916 "69c4e0d86a7b0430d8cdb78070b4c55a", | 916 "69c4e0d86a7b0430d8cdb78070b4c55a", |
917 "dda97ca4864cdfe06eaf70a0ec0d7191", | 917 "dda97ca4864cdfe06eaf70a0ec0d7191", |
918 "8ea2b7ca516745bfeafc49904b496089", | 918 "8ea2b7ca516745bfeafc49904b496089", |
919 "0edd33d3c621e546455bd8ba1418bec8", | 919 "0edd33d3c621e546455bd8ba1418bec8", |
920 "6cd02513e8d4dc986b4afe087a60bd0c", | 920 "6cd02513e8d4dc986b4afe087a60bd0c", |
921 "ddc6bf790c15760d8d9aeb6f9a75fd4e" | 921 "ddc6bf790c15760d8d9aeb6f9a75fd4e" |
922 | 922 |
923 ]; | 923 ]; |
924 | 924 |
925 AES t = new AES(); | 925 AES t = new AES(); |
926 foreach (uint i, char[] test_key; test_keys) | 926 foreach (uint i, string test_key; test_keys) |
927 { | 927 { |
928 ubyte[] buffer = new ubyte[t.blockSize]; | 928 ubyte[] buffer = new ubyte[t.blockSize]; |
929 char[] result; | 929 string result; |
930 SymmetricKey key = new SymmetricKey(ByteConverter.hexDecode(test_key)); | 930 SymmetricKey key = new SymmetricKey(ByteConverter.hexDecode(test_key)); |
931 | 931 |
932 // Encryption | 932 // Encryption |
933 t.init(true, key); | 933 t.init(true, key); |
934 t.update(ByteConverter.hexDecode(test_plaintexts[i]), buffer); | 934 t.update(ByteConverter.hexDecode(test_plaintexts[i]), buffer); |