Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Lập Trình

Các thuật toán Hashing phổ biến

Cryptographic Hash Functions (Hàm băm mật mã)

Thuật toánĐầu raThiết kếĐặc điểm nổi bậtTrạng thái 2024
SHA-256256-bitMerkle-DamgårdTiêu chuẩn NIST, TLS, Bitcoin, JWT, Git, hardware accelMặc định #1
SHA-512512-bitMerkle-DamgårdNhanh trên 64-bit, SHA-512/256 chống length extensionThay thế SHA-256 trên 64-bit
SHA3-256256-bitSponge (Keccak)Không length extension, đa dạng hóa, side-channel resistantDự phòng, PQC-friendly
SHAKE256Tuỳ ý (XOF)SpongeExtendable output, domain separation tự nhiênKhuyên dùng cho KDF, protocol design
BLAKE2b512-bit (tùy chỉnh)HAIFA (Merkle-Damgård improved)Nhanh hơn SHA-1/MD5, keyed mode (MAC), salt, personalizationHiệu năng cao, thay thế SHA-256
BLAKE3256-bit (XOF)Tree-hash + BLAKE2Song song, SIMD, cực nhanh (~1 cpb), keyed, derive keyXuân tinh 2024+ cho performance

Password Hashing / Key Derivation Functions (KDF)

Thuật toánLoạiĐặc điểmKhuyên dùng
Argon2idMemory-hard KDFPHC winner, time+memory+parallelism tunable, side-channel resistant#1 Mặc định
bcryptBlowfish-based KDFWork factor (log₂ rounds), 72-byte limit, widely supported#2 Tương thích rộng
scryptMemory-hard KDFN, r, p params, Litecoin, memory-hard gốcTốt, ít support hơn Argon2
PBKDF2-HMAC-SHA256Time-hard KDFChỉ iteration count, FIPS approved, no memory hardnessChỉ khi bắt buộc FIPS/legacy

Non-Cryptographic / Checksum (Không dùng cho bảo mật)

Thuật toánĐầu raDùng cho
xxHash (XXH3/XXH64)64/128-bitHash table, deduplication, database index, checksum nhanh
MurmurHash332/128-bitHash table, Bloom filter, Cassandra, HBase
FNV-1a32/64-bitHash table đơn giản, embedded
CRC32C (Castagnoli)32-bitNetwork/storage error detection, hardware accel (Intel SSE4.2, ARM CRC)
SipHash64/128-bitHash table chống DoS (HashDoS), keyed, fast

Legacy / Broken (Cấm dùng cho bảo mật mới)

  • MD5 (128-bit): Collision practical (2004), chosen-prefix (2008). Chỉ dùng checksum non-security.
  • SHA-1 (160-bit): Collision SHAttered (2017). HMAC-SHA1 chấp nhận được nhưng deprecated.
  • RIPEMD-160: Chỉ dùng Bitcoin legacy (Hash160).
  • LANMAN / NTLMv1: Windows legacy, cực yếu, dễ brute-force.

Khuyến nghị nhanh

# General purpose crypto hash
sha256(data)           # Default, everywhere
blake3(data)           # High performance, parallel, XOF
shake256(data, 32)     # Need XOF / domain separation

# Password storage
argon2id(password, salt, t=3, m=64MB, p=4)  # Default
bcrypt(password, cost=12)                    # Compatibility

# Non-crypto checksum / hash table
xxh3(data)             # Fastest general
crc32c(data)           # Hardware accelerated error detection
siphash(key, data)     # HashDoS resistant hash table