2 * Copyright 2019-2020 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
16 /* Helper macros for CPP string composition */
17 # define OPENSSL_MSTR_HELPER(x) #x
18 # define OPENSSL_MSTR(x) OPENSSL_MSTR_HELPER(x)
21 * Sometimes OPENSSSL_NO_xxx ends up with an empty file and some compilers
22 * don't like that. This will hopefully silence them.
24 # define NON_EMPTY_TRANSLATION_UNIT static void *dummy = &dummy;
27 * Generic deprecation macro
29 * If OPENSSL_SUPPRESS_DEPRECATED is defined, then OSSL_DEPRECATED and
30 * OSSL_DEPRECATED_FOR become no-ops
32 # ifndef OSSL_DEPRECATED
33 # undef OSSL_DEPRECATED_FOR
34 # ifndef OPENSSL_SUPPRESS_DEPRECATED
35 # if defined(_MSC_VER)
37 * MSVC supports __declspec(deprecated) since MSVC 2003 (13.10),
38 * and __declspec(deprecated(message)) since MSVC 2005 (14.00)
41 # define OSSL_DEPRECATED(since) \
42 __declspec(deprecated("Since OpenSSL " # since))
43 # define OSSL_DEPRECATED_FOR(since, message) \
44 __declspec(deprecated("Since OpenSSL " # since ";" message))
45 # elif _MSC_VER >= 1310
46 # define OSSL_DEPRECATED(since) __declspec(deprecated)
47 # define OSSL_DEPRECATED_FOR(since, message) __declspec(deprecated)
49 # elif defined(__GNUC__)
51 * According to GCC documentation, deprecations with message appeared in
54 # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
55 # define OSSL_DEPRECATED(since) \
56 __attribute__((deprecated("Since OpenSSL " # since)))
57 # define OSSL_DEPRECATED_FOR(since, message) \
58 __attribute__((deprecated("Since OpenSSL " # since ";" message)))
59 # elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)
60 # define OSSL_DEPRECATED(since) __attribute__((deprecated))
61 # define OSSL_DEPRECATED_FOR(since, message) __attribute__((deprecated))
63 # elif defined(__SUNPRO_C)
64 # if (__SUNPRO_C >= 0x5130)
65 # define OSSL_DEPRECATED(since) __attribute__ ((deprecated))
66 # define OSSL_DEPRECATED_FOR(since, message) __attribute__ ((deprecated))
72 /* Still not defined? Then define empty macros */
73 # ifndef OSSL_DEPRECATED
74 # define OSSL_DEPRECATED(since)
75 # define OSSL_DEPRECATED_FOR(since, message)
79 * Applications should use -DOPENSSL_API_COMPAT=<version> to suppress the
80 * declarations of functions deprecated in or before <version>. If this is
81 * undefined, the value of the macro OPENSSL_CONFIGURED_API (defined in
82 * <openssl/opensslconf.h>) is the default.
84 * For any version number up until version 1.1.x, <version> is expected to be
85 * the calculated version number 0xMNNFFPPSL.
86 * For version numbers 3.0 and on, <version> is expected to be a computation
87 * of the major and minor numbers in decimal using this formula:
89 * MAJOR * 10000 + MINOR * 100
91 * So version 3.0 becomes 30000, version 3.2 becomes 30200, etc.
95 * We use the OPENSSL_API_COMPAT value to define API level macros. These
96 * macros are used to enable or disable features at that API version boundary.
99 # ifdef OPENSSL_API_LEVEL
100 # error "OPENSSL_API_LEVEL must not be defined by application"
104 * We figure out what API level was intended by simple numeric comparison.
105 * The lowest old style number we recognise is 0x00908000L, so we take some
106 * safety margin and assume that anything below 0x00900000L is a new style
107 * number. This allows new versions up to and including v943.71.83.
109 # ifdef OPENSSL_API_COMPAT
110 # if OPENSSL_API_COMPAT < 0x900000L
111 # define OPENSSL_API_LEVEL (OPENSSL_API_COMPAT)
113 # define OPENSSL_API_LEVEL \
114 (((OPENSSL_API_COMPAT >> 28) & 0xF) * 10000 \
115 + ((OPENSSL_API_COMPAT >> 20) & 0xFF) * 100 \
116 + ((OPENSSL_API_COMPAT >> 12) & 0xFF))
121 * If OPENSSL_API_COMPAT wasn't given, we use default numbers to set
122 * the API compatibility level.
124 # ifndef OPENSSL_API_LEVEL
125 # if OPENSSL_CONFIGURED_API > 0
126 # define OPENSSL_API_LEVEL (OPENSSL_CONFIGURED_API)
128 # define OPENSSL_API_LEVEL \
129 (OPENSSL_VERSION_MAJOR * 10000 + OPENSSL_VERSION_MINOR * 100)
133 # if OPENSSL_API_LEVEL > OPENSSL_CONFIGURED_API
134 # error "The requested API level higher than the configured API compatibility level"
138 * Check of sane values.
140 /* Can't go higher than the current version. */
141 # if OPENSSL_API_LEVEL > (OPENSSL_VERSION_MAJOR * 10000 + OPENSSL_VERSION_MINOR * 100)
142 # error "OPENSSL_API_COMPAT expresses an impossible API compatibility level"
144 /* OpenSSL will have no version 2.y.z */
145 # if OPENSSL_API_LEVEL < 30000 && OPENSSL_API_LEVEL >= 20000
146 # error "OPENSSL_API_COMPAT expresses an impossible API compatibility level"
148 /* Below 0.9.8 is unacceptably low */
149 # if OPENSSL_API_LEVEL < 908
150 # error "OPENSSL_API_COMPAT expresses an impossible API compatibility level"
154 * Define macros for deprecation and simulated removal purposes.
156 * The macros OSSL_DEPRECATED_{major}_{minor} are always defined for
157 * all OpenSSL versions we care for. They can be used as attributes
158 * in function declarations where appropriate.
160 * The macros OPENSSL_NO_DEPRECATED_{major}_{minor} are defined for
161 * all OpenSSL versions up to or equal to the version given with
162 * OPENSSL_API_COMPAT. They are used as guards around anything that's
163 * deprecated up to that version, as an effect of the developer option
167 # undef OPENSSL_NO_DEPRECATED_3_0
168 # undef OPENSSL_NO_DEPRECATED_1_1_1
169 # undef OPENSSL_NO_DEPRECATED_1_1_0
170 # undef OPENSSL_NO_DEPRECATED_1_0_2
171 # undef OPENSSL_NO_DEPRECATED_1_0_1
172 # undef OPENSSL_NO_DEPRECATED_1_0_0
173 # undef OPENSSL_NO_DEPRECATED_0_9_8
175 # if OPENSSL_API_LEVEL >= 30000
176 # ifndef OPENSSL_NO_DEPRECATED
177 # define OSSL_DEPRECATEDIN_3_0 OSSL_DEPRECATED(3.0)
178 # define OSSL_DEPRECATEDIN_3_0_FOR(msg) OSSL_DEPRECATED_FOR(3.0, msg)
179 # define DEPRECATEDIN_3_0(f) OSSL_DEPRECATEDIN_3_0 f;
181 # define OPENSSL_NO_DEPRECATED_3_0
182 # define DEPRECATEDIN_3_0(f)
185 # define OSSL_DEPRECATEDIN_3_0
186 # define OSSL_DEPRECATEDIN_3_0_FOR(msg)
187 # define DEPRECATEDIN_3_0(f) f;
189 # if OPENSSL_API_LEVEL >= 10101
190 # ifndef OPENSSL_NO_DEPRECATED
191 # define OSSL_DEPRECATEDIN_1_1_1 OSSL_DEPRECATED(1.1.1)
192 # define OSSL_DEPRECATEDIN_1_1_1_FOR(msg) OSSL_DEPRECATED_FOR(1.1.1, msg)
193 # define DEPRECATEDIN_1_1_1(f) OSSL_DEPRECATEDIN_1_1_1 f;
195 # define OPENSSL_NO_DEPRECATED_1_1_1
196 # define DEPRECATEDIN_1_1_1(f)
199 # define OSSL_DEPRECATEDIN_1_1_1
200 # define OSSL_DEPRECATEDIN_1_1_1_FOR(msg)
201 # define DEPRECATEDIN_1_1_1(f) f;
203 # if OPENSSL_API_LEVEL >= 10100
204 # ifndef OPENSSL_NO_DEPRECATED
205 # define OSSL_DEPRECATEDIN_1_1_0 OSSL_DEPRECATED(1.1.0)
206 # define OSSL_DEPRECATEDIN_1_1_0_FOR(msg) OSSL_DEPRECATED_FOR(1.1.0, msg)
207 # define DEPRECATEDIN_1_1_0(f) OSSL_DEPRECATEDIN_1_1_0 f;
209 # define OPENSSL_NO_DEPRECATED_1_1_0
210 # define DEPRECATEDIN_1_1_0(f)
213 # define OSSL_DEPRECATEDIN_1_1_0
214 # define OSSL_DEPRECATEDIN_1_1_0_FOR(msg)
215 # define DEPRECATEDIN_1_1_0(f) f;
217 # if OPENSSL_API_LEVEL >= 10002
218 # ifndef OPENSSL_NO_DEPRECATED
219 # define OSSL_DEPRECATEDIN_1_0_2 OSSL_DEPRECATED(1.0.2)
220 # define OSSL_DEPRECATEDIN_1_0_2_FOR(msg) OSSL_DEPRECATED_FOR(1.0.2, msg)
221 # define DEPRECATEDIN_1_0_2(f) OSSL_DEPRECATEDIN_1_0_2 f;
223 # define OPENSSL_NO_DEPRECATED_1_0_2
224 # define DEPRECATEDIN_1_0_2(f)
227 # define OSSL_DEPRECATEDIN_1_0_2
228 # define OSSL_DEPRECATEDIN_1_0_2_FOR(msg)
229 # define DEPRECATEDIN_1_0_2(f) f;
231 # if OPENSSL_API_LEVEL >= 10001
232 # ifndef OPENSSL_NO_DEPRECATED
233 # define OSSL_DEPRECATEDIN_1_0_1 OSSL_DEPRECATED(1.0.1)
234 # define OSSL_DEPRECATEDIN_1_0_1_FOR(msg) OSSL_DEPRECATED_FOR(1.0.1, msg)
235 # define DEPRECATEDIN_1_0_1(f) OSSL_DEPRECATEDIN_1_0_1 f;
237 # define OPENSSL_NO_DEPRECATED_1_0_1
238 # define DEPRECATEDIN_1_0_1(f)
241 # define OSSL_DEPRECATEDIN_1_0_1
242 # define OSSL_DEPRECATEDIN_1_0_1_FOR(msg)
243 # define DEPRECATEDIN_1_0_1(f) f;
245 # if OPENSSL_API_LEVEL >= 10000
246 # ifndef OPENSSL_NO_DEPRECATED
247 # define OSSL_DEPRECATEDIN_1_0_0 OSSL_DEPRECATED(1.0.0)
248 # define OSSL_DEPRECATEDIN_1_0_0_FOR(msg) OSSL_DEPRECATED_FOR(1.0.0, msg)
249 # define DEPRECATEDIN_1_0_0(f) OSSL_DEPRECATEDIN_1_0_0 f;
251 # define OPENSSL_NO_DEPRECATED_1_0_0
252 # define DEPRECATEDIN_1_0_0(f)
255 # define OSSL_DEPRECATEDIN_1_0_0
256 # define OSSL_DEPRECATEDIN_1_0_0_FOR(msg)
257 # define DEPRECATEDIN_1_0_0(f) f;
259 # if OPENSSL_API_LEVEL >= 908
260 # ifndef OPENSSL_NO_DEPRECATED
261 # define OSSL_DEPRECATEDIN_0_9_8 OSSL_DEPRECATED(0.9.8)
262 # define OSSL_DEPRECATEDIN_0_9_8_FOR(msg) OSSL_DEPRECATED_FOR(0.9.8, msg)
263 # define DEPRECATEDIN_0_9_8(f) OSSL_DEPRECATEDIN_0_9_8 f;
265 # define OPENSSL_NO_DEPRECATED_0_9_8
266 # define DEPRECATEDIN_0_9_8(f)
269 # define OSSL_DEPRECATEDIN_0_9_8
270 # define OSSL_DEPRECATEDIN_0_9_8_FOR(msg)
271 # define DEPRECATEDIN_0_9_8(f) f;
275 * Make our own variants of __FILE__ and __LINE__, depending on configuration
278 # ifndef OPENSSL_FILE
279 # ifdef OPENSSL_NO_FILENAMES
280 # define OPENSSL_FILE ""
281 # define OPENSSL_LINE 0
283 # define OPENSSL_FILE __FILE__
284 # define OPENSSL_LINE __LINE__
289 * __func__ was standardized in C99, so for any compiler that claims
290 * to implement that language level or newer, we assume we can safely
293 * GNU C also provides __FUNCTION__ since version 2, which predates
294 * C99. We can, however, only use this if __STDC_VERSION__ exists,
295 * as it's otherwise not allowed according to ISO C standards (C90).
296 * (compiling with GNU C's -pedantic tells us so)
298 * If none of the above applies, we check if the compiler is MSVC,
299 * and use __FUNCTION__ if that's the case.
301 # ifndef OPENSSL_FUNC
302 # if defined(__STDC_VERSION__)
303 # if __STDC_VERSION__ >= 199901L
304 # define OPENSSL_FUNC __func__
305 # elif defined(__GNUC__) && __GNUC__ >= 2
306 # define OPENSSL_FUNC __FUNCTION__
308 # elif defined(_MSC_VER)
309 # define OPENSSL_FUNC __FUNCTION__
312 * If all these possibilities are exhausted, we give up and use a
315 # ifndef OPENSSL_FUNC
316 # define OPENSSL_FUNC "(unknown function)"
320 #endif /* OPENSSL_MACROS_H */