Add a return value to hasher_t.allocate_hash()
This commit is contained in:
@@ -112,18 +112,15 @@ METHOD(hasher_t, get_hash, bool,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash, void,
|
||||
METHOD(hasher_t, allocate_hash, bool,
|
||||
private_af_alg_hasher_t *this, chunk_t chunk, chunk_t *hash)
|
||||
{
|
||||
if (hash)
|
||||
{
|
||||
*hash = chunk_alloc(get_hash_size(this));
|
||||
get_hash(this, chunk, hash->ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
get_hash(this, chunk, NULL);
|
||||
return get_hash(this, chunk, hash->ptr);
|
||||
}
|
||||
return get_hash(this, chunk, NULL);
|
||||
}
|
||||
|
||||
METHOD(hasher_t, destroy, void,
|
||||
|
||||
@@ -61,18 +61,15 @@ METHOD(hasher_t, get_hash, bool,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash, void,
|
||||
METHOD(hasher_t, allocate_hash, bool,
|
||||
private_gcrypt_hasher_t *this, chunk_t chunk, chunk_t *hash)
|
||||
{
|
||||
if (hash)
|
||||
{
|
||||
*hash = chunk_alloc(get_hash_size(this));
|
||||
get_hash(this, chunk, hash->ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
get_hash(this, chunk, NULL);
|
||||
return get_hash(this, chunk, hash->ptr);
|
||||
}
|
||||
return get_hash(this, chunk, NULL);
|
||||
}
|
||||
|
||||
METHOD(hasher_t, destroy, void,
|
||||
|
||||
@@ -165,11 +165,11 @@ static bool sign_pkcs1(private_gcrypt_rsa_private_key_t *this,
|
||||
return FALSE;
|
||||
}
|
||||
hasher = lib->crypto->create_hasher(lib->crypto, hash_algorithm);
|
||||
if (!hasher)
|
||||
if (!hasher || !hasher->allocate_hash(hasher, data, &hash))
|
||||
{
|
||||
DESTROY_IF(hasher);
|
||||
return FALSE;
|
||||
}
|
||||
hasher->allocate_hash(hasher, data, &hash);
|
||||
hasher->destroy(hasher);
|
||||
|
||||
err = gcry_sexp_build(&in, NULL, "(data(flags pkcs1)(hash %s %b))",
|
||||
|
||||
@@ -121,11 +121,11 @@ static bool verify_pkcs1(private_gcrypt_rsa_public_key_t *this,
|
||||
gcry_sexp_t in, sig;
|
||||
|
||||
hasher = lib->crypto->create_hasher(lib->crypto, algorithm);
|
||||
if (!hasher)
|
||||
if (!hasher || !hasher->allocate_hash(hasher, data, &hash))
|
||||
{
|
||||
DESTROY_IF(hasher);
|
||||
return FALSE;
|
||||
}
|
||||
hasher->allocate_hash(hasher, data, &hash);
|
||||
hasher->destroy(hasher);
|
||||
|
||||
err = gcry_sexp_build(&in, NULL, "(data(flags pkcs1)(hash %s %b))",
|
||||
|
||||
@@ -235,11 +235,11 @@ static bool build_emsa_pkcs1_signature(private_gmp_rsa_private_key_t *this,
|
||||
}
|
||||
|
||||
hasher = lib->crypto->create_hasher(lib->crypto, hash_algorithm);
|
||||
if (hasher == NULL)
|
||||
if (!hasher || !hasher->allocate_hash(hasher, data, &hash))
|
||||
{
|
||||
DESTROY_IF(hasher);
|
||||
return FALSE;
|
||||
}
|
||||
hasher->allocate_hash(hasher, data, &hash);
|
||||
hasher->destroy(hasher);
|
||||
|
||||
/* build DER-encoded digestInfo */
|
||||
|
||||
@@ -252,7 +252,11 @@ static bool verify_emsa_pkcs1_signature(private_gmp_rsa_public_key_t *this,
|
||||
}
|
||||
|
||||
/* build our own hash and compare */
|
||||
hasher->allocate_hash(hasher, data, &hash);
|
||||
if (!hasher->allocate_hash(hasher, data, &hash))
|
||||
{
|
||||
hasher->destroy(hasher);
|
||||
goto end_parser;
|
||||
}
|
||||
hasher->destroy(hasher);
|
||||
success = memeq(object.ptr, hash.ptr, hash.len);
|
||||
free(hash.ptr);
|
||||
|
||||
@@ -266,8 +266,6 @@ static void MD4Final (private_md4_hasher_t *this, u_int8_t digest[16])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
METHOD(hasher_t, get_hash, bool,
|
||||
private_md4_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
|
||||
{
|
||||
@@ -280,7 +278,7 @@ METHOD(hasher_t, get_hash, bool,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash, void,
|
||||
METHOD(hasher_t, allocate_hash, bool,
|
||||
private_md4_hasher_t *this, chunk_t chunk, chunk_t *hash)
|
||||
{
|
||||
chunk_t allocated_hash;
|
||||
@@ -296,6 +294,7 @@ METHOD(hasher_t, allocate_hash, void,
|
||||
|
||||
*hash = allocated_hash;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash_size, size_t,
|
||||
|
||||
@@ -311,7 +311,7 @@ METHOD(hasher_t, get_hash, bool,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash, void,
|
||||
METHOD(hasher_t, allocate_hash, bool,
|
||||
private_md5_hasher_t *this, chunk_t chunk, chunk_t *hash)
|
||||
{
|
||||
chunk_t allocated_hash;
|
||||
@@ -327,6 +327,7 @@ METHOD(hasher_t, allocate_hash, void,
|
||||
|
||||
*hash = allocated_hash;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash_size, size_t,
|
||||
|
||||
@@ -221,13 +221,13 @@ bool openssl_ec_fingerprint(EC_KEY *ec, cred_encoding_type_t type, chunk_t *fp)
|
||||
return FALSE;
|
||||
}
|
||||
hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA1);
|
||||
if (!hasher)
|
||||
if (!hasher || !hasher->allocate_hash(hasher, key, fp))
|
||||
{
|
||||
DBG1(DBG_LIB, "SHA1 hash algorithm not supported, fingerprinting failed");
|
||||
DESTROY_IF(hasher);
|
||||
free(key.ptr);
|
||||
return FALSE;
|
||||
}
|
||||
hasher->allocate_hash(hasher, key, fp);
|
||||
hasher->destroy(hasher);
|
||||
free(key.ptr);
|
||||
lib->encoding->cache(lib->encoding, type, ec, *fp);
|
||||
|
||||
@@ -120,18 +120,15 @@ METHOD(hasher_t, get_hash, bool,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash, void,
|
||||
METHOD(hasher_t, allocate_hash, bool,
|
||||
private_openssl_hasher_t *this, chunk_t chunk, chunk_t *hash)
|
||||
{
|
||||
if (hash)
|
||||
{
|
||||
*hash = chunk_alloc(get_hash_size(this));
|
||||
get_hash(this, chunk, hash->ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
get_hash(this, chunk, NULL);
|
||||
return get_hash(this, chunk, hash->ptr);
|
||||
}
|
||||
return get_hash(this, chunk, NULL);
|
||||
}
|
||||
|
||||
METHOD(hasher_t, destroy, void,
|
||||
|
||||
@@ -217,13 +217,13 @@ bool openssl_rsa_fingerprint(RSA *rsa, cred_encoding_type_t type, chunk_t *fp)
|
||||
return FALSE;
|
||||
}
|
||||
hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA1);
|
||||
if (!hasher)
|
||||
if (!hasher || !hasher->allocate_hash(hasher, key, fp))
|
||||
{
|
||||
DBG1(DBG_LIB, "SHA1 hash algorithm not supported, fingerprinting failed");
|
||||
DESTROY_IF(hasher);
|
||||
free(key.ptr);
|
||||
return FALSE;
|
||||
}
|
||||
hasher->allocate_hash(hasher, key, fp);
|
||||
free(key.ptr);
|
||||
hasher->destroy(hasher);
|
||||
lib->encoding->cache(lib->encoding, type, rsa, *fp);
|
||||
|
||||
@@ -973,11 +973,11 @@ static bool parse_certificate(private_openssl_x509_t *this)
|
||||
parse_extKeyUsage(this);
|
||||
|
||||
hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA1);
|
||||
if (!hasher)
|
||||
if (!hasher || !hasher->allocate_hash(hasher, this->encoding, &this->hash))
|
||||
{
|
||||
DESTROY_IF(hasher);
|
||||
return FALSE;
|
||||
}
|
||||
hasher->allocate_hash(hasher, this->encoding, &this->hash);
|
||||
hasher->destroy(hasher);
|
||||
|
||||
if (issued_by(this, &this->public.x509.interface, NULL))
|
||||
|
||||
@@ -112,18 +112,15 @@ METHOD(hasher_t, get_hash, bool,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash, void,
|
||||
METHOD(hasher_t, allocate_hash, bool,
|
||||
private_padlock_sha1_hasher_t *this, chunk_t chunk, chunk_t *hash)
|
||||
{
|
||||
if (hash)
|
||||
{
|
||||
*hash = chunk_alloc(HASH_SIZE_SHA1);
|
||||
get_hash(this, chunk, hash->ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
get_hash(this, chunk, NULL);
|
||||
return get_hash(this, chunk, hash->ptr);
|
||||
}
|
||||
return get_hash(this, chunk, NULL);
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash_size, size_t,
|
||||
|
||||
@@ -321,8 +321,12 @@ static bool parse_public_key(private_pgp_cert_t *this, chunk_t packet)
|
||||
DBG1(DBG_ASN, "no SHA-1 hasher available");
|
||||
return FALSE;
|
||||
}
|
||||
hasher->allocate_hash(hasher, pubkey_packet_header, NULL);
|
||||
hasher->allocate_hash(hasher, pubkey_packet, &this->fingerprint);
|
||||
if (!hasher->allocate_hash(hasher, pubkey_packet_header, NULL) ||
|
||||
!hasher->allocate_hash(hasher, pubkey_packet, &this->fingerprint))
|
||||
{
|
||||
hasher->destroy(hasher);
|
||||
return FALSE;
|
||||
}
|
||||
hasher->destroy(hasher);
|
||||
DBG2(DBG_ASN, "L2 - v4 fingerprint %#B", &this->fingerprint);
|
||||
}
|
||||
|
||||
@@ -44,8 +44,12 @@ static bool build_v3_fingerprint(chunk_t *encoding, va_list args)
|
||||
{
|
||||
e = chunk_skip(e, 1);
|
||||
}
|
||||
hasher->allocate_hash(hasher, n, NULL);
|
||||
hasher->allocate_hash(hasher, e, encoding);
|
||||
if (!hasher->allocate_hash(hasher, n, NULL) ||
|
||||
!hasher->allocate_hash(hasher, e, encoding))
|
||||
{
|
||||
hasher->destroy(hasher);
|
||||
return FALSE;
|
||||
}
|
||||
hasher->destroy(hasher);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -94,14 +94,14 @@ static bool hash_pubkey(chunk_t pubkey, chunk_t *hash)
|
||||
hasher_t *hasher;
|
||||
|
||||
hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA1);
|
||||
if (hasher == NULL)
|
||||
if (!hasher || !hasher->allocate_hash(hasher, pubkey, hash))
|
||||
{
|
||||
DESTROY_IF(hasher);
|
||||
chunk_free(&pubkey);
|
||||
DBG1(DBG_LIB, "SHA1 hash algorithm not supported, "
|
||||
"fingerprinting failed");
|
||||
return FALSE;
|
||||
}
|
||||
hasher->allocate_hash(hasher, pubkey, hash);
|
||||
hasher->destroy(hasher);
|
||||
chunk_free(&pubkey);
|
||||
return TRUE;
|
||||
|
||||
@@ -203,18 +203,15 @@ METHOD(hasher_t, get_hash, bool,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash, void,
|
||||
METHOD(hasher_t, allocate_hash, bool,
|
||||
private_pkcs11_hasher_t *this, chunk_t chunk, chunk_t *hash)
|
||||
{
|
||||
if (hash)
|
||||
{
|
||||
*hash = chunk_alloc(this->size);
|
||||
get_hash(this, chunk, hash->ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
get_hash(this, chunk, NULL);
|
||||
return get_hash(this, chunk, hash->ptr);
|
||||
}
|
||||
return get_hash(this, chunk, NULL);
|
||||
}
|
||||
|
||||
METHOD(hasher_t, destroy, void,
|
||||
|
||||
@@ -266,13 +266,15 @@ METHOD(private_key_t, sign, bool,
|
||||
}
|
||||
if (hash_alg != HASH_UNKNOWN)
|
||||
{
|
||||
hasher_t *hasher = lib->crypto->create_hasher(lib->crypto, hash_alg);
|
||||
if (!hasher)
|
||||
hasher_t *hasher;
|
||||
|
||||
hasher = lib->crypto->create_hasher(lib->crypto, hash_alg);
|
||||
if (!hasher || !hasher->allocate_hash(hasher, data, &hash))
|
||||
{
|
||||
DESTROY_IF(hasher);
|
||||
this->lib->f->C_CloseSession(session);
|
||||
return FALSE;
|
||||
}
|
||||
hasher->allocate_hash(hasher, data, &hash);
|
||||
hasher->destroy(hasher);
|
||||
data = hash;
|
||||
}
|
||||
|
||||
@@ -235,13 +235,15 @@ METHOD(public_key_t, verify, bool,
|
||||
}
|
||||
if (hash_alg != HASH_UNKNOWN)
|
||||
{
|
||||
hasher_t *hasher = lib->crypto->create_hasher(lib->crypto, hash_alg);
|
||||
if (!hasher)
|
||||
hasher_t *hasher;
|
||||
|
||||
hasher = lib->crypto->create_hasher(lib->crypto, hash_alg);
|
||||
if (!hasher || !hasher->allocate_hash(hasher, data, &hash))
|
||||
{
|
||||
DESTROY_IF(hasher);
|
||||
this->lib->f->C_CloseSession(session);
|
||||
return FALSE;
|
||||
}
|
||||
hasher->allocate_hash(hasher, data, &hash);
|
||||
hasher->destroy(hasher);
|
||||
data = hash;
|
||||
}
|
||||
@@ -374,12 +376,12 @@ static bool fingerprint_ecdsa(private_pkcs11_public_key_t *this,
|
||||
return FALSE;
|
||||
}
|
||||
hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA1);
|
||||
if (!hasher)
|
||||
if (!hasher || !hasher->allocate_hash(hasher, asn1, fp))
|
||||
{
|
||||
DESTROY_IF(hasher);
|
||||
chunk_clear(&asn1);
|
||||
return FALSE;
|
||||
}
|
||||
hasher->allocate_hash(hasher, asn1, fp);
|
||||
hasher->destroy(hasher);
|
||||
chunk_clear(&asn1);
|
||||
lib->encoding->cache(lib->encoding, type, this, *fp);
|
||||
|
||||
@@ -199,7 +199,7 @@ METHOD(hasher_t, get_hash, bool,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash, void,
|
||||
METHOD(hasher_t, allocate_hash, bool,
|
||||
private_sha1_hasher_t *this, chunk_t chunk, chunk_t *hash)
|
||||
{
|
||||
SHA1Update(this, chunk.ptr, chunk.len);
|
||||
@@ -211,6 +211,7 @@ METHOD(hasher_t, allocate_hash, void,
|
||||
SHA1Final(this, hash->ptr);
|
||||
reset(this);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash_size, size_t,
|
||||
|
||||
@@ -512,7 +512,7 @@ METHOD(hasher_t, get_hash512, bool,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash224, void,
|
||||
METHOD(hasher_t, allocate_hash224, bool,
|
||||
private_sha256_hasher_t *this, chunk_t chunk, chunk_t *hash)
|
||||
{
|
||||
chunk_t allocated_hash;
|
||||
@@ -526,9 +526,10 @@ METHOD(hasher_t, allocate_hash224, void,
|
||||
reset224(this);
|
||||
*hash = allocated_hash;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash256, void,
|
||||
METHOD(hasher_t, allocate_hash256, bool,
|
||||
private_sha256_hasher_t *this, chunk_t chunk, chunk_t *hash)
|
||||
{
|
||||
chunk_t allocated_hash;
|
||||
@@ -542,9 +543,10 @@ METHOD(hasher_t, allocate_hash256, void,
|
||||
reset256(this);
|
||||
*hash = allocated_hash;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash384, void,
|
||||
METHOD(hasher_t, allocate_hash384, bool,
|
||||
private_sha512_hasher_t *this, chunk_t chunk, chunk_t *hash)
|
||||
{
|
||||
chunk_t allocated_hash;
|
||||
@@ -558,9 +560,10 @@ METHOD(hasher_t, allocate_hash384, void,
|
||||
reset384(this);
|
||||
*hash = allocated_hash;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, allocate_hash512, void,
|
||||
METHOD(hasher_t, allocate_hash512, bool,
|
||||
private_sha512_hasher_t *this, chunk_t chunk, chunk_t *hash)
|
||||
{
|
||||
chunk_t allocated_hash;
|
||||
@@ -574,6 +577,7 @@ METHOD(hasher_t, allocate_hash512, void,
|
||||
reset512(this);
|
||||
*hash = allocated_hash;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(hasher_t, get_hash_size224, size_t,
|
||||
|
||||
@@ -1490,12 +1490,13 @@ end:
|
||||
}
|
||||
/* create certificate hash */
|
||||
hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA1);
|
||||
if (hasher == NULL)
|
||||
if (!hasher ||
|
||||
!hasher->allocate_hash(hasher, this->encoding, &this->encoding_hash))
|
||||
{
|
||||
DESTROY_IF(hasher);
|
||||
DBG1(DBG_ASN, " unable to create hash of certificate, SHA1 not supported");
|
||||
return FALSE;
|
||||
}
|
||||
hasher->allocate_hash(hasher, this->encoding, &this->encoding_hash);
|
||||
hasher->destroy(hasher);
|
||||
}
|
||||
return success;
|
||||
@@ -2344,11 +2345,12 @@ static bool generate(private_x509_cert_t *cert, certificate_t *sign_cert,
|
||||
asn1_bitstring("c", cert->signature));
|
||||
|
||||
hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA1);
|
||||
if (!hasher)
|
||||
if (!hasher ||
|
||||
!hasher->allocate_hash(hasher, cert->encoding, &cert->encoding_hash))
|
||||
{
|
||||
DESTROY_IF(hasher);
|
||||
return FALSE;
|
||||
}
|
||||
hasher->allocate_hash(hasher, cert->encoding, &cert->encoding_hash);
|
||||
hasher->destroy(hasher);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -159,22 +159,24 @@ static chunk_t build_requestList(private_x509_ocsp_request_t *this)
|
||||
enumerator_t *enumerator;
|
||||
|
||||
issuer = cert->get_subject(cert);
|
||||
hasher->allocate_hash(hasher, issuer->get_encoding(issuer),
|
||||
&issuerNameHash);
|
||||
hasher->destroy(hasher);
|
||||
|
||||
enumerator = this->candidates->create_enumerator(this->candidates);
|
||||
while (enumerator->enumerate(enumerator, &x509))
|
||||
if (hasher->allocate_hash(hasher, issuer->get_encoding(issuer),
|
||||
&issuerNameHash))
|
||||
{
|
||||
chunk_t request, serialNumber;
|
||||
enumerator = this->candidates->create_enumerator(
|
||||
this->candidates);
|
||||
while (enumerator->enumerate(enumerator, &x509))
|
||||
{
|
||||
chunk_t request, serialNumber;
|
||||
|
||||
serialNumber = x509->get_serial(x509);
|
||||
request = build_Request(this, issuerNameHash, issuerKeyHash,
|
||||
serialNumber);
|
||||
list = chunk_cat("mm", list, request);
|
||||
serialNumber = x509->get_serial(x509);
|
||||
request = build_Request(this, issuerNameHash,
|
||||
issuerKeyHash, serialNumber);
|
||||
list = chunk_cat("mm", list, request);
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
chunk_free(&issuerNameHash);
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
chunk_free(&issuerNameHash);
|
||||
hasher->destroy(hasher);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -201,19 +201,22 @@ METHOD(ocsp_response_t, get_status, cert_validation_t,
|
||||
/* check issuerNameHash, if available */
|
||||
else if (response->issuerNameHash.ptr)
|
||||
{
|
||||
id = issuercert->get_subject(issuercert);
|
||||
hasher = lib->crypto->create_hasher(lib->crypto,
|
||||
hasher_algorithm_from_oid(response->hashAlgorithm));
|
||||
if (!hasher)
|
||||
if (!hasher ||
|
||||
!hasher->allocate_hash(hasher, id->get_encoding(id), &hash))
|
||||
{
|
||||
DESTROY_IF(hasher);
|
||||
continue;
|
||||
}
|
||||
id = issuercert->get_subject(issuercert);
|
||||
hasher->allocate_hash(hasher, id->get_encoding(id), &hash);
|
||||
hasher->destroy(hasher);
|
||||
if (!chunk_equals(hash, response->issuerNameHash))
|
||||
{
|
||||
free(hash.ptr);
|
||||
continue;
|
||||
}
|
||||
free(hash.ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user