Birthday attack

Last updated

A birthday attack is a bruteforce 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 be the number of possible values of a hash function, with . With a birthday attack, it is possible to find a collision of a hash function with chance in where is the bit length of the hash output, [1] [2] and with being the classical preimage resistance security with the same probability. [2] There is a general (though disputed [3] ) result that quantum computers can perform birthday attacks, thus breaking collision resistance, in . [4]

Contents

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. [5] :36

Understanding the problem

Comparison of the birthday problem (1) and birthday attack (2):
In (1), collisions are found within one set, in this case, 3 out of 276 pairings of the 24 lunar astronauts.
In (2), collisions are found between two sets, in this case, 1 out of 256 pairings of only the first bytes of SHA-256 hashes of 16 variants each of benign and malicious contracts. Birthday attack vs paradox.svg
Comparison of the birthday problem (1) and birthday attack (2):
In (1), collisions are found within one set, in this case, 3 out of 276 pairings of the 24 lunar astronauts.
In (2), collisions are found between two sets, in this case, 1 out of 256 pairings of only the first bytes of SHA-256 hashes of 16 variants each of benign and malicious contracts.

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 . [6]

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 , 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.

Terminology

In the context of the birthday attack, the key variables are related to the well-known balls and bins problem in probability theory as follows.

n: Number of Inputs (or Balls)

The variable n represents the number of inputs (or attempts) being made. In the analogy of the balls and bins problem, n refers to the number of balls that are randomly thrown into H bins. Each input corresponds to throwing a ball into one of the bins (hash values).

H: Number of Hash Values (or Bins)

The variable H represents the total number of possible outputs of the hash function. This is the number of unique "bins" that the balls can land in. The total number of hash outputs is often expressed as , where l is the bit length of the hash output. In the balls and bins analogy, H represents the number of bins, each corresponding to a unique hash value.

l: Bit Length of Hash Function Output

The variable l refers to the bit length of the hash function’s output. Since a hash function of bit length l can produce unique outputs, the number of possible hash values (or bins) is .

p: Probability of Collision

The variable p represents the probability that a collision will occur—that is, the probability that two or more inputs (balls) will be assigned the same output (bin). In a birthday attack, p is often set to 0.5 (50%) to estimate how many inputs are needed to have a 50% chance of a collision.

Summary of Relation to the Balls and Bins Problem

The birthday attack can be modeled as a variation of the balls and bins problem. In this problem:


Mathematics

Given a function , the goal of the attack is to find two different inputs such that . Such a pair is called a collision. The method used to find a collision is simply to evaluate the function 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 yields any of different outputs with equal probability and is sufficiently large, then we expect to obtain a pair of different arguments and with after evaluating the function for about 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

[7]

where is the number of chosen values (inputs) and 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

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×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. [8] This value is called birthday bound [9] and for l-bit codes, it could be approximated as 2l/2 [10] Other examples are as follows:

BitsPossible outputs (H)Desired probability of random collision
(2 s.f.) (p)
10−1810−1510−1210−910−60.1%1%25%50%75%
16216 (~6.5 x 104)<2<2<2<2<21136190300430
32232 (~4.3×109)<2<2<23932900930050,00077,000110,000
64264 (~1.8×1019)61906100190,0006,100,0001.9×1086.1×1083.3×1095.1×1097.2×109
96296 (~7.9×1028)4.0×1051.3×1074.0×1081.3×10104.0×10111.3×10134.0×10132.1×10143.3×10144.7×1014
1282128 (~3.4×1038)2.6×10108.2×10112.6×10138.2×10142.6×10168.3×10172.6×10181.4×10192.2×10193.1×1019
1922192 (~6.3×1057)1.1×10203.7×10211.1×10233.5×10241.1×10263.5×10271.1×10286.0×10289.3×10281.3×1029
2562256 (~1.2×1077)4.8×10291.5×10314.8×10321.5×10344.8×10351.5×10374.8×10372.6×10384.0×10385.7×1038
3842384 (~3.9×10115)8.9×10482.8×10508.9×10512.8×10538.9×10542.8×10568.9×10564.8×10577.4×10571.0×1058
5122512 (~1.3×10154)1.6×10685.2×10691.6×10715.2×10721.6×10745.2×10751.6×10768.8×10761.4×10771.9×1077
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. [11] 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. [12] The subexpression in the equation for is not computed accurately for small 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. [13] 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

which can also be written as

.

or

.

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 () and want the chance of a collision to be at most one in a million (), how many documents could we have at the most?

which is close to the correct answer of 93.

