Comprehensive Notes on Cryptographic Hash Functions, HMAC, SHA-512, and Digital Signatures
Fundamentals of Cryptographic Hash Functions
Definition: A cryptographic hash function is a mathematical algorithm that transforms input data into a fixed-length sequence of characters, known as a hash value or message digest.
The primary formula for the operation is represented as:
Core Operational Characteristics:
Input: Can be data of any size, including text, files, or passwords.
Output: Always a fixed size (for example, 256 bits or 512 bits).
Speed: The function is intended to be fast to compute.
Deterministic: The hash function consistently computes the same hash for the exact same input. Any alteration to the input leads to a totally unique hash.
One-Way Computation (Irreversibility): The algorithm is designed to be irreversible, meaning it is computationally impossible to recover the original input data from its hash value.
Avalanche Effect: A slight variation in the input yields a complete and significantly different hash value.
Collision Resistance: Functions are designed to minimize the probability of distinct inputs generating the same hash value. It is very unlikely for two different inputs to produce the same hash.
Working Modules:
Input Processing: The function can process data of any length.
Fixed Output Size Generation: The function generates a fixed output size, providing equality regardless of the input size.
Comparison of Integrity and Authentication: MDC and MAC
Modification Detection Code (MDC):
Concept: Based on message integrity to determine whether the message has been modified or not.
Also known as Message Hash Function or Message Digest.
Workflow: Message A is sent to B after performing the hash. The MDC is shared secretly, either by encrypting it using Symmetric or Public Key Cryptography.
Message Authentication Code (MAC):
Concept: Used to verify that a message was actually sent by the claimed sender (A).
Functionality: MAC performs both the modification detection (integrity) and provide authentication.
Workflow: Sender and Receiver share a secret key, similar to Symmetric Cryptography.
The formula involved includes the Key () and the Message ():
Security Risk: If the key size is too small, the system is subjected to brute-force attacks.
Hash-Based Message Authentication Code (HMAC)
Definition: HMAC is a specific technique for message authentication that ensures both data integrity and authentication using a hash function and a secret key.
HMAC Algorithm Components:
Key: Left-padded with zeros to match the block size.
ipad (Inner Pad): Defined as the bit pattern (Hexadecimal: ).
opad (Outer Pad): Defined as the bit pattern (Hexadecimal: ).
: The message, often divided into blocks ().
Numerical Example of HMAC:
Definitions: , , , , .
Step 1: Compute .
Step 2: Compute inner hash: .
Step 3: Compute .
Step 4: Final HMAC: .
Secure Hash Algorithm-512 (SHA-512) Architecture
Overview: SHA-512 is a hacking technique that converts text of arbitrary length into a fixed-size string of 512 bits (64 bytes).
Basic Properties:
Deterministic.
Irreversible.
Collision resistant.
Avalanche effect.
Message Processing and Iteration:
The variable-length message is divided into fixed block sizes of 1024 bits.
This is an iterative process where each 1024-bit block (Block 1, Block 2, $\dots$, Block N) goes through a compression function ().
The initial value is 512 bits.
The final output is the 512-bit Message Digest.
Padding and Length Field:
The last block may not contain exactly 1024 bits, necessitating padding.
Padding Rule: The original message needs to be padded if necessary, and finally, the length of the original message is attached.
The length field is assigned a size of 128 bits. The original length of the message () should be less than bits.
Padding bits () calculation example:
Let bits.
.
padding bits.
Padding structure: A single "1" followed by 819 zeros ().
SHA-512 Compression Function and Word Expansion
Word Conversion:
Each 1024-bit block is converted into 16 words, where each word is 64 bits ().
The 512-bit initial values/intermediate states are converted into 8 words labelled (each 64 bits).
Word Expansion Logic:
1024 bits are expanded into 80 words ( to ).
through are taken directly from the 1024-bit message block.
For to , words are generated using the formula:
The addition is performed to ensure the output stays within 64 bits.
Rotation and Shift Operations:
: Perform Right Circular Shift times.
: Shift left positions (fill with zeros; not circular).
Example of : Becomes .
Initial Constants ():
Generated by taking the square root of the first 8 prime numbers () and expanding the fractional part to 64 bits.
Example values:
Iterative Rounds:
There are 80 rounds ( to ).
Each round uses one word and one constant .
values are derived from the cube roots of the first 80 prime numbers.
SHA-512 Logic Functions
Operations performed in each round involve bitwise logic:
Digital Signature Principles
Technology: Based on Asymmetric Key Cryptography.
Process:
Signing: The sender uses their Private Key to sign the message/digest.
Verification: The receiver uses the sender's Public Key to decrypt and verify the signature.
Purpose:
Authentication: Proof of identity.
Non-repudiation: The sender cannot deny signing the message.
Implementation:
Digital Signatures are typically one-to-one (one signature per file).
Signatures are normally applied to the Message Digest () rather than the original message (). This is because the is unique and has a fixed length.
Non-repudiation can be proven via a Trusted Third Party.
RSA Digital Signature Scheme Example
Scenario: Sender signs a message using their private key; receiver verifies with the sender's public key.
Example Setup:
Choose primes: .
Compute .
Compute Euler's totient: .
Choose public exponent such that . Let .
Find private exponent such that .
; since , then .
Keys:
Public Key:
Private Key:
Signing Process:
Message .
Assume hash .
Signature .
Calculation: . with remainder . So .
Verification Process:
Receiver receives and .
Receiver calculates expected hash: .
Receiver verifies signature: .
Calculation: . with remainder .
Comparison: Since , the signature is valid.