Applied Cryptography

AES (block length 16 bytes) is used in CBC mode with PKCS#7 padding. In PKCS#7, if n bytes are missing, n bytes of value n are added, and even when the plaintext length is exactly a multiple of 16, 16 bytes of value 16 are added. Which of the following is the length of the ciphertext (not including the IV) when a 96-byte plaintext is encrypted?

  1. A96 bytes
  2. B112 bytes
  3. C128 bytes
Show answer and explanation

Answer: B. 112 bytes

96 bytes is exactly 6 blocks of 16 bytes, but PKCS#7 adds a block of sixteen bytes of value 16 even when the length divides evenly. The plaintext therefore becomes 96 + 16 = 112 bytes (7 blocks), and so does the ciphertext. Padding is added even in that case so that the decrypting side can always remove the padding by looking at the value of the last byte. Modes that XOR with a keystream, such as CTR mode and GCM, need no padding, and the ciphertext has the same length as the plaintext.

  • A. This is the value without padding. PKCS#7 adds a block of padding even when the length divides exactly.
  • B. Correct. 96 + 16 = 112 bytes.
  • C. This is 112 bytes plus the 16 bytes of the IV.
Practice this topic Back to topic

Books on Applied Cryptography Ad

As an Amazon Associate I earn from qualifying purchases.

More Applied Cryptography questions

  1. A server receiving data encrypted in CBC mode returned different errors when the padding after decryption was incorrect and when the padding was correct but the check of the contents failed. Which of the following correctly describes this situation?
  2. Which of the following correctly describes a feature of CTR mode (counter mode) of a block cipher?
  3. In CTR mode, two messages were mistakenly encrypted with the same key and the same nonce. For the byte at one position, the first plaintext P₁ is 01001000 (ASCII "H"), its ciphertext C₁ is 01110100 and the second ciphertext C₂ is 01010101. If the attacker knows P₁, which of the following is the second plaintext P₂ at the same position?
  4. Which of the following does authenticated encryption (AEAD) such as AES-GCM provide in a single operation?
  5. Which of the following correctly describes the 96-bit nonce (IV) used in AES-GCM?

Comparisons in this topic