Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-20 09:19:48

0001 /*
0002  * Copyright 2019-2025 The OpenSSL Project Authors. All Rights Reserved.
0003  *
0004  * Licensed under the Apache License 2.0 (the "License").  You may not use
0005  * this file except in compliance with the License.  You can obtain a copy
0006  * in the file LICENSE in the source distribution or at
0007  * https://www.openssl.org/source/license.html
0008  */
0009 
0010 #ifndef OPENSSL_MACROS_H
0011 #define OPENSSL_MACROS_H
0012 #pragma once
0013 
0014 #include <openssl/opensslconf.h>
0015 #include <openssl/opensslv.h>
0016 
0017 /* Helper macros for CPP string composition */
0018 #define OPENSSL_MSTR_HELPER(x) #x
0019 #define OPENSSL_MSTR(x) OPENSSL_MSTR_HELPER(x)
0020 
0021 /*
0022  * Sometimes OPENSSL_NO_xxx ends up with an empty file and some compilers
0023  * don't like that.  This will hopefully silence them.
0024  */
0025 #define NON_EMPTY_TRANSLATION_UNIT static void *dummy = &dummy;
0026 
0027 /*
0028  * Generic deprecation macro
0029  *
0030  * If OPENSSL_SUPPRESS_DEPRECATED is defined, then OSSL_DEPRECATED and
0031  * OSSL_DEPRECATED_FOR become no-ops
0032  */
0033 #ifndef OSSL_DEPRECATED
0034 #undef OSSL_DEPRECATED_FOR
0035 #ifndef OPENSSL_SUPPRESS_DEPRECATED
0036 #if defined(_MSC_VER)
0037 /*
0038  * MSVC supports __declspec(deprecated) since MSVC 2003 (13.10),
0039  * and __declspec(deprecated(message)) since MSVC 2005 (14.00)
0040  */
0041 #if _MSC_VER >= 1400
0042 #define OSSL_DEPRECATED(since) \
0043     __declspec(deprecated("Since OpenSSL " #since))
0044 #define OSSL_DEPRECATED_FOR(since, message) \
0045     __declspec(deprecated("Since OpenSSL " #since ";" message))
0046 #elif _MSC_VER >= 1310
0047 #define OSSL_DEPRECATED(since) __declspec(deprecated)
0048 #define OSSL_DEPRECATED_FOR(since, message) __declspec(deprecated)
0049 #endif
0050 #elif defined(__GNUC__)
0051 /*
0052  * According to GCC documentation, deprecations with message appeared in
0053  * GCC 4.5.0
0054  */
0055 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
0056 #define OSSL_DEPRECATED(since) \
0057     __attribute__((deprecated("Since OpenSSL " #since)))
0058 #define OSSL_DEPRECATED_FOR(since, message) \
0059     __attribute__((deprecated("Since OpenSSL " #since ";" message)))
0060 #elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)
0061 #define OSSL_DEPRECATED(since) __attribute__((deprecated))
0062 #define OSSL_DEPRECATED_FOR(since, message) __attribute__((deprecated))
0063 #endif
0064 #elif defined(__SUNPRO_C)
0065 #if (__SUNPRO_C >= 0x5130)
0066 #define OSSL_DEPRECATED(since) __attribute__((deprecated))
0067 #define OSSL_DEPRECATED_FOR(since, message) __attribute__((deprecated))
0068 #endif
0069 #endif
0070 #endif
0071 #endif
0072 
0073 /*
0074  * Still not defined?  Then define no-op macros. This means these macros
0075  * are unsuitable for use in a typedef.
0076  */
0077 #ifndef OSSL_DEPRECATED
0078 #define OSSL_DEPRECATED(since) extern
0079 #define OSSL_DEPRECATED_FOR(since, message) extern
0080 #endif
0081 
0082 /*
0083  * Applications should use -DOPENSSL_API_COMPAT=<version> to suppress the
0084  * declarations of functions deprecated in or before <version>.  If this is
0085  * undefined, the value of the macro OPENSSL_CONFIGURED_API (defined in
0086  * <openssl/opensslconf.h>) is the default.
0087  *
0088  * For any version number up until version 1.1.x, <version> is expected to be
0089  * the calculated version number 0xMNNFFPPSL.
0090  * For version numbers 3.0 and on, <version> is expected to be a computation
0091  * of the major and minor numbers in decimal using this formula:
0092  *
0093  *     MAJOR * 10000 + MINOR * 100
0094  *
0095  * So version 3.0 becomes 30000, version 3.2 becomes 30200, etc.
0096  */
0097 
0098 /*
0099  * We use the OPENSSL_API_COMPAT value to define API level macros.  These
0100  * macros are used to enable or disable features at that API version boundary.
0101  */
0102 
0103 #ifdef OPENSSL_API_LEVEL
0104 #error "OPENSSL_API_LEVEL must not be defined by application"
0105 #endif
0106 
0107 /*
0108  * We figure out what API level was intended by simple numeric comparison.
0109  * The lowest old style number we recognise is 0x00908000L, so we take some
0110  * safety margin and assume that anything below 0x00900000L is a new style
0111  * number.  This allows new versions up to and including v943.71.83.
0112  */
0113 #ifdef OPENSSL_API_COMPAT
0114 #if OPENSSL_API_COMPAT < 0x900000L
0115 #define OPENSSL_API_LEVEL (OPENSSL_API_COMPAT)
0116 #else
0117 #define OPENSSL_API_LEVEL                           \
0118     (((OPENSSL_API_COMPAT >> 28) & 0xF) * 10000     \
0119         + ((OPENSSL_API_COMPAT >> 20) & 0xFF) * 100 \
0120         + ((OPENSSL_API_COMPAT >> 12) & 0xFF))
0121 #endif
0122 #endif
0123 
0124 /*
0125  * If OPENSSL_API_COMPAT wasn't given, we use default numbers to set
0126  * the API compatibility level.
0127  */
0128 #ifndef OPENSSL_API_LEVEL
0129 #if OPENSSL_CONFIGURED_API > 0
0130 #define OPENSSL_API_LEVEL (OPENSSL_CONFIGURED_API)
0131 #else
0132 #define OPENSSL_API_LEVEL \
0133     (OPENSSL_VERSION_MAJOR * 10000 + OPENSSL_VERSION_MINOR * 100)
0134 #endif
0135 #endif
0136 
0137 #if OPENSSL_API_LEVEL > OPENSSL_CONFIGURED_API
0138 #error "The requested API level higher than the configured API compatibility level"
0139 #endif
0140 
0141 /*
0142  * Check of sane values.
0143  */
0144 /* Can't go higher than the current version. */
0145 #if OPENSSL_API_LEVEL > (OPENSSL_VERSION_MAJOR * 10000 + OPENSSL_VERSION_MINOR * 100)
0146 #error "OPENSSL_API_COMPAT expresses an impossible API compatibility level"
0147 #endif
0148 /* OpenSSL will have no version 2.y.z */
0149 #if OPENSSL_API_LEVEL < 30000 && OPENSSL_API_LEVEL >= 20000
0150 #error "OPENSSL_API_COMPAT expresses an impossible API compatibility level"
0151 #endif
0152 /* Below 0.9.8 is unacceptably low */
0153 #if OPENSSL_API_LEVEL < 908
0154 #error "OPENSSL_API_COMPAT expresses an impossible API compatibility level"
0155 #endif
0156 
0157 /*
0158  * Define macros for deprecation and simulated removal purposes.
0159  *
0160  * The macros OSSL_DEPRECATEDIN_{major}_{minor} are always defined for
0161  * all OpenSSL versions we care for.  They can be used as attributes
0162  * in function declarations where appropriate.
0163  *
0164  * The macros OPENSSL_NO_DEPRECATED_{major}_{minor} are defined for
0165  * all OpenSSL versions up to or equal to the version given with
0166  * OPENSSL_API_COMPAT.  They are used as guards around anything that's
0167  * deprecated up to that version, as an effect of the developer option
0168  * 'no-deprecated'.
0169  */
0170 
0171 #undef OPENSSL_NO_DEPRECATED_3_6
0172 #undef OPENSSL_NO_DEPRECATED_3_4
0173 #undef OPENSSL_NO_DEPRECATED_3_1
0174 #undef OPENSSL_NO_DEPRECATED_3_0
0175 #undef OPENSSL_NO_DEPRECATED_1_1_1
0176 #undef OPENSSL_NO_DEPRECATED_1_1_0
0177 #undef OPENSSL_NO_DEPRECATED_1_0_2
0178 #undef OPENSSL_NO_DEPRECATED_1_0_1
0179 #undef OPENSSL_NO_DEPRECATED_1_0_0
0180 #undef OPENSSL_NO_DEPRECATED_0_9_8
0181 
0182 #if OPENSSL_API_LEVEL >= 30600
0183 #ifndef OPENSSL_NO_DEPRECATED
0184 #define OSSL_DEPRECATEDIN_3_6 OSSL_DEPRECATED(3.6)
0185 #define OSSL_DEPRECATEDIN_3_6_FOR(msg) OSSL_DEPRECATED_FOR(3.6, msg)
0186 #else
0187 #define OPENSSL_NO_DEPRECATED_3_6
0188 #endif
0189 #else
0190 #define OSSL_DEPRECATEDIN_3_6
0191 #define OSSL_DEPRECATEDIN_3_6_FOR(msg)
0192 #endif
0193 #if OPENSSL_API_LEVEL >= 30500
0194 #ifndef OPENSSL_NO_DEPRECATED
0195 #define OSSL_DEPRECATEDIN_3_5 OSSL_DEPRECATED(3.5)
0196 #define OSSL_DEPRECATEDIN_3_5_FOR(msg) OSSL_DEPRECATED_FOR(3.5, msg)
0197 #else
0198 #define OPENSSL_NO_DEPRECATED_3_5
0199 #endif
0200 #else
0201 #define OSSL_DEPRECATEDIN_3_5
0202 #define OSSL_DEPRECATEDIN_3_5_FOR(msg)
0203 #endif
0204 #if OPENSSL_API_LEVEL >= 30400
0205 #ifndef OPENSSL_NO_DEPRECATED
0206 #define OSSL_DEPRECATEDIN_3_4 OSSL_DEPRECATED(3.4)
0207 #define OSSL_DEPRECATEDIN_3_4_FOR(msg) OSSL_DEPRECATED_FOR(3.4, msg)
0208 #else
0209 #define OPENSSL_NO_DEPRECATED_3_4
0210 #endif
0211 #else
0212 #define OSSL_DEPRECATEDIN_3_4
0213 #define OSSL_DEPRECATEDIN_3_4_FOR(msg)
0214 #endif
0215 #if OPENSSL_API_LEVEL >= 30100
0216 #ifndef OPENSSL_NO_DEPRECATED
0217 #define OSSL_DEPRECATEDIN_3_1 OSSL_DEPRECATED(3.1)
0218 #define OSSL_DEPRECATEDIN_3_1_FOR(msg) OSSL_DEPRECATED_FOR(3.1, msg)
0219 #else
0220 #define OPENSSL_NO_DEPRECATED_3_1
0221 #endif
0222 #else
0223 #define OSSL_DEPRECATEDIN_3_1
0224 #define OSSL_DEPRECATEDIN_3_1_FOR(msg)
0225 #endif
0226 #if OPENSSL_API_LEVEL >= 30000
0227 #ifndef OPENSSL_NO_DEPRECATED
0228 #define OSSL_DEPRECATEDIN_3_0 OSSL_DEPRECATED(3.0)
0229 #define OSSL_DEPRECATEDIN_3_0_FOR(msg) OSSL_DEPRECATED_FOR(3.0, msg)
0230 #else
0231 #define OPENSSL_NO_DEPRECATED_3_0
0232 #endif
0233 #else
0234 #define OSSL_DEPRECATEDIN_3_0
0235 #define OSSL_DEPRECATEDIN_3_0_FOR(msg)
0236 #endif
0237 #if OPENSSL_API_LEVEL >= 10101
0238 #ifndef OPENSSL_NO_DEPRECATED
0239 #define OSSL_DEPRECATEDIN_1_1_1 OSSL_DEPRECATED(1.1.1)
0240 #define OSSL_DEPRECATEDIN_1_1_1_FOR(msg) OSSL_DEPRECATED_FOR(1.1.1, msg)
0241 #else
0242 #define OPENSSL_NO_DEPRECATED_1_1_1
0243 #endif
0244 #else
0245 #define OSSL_DEPRECATEDIN_1_1_1
0246 #define OSSL_DEPRECATEDIN_1_1_1_FOR(msg)
0247 #endif
0248 #if OPENSSL_API_LEVEL >= 10100
0249 #ifndef OPENSSL_NO_DEPRECATED
0250 #define OSSL_DEPRECATEDIN_1_1_0 OSSL_DEPRECATED(1.1.0)
0251 #define OSSL_DEPRECATEDIN_1_1_0_FOR(msg) OSSL_DEPRECATED_FOR(1.1.0, msg)
0252 #else
0253 #define OPENSSL_NO_DEPRECATED_1_1_0
0254 #endif
0255 #else
0256 #define OSSL_DEPRECATEDIN_1_1_0
0257 #define OSSL_DEPRECATEDIN_1_1_0_FOR(msg)
0258 #endif
0259 #if OPENSSL_API_LEVEL >= 10002
0260 #ifndef OPENSSL_NO_DEPRECATED
0261 #define OSSL_DEPRECATEDIN_1_0_2 OSSL_DEPRECATED(1.0.2)
0262 #define OSSL_DEPRECATEDIN_1_0_2_FOR(msg) OSSL_DEPRECATED_FOR(1.0.2, msg)
0263 #else
0264 #define OPENSSL_NO_DEPRECATED_1_0_2
0265 #endif
0266 #else
0267 #define OSSL_DEPRECATEDIN_1_0_2
0268 #define OSSL_DEPRECATEDIN_1_0_2_FOR(msg)
0269 #endif
0270 #if OPENSSL_API_LEVEL >= 10001
0271 #ifndef OPENSSL_NO_DEPRECATED
0272 #define OSSL_DEPRECATEDIN_1_0_1 OSSL_DEPRECATED(1.0.1)
0273 #define OSSL_DEPRECATEDIN_1_0_1_FOR(msg) OSSL_DEPRECATED_FOR(1.0.1, msg)
0274 #else
0275 #define OPENSSL_NO_DEPRECATED_1_0_1
0276 #endif
0277 #else
0278 #define OSSL_DEPRECATEDIN_1_0_1
0279 #define OSSL_DEPRECATEDIN_1_0_1_FOR(msg)
0280 #endif
0281 #if OPENSSL_API_LEVEL >= 10000
0282 #ifndef OPENSSL_NO_DEPRECATED
0283 #define OSSL_DEPRECATEDIN_1_0_0 OSSL_DEPRECATED(1.0.0)
0284 #define OSSL_DEPRECATEDIN_1_0_0_FOR(msg) OSSL_DEPRECATED_FOR(1.0.0, msg)
0285 #else
0286 #define OPENSSL_NO_DEPRECATED_1_0_0
0287 #endif
0288 #else
0289 #define OSSL_DEPRECATEDIN_1_0_0
0290 #define OSSL_DEPRECATEDIN_1_0_0_FOR(msg)
0291 #endif
0292 #if OPENSSL_API_LEVEL >= 908
0293 #ifndef OPENSSL_NO_DEPRECATED
0294 #define OSSL_DEPRECATEDIN_0_9_8 OSSL_DEPRECATED(0.9.8)
0295 #define OSSL_DEPRECATEDIN_0_9_8_FOR(msg) OSSL_DEPRECATED_FOR(0.9.8, msg)
0296 #else
0297 #define OPENSSL_NO_DEPRECATED_0_9_8
0298 #endif
0299 #else
0300 #define OSSL_DEPRECATEDIN_0_9_8
0301 #define OSSL_DEPRECATEDIN_0_9_8_FOR(msg)
0302 #endif
0303 
0304 /*
0305  * Make our own variants of __FILE__ and __LINE__, depending on configuration
0306  */
0307 
0308 #ifndef OPENSSL_FILE
0309 #ifdef OPENSSL_NO_FILENAMES
0310 #define OPENSSL_FILE ""
0311 #define OPENSSL_LINE 0
0312 #else
0313 #define OPENSSL_FILE __FILE__
0314 #define OPENSSL_LINE __LINE__
0315 #endif
0316 #endif
0317 
0318 /*
0319  * __func__ was standardized in C99, so for any compiler that claims
0320  * to implement that language level or newer, we assume we can safely
0321  * use that symbol.
0322  *
0323  * GNU C also provides __FUNCTION__ since version 2, which predates
0324  * C99.  We can, however, only use this if __STDC_VERSION__ exists,
0325  * as it's otherwise not allowed according to ISO C standards (C90).
0326  * (compiling with GNU C's -pedantic tells us so)
0327  *
0328  * If none of the above applies, we check if the compiler is MSVC,
0329  * and use __FUNCTION__ if that's the case.
0330  */
0331 #ifndef OPENSSL_FUNC
0332 #if defined(__STDC_VERSION__)
0333 #if __STDC_VERSION__ >= 199901L
0334 #define OPENSSL_FUNC __func__
0335 #elif defined(__GNUC__) && __GNUC__ >= 2
0336 #define OPENSSL_FUNC __FUNCTION__
0337 #endif
0338 #elif defined(_MSC_VER)
0339 #define OPENSSL_FUNC __FUNCTION__
0340 #endif
0341 /*
0342  * If all these possibilities are exhausted, we give up and use a
0343  * static string.
0344  */
0345 #ifndef OPENSSL_FUNC
0346 #define OPENSSL_FUNC "(unknown function)"
0347 #endif
0348 #endif
0349 
0350 #ifndef OSSL_CRYPTO_ALLOC
0351 #if defined(__GNUC__)
0352 #define OSSL_CRYPTO_ALLOC __attribute__((__malloc__))
0353 #elif defined(_MSC_VER)
0354 #define OSSL_CRYPTO_ALLOC __declspec(restrict)
0355 #else
0356 #define OSSL_CRYPTO_ALLOC
0357 #endif
0358 #endif
0359 
0360 #endif /* OPENSSL_MACROS_H */