Test PaddedBufferedBlockCipher with AES and PKCS7 padding.
import dcrypt.crypto.padding.pkcs7; import dcrypt.crypto.engines.aes; PaddedBufferedBlockCipher!(AES, PKCS7Pad) c; immutable ubyte[] key = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; ubyte[] plain = new ubyte[65]; ubyte[] output = new ubyte[96]; foreach(plainTextLength; [0,1,15,16,17,24,31,32,33,63,64,65]) { // some odd number, smaller than one block, larger than two blocks plain.length = plainTextLength; foreach(i,ref b; plain) { b = cast(ubyte)i; } output.length = ((plainTextLength/c.blockSize)+2)*c.blockSize; // next even block size c.start(true, key); size_t len = c.processBytes(plain, output); len += c.doFinal(output[len..$]); output = output[0..len]; // crop slice to its size ubyte[] cipher = output.dup; output[] = 0; c.start(false, key); len = c.processBytes(cipher, output); len += c.doFinal(output[len..$]); assert(len == plain.length, "length does not match"); assert(output[0..len] == plain, "decrypted ciphertext is not equal to original plaintext"); }
test if T is a block cipher padding