diff options
author | Martin Willi <martin@revosec.ch> | 2012-07-17 10:58:53 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2012-07-17 10:58:53 +0200 |
commit | 082b0d7249539f7b47a308aed3d3cc3ceecfc4cc (patch) | |
tree | 141eea63671bb330b16571f69e36c24b20abac39 /src/libstrongswan/plugins/openssl/openssl_hmac.c | |
parent | 931da8202bf4425a708f5612ffd21323b6aef6b1 (diff) | |
download | strongswan-082b0d7249539f7b47a308aed3d3cc3ceecfc4cc.tar.bz2 strongswan-082b0d7249539f7b47a308aed3d3cc3ceecfc4cc.tar.xz |
Support void return values in OpenSSL 0.9.8 HMAC functions
Diffstat (limited to 'src/libstrongswan/plugins/openssl/openssl_hmac.c')
-rw-r--r-- | src/libstrongswan/plugins/openssl/openssl_hmac.c | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/src/libstrongswan/plugins/openssl/openssl_hmac.c b/src/libstrongswan/plugins/openssl/openssl_hmac.c index 8c8767d89..8519271f8 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; } - |