Message Authentication Codes




 Message Authentication Codes (MAC)

What is Message Authentication?

Message authentication ensures that:

  • The message comes from the correct sender
  • The message is not altered
  • The message is fresh (not replayed)

Authentication Requirements

RequirementMeaningReal-Life Example
Data IntegrityMessage not changedSealed courier
AuthenticationSender identity verifiedOTP verification
Non-repudiationSender cannot denyDigital signature
FreshnessNo replay attackSession token

Authentication Functions

Authentication functions verify data integrity and sender identity.

Types of Authentication Functions

MethodKey UsedSecurity Level
EncryptionSecret keyMedium
MACSecret keyHigh
Hash functionNo keyIntegrity only
Digital SignaturePublic/privateVery high

Message Authentication Code (MAC)

A MAC is a fixed-size code generated using:

  • Message
  • Secret key

MAC Formula

MAC=F(K,M)

Where:

  • K = secret key
  • M = message

Verification: Receiver recomputes MAC and compares.

Example 

  • Bank message + secret PIN
  • If PIN matches → message accepted

Real-Life Use

  • ATM communication
  • Online payments
  • Secure APIs

Hash Functions

A hash function converts data of any size into a fixed-length value.

Hash Function Properties

PropertyMeaning
Fixed lengthOutput size constant
One-wayCannot reverse
Fast computationQuick processing
Avalanche effectSmall change → big difference

Hash Formula

h=H(M)

Real-Life Example

  • Password storage
  • File integrity check
  • Blockchain

Birthday Attacks

A birthday attack exploits the probability of hash collisions.

Birthday Paradox

  • Only 23 people needed for same birthday probability > 50%

In Hashing

For n-bit hash, collision possible in:

2n/22^{n/2}

Example: 128-bit hash → attack possible at 2⁶⁴ tries

Impact

  • Breaks digital signatures
  • Weakens hash security

Security of Hash Functions

Security Requirements

PropertyDescription
Pre-image resistanceCannot find message from hash
Second pre-image resistanceCannot find same hash
Collision resistanceNo two inputs same hash

Weak Hash Example

  • MD5
  • SHA-1 (deprecated)

Secure Hash Algorithm (SHA)

What Is SHA?

SHA is a family of cryptographic hash algorithms developed by NIST.

SHA Variants

AlgorithmOutput SizeStatus
SHA-1160-bitBroken
SHA-256256-bitSecure
SHA-512512-bitSecure
SHA-3VariableVery Secure

SHA-256 Working (Simplified)

  • Message padding
  • Divide into blocks
  • Compression function
  • Produce hash

Real-Life Use

  • Password hashing
  • Blockchain (Bitcoin)
  • SSL certificates
  • Digital signatures

Comparison Table: Hash vs MAC

FeatureHashMAC
Secret keyNoYes
IntegrityYesYes
AuthenticationNoYes
Used inPasswordsSecure communication

Final Quick Revision Table

TopicKey Point
AuthenticationVerify sender + data
MACKeyed integrity
HashOne-way function
Birthday AttackCollision attack
Hash SecurityPre-image resistance
SHASecure hash family

Digital Signatures

What is a Digital Signature?

A digital signature is a cryptographic technique used to:

  • Verify the identity of the sender
  • Ensure message integrity
  • Provide non-repudiation (sender cannot deny)

Simple Meaning: A digital signature is like a handwritten signature, but for digital documents, secured using mathematics and cryptography.

Why Digital Signatures Are Needed

RequirementExplanationReal-Life Example
AuthenticationConfirms senderEmail sender verification
IntegrityMessage not alteredLegal document protection
Non-repudiationSender cannot denyOnline contracts
SecurityTamper-proofBanking transactions

How Digital Signature Works (Basic Flow)

  • Sender hashes the message
  • Hash is encrypted using private key
  • Receiver decrypts using public key
  • Hash is compared

Digital Signature Formula

Signature=EncryptPrivateKey(Hash(Message))

Real-Life Applications

  • Online banking
  • E-tendering
  • Income tax filing
  • Software updates
  • Legal documents

ElGamal Digital Signature Technique

What is ElGamal Digital Signature?

ElGamal is a public key digital signature algorithm based on the Discrete Logarithm Problem (DLP).

Security Basis

  • Security relies on difficulty of solving:

gxmodp

ElGamal Signature Components

SymbolMeaning
pLarge prime number
gPrimitive root of p
xPrivate key
yPublic key = g^x mod p
H(m)Hash of message

ElGamal Signature Generation Steps

  • Choose large prime p and generator g
  • Select private key x
  • Compute public key:

y=gxmodp
  • Choose random k such that gcd(k, p−1)=1
  • Compute:
r=gkmodpr = g^k \mod p
  • Compute:
s=(H(m)xr)k1mod(p1)

Signature = (r, s)

ElGamal Signature Verification

Verify:

gH(m)yrrsmodp

If true → signature valid.

Real-Life Use

  • Secure email systems
  • Digital certificates
  • Basis for DSA

Digital Signature Standard (DSS)

What is DSS?

DSS (Digital Signature Standard) is a U.S. government standard published by NIST.

Algorithm Used

  • DSA (Digital Signature Algorithm)
    (Based on ElGamal concept)

DSS Key Features

FeatureDescription
Hash functionSHA-1 / SHA-2
Key typePublic key
Security baseDiscrete logarithm
UsageDigital signatures only

DSS Working (Simplified)

  • Message hashed using SHA
  • Signature generated using DSA
  • Verification done using public key

DSS vs RSA

FeatureDSSRSA
PurposeSignature onlyEncrypt + Sign
SpeedFaster signingFaster verification
Security baseDLPFactorization

Proof of Digital Signature Algorithm

What is Proof?

Proof shows that:

  • Only sender could create signature
  • Receiver can verify signature
  • Signature cannot be forged

Proof Concept (Simplified)

Let:

S=EncryptPrivateKey(Hash(M))

Receiver computes:

DecryptPublicKey(S)

If:

DecryptPublicKey(S)=Hash(M)

Then:

  • Message is authentic
  • Signature is valid
  • Sender cannot deny

Mathematical Proof (RSA-Based)

Encryption:

S=H(M)dmodn

Verification:

H(M)=SemodnH(M) = S^e \mod n

Since:

(de)1modφ(n)

Correctness is guaranteed.

Why Digital Signature Is Secure

ReasonExplanation
Private key secrecyOnly owner can sign
HashingMessage integrity
Public verificationAnyone can verify
Mathematical hardnessCannot forge

Final Revision Table

TopicKey Idea
Digital SignatureAuthentication + Integrity
ElGamal SignatureDLP based
DSSNIST standard
ProofMathematical correctness
SecurityNon-repudiation

MCA Exam Writing Tips

  • Start with definition
  • Write algorithm steps
  • Include formula
  • Add real-life example
  • Draw simple block diagram