Applied Cryptography
Using the hash SHA-256(K ‖ m) of a secret key K concatenated with a message m as a tag for detecting tampering is considered dangerous. Which of the following is the reason?
- AIf the tag and the input length are known, the tag of a message with data appended after m can be computed without knowing K
- BAn efficient method is known for working back from the SHA-256 output to just the key K placed at the start of the input
- CPlacing the key K in front of the message makes the input longer, and with SHA-256 this makes collisions easier to find
Show answer and explanation
Answer: A. If the tag and the input length are known, the tag of a message with data appended after m can be computed without knowing K
In a Merkle–Damgård hash function such as SHA-256, the output hash value is exactly the internal state after the last block has been processed. An attacker can therefore take the tag as the internal state and continue the computation, obtaining the hash of K ‖ m followed by padding of a fixed form and arbitrary data, without knowing K (a length extension attack). HMAC, which uses two values derived from the key and hashes the inner hash value once more together with the key, prevents this attack. SHA-3 is not vulnerable to this attack by its construction, so KMAC, which simply puts the key in front, has also been standardized.
- A. Correct. This is called a length extension attack, and it is one of the reasons for using HMAC.
- B. No efficient method of finding the input from the SHA-256 output is known. The problem is not working backwards but being able to continue the computation.
- C. A longer input does not make collisions easier to find.