User:Carlaobatista

Ataque de Aniversário

A  birthday attack  is a type of cryptographic 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 collision s found between random attack attempts and a fixed degree of permutations ( pigeonhole s).

Understanding the problem
As an example, consider the scenario in which a teacher with a class of 30 students asks for everybody's birthday, to determine whether any two students have the same birthday (corresponding to a hash collision as described further [for simplicity, ignore February 29]). Intuitively, this chance may seem small. If the teacher picked a specific day (say September 16), then the chance that at least one student was born on that specific day is $$1 - (364/365)^{30}$$, about 7.9%. However, the probability that at least one student has the same birthday as  any  other student is around 70% for n = 30, from the formula $$1-365!/((365-n)!\cdot 365^n)$$.

Mathematics
Given a function $$f$$, the goal of the attack is to find two different inputs $$x_{1}, x_{2}$$ such that $$f(x_{1}) = f(x_{2})$$. Such a pair $$x_{1}, x_{2}$$ 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 $$x_{1}$$ and $$x_{2}$$ with $$f(x_{1}) = f(x_{2})$$ after evaluating the function for about $$1.25\sqrt{H}$$ 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  ; & nbsp;  H  ) be the probability that during this experiment at least one value is chosen more than once. This probability can be approximated as



Let  n  (  p  ; & nbsp;  H  ) be the smallest number of values we have to choose, such that the probability for finding a collision is at least & nbsp;  p . By inverting this expression above, we find the following approximation


 * $$n(p;H)\approx \sqrt{2H\ln\frac{1}{1-p}},$$

and assigning a 0.5 probability of collision we arrive at



Let Q(H ) be the expected number of values we have to choose before finding the first collision. This number can be approximated by



As an example, if a 64-bit hash is used, there are approximately 1.8 & nbsp;× & nbsp;10 19 different outputs. If these are all equally probable (the best case), then it would take 'only' approximately 5 billion attempts (5.1 & nbsp;× & nbsp;10 9 ) to generate a collision using brute force. This value is called  birthday bound  and for  n  -bit codes it could be computed as 2  n  /2. Other examples are as follows:

! rowspan="2"  style="background:lightgrey;" | Bits ! rowspan="2"  style="background:lightgrey;" | Possible outputs (2 s.f. ) (H) ! colspan="10" style="background:lightgrey;" | Desired probability of random collision (2 s.f.) (p) ! style="background:lightgrey;" | 10−18 ! style="background:lightgrey;" | 10−15 ! style="background:lightgrey;" | 10−12 ! style="background:lightgrey;" | 10−9 ! style="background:lightgrey;" | 10−6 ! style="background:lightgrey;" | 0.1% ! style="background:lightgrey;" | 1% ! style="background:lightgrey;" | 25% ! style="background:lightgrey;" | 50% ! style="background:lightgrey;" | 75% | bgcolor="lightgrey" | 65,536 | bgcolor="lightgrey" | 4.3 × 10 9 | bgcolor="lightgrey" | 1.8 × 10 19 | 1.9 × 10 8 | 6.1 × 10 8  | 3.3 × 10 9  | 5.1 × 10 9  | 7.2 × 10 9  | bgcolor="lightgrey" | 3.4 × 10 38 | 2.6 × 10 10 | 8.2 × 10 11  | 2.6 × 10 13  | 8.2 × 10 14  | 2.6 × 10 16  | 8.3 × 10 17  | 2.6 × 10 18  | 1.4 × 10 19  | 2.2 × 10 19  | 3.1 × 10 19  | bgcolor="lightgrey" | 1.2 × 10 77 | 4.8 × 10 29 | 1.5 × 10 31  | 4.8 × 10 32  | 1.5 × 10 34  | 4.8 × 10 35  | 1.5 × 10 37  | 4.8 × 10 37  | 2.6 × 10 38  | 4.0 × 10 38  | 5.7 × 10 38  | bgcolor="lightgrey" | 3.9 × 10 115 | 8.9 × 10 48 | 2.8 × 10 50  | 8.9 × 10 51  | 2.8 × 10 53  | 8.9 × 10 54  | 2.8 × 10 56  | 8.9 × 10 56  | 4.8 × 10 57  | 7.4 × 10 57  | 1.0 × 10 58  | bgcolor="lightgrey" | 1.3 × 10 154 | 1.6 × 10 68 | 5.2 × 10 69  | 1.6 × 10 71  | 5.2 × 10 72  | 1.6 × 10 74  | 5.2 × 10 75  | 1.6 × 10 76  | 8.8 × 10 76  | 1.4 × 10 77  | 1.9 × 10 77  :   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 128 bits, should stay within that range until about 820 billion documents, even if its possible outputs are many more. ''
 * - align="center"
 * bgcolor="lightgrey" | 16
 * <2
 * <2
 * <2
 * <2
 * <2
 * 11
 * 36
 * 190
 * 300
 * 430
 * - align="center"
 * bgcolor="lightgrey" | 32
 * <2
 * <2
 * <2
 * 3
 * 93
 * 2900
 * 9300
 * 50,000
 * 77,000
 * 110,000
 * - align="center"
 * bgcolor="lightgrey" | 64
 * 6
 * 190
 * 6100
 * 190,000
 * 6,100,000
 * - align="center"
 * bgcolor="lightgrey" | 128
 * - align="center"
 * bgcolor="lightgrey" | 256
 * - align="center"
 * bgcolor="lightgrey" | 384
 * - align="center"
 * bgcolor="lightgrey" | 512
 * }

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) and allows the vulnerability of popular hashes such as MD and SHA to be estimated ( Bellare and Kohno, 2004 ).

