crypto_openssl.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. DISABLE_GCC_WARNING(redundant-decls)
  17. #include <openssl/err.h>
  18. #include <openssl/rsa.h>
  19. #include <openssl/pem.h>
  20. #include <openssl/evp.h>
  21. #include <openssl/engine.h>
  22. #include <openssl/rand.h>
  23. #include <openssl/bn.h>
  24. #include <openssl/dh.h>
  25. #include <openssl/conf.h>
  26. #include <openssl/hmac.h>
  27. ENABLE_GCC_WARNING(redundant-decls)
  28. /*
  29. Macro to create an arbitrary OpenSSL version number as used by
  30. OPENSSL_VERSION_NUMBER or SSLeay(), since the actual numbers are a bit hard
  31. to read.
  32. Don't use this directly, instead use one of the other OPENSSL_V macros
  33. below.
  34. The format is: 4 bits major, 8 bits minor, 8 bits fix, 8 bits patch, 4 bit
  35. status.
  36. */
  37. #define OPENSSL_VER(a,b,c,d,e) \
  38. (((a)<<28) | \
  39. ((b)<<20) | \
  40. ((c)<<12) | \
  41. ((d)<< 4) | \
  42. (e))
  43. /** An openssl release number. For example, OPENSSL_V(0,9,8,'j') is the
  44. * version for the released version of 0.9.8j */
  45. #define OPENSSL_V(a,b,c,d) \
  46. OPENSSL_VER((a),(b),(c),(d)-'a'+1,0xf)
  47. /** An openssl release number for the first release in the series. For
  48. * example, OPENSSL_V_NOPATCH(1,0,0) is the first released version of OpenSSL
  49. * 1.0.0. */
  50. #define OPENSSL_V_NOPATCH(a,b,c) \
  51. OPENSSL_VER((a),(b),(c),0,0xf)
  52. /** The first version that would occur for any alpha or beta in an openssl
  53. * series. For example, OPENSSL_V_SERIES(0,9,8) is greater than any released
  54. * 0.9.7, and less than any released 0.9.8. */
  55. #define OPENSSL_V_SERIES(a,b,c) \
  56. OPENSSL_VER((a),(b),(c),0,0)
  57. #ifdef ANDROID
  58. /* Android's OpenSSL seems to have removed all of its Engine support. */
  59. #define DISABLE_ENGINES
  60. #endif
  61. #if OPENSSL_VERSION_NUMBER >= OPENSSL_VER(1,1,0,0,5) && \
  62. !defined(LIBRESSL_VERSION_NUMBER)
  63. /* OpenSSL as of 1.1.0pre4 has an "new" thread API, which doesn't require
  64. * seting up various callbacks.
  65. *
  66. * OpenSSL 1.1.0pre4 has a messed up `ERR_remove_thread_state()` prototype,
  67. * while the previous one was restored in pre5, and the function made a no-op
  68. * (along with a deprecated annotation, which produces a compiler warning).
  69. *
  70. * While it is possible to support all three versions of the thread API,
  71. * a version that existed only for one snapshot pre-release is kind of
  72. * pointless, so let's not.
  73. */
  74. #define NEW_THREAD_API
  75. #endif /* OPENSSL_VERSION_NUMBER >= OPENSSL_VER(1,1,0,0,5) && ... */
  76. tor_mutex_t **openssl_mutexes_;
  77. int n_openssl_mutexes_;
  78. /* global openssl state */
  79. const char * crypto_openssl_get_version_str(void);
  80. const char * crypto_openssl_get_header_version_str(void);
  81. /* generics OpenSSL functions */
  82. char * parse_openssl_version_str(const char *raw_version);
  83. void openssl_locking_cb_(int mode, int n, const char *file, int line);
  84. void tor_set_openssl_thread_id(CRYPTO_THREADID *threadid);
  85. /* OpenSSL threading setup function */
  86. int setup_openssl_threading(void);
  87. #endif /* !defined(TOR_CRYPTO_OPENSSL_H) */