Proofs

The birthday attack is a method that exploits the mathematics of collisions in hash functions. Below, we provide upper and lower bounds for the probability of a collision, based on the analogy of the balls and bins problem, and derive key equations.

Birthday Attack - Upper Bound

The birthday attack can be modeled as throwing n balls (inputs) into H bins (possible hash outputs). The probability of a collision is bounded by the following equation:

This equation follows from the union bound, which gives an upper bound on the probability that at least one collision occurs. We denote the event that the i-th ball collides with one of the previous balls as . The probability of a collision for the i-th ball is:

Thus, the total probability of a collision after throwing all n balls is bounded by:

This gives the upper bound for the probability of a collision in a hash function.

Birthday Attack - Lower Bound

The lower bound for the probability of a collision can be derived by assuming no collision after throwing in i balls, which must all occupy different bins. The probability of no collision after throwing the (i+1)-st ball is:

The total probability of no collision after throwing all n balls is the product of these terms:

By using the inequality , we can approximate this as:

Thus, the probability of at least one collision is bounded below by:

This provides the lower bound for the probability of a collision.

Birthday Attack and Balls and Bins Problem

It follows from the above argument that the probability of at least one collision is bounded between:

Letting , an almost sure collision occurs when the number of trials, n, is given by:

This illustrates how the number of inputs required for a collision grows as a function of the bit length of the hash output.

Digital signature susceptibility

Digital signatures can be susceptible to a birthday attack or more precisely a chosen-prefix collision attack. A message is typically signed by first computing , where is a cryptographic hash function, and then using some secret key to sign . Suppose Mallory wants to trick Bob into signing a fraudulent contract. Mallory prepares a fair contract and a fraudulent one . She then finds a number of positions where 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 which are all fair contracts.

In a similar manner, Mallory also creates a huge number of variations on the fraudulent contract . 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, . 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. For a given hash function is the number of possible hashes, where is the bit length of the hash output. The birthday problem equations do not exactly apply here. For a 50% chance of a collision, Mallory would need to generate approximately hashes, which is twice the number required for a simple collision under the classical birthday problem.

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.

Besides using a larger bit length, the signer (Bob) can protect himself by making some random, inoffensive changes to the document before signing it, and by keeping a copy of the contract he signed in his own possession, so that he can at least demonstrate in court that his signature matches that contract, not just the fraudulent one.

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

Reverse attack

The same fraud is possible if the signer is Mallory, not Bob. Bob could suggest a contract to Mallory for a signature. Mallory could find both an inoffensively-modified version of this fair contract that has the same signature as a fraudulent contract, and Mallory could provide the modified fair contract and signature to Bob. Later, Mallory could produce the fraudulent copy. If Bob doesn't have the inoffensively-modified version contract (perhaps only finding their original proposal), Mallory's fraud is perfect. If Bob does have it, Mallory can at least claim that it is Bob who is the fraudster.

Here are additional details:

1. Original Contract Proposal: Bob proposes a fair contract to Mallory, expecting her to sign it.

2. Mallory’s Modified and Fraudulent Contracts: Instead of signing Bob's contract directly, Mallory creates two versions of the contract

3. Mallory Provides the Modified Contract: Mallory signs the modified version and gives it to Bob. The signature on this version is the same as what would appear on the fraudulent contract.

4. Bob’s Risk: If Bob does not keep a copy of the modified version Mallory signed, but only retains the original proposal, he will not have proof of what Mallory agreed to. Later, Mallory can present the fraudulent contract (which carries the same signature) and claim it was the one that was signed.

5. Outcomes:

See also

