Add a base implementation of SHA-256 support
SHA-1 is weak and we need to transition to a new hash function. For some time, we have referred to this new function as NewHash. Recently, we decided to pick SHA-256 as NewHash. The reasons behind the choice of SHA-256 are outlined in the thread starting at [1] and in the commit history for the hash function transition document. Add a basic implementation of SHA-256 based off libtomcrypt, which is in the public domain. Optimize it and restructure it to meet our coding standards. Pull in the update and final functions from the SHA-1 block implementation, as we know these function correctly with all compilers. This implementation is slower than SHA-1, but more performant implementations will be introduced in future commits. Wire up SHA-256 in the list of hash algorithms, and add a test that the algorithm works correctly. Note that with this patch, it is still not possible to switch to using SHA-256 in Git. Additional patches are needed to prepare the code to handle a larger hash algorithm and further test fixes are needed. [1] https://public-inbox.org/git/20180609224913.GC38834@genre.crustytoothpaste.net/ Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
c166599862
commit
13eeedb5d1
12
cache.h
12
cache.h
@ -48,11 +48,17 @@ unsigned long git_deflate_bound(git_zstream *, unsigned long);
|
||||
/* The block size of SHA-1. */
|
||||
#define GIT_SHA1_BLKSZ 64
|
||||
|
||||
/* The length in bytes and in hex digits of an object name (SHA-256 value). */
|
||||
#define GIT_SHA256_RAWSZ 32
|
||||
#define GIT_SHA256_HEXSZ (2 * GIT_SHA256_RAWSZ)
|
||||
/* The block size of SHA-256. */
|
||||
#define GIT_SHA256_BLKSZ 64
|
||||
|
||||
/* The length in byte and in hex digits of the largest possible hash value. */
|
||||
#define GIT_MAX_RAWSZ GIT_SHA1_RAWSZ
|
||||
#define GIT_MAX_HEXSZ GIT_SHA1_HEXSZ
|
||||
#define GIT_MAX_RAWSZ GIT_SHA256_RAWSZ
|
||||
#define GIT_MAX_HEXSZ GIT_SHA256_HEXSZ
|
||||
/* The largest possible block size for any supported hash. */
|
||||
#define GIT_MAX_BLKSZ GIT_SHA1_BLKSZ
|
||||
#define GIT_MAX_BLKSZ GIT_SHA256_BLKSZ
|
||||
|
||||
struct object_id {
|
||||
unsigned char hash[GIT_MAX_RAWSZ];
|
||||
|
||||
Reference in New Issue
Block a user