knowledge

Overview

Hashing transforms plaintext into a fixed-size digest using a one-way function, making it irreversible by design. It is used to protect data integrity, support confidentiality, and securely store passwords. Unlike encryption, hashed data cannot be decrypted — only compared against a new hash of the same input.


Terminology

TermDefinition
Hash FunctionTakes input of arbitrary size and produces a fixed-size output (digest)
Hash Value / DigestFixed-size string output produced by a hash function
Hash CollisionWhen two different inputs produce the same hash output
SaltRandom value added to a password before hashing; unique per user
Password SaltingAdding salt to prevent precomputed attacks such as rainbow tables
HMACKeyed-Hash Message Authentication Code; combines a secret key with a hash function
NThashModern Windows password hash format; MD4-based
Rainbow TablePrecomputed table of hash values used to reverse hash lookups

Core Concepts

Hashing Algorithms

AlgorithmCommandOutput Length
MD5md5sum32 hex characters
SHA1sha1sum40 hex characters
SHA256sha256sum64 hex characters
SHA512sha512sum128 hex characters

Salting

  • A salt is a random value added to a password before hashing
  • Unique per user — prevents two users with the same password from having the same hash
  • Defeats precomputed rainbow table attacks
  • Salt is stored alongside the hash so verification can reproduce it

HMAC (Keyed-Hash Message Authentication Code)

Combines a secret key with a hash function to verify both integrity and authenticity.

Process:

  1. Key is padded to block size
  2. Key is XORed with a constant
  3. Message is hashed with the modified key
  4. Result is hashed again with a second modified key
  5. Output is a fixed-size HMAC value

Linux Password Storage

Passwords stored in /etc/shadow — see Linux Fundamentals for file structure detail.

Format: $prefix$options$salt$hash Fields separated by colons. View algorithm info: man 5 crypt

AlgorithmPrefix
yescrypt$y$
gost-yescrypt$gy$
scrypt$7$
bcrypt$2b$
sha512crypt$6$
md5crypt$1$
SunMD5$md5

Windows Password Storage

  • Stored in SAM (Security Accounts Manager) — see Windows Fundamentals
  • Uses NTLM (MD4-based) hashing
  • Modern format: NThash

Hash Identification Quick Reference

Hash TypeLengthNotes
MD532 hex charsLegacy, fast — avoid for passwords
SHA140 hex charsDeprecated for security use
SHA25664 hex charsCommon integrity verification
SHA512128 hex charsStrong password hashing

  • Password Cracking

References / Images