Applications of cryptographic hash functions
A cryptographic hash function is a function that takes input data and produces a fixed-size
hash (digest). It is:
Deterministic (Same input gives the same output if you run it on different computers
at different times)
Fast computation
Collision-resistant
1. Data Integrity Verification
Data integrity verification ensures that data has not been changed or corrupted
during transmission.
A cryptographic hash function is used to check whether the data is still the same as
when it was created.
Step-by-Step:
1. Original Hash Creation:
o Sender computes the hash value of the original data using a hash function
(e.g., SHA-256).
o This hash (called digest) is sent along with the data.
2. Verification Later:
o When the data is received, the receiver recomputes the hash.
o If the new hash matches the original one → Data is not modified.
o If the hashes don’t match → Data is modified.
Hash Functions Used:
SHA-256 (most common), SHA-1 (older), MD5
2. Digital Signatures
A digital signature is like an electronic fingerprint that proves:
• Who sent the message.
• That the message wasn't changed.
• That the sender can’t deny sending it later (non-repudiation).
It’s used to verify:
• The identity of the sender.
• The integrity of the message.
• The authenticity of the signature.
There are three main steps in Digital signature algorithm
1. Key Generation
2. Signature Generation
3. Signature Verification
Working
The sender uses a signature generation algorithm to sign the message.
The message and the signature are sent to the receiver.
The receiver receives the message and the signature and applies the verifying
algorithm to the combination.
If the signature is verified then the message is accepted; otherwise, it is rejected
3. Password Storage
Password storage means saving passwords securely so that hackers cannot read
them if they get access to the database.
Working
1. User creates a password
Example: hello123
2. Hash the password using a hash function like SHA-256
3. Store only the hash, not the real password.
4. When the user logs in, hash the entered password again and compare it with the
stored hash.
If they match → Correct password
If not → Wrong password
4. Message Authentication Codes (HMAC)
HMAC is a message authentication code. It ensures:
Integrity → Message has not been changed.
Authenticity → Message came from the right sender.
HMAC uses:
A secret key (K)
A hash function (H) like SHA-256 or MD5
The message (M)
Step-by-Step Working of HMAC
Step 1: Agree on a Secret Key
Both sender and receiver share a secret key (just like a password).
Example:
Key = "mySecretKey"
Step 2: Prepare the Message
You have some message to send.
Example:
Message = "Hello World"
Step 3: Choose a Hash Function
Example: SHA-256 (a cryptographic hash function)
Step 4: Process with Inner and Outer Padding
HMAC uses two constants:
ipad (inner padding) = 0x36 repeated
opad (outer padding) = 0x5C repeated
Then it does this:
Hash((Key ⊕ ipad) + Message)
1. Inner hash =
Hash((Key ⊕ opad) + InnerHash)
2. Outer hash =
Step 5: Final Result
The result of the outer hash is the HMAC value.
This is sent along with the message.