Chapter 16 Β· Concepts

Hashing & Digital Signatures β€” Core Concepts

Comparison tables, process flows, and visual guides for the exam.

Hash Function Properties

1. Deterministic

The same input always produces the same output hash. Hash("hello") = 2cf24dba... every single time, on any machine, with any implementation. This is what makes hash comparison reliable.

2. One-Way (Pre-image Resistant)

Given a hash, you cannot work backward to find the original input. There is no "unhash" operation. The only way to find an input that produces a given hash is to try inputs until one matches β€” which is computationally infeasible for a strong hash.

3. Avalanche Effect

Changing a single bit of input completely changes the output β€” roughly half of all output bits flip. Hash("hello") and Hash("Hello") (just capital H) produce completely different digests with no resemblance. Small changes are magnified into completely different fingerprints.

4. Collision-Resistant

Computationally infeasible to find two different inputs that produce the same hash. The SHA-256 output space has 2^256 possible values β€” finding a collision by chance or computation is astronomically unlikely. MD5 lost this property β€” practical collisions exist.

Hash Algorithms: Comparison

AlgorithmOutput SizeStatusUse Today?
MD5128 bits (32 hex chars)BROKEN β€” collisions found (2004)No β€” not for security. Sometimes for non-security checksums only.
SHA-1160 bits (40 hex chars)DEPRECATED β€” collision demonstrated (2017 SHAttered attack)No β€” browsers and CAs stopped accepting SHA-1 certificates.
SHA-256256 bits (64 hex chars)SecureYes β€” primary standard for most security uses.
SHA-384384 bits (96 hex chars)SecureYes β€” used where extra margin desired.
SHA-512512 bits (128 hex chars)SecureYes β€” high-security applications.
SHA-3Variable (224–512 bits)Secure (different design)Yes β€” alternative to SHA-2 with different internal structure.

Password Hashing: Without and With Salt

ScenarioWithout SaltWith Salt
User A password: "pass123"Hash("pass123") = abc123Hash("pass123" + saltA) = x7q2ab
User B password: "pass123"Hash("pass123") = abc123 (SAME)Hash("pass123" + saltB) = p9r3kl (DIFFERENT)
Rainbow table attackLook up abc123 β†’ "pass123" instantlyMust generate rainbow table for every unique salt β€” infeasible
Database breach impactAll users with same password exposed simultaneouslyEach user must be cracked individually with their salt
The salt is stored in the database alongside the hash β€” it is NOT secret. Its purpose is uniqueness, not secrecy. The attacker has both the salt and the hash. But the salt still defeats precomputed attacks because every user has a different salt.

Digital Signature Process

SIGN
Step 1 β€” Sender hashes the document
Alice computes SHA-256 of the document. This produces a unique 256-bit digest that represents this exact version of the document.
↓
SIGN
Step 2 β€” Sender encrypts the hash with their private key
Alice encrypts the hash using her own private key. This creates the digital signature. Only Alice can do this β€” she is the only one with her private key.
↓
SEND
Step 3 β€” Document + signature sent to recipient
Bob receives both the original document and Alice's digital signature attached to it.
↓
VERIFY
Step 4 β€” Recipient decrypts signature with sender's public key
Bob uses Alice's public key (which is publicly available) to decrypt the signature. This reveals the hash Alice computed in Step 1.
↓
VERIFY
Step 5 β€” Recipient computes their own hash of the document
Bob independently computes SHA-256 of the received document.
↓
VERIFY
Step 6 β€” Compare hashes
If Alice's hash (decrypted from signature) = Bob's computed hash β†’ document is authentic and unmodified. If they differ β†’ document was changed or signature is forged.

What Digital Signatures Prove

PropertyWhat It MeansHow the Signature Provides It
IntegrityThe document hasn't been modifiedAny change to the document changes the hash β€” the hash comparison fails
AuthenticationThe document came from who it claimsOnly the holder of Alice's private key could have created a signature that Alice's public key can verify
Non-RepudiationThe signer cannot deny having signedThe private key is uniquely Alice's β€” mathematical proof that she signed it, not forgeable without her key

Hashing vs. Encryption vs. Digital Signatures

PropertyHashingEncryptionDigital Signature
Reversible?No (one-way)Yes (with key)Hash portion: No. Signature: Yes (verify with public key)
Keys required?NoneSymmetric key OR public/private key pairPrivate key to sign; public key to verify
Provides confidentiality?NoYesNo
Provides integrity?Yes (comparison)No (just confidentiality)Yes
Provides authentication?NoNo (alone)Yes
Provides non-repudiation?NoNoYes