test AES/CTR encryption test vectors: http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
1 import dcrypt.blockcipher.aes; 2 import std.range; 3 import std.conv: text; 4 5 CTR!AES ctr; 6 7 const ubyte[] key = cast(const ubyte[])x"2b7e151628aed2a6abf7158809cf4f3c"; 8 const ubyte[] iv = cast(const ubyte[])x"f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"; 9 10 const ubyte[] plain = cast(const ubyte[])x" 11 6bc1bee22e409f96e93d7e117393172a 12 ae2d8a571e03ac9c9eb76fac45af8e51 13 30c81c46a35ce411e5fbc1191a0a52ef 14 f69f2445df4f9b17ad2b417be66c3710 15 "; 16 17 const ubyte[] expected_ciphertext = cast(const ubyte[])x" 18 874d6191b620e3261bef6864990db6ce 19 9806f66b7970fdff8617187bb9fffdff 20 5ae4df3edbd5d35e5b4f09020db03eab 21 1e031dda2fbe03d1792170a0f3009cee 22 "; 23 24 25 // encryption mode 26 ctr.start(true, key, iv); 27 28 ubyte[plain.length] buf; 29 buf = plain; 30 31 foreach(block; chunks(buf[],16)) { 32 ctr.processBlock(block,block); 33 } 34 35 assert(buf == expected_ciphertext, text(ctr.name,": encryption failed")); 36 37 // decryption mode 38 ctr.start(false, key, iv); 39 40 foreach(block; chunks(buf[],16)) { 41 ctr.processBlock(block,block); 42 } 43 44 assert(buf == plain, text(ctr.name,": decryption failed"));