git/sha1collisiondetection — 37★ on GitHub (C). Marc Stevens's sha1collisiondetection, for use by git.git as its submodule
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
See accompanying file LICENSE.txt or copy at https://opensource.org/licenses/MIT.
Developers
Marc Stevens, CWI Amsterdam (https://marc-stevens.nl)
Dan Shumow, Microsoft Research (https://www.microsoft.com/en-us/research/people/danshu/)
About
This library and command line tool were designed as near drop-in replacements for common SHA-1 libraries and sha1sum.
They will compute the SHA-1 hash of any given file and additionally will detect cryptanalytic collision attacks against SHA-1 present in each file. It is very fast and takes less than twice the amount of time as regular SHA-1.
More specifically they will detect any cryptanalytic collision attack against SHA-1 using any of the top 32 SHA-1 disturbance vectors with probability 1:
The possibility of false positives can be neglected as the probability is smaller than 2^-90.
The library supports both an indicator flag that applications can check and act on, as well as a special safe-hash mode that returns the real SHA-1 hash when no collision was detected and a different safe hash when a collision was detected.
Colliding files will have the same SHA-1 hash, but will have different unpredictable safe-hashes.
This essentially enables protection of applications against SHA-1 collisions with no further changes in the application, e.g., digital signature forgeries based on SHA-1 collisions automatically become invalid.
For the theoretical explanation of collision detection see the award-winning paper on Counter-Cryptanalysis:
Counter-cryptanalysis, Marc Stevens, CRYPTO 2013, Lecture Notes in Computer Science, vol. 8042, Springer, 2013, pp. 129-146,
https://marc-stevens.nl/research/papers/C13-S.pdf
Compiling
Run:
make
Command-line usage
There are two programs bin/sha1dcsum and bin/sha1dcsum_partialcoll.
The first program bin/sha1dcsum will detect and warn for files that were generated with a cryptanalytic SHA-1 collision attack like the one documented at https://shattered.io/.
The second program bin/sha1dcsum_partialcoll will detect and warn for files that were generated with a cryptanalytic collision attack against reduced-round SHA-1 (of which there are a few examples so far).
See the documentation in lib/sha1.h. Here is a simple example code snippet:
#include <sha1dc/sha1.h>
SHA1_CTX ctx;
unsigned char hash[20];
SHA1DCInit(&ctx);
/** disable safe-hash mode (safe-hash mode is enabled by default) **/
// SHA1DCSetSafeHash(&ctx, 0);
/** disable use of unavoidable attack conditions to speed up detection (enabled by default) **/
// SHA1DCSetUseUBC(&ctx, 0);
SHA1DCUpdate(&ctx, buffer, (unsigned)(size));
int iscoll = SHA1DCFinal(hash,&ctx);
if (iscoll)
printf("collision detected");
else
printf("no collision detected");
Inclusion in other programs
In order to make it easier to include these sources in other project
there are several preprocessor macros that the code uses. Rather than
copy/pasting and customizing or specializing the code, first see if
setting any of these defines appropriately will allow you to avoid
modifying the code yourself.
SHA1DC_NO_STANDARD_INCLUDES
Skips including standard headers. Use this if your project for
whatever reason wishes to do its own header includes.
SHA1DC_CUSTOM_INCLUDE_SHA1_C
Includes a custom header at the top of sha1.c. Usually this would be
set in conjunction with SHA1DC_NO_STANDARD_INCLUDES to point to a
header file which includes various standard headers.
SHA1DC_INIT_SAFE_HASH_DEFAULT
Sets the default for safe_hash in SHA1DCInit(). Valid values are 0
and 1. If unset 1 is the default.
SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_C
Includes a custom trailer in sha1.c. Useful for any extra utility
functions that make use of the functions already defined in sha1.c.
SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_H
Includes a custom trailer in sha1.h. Useful for defining the
prototypes of the functions or code included by
SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_C.
SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C
Includes a custom header at the top of ubc_check.c.
SHA1DC_CUSTOM_TRAILING_INCLUDE_UBC_CHECK_C
Includes a custom trailer in ubc_check.c.
SHA1DC_CUSTOM_TRAILING_INCLUDE_UBC_CHECK_H
Includes a custom trailer in ubc_check.H.
This code will try to auto-detect certain things based on
CPU/platform. Unless you're running on some really obscure CPU or
porting to a new platform you should not need to tweak this. If you do
please open an issue at
https://github.com/cr-marcstevens/sha1collisiondetection
Override the check for processor endianenss and force either
Little-Endian or Big-Endian.
SHA1DC_FORCE_UNALIGNED_ACCESS
Permit unaligned access. This will fail on e.g. SPARC processors, so
it's only permitted on a whitelist of processors. If your CPU isn't
detected as allowing this, and allows unaligned access, setting this
may improve performance (or make it worse, if the kernel has to
catch and emulate such access on its own).
How active is development on git/sha1collisiondetection?
The most recent commit recorded on git/sha1collisiondetection was 9.3 years ago, based on the GitHub push timestamp. The repository has 31 forks — one of the better signals of community interest.
How many stars does git/sha1collisiondetection have?
git/sha1collisiondetection has 37 GitHub stars — refresh the page for the live number, or check github.com/git/sha1collisiondetection. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is git/sha1collisiondetection open source?
TopGit's metadata for git/sha1collisiondetection does not record a license. Most public repositories on GitHub ARE open source, but the exact terms vary — verify by opening the LICENSE file directly.
What is git/sha1collisiondetection?
git/sha1collisiondetection (git/sha1collisiondetection) is a C project on GitHub. From the project's own README: Marc Stevens's sha1collisiondetection, for use by git.git as its submodule
What language is git/sha1collisiondetection written in?
git/sha1collisiondetection is written primarily in C. GitHub's language field is based on the largest share of bytes in the default branch.
Where do I read more about git/sha1collisiondetection?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/git/sha1collisiondetection is the definitive source.
Read full README in the tab above.
Is sha1collisiondetection worth your time?
ChatGPT, Claude and Perplexity can all read this page. Ask one of them what it makes of sha1collisiondetection.