Ravindra BagaleCourses & study guides

33. Cryptography Basics

33.2 Hashing, Salts and Password Storage

A hash function turns any input into a fixed-length fingerprint. Good hashes are one-way, and a tiny change in input gives a completely different output (the "avalanche effect").

Algorithm Output Status
MD5 128-bit Broken – collisions are practical; never for security
SHA-1 160-bit Broken for collisions; being retired
SHA-256 / SHA-3 256-bit Safe for integrity and signatures
bcrypt, scrypt, Argon2, PBKDF2 Variable Designed for passwords – slow on purpose

Uses: checking downloads (compare the published SHA-256 of the Kali ISO), file integrity (Wazuh FIM, Chapter 31), digital forensics (hash evidence before and after, Chapter 28), and password storage.

Passwords need special care. A plain fast hash like SHA-256 lets Hashcat try billions of guesses per second (Chapter 22). So we use:

  • a salt – a random value added per user, so the same password gives different hashes and rainbow tables fail;
  • a slow algorithm (bcrypt/Argon2) with a work factor, so each guess is expensive.
sha256sum kali-linux-installer-amd64.iso     # compare with the value on kali.org
php -r 'echo password_hash("Pune123", PASSWORD_BCRYPT), PHP_EOL;'   # different every run (salt)
openssl passwd -6 -salt Xy12 Pune123         # SHA-512 crypt, like /etc/shadow ($6$)

A HMAC (hash + secret key) proves both integrity and that the sender knew the key – used in API signatures and JWT tokens (HS256).

Ravindra Bagale's Tip

Students md5($password) kiwa sha256($password) ne password save kartat ani vichartat "hash ahe na, mag safe?" Nahi! Fast hash crack karayla sopa. PHP madhe nehmi password_hash() ani password_verify() vapra – salt ani bcrypt apoaap yetat.

Lab

In your lab, create two users with the same password and compare their lines in /etc/shadow – note the different salts. Then use john (Chapter 22) on an MD5 hash and a bcrypt hash of the same weak password and compare how long each takes.