mirror of
https://github.com/AGWA/git-crypt.git
synced 2025-12-27 13:13:20 -08:00
Check HMAC in smudge and diff commands
Git-crypt's position has always been that authentication is best left to Git, since 1) Git provides immutable history based on SHA-1 hashes as well as GPG-signed commits and tags, and 2) git-crypt can't be used safely anyways unless the overall integrity of your repository is assured. But, since git-crypt already has easy access to a (truncated) HMAC of the file when decrypting, there's really no reason why git-crypt shouldn't just verify it and provide an additional layer of protection.
This commit is contained in:
17
util.cpp
17
util.cpp
@@ -92,6 +92,23 @@ void* explicit_memset (void* s, int c, std::size_t n)
|
||||
return s;
|
||||
}
|
||||
|
||||
static bool leakless_equals_char (const unsigned char* a, const unsigned char* b, std::size_t len)
|
||||
{
|
||||
volatile int diff = 0;
|
||||
|
||||
while (len > 0) {
|
||||
diff |= *a++ ^ *b++;
|
||||
--len;
|
||||
}
|
||||
|
||||
return diff == 0;
|
||||
}
|
||||
|
||||
bool leakless_equals (const void* a, const void* b, std::size_t len)
|
||||
{
|
||||
return leakless_equals_char(reinterpret_cast<const unsigned char*>(a), reinterpret_cast<const unsigned char*>(b), len);
|
||||
}
|
||||
|
||||
static void init_std_streams_platform (); // platform-specific initialization
|
||||
|
||||
void init_std_streams ()
|
||||
|
||||
Reference in New Issue
Block a user