git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC] adding support for md5

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Aug 19, 2006, 02:35 UTC
Message-ID
<Pine.LNX.4.63.0608190416370.28360@wbgn013.biozentrum.uni-wuerzburg.de>
In-Reply-To
<9e4733910608181452x65ca937aqbfde55caa98ff6da@mail.gmail.com>
Hi,
On Fri, 18 Aug 2006, Jon Smirl wrote:
> If I have two repositories each with 100M objects in them and I merge 
> them, what is the probability of a object id collision with MD5 (128b) 
> versus SHA1 (160b)?

Assuming a uniform distribution of the hashes over our data, this is the birthday problem:

http://mathworld.wolfram.com/BirthdayProblem.html

(In short, given a number of days in the year, how many people do I need to pick randomly until at least two of them have the same birthday?)

In our case, we want to know how many objects we need in order to probably have a clash in 2^128 (approx. 3.4e38) and 2^160 (approx. 1.5e48) hashes, respectively.

Mathworld tells us that a good approximation of the probability is
p = 1 - (1-n/(2d))^(n-1)

where n is the number of objects, and d is the total number of hashes. If you have 100M = 1e5 objects, you probably want the probability of a clash below 1/1e5 = 1e-5, so let's take 1e-10. Assuming n is way lower than d, we can approximate

p = 1 - (1 - (n - 1 over 1) * n/(2d)) = n(n-1)/2d
and therefore (approximately)
n = sqrt(2pd)

which amounts to 2.6e14 in the case of a 128-bit hash, and 1.7e19 in the case of a 160-bit hash, both well beyond your 100M objects. BTW the addressable space of a 64-bit processor is about 1.9e19.

If you want to know the probability of a clash, you can use the same approximation:

For 100M objects: p = 1.5e-59 for 128-bit, and p = 3.3e-69 for 160-bit. This is so low as to be incomprehensible.

Remember that all these approximations are really crude, so do not rely on the precise numbers. But they'll give you good ballpark figures (if I did not make a mistake...).

Hth, Dscho

Previous: Jon SmirlNext: Linus Torvalds
Message 11 of 20 in “[RFC] adding support for md5”
  1. David RientjesAug 18, 2006
  2. Nguyễn Thái Ngọc DuyAug 18, 2006
  3. Johannes SchindelinAug 18, 2006
  4. Petr BaudisAug 18, 2006
  5. David RientjesAug 18, 2006
  6. TrekieAug 18, 2006
  7. Johannes SchindelinAug 18, 2006
  8. TrekieAug 18, 2006
  9. Johannes SchindelinAug 18, 2006
  10. Jon SmirlAug 18, 2006
  11. Johannes SchindelinAug 19, 2006
  12. Linus TorvaldsAug 19, 2006
  13. Chris WedgwoodAug 21, 2006
  14. Junio C HamanoAug 22, 2006
  15. Shawn PearceAug 23, 2006
  16. Junio C HamanoAug 23, 2006
  17. Shawn PearceAug 23, 2006
  18. Junio C HamanoAug 24, 2006
  19. Shawn PearceAug 24, 2006
  20. Junio C HamanoAug 24, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.