]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
OpenSSL: Add support for HMAC functions with 0.9.8 and older
authorJouni Malinen <j@w1.fi>
Sat, 7 Jul 2012 07:58:32 +0000 (10:58 +0300)
committerJouni Malinen <j@w1.fi>
Sat, 7 Jul 2012 07:58:32 +0000 (10:58 +0300)
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 <j@w1.fi>

src/crypto/crypto_openssl.c

index 457da566657a565c812504275a730f28b19f8549..8506fff49559da39336154864c9d6e1a6115e42e 100644 (file)
@@ -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);