Padding (cryptography)

In cryptography, padding is any of a number of distinct practices which all include adding data to the beginning, middle, or end of a message prior to encryption.

Official messages often start and end in predictable ways: My dear ambassador, Weather report, Sincerely yours, etc.

The primary use of padding with classical ciphers is to prevent the cryptanalyst from using that predictability to find known plaintext[1] that aids in breaking the encryption.

In that example, Admiral Chester Nimitz, the Commander in Chief, U.S. Pacific Fleet in WWII, sent the following message to Admiral Bull Halsey, commander of Task Force Thirty Four (the main Allied fleet) at the Battle of Leyte Gulf, on October 25, 1944:[2] Where is, repeat, where is Task Force Thirty Four?

More intricate ways of ending a message such as ciphertext stealing or residual block termination avoid the need for padding.

This can be accomplished by verifying a message authentication code (MAC) or digital signature before removal of the padding bytes, or by switching to a streaming mode of operation.

[citation needed] In public key cryptography, padding is the process of preparing a message for encryption or signing using a specification or scheme such as PKCS#1 v2.2, OAEP, PSS, PSSR, IEEE P1363 EMSA2 and EMSA5.

A modern form of padding for asymmetric primitives is OAEP applied to the RSA algorithm, when it is used to encrypt a limited number of bytes.

The operation is referred to as "padding" because originally, random material was simply appended to the message to make it long enough for the primitive.

A modern padding scheme aims to ensure that the attacker cannot manipulate the plaintext to exploit the mathematical structure of the primitive and will usually be accompanied by a proof, often in the random oracle model, that breaking the padding scheme is as hard as solving the hard problem underlying the primitive.

[14][15][16] The side-channel of encrypted content length was used to extract passwords from HTTPS communications in the well-known CRIME and BREACH attacks.

[17] Padding an encrypted message can make traffic analysis harder by obscuring the true length of its payload.

The choice of length to pad a message to may be made either deterministically or randomly; each approach has strengths and weaknesses that apply in different contexts.

If the amount of padding is chosen as a uniform random number between 0 and some maximum M, for example, then an eavesdropper will be unable to determine the message's length precisely within that range.

Alternatively, an active attacker might be able to induce an endpoint to send messages regularly, such as if the victim is a public server.

In such cases, the eavesdropper can simply compute the average over many observations to determine the length of the regular message's payload.

In this respect, deterministic padding schemes have the advantage of not leaking any additional information with each successive message of the same payload size.

On the other hand, suppose an eavesdropper can benefit from learning about small variations in payload size, such as plus or minus just one byte in a password-guessing attack for example.

Against such risks, randomized padding can offer more protection by independently obscuring the least-significant bits of message lengths.