blob: 5c300e812e0a11960dba743773720246e1a84cf1 [file] [log] [blame]
Takashi Iwai36f048c2017-08-15 14:04:16 +02001#include "cache.h"
Ævar Arnfjörð Bjarmasona0103912017-05-20 11:54:28 +00002
Takashi Iwai3964cbb2017-08-15 14:04:17 +02003#ifdef DC_SHA1_EXTERNAL
4/*
5 * Same as SHA1DCInit, but with default save_hash=0
6 */
7void git_SHA1DCInit(SHA1_CTX *ctx)
8{
9 SHA1DCInit(ctx);
10 SHA1DCSetSafeHash(ctx, 0);
11}
12#endif
13
Takashi Iwai36f048c2017-08-15 14:04:16 +020014/*
15 * Same as SHA1DCFinal, but convert collision attack case into a verbose die().
16 */
Ævar Arnfjörð Bjarmasona0103912017-05-20 11:54:28 +000017void git_SHA1DCFinal(unsigned char hash[20], SHA1_CTX *ctx)
18{
19 if (!SHA1DCFinal(hash, ctx))
20 return;
21 die("SHA-1 appears to be part of a collision attack: %s",
Jeff Kingb19f3fe2019-11-11 04:04:18 -050022 hash_to_hex_algop(hash, &hash_algos[GIT_HASH_SHA1]));
Ævar Arnfjörð Bjarmasona0103912017-05-20 11:54:28 +000023}
24
Takashi Iwai36f048c2017-08-15 14:04:16 +020025/*
26 * Same as SHA1DCUpdate, but adjust types to match git's usual interface.
27 */
Ævar Arnfjörð Bjarmasona0103912017-05-20 11:54:28 +000028void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *vdata, unsigned long len)
29{
30 const char *data = vdata;
31 /* We expect an unsigned long, but sha1dc only takes an int */
32 while (len > INT_MAX) {
33 SHA1DCUpdate(ctx, data, INT_MAX);
34 data += INT_MAX;
35 len -= INT_MAX;
36 }
37 SHA1DCUpdate(ctx, data, len);
38}