CPSA ยท Cryptography for testers
Hashes and HMAC
SHA-1 and MD5 weaknesses, integrity checking, HMAC as a keyed message integrity code.
Key points
- A hash maps data to a fixed-length digest.
- MD5 (128-bit), SHA-1 (160-bit): broken for collision resistance; MD5 collisions are cheap, SHA-1 collisions shown in 2017 (SHAttered).
- Use the SHA-2 family, such as SHA-256.
- Plain hash: integrity only against accidental change, as an attacker can recompute it.
- HMAC (RFC 2104): mixes in a secret key, so only key holders create a valid tag; gives integrity and authenticity.
Source: https://shattered.io/
Practice questions
How long is a SHA-1 digest?
- 128 bits
- 160 bits
- 256 bits
- 512 bits
Show answer
Answer: B. 160 bits
SHA-1 produces a 160-bit (20-byte) digest. MD5 is 128 bits and SHA-256 is 256 bits.
Which statements are correct?
- Practical MD5 collisions can be generated cheaply
- A SHA-1 collision was demonstrated publicly in 2017
- HMAC needs a shared secret key
- SHA-256 produces a 160-bit digest
- A bare hash proves who sent a file
Show answer
Answer: A. Practical MD5 collisions can be generated cheaply, B. A SHA-1 collision was demonstrated publicly in 2017, C. HMAC needs a shared secret key
MD5 and SHA-1 both have demonstrated collisions, and HMAC is keyed. SHA-256 is 256 bits, and a bare hash can be recomputed by anyone so it does not identify a sender.
If a message arrives with a correct SHA-256 hash of its content, the receiver knows it came from the claimed sender.
Show answer
Answer: False
False. Anyone can compute a SHA-256 hash of any message. Only a keyed construction such as HMAC, or a digital signature, ties the tag to someone holding a secret.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