The subexpression $$\ln\frac{1}{1-p}$$ in the equation for $$n(p;H)$$ is not computed accurately for small $$p$$ when directly translated into common programming languages as due to loss of significance. When is available (as it is in C99 ) for example, the equivalent expression  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.

Source code example
Here is a Python function that can accurately generate most of the above table: If the code is saved in a file named, it can be run interactively as in the following example:

Simple approximation
A good rule of thumb which can be used for mental calculation is the relation



which can also be written as



This works well for probabilities less than or equal to 0.5.

This approximation scheme is especially easy to use for when working with exponents. For instance, suppose you are building 32-bit hashes ( $$ m = 2^{32}$$ ) and want the chance of a collision to be at most one in a million ( $$ p \approx 2^{-20} $$ ), how many documents could we have at the most?


 * $$n \approx \sqrt { 2 \times 2^{32} \times 2^{-20}} = \sqrt { 2^{1+32-20} } = \sqrt { 2^{13} } = 2^{6.5} \approx 90.5 $$

which is close to the correct answer of 93.

Digital signature susceptibility
Digital signature s can be susceptible to a birthday attack. A message $$m$$ is typically signed by first computing $$f(m)$$, where $$f$$ is a cryptographic hash function , and then using some secret key to sign $$f(m)$$. Suppose Mallory wants to trick Bob into signing a fraudulent contract. Mallory prepares a fair contract $$m$$ and a fraudulent one $$m'$$. She then finds a number of positions where $$m$$ can be changed without changing the meaning, such as inserting commas, empty lines, one versus two spaces after a sentence, replacing synonyms, etc. By combining these changes, she can create a huge number of variations on $$m$$ which are all fair contracts.

In a similar manner, Mallory also creates a huge number of variations on the fraudulent contract $$m'$$. She then applies the hash function to all these variations until she finds a version of the fair contract and a version of the fraudulent contract which have the same hash value, $$f(m) = f(m')$$. She presents the fair version to Bob for signing. After Bob has signed, Mallory takes the signature and attaches it to the fraudulent contract. This signature then "proves" that Bob signed the fraudulent contract.

The probabilities differ slightly from the original birthday problem, as Mallory gains nothing by finding two fair or two fraudulent contracts with the same hash. Mallory's strategy is to generate pairs of one fair and one fraudulent contract. The birthday problem equations apply where $$n$$ is the number of pairs. The number of hashes Mallory actually generates is $$2n$$.

To avoid this attack, the output length of the hash function used for a signature scheme can be chosen large enough so that the birthday attack becomes computationally infeasible, i.e. about twice as many bits as are needed to prevent an ordinary brute-force attack.

Pollard's rho algorithm for logarithms is an example for an algorithm using a birthday attack for the computation of discrete logarithm s.