Add hash_equal() function

This commit is contained in:
Joel Rosdahl 2010-08-13 22:58:06 +02:00
parent f86dbeaf3c
commit 65c847fa22
2 changed files with 10 additions and 0 deletions

View File

@ -71,6 +71,7 @@ void hash_start(struct mdfour *md);
void hash_buffer(struct mdfour *md, const void *s, size_t len);
char *hash_result(struct mdfour *md);
void hash_result_as_bytes(struct mdfour *md, unsigned char *out);
int hash_equal(struct mdfour *md1, struct mdfour *md2);
void hash_delimiter(struct mdfour *md, const char* type);
void hash_string(struct mdfour *md, const char *s);
void hash_int(struct mdfour *md, int x);

9
hash.c
View File

@ -58,6 +58,15 @@ hash_result_as_bytes(struct mdfour *md, unsigned char *out)
mdfour_result(md, out);
}
int
hash_equal(struct mdfour *md1, struct mdfour *md2)
{
unsigned char sum1[16], sum2[16];
hash_result_as_bytes(md1, sum1);
hash_result_as_bytes(md2, sum2);
return memcmp(sum1, sum2, sizeof(sum1)) == 0;
}
/*
* Hash some data that is unlikely to occur in the input. The idea is twofold:
*