diff options
author | Tobias Brunner <tobias@strongswan.org> | 2012-06-22 11:30:46 +0200 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2012-06-25 16:35:06 +0200 |
commit | 228d096e429da68e24a19fd0e89d2ac98a483091 (patch) | |
tree | bee401b140777da27d2f72abc48d8171c56873c1 | |
parent | 01850f5d5554e72fa1975bce1991b9e5182cc59b (diff) | |
download | strongswan-228d096e429da68e24a19fd0e89d2ac98a483091.tar.bz2 strongswan-228d096e429da68e24a19fd0e89d2ac98a483091.tar.xz |
Simplified creation of PRFs and signers in openssl and hmac plugins
-rw-r--r-- | src/libstrongswan/plugins/hmac/hmac_hmac.c | 73 | ||||
-rw-r--r-- | src/libstrongswan/plugins/openssl/openssl_hmac.c | 73 |
2 files changed, 10 insertions, 136 deletions
diff --git a/src/libstrongswan/plugins/hmac/hmac_hmac.c b/src/libstrongswan/plugins/hmac/hmac_hmac.c index 871a294d9..975dc3a8f 100644 --- a/src/libstrongswan/plugins/hmac/hmac_hmac.c +++ b/src/libstrongswan/plugins/hmac/hmac_hmac.c @@ -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); diff --git a/src/libstrongswan/plugins/openssl/openssl_hmac.c b/src/libstrongswan/plugins/openssl/openssl_hmac.c index 07f5f6ba0..932d0e434 100644 --- a/src/libstrongswan/plugins/openssl/openssl_hmac.c +++ b/src/libstrongswan/plugins/openssl/openssl_hmac.c @@ -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); |