aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2012-06-22 11:28:43 +0200
committerTobias Brunner <tobias@strongswan.org>2012-06-25 16:35:06 +0200
commit01850f5d5554e72fa1975bce1991b9e5182cc59b (patch)
treec51bfdb68addaf7b9fde5d90e32f19afe7d185ab
parent903093d439c4bc5d6083c07b4a6aa410cf90216e (diff)
downloadstrongswan-01850f5d5554e72fa1975bce1991b9e5182cc59b.tar.bz2
strongswan-01850f5d5554e72fa1975bce1991b9e5182cc59b.tar.xz
Function to convert PRFs to hash algorithms added
-rw-r--r--src/libstrongswan/crypto/hashers/hasher.c30
-rw-r--r--src/libstrongswan/crypto/hashers/hasher.h9
2 files changed, 39 insertions, 0 deletions
diff --git a/src/libstrongswan/crypto/hashers/hasher.c b/src/libstrongswan/crypto/hashers/hasher.c
index 580976222..e0a4995cf 100644
--- a/src/libstrongswan/crypto/hashers/hasher.c
+++ b/src/libstrongswan/crypto/hashers/hasher.c
@@ -68,6 +68,36 @@ hash_algorithm_t hasher_algorithm_from_oid(int oid)
/*
* Described in header.
*/
+hash_algorithm_t hasher_algorithm_from_prf(pseudo_random_function_t alg)
+{
+ switch (alg)
+ {
+ case PRF_HMAC_MD5:
+ return HASH_MD5;
+ case PRF_HMAC_SHA1:
+ case PRF_FIPS_SHA1_160:
+ case PRF_KEYED_SHA1:
+ return HASH_SHA1;
+ case PRF_HMAC_SHA2_256:
+ return HASH_SHA256;
+ case PRF_HMAC_SHA2_384:
+ return HASH_SHA384;
+ case PRF_HMAC_SHA2_512:
+ return HASH_SHA512;
+ case PRF_HMAC_TIGER:
+ case PRF_AES128_XCBC:
+ case PRF_AES128_CMAC:
+ case PRF_FIPS_DES:
+ case PRF_CAMELLIA128_XCBC:
+ case PRF_UNDEFINED:
+ break;
+ }
+ return HASH_UNKNOWN;
+}
+
+/*
+ * Described in header.
+ */
hash_algorithm_t hasher_algorithm_from_integrity(integrity_algorithm_t alg,
size_t *length)
{
diff --git a/src/libstrongswan/crypto/hashers/hasher.h b/src/libstrongswan/crypto/hashers/hasher.h
index 5325e017b..c5be29edb 100644
--- a/src/libstrongswan/crypto/hashers/hasher.h
+++ b/src/libstrongswan/crypto/hashers/hasher.h
@@ -27,6 +27,7 @@ typedef enum hash_algorithm_t hash_algorithm_t;
typedef struct hasher_t hasher_t;
#include <library.h>
+#include <crypto/prfs/prf.h>
#include <crypto/signers/signer.h>
#include <credentials/keys/public_key.h>
@@ -120,6 +121,14 @@ struct hasher_t {
hash_algorithm_t hasher_algorithm_from_oid(int oid);
/**
+ * Conversion of PRF algorithm to hash algorithm (if based on one).
+ *
+ * @param alg prf algorithm
+ * @return hash algorithm, HASH_UNKNOWN if not based on a hash
+ */
+hash_algorithm_t hasher_algorithm_from_prf(pseudo_random_function_t alg);
+
+/**
* Conversion of integrity algorithm to hash algorithm (if based on one).
*
* If length is not NULL the length of the resulting signature is returned,