CS FundamentalsVery hardProduct-company placement · Security interview

A developer authenticates API messages as tag = SHA-256(secret ‖ message) instead of using HMAC. Why is this unsafe?

  1. A. SHA-256 is not collision-resistant, so two messages share a tag
  2. B. The secret can be recovered from the tag by inverting SHA-256
  3. C. An attacker who knows one message and its tag can compute a valid tag for that message with extra data appended, without the secret
  4. D. The tag is too short to resist brute force

Correct answer: C. An attacker who knows one message and its tag can compute a valid tag for that message with extra data appended, without the secret

Merkle–Damgård hashes like SHA-256 expose their internal state as the output, so from H(secret ‖ m) one can continue hashing to get H(secret ‖ m ‖ padding ‖ extra): a length-extension attack. HMAC's nested construction blocks this; SHA-256 itself is still collision- and preimage-resistant.

More Computer Networks questions

Exams that ask this topic