openssl_compat.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. #include <openssl/opensslv.h>
  7. #if OPENSSL_VERSION_NUMBER < 0x10100000L
  8. // This file is included by hash and hmac codes so KEA_H* macros
  9. // avoid to define unused inlines.
  10. #ifdef KEA_HASH
  11. // EVP_MD_CTX_new() is EVP_MD_CTX_create() in OpenSSL < 1.1
  12. inline EVP_MD_CTX* EVP_MD_CTX_new() {
  13. return (EVP_MD_CTX_create());
  14. }
  15. // EVP_MD_CTX_free(ctx) is EVP_MD_CTX_destroy(ctx) in OpenSSL < 1.1
  16. inline void EVP_MD_CTX_free(EVP_MD_CTX* ctx) {
  17. EVP_MD_CTX_destroy(ctx);
  18. }
  19. #endif
  20. #ifdef KEA_HMAC
  21. // HMAC_CTX_new() implementation for OpenSSL < 1.1
  22. inline HMAC_CTX* HMAC_CTX_new() {
  23. HMAC_CTX* ctx = static_cast<HMAC_CTX*>(OPENSSL_malloc(sizeof(HMAC_CTX)));
  24. if (ctx != 0) {
  25. HMAC_CTX_init(ctx);
  26. }
  27. return (ctx);
  28. }
  29. // HMAC_CTX_free() implementation for OpenSSL < 1.1
  30. inline void HMAC_CTX_free(HMAC_CTX* ctx) {
  31. if (ctx != 0) {
  32. HMAC_CTX_cleanup(ctx);
  33. OPENSSL_free(ctx);
  34. }
  35. }
  36. #endif
  37. #endif