Notes

  1. "Avoiding collisions, Cryptographic hash functions" (PDF). Foundations of Cryptography, Computer Science Department, Wellesley College.
  2. 1 2 Dang, Q H (2012). Recommendation for applications using approved hash algorithms (Report). Gaithersburg, MD: National Institute of Standards and Technology.
  3. Daniel J. Bernstein. "Cost analysis of hash collisions : Will quantum computers make SHARCS obsolete?" (PDF). Cr.yp.to. Retrieved 29 October 2017.
  4. Brassard, Gilles; HØyer, Peter; Tapp, Alain (20 April 1998). "Quantum cryptanalysis of hash and claw-free functions". LATIN'98: Theoretical Informatics. Lecture Notes in Computer Science. Vol. 1380. Springer, Berlin, Heidelberg. pp. 163–169. arXiv: quant-ph/9705002 . doi:10.1007/BFb0054319. ISBN   978-3-540-64275-6. S2CID   118940551.
  5. R. Shirey (August 2007). Internet Security Glossary, Version 2. Network Working Group. doi: 10.17487/RFC4949 . RFC 4949.Informational.
  6. "Birthday Problem". Brilliant.org. Brilliant_(website) . Retrieved 28 July 2023.
  7. Bellare, Mihir; Rogaway, Phillip (2005). "The Birthday Problem". Introduction to Modern Cryptography (PDF). pp. 273–274. Retrieved 2023-03-31.
  8. Flajolet, Philippe; Odlyzko, Andrew M. (1990). "Random Mapping Statistics". In Quisquater, Jean-Jacques; Vandewalle, Joos (eds.). Advances in Cryptology — EUROCRYPT '89. Lecture Notes in Computer Science. Vol. 434. Berlin, Heidelberg: Springer. pp. 329–354. doi:10.1007/3-540-46885-4_34. ISBN   978-3-540-46885-1.
  9. See upper and lower bounds.
  10. Jacques Patarin, Audrey Montreuil (2005). "Benes and Butterfly schemes revisited" (PostScript, PDF). Université de Versailles. Retrieved 2007-03-15.{{cite journal}}: Cite journal requires |journal= (help)
  11. Gray, Jim; van Ingen, Catharine (25 January 2007). "Empirical Measurements of Disk Failure Rates and Error Rates". arXiv: cs/0701166 .
  12. "CiteSeerX". Archived from the original on 2008-02-23. Retrieved 2006-05-02.
  13. "Compute log(1+x) accurately for small values of x". Mathworks.com. Retrieved 29 October 2017.

Related Research Articles

<span class="mw-page-title-main">Birthday problem</span> Probability of shared birthdays

In probability theory, the birthday problem asks for the probability that, in a set of n randomly chosen people, at least two will share a birthday. The birthday paradox refers to the counterintuitive fact that only 23 people are needed for that probability to exceed 50%.

In computer science, a one-way function is a function that is easy to compute on every input, but hard to invert given the image of a random input. Here, "easy" and "hard" are to be understood in the sense of computational complexity theory, specifically the theory of polynomial time problems. Not being one-to-one is not considered sufficient for a function to be called one-way.

A commitment scheme is a cryptographic primitive that allows one to commit to a chosen value while keeping it hidden to others, with the ability to reveal the committed value later. Commitment schemes are designed so that a party cannot change the value or statement after they have committed to it: that is, commitment schemes are binding. Commitment schemes have important applications in a number of cryptographic protocols including secure coin flipping, zero-knowledge proofs, and secure computation.

<span class="mw-page-title-main">Cryptographic hash function</span> Hash function that is suitable for use in cryptography

A cryptographic hash function (CHF) is a hash algorithm that has special properties desirable for a cryptographic application:

In cryptography, the Elliptic Curve Digital Signature Algorithm (ECDSA) offers a variant of the Digital Signature Algorithm (DSA) which uses elliptic-curve cryptography.

In cryptography, a preimage attack on cryptographic hash functions tries to find a message that has a specific hash value. A cryptographic hash function should resist attacks on its preimage.

In cryptography, collision resistance is a property of cryptographic hash functions: a hash function H is collision-resistant if it is hard to find two inputs that hash to the same output; that is, two inputs a and b where ab but H(a) = H(b). The pigeonhole principle means that any hash function with more inputs than outputs will necessarily have such collisions; the harder they are to find, the more cryptographically secure the hash function is.

<span class="mw-page-title-main">One-way compression function</span> Cryptographic primitive

In cryptography, a one-way compression function is a function that transforms two fixed-length inputs into a fixed-length output. The transformation is "one-way", meaning that it is difficult given a particular output to compute inputs which compress to that output. One-way compression functions are not related to conventional data compression algorithms, which instead can be inverted exactly or approximately to the original data.

In cryptography a universal one-way hash function is a type of universal hash function of particular importance to cryptography. UOWHFs are proposed as an alternative to collision-resistant hash functions (CRHFs). CRHFs have a strong collision-resistance property: that it is hard, given randomly chosen hash function parameters, to find any collision of the hash function. In contrast, UOWHFs require that it be hard to find a collision where one preimage is chosen independently of the hash function parameters. The primitive was suggested by Moni Naor and Moti Yung and is also known as "target collision resistant" hash functions; it was employed to construct general digital signature schemes without trapdoor functions, and also within chosen-ciphertext secure public key encryption schemes.

