crypto_openssl_mgt.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Copyright (c) 2001, Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file crypto_openssl_mgt.h
  8. *
  9. * \brief Headers for crypto_openssl_mgt.c
  10. **/
  11. #ifndef TOR_CRYPTO_OPENSSL_H
  12. #define TOR_CRYPTO_OPENSSL_H
  13. #include "orconfig.h"
  14. #include <openssl/engine.h>
  15. /*
  16. Macro to create an arbitrary OpenSSL version number as used by
  17. OPENSSL_VERSION_NUMBER or SSLeay(), since the actual numbers are a bit hard
  18. to read.
  19. Don't use this directly, instead use one of the other OPENSSL_V macros
  20. below.
  21. The format is: 4 bits major, 8 bits minor, 8 bits fix, 8 bits patch, 4 bit
  22. status.
  23. */
  24. #define OPENSSL_VER(a,b,c,d,e) \
  25. (((a)<<28) | \
  26. ((b)<<20) | \
  27. ((c)<<12) | \
  28. ((d)<< 4) | \
  29. (e))
  30. /** An openssl release number. For example, OPENSSL_V(0,9,8,'j') is the
  31. * version for the released version of 0.9.8j */
  32. #define OPENSSL_V(a,b,c,d) \
  33. OPENSSL_VER((a),(b),(c),(d)-'a'+1,0xf)
  34. /** An openssl release number for the first release in the series. For
  35. * example, OPENSSL_V_NOPATCH(1,0,0) is the first released version of OpenSSL
  36. * 1.0.0. */
  37. #define OPENSSL_V_NOPATCH(a,b,c) \
  38. OPENSSL_VER((a),(b),(c),0,0xf)
  39. /** The first version that would occur for any alpha or beta in an openssl
  40. * series. For example, OPENSSL_V_SERIES(0,9,8) is greater than any released
  41. * 0.9.7, and less than any released 0.9.8. */
  42. #define OPENSSL_V_SERIES(a,b,c) \
  43. OPENSSL_VER((a),(b),(c),0,0)
  44. #ifdef ANDROID
  45. /* Android's OpenSSL seems to have removed all of its Engine support. */
  46. #define DISABLE_ENGINES
  47. #endif
  48. #if OPENSSL_VERSION_NUMBER >= OPENSSL_VER(1,1,0,0,5) && \
  49. !defined(LIBRESSL_VERSION_NUMBER)
  50. /* OpenSSL as of 1.1.0pre4 has an "new" thread API, which doesn't require
  51. * seting up various callbacks.
  52. *
  53. * OpenSSL 1.1.0pre4 has a messed up `ERR_remove_thread_state()` prototype,
  54. * while the previous one was restored in pre5, and the function made a no-op
  55. * (along with a deprecated annotation, which produces a compiler warning).
  56. *
  57. * While it is possible to support all three versions of the thread API,
  58. * a version that existed only for one snapshot pre-release is kind of
  59. * pointless, so let's not.
  60. */
  61. #define NEW_THREAD_API
  62. #endif /* OPENSSL_VERSION_NUMBER >= OPENSSL_VER(1,1,0,0,5) && ... */
  63. /* global openssl state */
  64. const char * crypto_openssl_get_version_str(void);
  65. const char * crypto_openssl_get_header_version_str(void);
  66. /* OpenSSL threading setup function */
  67. int setup_openssl_threading(void);
  68. /* Tor OpenSSL utility functions */
  69. void crypto_openssl_free_all(void);
  70. #endif /* !defined(TOR_CRYPTO_OPENSSL_H) */