Tor 0.4.9.0-alpha-dev
compat_openssl.h
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-2021, The Tor Project, Inc. */
5/* See LICENSE for licensing information */
6
7#ifndef TOR_COMPAT_OPENSSL_H
8#define TOR_COMPAT_OPENSSL_H
9
10#include "orconfig.h"
11
12#ifdef ENABLE_OPENSSL
13
14#include <openssl/opensslv.h>
16
17/**
18 * \file compat_openssl.h
19 *
20 * \brief compatibility definitions for working with different openssl forks
21 **/
22
23#if OPENSSL_VERSION_NUMBER < OPENSSL_V_SERIES(1,0,1)
24#error "We require OpenSSL >= 1.0.1"
25#endif
26
27#if OPENSSL_VERSION_NUMBER >= OPENSSL_V_SERIES(1,1,0)
28/* We define this macro if we're trying to build with the majorly refactored
29 * API in OpenSSL 1.1 */
30#define OPENSSL_1_1_API
31#endif /* OPENSSL_VERSION_NUMBER >= OPENSSL_V_SERIES(1,1,0) && ... */
32
33/* LibreSSL claims to be OpenSSL 2.0 but lacks these OpenSSL 1.1 APIs */
34#if !defined(OPENSSL_1_1_API) || defined(LIBRESSL_VERSION_NUMBER)
35#define RAND_OpenSSL() RAND_SSLeay()
36#define STATE_IS_SW_SERVER_HELLO(st) \
37 (((st) == SSL3_ST_SW_SRVR_HELLO_A) || \
38 ((st) == SSL3_ST_SW_SRVR_HELLO_B))
39#define OSSL_HANDSHAKE_STATE int
40#define CONST_IF_OPENSSL_1_1_API
41#else
42#define STATE_IS_SW_SERVER_HELLO(st) \
43 ((st) == TLS_ST_SW_SRVR_HELLO)
44#define CONST_IF_OPENSSL_1_1_API const
45#endif
46
47/* OpenSSL 1.1 and LibreSSL both have these APIs */
48#ifndef OPENSSL_1_1_API
49#define OpenSSL_version(v) SSLeay_version(v)
50#define tor_OpenSSL_version_num() SSLeay()
51#else /* defined(OPENSSL_1_1_API) */
52#define tor_OpenSSL_version_num() OpenSSL_version_num()
53#endif /* !defined(OPENSSL_1_1_API) */
54
55#endif /* defined(ENABLE_OPENSSL) */
56
57#endif /* !defined(TOR_COMPAT_OPENSSL_H) */
Headers for crypto_openssl_mgt.c.