Whatever happened to SHA-256 support in Git?
Whatever happened to SHA-256 support in Git?
Posted Jun 24, 2022 3:18 UTC (Fri) by brasic (guest, #159230)In reply to: Whatever happened to SHA-256 support in Git? by dtlin
Parent article: Whatever happened to SHA-256 support in Git?
Fortunately this is incorrect! Well, the second part is incorrect; the first is quite right but doesn’t imply what you think it does.
Every git commit is the root of a merkle tree, or as the kids call it, a “blockchain”. A git commit object id is the hash of a string which includes among other things the commit’s immediate parent object ids, and the commit’s root tree object id. Here is the canonical serialization of a commit, the input bytes passed to the hash function: https://github.com/git/git/blob/39c15e485575089eb77c769f6...
The tree oid is also the root of a separate merkle tree which recursively hashes the contents, file names and permissions of every file in the repo.
Since the input string which is hashed to produce the commit oid includes the tree oid, the contents of every file in that commit and all prior ones are part of the id and any change to any file will produce an entirely different object id.
The actual string which is signed is exactly the canonical serialization above. Then the sig is added to a header and the object id is computed (now including the signature as a has component)
So you’re quite right that only the commit is signed. But because of the magic of git, signing a commit is equivalent to signing the whole tree and all of history!
