blob: c9691265f6c534e00772533595cf40ee424f8543 [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001From 2fe4bdeb8cdd0b0f46d9caed807812855d51ea56 Mon Sep 17 00:00:00 2001
2From: Alexander Kanavin <alex.kanavin@gmail.com>
3Date: Wed, 28 Mar 2018 20:11:05 +0300
4Subject: [PATCH] Port tests to openssl 1.1
5
6Upstream-Status: Accepted [https://github.com/cryptodev-linux/cryptodev-linux/pull/36]
7Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
8
9---
10 tests/openssl_wrapper.c | 33 +++++++++++++++++++++++++++++++++
11 1 file changed, 33 insertions(+)
12
13diff --git a/tests/openssl_wrapper.c b/tests/openssl_wrapper.c
14index 038c58f..dea2496 100644
15--- a/tests/openssl_wrapper.c
16+++ b/tests/openssl_wrapper.c
17@@ -4,6 +4,7 @@
18 #include <openssl/aes.h>
19 #include <openssl/evp.h>
20 #include <openssl/hmac.h>
21+#include <openssl/opensslv.h>
22
23 //#define DEBUG
24
25@@ -23,10 +24,17 @@ enum ctx_type {
26 ctx_type_md,
27 };
28
29+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
30+union openssl_ctx {
31+ HMAC_CTX *hmac;
32+ EVP_MD_CTX *md;
33+};
34+#else
35 union openssl_ctx {
36 HMAC_CTX hmac;
37 EVP_MD_CTX md;
38 };
39+#endif
40
41 struct ctx_mapping {
42 __u32 ses;
43@@ -63,6 +71,16 @@ static void remove_mapping(__u32 ses)
44 switch (mapping->type) {
45 case ctx_type_none:
46 break;
47+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
48+ case ctx_type_hmac:
49+ dbgp("%s: calling HMAC_CTX_free\n", __func__);
50+ HMAC_CTX_free(mapping->ctx.hmac);
51+ break;
52+ case ctx_type_md:
53+ dbgp("%s: calling EVP_MD_CTX_free\n", __func__);
54+ EVP_MD_CTX_free(mapping->ctx.md);
55+ break;
56+#else
57 case ctx_type_hmac:
58 dbgp("%s: calling HMAC_CTX_cleanup\n", __func__);
59 HMAC_CTX_cleanup(&mapping->ctx.hmac);
60@@ -71,6 +89,7 @@ static void remove_mapping(__u32 ses)
61 dbgp("%s: calling EVP_MD_CTX_cleanup\n", __func__);
62 EVP_MD_CTX_cleanup(&mapping->ctx.md);
63 break;
64+#endif
65 }
66 memset(mapping, 0, sizeof(*mapping));
67 }
68@@ -127,10 +146,17 @@ static int openssl_hmac(struct session_op *sess, struct crypt_op *cop)
69
70 mapping->ses = sess->ses;
71 mapping->type = ctx_type_hmac;
72+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
73+ ctx = mapping->ctx.hmac;
74+
75+ dbgp("calling HMAC_CTX_new");
76+ ctx = HMAC_CTX_new();
77+#else
78 ctx = &mapping->ctx.hmac;
79
80 dbgp("calling HMAC_CTX_init");
81 HMAC_CTX_init(ctx);
82+#endif
83 dbgp("calling HMAC_Init_ex");
84 if (!HMAC_Init_ex(ctx, sess->mackey, sess->mackeylen,
85 sess_to_evp_md(sess), NULL)) {
86@@ -172,10 +198,17 @@ static int openssl_md(struct session_op *sess, struct crypt_op *cop)
87
88 mapping->ses = sess->ses;
89 mapping->type = ctx_type_md;
90+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
91+ ctx = mapping->ctx.md;
92+
93+ dbgp("calling EVP_MD_CTX_new");
94+ ctx = EVP_MD_CTX_new();
95+#else
96 ctx = &mapping->ctx.md;
97
98 dbgp("calling EVP_MD_CTX_init");
99 EVP_MD_CTX_init(ctx);
100+#endif
101 dbgp("calling EVP_DigestInit");
102 EVP_DigestInit(ctx, sess_to_evp_md(sess));
103 }