hasher: Add function to determine length of hashes

This commit is contained in:
Tobias Brunner 2017-09-22 09:46:14 +02:00
parent ffd0eeecf0
commit c2b878cd61
2 changed files with 46 additions and 0 deletions

View File

@ -56,6 +56,44 @@ ENUM_NEXT(hash_algorithm_short_names, HASH_UNKNOWN, HASH_SHA3_512, HASH_IDENTITY
"sha3_512");
ENUM_END(hash_algorithm_short_names, HASH_SHA3_512);
/*
* Described in header
*/
size_t hasher_hash_size(hash_algorithm_t alg)
{
switch (alg)
{
case HASH_SHA1:
return HASH_SIZE_SHA1;
case HASH_SHA256:
return HASH_SIZE_SHA256;
case HASH_SHA384:
return HASH_SIZE_SHA384;
case HASH_SHA512:
return HASH_SIZE_SHA512;
case HASH_MD2:
return HASH_SIZE_MD2;
case HASH_MD4:
return HASH_SIZE_MD4;
case HASH_MD5:
return HASH_SIZE_MD5;
case HASH_SHA224:
return HASH_SIZE_SHA224;
case HASH_SHA3_224:
return HASH_SIZE_SHA224;
case HASH_SHA3_256:
return HASH_SIZE_SHA256;
case HASH_SHA3_384:
return HASH_SIZE_SHA384;
case HASH_SHA3_512:
return HASH_SIZE_SHA512;
case HASH_IDENTITY:
case HASH_UNKNOWN:
break;
}
return 0;
}
/*
* Described in header.
*/

View File

@ -130,6 +130,14 @@ struct hasher_t {
void (*destroy)(hasher_t *this);
};
/**
* Returns the size of the hash for the given algorithm.
*
* @param alg hash algorithm
* @return size of hash or 0 if unknown
*/
size_t hasher_hash_size(hash_algorithm_t alg);
/**
* Conversion of ASN.1 OID to hash algorithm.
*