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
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 # ifndef DECLARE_DEPRECATED
30 # define DECLARE_DEPRECATED(f) f;
32 # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)
33 # undef DECLARE_DEPRECATED
34 # define DECLARE_DEPRECATED(f) f __attribute__ ((deprecated));
36 # elif defined(__SUNPRO_C)
37 # if (__SUNPRO_C >= 0x5130)
38 # undef DECLARE_DEPRECATED
39 # define DECLARE_DEPRECATED(f) f __attribute__ ((deprecated));
45 * Applications should use -DOPENSSL_API_COMPAT=<version> to suppress the
46 * declarations of functions deprecated in or before <version>. If this is
47 * undefined, the value of the macro OPENSSL_CONFIGURED_API (defined in
48 * <openssl/opensslconf.h>) is the default.
50 * For any version number up until version 1.1.x, <version> is expected to be
51 * the calculated version number 0xMNNFFPPSL.
52 * For version numbers 3.0 and on, <version> is expected to be a computation
53 * of the major and minor numbers in decimal using this formula:
55 * MAJOR * 10000 + MINOR * 100
57 * So version 3.0 becomes 30000, version 3.2 becomes 30200, etc.
61 * We use the OPENSSL_API_COMPAT value to define API level macros. These
62 * macros are used to enable or disable features at that API version boundary.
65 # ifdef OPENSSL_API_LEVEL
66 # error "OPENSSL_API_LEVEL must not be defined by application"
70 * We figure out what API level was intended by simple numeric comparison.
71 * The lowest old style number we recognise is 0x00908000L, so we take some
72 * safety margin and assume that anything below 0x00900000L is a new style
73 * number. This allows new versions up to and including v943.71.83.
75 # ifdef OPENSSL_API_COMPAT
76 # if OPENSSL_API_COMPAT < 0x900000L
77 # define OPENSSL_API_LEVEL (OPENSSL_API_COMPAT)
79 # define OPENSSL_API_LEVEL \
80 (((OPENSSL_API_COMPAT >> 28) & 0xF) * 10000 \
81 + ((OPENSSL_API_COMPAT >> 20) & 0xFF) * 100 \
82 + ((OPENSSL_API_COMPAT >> 12) & 0xFF))
87 * If OPENSSL_API_COMPAT wasn't given, we use default numbers to set
88 * the API compatibility level.
90 # ifndef OPENSSL_API_LEVEL
91 # if OPENSSL_CONFIGURED_API > 0
92 # define OPENSSL_API_LEVEL (OPENSSL_CONFIGURED_API)
94 # define OPENSSL_API_LEVEL \
95 (OPENSSL_VERSION_MAJOR * 10000 + OPENSSL_VERSION_MINOR * 100)
99 # if OPENSSL_API_LEVEL > OPENSSL_CONFIGURED_API
100 # error "The requested API level higher than the configured API compatibility level"
104 * Check of sane values.
106 /* Can't go higher than the current version. */
107 # if OPENSSL_API_LEVEL > (OPENSSL_VERSION_MAJOR * 10000 + OPENSSL_VERSION_MINOR * 100)
108 # error "OPENSSL_API_COMPAT expresses an impossible API compatibility level"
110 /* OpenSSL will have no version 2.y.z */
111 # if OPENSSL_API_LEVEL < 30000 && OPENSSL_API_LEVEL >= 20000
112 # error "OPENSSL_API_COMPAT expresses an impossible API compatibility level"
114 /* Below 0.9.8 is unacceptably low */
115 # if OPENSSL_API_LEVEL < 908
116 # error "OPENSSL_API_COMPAT expresses an impossible API compatibility level"
120 * Define macros for deprecation purposes. We always define the macros
121 * DEPERECATEDIN_{major}_{minor}() for all OpenSSL versions we care for,
122 * and OPENSSL_NO_DEPRECATED_{major}_{minor} to be used to check if
123 * removal of deprecated functions applies on that particular version.
126 # undef OPENSSL_NO_DEPRECATED_3_0
127 # undef OPENSSL_NO_DEPRECATED_1_1_1
128 # undef OPENSSL_NO_DEPRECATED_1_1_0
129 # undef OPENSSL_NO_DEPRECATED_1_0_2
130 # undef OPENSSL_NO_DEPRECATED_1_0_1
131 # undef OPENSSL_NO_DEPRECATED_1_0_0
132 # undef OPENSSL_NO_DEPRECATED_0_9_8
134 # if OPENSSL_API_LEVEL >= 30000
135 # ifndef OPENSSL_NO_DEPRECATED
136 # define DEPRECATEDIN_3_0(f) DECLARE_DEPRECATED(f)
138 # define DEPRECATEDIN_3_0(f)
139 # define OPENSSL_NO_DEPRECATED_3_0
142 # define DEPRECATEDIN_3_0(f) f;
144 # if OPENSSL_API_LEVEL >= 10101
145 # ifndef OPENSSL_NO_DEPRECATED
146 # define DEPRECATEDIN_1_1_1(f) DECLARE_DEPRECATED(f)
148 # define DEPRECATEDIN_1_1_1(f)
149 # define OPENSSL_NO_DEPRECATED_1_1_1
152 # define DEPRECATEDIN_1_1_1(f) f;
154 # if OPENSSL_API_LEVEL >= 10100
155 # ifndef OPENSSL_NO_DEPRECATED
156 # define DEPRECATEDIN_1_1_0(f) DECLARE_DEPRECATED(f)
158 # define DEPRECATEDIN_1_1_0(f)
159 # define OPENSSL_NO_DEPRECATED_1_1_0
162 # define DEPRECATEDIN_1_1_0(f) f;
164 # if OPENSSL_API_LEVEL >= 10002
165 # ifndef OPENSSL_NO_DEPRECATED
166 # define DEPRECATEDIN_1_0_2(f) DECLARE_DEPRECATED(f)
168 # define DEPRECATEDIN_1_0_2(f)
169 # define OPENSSL_NO_DEPRECATED_1_0_2
172 # define DEPRECATEDIN_1_0_2(f) f;
174 # if OPENSSL_API_LEVEL >= 10001
175 # ifndef OPENSSL_NO_DEPRECATED
176 # define DEPRECATEDIN_1_0_1(f) DECLARE_DEPRECATED(f)
178 # define DEPRECATEDIN_1_0_1(f)
179 # define OPENSSL_NO_DEPRECATED_1_0_1
182 # define DEPRECATEDIN_1_0_1(f) f;
184 # if OPENSSL_API_LEVEL >= 10000
185 # ifndef OPENSSL_NO_DEPRECATED
186 # define DEPRECATEDIN_1_0_0(f) DECLARE_DEPRECATED(f)
188 # define DEPRECATEDIN_1_0_0(f)
189 # define OPENSSL_NO_DEPRECATED_1_0_0
192 # define DEPRECATEDIN_1_0_0(f) f;
194 # if OPENSSL_API_LEVEL >= 908
195 # ifndef OPENSSL_NO_DEPRECATED
196 # define DEPRECATEDIN_0_9_8(f) DECLARE_DEPRECATED(f)
198 # define DEPRECATEDIN_0_9_8(f)
199 # define OPENSSL_NO_DEPRECATED_0_9_8
202 # define DEPRECATEDIN_0_9_8(f) f;
206 * Make our own variants of __FILE__ and __LINE__, depending on configuration
209 # ifndef OPENSSL_FILE
210 # ifdef OPENSSL_NO_FILENAMES
211 # define OPENSSL_FILE ""
212 # define OPENSSL_LINE 0
214 # define OPENSSL_FILE __FILE__
215 # define OPENSSL_LINE __LINE__
220 * __func__ was standardized in C99, so for any compiler that claims
221 * to implement that language level or newer, we assume we can safely
224 * GNU C also provides __FUNCTION__ since version 2, which predates
225 * C99. We can, however, only use this if __STDC_VERSION__ exists,
226 * as it's otherwise not allowed according to ISO C standards (C90).
227 * (compiling with GNU C's -pedantic tells us so)
229 * If none of the above applies, we check if the compiler is MSVC,
230 * and use __FUNCTION__ if that's the case.
232 # ifndef OPENSSL_FUNC
233 # if defined(__STDC_VERSION__)
234 # if __STDC_VERSION__ >= 199901L
235 # define OPENSSL_FUNC __func__
236 # elif defined(__GNUC__) && __GNUC__ >= 2
237 # define OPENSSL_FUNC __FUNCTION__
239 # elif defined(_MSC_VER)
240 # define OPENSSL_FUNC __FUNCTION__
243 * If all these possibilities are exhausted, we give up and use a
246 # ifndef OPENSSL_FUNC
247 # define OPENSSL_FUNC "(unknown function)"
251 #endif /* OPENSSL_MACROS_H */