[Day 5] 6. Message Authentication Code
Why is MAC Used?
Imagine you're sending a box of chocolates to a friend through a delivery service. Along with the box, you attach a unique lock (the MAC) that only you and your friend can open using the same key (symmetric key).
- The lock ensures:
- Integrity: The chocolates haven't been replaced or tampered with during delivery.
- Authentication: Only your friend, who has the same key, can confirm it came from you.
If someone else tries to replace the chocolates, they can't re-lock the box without your unique key.
Technical Explanation
- A MAC (Message Authentication Code) is like the lock in the example. It is a code generated by combining a secret key and the message (data).
- The receiver uses the same secret key to verify that the code matches the message.
- If the code doesn't match, the message has been altered or doesn't come from the expected sender.
**Types of MAC **
1. Hash MAC (HMAC)
-
Imagine This: Instead of a physical lock, you write a secret "signature" (hash value) on the delivery note. Only your friend knows how to recreate the signature using their secret formula (hash function + key).
-
How It Works (Technically):
- The sender combines the message with a key and calculates a hash value (a fixed-size digital fingerprint).
- The hash value (HMAC) is sent along with the message.
- The receiver:
-
Combines their copy of the key with the received message.
-
Calculates the hash value again and compares it to the received HMAC.
-
- If it matches: The message is authentic and hasn't been changed.
- Key Points: HMAC ensures data integrity but relies on the shared key for trust.
2. Cipher Block Chaining MAC (CBC-MAC)
-
Imagine This: Instead of a signature, you use a high-security lock (encryption algorithm) to secure the box. This lock is stronger and uses more complex techniques.
-
How It Works (Technically):
-
It uses block ciphers like AES in Cipher Block Chaining mode:
- The message is split into blocks.
- Each block is processed (encrypted) using the key.
- The result of the last block is the MAC.
-
Key Points:
- Provides stronger security for authentication.
- Useful for systems that require high levels of protection.
-
Digital Signature
What is a Digital Signature?
- A digital signature ensures both data integrity and authentication using public-key cryptography.
- The hash value of the message is encrypted using the sender’s private key, and the receiver verifies it using the sender’s public key.
Example: Tinku and Pinki Communicating
-
Keys Setup:
- Tinku has a private key and a public key.
- Pinki has her own private key and public key.
- Both share their public keys with each other.
-
Tinku Sends a Message:
- Tinku creates a message M1.
- Calculates the hash of the message (H1).
- Encrypts H1 using his private key to generate the digital signature.
- Sends the M1 (message) and the digital signature to Pinki.
-
Pinki Verifies the Message:
- Pinki decrypts the digital signature using Tinku’s public key, obtaining the original hash value (H1).
- She recalculates the hash value for the received message M1.
- If both hash values match:
- The message is authentic (ensured by Tinku’s private key).
- The message integrity is verified (not tampered in transit).
Comparison: MAC vs. Digital Signature
|Feature|MAC|Digital Signature| |---|---|---| |Key Type|Symmetric Key|Asymmetric Key (Private/Public)| |Authentication|Assumes shared key provides authentication|Ensures authentication using private key| |Integrity|Ensures integrity|Ensures integrity| |Use Case|Faster, simpler for trusted parties|More secure for untrusted environments|
Read Next
[Day 5] 7. Squid as a Load Balancer
### **Setup Overview** We are configuring **SQUID** to act as a load balancer for two **Apache Servers** on separate machines. #### **Network Co...
[Day 5] 8. Monitoring a Remote Linux Machine using Nagios
### **Overview** **Goal:** Set up Nagios to monitor a remote Linux machine using **NCPA** (Nagios Cross-Platform Agent). **Setup:** 1. **N...