GitHub - trichner/gitc0ffee: Git Commit Vanity Hash Solver
source link: https://github.com/trichner/gitc0ffee
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Git Commit Vanity Hash Solver
Neat tool to find a 'vanity' hash for a given git commit. Make all your commits hashes start with the
prefix c0ffee
, cafe
, badc0de5
or whatever makes you happy!
Install
go install github.com/trichner/gitc0ffee@latest
Usage
# do a normal git commit
$ git commit -am '...'
# update the last commit with a vanity hash
$ gitc0ffee --update-ref --prefix c0ffee
Will this break git tooling?
Maybe. Not all tooling deals well with prefix collisions. Some tools just deal with short-revisions (7 characters) and may therefore break.
How fast is it?
- 6 character prefix: less than a second
- 8 character prefix: in the order of one or more minutes
Measured on a MacBook Pro 16' 2021 with an M1 Max. Slightly slower on an AMD Ryzen 7 5800X.
Why not use the GPU?
Using the GPU is a lot more effort and a lot less portable, since it takes less than a second to brute force
the c0ffee
prefix there is no need for anything fancier.
The solver implementation can easily be extended though and as a matter of fact there are already at least three available:
singlethreaded - plain Go implementation of single thread brute force
concurrent - concurrent version of the singlethreaded solver
native - concurrent solver with hot-loop written in C,
slightly faster than 'concurrent' solver
# use:
gitc0ffee --solver <solver> ...
What prefix should I choose?
All even-length hexadecimal prefix will do ([0-9a-f]{0,40}
), for cool inspiration
see Hexspeak. Other ideas are repetions or sequences, e.g. 0001
, 0002
, ...
Note that the longer the prefix is, the longer cracking will take. Prefixes beyond 8 characters may not finish in useful time.
Implementation Details
Conceptually it roughly works as follows:
- Get the latest commit digest (
git rev-parse HEAD
). - Parse the raw object (
git cat-file -p <digest>
). - Add an additional
coffeesalt
header to the commit object and tweak the salt value until a prefix collision is found. This is the actual brute-forcing. - Write the new commit object to the git store (
git hash-object -t commit --stdin
). - (optional) Update the current branch the new commit object (
git update-ref HEAD <new digest>
).
Previous Work & Inspirations
There are quite a few similar tools. Some are either a bit more on the proof-of-concept side or might need specific GPU features.
Wishlist
- use CPU accelerated assembly, see also Linux Implementation
- GPU accelerated solver -
OpenCL
orCUDA
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK