SLAU723A October 2017 – October 2018 MSP432E401Y , MSP432E411Y
The amount of data to hash is not necessarily a multiple of 64 bytes. The CLOSE_HASH bit in the SHA_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 SHA_DIGESTCOUNT register returns restored Digest Count + Length when it is read, and hashing completes.
Assuming a message of 129 bytes, Table 25-5 shows the SHA digest for three passes.Table 25-6 shows the SHA digest for one pass.
Digest (A to E) | SHA_ DIGEST_COUNT | SHA_MODE and SHA_LENGTH | SHA_DATA_n_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) | SHA_ DIGEST_COUNT | SHA_MODE and SHA_LENGTH | SHA_DATA_n_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 |