diff options
author | Tobias Brunner <tobias@strongswan.org> | 2017-09-22 09:46:14 +0200 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2017-11-08 16:48:10 +0100 |
commit | c2b878cd6131091645a47eeb4c94ad4afa26720f (patch) | |
tree | ebaf47125219ec889440f5727b58a94026601061 /src/libstrongswan | |
parent | ffd0eeecf05d84a25f3df96850312adc1896d6f0 (diff) | |
download | strongswan-c2b878cd6131091645a47eeb4c94ad4afa26720f.tar.bz2 strongswan-c2b878cd6131091645a47eeb4c94ad4afa26720f.tar.xz |
hasher: Add function to determine length of hashes
Diffstat (limited to 'src/libstrongswan')
-rw-r--r-- | src/libstrongswan/crypto/hashers/hasher.c | 38 | ||||
-rw-r--r-- | src/libstrongswan/crypto/hashers/hasher.h | 8 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/libstrongswan/crypto/hashers/hasher.c b/src/libstrongswan/crypto/hashers/hasher.c index 3f49f3600..c04835b2c 100644 --- a/src/libstrongswan/crypto/hashers/hasher.c +++ b/src/libstrongswan/crypto/hashers/hasher.c @@ -57,6 +57,44 @@ ENUM_NEXT(hash_algorithm_short_names, HASH_UNKNOWN, HASH_SHA3_512, HASH_IDENTITY 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. */ hash_algorithm_t hasher_algorithm_from_oid(int oid) diff --git a/src/libstrongswan/crypto/hashers/hasher.h b/src/libstrongswan/crypto/hashers/hasher.h index ec0c6320b..9d2df1d4b 100644 --- a/src/libstrongswan/crypto/hashers/hasher.h +++ b/src/libstrongswan/crypto/hashers/hasher.h @@ -131,6 +131,14 @@ struct hasher_t { }; /** + * 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. * * @param oid ASN.1 OID |