]> git.ipfire.org Git - thirdparty/git.git/blame - sha1dc_git.c
replace-object.h: move read_replace_refs declaration from cache.h to here
[thirdparty/git.git] / sha1dc_git.c
CommitLineData
36f048c5 1#include "cache.h"
41771fa4 2#include "hex.h"
36f048c5 3
3964cbbb
TI
4#ifdef DC_SHA1_EXTERNAL
5/*
6 * Same as SHA1DCInit, but with default save_hash=0
7 */
8void git_SHA1DCInit(SHA1_CTX *ctx)
9{
10 SHA1DCInit(ctx);
11 SHA1DCSetSafeHash(ctx, 0);
12}
13#endif
14
a0103914 15/*
36f048c5 16 * Same as SHA1DCFinal, but convert collision attack case into a verbose die().
a0103914 17 */
a0103914
ÆAB
18void git_SHA1DCFinal(unsigned char hash[20], SHA1_CTX *ctx)
19{
20 if (!SHA1DCFinal(hash, ctx))
21 return;
22 die("SHA-1 appears to be part of a collision attack: %s",
b19f3fe9 23 hash_to_hex_algop(hash, &hash_algos[GIT_HASH_SHA1]));
a0103914
ÆAB
24}
25
36f048c5
TI
26/*
27 * Same as SHA1DCUpdate, but adjust types to match git's usual interface.
28 */
a0103914
ÆAB
29void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *vdata, unsigned long len)
30{
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;
37 }
38 SHA1DCUpdate(ctx, data, len);
39}