From: Martin Willi Date: Tue, 17 Jul 2012 08:58:53 +0000 (+0200) Subject: Support void return values in OpenSSL 0.9.8 HMAC functions X-Git-Tag: 5.0.1~293 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=082b0d7249539f7b47a308aed3d3cc3ceecfc4cc;p=thirdparty%2Fstrongswan.git Support void return values in OpenSSL 0.9.8 HMAC functions --- diff --git a/src/libstrongswan/plugins/openssl/openssl_hmac.c b/src/libstrongswan/plugins/openssl/openssl_hmac.c index 8c8767d891..8519271f81 100644 --- a/src/libstrongswan/plugins/openssl/openssl_hmac.c +++ b/src/libstrongswan/plugins/openssl/openssl_hmac.c @@ -67,24 +67,42 @@ struct private_mac_t { HMAC_CTX hmac; }; -/** - * Resets HMAC context - */ -static bool reset(private_mac_t *this) +METHOD(mac_t, set_key, bool, + private_mac_t *this, chunk_t key) { - return HMAC_Init_ex(&this->hmac, NULL, 0, this->hasher, NULL); +#if OPENSSL_VERSION_NUMBER >= 0x10000000L + return HMAC_Init_ex(&this->hmac, key.ptr, key.len, this->hasher, NULL); +#else /* OPENSSL_VERSION_NUMBER < 1.0 */ + HMAC_Init_ex(&this->hmac, key.ptr, key.len, this->hasher, NULL); + return TRUE; +#endif } METHOD(mac_t, get_mac, bool, private_mac_t *this, chunk_t data, u_int8_t *out) { +#if OPENSSL_VERSION_NUMBER >= 0x10000000L + if (!HMAC_Update(&this->hmac, data.ptr, data.len)) + { + return FALSE; + } if (out == NULL) { - return HMAC_Update(&this->hmac, data.ptr, data.len); + return TRUE; } - return HMAC_Update(&this->hmac, data.ptr, data.len) && - HMAC_Final(&this->hmac, out, NULL) && - reset(this); + if (!HMAC_Final(&this->hmac, out, NULL)) + { + return FALSE; + } +#else /* OPENSSL_VERSION_NUMBER < 1.0 */ + HMAC_Update(&this->hmac, data.ptr, data.len); + if (out == NULL) + { + return TRUE; + } + HMAC_Final(&this->hmac, out, NULL); +#endif + return set_key(this, chunk_empty); } METHOD(mac_t, get_mac_size, size_t, @@ -93,12 +111,6 @@ METHOD(mac_t, get_mac_size, size_t, return EVP_MD_size(this->hasher); } -METHOD(mac_t, set_key, bool, - private_mac_t *this, chunk_t key) -{ - return HMAC_Init_ex(&this->hmac, key.ptr, key.len, this->hasher, NULL); -} - METHOD(mac_t, destroy, void, private_mac_t *this) { @@ -150,7 +162,7 @@ static mac_t *hmac_create(hash_algorithm_t algo) } HMAC_CTX_init(&this->hmac); - if (!HMAC_Init_ex(&this->hmac, NULL, 0, this->hasher, NULL)) + if (!set_key(this, chunk_empty)) { destroy(this); return NULL; @@ -190,4 +202,3 @@ signer_t *openssl_hmac_signer_create(integrity_algorithm_t algo) return NULL; } -