Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1 | /* ==================================================================== |
| 2 | * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright |
Adam Langley | 428fb3a | 2018-07-09 17:03:57 -0700 | [diff] [blame] | 9 | * notice, this list of conditions and the following disclaimer. |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 10 | * |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in |
| 13 | * the documentation and/or other materials provided with the |
| 14 | * distribution. |
| 15 | * |
| 16 | * 3. All advertising materials mentioning features or use of this |
| 17 | * software must display the following acknowledgment: |
| 18 | * "This product includes software developed by the OpenSSL Project |
| 19 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" |
| 20 | * |
| 21 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to |
| 22 | * endorse or promote products derived from this software without |
| 23 | * prior written permission. For written permission, please contact |
| 24 | * openssl-core@openssl.org. |
| 25 | * |
| 26 | * 5. Products derived from this software may not be called "OpenSSL" |
| 27 | * nor may "OpenSSL" appear in their names without prior written |
| 28 | * permission of the OpenSSL Project. |
| 29 | * |
| 30 | * 6. Redistributions of any form whatsoever must retain the following |
| 31 | * acknowledgment: |
| 32 | * "This product includes software developed by the OpenSSL Project |
| 33 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" |
| 34 | * |
| 35 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY |
| 36 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 37 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 38 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR |
| 39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 41 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 42 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 43 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 44 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 45 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 46 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 47 | * ==================================================================== |
| 48 | * |
| 49 | * This product includes cryptographic software written by Eric Young |
| 50 | * (eay@cryptsoft.com). This product includes software written by Tim |
| 51 | * Hudson (tjh@cryptsoft.com). */ |
| 52 | |
| 53 | #ifndef OPENSSL_HEADER_BASE_H |
| 54 | #define OPENSSL_HEADER_BASE_H |
| 55 | |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 56 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 57 | // This file should be the first included by all BoringSSL headers. |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 58 | |
Brian Smith | 054e682 | 2015-03-27 21:12:01 -1000 | [diff] [blame] | 59 | #include <stddef.h> |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 60 | #include <stdint.h> |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 61 | #include <sys/types.h> |
| 62 | |
David Benjamin | 8404bdb | 2016-10-10 14:41:44 -0400 | [diff] [blame] | 63 | #if defined(__MINGW32__) |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 64 | // stdio.h is needed on MinGW for __MINGW_PRINTF_FORMAT. |
David Benjamin | 8404bdb | 2016-10-10 14:41:44 -0400 | [diff] [blame] | 65 | #include <stdio.h> |
| 66 | #endif |
| 67 | |
David Benjamin | 7c3ce51 | 2018-09-30 18:50:26 -0500 | [diff] [blame] | 68 | #if defined(__APPLE__) |
| 69 | #include <TargetConditionals.h> |
| 70 | #endif |
| 71 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 72 | // Include a BoringSSL-only header so consumers including this header without |
| 73 | // setting up include paths do not accidentally pick up the system |
| 74 | // opensslconf.h. |
David Benjamin | d403be9 | 2017-04-12 16:28:25 -0400 | [diff] [blame] | 75 | #include <openssl/is_boringssl.h> |
David Benjamin | e593fed | 2016-02-25 11:39:59 -0500 | [diff] [blame] | 76 | #include <openssl/opensslconf.h> |
David Benjamin | a905bbb | 2023-06-12 18:11:13 -0400 | [diff] [blame] | 77 | #include <openssl/target.h> // IWYU pragma: export |
Piotr Sikora | 987b8f1 | 2014-07-14 19:21:44 -0700 | [diff] [blame] | 78 | |
Joshua Liebow-Feeser | 8c7c635 | 2018-08-26 18:53:36 -0700 | [diff] [blame] | 79 | #if defined(BORINGSSL_PREFIX) |
| 80 | #include <boringssl_prefix_symbols.h> |
| 81 | #endif |
| 82 | |
Adam Langley | b2cb0ec | 2014-09-02 14:28:49 -0700 | [diff] [blame] | 83 | #if defined(__cplusplus) |
| 84 | extern "C" { |
| 85 | #endif |
| 86 | |
| 87 | |
Adam Langley | 30eda1d | 2014-06-24 11:15:12 -0700 | [diff] [blame] | 88 | #if defined(__APPLE__) |
David Benjamin | 40633ac | 2019-08-30 16:00:33 -0400 | [diff] [blame] | 89 | // Note |TARGET_OS_MAC| is set for all Apple OS variants. |TARGET_OS_OSX| |
| 90 | // targets macOS specifically. |
| 91 | #if defined(TARGET_OS_OSX) && TARGET_OS_OSX |
| 92 | #define OPENSSL_MACOS |
| 93 | #endif |
David Benjamin | 13fd627 | 2018-09-28 10:12:35 -0500 | [diff] [blame] | 94 | #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE |
| 95 | #define OPENSSL_IOS |
| 96 | #endif |
Adam Langley | 30eda1d | 2014-06-24 11:15:12 -0700 | [diff] [blame] | 97 | #endif |
| 98 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 99 | #define OPENSSL_IS_BORINGSSL |
David Benjamin | 49e9f67 | 2020-09-16 12:29:13 -0400 | [diff] [blame] | 100 | #define OPENSSL_VERSION_NUMBER 0x1010107f |
Matt Braithwaite | 6454a4c | 2015-07-31 15:57:07 -0700 | [diff] [blame] | 101 | #define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 102 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 103 | // BORINGSSL_API_VERSION is a positive integer that increments as BoringSSL |
| 104 | // changes over time. The value itself is not meaningful. It will be incremented |
| 105 | // whenever is convenient to coordinate an API change with consumers. This will |
| 106 | // not denote any special point in development. |
| 107 | // |
| 108 | // A consumer may use this symbol in the preprocessor to temporarily build |
| 109 | // against multiple revisions of BoringSSL at the same time. It is not |
| 110 | // recommended to do so for longer than is necessary. |
David Benjamin | 0ffd365 | 2023-07-23 13:18:31 -0700 | [diff] [blame] | 111 | #define BORINGSSL_API_VERSION 25 |
David Benjamin | 9d908ba | 2016-05-05 18:54:33 -0400 | [diff] [blame] | 112 | |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 113 | #if defined(BORINGSSL_SHARED_LIBRARY) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 114 | |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 115 | #if defined(OPENSSL_WINDOWS) |
| 116 | |
| 117 | #if defined(BORINGSSL_IMPLEMENTATION) |
| 118 | #define OPENSSL_EXPORT __declspec(dllexport) |
| 119 | #else |
| 120 | #define OPENSSL_EXPORT __declspec(dllimport) |
| 121 | #endif |
| 122 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 123 | #else // defined(OPENSSL_WINDOWS) |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 124 | |
| 125 | #if defined(BORINGSSL_IMPLEMENTATION) |
| 126 | #define OPENSSL_EXPORT __attribute__((visibility("default"))) |
| 127 | #else |
| 128 | #define OPENSSL_EXPORT |
| 129 | #endif |
| 130 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 131 | #endif // defined(OPENSSL_WINDOWS) |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 132 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 133 | #else // defined(BORINGSSL_SHARED_LIBRARY) |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 134 | |
| 135 | #define OPENSSL_EXPORT |
| 136 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 137 | #endif // defined(BORINGSSL_SHARED_LIBRARY) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 138 | |
Bob Beck | ac6d558 | 2023-03-28 14:23:03 -0600 | [diff] [blame] | 139 | #if defined(_MSC_VER) |
| 140 | |
| 141 | // OPENSSL_DEPRECATED is used to mark a function as deprecated. Use |
| 142 | // of any functions so marked in caller code will produce a warning. |
| 143 | // OPENSSL_BEGIN_ALLOW_DEPRECATED and OPENSSL_END_ALLOW_DEPRECATED |
| 144 | // can be used to suppress the warning in regions of caller code. |
| 145 | #define OPENSSL_DEPRECATED __declspec(deprecated) |
| 146 | #define OPENSSL_BEGIN_ALLOW_DEPRECATED \ |
| 147 | __pragma(warning(push)) __pragma(warning(disable : 4996)) |
| 148 | #define OPENSSL_END_ALLOW_DEPRECATED __pragma(warning(pop)) |
| 149 | |
| 150 | #elif defined(__GNUC__) || defined(__clang__) |
| 151 | |
| 152 | #define OPENSSL_DEPRECATED __attribute__((__deprecated__)) |
| 153 | #define OPENSSL_BEGIN_ALLOW_DEPRECATED \ |
| 154 | _Pragma("GCC diagnostic push") \ |
| 155 | _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") |
| 156 | #define OPENSSL_END_ALLOW_DEPRECATED _Pragma("GCC diagnostic pop") |
| 157 | |
| 158 | #else |
| 159 | |
| 160 | #define OPENSSL_DEPRECATED |
| 161 | #define OPENSSL_BEGIN_ALLOW_DEPRECATED |
| 162 | #define OPENSSL_END_ALLOW_DEPRECATED |
| 163 | |
| 164 | #endif |
| 165 | |
Brian Smith | 061332f | 2016-01-17 09:30:42 -1000 | [diff] [blame] | 166 | |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 167 | #if defined(__GNUC__) || defined(__clang__) |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 168 | // MinGW has two different printf implementations. Ensure the format macro |
| 169 | // matches the selected implementation. See |
| 170 | // https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/. |
David Benjamin | 8404bdb | 2016-10-10 14:41:44 -0400 | [diff] [blame] | 171 | #if defined(__MINGW_PRINTF_FORMAT) |
Brian Smith | 061332f | 2016-01-17 09:30:42 -1000 | [diff] [blame] | 172 | #define OPENSSL_PRINTF_FORMAT_FUNC(string_index, first_to_check) \ |
David Benjamin | 8404bdb | 2016-10-10 14:41:44 -0400 | [diff] [blame] | 173 | __attribute__( \ |
| 174 | (__format__(__MINGW_PRINTF_FORMAT, string_index, first_to_check))) |
| 175 | #else |
| 176 | #define OPENSSL_PRINTF_FORMAT_FUNC(string_index, first_to_check) \ |
| 177 | __attribute__((__format__(__printf__, string_index, first_to_check))) |
| 178 | #endif |
Brian Smith | 061332f | 2016-01-17 09:30:42 -1000 | [diff] [blame] | 179 | #else |
| 180 | #define OPENSSL_PRINTF_FORMAT_FUNC(string_index, first_to_check) |
| 181 | #endif |
| 182 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 183 | // OPENSSL_MSVC_PRAGMA emits a pragma on MSVC and nothing on other compilers. |
David Benjamin | a353cdb | 2016-06-09 16:48:33 -0400 | [diff] [blame] | 184 | #if defined(_MSC_VER) |
| 185 | #define OPENSSL_MSVC_PRAGMA(arg) __pragma(arg) |
| 186 | #else |
| 187 | #define OPENSSL_MSVC_PRAGMA(arg) |
| 188 | #endif |
| 189 | |
David Benjamin | 806e18c | 2017-05-24 18:04:18 -0400 | [diff] [blame] | 190 | #if defined(__GNUC__) || defined(__clang__) |
David Benjamin | 01f8a8c | 2017-04-15 18:12:55 -0400 | [diff] [blame] | 191 | #define OPENSSL_UNUSED __attribute__((unused)) |
| 192 | #else |
| 193 | #define OPENSSL_UNUSED |
| 194 | #endif |
| 195 | |
David Benjamin | a943613 | 2018-09-23 18:36:01 -0500 | [diff] [blame] | 196 | // C and C++ handle inline functions differently. In C++, an inline function is |
| 197 | // defined in just the header file, potentially emitted in multiple compilation |
| 198 | // units (in cases the compiler did not inline), but each copy must be identical |
| 199 | // to satsify ODR. In C, a non-static inline must be manually emitted in exactly |
| 200 | // one compilation unit with a separate extern inline declaration. |
| 201 | // |
| 202 | // In both languages, exported inline functions referencing file-local symbols |
| 203 | // are problematic. C forbids this altogether (though GCC and Clang seem not to |
| 204 | // enforce it). It works in C++, but ODR requires the definitions be identical, |
| 205 | // including all names in the definitions resolving to the "same entity". In |
| 206 | // practice, this is unlikely to be a problem, but an inline function that |
| 207 | // returns a pointer to a file-local symbol |
| 208 | // could compile oddly. |
| 209 | // |
| 210 | // Historically, we used static inline in headers. However, to satisfy ODR, use |
| 211 | // plain inline in C++, to allow inline consumer functions to call our header |
| 212 | // functions. Plain inline would also work better with C99 inline, but that is |
| 213 | // not used much in practice, extern inline is tedious, and there are conflicts |
| 214 | // with the old gnu89 model: |
| 215 | // https://stackoverflow.com/questions/216510/extern-inline |
| 216 | #if defined(__cplusplus) |
| 217 | #define OPENSSL_INLINE inline |
| 218 | #else |
| 219 | // Add OPENSSL_UNUSED so that, should an inline function be emitted via macro |
| 220 | // (e.g. a |STACK_OF(T)| implementation) in a source file without tripping |
| 221 | // clang's -Wunused-function. |
| 222 | #define OPENSSL_INLINE static inline OPENSSL_UNUSED |
| 223 | #endif |
| 224 | |
Adam Langley | 7540cc2 | 2019-04-18 09:56:13 -0700 | [diff] [blame] | 225 | #if defined(__cplusplus) |
| 226 | // enums can be predeclared, but only in C++ and only if given an explicit type. |
| 227 | // C doesn't support setting an explicit type for enums thus a #define is used |
| 228 | // to do this only for C++. However, the ABI type between C and C++ need to have |
| 229 | // equal sizes, which is confirmed in a unittest. |
| 230 | #define BORINGSSL_ENUM_INT : int |
David Benjamin | 6477012 | 2019-05-04 11:00:04 -0500 | [diff] [blame] | 231 | enum ssl_early_data_reason_t BORINGSSL_ENUM_INT; |
Adam Langley | 7540cc2 | 2019-04-18 09:56:13 -0700 | [diff] [blame] | 232 | enum ssl_encryption_level_t BORINGSSL_ENUM_INT; |
David Benjamin | 6477012 | 2019-05-04 11:00:04 -0500 | [diff] [blame] | 233 | enum ssl_private_key_result_t BORINGSSL_ENUM_INT; |
Adam Langley | 7540cc2 | 2019-04-18 09:56:13 -0700 | [diff] [blame] | 234 | enum ssl_renegotiate_mode_t BORINGSSL_ENUM_INT; |
| 235 | enum ssl_select_cert_result_t BORINGSSL_ENUM_INT; |
| 236 | enum ssl_select_cert_result_t BORINGSSL_ENUM_INT; |
David Benjamin | 6477012 | 2019-05-04 11:00:04 -0500 | [diff] [blame] | 237 | enum ssl_ticket_aead_result_t BORINGSSL_ENUM_INT; |
| 238 | enum ssl_verify_result_t BORINGSSL_ENUM_INT; |
Adam Langley | 7540cc2 | 2019-04-18 09:56:13 -0700 | [diff] [blame] | 239 | #else |
| 240 | #define BORINGSSL_ENUM_INT |
| 241 | #endif |
| 242 | |
David Benjamin | dd81bf7 | 2022-10-18 21:41:30 -0400 | [diff] [blame] | 243 | // ossl_ssize_t is a signed type which is large enough to fit the size of any |
| 244 | // valid memory allocation. We prefer using |size_t|, but sometimes we need a |
| 245 | // signed type for OpenSSL API compatibility. This type can be used in such |
| 246 | // cases to avoid overflow. |
| 247 | // |
| 248 | // Not all |size_t| values fit in |ossl_ssize_t|, but all |size_t| values that |
| 249 | // are sizes of or indices into C objects, can be converted without overflow. |
| 250 | typedef ptrdiff_t ossl_ssize_t; |
| 251 | |
David Benjamin | a1dffbf | 2022-10-25 16:29:43 -0400 | [diff] [blame] | 252 | // CBS_ASN1_TAG is the type used by |CBS| and |CBB| for ASN.1 tags. See that |
| 253 | // header for details. This type is defined in base.h as a forward declaration. |
| 254 | typedef uint32_t CBS_ASN1_TAG; |
| 255 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 256 | // CRYPTO_THREADID is a dummy value. |
David Benjamin | f0df86a | 2015-04-20 11:32:12 -0400 | [diff] [blame] | 257 | typedef int CRYPTO_THREADID; |
| 258 | |
David Benjamin | a406ad7 | 2021-10-04 19:21:01 -0400 | [diff] [blame] | 259 | // An |ASN1_NULL| is an opaque type. asn1.h represents the ASN.1 NULL value as |
| 260 | // an opaque, non-NULL |ASN1_NULL*| pointer. |
| 261 | typedef struct asn1_null_st ASN1_NULL; |
| 262 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 263 | typedef int ASN1_BOOLEAN; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 264 | typedef struct ASN1_ITEM_st ASN1_ITEM; |
| 265 | typedef struct asn1_object_st ASN1_OBJECT; |
| 266 | typedef struct asn1_pctx_st ASN1_PCTX; |
| 267 | typedef struct asn1_string_st ASN1_BIT_STRING; |
| 268 | typedef struct asn1_string_st ASN1_BMPSTRING; |
| 269 | typedef struct asn1_string_st ASN1_ENUMERATED; |
| 270 | typedef struct asn1_string_st ASN1_GENERALIZEDTIME; |
| 271 | typedef struct asn1_string_st ASN1_GENERALSTRING; |
| 272 | typedef struct asn1_string_st ASN1_IA5STRING; |
| 273 | typedef struct asn1_string_st ASN1_INTEGER; |
| 274 | typedef struct asn1_string_st ASN1_OCTET_STRING; |
| 275 | typedef struct asn1_string_st ASN1_PRINTABLESTRING; |
| 276 | typedef struct asn1_string_st ASN1_STRING; |
| 277 | typedef struct asn1_string_st ASN1_T61STRING; |
| 278 | typedef struct asn1_string_st ASN1_TIME; |
| 279 | typedef struct asn1_string_st ASN1_UNIVERSALSTRING; |
| 280 | typedef struct asn1_string_st ASN1_UTCTIME; |
| 281 | typedef struct asn1_string_st ASN1_UTF8STRING; |
| 282 | typedef struct asn1_string_st ASN1_VISIBLESTRING; |
Matt Braithwaite | d17d74d | 2016-08-17 20:10:28 -0700 | [diff] [blame] | 283 | typedef struct asn1_type_st ASN1_TYPE; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 284 | typedef struct AUTHORITY_KEYID_st AUTHORITY_KEYID; |
Matt Braithwaite | b9afd51 | 2016-07-19 12:41:35 -0700 | [diff] [blame] | 285 | typedef struct BASIC_CONSTRAINTS_st BASIC_CONSTRAINTS; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 286 | typedef struct DIST_POINT_st DIST_POINT; |
Matt Braithwaite | b9afd51 | 2016-07-19 12:41:35 -0700 | [diff] [blame] | 287 | typedef struct DSA_SIG_st DSA_SIG; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 288 | typedef struct ISSUING_DIST_POINT_st ISSUING_DIST_POINT; |
| 289 | typedef struct NAME_CONSTRAINTS_st NAME_CONSTRAINTS; |
Matt Braithwaite | 16f774f | 2015-08-03 14:14:14 -0700 | [diff] [blame] | 290 | typedef struct Netscape_spkac_st NETSCAPE_SPKAC; |
| 291 | typedef struct Netscape_spki_st NETSCAPE_SPKI; |
Adam Langley | ff452c1 | 2016-03-08 14:17:02 -0800 | [diff] [blame] | 292 | typedef struct RIPEMD160state_st RIPEMD160_CTX; |
Matt Braithwaite | b9afd51 | 2016-07-19 12:41:35 -0700 | [diff] [blame] | 293 | typedef struct X509_VERIFY_PARAM_st X509_VERIFY_PARAM; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 294 | typedef struct X509_algor_st X509_ALGOR; |
| 295 | typedef struct X509_crl_st X509_CRL; |
Matt Braithwaite | 16f774f | 2015-08-03 14:14:14 -0700 | [diff] [blame] | 296 | typedef struct X509_extension_st X509_EXTENSION; |
| 297 | typedef struct X509_info_st X509_INFO; |
| 298 | typedef struct X509_name_entry_st X509_NAME_ENTRY; |
| 299 | typedef struct X509_name_st X509_NAME; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 300 | typedef struct X509_pubkey_st X509_PUBKEY; |
Matt Braithwaite | 16f774f | 2015-08-03 14:14:14 -0700 | [diff] [blame] | 301 | typedef struct X509_req_st X509_REQ; |
| 302 | typedef struct X509_sig_st X509_SIG; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 303 | typedef struct bignum_ctx BN_CTX; |
| 304 | typedef struct bignum_st BIGNUM; |
| 305 | typedef struct bio_method_st BIO_METHOD; |
| 306 | typedef struct bio_st BIO; |
Adam Langley | e133345 | 2021-01-21 11:56:52 -0800 | [diff] [blame] | 307 | typedef struct blake2b_state_st BLAKE2B_CTX; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 308 | typedef struct bn_gencb_st BN_GENCB; |
| 309 | typedef struct bn_mont_ctx_st BN_MONT_CTX; |
| 310 | typedef struct buf_mem_st BUF_MEM; |
| 311 | typedef struct cbb_st CBB; |
| 312 | typedef struct cbs_st CBS; |
Adam Langley | 0d107e1 | 2015-05-05 16:36:32 -0700 | [diff] [blame] | 313 | typedef struct cmac_ctx_st CMAC_CTX; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 314 | typedef struct conf_st CONF; |
Brian Smith | 054e682 | 2015-03-27 21:12:01 -1000 | [diff] [blame] | 315 | typedef struct conf_value_st CONF_VALUE; |
Adam Langley | 9ef99d5 | 2016-10-25 17:33:49 -0700 | [diff] [blame] | 316 | typedef struct crypto_buffer_pool_st CRYPTO_BUFFER_POOL; |
| 317 | typedef struct crypto_buffer_st CRYPTO_BUFFER; |
Adam Langley | 24c0186 | 2022-05-06 16:14:47 -0700 | [diff] [blame] | 318 | typedef struct ctr_drbg_state_st CTR_DRBG_STATE; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 319 | typedef struct dh_st DH; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 320 | typedef struct dsa_st DSA; |
Matt Braithwaite | b9afd51 | 2016-07-19 12:41:35 -0700 | [diff] [blame] | 321 | typedef struct ec_group_st EC_GROUP; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 322 | typedef struct ec_key_st EC_KEY; |
Matt Braithwaite | b9afd51 | 2016-07-19 12:41:35 -0700 | [diff] [blame] | 323 | typedef struct ec_point_st EC_POINT; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 324 | typedef struct ecdsa_method_st ECDSA_METHOD; |
| 325 | typedef struct ecdsa_sig_st ECDSA_SIG; |
| 326 | typedef struct engine_st ENGINE; |
| 327 | typedef struct env_md_ctx_st EVP_MD_CTX; |
| 328 | typedef struct env_md_st EVP_MD; |
Adam Langley | fd772a5 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 329 | typedef struct evp_aead_st EVP_AEAD; |
Adam Langley | ce2a353 | 2022-05-13 11:00:24 -0700 | [diff] [blame] | 330 | typedef struct evp_aead_ctx_st EVP_AEAD_CTX; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 331 | typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX; |
| 332 | typedef struct evp_cipher_st EVP_CIPHER; |
David Benjamin | 97a3393 | 2015-09-19 15:17:34 -0400 | [diff] [blame] | 333 | typedef struct evp_encode_ctx_st EVP_ENCODE_CTX; |
David Benjamin | 070a6c3 | 2021-05-05 15:39:27 -0400 | [diff] [blame] | 334 | typedef struct evp_hpke_aead_st EVP_HPKE_AEAD; |
| 335 | typedef struct evp_hpke_ctx_st EVP_HPKE_CTX; |
| 336 | typedef struct evp_hpke_kdf_st EVP_HPKE_KDF; |
| 337 | typedef struct evp_hpke_kem_st EVP_HPKE_KEM; |
| 338 | typedef struct evp_hpke_key_st EVP_HPKE_KEY; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 339 | typedef struct evp_pkey_ctx_st EVP_PKEY_CTX; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 340 | typedef struct evp_pkey_st EVP_PKEY; |
| 341 | typedef struct hmac_ctx_st HMAC_CTX; |
Adam Langley | c9eb7ea | 2014-08-22 11:06:14 -0700 | [diff] [blame] | 342 | typedef struct md4_state_st MD4_CTX; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 343 | typedef struct md5_state_st MD5_CTX; |
David Benjamin | 81f030b | 2016-08-12 14:48:19 -0400 | [diff] [blame] | 344 | typedef struct ossl_init_settings_st OPENSSL_INIT_SETTINGS; |
Adam Langley | 5127db3 | 2014-09-19 10:49:56 -0700 | [diff] [blame] | 345 | typedef struct pkcs12_st PKCS12; |
Matt Braithwaite | 16f774f | 2015-08-03 14:14:14 -0700 | [diff] [blame] | 346 | typedef struct pkcs8_priv_key_info_st PKCS8_PRIV_KEY_INFO; |
| 347 | typedef struct private_key_st X509_PKEY; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 348 | typedef struct rand_meth_st RAND_METHOD; |
Adam Langley | 3f92d21 | 2015-02-20 15:32:52 -0800 | [diff] [blame] | 349 | typedef struct rc4_key_st RC4_KEY; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 350 | typedef struct rsa_meth_st RSA_METHOD; |
Shelley Vohr | 0446b59 | 2021-09-09 11:25:24 +0200 | [diff] [blame] | 351 | typedef struct rsa_pss_params_st RSA_PSS_PARAMS; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 352 | typedef struct rsa_st RSA; |
| 353 | typedef struct sha256_state_st SHA256_CTX; |
| 354 | typedef struct sha512_state_st SHA512_CTX; |
| 355 | typedef struct sha_state_st SHA_CTX; |
Arnar Birgisson | f27459e | 2016-02-09 18:09:00 -0800 | [diff] [blame] | 356 | typedef struct spake2_ctx_st SPAKE2_CTX; |
David Benjamin | cfd65b6 | 2015-09-14 01:54:44 -0400 | [diff] [blame] | 357 | typedef struct srtp_protection_profile_st SRTP_PROTECTION_PROFILE; |
David Benjamin | 79c117a | 2015-09-13 13:53:19 -0400 | [diff] [blame] | 358 | typedef struct ssl_cipher_st SSL_CIPHER; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 359 | typedef struct ssl_ctx_st SSL_CTX; |
David Benjamin | 45c8be9 | 2021-10-07 16:15:01 -0400 | [diff] [blame] | 360 | typedef struct ssl_early_callback_ctx SSL_CLIENT_HELLO; |
David Benjamin | c3b373b | 2021-06-06 13:04:26 -0400 | [diff] [blame] | 361 | typedef struct ssl_ech_keys_st SSL_ECH_KEYS; |
David Benjamin | e39ac8f | 2017-07-20 12:22:21 -0400 | [diff] [blame] | 362 | typedef struct ssl_method_st SSL_METHOD; |
Adam Langley | d04ca95 | 2017-02-28 11:26:51 -0800 | [diff] [blame] | 363 | typedef struct ssl_private_key_method_st SSL_PRIVATE_KEY_METHOD; |
Steven Valdez | c8e0f90 | 2018-07-14 11:23:01 -0400 | [diff] [blame] | 364 | typedef struct ssl_quic_method_st SSL_QUIC_METHOD; |
David Benjamin | a6b8cdf | 2015-09-13 14:07:33 -0400 | [diff] [blame] | 365 | typedef struct ssl_session_st SSL_SESSION; |
David Benjamin | e39ac8f | 2017-07-20 12:22:21 -0400 | [diff] [blame] | 366 | typedef struct ssl_st SSL; |
Adam Langley | 4c341d0 | 2017-03-08 19:33:21 -0800 | [diff] [blame] | 367 | typedef struct ssl_ticket_aead_method_st SSL_TICKET_AEAD_METHOD; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 368 | typedef struct st_ERR_FNS ERR_FNS; |
Steven Valdez | 538a124 | 2019-12-16 12:12:31 -0500 | [diff] [blame] | 369 | typedef struct trust_token_st TRUST_TOKEN; |
| 370 | typedef struct trust_token_client_st TRUST_TOKEN_CLIENT; |
| 371 | typedef struct trust_token_issuer_st TRUST_TOKEN_ISSUER; |
David Benjamin | 239634d | 2020-04-29 11:17:51 -0400 | [diff] [blame] | 372 | typedef struct trust_token_method_st TRUST_TOKEN_METHOD; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 373 | typedef struct v3_ext_ctx X509V3_CTX; |
Matt Braithwaite | 16f774f | 2015-08-03 14:14:14 -0700 | [diff] [blame] | 374 | typedef struct x509_attributes_st X509_ATTRIBUTE; |
Matt Braithwaite | d17d74d | 2016-08-17 20:10:28 -0700 | [diff] [blame] | 375 | typedef struct x509_lookup_st X509_LOOKUP; |
David Benjamin | dddb60e | 2021-08-11 01:23:09 -0400 | [diff] [blame] | 376 | typedef struct x509_lookup_method_st X509_LOOKUP_METHOD; |
| 377 | typedef struct x509_object_st X509_OBJECT; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 378 | typedef struct x509_revoked_st X509_REVOKED; |
| 379 | typedef struct x509_st X509; |
| 380 | typedef struct x509_store_ctx_st X509_STORE_CTX; |
| 381 | typedef struct x509_store_st X509_STORE; |
Matt Braithwaite | 16f774f | 2015-08-03 14:14:14 -0700 | [diff] [blame] | 382 | typedef struct x509_trust_st X509_TRUST; |
| 383 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 384 | typedef void *OPENSSL_BLOCK; |
| 385 | |
| 386 | |
Adam Langley | b2cb0ec | 2014-09-02 14:28:49 -0700 | [diff] [blame] | 387 | #if defined(__cplusplus) |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 388 | } // extern C |
David Benjamin | ebb4a37 | 2017-07-20 12:50:11 -0400 | [diff] [blame] | 389 | #elif !defined(BORINGSSL_NO_CXX) |
| 390 | #define BORINGSSL_NO_CXX |
| 391 | #endif |
Matt Braithwaite | d17d74d | 2016-08-17 20:10:28 -0700 | [diff] [blame] | 392 | |
Joshua Liebow-Feeser | 8c7c635 | 2018-08-26 18:53:36 -0700 | [diff] [blame] | 393 | #if defined(BORINGSSL_PREFIX) |
| 394 | #define BSSL_NAMESPACE_BEGIN \ |
| 395 | namespace bssl { \ |
| 396 | inline namespace BORINGSSL_PREFIX { |
| 397 | #define BSSL_NAMESPACE_END \ |
| 398 | } \ |
| 399 | } |
| 400 | #else |
| 401 | #define BSSL_NAMESPACE_BEGIN namespace bssl { |
| 402 | #define BSSL_NAMESPACE_END } |
| 403 | #endif |
| 404 | |
David Benjamin | 689019f | 2018-09-11 01:18:50 -0500 | [diff] [blame] | 405 | // MSVC doesn't set __cplusplus to 201103 to indicate C++11 support (see |
| 406 | // https://connect.microsoft.com/VisualStudio/feedback/details/763051/a-value-of-predefined-macro-cplusplus-is-still-199711l) |
| 407 | // so MSVC is just assumed to support C++11. |
| 408 | #if !defined(BORINGSSL_NO_CXX) && __cplusplus < 201103L && !defined(_MSC_VER) |
| 409 | #define BORINGSSL_NO_CXX |
| 410 | #endif |
| 411 | |
| 412 | #if !defined(BORINGSSL_NO_CXX) |
| 413 | |
David Benjamin | 3e5619d | 2016-09-07 17:28:59 -0400 | [diff] [blame] | 414 | extern "C++" { |
| 415 | |
| 416 | #include <memory> |
| 417 | |
| 418 | // STLPort, used by some Android consumers, not have std::unique_ptr. |
| 419 | #if defined(_STLPORT_VERSION) |
| 420 | #define BORINGSSL_NO_CXX |
| 421 | #endif |
| 422 | |
| 423 | } // extern C++ |
| 424 | #endif // !BORINGSSL_NO_CXX |
| 425 | |
David Benjamin | f0e935d | 2016-09-06 18:10:19 -0400 | [diff] [blame] | 426 | #if defined(BORINGSSL_NO_CXX) |
Matt Braithwaite | d17d74d | 2016-08-17 20:10:28 -0700 | [diff] [blame] | 427 | |
| 428 | #define BORINGSSL_MAKE_DELETER(type, deleter) |
Adam Langley | 428fb3a | 2018-07-09 17:03:57 -0700 | [diff] [blame] | 429 | #define BORINGSSL_MAKE_UP_REF(type, up_ref_func) |
Matt Braithwaite | d17d74d | 2016-08-17 20:10:28 -0700 | [diff] [blame] | 430 | |
| 431 | #else |
| 432 | |
David Benjamin | f0e935d | 2016-09-06 18:10:19 -0400 | [diff] [blame] | 433 | extern "C++" { |
| 434 | |
Joshua Liebow-Feeser | 8c7c635 | 2018-08-26 18:53:36 -0700 | [diff] [blame] | 435 | BSSL_NAMESPACE_BEGIN |
Matt Braithwaite | d17d74d | 2016-08-17 20:10:28 -0700 | [diff] [blame] | 436 | |
| 437 | namespace internal { |
| 438 | |
David Benjamin | cfc11c2 | 2017-07-18 22:45:18 -0400 | [diff] [blame] | 439 | // The Enable parameter is ignored and only exists so specializations can use |
| 440 | // SFINAE. |
| 441 | template <typename T, typename Enable = void> |
David Benjamin | 4709203 | 2016-09-09 14:54:10 -0400 | [diff] [blame] | 442 | struct DeleterImpl {}; |
| 443 | |
David Benjamin | 4709203 | 2016-09-09 14:54:10 -0400 | [diff] [blame] | 444 | struct Deleter { |
David Benjamin | 971b330 | 2023-01-25 15:59:39 -0500 | [diff] [blame] | 445 | template <typename T> |
David Benjamin | 4709203 | 2016-09-09 14:54:10 -0400 | [diff] [blame] | 446 | void operator()(T *ptr) { |
| 447 | // Rather than specialize Deleter for each type, we specialize |
| 448 | // DeleterImpl. This allows bssl::UniquePtr<T> to be used while only |
| 449 | // including base.h as long as the destructor is not emitted. This matches |
| 450 | // std::unique_ptr's behavior on forward-declared types. |
| 451 | // |
| 452 | // DeleterImpl itself is specialized in the corresponding module's header |
| 453 | // and must be included to release an object. If not included, the compiler |
| 454 | // will error that DeleterImpl<T> does not have a method Free. |
| 455 | DeleterImpl<T>::Free(ptr); |
| 456 | } |
| 457 | }; |
Matt Braithwaite | d17d74d | 2016-08-17 20:10:28 -0700 | [diff] [blame] | 458 | |
David Benjamin | f0e935d | 2016-09-06 18:10:19 -0400 | [diff] [blame] | 459 | template <typename T, typename CleanupRet, void (*init)(T *), |
| 460 | CleanupRet (*cleanup)(T *)> |
| 461 | class StackAllocated { |
| 462 | public: |
| 463 | StackAllocated() { init(&ctx_); } |
| 464 | ~StackAllocated() { cleanup(&ctx_); } |
| 465 | |
David Benjamin | e9109cb | 2021-05-22 17:20:53 -0400 | [diff] [blame] | 466 | StackAllocated(const StackAllocated &) = delete; |
| 467 | StackAllocated& operator=(const StackAllocated &) = delete; |
| 468 | |
| 469 | T *get() { return &ctx_; } |
| 470 | const T *get() const { return &ctx_; } |
| 471 | |
| 472 | T *operator->() { return &ctx_; } |
| 473 | const T *operator->() const { return &ctx_; } |
| 474 | |
| 475 | void Reset() { |
| 476 | cleanup(&ctx_); |
| 477 | init(&ctx_); |
| 478 | } |
| 479 | |
| 480 | private: |
| 481 | T ctx_; |
| 482 | }; |
| 483 | |
| 484 | template <typename T, typename CleanupRet, void (*init)(T *), |
| 485 | CleanupRet (*cleanup)(T *), void (*move)(T *, T *)> |
| 486 | class StackAllocatedMovable { |
| 487 | public: |
| 488 | StackAllocatedMovable() { init(&ctx_); } |
| 489 | ~StackAllocatedMovable() { cleanup(&ctx_); } |
| 490 | |
| 491 | StackAllocatedMovable(StackAllocatedMovable &&other) { |
| 492 | init(&ctx_); |
| 493 | move(&ctx_, &other.ctx_); |
| 494 | } |
| 495 | StackAllocatedMovable &operator=(StackAllocatedMovable &&other) { |
| 496 | move(&ctx_, &other.ctx_); |
| 497 | return *this; |
| 498 | } |
Matthew Braithwaite | 1b0bd28 | 2016-09-27 13:25:32 -0700 | [diff] [blame] | 499 | |
David Benjamin | f0e935d | 2016-09-06 18:10:19 -0400 | [diff] [blame] | 500 | T *get() { return &ctx_; } |
| 501 | const T *get() const { return &ctx_; } |
| 502 | |
David Benjamin | 4492a61 | 2017-08-02 17:16:31 -0400 | [diff] [blame] | 503 | T *operator->() { return &ctx_; } |
| 504 | const T *operator->() const { return &ctx_; } |
| 505 | |
David Benjamin | f0e935d | 2016-09-06 18:10:19 -0400 | [diff] [blame] | 506 | void Reset() { |
| 507 | cleanup(&ctx_); |
| 508 | init(&ctx_); |
| 509 | } |
| 510 | |
| 511 | private: |
| 512 | T ctx_; |
| 513 | }; |
| 514 | |
| 515 | } // namespace internal |
| 516 | |
David Benjamin | 4709203 | 2016-09-09 14:54:10 -0400 | [diff] [blame] | 517 | #define BORINGSSL_MAKE_DELETER(type, deleter) \ |
| 518 | namespace internal { \ |
| 519 | template <> \ |
| 520 | struct DeleterImpl<type> { \ |
| 521 | static void Free(type *ptr) { deleter(ptr); } \ |
| 522 | }; \ |
David Benjamin | f0e935d | 2016-09-06 18:10:19 -0400 | [diff] [blame] | 523 | } |
Matt Braithwaite | d17d74d | 2016-08-17 20:10:28 -0700 | [diff] [blame] | 524 | |
Matt Braithwaite | d17d74d | 2016-08-17 20:10:28 -0700 | [diff] [blame] | 525 | // Holds ownership of heap-allocated BoringSSL structures. Sample usage: |
David Benjamin | 8ee0d14 | 2017-05-02 09:54:05 -0400 | [diff] [blame] | 526 | // bssl::UniquePtr<RSA> rsa(RSA_new()); |
Matt Braithwaite | d17d74d | 2016-08-17 20:10:28 -0700 | [diff] [blame] | 527 | // bssl::UniquePtr<BIO> bio(BIO_new(BIO_s_mem())); |
| 528 | template <typename T> |
David Benjamin | 971b330 | 2023-01-25 15:59:39 -0500 | [diff] [blame] | 529 | using UniquePtr = std::unique_ptr<T, internal::Deleter>; |
Matt Braithwaite | d17d74d | 2016-08-17 20:10:28 -0700 | [diff] [blame] | 530 | |
David Benjamin | a943613 | 2018-09-23 18:36:01 -0500 | [diff] [blame] | 531 | #define BORINGSSL_MAKE_UP_REF(type, up_ref_func) \ |
| 532 | inline UniquePtr<type> UpRef(type *v) { \ |
| 533 | if (v != nullptr) { \ |
| 534 | up_ref_func(v); \ |
| 535 | } \ |
| 536 | return UniquePtr<type>(v); \ |
| 537 | } \ |
| 538 | \ |
| 539 | inline UniquePtr<type> UpRef(const UniquePtr<type> &ptr) { \ |
| 540 | return UpRef(ptr.get()); \ |
David Benjamin | 2908dd1 | 2018-06-29 17:46:42 -0400 | [diff] [blame] | 541 | } |
| 542 | |
Joshua Liebow-Feeser | 8c7c635 | 2018-08-26 18:53:36 -0700 | [diff] [blame] | 543 | BSSL_NAMESPACE_END |
Matt Braithwaite | d17d74d | 2016-08-17 20:10:28 -0700 | [diff] [blame] | 544 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 545 | } // extern C++ |
Matt Braithwaite | d17d74d | 2016-08-17 20:10:28 -0700 | [diff] [blame] | 546 | |
David Benjamin | f0e935d | 2016-09-06 18:10:19 -0400 | [diff] [blame] | 547 | #endif // !BORINGSSL_NO_CXX |
| 548 | |
David Benjamin | 4512b79 | 2017-08-18 19:21:50 -0400 | [diff] [blame] | 549 | #endif // OPENSSL_HEADER_BASE_H |