]> git.ipfire.org Git - people/ms/strongswan.git/commitdiff
Function to convert PRFs to hash algorithms added
authorTobias Brunner <tobias@strongswan.org>
Fri, 22 Jun 2012 09:28:43 +0000 (11:28 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 25 Jun 2012 14:35:06 +0000 (16:35 +0200)
src/libstrongswan/crypto/hashers/hasher.c
src/libstrongswan/crypto/hashers/hasher.h

index 5809762220c6d0623233db8708f89baba57d13da..e0a4995cfb1fcb48ce02cdd73935c1fc7fce8631 100644 (file)
@@ -65,6 +65,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.
  */
index 5325e017bb65559c491d59284f1e67f9cd989d09..c5be29edb96cd7e9c1b5a12f2c1b3ed9e1ad2f97 100644 (file)
@@ -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>
 
@@ -119,6 +120,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).
  *