Skip to content

Commit

Permalink
Port tests to openssl 1.1
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Kanavin <[email protected]>
  • Loading branch information
kanavin authored and cristian-stoica committed Apr 4, 2018
1 parent 0a54e38 commit 9c70011
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/openssl_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <openssl/aes.h>
#include <openssl/evp.h>
#include <openssl/hmac.h>
#include <openssl/opensslv.h>

//#define DEBUG

Expand All @@ -23,10 +24,17 @@ enum ctx_type {
ctx_type_md,
};

#if OPENSSL_VERSION_NUMBER >= 0x10100000L
union openssl_ctx {
HMAC_CTX *hmac;
EVP_MD_CTX *md;
};
#else
union openssl_ctx {
HMAC_CTX hmac;
EVP_MD_CTX md;
};
#endif

struct ctx_mapping {
__u32 ses;
Expand Down Expand Up @@ -63,6 +71,16 @@ static void remove_mapping(__u32 ses)
switch (mapping->type) {
case ctx_type_none:
break;
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
case ctx_type_hmac:
dbgp("%s: calling HMAC_CTX_free\n", __func__);
HMAC_CTX_free(mapping->ctx.hmac);
break;
case ctx_type_md:
dbgp("%s: calling EVP_MD_CTX_free\n", __func__);
EVP_MD_CTX_free(mapping->ctx.md);
break;
#else
case ctx_type_hmac:
dbgp("%s: calling HMAC_CTX_cleanup\n", __func__);
HMAC_CTX_cleanup(&mapping->ctx.hmac);
Expand All @@ -71,6 +89,7 @@ static void remove_mapping(__u32 ses)
dbgp("%s: calling EVP_MD_CTX_cleanup\n", __func__);
EVP_MD_CTX_cleanup(&mapping->ctx.md);
break;
#endif
}
memset(mapping, 0, sizeof(*mapping));
}
Expand Down Expand Up @@ -127,10 +146,17 @@ static int openssl_hmac(struct session_op *sess, struct crypt_op *cop)

mapping->ses = sess->ses;
mapping->type = ctx_type_hmac;
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
ctx = mapping->ctx.hmac;

dbgp("calling HMAC_CTX_new");
ctx = HMAC_CTX_new();
#else
ctx = &mapping->ctx.hmac;

dbgp("calling HMAC_CTX_init");
HMAC_CTX_init(ctx);
#endif
dbgp("calling HMAC_Init_ex");
if (!HMAC_Init_ex(ctx, sess->mackey, sess->mackeylen,
sess_to_evp_md(sess), NULL)) {
Expand Down Expand Up @@ -172,10 +198,17 @@ static int openssl_md(struct session_op *sess, struct crypt_op *cop)

mapping->ses = sess->ses;
mapping->type = ctx_type_md;
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
ctx = mapping->ctx.md;

dbgp("calling EVP_MD_CTX_new");
ctx = EVP_MD_CTX_new();
#else
ctx = &mapping->ctx.md;

dbgp("calling EVP_MD_CTX_init");
EVP_MD_CTX_init(ctx);
#endif
dbgp("calling EVP_DigestInit");
EVP_DigestInit(ctx, sess_to_evp_md(sess));
}
Expand Down

0 comments on commit 9c70011

Please sign in to comment.