2 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include <openssl/opensslconf.h>
11 #include <openssl/opensslv.h>
13 #ifndef OPENSSL_MACROS_H
14 # define OPENSSL_MACROS_H
17 * Sometimes OPENSSSL_NO_xxx ends up with an empty file and some compilers
18 * don't like that. This will hopefully silence them.
20 # define NON_EMPTY_TRANSLATION_UNIT static void *dummy = &dummy;
23 * Generic deprecation macro
25 # ifndef DECLARE_DEPRECATED
26 # define DECLARE_DEPRECATED(f) f;
28 # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)
29 # undef DECLARE_DEPRECATED
30 # define DECLARE_DEPRECATED(f) f __attribute__ ((deprecated));
32 # elif defined(__SUNPRO_C)
33 # if (__SUNPRO_C >= 0x5130)
34 # undef DECLARE_DEPRECATED
35 # define DECLARE_DEPRECATED(f) f __attribute__ ((deprecated));
41 * Applications should use -DOPENSSL_API_COMPAT=<version> to suppress the
42 * declarations of functions deprecated in or before <version>. If this is
43 * undefined, the value of the macro OPENSSL_CONFIGURED_API (defined in
44 * <openssl/opensslconf.h>) is the default.
46 * For any version number up until version 1.1.x, <version> is expected to be
47 * the calculated version number 0xMNNFFPPSL.
48 * For version numbers 3.0 and on, <version> is expected to be a computation
49 * of the major and minor numbers in decimal using this formula:
51 * MAJOR * 10000 + MINOR * 100
53 * So version 3.0 becomes 30000, version 3.2 becomes 30200, etc.
57 * We use the OPENSSL_API_COMPAT value to define API level macros. These
58 * macros are used to enable or disable features at that API version boundary.
61 # ifdef OPENSSL_API_LEVEL
62 # error "OPENSSL_API_LEVEL must not be defined by application"
66 * We figure out what API level was intended by simple numeric comparison.
67 * The lowest old style number we recognise is 0x00908000L, so we take some
68 * safety margin and assume that anything below 0x00900000L is a new style
69 * number. This allows new versions up to and including v943.71.83.
71 # ifdef OPENSSL_API_COMPAT
72 # if OPENSSL_API_COMPAT < 0x900000L
73 # define OPENSSL_API_LEVEL (OPENSSL_API_COMPAT)
75 # define OPENSSL_API_LEVEL \
76 (((OPENSSL_API_COMPAT >> 28) & 0xF) * 10000 \
77 + ((OPENSSL_API_COMPAT >> 20) & 0xFF) * 100 \
78 + ((OPENSSL_API_COMPAT >> 12) & 0xFF))
83 * If OPENSSL_API_COMPAT wasn't given, we use default numbers to set
84 * the API compatibility level.
86 # ifndef OPENSSL_API_LEVEL
87 # if OPENSSL_CONFIGURED_API > 0
88 # define OPENSSL_API_LEVEL (OPENSSL_CONFIGURED_API)
90 # define OPENSSL_API_LEVEL \
91 (OPENSSL_VERSION_MAJOR * 10000 + OPENSSL_VERSION_MINOR * 100)
95 # if OPENSSL_API_LEVEL > OPENSSL_CONFIGURED_API
96 # error "The requested API level higher than the configured API compatibility level"
100 * Check of sane values.
102 /* Can't go higher than the current version. */
103 # if OPENSSL_API_LEVEL > (OPENSSL_VERSION_MAJOR * 10000 + OPENSSL_VERSION_MINOR * 100)
104 # error "OPENSSL_API_COMPAT expresses an impossible API compatibility level"
106 /* OpenSSL will have no version 2.y.z */
107 # if OPENSSL_API_LEVEL < 30000 && OPENSSL_API_LEVEL >= 20000
108 # error "OPENSSL_API_COMPAT expresses an impossible API compatibility level"
110 /* Below 0.9.8 is unacceptably low */
111 # if OPENSSL_API_LEVEL < 908
112 # error "OPENSSL_API_COMPAT expresses an impossible API compatibility level"
116 * Define macros for deprecation purposes. We always define the macros
117 * DEPERECATEDIN_{major}_{minor}() for all OpenSSL versions we care for,
118 * and OPENSSL_NO_DEPRECATED_{major}_{minor} to be used to check if
119 * removal of deprecated functions applies on that particular version.
122 # undef OPENSSL_NO_DEPRECATED_3_0
123 # undef OPENSSL_NO_DEPRECATED_1_1_1
124 # undef OPENSSL_NO_DEPRECATED_1_1_0
125 # undef OPENSSL_NO_DEPRECATED_1_0_2
126 # undef OPENSSL_NO_DEPRECATED_1_0_1
127 # undef OPENSSL_NO_DEPRECATED_1_0_0
128 # undef OPENSSL_NO_DEPRECATED_0_9_8
130 # if OPENSSL_API_LEVEL >= 30000
131 # ifndef OPENSSL_NO_DEPRECATED
132 # define DEPRECATEDIN_3_0(f) DECLARE_DEPRECATED(f)
134 # define DEPRECATEDIN_3_0(f)
135 # define OPENSSL_NO_DEPRECATED_3_0
138 # define DEPRECATEDIN_3_0(f) f;
140 # if OPENSSL_API_LEVEL >= 10101
141 # ifndef OPENSSL_NO_DEPRECATED
142 # define DEPRECATEDIN_1_1_1(f) DECLARE_DEPRECATED(f)
144 # define DEPRECATEDIN_1_1_1(f)
145 # define OPENSSL_NO_DEPRECATED_1_1_1
148 # define DEPRECATEDIN_1_1_1(f) f;
150 # if OPENSSL_API_LEVEL >= 10100
151 # ifndef OPENSSL_NO_DEPRECATED
152 # define DEPRECATEDIN_1_1_0(f) DECLARE_DEPRECATED(f)
154 # define DEPRECATEDIN_1_1_0(f)
155 # define OPENSSL_NO_DEPRECATED_1_1_0
158 # define DEPRECATEDIN_1_1_0(f) f;
160 # if OPENSSL_API_LEVEL >= 10002
161 # ifndef OPENSSL_NO_DEPRECATED
162 # define DEPRECATEDIN_1_0_2(f) DECLARE_DEPRECATED(f)
164 # define DEPRECATEDIN_1_0_2(f)
165 # define OPENSSL_NO_DEPRECATED_1_0_2
168 # define DEPRECATEDIN_1_0_2(f) f;
170 # if OPENSSL_API_LEVEL >= 10001
171 # ifndef OPENSSL_NO_DEPRECATED
172 # define DEPRECATEDIN_1_0_1(f) DECLARE_DEPRECATED(f)
174 # define DEPRECATEDIN_1_0_1(f)
175 # define OPENSSL_NO_DEPRECATED_1_0_1
178 # define DEPRECATEDIN_1_0_1(f) f;
180 # if OPENSSL_API_LEVEL >= 10000
181 # ifndef OPENSSL_NO_DEPRECATED
182 # define DEPRECATEDIN_1_0_0(f) DECLARE_DEPRECATED(f)
184 # define DEPRECATEDIN_1_0_0(f)
185 # define OPENSSL_NO_DEPRECATED_1_0_0
188 # define DEPRECATEDIN_1_0_0(f) f;
190 # if OPENSSL_API_LEVEL >= 908
191 # ifndef OPENSSL_NO_DEPRECATED
192 # define DEPRECATEDIN_0_9_8(f) DECLARE_DEPRECATED(f)
194 # define DEPRECATEDIN_0_9_8(f)
195 # define OPENSSL_NO_DEPRECATED_0_9_8
198 # define DEPRECATEDIN_0_9_8(f) f;
202 * Make our own variants of __FILE__ and __LINE__, depending on configuration
205 # ifndef OPENSSL_FILE
206 # ifdef OPENSSL_NO_FILENAMES
207 # define OPENSSL_FILE ""
208 # define OPENSSL_LINE 0
210 # define OPENSSL_FILE __FILE__
211 # define OPENSSL_LINE __LINE__
216 * __func__ was standardized in C99, so for any compiler that claims
217 * to implement that language level or newer, we assume we can safely
220 * GNU C also provides __FUNCTION__ since version 2, which predates
221 * C99. We can, however, only use this if __STDC_VERSION__ exists,
222 * as it's otherwise not allowed according to ISO C standards (C90).
223 * (compiling with GNU C's -pedantic tells us so)
225 * If none of the above applies, we check if the compiler is MSVC,
226 * and use __FUNCTION__ if that's the case.
228 # ifndef OPENSSL_FUNC
229 # if defined(__STDC_VERSION__)
230 # if __STDC_VERSION__ >= 199901L
231 # define OPENSSL_FUNC __func__
232 # elif defined(__GNUC__) && __GNUC__ >= 2
233 # define OPENSSL_FUNC __FUNCTION__
235 # elif defined(_MSC_VER)
236 # define OPENSSL_FUNC __FUNCTION__
239 * If all these possibilities are exhausted, we give up and use a
242 # ifndef OPENSSL_FUNC
243 # define OPENSSL_FUNC "(unknown function)"
247 #endif /* OPENSSL_MACROS_H */