Cryptography

What is MAC and why is it needed?

Easy
10 min

What is MAC?

Message Authentication Code (MAC) is essentially a cryptographic hash that, in addition to verifying the integrity of the message (message has remained unchanged), also has an important additional task: to verify the authenticity of the message, i.e., to verify that the message really originates from the expected sender.

How Does MAC Work?

The operating principle of MAC is quite simple.

  • First, there must be a shared symmetric encryption key between the sender and receiver.
  • Then the sender creates a MAC value. MAC is created, simplistically, by combining a secret key with the contents of the message and calculating a cryptographic digest of these.
  • The recipient itself calculates the MAC value of the incoming message in exactly the same way and with the secret key known to the recipient.
  • Then the recipient compares the MAC value it calculated itself with the MAC value sent by the sender.
  • If the content of the message changes, for example by an attacker, along the way, the MAC value no longer matches the value calculated by the recipient.

Exercise

You have shared the encryption key with Alice: 01:02:03 (hex) and agreed to use the HMAC-SHA256 MAC algorithm.

  • Alice sends you the coordinates of the secret meeting place with a message: 51.848637, -0.55462
  • Message includes MAC: bc31e702151483ab8ce821519bf10dbde09a66fd930a03cadccef7bc1c72eae1

Use CyberChef's HMAC module to verify the authenticity of the message!

Is the MAC correct?

What would have been the correct MAC?

hakatemia pro

Ready to become an ethical hacker?
Start today.

As a member of Hakatemia you get unlimited access to Hakatemia modules, exercises and tools, and you get access to the Hakatemia Discord channel where you can ask for help from both instructors and other Hakatemia members.