SPRUJ17H March 2022 – October 2024 AM2631 , AM2631-Q1 , AM2632 , AM2632-Q1 , AM2634 , AM2634-Q1
The amount of data to hash is not necessarily a multiple of 64 bytes. The CLOSE_HASH bit in the S_MODE (or S_HASH512_MODE) register is set to append padding so that the message size becomes a multiple of 64 bytes. Consequently, a minimum of 9 bytes must be added to the message. Nine bytes is the minimum number of bytes that contains the minimum 65-bit padding specified by FIPS 180-1.
If the size of the last block of data is less than or equal to 55 bytes, no additional 64-byte block is required. However, if the last block of data contains more than 55 bytes, an extra 64-byte block must be added to make the padding as specified by FIPS 180-1. This extra block is added automatically by the hardware; thus, the module is fed with a 64-byte block of data. However, appending a pad on the last block of data can result in the creation of an extra 64-byte block.
The one or two last blocks that contain the padding are processed in the same way as the other blocks. Hash completion is then indicated in the same way as for a new hash, and the hash result can be read in the digest registers. The S_DIGEST_COUNT register returns restored Digest Count + Length when it is read, and hashing completes.
Assuming a message of 129 bytes, Table 7-135 shows the SHA digest for three passes. Table 7-136 shows the SHA digest for one pass.
Digest (A to E) | S_DIGESTCOUNT | S_MODE and S_LENGTH | S_DATAn_IN | |
---|---|---|---|---|
First pass | WRITE: LENGTH=64 ALGO (dependent on the algorithm to apply) ALGO_CONSTANT=1 CLOSE_HASH=0 | First 64 bytes of message | ||
Second pass | Round 1 digest calculation | WRITE: 64 | WRITE: LENGTH=64 ALGO (dependent on the algorithm to apply) ALGO_CONSTANT=0 CLOSE_HASH=0 | Second 64 bytes of message |
Third pass | Round 2 digest calculation | WRITE: 128 | Write: LENGTH=1 ALGO (dependent on the algorithm to apply) ALGO_CONSTANT=0 CLOSE_HASH=1 | Last byte of message |
Final digest | READ: 129 |
If the three passes are not performed in succession, the digest registers must be saved and restored for the next use of the SHA/MD5 engine. If the rounds are performed consecutively, there is no need to do anything with the digest registers.
Digest (A to E) | S_DIGESTCOUNT | S_MODE and S_LENGTH | S_DATAn_IN | |
---|---|---|---|---|
First pass | WRITE: LENGTH=129 ALGO (dependent on the algorithm to apply) ALGO_CONSTANT=1 CLOSE_HASH=1 | First 64 bytes of message | ||
Round 1 digest calculation | Second 64 bytes of message | |||
Round 2 digest calculation | Last byte of message | |||
Final digest | Read: 129 |