Hash-based MACs

Similar to the hash function, Hash-based MACs (HMACs) produce a fixed-length output and take an arbitrarily long message as the input. In this scheme, the sender signs a message using the MAC and the receiver verifies it using the shared key. The key is hashed with the message using either of the two methods known as secret prefix or the secret suffix. With the secret prefix method, the key is concatenated with the message; that is, the key comes first and the message comes afterwards, whereas with the secret suffix method, the key comes after the message, as shown in the following equations:

Secret prefix: M = MACk(x) = h(k||x)

Secret suffix: M=MACk(x) = h(x||k)

There are pros and cons to both methods. Some attacks on both ...

Get Mastering Blockchain - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.