Add a return value to hasher_t.reset()
This commit is contained in:
parent
87dd205b61
commit
e3b2e900e6
|
@ -108,8 +108,11 @@ struct hasher_t {
|
|||
|
||||
/**
|
||||
* Resets the hasher's state.
|
||||
*
|
||||
* @return TRUE if hasher reset successfully
|
||||
*/
|
||||
void (*reset) (hasher_t *this);
|
||||
__attribute__((warn_unused_result))
|
||||
bool (*reset) (hasher_t *this);
|
||||
|
||||
/**
|
||||
* Destroys a hasher object.
|
||||
|
|
|
@ -99,10 +99,11 @@ METHOD(hasher_t, get_hash_size, size_t,
|
|||
return this->size;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, reset, void,
|
||||
METHOD(hasher_t, reset, bool,
|
||||
private_af_alg_hasher_t *this)
|
||||
{
|
||||
this->ops->reset(this->ops);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash, bool,
|
||||
|
|
|
@ -43,10 +43,11 @@ METHOD(hasher_t, get_hash_size, size_t,
|
|||
return gcry_md_get_algo_dlen(gcry_md_get_algo(this->hd));
|
||||
}
|
||||
|
||||
METHOD(hasher_t, reset, void,
|
||||
METHOD(hasher_t, reset, bool,
|
||||
private_gcrypt_hasher_t *this)
|
||||
{
|
||||
gcry_md_reset(this->hd);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash, bool,
|
||||
|
|
|
@ -122,8 +122,8 @@ METHOD(mac_t, set_key, bool,
|
|||
}
|
||||
|
||||
/* begin hashing of inner pad */
|
||||
this->h->reset(this->h);
|
||||
return this->h->get_hash(this->h, this->ipaded_key, NULL);
|
||||
return this->h->reset(this->h) &&
|
||||
this->h->get_hash(this->h, this->ipaded_key, NULL);
|
||||
}
|
||||
|
||||
METHOD(mac_t, destroy, void,
|
||||
|
|
|
@ -266,6 +266,19 @@ static void MD4Final (private_md4_hasher_t *this, u_int8_t digest[16])
|
|||
}
|
||||
}
|
||||
|
||||
METHOD(hasher_t, reset, bool,
|
||||
private_md4_hasher_t *this)
|
||||
{
|
||||
this->state[0] = 0x67452301;
|
||||
this->state[1] = 0xefcdab89;
|
||||
this->state[2] = 0x98badcfe;
|
||||
this->state[3] = 0x10325476;
|
||||
this->count[0] = 0;
|
||||
this->count[1] = 0;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash, bool,
|
||||
private_md4_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
|
||||
{
|
||||
|
@ -273,7 +286,7 @@ METHOD(hasher_t, get_hash, bool,
|
|||
if (buffer != NULL)
|
||||
{
|
||||
MD4Final(this, buffer);
|
||||
this->public.hasher_interface.reset(&(this->public.hasher_interface));
|
||||
reset(this);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -290,7 +303,7 @@ METHOD(hasher_t, allocate_hash, bool,
|
|||
allocated_hash.len = HASH_SIZE_MD4;
|
||||
|
||||
MD4Final(this, allocated_hash.ptr);
|
||||
this->public.hasher_interface.reset(&(this->public.hasher_interface));
|
||||
reset(this);
|
||||
|
||||
*hash = allocated_hash;
|
||||
}
|
||||
|
@ -303,17 +316,6 @@ METHOD(hasher_t, get_hash_size, size_t,
|
|||
return HASH_SIZE_MD4;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, reset, void,
|
||||
private_md4_hasher_t *this)
|
||||
{
|
||||
this->state[0] = 0x67452301;
|
||||
this->state[1] = 0xefcdab89;
|
||||
this->state[2] = 0x98badcfe;
|
||||
this->state[3] = 0x10325476;
|
||||
this->count[0] = 0;
|
||||
this->count[1] = 0;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, destroy, void,
|
||||
private_md4_hasher_t *this)
|
||||
{
|
||||
|
|
|
@ -299,44 +299,7 @@ static void MD5Final (private_md5_hasher_t *this, u_int8_t digest[16])
|
|||
}
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash, bool,
|
||||
private_md5_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
|
||||
{
|
||||
MD5Update(this, chunk.ptr, chunk.len);
|
||||
if (buffer != NULL)
|
||||
{
|
||||
MD5Final(this, buffer);
|
||||
this->public.hasher_interface.reset(&(this->public.hasher_interface));
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash, bool,
|
||||
private_md5_hasher_t *this, chunk_t chunk, chunk_t *hash)
|
||||
{
|
||||
chunk_t allocated_hash;
|
||||
|
||||
MD5Update(this, chunk.ptr, chunk.len);
|
||||
if (hash != NULL)
|
||||
{
|
||||
allocated_hash.ptr = malloc(HASH_SIZE_MD5);
|
||||
allocated_hash.len = HASH_SIZE_MD5;
|
||||
|
||||
MD5Final(this, allocated_hash.ptr);
|
||||
this->public.hasher_interface.reset(&(this->public.hasher_interface));
|
||||
|
||||
*hash = allocated_hash;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash_size, size_t,
|
||||
private_md5_hasher_t *this)
|
||||
{
|
||||
return HASH_SIZE_MD5;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, reset, void,
|
||||
METHOD(hasher_t, reset, bool,
|
||||
private_md5_hasher_t *this)
|
||||
{
|
||||
this->state[0] = 0x67452301;
|
||||
|
@ -345,6 +308,39 @@ METHOD(hasher_t, reset, void,
|
|||
this->state[3] = 0x10325476;
|
||||
this->count[0] = 0;
|
||||
this->count[1] = 0;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash, bool,
|
||||
private_md5_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
|
||||
{
|
||||
MD5Update(this, chunk.ptr, chunk.len);
|
||||
if (buffer != NULL)
|
||||
{
|
||||
MD5Final(this, buffer);
|
||||
reset(this);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash, bool,
|
||||
private_md5_hasher_t *this, chunk_t chunk, chunk_t *hash)
|
||||
{
|
||||
MD5Update(this, chunk.ptr, chunk.len);
|
||||
if (hash != NULL)
|
||||
{
|
||||
*hash = chunk_alloc(HASH_SIZE_MD5);
|
||||
MD5Final(this, hash->ptr);
|
||||
reset(this);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash_size, size_t,
|
||||
private_md5_hasher_t *this)
|
||||
{
|
||||
return HASH_SIZE_MD5;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, destroy, void,
|
||||
|
|
|
@ -96,10 +96,10 @@ METHOD(hasher_t, get_hash_size, size_t,
|
|||
return this->hasher->md_size;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, reset, void,
|
||||
METHOD(hasher_t, reset, bool,
|
||||
private_openssl_hasher_t *this)
|
||||
{
|
||||
EVP_DigestInit_ex(this->ctx, this->hasher, NULL);
|
||||
return EVP_DigestInit_ex(this->ctx, this->hasher, NULL) == 1;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash, bool,
|
||||
|
@ -115,7 +115,7 @@ METHOD(hasher_t, get_hash, bool,
|
|||
{
|
||||
return FALSE;
|
||||
}
|
||||
reset(this);
|
||||
return reset(this);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -175,7 +175,11 @@ openssl_hasher_t *openssl_hasher_create(hash_algorithm_t algo)
|
|||
this->ctx = EVP_MD_CTX_create();
|
||||
|
||||
/* initialization */
|
||||
reset(this);
|
||||
if (!reset(this))
|
||||
{
|
||||
destroy(this);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
|
|
@ -83,10 +83,11 @@ static void append_data(private_padlock_sha1_hasher_t *this, chunk_t data)
|
|||
this->data.len += data.len;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, reset, void,
|
||||
METHOD(hasher_t, reset, bool,
|
||||
private_padlock_sha1_hasher_t *this)
|
||||
{
|
||||
chunk_free(&this->data);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash, bool,
|
||||
|
|
|
@ -138,10 +138,11 @@ static bool load_state(private_pkcs11_hasher_t *this)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, reset, void,
|
||||
METHOD(hasher_t, reset, bool,
|
||||
private_pkcs11_hasher_t *this)
|
||||
{
|
||||
this->have_state = FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash, bool,
|
||||
|
|
|
@ -175,7 +175,7 @@ static void SHA1Final(private_sha1_hasher_t *this, u_int8_t *digest)
|
|||
}
|
||||
}
|
||||
|
||||
METHOD(hasher_t, reset, void,
|
||||
METHOD(hasher_t, reset, bool,
|
||||
private_sha1_hasher_t *this)
|
||||
{
|
||||
this->state[0] = 0x67452301;
|
||||
|
@ -185,6 +185,8 @@ METHOD(hasher_t, reset, void,
|
|||
this->state[4] = 0xC3D2E1F0;
|
||||
this->count[0] = 0;
|
||||
this->count[1] = 0;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash, bool,
|
||||
|
|
|
@ -100,7 +100,11 @@ METHOD(prf_t, set_key, bool,
|
|||
int i, rounds;
|
||||
u_int32_t *iv = (u_int32_t*)key.ptr;
|
||||
|
||||
this->hasher->public.hasher_interface.reset(&this->hasher->public.hasher_interface);
|
||||
if (!this->hasher->public.hasher_interface.reset(
|
||||
&this->hasher->public.hasher_interface))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
rounds = min(key.len/sizeof(u_int32_t), sizeof(this->hasher->state));
|
||||
for (i = 0; i < rounds; i++)
|
||||
{
|
||||
|
|
|
@ -426,38 +426,46 @@ static void sha512_final(private_sha512_hasher_t *ctx)
|
|||
} while(++j < 8);
|
||||
}
|
||||
|
||||
METHOD(hasher_t, reset224, void,
|
||||
METHOD(hasher_t, reset224, bool,
|
||||
private_sha256_hasher_t *this)
|
||||
{
|
||||
memcpy(&this->sha_H[0], &sha224_hashInit[0], sizeof(this->sha_H));
|
||||
this->sha_blocks = 0;
|
||||
this->sha_bufCnt = 0;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, reset256, void,
|
||||
METHOD(hasher_t, reset256, bool,
|
||||
private_sha256_hasher_t *this)
|
||||
{
|
||||
memcpy(&this->sha_H[0], &sha256_hashInit[0], sizeof(this->sha_H));
|
||||
this->sha_blocks = 0;
|
||||
this->sha_bufCnt = 0;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, reset384, void,
|
||||
METHOD(hasher_t, reset384, bool,
|
||||
private_sha512_hasher_t *this)
|
||||
{
|
||||
memcpy(&this->sha_H[0], &sha384_hashInit[0], sizeof(this->sha_H));
|
||||
this->sha_blocks = 0;
|
||||
this->sha_blocksMSB = 0;
|
||||
this->sha_bufCnt = 0;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, reset512, void,
|
||||
METHOD(hasher_t, reset512, bool,
|
||||
private_sha512_hasher_t *this)
|
||||
{
|
||||
memcpy(&this->sha_H[0], &sha512_hashInit[0], sizeof(this->sha_H));
|
||||
this->sha_blocks = 0;
|
||||
this->sha_blocksMSB = 0;
|
||||
this->sha_bufCnt = 0;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash224, bool,
|
||||
|
|
Loading…
Reference in New Issue