Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Message Authentication Code or MAC
3.
How Authentication Happens
4.
Benefits of Message Authentication Codes
4.1.
Keeps Data Integrity
4.2.
Altered Message Detection
5.
Limitations of Message Authentication Codes
5.1.
Shared Key Establishment
5.2.
Unable to give Non-Repudiation
6.
Frequently Asked Questions
6.1.
How long can a message authentication code be?
6.2.
Does the message authentication code use the public key?
6.3.
What is authenticated code?
6.4.
What are the four principles of cryptography?
6.5.
What are the two main types of cryptographic algorithms?
7.
Conclusion
Last Updated: Mar 27, 2024

Message Authentication Codes in Cryptography

Author Amit Singh
0 upvote
Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

Have you sent a message to your friend or family? Have you ever wondered how that message is authenticated on the other end?

message authentication code

This article focuses on a critical topic in Cryptography, i.e., MAC or Message Authentication Code. We will study Message Authentication Code or MAC in detail. We will try to understand how the authentication process works. We will also see the benefits and limitations of MAC.

Message Authentication Code or MAC

Message Authentication Code or MAC is a type of code we use to authenticate the nature and the origin of a message received. MACs authenticate data exchanged over a network or forwarded from one person to another using authentication Cryptography.

In other words, MAC ensures that the data being transported across a network, kept inside or outside a system, or both, is authentic and free of malicious code and that the message is coming from the correct sender and has not been altered. 

A hardware security module is a device that maintains private digital keys that can store MACs.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

How Authentication Happens

Message Authentication Code (MAC) Algorithm is a symmetric key cryptography method for message authentication. The sender and receiver use the same symmetric key K to establish the MAC procedure.

A MAC is essentially an encrypted checksum created on the underlying message and sent with a message to ensure message authentication.

working

Let's try to understand the complete process of how the authentication of the message happens.

  1. The sender enters the message and the secret key K into a publicly available MAC algorithm and generates a MAC value.
     
  2. The MAC function compresses an arbitrarily long input into a fixed-length output, much like the hash function. Hash and MAC differ significantly in that MAC requires a secret key to compress data.
     
  3. The sender sends the message with the MAC. Since we are only concerned with providing message origin authentication in this case and not message secrecy, we presume the message is sent in the open. Encryption is necessary if confidentiality is required for the message.
     
  4. The receiver updates the MAC value after receiving the message and MAC by feeding the message that is received and the shared secret key K into the MAC algorithm.
     
  5. The receiver will now compare the freshly computed MAC to the MAC it received from the sender to ensure equality. If they line up, the message will be accepted by the recipient. The receiver is now confident that the message is sent by the intended sender.
     
  6. If the computed MAC and the MAC sent by the sender do not match, the receiver cannot tell whether the message has been altered or the origin has been tampered with. Bottom line: A receiver can assume that the communication is fake without risk.

Benefits of Message Authentication Codes

Now, let's see the benefits of the Message Authentication Codes:

Keeps Data Integrity

  • You can ensure that malicious code, such as executable codes used by viruses, has not been added to your system using MACs.
     
  • MACs are helpful when attempting to tackle viruses and other malware.

Altered Message Detection

  • You can use any program or application to create a MAC based on data sent to you or made available through a storage device. 
     
  • The application might compare the generated MAC to the original one to identify data changes.

Limitations of Message Authentication Codes

After the benefits, let's check out the limitations of the Message Authentication Codes:

Shared Key Establishment

  • It can offer message authentication between predetermined legitimate users who already have a shared key.
     
  • Before using MAC, it calls for creating a shared secret.

Unable to give Non-Repudiation

  • The guarantee of non-repudiation states that the sender of a message cannot retract any earlier pledges or actions.
     
  • Message Authentication Code techniques do not offer non-repudiation service. MACs cannot show that the sender sent a message if the sender and recipient get caught in a dispute over message origination.
     
  • Even if a third party cannot compute the MAC, the sender could dispute sending the message and assert that the recipient forged it because it is impossible to tell which of the two parties computed the MAC.
     
  • We can overcome all the above limitations by using a digital signature made up of the public key.

Frequently Asked Questions

How long can a message authentication code be?

The most recommended size is a 128-bit (16-bytes) tag.

Does the message authentication code use the public key?

A message recipient can use private keys provided by MACs to confirm that a message hasn't been tampered with during transmission.

What is authenticated code?

Message Authentication Code is an approved security function-based keyed cryptographic checksum.

What are the four principles of cryptography?

The key pillars of contemporary cryptography are Data Confidentiality, Data Integrity, Authentication, and Non-repudiation.

What are the two main types of cryptographic algorithms?

There are two main types of cryptography, asymmetric key encryption, and symmetric key encryption.

Conclusion

In this article, we have studied a critical topic in Cryptography, i.e., MAC or Message Authentication Code. We have studied Message Authentication Code or MAC in detail. We have also learnt how the authentication process works. We have also seen the benefits and limitations of MAC.

We hope that this article has provided you with the help to enhance your knowledge regarding Cryptography and if you would like to learn more, check out our articles on what-are-basic-cryptography-tools and what-is-cryptography-and-why-do-we-use-it.

Refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. Enroll in our courses and refer to the mock test and problems available; take a look at the interview experiences and interview bundle for placement preparations.

Do upvote our blog to help other ninjas grow.

Merry Learning!

Previous article
The Sponge Construction in Hash Functions
Next article
Nested MACs and HMAC in Cryptography
Live masterclass