You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SHA1.compress 3.0KB

SHA-1: collision detection support Update SHA1 class to include a Java port of sha1dc[1]'s ubc_check, which can detect the attack pattern used by the SHAttered[2] authors. Given the shattered example files that have the same SHA-1, this modified implementation can identify there is risk of collision given only one file in the pair: $ jgit ... [main] WARN org.eclipse.jgit.util.sha1.SHA1 - SHA-1 collision 38762cf7f55934b34d179ae6a4c80cadccbb7f0a When JGit detects probability of a collision the SHA1 class now warns on the logger, reporting the object's SHA-1 hash, and then throws a Sha1CollisionException to the caller. From the paper[3] by Marc Stevens, the probability of a false positive identification of a collision is about 14 * 2^(-160), sufficiently low enough for any detected collision to likely be a real collision. git-core[4] may adopt sha1dc before the system migrates to an entirely new hash function. This commit enables JGit to remain compatible with that move to sha1dc, and help protect users by warning if similar attacks as SHAttered are identified. Performance declined about 8% (detection off), now: MessageDigest 238.41 MiB/s MessageDigest 244.52 MiB/s MessageDigest 244.06 MiB/s MessageDigest 242.58 MiB/s SHA1 216.77 MiB/s (was ~240.83 MiB/s) SHA1 220.98 MiB/s SHA1 221.76 MiB/s SHA1 221.34 MiB/s This decline in throughput is attributed to the step loop unrolling in compress(), which was necessary to easily fit the UbcCheck logic into the hash function. Using helper functions s1-s4 reduces the code explosion, providing acceptable throughput. With detection enabled (default): SHA1 detectCollision 180.12 MiB/s SHA1 detectCollision 181.59 MiB/s SHA1 detectCollision 181.64 MiB/s SHA1 detectCollision 182.24 MiB/s sha1dc (native C) ~206.28 MiB/s sha1dc (native C) ~204.47 MiB/s sha1dc (native C) ~203.74 MiB/s Average time across 100,000 calls to hash 4100 bytes (such as a commit or tree) for the various algorithms available to JGit also shows SHA1 is slower than MessageDigest, but by an acceptable margin: MessageDigest 17 usec SHA1 18 usec SHA1 detectCollision 22 usec Time to index-pack for git.git (217982 objects, 69 MiB) has increased: MessageDigest SHA1 w/ detectCollision ------------- ----------------------- 20.12s 25.25s 19.87s 25.48s 20.04s 25.26s avg 20.01s 25.33s +26% Being implemented in Java with these additional safety checks is clearly a penalty, but throughput is still acceptable given the increased security against object name collisions. [1] https://github.com/cr-marcstevens/sha1collisiondetection [2] https://shattered.it/ [3] https://marc-stevens.nl/research/papers/C13-S.pdf [4] https://public-inbox.org/git/20170223230621.43anex65ndoqbgnf@sigill.intra.peff.net/ Change-Id: I9fe4c6d8fc5e5a661af72cd3246c9e67b1b9fee6
7 anni fa
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* Template for compress method; run through cpp. */
  2. #define ROUND1_STEP(a, b, c, d, e, T) e += s1(a,b,c,d,w[T]); b = rotateLeft(b, 30)
  3. #define ROUND2_STEP(a, b, c, d, e, T) e += s2(a,b,c,d,w[T]); b = rotateLeft(b, 30)
  4. #define ROUND3_STEP(a, b, c, d, e, T) e += s3(a,b,c,d,w[T]); b = rotateLeft(b, 30)
  5. #define ROUND4_STEP(a, b, c, d, e, T) e += s4(a,b,c,d,w[T]); b = rotateLeft(b, 30)
  6. ROUND1_STEP(a, b, c, d, e, 0);
  7. ROUND1_STEP(e, a, b, c, d, 1);
  8. ROUND1_STEP(d, e, a, b, c, 2);
  9. ROUND1_STEP(c, d, e, a, b, 3);
  10. ROUND1_STEP(b, c, d, e, a, 4);
  11. ROUND1_STEP(a, b, c, d, e, 5);
  12. ROUND1_STEP(e, a, b, c, d, 6);
  13. ROUND1_STEP(d, e, a, b, c, 7);
  14. ROUND1_STEP(c, d, e, a, b, 8);
  15. ROUND1_STEP(b, c, d, e, a, 9);
  16. ROUND1_STEP(a, b, c, d, e, 10);
  17. ROUND1_STEP(e, a, b, c, d, 11);
  18. ROUND1_STEP(d, e, a, b, c, 12);
  19. ROUND1_STEP(c, d, e, a, b, 13);
  20. ROUND1_STEP(b, c, d, e, a, 14);
  21. ROUND1_STEP(a, b, c, d, e, 15);
  22. ROUND1_STEP(e, a, b, c, d, 16);
  23. ROUND1_STEP(d, e, a, b, c, 17);
  24. ROUND1_STEP(c, d, e, a, b, 18);
  25. ROUND1_STEP(b, c, d, e, a, 19);
  26. ROUND2_STEP(a, b, c, d, e, 20);
  27. ROUND2_STEP(e, a, b, c, d, 21);
  28. ROUND2_STEP(d, e, a, b, c, 22);
  29. ROUND2_STEP(c, d, e, a, b, 23);
  30. ROUND2_STEP(b, c, d, e, a, 24);
  31. ROUND2_STEP(a, b, c, d, e, 25);
  32. ROUND2_STEP(e, a, b, c, d, 26);
  33. ROUND2_STEP(d, e, a, b, c, 27);
  34. ROUND2_STEP(c, d, e, a, b, 28);
  35. ROUND2_STEP(b, c, d, e, a, 29);
  36. ROUND2_STEP(a, b, c, d, e, 30);
  37. ROUND2_STEP(e, a, b, c, d, 31);
  38. ROUND2_STEP(d, e, a, b, c, 32);
  39. ROUND2_STEP(c, d, e, a, b, 33);
  40. ROUND2_STEP(b, c, d, e, a, 34);
  41. ROUND2_STEP(a, b, c, d, e, 35);
  42. ROUND2_STEP(e, a, b, c, d, 36);
  43. ROUND2_STEP(d, e, a, b, c, 37);
  44. ROUND2_STEP(c, d, e, a, b, 38);
  45. ROUND2_STEP(b, c, d, e, a, 39);
  46. ROUND3_STEP(a, b, c, d, e, 40);
  47. ROUND3_STEP(e, a, b, c, d, 41);
  48. ROUND3_STEP(d, e, a, b, c, 42);
  49. ROUND3_STEP(c, d, e, a, b, 43);
  50. ROUND3_STEP(b, c, d, e, a, 44);
  51. ROUND3_STEP(a, b, c, d, e, 45);
  52. ROUND3_STEP(e, a, b, c, d, 46);
  53. ROUND3_STEP(d, e, a, b, c, 47);
  54. ROUND3_STEP(c, d, e, a, b, 48);
  55. ROUND3_STEP(b, c, d, e, a, 49);
  56. ROUND3_STEP(a, b, c, d, e, 50);
  57. ROUND3_STEP(e, a, b, c, d, 51);
  58. ROUND3_STEP(d, e, a, b, c, 52);
  59. ROUND3_STEP(c, d, e, a, b, 53);
  60. ROUND3_STEP(b, c, d, e, a, 54);
  61. ROUND3_STEP(a, b, c, d, e, 55);
  62. ROUND3_STEP(e, a, b, c, d, 56);
  63. ROUND3_STEP(d, e, a, b, c, 57);
  64. state58.save(a, b, c, d, e);
  65. ROUND3_STEP(c, d, e, a, b, 58);
  66. ROUND3_STEP(b, c, d, e, a, 59);
  67. ROUND4_STEP(a, b, c, d, e, 60);
  68. ROUND4_STEP(e, a, b, c, d, 61);
  69. ROUND4_STEP(d, e, a, b, c, 62);
  70. ROUND4_STEP(c, d, e, a, b, 63);
  71. ROUND4_STEP(b, c, d, e, a, 64);
  72. state65.save(a, b, c, d, e);
  73. ROUND4_STEP(a, b, c, d, e, 65);
  74. ROUND4_STEP(e, a, b, c, d, 66);
  75. ROUND4_STEP(d, e, a, b, c, 67);
  76. ROUND4_STEP(c, d, e, a, b, 68);
  77. ROUND4_STEP(b, c, d, e, a, 69);
  78. ROUND4_STEP(a, b, c, d, e, 70);
  79. ROUND4_STEP(e, a, b, c, d, 71);
  80. ROUND4_STEP(d, e, a, b, c, 72);
  81. ROUND4_STEP(c, d, e, a, b, 73);
  82. ROUND4_STEP(b, c, d, e, a, 74);
  83. ROUND4_STEP(a, b, c, d, e, 75);
  84. ROUND4_STEP(e, a, b, c, d, 76);
  85. ROUND4_STEP(d, e, a, b, c, 77);
  86. ROUND4_STEP(c, d, e, a, b, 78);
  87. ROUND4_STEP(b, c, d, e, a, 79);