#include "ccache.h"
#include "hash.h"
-#include "mdfour.h"
+#include <blake2.h>
#define HASH_DELIMITER "\000cCaChE"
struct hash {
- struct mdfour md;
+ blake2b_state state;
FILE *debug_binary;
FILE *debug_text;
};
{
assert(s);
- mdfour_update(&hash->md, (const unsigned char *)s, len);
+ blake2b_update(&hash->state, (const uint8_t *)s, len);
if (len > 0 && hash->debug_binary) {
(void) fwrite(s, 1, len, hash->debug_binary);
}
hash_init(void)
{
struct hash *hash = malloc(sizeof(struct hash));
- mdfour_begin(&hash->md);
+ blake2b_init(&hash->state, DIGEST_SIZE);
hash->debug_binary = NULL;
hash->debug_text = NULL;
return hash;
hash_copy(struct hash *hash)
{
struct hash *result = malloc(sizeof(struct hash));
- result->md = hash->md;
+ result->state = hash->state;
result->debug_binary = NULL;
result->debug_text = NULL;
return result;
void
hash_result_as_bytes(struct hash *hash, struct digest *digest)
{
- mdfour_result(&hash->md, digest->bytes);
- size_t input_size = hash->md.totalN + hash->md.tail_len;
- for (size_t i = 0; i < 4; i++) {
- digest->bytes[16 + i] = (input_size >> ((3 - i) * 8)) & 0xFF;
- }
+ // make a copy before altering state
+ struct hash *copy = hash_copy(hash);
+ blake2b_final(©->state, digest->bytes, DIGEST_SIZE);
+ hash_free(copy);
}
void
manifest=`find $CCACHE_DIR -name '*.manifest'`
$CCACHE --dump-manifest $manifest >manifest.dump
- if grep 'Hash: d4de2f956b4a386c6660990a7a1ab13f0000001e' manifest.dump >/dev/null && \
- grep 'Hash: e94ceb9f1b196c387d098a5f1f4fe8620000000b' manifest.dump >/dev/null && \
- grep 'Hash: ba753bebf9b5eb99524bb7447095e2e60000000b' manifest.dump >/dev/null; then
+ checksum_test1_h='7706603374730d6e19c22f607768040f13be686d'
+ checksum_test2_h='0f1d0cf7d790a6a31248d8a52e826dad433d191c'
+ checksum_test3_h='d07f2a91a649bc56a1b008279b326201077d341b'
+
+ if grep "Hash: $checksum_test1_h" manifest.dump >/dev/null 2>&1 && \
+ grep "Hash: $checksum_test2_h" manifest.dump >/dev/null 2>&1 && \
+ grep "Hash: $checksum_test3_h" manifest.dump >/dev/null 2>&1; then
: OK
else
test_failed "Unexpected output of --dump-manifest"
struct hash *h = hash_init();
hash_string(h, "");
hash_result_as_string(h, d);
- CHECK_STR_EQ("31d6cfe0d16ae931b73c59d7e0c089c000000000", d);
+ CHECK_STR_EQ("3345524abf6bbe1809449224b5972c41790b6cf2", d);
hash_free(h);
}
struct hash *h = hash_init();
hash_string(h, "a");
hash_result_as_string(h, d);
- CHECK_STR_EQ("bde52cb31de33e46245e05fbdbd6fb2400000001", d);
+ CHECK_STR_EQ("948caa2db61bc4cdb4faf7740cd491f195043914", d);
hash_free(h);
}
struct hash *h = hash_init();
hash_string(h, "message digest");
hash_result_as_string(h, d);
- CHECK_STR_EQ("d9130a8164549fe818874806e1c7014b0000000e", d);
+ CHECK_STR_EQ("6bfec6f65e52962be863d6ea1005fc5e4cc8478c", d);
hash_free(h);
}
"12345678901234567890123456789012345678901234567890123456789012345678901"
"234567890");
hash_result_as_string(h, d);
- CHECK_STR_EQ("e33b4ddc9c38f2199c3e7b164fcc053600000050", d);
+ CHECK_STR_EQ("c2be0e534a67d25947f0c7e78527b2f82abd260f", d);
hash_free(h);
}
}
hash_result_as_string(h, d);
hash_string(h, " digest");
hash_result_as_string(h, d);
- CHECK_STR_EQ("d9130a8164549fe818874806e1c7014b0000000e", d);
+ CHECK_STR_EQ("6bfec6f65e52962be863d6ea1005fc5e4cc8478c", d);
hash_free(h);
}
struct hash *h = hash_init();
hash_string(h, "");
hash_result_as_string(h, d);
- CHECK_STR_EQ("31d6cfe0d16ae931b73c59d7e0c089c000000000", d);
+ CHECK_STR_EQ("3345524abf6bbe1809449224b5972c41790b6cf2", d);
hash_result_as_string(h, d);
- CHECK_STR_EQ("31d6cfe0d16ae931b73c59d7e0c089c000000000", d);
+ CHECK_STR_EQ("3345524abf6bbe1809449224b5972c41790b6cf2", d);
hash_free(h);
}
struct digest d;
hash_result_as_bytes(h, &d);
uint8_t expected[sizeof(d.bytes)] = {
- 0xd9, 0x13, 0x0a, 0x81, 0x64, 0x54, 0x9f, 0xe8, 0x18, 0x87, 0x48, 0x06,
- 0xe1, 0xc7, 0x01, 0x4b, 0x00, 0x00, 0x00, 0x0e
+ 0x6b, 0xfe, 0xc6, 0xf6, 0x5e, 0x52, 0x96, 0x2b, 0xe8, 0x63, 0xd6, 0xea,
+ 0x10, 0x05, 0xfc, 0x5e, 0x4c, 0xc8, 0x47, 0x8c
};
CHECK_DATA_EQ(d.bytes, expected, sizeof(d.bytes));
hash_free(h);