replace-object.h: move read_replace_refs declaration from cache.h to here
[git.git] / sha1dc_git.c
blob72709606fdf4aa71a2abb319216f34560e757bed
1 #include "cache.h"
2 #include "hex.h"
4 #ifdef DC_SHA1_EXTERNAL
5 /*
6 * Same as SHA1DCInit, but with default save_hash=0
7 */
8 void git_SHA1DCInit(SHA1_CTX *ctx)
10 SHA1DCInit(ctx);
11 SHA1DCSetSafeHash(ctx, 0);
13 #endif
16 * Same as SHA1DCFinal, but convert collision attack case into a verbose die().
18 void git_SHA1DCFinal(unsigned char hash[20], SHA1_CTX *ctx)
20 if (!SHA1DCFinal(hash, ctx))
21 return;
22 die("SHA-1 appears to be part of a collision attack: %s",
23 hash_to_hex_algop(hash, &hash_algos[GIT_HASH_SHA1]));
27 * Same as SHA1DCUpdate, but adjust types to match git's usual interface.
29 void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *vdata, unsigned long len)
31 const char *data = vdata;
32 /* We expect an unsigned long, but sha1dc only takes an int */
33 while (len > INT_MAX) {
34 SHA1DCUpdate(ctx, data, INT_MAX);
35 data += INT_MAX;
36 len -= INT_MAX;
38 SHA1DCUpdate(ctx, data, len);