Add a return value to hasher_t.get_hash()

This commit is contained in:
Martin Willi
2012-07-16 14:55:06 +02:00
parent ce73fc19db
commit 8bd6a30af1
23 changed files with 174 additions and 89 deletions
+11 -6
View File
@@ -688,8 +688,10 @@ static u_int bench_hasher(private_crypto_tester_t *this,
start_timing(&start);
while (end_timing(&start) < this->bench_time)
{
hasher->get_hash(hasher, buf, hash);
runs++;
if (hasher->get_hash(hasher, buf, hash))
{
runs++;
}
}
free(buf.ptr);
hasher->destroy(hasher);
@@ -744,7 +746,10 @@ METHOD(crypto_tester_t, test_hasher, bool,
}
/* hash to existing buffer */
memset(hash.ptr, 0, hash.len);
hasher->get_hash(hasher, data, hash.ptr);
if (!hasher->get_hash(hasher, data, hash.ptr))
{
failed = TRUE;
}
if (!memeq(vector->hash, hash.ptr, hash.len))
{
failed = TRUE;
@@ -754,9 +759,9 @@ METHOD(crypto_tester_t, test_hasher, bool,
{
memset(hash.ptr, 0, hash.len);
hasher->allocate_hash(hasher, chunk_create(data.ptr, 1), NULL);
hasher->get_hash(hasher, chunk_create(data.ptr + 1, 1), NULL);
hasher->get_hash(hasher, chunk_skip(data, 2), hash.ptr);
if (!memeq(vector->hash, hash.ptr, hash.len))
if (!hasher->get_hash(hasher, chunk_create(data.ptr + 1, 1), NULL) ||
!hasher->get_hash(hasher, chunk_skip(data, 2), hash.ptr) ||
!memeq(vector->hash, hash.ptr, hash.len))
{
failed = TRUE;
}
+4 -1
View File
@@ -67,6 +67,7 @@ extern enum_name_t *hash_algorithm_names;
* Generic interface for all hash functions.
*/
struct hasher_t {
/**
* Hash data and write it in the buffer.
*
@@ -79,8 +80,10 @@ struct hasher_t {
*
* @param data data to hash
* @param hash pointer where the hash will be written
* @return TRUE if hash created successfully
*/
void (*get_hash) (hasher_t *this, chunk_t data, u_int8_t *hash);
__attribute__((warn_unused_result))
bool (*get_hash) (hasher_t *this, chunk_t data, u_int8_t *hash);
/**
* Hash data and allocate space for the hash.