The model for MAC generation comprises six steps: •
Padding of the data to a multiple of the
cipher block size •
Splitting of the data into blocks •
Initial transformation of the first block of data •
Iteration through the remaining blocks of data •
Output transformation of the result of the last iteration •
Truncation of the result to the required length For most steps, the standard provides several options from which to choose, and/or allows some configurability.
Padding The input data must be padded to a multiple of the cipher block size, so that each subsequent cryptographic operation will have a complete block of data. Three padding methods are defined. In each case
n is the block length (in
bits):
Padding method 1 If necessary, add bits with value 0 to the end of the data until the padded data is a multiple of
n. (If the original data was already a multiple of
n, no bits are added.)
Padding method 2 Add a single bit with value 1 to the end of the data. Then if necessary add bits with value 0 to the end of the data until the padded data is a multiple of
n.
Padding method 3 The padded data comprises (in this order): • The length of the unpadded data (in bits) expressed in
big-endian binary in
n bits (i.e. one cipher block) • The unpadded data • As many (possibly none) bits with value 0 as are required to bring the total length to a multiple of
n bits It is not necessary to transmit or store the padding bits, because the recipient can regenerate them, knowing the length of the unpadded data and the padding method used.
Splitting The padded data
D is split into
q blocks
D1,
D2, ...
Dq, each of length
n, suitable for the block cipher.
Initial transformation A cryptographic operation is performed on the first block (
D1), to create an intermediate block
H1. Two initial transformations are defined:
Initial transformation 1 D1 is encrypted with the key
K: :
H1 = e
K(
D1)
Initial transformation 2 D1 is encrypted with the key
K, and then by a second key
K′′: :
H1 = e
K′′(e
K(
D1))
Iteration Blocks
H2 ...
Hq are calculated by encrypting, with the key
K, the bitwise
exclusive-or of the corresponding data block and the previous
H block. :for
i = 2 to
q ::
Hi = e
K(
Di ⊕
Hi-1) If there is only one data block (
q=1), this step is omitted.
Output transformation A cryptographic operation is (optionally) performed on the last iteration output block
Hq to produce the block
G. Three output transformations are defined:
Output transformation 1 Hq is used unchanged: :
G =
Hq Output transformation 2 Hq is encrypted with the key
K′: :
G = e
K′(
Hq)
Output transformation 3 Hq is decrypted with the key
K′ and the result encrypted with the key
K: :
G = e
K(d
K′(
Hq))
Truncation The MAC is obtained by truncating the block
G (keeping the leftmost bits, discarding the rightmost bits), to the required length. ==Specific algorithms==