In mathematics and computing, universal hashing refers to selecting a hash function at random from a family of hash functions with a certain mathematical property. This guarantees a low number of collisions in expectation, even if the data is chosen by an adversary. Many universal families are known, and their evaluation is often very efficient. Universal hashing has numerous uses in computer science, for example in implementations of hash tables, randomized algorithms, and cryptography.

<span class="mw-page-title-main">Beta-binomial distribution</span> Discrete probability distribution

In probability theory and statistics, the beta-binomial distribution is a family of discrete probability distributions on a finite support of non-negative integers arising when the probability of success in each of a fixed or known number of Bernoulli trials is either unknown or random. The beta-binomial distribution is the binomial distribution in which the probability of success at each of n trials is not fixed but randomly drawn from a beta distribution. It is frequently used in Bayesian statistics, empirical Bayes methods and classical statistics to capture overdispersion in binomial type distributed data.

In computer science, locality-sensitive hashing (LSH) is a fuzzy hashing technique that hashes similar input items into the same "buckets" with high probability. Since similar items end up in the same buckets, this technique can be used for data clustering and nearest neighbor search. It differs from conventional hashing techniques in that hash collisions are maximized, not minimized. Alternatively, the technique can be seen as a way to reduce the dimensionality of high-dimensional data; high-dimensional input items can be reduced to low-dimensional versions while preserving relative distances between items.

In cryptography, Very Smooth Hash (VSH) is a provably secure cryptographic hash function invented in 2005 by Scott Contini, Arjen Lenstra, and Ron Steinfeld. Provably secure means that finding collisions is as difficult as some known hard mathematical problem. Unlike other provably secure collision-resistant hashes, VSH is efficient and usable in practice. Asymptotically, it only requires a single multiplication per log(n) message-bits and uses RSA-type arithmetic. Therefore, VSH can be useful in embedded environments where code space is limited.

The elliptic curve only hash (ECOH) algorithm was submitted as a candidate for SHA-3 in the NIST hash function competition. However, it was rejected in the beginning of the competition since a second pre-image attack was found.

In cryptography, SWIFFT is a collection of provably secure hash functions. It is based on the concept of the fast Fourier transform (FFT). SWIFFT is not the first hash function based on the FFT, but it sets itself apart by providing a mathematical proof of its security. It also uses the LLL basis reduction algorithm. It can be shown that finding collisions in SWIFFT is at least as difficult as finding short vectors in cyclic/ideal lattices in the worst case. By giving a security reduction to the worst-case scenario of a difficult mathematical problem, SWIFFT gives a much stronger security guarantee than most other cryptographic hash functions.

In discrete mathematics, ideal lattices are a special class of lattices and a generalization of cyclic lattices. Ideal lattices naturally occur in many parts of number theory, but also in other areas. In particular, they have a significant place in cryptography. Micciancio defined a generalization of cyclic lattices as ideal lattices. They can be used in cryptosystems to decrease by a square root the number of parameters necessary to describe a lattice, making them more efficient. Ideal lattices are a new concept, but similar lattice classes have been used for a long time. For example, cyclic lattices, a special case of ideal lattices, are used in NTRUEncrypt and NTRUSign.

In computer science and data mining, MinHash is a technique for quickly estimating how similar two sets are. The scheme was invented by Andrei Broder, and initially used in the AltaVista search engine to detect duplicate web pages and eliminate them from search results. It has also been applied in large-scale clustering problems, such as clustering documents by the similarity of their sets of words.

Badger is a Message Authentication Code (MAC) based on the idea of universal hashing and was developed by Boesgaard, Scavenius, Pedersen, Christensen, and Zenner. It is constructed by strengthening the ∆-universal hash family MMH using an ϵ-almost strongly universal (ASU) hash function family after the application of ENH, where the value of ϵ is . Since Badger is a MAC function based on the universal hash function approach, the conditions needed for the security of Badger are the same as those for other universal hash functions such as UMAC.

Network coding has been shown to optimally use bandwidth in a network, maximizing information flow but the scheme is very inherently vulnerable to pollution attacks by malicious nodes in the network. A node injecting garbage can quickly affect many receivers. The pollution of network packets spreads quickly since the output of honest node is corrupted if at least one of the incoming packets is corrupted.

The balls into binsproblem is a classic problem in probability theory that has many applications in computer science. The problem involves m balls and n boxes. Each time, a single ball is placed into one of the bins. After all balls are in the bins, we look at the number of balls in each bin; we call this number the load on the bin. The problem can be modelled using a Multinomial distribution, and may involve asking a question such as: What is the expected number of bins with a ball in them?

References