diff options
author | Yves-Alexis Perez <corsac@debian.org> | 2013-08-25 15:37:26 +0200 |
---|---|---|
committer | Yves-Alexis Perez <corsac@debian.org> | 2013-08-25 15:37:26 +0200 |
commit | 6b99c8d9cff7b3e8ae8f3204b99e7ea40f791349 (patch) | |
tree | 009fc492961e13860d2a4bc2de8caf2bbe2975e7 /src/libstrongswan/crypto/hashers | |
parent | c83921a2b566aa9d55d8ccc7258f04fca6292ee6 (diff) | |
download | vyos-strongswan-6b99c8d9cff7b3e8ae8f3204b99e7ea40f791349.tar.gz vyos-strongswan-6b99c8d9cff7b3e8ae8f3204b99e7ea40f791349.zip |
Imported Upstream version 5.1.0
Diffstat (limited to 'src/libstrongswan/crypto/hashers')
-rw-r--r-- | src/libstrongswan/crypto/hashers/hasher.c | 72 | ||||
-rw-r--r-- | src/libstrongswan/crypto/hashers/hasher.h | 11 |
2 files changed, 83 insertions, 0 deletions
diff --git a/src/libstrongswan/crypto/hashers/hasher.c b/src/libstrongswan/crypto/hashers/hasher.c index dc73d5223..679bb324e 100644 --- a/src/libstrongswan/crypto/hashers/hasher.c +++ b/src/libstrongswan/crypto/hashers/hasher.c @@ -141,6 +141,9 @@ hash_algorithm_t hasher_algorithm_from_integrity(integrity_algorithm_t alg, case AUTH_HMAC_SHA2_384_384: *length = 48; break; + case AUTH_HMAC_SHA2_512_512: + *length = 64; + break; default: break; } @@ -163,6 +166,7 @@ hash_algorithm_t hasher_algorithm_from_integrity(integrity_algorithm_t alg, case AUTH_HMAC_SHA2_384_384: return HASH_SHA384; case AUTH_HMAC_SHA2_512_256: + case AUTH_HMAC_SHA2_512_512: return HASH_SHA512; case AUTH_AES_CMAC_96: case AUTH_AES_128_GMAC: @@ -180,6 +184,74 @@ hash_algorithm_t hasher_algorithm_from_integrity(integrity_algorithm_t alg, /* * Described in header. */ +integrity_algorithm_t hasher_algorithm_to_integrity(hash_algorithm_t alg, + size_t length) +{ + switch (alg) + { + case HASH_MD5: + switch (length) + { + case 12: + return AUTH_HMAC_MD5_96; + case 16: + return AUTH_HMAC_MD5_128; + } + break; + case HASH_SHA1: + case HASH_PREFERRED: + switch (length) + { + case 12: + return AUTH_HMAC_SHA1_96; + case 16: + return AUTH_HMAC_SHA1_128; + case 20: + return AUTH_HMAC_SHA1_160; + } + break; + case HASH_SHA256: + switch (length) + { + case 12: + return AUTH_HMAC_SHA2_256_96; + case 16: + return AUTH_HMAC_SHA2_256_128; + case 32: + return AUTH_HMAC_SHA2_256_256; + } + break; + case HASH_SHA384: + switch (length) + { + case 24: + return AUTH_HMAC_SHA2_384_192; + case 48: + return AUTH_HMAC_SHA2_384_384; + + } + break; + case HASH_SHA512: + switch (length) + { + case 32: + return AUTH_HMAC_SHA2_512_256; + case 64: + return AUTH_HMAC_SHA2_512_512; + } + break; + case HASH_MD2: + case HASH_MD4: + case HASH_SHA224: + case HASH_UNKNOWN: + break; + } + return AUTH_UNDEFINED; +} + +/* + * Described in header. + */ int hasher_algorithm_to_oid(hash_algorithm_t alg) { int oid; diff --git a/src/libstrongswan/crypto/hashers/hasher.h b/src/libstrongswan/crypto/hashers/hasher.h index 759f6a23c..4e46fca10 100644 --- a/src/libstrongswan/crypto/hashers/hasher.h +++ b/src/libstrongswan/crypto/hashers/hasher.h @@ -154,6 +154,17 @@ hash_algorithm_t hasher_algorithm_from_integrity(integrity_algorithm_t alg, size_t *length); /** + * Conversion of hash algorithm to integrity algorithm (if based on a hash). + * + * @param alg hash algorithm + * @param length length of the signature + * @return integrity algorithm, AUTH_UNDEFINED if none is known + * based on the given hash function + */ +integrity_algorithm_t hasher_algorithm_to_integrity(hash_algorithm_t alg, + size_t length); + +/** * Conversion of hash algorithm into ASN.1 OID. * * @param alg hash algorithm |