From 610f90a8b9190b191e41af0b60753ecc2edc4c8c Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Tue, 17 Jul 2012 17:30:23 +0200 Subject: Use centralized hasher names in openssl plugin --- src/libstrongswan/plugins/openssl/openssl_hmac.c | 29 +++++++----------------- 1 file changed, 8 insertions(+), 21 deletions(-) (limited to 'src/libstrongswan/plugins/openssl/openssl_hmac.c') diff --git a/src/libstrongswan/plugins/openssl/openssl_hmac.c b/src/libstrongswan/plugins/openssl/openssl_hmac.c index 8519271f8..5d05425d3 100644 --- a/src/libstrongswan/plugins/openssl/openssl_hmac.c +++ b/src/libstrongswan/plugins/openssl/openssl_hmac.c @@ -124,6 +124,13 @@ METHOD(mac_t, destroy, void, static mac_t *hmac_create(hash_algorithm_t algo) { private_mac_t *this; + char *name; + + name = enum_to_name(hash_algorithm_short_names, algo); + if (!name) + { + return NULL; + } INIT(this, .public = { @@ -132,29 +139,9 @@ static mac_t *hmac_create(hash_algorithm_t algo) .set_key = _set_key, .destroy = _destroy, }, + .hasher = EVP_get_digestbyname(name), ); - switch (algo) - { - case HASH_MD5: - this->hasher = EVP_get_digestbyname("md5"); - break; - case HASH_SHA1: - this->hasher = EVP_get_digestbyname("sha1"); - break; - case HASH_SHA256: - this->hasher = EVP_get_digestbyname("sha256"); - break; - case HASH_SHA384: - this->hasher = EVP_get_digestbyname("sha384"); - break; - case HASH_SHA512: - this->hasher = EVP_get_digestbyname("sha512"); - break; - default: - break; - } - if (!this->hasher) { free(this); -- cgit v1.2.3