๐Ÿ“Padding (Encryption)

tags
ยง Cryptography
  • Because block ciphers work on fixed-size blocks, the input for many modes of operation must be padded to the block size. However, care must be taken to ensure that original length can be recovered.
  • If input is C-style string (does not contain 0 bytes), padding is trivial โ€” just add as many 0 bytes as needed.
  • Another scheme: append a single 1 bit and as many 0 bits as necessary to pad the block. If the input length is on the boundary of the block, add a whole block of padding.
  • Another schemes like ciphertext stealing and residual block termination do not cause any extra ciphertext.
  • Append a byte with value 128 (0x80) and as many zero bytes as necessary.
  • Pad the last block with n bytes all with value n.
  • CFB, OFB, and CTR modes do not require any padding, because they can be used as stream ciphers.
  • Backlinks