]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Simplified creation of PRFs and signers in openssl and hmac plugins
authorTobias Brunner <tobias@strongswan.org>
Fri, 22 Jun 2012 09:30:46 +0000 (11:30 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 25 Jun 2012 14:35:06 +0000 (16:35 +0200)
src/libstrongswan/plugins/hmac/hmac_hmac.c
src/libstrongswan/plugins/openssl/openssl_hmac.c

index 871a294d9a78d1ac9ec38d8b84bccb3b625bef55..975dc3a8fe61fd65af7ae74b3129339d1d5e724a 100644 (file)
@@ -193,28 +193,9 @@ static hmac_t *hmac_create(hash_algorithm_t hash_algorithm)
  */
 prf_t *hmac_hmac_prf_create(pseudo_random_function_t algo)
 {
-       hmac_t *hmac = NULL;
+       hmac_t *hmac;
 
-       switch (algo)
-       {
-               case PRF_HMAC_SHA1:
-                       hmac = hmac_create(HASH_SHA1);
-                       break;
-               case PRF_HMAC_MD5:
-                       hmac = hmac_create(HASH_MD5);
-                       break;
-               case PRF_HMAC_SHA2_256:
-                       hmac = hmac_create(HASH_SHA256);
-                       break;
-               case PRF_HMAC_SHA2_384:
-                       hmac = hmac_create(HASH_SHA384);
-                       break;
-               case PRF_HMAC_SHA2_512:
-                       hmac = hmac_create(HASH_SHA512);
-                       break;
-               default:
-                       break;
-       }
+       hmac = hmac_create(hasher_algorithm_from_prf(algo));
        if (hmac)
        {
                return hmac_prf_create(hmac);
@@ -227,54 +208,10 @@ prf_t *hmac_hmac_prf_create(pseudo_random_function_t algo)
  */
 signer_t *hmac_hmac_signer_create(integrity_algorithm_t algo)
 {
-       hmac_t *hmac = NULL;
-       size_t trunc = 0;
+       hmac_t *hmac;
+       size_t trunc;
 
-       switch (algo)
-       {
-               case AUTH_HMAC_MD5_96:
-                       hmac = hmac_create(HASH_MD5);
-                       trunc = 12;
-                       break;
-               case AUTH_HMAC_MD5_128:
-                       hmac = hmac_create(HASH_MD5);
-                       trunc = 16;
-                       break;
-               case AUTH_HMAC_SHA1_96:
-                       hmac = hmac_create(HASH_SHA1);
-                       trunc = 12;
-                       break;
-               case AUTH_HMAC_SHA1_128:
-                       hmac = hmac_create(HASH_SHA1);
-                       trunc = 16;
-                       break;
-               case AUTH_HMAC_SHA1_160:
-                       hmac = hmac_create(HASH_SHA1);
-                       trunc = 20;
-                       break;
-               case AUTH_HMAC_SHA2_256_128:
-                       hmac = hmac_create(HASH_SHA256);
-                       trunc = 16;
-                       break;
-               case AUTH_HMAC_SHA2_256_256:
-                       hmac = hmac_create(HASH_SHA256);
-                       trunc = 32;
-                       break;
-               case AUTH_HMAC_SHA2_384_192:
-                       hmac = hmac_create(HASH_SHA384);
-                       trunc = 24;
-                       break;
-               case AUTH_HMAC_SHA2_384_384:
-                       hmac = hmac_create(HASH_SHA384);
-                       trunc = 48;
-                       break;
-               case AUTH_HMAC_SHA2_512_256:
-                       hmac = hmac_create(HASH_SHA512);
-                       trunc = 32;
-                       break;
-               default:
-                       break;
-       }
+       hmac = hmac_create(hasher_algorithm_from_integrity(algo, &trunc));
        if (hmac)
        {
                return hmac_signer_create(hmac, trunc);
index 07f5f6ba0291da51695386c402e396f18d6e2d3f..932d0e434d3cebb8639534cccb8c12b1f2bb1eac 100644 (file)
@@ -170,28 +170,9 @@ static hmac_t *hmac_create(hash_algorithm_t algo)
  */
 prf_t *openssl_hmac_prf_create(pseudo_random_function_t algo)
 {
-       hmac_t *hmac = NULL;
+       hmac_t *hmac;
 
-       switch (algo)
-       {
-               case PRF_HMAC_SHA1:
-                       hmac = hmac_create(HASH_SHA1);
-                       break;
-               case PRF_HMAC_MD5:
-                       hmac = hmac_create(HASH_MD5);
-                       break;
-               case PRF_HMAC_SHA2_256:
-                       hmac = hmac_create(HASH_SHA256);
-                       break;
-               case PRF_HMAC_SHA2_384:
-                       hmac = hmac_create(HASH_SHA384);
-                       break;
-               case PRF_HMAC_SHA2_512:
-                       hmac = hmac_create(HASH_SHA512);
-                       break;
-               default:
-                       break;
-       }
+       hmac = hmac_create(hasher_algorithm_from_prf(algo));
        if (hmac)
        {
                return hmac_prf_create(hmac);
@@ -204,54 +185,10 @@ prf_t *openssl_hmac_prf_create(pseudo_random_function_t algo)
  */
 signer_t *openssl_hmac_signer_create(integrity_algorithm_t algo)
 {
-       hmac_t *hmac = NULL;
-       size_t trunc = 0;
+       hmac_t *hmac;
+       size_t trunc;
 
-       switch (algo)
-       {
-               case AUTH_HMAC_MD5_96:
-                       hmac = hmac_create(HASH_MD5);
-                       trunc = 12;
-                       break;
-               case AUTH_HMAC_MD5_128:
-                       hmac = hmac_create(HASH_MD5);
-                       trunc = 16;
-                       break;
-               case AUTH_HMAC_SHA1_96:
-                       hmac = hmac_create(HASH_SHA1);
-                       trunc = 12;
-                       break;
-               case AUTH_HMAC_SHA1_128:
-                       hmac = hmac_create(HASH_SHA1);
-                       trunc = 16;
-                       break;
-               case AUTH_HMAC_SHA1_160:
-                       hmac = hmac_create(HASH_SHA1);
-                       trunc = 20;
-                       break;
-               case AUTH_HMAC_SHA2_256_128:
-                       hmac = hmac_create(HASH_SHA256);
-                       trunc = 16;
-                       break;
-               case AUTH_HMAC_SHA2_256_256:
-                       hmac = hmac_create(HASH_SHA256);
-                       trunc = 32;
-                       break;
-               case AUTH_HMAC_SHA2_384_192:
-                       hmac = hmac_create(HASH_SHA384);
-                       trunc = 24;
-                       break;
-               case AUTH_HMAC_SHA2_384_384:
-                       hmac = hmac_create(HASH_SHA384);
-                       trunc = 48;
-                       break;
-               case AUTH_HMAC_SHA2_512_256:
-                       hmac = hmac_create(HASH_SHA512);
-                       trunc = 32;
-                       break;
-               default:
-                       break;
-       }
+       hmac = hmac_create(hasher_algorithm_from_integrity(algo, &trunc));
        if (hmac)
        {
                return hmac_signer_create(hmac, trunc);