Information Security Basics

For an ideal hash function with a 256-bit output, which combination gives the approximate number of computations needed for a brute-force attack in two cases: finding an input that produces a given hash value (a preimage attack), and finding any two different inputs that produce the same hash value (a collision attack)?

  1. APreimage attack: about 2^256; collision attack: about 2^128
  2. BPreimage attack: about 2^128; collision attack: about 2^256
  3. CAbout 2^256 for both the preimage attack and the collision attack
Show answer and explanation

Answer: A. Preimage attack: about 2^256; collision attack: about 2^128

An ideal hash function with an n-bit output has 2^n possible hash values, and each input tried matches a given hash value with probability 1/2^n. A preimage attack therefore needs about 2^n computations, which for n = 256 is about 2^256. In a collision attack, however, any two inputs may match, so trying k inputs gives about k^2/2 pairs to compare. Once k^2/2 approaches 2^n, that is, when k is around 2^(n/2), a collision becomes likely; for n = 256 that is about 2^128. This is the same idea as the birthday paradox, in which a group of 23 people has a better than 50% chance that two share a birthday, so it is called a birthday attack. Consequently, a hash function's strength against collisions is estimated at half its output length, and achieving 128-bit strength requires a 256-bit output.

  • A. Correct. A preimage attack takes about 2^256 computations, and a collision attack about 2^128 thanks to the birthday attack.
  • B. This swaps the two. The collision attack, where any two inputs may match, needs fewer computations.
  • C. In a collision attack any pair of the inputs tried may match, so about 2^128 computations suffice, far fewer than for a preimage attack.
Practice this topic Back to topic

Related calculators

Books on Information Security Basics Ad

As an Amazon Associate I earn from qualifying purchases.

More Information Security Basics questions

  1. When a web service stores users' passwords, it adds a random value that differs for each user (a salt) to the password before computing and storing the hash value. What is the main purpose of the salt?
  2. For storing passwords, it is recommended not to use a fast hash function such as SHA-256 directly but a scheme deliberately designed to take time to compute, such as bcrypt or Argon2. Why?
  3. An 8-character password is searched for by brute force, trying every candidate. If 1×10^10 candidates can be tried per second, which combination is closest to the time needed to try all candidates for a password made only of lowercase letters (26 kinds) and one made of uppercase letters, lowercase letters and digits (62 kinds)?
  4. A attaches a digital signature to a document sent to B. Which combination correctly gives the keys used to create and verify the signature and what the digital signature can confirm?
  5. Which statement correctly compares a message authentication code (MAC) with a digital signature?