aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/crypto/hashers/hasher.c
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2012-06-22 11:28:10 +0200
committerTobias Brunner <tobias@strongswan.org>2012-06-25 16:35:06 +0200
commit903093d439c4bc5d6083c07b4a6aa410cf90216e (patch)
treed7c609779bc80370452fc13bc3ffe268641e6993 /src/libstrongswan/crypto/hashers/hasher.c
parent73d032e41276ecca3b1b7c7f95c805a649113b48 (diff)
downloadstrongswan-903093d439c4bc5d6083c07b4a6aa410cf90216e.tar.bz2
strongswan-903093d439c4bc5d6083c07b4a6aa410cf90216e.tar.xz
hasher_algorithm_from_integrity() optionally returns truncation length
Diffstat (limited to 'src/libstrongswan/crypto/hashers/hasher.c')
-rw-r--r--src/libstrongswan/crypto/hashers/hasher.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/libstrongswan/crypto/hashers/hasher.c b/src/libstrongswan/crypto/hashers/hasher.c
index 6cf828a36..580976222 100644
--- a/src/libstrongswan/crypto/hashers/hasher.c
+++ b/src/libstrongswan/crypto/hashers/hasher.c
@@ -68,9 +68,41 @@ hash_algorithm_t hasher_algorithm_from_oid(int oid)
/*
* Described in header.
*/
-hash_algorithm_t hasher_algorithm_from_integrity(integrity_algorithm_t integrity)
+hash_algorithm_t hasher_algorithm_from_integrity(integrity_algorithm_t alg,
+ size_t *length)
{
- switch (integrity)
+ if (length)
+ {
+ switch (alg)
+ {
+ case AUTH_HMAC_MD5_96:
+ case AUTH_HMAC_SHA1_96:
+ case AUTH_HMAC_SHA2_256_96:
+ *length = 12;
+ break;
+ case AUTH_HMAC_MD5_128:
+ case AUTH_HMAC_SHA1_128:
+ case AUTH_HMAC_SHA2_256_128:
+ *length = 16;
+ break;
+ case AUTH_HMAC_SHA1_160:
+ *length = 20;
+ break;
+ case AUTH_HMAC_SHA2_384_192:
+ *length = 24;
+ break;
+ case AUTH_HMAC_SHA2_256_256:
+ case AUTH_HMAC_SHA2_512_256:
+ *length = 32;
+ break;
+ case AUTH_HMAC_SHA2_384_384:
+ *length = 48;
+ break;
+ default:
+ break;
+ }
+ }
+ switch (alg)
{
case AUTH_HMAC_MD5_96:
case AUTH_HMAC_MD5_128: