Score:5

How can a preimage attack on SHA-256 always succeed within 2^256 evaluations when done though brute force?

in flag

I was reading the Wikipedia page for SHA-256 (SHA-2) and came across the following statement:

For a hash function for which $L$ is the number of bits in the message digest, finding a message that corresponds to a given message digest can always be done using a brute force search in $2^L$ evaluations.

Why is this true? Is it some property of SHA-256 or am I missing something? I know that there must be a collision within $2^{256} + 1$ unique inputs, but I don't see why this would mean that there must be a specified digest from some list of unique inputs of length $2^{256} + 1$.

in flag
Strictly speaking, it is not even known [whether SHA-2 is surjective](https://stackoverflow.com/a/2659174/1340389). If it is not surjective, that means there are some digests which it never outputs, and so *no* amount of brute forcing would be able to find a primage of those digests. But SHA-2 is probably surjective because it tries to maximize entropy - it "should" produce all possible outputs with (more or less) uniform probability, given a randomized input, and if it is not surjective, then it fails to accomplish that design goal. You could interpret the quote to exclude such digests.
Score:6
ru flag

This is a lazy expression on the part of the writer. You are correct that if SHA256 is a well-constructed hash function (and we believe that it is) then trying $2^L$ inputs is likely to produce a preimage, but not certain to do so. To be precise if we have $2^L$ distinct inputs, we expect the probability of finding a pre-image to be $$1-\left(1-\frac 1{2^L}\right)^{2^L}\approx 1-\frac1e.$$ More generally the probability distribution $n$, on the number of guesses needed to succeed is given by $$\mathbb P({\rm guesses}\le n)=1-\left(1-\frac 1{2^L}\right)^{n}$$ so that the expected number of guesses is $2^L$.

It is often useful for "back-of-the-envelope" calculations to approximate the distribution with its mean and this habit has led to the writer making a technically incorrect statement.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.