diff options
Diffstat (limited to 'src/libstrongswan/plugins/openssl/openssl_hmac.c')
-rw-r--r-- | src/libstrongswan/plugins/openssl/openssl_hmac.c | 29 |
1 files changed, 8 insertions, 21 deletions
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); |