HMAC algorithm stands for Hashed or Hash based Message Authentication Code.

It is a result of work done on developing a MAC derived from cryptographic hash functions.

HMAC is a great resistant towards cryptanalysis attacks as it uses the Hashing concept twice.

HMAC consists of twin benefits of Hashing and MAC, and thus is more secure than any other authentication codes

HMAC has been chosen as the mandatory-to-implement MAC for **IP security**, and is used in other Internet protocols, such as **SSL**

HMAC has been made compulsory to implement in IP security. The FIPS 198 NIST standard has also issued HMAC.

In recent years, there has been increased interest in developing

a MAC derived from a cryptographic hash function. The motivations for this

interest are

**Motivation**

1. Cryptographic hash functions such as MD5 and SHA generally execute faster

in software than symmetric block ciphers such as DES.

2. Library code for cryptographic hash functions is widely available.

With the development of AES and the more widespread availability of code

for encryption algorithms, these considerations are less significant, but hash-based

MACs continue to be widely used.

**Objectives –**

- As the Hash Function, HMAC is also aimed to be one way, i.e, easy to generate output from input but complex the other way round.
- It aims at being less effected by collisions than the hash functions.
- HMAC reuses the algorithms like MD5 and SHA-1 and checks to replace the embedded hash functions with more secure hash functions, in case found.
- HMAC tries to handle the Keys in more simple manner.

**design objectives for HMAC: **

• To use, without modifications, available hash functions. In particular, hash functions that perform well in software, and for which code is freely and widely available.

• To allow for easy replaceability of the embedded hash function in case faster or more secure hash functions are found or required.

• To preserve the original performance of the hash function without incurring a significant degradation.

• To use and handle keys in a simple way.

• To have a well understood cryptographic analysis of the strength of the authentication mechanism based on reasonable assumptions about the embedded hash function.

A hash function such as SHA was not designed for use as a MAC and cannot

be used directly for that purpose, because it does not rely on a secret key.

There have been a number of proposals for the incorporation of a secret key into

an existing hash algorithm. The approach that has received the most support is HMAC

**HMAC algorithm –**

The working of HMAC starts with taking a message M containing blocks of length *b* bits. An input signature is padded to the left of the message and the whole is given as input to a hash function which gives us a temporary message digest MD’. MD’ again is appended to an output signature and the whole is applied a hash function again, the result is our final message digest MD

Here, H stands for Hashing function,

M is original message

Si and So are input and output signatures respectively,

Yi is the ith block in original message M, where i ranges from [1, L)

L = the count of blocks in M

K is the secret key used for hashing

IV is an initial vector (some constant)

The generation of input signature and output signature *Si* and *So* respectively.

**Secret Key K. **

**n < K ^{+} < b**

** ipad = input pad **

** = 36 **_{H }**= 0011 0110**

_{ }** opad = output pad **

** = 5C _{H }= 0101 1100**

**HMAC Structure**

- The message is divided into L blocks, each of b bits
- The secret key K
^{+} - The result of step 2 is Exclusive-ORed with a constant called
**i-pad**(input pad) to create a b-bit block. The value of i-pad is the b/8 repetition of the sequence 00110110 (36 in hex). - The resulting block is prepended to the L-block message.
- The result of step-4 is hashed to create an n-bit digest. We call this as
**intermediate HMAC**. - The intermediate HMAC is left-padded with 0’s to make a b-bit block.
- Step 3 is repeated with a different constant
**o-pad**(output pad). The value of o-pad is the b/8 repetition of the sequence 0101 1100 (5C in hex). - The result of step-7 is prepended to the result of step-6.
- The result of step-8 is hashed with the same hashing algorithm to create the final n-bit HMAC.