This article does not cite any sources. Please help improve this article by adding citations to reliable sources. (December 2009)
In cryptography, residual block termination is a variation of cipher block chaining mode (CBC) that does not require any padding. It does this by effectively changing to cipher feedback mode for one block. The cost is the increased complexity.
Encryption procedureEdit
If the plaintext length N is not a multiple of the block size L:
 Encrypt the ⌊N/L⌋ full blocks of plaintext using the cipher block chaining mode;
 Encrypt the last full encrypted block again;
 XOR the remaining bits of the plaintext with leftmost bits of the reencrypted block.
Decryption procedureEdit
 Decrypt the ⌊N/L⌋ full encrypted blocks using the Cipher Block Chaining mode;
 Encrypt the last full encrypted block;
 XOR the remaining bits of the ciphertext with leftmost bits of the reencrypted block.
Proof that this decryption procedure really is the inverse of the encryption procedure is left as an exercise for the reader.
Short messageEdit
For messages shorter than one block, residual block termination can use an encrypted IV instead of the previously encrypted block.

Community content is available under CCBYSA
unless otherwise noted.