Elijah Newren | fc7bd51 | 2023-02-24 00:09:34 +0000 | [diff] [blame] | 1 | #include "git-compat-util.h" |
| 2 | #include "sha1dc_git.h" |
Elijah Newren | 41771fa | 2023-02-24 00:09:27 +0000 | [diff] [blame] | 3 | #include "hex.h" |
Ævar Arnfjörð Bjarmason | a010391 | 2017-05-20 11:54:28 +0000 | [diff] [blame] | 4 | |
Takashi Iwai | 3964cbb | 2017-08-15 14:04:17 +0200 | [diff] [blame] | 5 | #ifdef DC_SHA1_EXTERNAL |
| 6 | /* |
| 7 | * Same as SHA1DCInit, but with default save_hash=0 |
| 8 | */ |
| 9 | void git_SHA1DCInit(SHA1_CTX *ctx) |
| 10 | { |
| 11 | SHA1DCInit(ctx); |
| 12 | SHA1DCSetSafeHash(ctx, 0); |
| 13 | } |
| 14 | #endif |
| 15 | |
Takashi Iwai | 36f048c | 2017-08-15 14:04:16 +0200 | [diff] [blame] | 16 | /* |
| 17 | * Same as SHA1DCFinal, but convert collision attack case into a verbose die(). |
| 18 | */ |
Ævar Arnfjörð Bjarmason | a010391 | 2017-05-20 11:54:28 +0000 | [diff] [blame] | 19 | void git_SHA1DCFinal(unsigned char hash[20], SHA1_CTX *ctx) |
| 20 | { |
| 21 | if (!SHA1DCFinal(hash, ctx)) |
| 22 | return; |
| 23 | die("SHA-1 appears to be part of a collision attack: %s", |
Jeff King | b19f3fe | 2019-11-11 04:04:18 -0500 | [diff] [blame] | 24 | hash_to_hex_algop(hash, &hash_algos[GIT_HASH_SHA1])); |
Ævar Arnfjörð Bjarmason | a010391 | 2017-05-20 11:54:28 +0000 | [diff] [blame] | 25 | } |
| 26 | |
Takashi Iwai | 36f048c | 2017-08-15 14:04:16 +0200 | [diff] [blame] | 27 | /* |
| 28 | * Same as SHA1DCUpdate, but adjust types to match git's usual interface. |
| 29 | */ |
Ævar Arnfjörð Bjarmason | a010391 | 2017-05-20 11:54:28 +0000 | [diff] [blame] | 30 | void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *vdata, unsigned long len) |
| 31 | { |
| 32 | const char *data = vdata; |
| 33 | /* We expect an unsigned long, but sha1dc only takes an int */ |
| 34 | while (len > INT_MAX) { |
| 35 | SHA1DCUpdate(ctx, data, INT_MAX); |
| 36 | data += INT_MAX; |
| 37 | len -= INT_MAX; |
| 38 | } |
| 39 | SHA1DCUpdate(ctx, data, len); |
| 40 | } |