]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Added function to convert integrity algorithms to hash algorithms (if based on one).
authorTobias Brunner <tobias@strongswan.org>
Wed, 30 May 2012 12:46:24 +0000 (14:46 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 11 Jun 2012 15:33:28 +0000 (17:33 +0200)
src/libstrongswan/crypto/hashers/hasher.c
src/libstrongswan/crypto/hashers/hasher.h

index 81750a5192c7f3cdc09ee598c57e8182e4f9e1a7..6cf828a3645fa40acad9f2ba0e131d4f69974c79 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * Copyright (C) 2005 Jan Hutter
+ * Copyright (C) 2012 Tobias Brunner
  * Copyright (C) 2005-2006 Martin Willi
- *
+ * Copyright (C) 2005 Jan Hutter
  * Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -65,6 +65,43 @@ hash_algorithm_t hasher_algorithm_from_oid(int oid)
        }
 }
 
+/*
+ * Described in header.
+ */
+hash_algorithm_t hasher_algorithm_from_integrity(integrity_algorithm_t integrity)
+{
+       switch (integrity)
+       {
+               case AUTH_HMAC_MD5_96:
+               case AUTH_HMAC_MD5_128:
+               case AUTH_KPDK_MD5:
+                       return HASH_MD5;
+               case AUTH_HMAC_SHA1_96:
+               case AUTH_HMAC_SHA1_128:
+               case AUTH_HMAC_SHA1_160:
+                       return HASH_SHA1;
+               case AUTH_HMAC_SHA2_256_96:
+               case AUTH_HMAC_SHA2_256_128:
+               case AUTH_HMAC_SHA2_256_256:
+                       return HASH_SHA256;
+               case AUTH_HMAC_SHA2_384_192:
+               case AUTH_HMAC_SHA2_384_384:
+                       return HASH_SHA384;
+               case AUTH_HMAC_SHA2_512_256:
+                       return HASH_SHA512;
+               case AUTH_AES_CMAC_96:
+               case AUTH_AES_128_GMAC:
+               case AUTH_AES_192_GMAC:
+               case AUTH_AES_256_GMAC:
+               case AUTH_AES_XCBC_96:
+               case AUTH_DES_MAC:
+               case AUTH_CAMELLIA_XCBC_96:
+               case AUTH_UNDEFINED:
+                       break;
+       }
+       return HASH_UNKNOWN;
+}
+
 /*
  * Described in header.
  */
index 9fa043c7ef4cb53d5cbaa452b55965c947910f3d..4d0d66fcf3262524efb47f61293b936b18d713ca 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * Copyright (C) 2005 Jan Hutter
+ * Copyright (C) 2012 Tobias Brunner
  * Copyright (C) 2005-2006 Martin Willi
- *
+ * Copyright (C) 2005 Jan Hutter
  * Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@ typedef enum hash_algorithm_t hash_algorithm_t;
 typedef struct hasher_t hasher_t;
 
 #include <library.h>
+#include <crypto/signers/signer.h>
 #include <credentials/keys/public_key.h>
 
 /**
@@ -118,6 +119,14 @@ struct hasher_t {
  */
 hash_algorithm_t hasher_algorithm_from_oid(int oid);
 
+/**
+ * Conversion of integrity algorithm to hash algorithm (if based on one).
+ *
+ * @param integrity            integrity algorithm
+ * @return                             hash algorithm, HASH_UNKNOWN if not based on a hash
+ */
+hash_algorithm_t hasher_algorithm_from_integrity(integrity_algorithm_t integrity);
+
 /**
  * Conversion of hash algorithm into ASN.1 OID.
  *