From 895cb1683d56d6def966ca5bd0b77c43cad823b1 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sat, 7 Jul 2012 10:58:32 +0300 Subject: [PATCH] OpenSSL: Add support for HMAC functions with 0.9.8 and older Commit d9cc4646eb0255be31f11d8a8edad857431fdf49 added crypto_hash_{init,update,finish}() wrappers for OpenSSL, but it assumed the current HMAC API in OpenSSL. This was changed in 0.9.9 to return error codes from the functions while older versions used void functions. Add support for the older versions, too. Signed-hostap: Jouni Malinen --- src/crypto/crypto_openssl.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/crypto/crypto_openssl.c b/src/crypto/crypto_openssl.c index 457da5666..8506fff49 100644 --- a/src/crypto/crypto_openssl.c +++ b/src/crypto/crypto_openssl.c @@ -572,10 +572,14 @@ struct crypto_hash * crypto_hash_init(enum crypto_hash_alg alg, const u8 *key, if (ctx == NULL) return NULL; +#if OPENSSL_VERSION_NUMBER < 0x00909000 + HMAC_Init_ex(&ctx->ctx, key, key_len, md, NULL); +#else /* openssl < 0.9.9 */ if (HMAC_Init_ex(&ctx->ctx, key, key_len, md, NULL) != 1) { os_free(ctx); return NULL; } +#endif /* openssl < 0.9.9 */ return ctx; } @@ -603,7 +607,12 @@ int crypto_hash_finish(struct crypto_hash *ctx, u8 *mac, size_t *len) } mdlen = *len; +#if OPENSSL_VERSION_NUMBER < 0x00909000 + HMAC_Final(&ctx->ctx, mac, &mdlen); + res = 1; +#else /* openssl < 0.9.9 */ res = HMAC_Final(&ctx->ctx, mac, &mdlen); +#endif /* openssl < 0.9.9 */ HMAC_CTX_cleanup(&ctx->ctx); os_free(ctx);