Hashing & crypto

SHA-256, SHA-3, and HMAC: which hash for which job

“Use SHA-256” is good advice for one job and bad advice for another. The algorithm is only part of the design; the key, the framing, and the purpose matter as much.

Quick answer

Use SHA-256 or SHA-512 for ordinary integrity checks and as a building block in signatures. Use SHA-3 when a standard or system calls for it. Use HMAC when you need keyed message authentication. Do not use any general-purpose hash alone for password storage.

The SHA-2 family

SHA-256 and SHA-512 are part of SHA-2. They produce 256-bit and 512-bit digests and are widely supported in browsers, operating systems, and libraries. SHA-256 is a common default for file integrity, certificate signatures, and content identifiers. SHA-512 is also common and may be faster on some 64-bit systems, but the choice usually follows the protocol or platform requirement rather than raw speed.

Truncated variants such as SHA-384 exist and are used in some protocols. A shorter digest is not automatically weaker in every context, but it has a smaller collision space. Follow the specification for the system you are building.

SHA-3 is a different design

SHA-3 is based on the Keccak permutation, not the Merkle–Damgård construction used by SHA-2. It is standardized and secure, but it is not a drop-in performance upgrade or a response to a practical SHA-256 break. Use it when a standard, protocol, or platform calls for it, or when you want algorithm diversity. Do not switch just because the number is higher.

HMAC is a keyed construction

HMAC combines a hash with a secret key. It lets two parties who share a key authenticate a message and detect tampering by someone who does not have the key. It is used in APIs, tokens, and protocol designs. HMAC-SHA-256 is a common choice.

HMAC is not a digital signature. A shared key means both parties can produce a valid tag, so it does not provide public verifiability or non-repudiation. It is also not a password hash. Use the right tool for the property you need.

A short decision table

JobReasonable choiceWhy
Compare a downloaded file with a trusted digestSHA-256 or SHA-512Widely supported; integrity signal
Authenticate a message with a shared secretHMAC-SHA-256Keyed integrity and authenticity
Sign a document or certificateThe signature scheme's required hashFollow the protocol; do not invent the combination
Store account passwordsArgon2id, bcrypt, scrypt, or PBKDF2 with current parametersDeliberately slow, salted, and designed for passwords
Need algorithm diversity or a standard requires itSHA-3Different construction; follow the spec

A small correctness check

In November 2026, the Signal Bench SHA-2 tool produced this digest for the ASCII text Signal Bench using SHA-256:

09f996835a71624fa348c79fdb672744da18a2e2ab31ef0fea6a847374c15733

OpenSSL and shasum -a 256 produced the same value. That is a correctness check for one input and one encoding, not a test of every browser, file type, or character set. If you need to hash bytes rather than text, hash the bytes, not a decoded string.

Common mistakes

  • Using a plain hash for passwords. Fast hashes are the wrong tool; use a password-hashing scheme with a salt and a work factor.
  • Comparing digests without a trusted reference. If the expected value can be replaced, the comparison proves little.
  • Confusing HMAC with a signature. A shared key is not a public verification key.
  • Hashing the wrong representation. Text encoding, line endings, and whitespace change the bytes and the digest.
  • Truncating a digest without understanding the protocol. Follow the specification's length and encoding rules.

Limits

Cryptographic choices depend on the threat model and the protocol. A digest does not provide confidentiality. HMAC does not provide public verifiability. A password hash does not protect a compromised server. If a decision affects money, safety, or records, use current standards and qualified review.

Try a digest: the local tool uses Web Crypto and does not send the text to a hash API. Open the hash generator.

Common questions

Is SHA-3 better than SHA-256?

Both are secure standard hashes. SHA-3 uses a different construction. Choose based on the protocol or platform requirement, not the number in the name.

Can I use HMAC for passwords?

No. HMAC is a keyed message authentication construction. Password storage needs a dedicated password-hashing scheme with a salt and a work factor.

Why do two hashes of the same text differ?

The input bytes probably differ: encoding, line endings, whitespace, or a hidden character. Hash the exact byte sequence you intend to compare.

Sources and further reading

Signal Bench Editorial

We maintain the Signal Bench tools and write the guides around them. Each guide is checked against the tool's actual behavior, and corrections are logged on the site.

About the author