In this era of Information technology, everything is been digital. We exchange information and communicate through the internet. To secure our information from unusual access and to maintain confidentiality we use some methods to achieve that. One such is Cryptography. Cryptography is a technique used to secure information and communications by means of codes.
The cryptographic authentication method which uses a hash function and a secret key is known as a Hash-based Message Authentication Code (or HMAC). You can utilize shared secrets and HMAC to accomplish authentication and confirm that the data is accurate and valid (both sender and recipient use the same key to generate and check the MAC).
Consider an information exchange between two persons, Person A(sender) and Person B (recipient), Person A sends a shared secret with Person B and Person B tries to authenticate. If the shared secret of A and B is the same then there you got what you are waiting for.
Working of the HMAC
Make the symmetric key's length multiple bits in each block as the first step
We must take action to match the length of the key to the number of bits based on each of the three choices. A key's length is smaller than the total number of bits in a block. In this instance, we need to increase the length of a key by many 0 bits in order to equal it to many bits.
A key's length corresponds to the number of bits in each block. Since the key is equal to the number of bits, there is nothing we need to do. The amount of bits in each block is less than the length of a key. In this scenario, we need to trim the key by using the message digest technique, which we will employ to create the HMAC, in order to equal the length of the key to the number of bits.
Symmetric XOR with a pad is the second step.
To create a variable called S1, we XOR the symmetric with the pad in this step.
Add the initial message to S1 in step three.
In this action, the original message is added at the end of S1.
Apply the message-digest algorithm in step four.
The output of step 3 is subjected to the chosen message-digest algorithm (such as MD5, SHA-1, SHA-512, etc.) in this phase. Considering that step 4's result is H.
Use a pad and an XOR symmetric key in the fifth step.
In this stage, the symmetric key and pad are XORed to create the variable known as S2. Repetition of the string 01011010 b/8 times is what makes up the pad.
Disadvantages of HMAC:
- Let's talk about some issues with the hash-based message authentication code. The Hash-based Message Authentication Code makes use of a symmetric key, as we've just covered. The term "symmetric key" refers to a key that is utilized by both the sender and the recipient. The challenge that emerges here is how the sender and receiver will exchange the key?
- The symmetric key exchange issue mentioned above has been resolved, but we are unable to apply the hash-based message authentication code when there are several receivers. this is so because HMAC generates MAC using a symmetric key. Only the sender and recipient, or two other people, are required to exchange the symmetric key.
- Here are several issues with the hash-based message authentication code that we might encounter. The Hash-based Message Authentication Code employs a symmetric key, as we have just covered. A symmetric key is one that is utilized by both the sender and the receiver. How the sender and receiver will exchange the key is the issue that emerges here.