Add a return value to hasher_t.get_hash()
This commit is contained in:
@@ -105,10 +105,11 @@ METHOD(hasher_t, reset, void,
|
||||
this->ops->reset(this->ops);
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash, void,
|
||||
METHOD(hasher_t, get_hash, bool,
|
||||
private_af_alg_hasher_t *this, chunk_t chunk, u_int8_t *hash)
|
||||
{
|
||||
this->ops->hash(this->ops, chunk, hash, this->size);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash, void,
|
||||
|
||||
@@ -49,7 +49,7 @@ METHOD(hasher_t, reset, void,
|
||||
gcry_md_reset(this->hd);
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash, void,
|
||||
METHOD(hasher_t, get_hash, bool,
|
||||
private_gcrypt_hasher_t *this, chunk_t chunk, u_int8_t *hash)
|
||||
{
|
||||
gcry_md_write(this->hd, chunk.ptr, chunk.len);
|
||||
@@ -58,6 +58,7 @@ METHOD(hasher_t, get_hash, void,
|
||||
memcpy(hash, gcry_md_read(this->hd, 0), get_hash_size(this));
|
||||
gcry_md_reset(this->hd);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash, void,
|
||||
|
||||
@@ -72,25 +72,18 @@ METHOD(mac_t, get_mac, bool,
|
||||
if (out == NULL)
|
||||
{
|
||||
/* append data to inner */
|
||||
this->h->get_hash(this->h, data, NULL);
|
||||
return this->h->get_hash(this->h, data, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* append and do outer hash */
|
||||
inner.ptr = buffer;
|
||||
inner.len = this->h->get_hash_size(this->h);
|
||||
|
||||
/* complete inner */
|
||||
this->h->get_hash(this->h, data, buffer);
|
||||
/* append and do outer hash */
|
||||
inner.ptr = buffer;
|
||||
inner.len = this->h->get_hash_size(this->h);
|
||||
|
||||
/* do outer */
|
||||
this->h->get_hash(this->h, this->opaded_key, NULL);
|
||||
this->h->get_hash(this->h, inner, out);
|
||||
|
||||
/* reinit for next call */
|
||||
this->h->get_hash(this->h, this->ipaded_key, NULL);
|
||||
}
|
||||
return TRUE;
|
||||
/* complete inner, do outer and reinit for next call */
|
||||
return this->h->get_hash(this->h, data, buffer) &&
|
||||
this->h->get_hash(this->h, this->opaded_key, NULL) &&
|
||||
this->h->get_hash(this->h, inner, out) &&
|
||||
this->h->get_hash(this->h, this->ipaded_key, NULL);
|
||||
}
|
||||
|
||||
METHOD(mac_t, get_mac_size, size_t,
|
||||
@@ -110,7 +103,10 @@ METHOD(mac_t, set_key, bool,
|
||||
if (key.len > this->b)
|
||||
{
|
||||
/* if key is too long, it will be hashed */
|
||||
this->h->get_hash(this->h, key, buffer);
|
||||
if (!this->h->get_hash(this->h, key, buffer))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -127,9 +123,7 @@ METHOD(mac_t, set_key, bool,
|
||||
|
||||
/* begin hashing of inner pad */
|
||||
this->h->reset(this->h);
|
||||
this->h->get_hash(this->h, this->ipaded_key, NULL);
|
||||
|
||||
return TRUE;
|
||||
return this->h->get_hash(this->h, this->ipaded_key, NULL);
|
||||
}
|
||||
|
||||
METHOD(mac_t, destroy, void,
|
||||
|
||||
@@ -268,7 +268,7 @@ static void MD4Final (private_md4_hasher_t *this, u_int8_t digest[16])
|
||||
|
||||
|
||||
|
||||
METHOD(hasher_t, get_hash, void,
|
||||
METHOD(hasher_t, get_hash, bool,
|
||||
private_md4_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
|
||||
{
|
||||
MD4Update(this, chunk.ptr, chunk.len);
|
||||
@@ -277,6 +277,7 @@ METHOD(hasher_t, get_hash, void,
|
||||
MD4Final(this, buffer);
|
||||
this->public.hasher_interface.reset(&(this->public.hasher_interface));
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash, void,
|
||||
|
||||
@@ -299,7 +299,7 @@ static void MD5Final (private_md5_hasher_t *this, u_int8_t digest[16])
|
||||
}
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash, void,
|
||||
METHOD(hasher_t, get_hash, bool,
|
||||
private_md5_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
|
||||
{
|
||||
MD5Update(this, chunk.ptr, chunk.len);
|
||||
@@ -308,6 +308,7 @@ METHOD(hasher_t, get_hash, void,
|
||||
MD5Final(this, buffer);
|
||||
this->public.hasher_interface.reset(&(this->public.hasher_interface));
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash, void,
|
||||
|
||||
@@ -102,15 +102,22 @@ METHOD(hasher_t, reset, void,
|
||||
EVP_DigestInit_ex(this->ctx, this->hasher, NULL);
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash, void,
|
||||
METHOD(hasher_t, get_hash, bool,
|
||||
private_openssl_hasher_t *this, chunk_t chunk, u_int8_t *hash)
|
||||
{
|
||||
EVP_DigestUpdate(this->ctx, chunk.ptr, chunk.len);
|
||||
if (EVP_DigestUpdate(this->ctx, chunk.ptr, chunk.len) != 1)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if (hash)
|
||||
{
|
||||
EVP_DigestFinal_ex(this->ctx, hash, NULL);
|
||||
if (EVP_DigestFinal_ex(this->ctx, hash, NULL) != 1)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
reset(this);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash, void,
|
||||
|
||||
@@ -89,7 +89,7 @@ METHOD(hasher_t, reset, void,
|
||||
chunk_free(&this->data);
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash, void,
|
||||
METHOD(hasher_t, get_hash, bool,
|
||||
private_padlock_sha1_hasher_t *this, chunk_t chunk, u_int8_t *hash)
|
||||
{
|
||||
if (hash)
|
||||
@@ -109,6 +109,7 @@ METHOD(hasher_t, get_hash, void,
|
||||
{
|
||||
append_data(this, chunk);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash, void,
|
||||
|
||||
@@ -104,15 +104,21 @@ static status_t pem_decrypt(chunk_t *blob, encryption_algorithm_t alg,
|
||||
}
|
||||
hash.len = hasher->get_hash_size(hasher);
|
||||
hash.ptr = alloca(hash.len);
|
||||
hasher->get_hash(hasher, passphrase, NULL);
|
||||
hasher->get_hash(hasher, salt, hash.ptr);
|
||||
if (!hasher->get_hash(hasher, passphrase, NULL) ||
|
||||
!hasher->get_hash(hasher, salt, hash.ptr))
|
||||
{
|
||||
return FAILED;
|
||||
}
|
||||
memcpy(key.ptr, hash.ptr, hash.len);
|
||||
|
||||
if (key.len > hash.len)
|
||||
{
|
||||
hasher->get_hash(hasher, hash, NULL);
|
||||
hasher->get_hash(hasher, passphrase, NULL);
|
||||
hasher->get_hash(hasher, salt, hash.ptr);
|
||||
if (!hasher->get_hash(hasher, hash, NULL) ||
|
||||
!hasher->get_hash(hasher, passphrase, NULL) ||
|
||||
!hasher->get_hash(hasher, salt, hash.ptr))
|
||||
{
|
||||
return FAILED;
|
||||
}
|
||||
memcpy(key.ptr + hash.len, hash.ptr, key.len - hash.len);
|
||||
}
|
||||
hasher->destroy(hasher);
|
||||
|
||||
@@ -84,7 +84,7 @@ METHOD(hasher_t, get_hash_size, size_t,
|
||||
/**
|
||||
* Save the Operation state to host memory
|
||||
*/
|
||||
static void save_state(private_pkcs11_hasher_t *this)
|
||||
static bool save_state(private_pkcs11_hasher_t *this)
|
||||
{
|
||||
CK_RV rv;
|
||||
|
||||
@@ -110,20 +110,20 @@ static void save_state(private_pkcs11_hasher_t *this)
|
||||
continue;
|
||||
case CKR_OK:
|
||||
this->have_state = TRUE;
|
||||
return;
|
||||
return TRUE;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
DBG1(DBG_CFG, "C_GetOperationState() failed: %N", ck_rv_names, rv);
|
||||
abort();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the Operation state from host memory
|
||||
*/
|
||||
static void load_state(private_pkcs11_hasher_t *this)
|
||||
static bool load_state(private_pkcs11_hasher_t *this)
|
||||
{
|
||||
CK_RV rv;
|
||||
|
||||
@@ -132,9 +132,10 @@ static void load_state(private_pkcs11_hasher_t *this)
|
||||
if (rv != CKR_OK)
|
||||
{
|
||||
DBG1(DBG_CFG, "C_SetOperationState() failed: %N", ck_rv_names, rv);
|
||||
abort();
|
||||
return FALSE;
|
||||
}
|
||||
this->have_state = FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, reset, void,
|
||||
@@ -143,7 +144,7 @@ METHOD(hasher_t, reset, void,
|
||||
this->have_state = FALSE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash, void,
|
||||
METHOD(hasher_t, get_hash, bool,
|
||||
private_pkcs11_hasher_t *this, chunk_t chunk, u_int8_t *hash)
|
||||
{
|
||||
CK_RV rv;
|
||||
@@ -152,7 +153,11 @@ METHOD(hasher_t, get_hash, void,
|
||||
this->mutex->lock(this->mutex);
|
||||
if (this->have_state)
|
||||
{
|
||||
load_state(this);
|
||||
if (!load_state(this))
|
||||
{
|
||||
this->mutex->unlock(this->mutex);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -160,7 +165,8 @@ METHOD(hasher_t, get_hash, void,
|
||||
if (rv != CKR_OK)
|
||||
{
|
||||
DBG1(DBG_CFG, "C_DigestInit() failed: %N", ck_rv_names, rv);
|
||||
abort();
|
||||
this->mutex->unlock(this->mutex);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
if (chunk.len)
|
||||
@@ -169,7 +175,8 @@ METHOD(hasher_t, get_hash, void,
|
||||
if (rv != CKR_OK)
|
||||
{
|
||||
DBG1(DBG_CFG, "C_DigestUpdate() failed: %N", ck_rv_names, rv);
|
||||
abort();
|
||||
this->mutex->unlock(this->mutex);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
if (hash)
|
||||
@@ -180,14 +187,20 @@ METHOD(hasher_t, get_hash, void,
|
||||
if (rv != CKR_OK)
|
||||
{
|
||||
DBG1(DBG_CFG, "C_DigestFinal() failed: %N", ck_rv_names, rv);
|
||||
abort();
|
||||
this->mutex->unlock(this->mutex);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
save_state(this);
|
||||
if (!save_state(this))
|
||||
{
|
||||
this->mutex->unlock(this->mutex);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
this->mutex->unlock(this->mutex);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash, void,
|
||||
|
||||
@@ -293,12 +293,18 @@ static bool pbkdf1(hasher_t *hasher, chunk_t password, chunk_t salt,
|
||||
u_int64_t i;
|
||||
|
||||
hash = chunk_alloca(hasher->get_hash_size(hasher));
|
||||
hasher->get_hash(hasher, password, NULL);
|
||||
hasher->get_hash(hasher, salt, hash.ptr);
|
||||
if (!hasher->get_hash(hasher, password, NULL) ||
|
||||
!hasher->get_hash(hasher, salt, hash.ptr))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (i = 1; i < iterations; i++)
|
||||
{
|
||||
hasher->get_hash(hasher, hash, hash.ptr);
|
||||
if (!hasher->get_hash(hasher, hash, hash.ptr))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(key.ptr, hash.ptr, key.len);
|
||||
|
||||
@@ -187,7 +187,7 @@ METHOD(hasher_t, reset, void,
|
||||
this->count[1] = 0;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash, void,
|
||||
METHOD(hasher_t, get_hash, bool,
|
||||
private_sha1_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
|
||||
{
|
||||
SHA1Update(this, chunk.ptr, chunk.len);
|
||||
@@ -196,6 +196,7 @@ METHOD(hasher_t, get_hash, void,
|
||||
SHA1Final(this, buffer);
|
||||
reset(this);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash, void,
|
||||
|
||||
@@ -460,7 +460,7 @@ METHOD(hasher_t, reset512, void,
|
||||
this->sha_bufCnt = 0;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash224, void,
|
||||
METHOD(hasher_t, get_hash224, bool,
|
||||
private_sha256_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
|
||||
{
|
||||
sha256_write(this, chunk.ptr, chunk.len);
|
||||
@@ -470,9 +470,10 @@ METHOD(hasher_t, get_hash224, void,
|
||||
memcpy(buffer, this->sha_out, HASH_SIZE_SHA224);
|
||||
reset224(this);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash256, void,
|
||||
METHOD(hasher_t, get_hash256, bool,
|
||||
private_sha256_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
|
||||
{
|
||||
sha256_write(this, chunk.ptr, chunk.len);
|
||||
@@ -482,9 +483,10 @@ METHOD(hasher_t, get_hash256, void,
|
||||
memcpy(buffer, this->sha_out, HASH_SIZE_SHA256);
|
||||
reset256(this);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash384, void,
|
||||
METHOD(hasher_t, get_hash384, bool,
|
||||
private_sha512_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
|
||||
{
|
||||
sha512_write(this, chunk.ptr, chunk.len);
|
||||
@@ -494,9 +496,10 @@ METHOD(hasher_t, get_hash384, void,
|
||||
memcpy(buffer, this->sha_out, HASH_SIZE_SHA384);
|
||||
reset384(this);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash512, void,
|
||||
METHOD(hasher_t, get_hash512, bool,
|
||||
private_sha512_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
|
||||
{
|
||||
sha512_write(this, chunk.ptr, chunk.len);
|
||||
@@ -506,6 +509,7 @@ METHOD(hasher_t, get_hash512, void,
|
||||
memcpy(buffer, this->sha_out, HASH_SIZE_SHA512);
|
||||
reset512(this);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash224, void,
|
||||
|
||||
Reference in New Issue
Block a user