Bitzu

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

Single choice

How long is a SHA-1 digest?

  1. 128 bits
  2. 160 bits
  3. 256 bits
  4. 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.

Select all that apply

Which statements are correct?

  1. Practical MD5 collisions can be generated cheaply
  2. A SHA-1 collision was demonstrated publicly in 2017
  3. HMAC needs a shared secret key
  4. SHA-256 produces a 160-bit digest
  5. 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.

True or false

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.

Download on the App StoreGet it on Google Play

More CPSA topics in this module