Cryptography Reference
In-Depth Information
though they are used in many applications today. Thus, we continue to develop better enci-
phering methods. However, before we move on to the next topic, we need to address the topic
of padding.
5.8
PADDING METHODS
Note that when we use block ciphers, the size of the message we are sending may not be a
multiple of the block size. For example, when we are using a block size of four,
HOWDY DOO
=
HOWD
YDOO
is a perfect multiple of the block size, but
HOWDY FOLKS
=
HOWD
YFOL
KS
is not. When this happens, we must pad the end of the message so that it becomes a perfect
block. We may choose to pad with some character, such as the letter X, as in
HOWD
YFOL
KSXX
or we may pad with zeros once we have converted the message into its numerical equiva-
lent, like
07142203
24051411
10180000.
This is not really satisfactory, as the characters or digits that we choose to pad with may
well be a valid part of the message, and not padding at all. This might possibly create con-
fusion at the receiving end. One solution to this problem is PKCS#5, a proposed standard
method of padding.
PKCS#5 Padding. This type of padding works like this: suppose the block size is 64
bytes, and the message is 125 bytes long. This makes 1 complete block, plus 61 bytes, 3 bytes
short of a full block. To complete the block, we append 3 bytes, each containing the num-
ber 3, as seen in Figure 5.3 (in binary):
FIGURE 5.3
Message
Padding
........
........
........
00000011
00000011
00000011
The message is now encrypted, and sent. On the receiving end, the message is decrypted.
The last block is inspected, and the last 3 bytes, each containing the number 3, are removed.
In general, if our message is
N
bytes short of a full block, we append
N
blocks, each con-
taining the number
.
What if our last block is complete? With PKCS#5, we add padding anyway! If our block
size is 64 bytes, and our message is 128 bytes, we will still append 64 bytes (each byte con-
taining the number 64) to the message! Why is this done? Suppose the message being sent
is an exact multiple of the block size. Now, suppose the last 6 bytes of the message happen
to contain the number 6. How is the receiver to know whether this is padding or part of the
N
Search WWH ::




Custom Search