crypto_openssl_mgt.h 2.9 KB

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