← Cryptography guide

K049 / Hashes, MACs and key derivation

SHA-1

SHA-1 hash · Survey date 2026-12-05

SHA-1 is a hash function mapping arbitrary-length input to a 160-bit message digest.

CRYPTOGRAPHY LAB / K049

Cryptography Lab · SHA-1

Run real computations and inspect intermediate states step by step.

Educational only. Never enter real passwords or secret keys. Computation stays in your browser; input and trace values are not sent to a server. Do not use this implementation in production.

Scope: Legacy / non-secure

SHA-1 (legacy)

See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.

Reference ↗

Open lab →

Definition and overview
SHA-1 is a hash function mapping arbitrary-length input to a 160-bit message digest. Source document ↗
Classification and reversibility
One-way hash; original cannot be recovered by decryption. Source document ↗
Key or secret requirements
SHA-1 itself needs no key; keyed MACs such as HMAC-SHA1 require secret key. Source document ↗
Operating principle and structure
Compression/iteration processes 512-bit chunks as sixteen 32-bit words. Source document ↗
Key size, block size and parameters
512-bit blocks and 160-bit chaining value/final digest. Source document ↗
Security strength and recommendation
NIST is retiring SHA-1 with planned completion by 2030; recommends SHA-2/SHA-3. Source document ↗
Known attacks and vulnerabilities
Collision attacks are feasible, greatly reducing security. Source document ↗
Standards and certification
Specified in FIPS 180-4 Secure Hash Standard. Source document ↗
Typical uses
Used for integrity checks, signature verification and MACs. Source document ↗
Implementations, libraries and tools
Libraries such as crypto-es expose SHA1()/HmacSHA1(). Source document ↗
Decryption or decoding
No decryption or decoding; verify only by comparing stored and recomputed digest. Source document ↗
Advantages
Fixed-length digest sensitive to input changes aids integrity checks. Source document ↗
Limitations and cautions
Vulnerable to length extension; unsuitable for secret-message hashing or simple password storage. Source document ↗
Distinguishing encryption, encoding and hashing
Do not mistake SHA-1 hash for encrypted data and attempt decryption. Source document ↗

Practical examples

Examples are illustrative; they are not execution-tested implementations or operational recommendations.

Example

Hash message/file to fixed 160-bit digest. Compare stored digest against recomputed value to check integrity.

Procedure

Compute SHA-1 digest, store/send, recompute and compare; no encryption/decryption. For keyed authentication consider HMAC-SHA1 only for compatibility; new designs use SHA-256 or stronger.

Scenario

Only read/verify SHA-1 for legacy checksums; use SHA-256/SHA-3 for new integrity checks, signatures and TLS. Treat SHA-1 as comparison/verification, not decryption.

Pitfalls and alternatives

Do not use SHA-1 as primary password, signature, certificate or security MAC algorithm. Due to collisions, length extension and NIST retirement replace with SHA-256/SHA-3; passwords use Argon2/bcrypt/scrypt/PBKDF2.

Diagram source ↗

References