Hash processor (HASH)
21.3.5
Hash operation
The hash function (SHA-1, and MD5) is selected when the INIT bit is written to '1' in the
HASH_CR register while the MODE bit is at '0' in HASH_CR. The algorithm (SHA-1, or
MD5) is selected at the same time (that is when the INIT bit is set) using the ALGO bits.
The message can then be sent by writing it word by word into the HASH_DIN register. When
a block of 512 bits —that is 16 words— has been written, a partial digest computation starts
upon writing the first data of the next block. The hash processor remains busy for 66 cycles
for the SHA-1 algorithm, or 50 cycles for the MD5
The process can then be repeated until the last word of the message. If DMA transfers are
used, refer to the
message length is not an exact multiple of 512 bits, then the HASH_STR register has to be
written to launch the computation of the final digest.
Once computed, the digest can be read from the HASH_H0...HASH_H4 registers (for
the MD5 algorithm, HASH_H4 is not relevant).
21.3.6
HMAC operation
The HMAC algorithm is used for message authentication, by irreversibly binding the
message being processed to a key chosen by the user. For HMAC specifications, refer to
"HMAC: keyed-hashing for message authentication, H. Krawczyk, M. Bellare, R. Canetti,
February 1997.
Basically, the algorithm consists of two nested hash operations:
HMAC(message) = Hash[((key | pad) XOR 0x5C)
where:
•
pad is a sequence of zeroes needed to extend the key to the length of the underlying
hash function data block (that is 512 bits for both the SHA-1, and MD5 hash algorithms)
•
| represents the concatenation operator
To compute the HMAC, four different phases are required:
1.
The block is initialized by writing the INIT bit to '1' with the MODE bit at '1' and the
ALGO bits set to the value corresponding to the desired algorithm. The LKEY bit must
also be set during this phase if the key being used is longer than 64 bytes (in this case,
the HMAC specifications specify that the hash of the key should be used in place of the
real key).
2.
The key (to be used for the inner hash function) is then given to the core. This
operation follows the same mechanism as the one used to send the message in the
hash operation (that is, by writing into HASH_DIN and, finally, into HASH_STR).
3.
Once the last word has been entered and computation has started, the hash processor
elaborates the key. It is then ready to accept the message text using the same
mechanism as the one used to send the message in the hash operation.
4.
After the first hash round, the hash processor returns "ready" to indicate that it is ready
to receive the key to be used for the outer hash function (normally, this key is the same
as the one used for the inner hash function). When the last word of the key is entered
and computation starts, the HMAC result is made available in the
HASH_H0...HASH_H4 registers.
556/1378
Procedure where the data are loaded by DMA
| Hash(((key | pad) XOR 0x36) | message)]
RM0033 Rev 8
algorithm.
section. Otherwise, if the
RM0033
Need help?
Do you have a question about the STM32F205 series and is the answer not in the manual?