K050 / Hashes, MACs and key derivation
SHA-2
SHA-2 is a family of cryptographic hash functions including SHA-224/256/384/512 and SHA-512/224, SHA-512/256.
CRYPTOGRAPHY LAB / K050
Cryptography Lab · SHA-2
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.
SHA-256
See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.Output
Previous state
- Definition and overview
- SHA-2 is a family of cryptographic hash functions including SHA-224/256/384/512 and SHA-512/224, SHA-512/256. Source document ↗
- Classification and reversibility
- SHA-256 is a hash function, not encryption; it has no key or decryption and is not reversible. Source document ↗
- Key or secret requirements
- No key or secret is required, and there is no decryption key. Source document ↗
- Operating principle and structure
- SHA-256 uses 512-bit blocks, 32-bit words and 64 rounds; SHA-512 uses 1024-bit blocks, 64-bit words and 80 rounds. Source document ↗
- Key size, block size and parameters
- The SHA-2 family comprises six hash functions producing 224-, 256-, 384- or 512-bit digests. Source document ↗
- Security strength and recommendation
- NIST recommends SHA-2 or SHA-3 instead of SHA-1 for federal agencies. Source document ↗
- Known attacks and vulnerabilities
- SHA-256 is susceptible to length-extension attacks; particular care is required when hashing secret messages. Source document ↗
- Standards and certification
- FIPS 180-4 specifies the SHA-2 family as standard hash algorithms. Source document ↗
- Typical uses
- Used in certificate signatures, software checksums, Bitcoin proof of work and some signature schemes. Source document ↗
- Implementations, libraries and tools
- Python's hashlib provides sha256() to create a SHA-256 hash object. Source document ↗
- Decryption or decoding
- SHA-256 cannot be decrypted; verification consists of recomputing and comparing the digest for the same input. Source document ↗
- Advantages
- No practical collision attack against SHA-256 is known. Source document ↗
- Limitations and cautions
- Plan algorithm replacement and upgrades in advance. Source document ↗
- Distinguishing encryption, encoding and hashing
- SHA-256 is hashing rather than encryption; do not confuse it with keys or decryption. Source document ↗
Practical examples
Example
Feeding a message into SHA-256 produces a fixed-length 256-bit digest. Identical input produces identical digests, and the original cannot be recovered from the digest alone. It is used to compare hashes of original content in file checksums or signature verification.
Procedure
SHA-256 is hashing, not encryption/decryption: (1) input bytes to obtain a fixed-length digest; (2) if needed, compare the recomputed digest with the stored value to check integrity. Encryption transforms plaintext into ciphertext using a key, decryption reverses it with a key, and encoding changes representation with decoding as its inverse; distinguish these from SHA-256.
Scenario
Publish the SHA-256 checksum of a distribution file and have the user hash the downloaded file again and compare to verify integrity. It is used as a hashing component in TLS and certificate signing; use a dedicated KDF instead of SHA-256 alone for password storage.
Pitfalls and alternatives
Do not mistake SHA-256 for encryption or a standalone password-storage KDF. Use keyed MACs such as HMAC-SHA-256 for secret-based integrity and authentication, and dedicated KDFs such as bcrypt, scrypt or Argon2 for password storage. Be aware of length-extension attacks and compare digests in constant time.
References
- Hash Functions | CSRC ↗
- What is SHA- 256? ↗
- SHA-2 (SHA-256): Hash functions, variants and code | NextSSL ↗
- SHA-2 ↗
- Hash Functions | CSRC ↗
- SHA-256 - PyCryptodome ↗
- SHA-256 — The Cipher Museum ↗
- hashlib — Secure hashes and message digests — Python 3.15.2 documentation ↗
- SHA-256 Explained: How It Works and Why It Matters ↗
- Message digests (Hashing) — Cryptography 43.0.0 documentation ↗