A birthday attack is a brute-force collision attack that exploits the mathematics behind the birthday problem in probability theory. This attack can be used to abuse communication between two or more parties. The attack depends on the higher likelihood of collisions found between random attack attempts and a fixed degree of permutations (pigeonholes). Let H be the number of possible values of a hash function, with H=2l. With a birthday attack, it is possible to find a collision of a hash function with 50% chance in 2l=2l/2, where l is the bit length of the hash output, and with 2l−1 being the classical preimage resistance security with the same probability. There is a general (though disputed) result that quantum computers can perform birthday attacks, thus breaking collision resistance, in 2l3=2l/3. Although there are some digital signature vulnerabilities associated with the birthday attack, it cannot be used to break an encryption scheme any faster than a brute-force attack.
Understanding the problem
As an example, consider the scenario in which a teacher with a class of 30 students (n = 30) asks for everybody's birthday (for simplicity, ignore leap years) to determine whether any two students have the same birthday (corresponding to a hash collision as described further). Intuitively, this chance may seem small. Counter-intuitively, the probability that at least one student has the same birthday as any other student on any day is around 70% (for n = 30), from the formula 1−365!(365−n)!⋅365n. If the teacher had picked a specific day (say, 16 September), then the chance that at least one student was born on that specific day is 1−(364/365)30, about 7.9%. In a birthday attack, the attacker prepares many different variants of benign and malicious contracts, each having a digital signature. A pair of benign and malicious contracts with the same signature is sought. In this fictional example, suppose that the digital signature of a string is the first byte of its SHA-256 hash. The pair found is indicated in green – note that finding a pair of benign contracts (blue) or a pair of malicious contracts (red) is useless. After the victim accepts the benign contract, the attacker substitutes it with the malicious one and claims the victim signed it, as proven by the digital signature.
Relation to the balls into bins problem The birthday attack can be modelled as a variation of the balls into bins problem, where balls (hash function inputs) are randomly placed into bins (hash function outputs). A hash collision occurs when at least two balls are placed into the same bin.
Mathematics Given a function f, the goal of the attack is to find two different inputs x1,x2 such that f(x1)=f(x2). Such a pair x1,x2 is called a collision. The method used to find a collision is simply to evaluate the function f for different input values that may be chosen randomly or pseudorandomly until the same result is found more than once. Because of the birthday problem, this method can be rather efficient. Specifically, if a function f(x) yields any of H different outputs with equal probability and H is sufficiently large, then we expect to obtain a pair of different arguments x1 and x2 with f(x1)=f(x2) after evaluating the function for about 1.25H different arguments on average. We consider the following experiment. From a set of H values we choose n values uniformly at random thereby allowing repetitions. Let p(n; H) be the probability that during this experiment at least one value is chosen more than once. This probability can be approximated as
p(n;H)≈1−e−n(n−1)/(2H)≈1−e−n2/(2H) where n is the number of chosen values (inputs) and H is the number of possible outcomes (possible hash outputs). Let n(p; H) be the smallest number of values we have to choose, such that the probability for finding a collision is at least p. By inverting this expression above, we find the following approximation
n(p;H)≈2Hln11−p and assigning a 0.5 probability of collision we arrive at
n(0.5;H)≈1.1774H Let Q(H) be the expected number of values we have to choose before finding the first collision. This number can be approximated by
Q(H)≈π2H As an example, if a 64-bit hash is used, there are approximately 1.8×1019 different outputs. If these are all equally probable (the best case), then it would take 'only' approximately 5 billion attempts (5.38×109) to generate a collision using brute force. This value is called birthday bound and it could be approximated as 2l/2, where l is the number of bits in H. Other examples are as follows:
Table shows number of hashes n(p) needed to achieve the given probability of success, assuming all hashes are equally likely. For comparison, 10−18 to 10−15 is the uncorrectable bit error rate of a typical hard disk. In theory, MD5 hashes or UUIDs, being roughly 128 bits, should stay within that range until about 820 billion documents, even if its possible outputs are many more. It is easy to see that if the outputs of the function are distributed unevenly, then a collision could be found even faster. The notion of 'balance' of a hash function quantifies the resistance of the function to birthday attacks (exploiting uneven key distribution). However, determining the balance of a hash function will typically require all possible inputs to be calculated and thus is infeasible for popular hash functions such as the MD and SHA families. The subexpression ln11−p in the equation for n(p;H) is not computed accurately for small p when directly translated into common programming languages as log(1/(1-p)) due to loss of significance. When log1p is available (as it is in C99) for example, the equivalent expression -log1p(-p) should be used instead. If this is not done, the first column of the above table is computed as zero, and several items in the second column do not have even one correct significant digit.
Simple approximation A good rule of thumb which can be used for mental calculation is the relation
p(n)≈n22H which can also be written as
H≈n22p(n). or
n≈2H×p(n). This works well for probabilities less than or equal to 0.5. This approximation scheme is especially easy to use when working with exponents. For instance, suppose you are building 32-bit hashes (H=232) and want the chance of a collision to be at most one in a million (p≈2−20), how many documents could we have at the most?
n≈2×232×2−20=21+32−20=213=26.5≈90.5 which is close to the correct answer of 93.
… excerpt ends here. Continue reading the full article.
