0001-Port-tests-to-openssl-1.1.patch 2.7 KB

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