blob: 2be5ed092d196889f04bbc0202f574f5332cc4e3 [file] [log] [blame]
Adam Langley95c29f32014-06-20 12:00:00 -07001/* ====================================================================
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
9 * notice, this list of conditions and the following disclaimer.
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 Langleyeb7d2ed2014-07-30 16:02:14 -070056
David Benjamin4512b792017-08-18 19:21:50 -040057// This file should be the first included by all BoringSSL headers.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -070058
Brian Smith054e6822015-03-27 21:12:01 -100059#include <stddef.h>
Adam Langley95c29f32014-06-20 12:00:00 -070060#include <stdint.h>
Adam Langley95c29f32014-06-20 12:00:00 -070061#include <sys/types.h>
62
David Benjamin8404bdb2016-10-10 14:41:44 -040063#if defined(__MINGW32__)
David Benjamin4512b792017-08-18 19:21:50 -040064// stdio.h is needed on MinGW for __MINGW_PRINTF_FORMAT.
David Benjamin8404bdb2016-10-10 14:41:44 -040065#include <stdio.h>
66#endif
67
David Benjamin4512b792017-08-18 19:21:50 -040068// Include a BoringSSL-only header so consumers including this header without
69// setting up include paths do not accidentally pick up the system
70// opensslconf.h.
David Benjamind403be92017-04-12 16:28:25 -040071#include <openssl/is_boringssl.h>
David Benjamine593fed2016-02-25 11:39:59 -050072#include <openssl/opensslconf.h>
Piotr Sikora987b8f12014-07-14 19:21:44 -070073
Steven Valdez9980ce12016-04-14 16:35:26 -040074#if defined(BORINGSSL_PREFIX)
75#include <boringssl_prefix_symbols.h>
76#endif
77
Adam Langleyb2cb0ec2014-09-02 14:28:49 -070078#if defined(__cplusplus)
79extern "C" {
80#endif
81
82
Adam Langley95c29f32014-06-20 12:00:00 -070083#if defined(__x86_64) || defined(_M_AMD64) || defined(_M_X64)
84#define OPENSSL_64_BIT
85#define OPENSSL_X86_64
86#elif defined(__x86) || defined(__i386) || defined(__i386__) || defined(_M_IX86)
87#define OPENSSL_32_BIT
88#define OPENSSL_X86
89#elif defined(__aarch64__)
90#define OPENSSL_64_BIT
91#define OPENSSL_AARCH64
92#elif defined(__arm) || defined(__arm__) || defined(_M_ARM)
93#define OPENSSL_32_BIT
94#define OPENSSL_ARM
Adam Langley4467e592016-09-23 12:47:24 -070095#elif (defined(__PPC64__) || defined(__powerpc64__)) && defined(_LITTLE_ENDIAN)
Adam Langley3e652652015-01-09 15:44:37 -080096#define OPENSSL_64_BIT
Adam Langley4467e592016-09-23 12:47:24 -070097#define OPENSSL_PPC64LE
Adam Langleyc11e13a2015-03-20 16:46:23 -070098#elif defined(__mips__) && !defined(__LP64__)
Adam Langley09020c22014-07-10 09:14:56 -070099#define OPENSSL_32_BIT
100#define OPENSSL_MIPS
Adam Langleyc11e13a2015-03-20 16:46:23 -0700101#elif defined(__mips__) && defined(__LP64__)
102#define OPENSSL_64_BIT
103#define OPENSSL_MIPS64
Adam Langley0113a4f2014-07-10 17:07:14 -0700104#elif defined(__pnacl__)
105#define OPENSSL_32_BIT
106#define OPENSSL_PNACL
Radu Margarint17b6a7f2016-07-21 15:46:57 -0700107#elif defined(__myriad2__)
108#define OPENSSL_32_BIT
Adam Langley95c29f32014-06-20 12:00:00 -0700109#else
David Benjamin4512b792017-08-18 19:21:50 -0400110// Note BoringSSL only supports standard 32-bit and 64-bit two's-complement,
111// little-endian architectures. Functions will not produce the correct answer
112// on other systems. Run the crypto_test binary, notably
113// crypto/compiler_test.cc, before adding a new architecture.
Adam Langley95c29f32014-06-20 12:00:00 -0700114#error "Unknown target CPU"
115#endif
116
Adam Langley30eda1d2014-06-24 11:15:12 -0700117#if defined(__APPLE__)
118#define OPENSSL_APPLE
119#endif
120
Brian Smith8a36e532015-07-31 16:11:31 -0400121#if defined(_WIN32)
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700122#define OPENSSL_WINDOWS
123#endif
124
Alessandro Ghedini5e393fe2016-07-09 13:02:18 +0100125#if defined(__linux__)
126#define OPENSSL_LINUX
127#endif
128
Aaron Greenc80e4162017-01-13 11:49:38 -0800129#if defined(__Fuchsia__)
130#define OPENSSL_FUCHSIA
131#endif
132
Adam Langley65a7e942015-05-07 18:28:27 -0700133#if defined(TRUSTY)
134#define OPENSSL_TRUSTY
135#define OPENSSL_NO_THREADS
136#endif
137
Adam Langley95c29f32014-06-20 12:00:00 -0700138#define OPENSSL_IS_BORINGSSL
Alessandro Ghedini0aecbcf2016-10-03 17:14:34 +0100139#define OPENSSL_VERSION_NUMBER 0x100020af
Matt Braithwaite6454a4c2015-07-31 15:57:07 -0700140#define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER
Adam Langley95c29f32014-06-20 12:00:00 -0700141
David Benjamin4512b792017-08-18 19:21:50 -0400142// BORINGSSL_API_VERSION is a positive integer that increments as BoringSSL
143// changes over time. The value itself is not meaningful. It will be incremented
144// whenever is convenient to coordinate an API change with consumers. This will
145// not denote any special point in development.
146//
147// A consumer may use this symbol in the preprocessor to temporarily build
148// against multiple revisions of BoringSSL at the same time. It is not
149// recommended to do so for longer than is necessary.
David Benjamin073391f2017-05-03 15:03:35 -0400150#define BORINGSSL_API_VERSION 4
David Benjamin9d908ba2016-05-05 18:54:33 -0400151
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700152#if defined(BORINGSSL_SHARED_LIBRARY)
Adam Langley95c29f32014-06-20 12:00:00 -0700153
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700154#if defined(OPENSSL_WINDOWS)
155
156#if defined(BORINGSSL_IMPLEMENTATION)
157#define OPENSSL_EXPORT __declspec(dllexport)
158#else
159#define OPENSSL_EXPORT __declspec(dllimport)
160#endif
161
David Benjamin4512b792017-08-18 19:21:50 -0400162#else // defined(OPENSSL_WINDOWS)
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700163
164#if defined(BORINGSSL_IMPLEMENTATION)
165#define OPENSSL_EXPORT __attribute__((visibility("default")))
166#else
167#define OPENSSL_EXPORT
168#endif
169
David Benjamin4512b792017-08-18 19:21:50 -0400170#endif // defined(OPENSSL_WINDOWS)
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700171
David Benjamin4512b792017-08-18 19:21:50 -0400172#else // defined(BORINGSSL_SHARED_LIBRARY)
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700173
174#define OPENSSL_EXPORT
175
David Benjamin4512b792017-08-18 19:21:50 -0400176#endif // defined(BORINGSSL_SHARED_LIBRARY)
Adam Langley95c29f32014-06-20 12:00:00 -0700177
Brian Smith061332f2016-01-17 09:30:42 -1000178
179#if defined(__GNUC__)
David Benjamin4512b792017-08-18 19:21:50 -0400180// MinGW has two different printf implementations. Ensure the format macro
181// matches the selected implementation. See
182// https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/.
David Benjamin8404bdb2016-10-10 14:41:44 -0400183#if defined(__MINGW_PRINTF_FORMAT)
Brian Smith061332f2016-01-17 09:30:42 -1000184#define OPENSSL_PRINTF_FORMAT_FUNC(string_index, first_to_check) \
David Benjamin8404bdb2016-10-10 14:41:44 -0400185 __attribute__( \
186 (__format__(__MINGW_PRINTF_FORMAT, string_index, first_to_check)))
187#else
188#define OPENSSL_PRINTF_FORMAT_FUNC(string_index, first_to_check) \
189 __attribute__((__format__(__printf__, string_index, first_to_check)))
190#endif
Brian Smith061332f2016-01-17 09:30:42 -1000191#else
192#define OPENSSL_PRINTF_FORMAT_FUNC(string_index, first_to_check)
193#endif
194
David Benjamin4512b792017-08-18 19:21:50 -0400195// OPENSSL_MSVC_PRAGMA emits a pragma on MSVC and nothing on other compilers.
David Benjamina353cdb2016-06-09 16:48:33 -0400196#if defined(_MSC_VER)
197#define OPENSSL_MSVC_PRAGMA(arg) __pragma(arg)
198#else
199#define OPENSSL_MSVC_PRAGMA(arg)
200#endif
201
David Benjamin806e18c2017-05-24 18:04:18 -0400202#if defined(__GNUC__) || defined(__clang__)
David Benjamin01f8a8c2017-04-15 18:12:55 -0400203#define OPENSSL_UNUSED __attribute__((unused))
204#else
205#define OPENSSL_UNUSED
206#endif
207
David Benjamin14c7e8d2016-11-09 17:57:31 -0500208#if defined(BORINGSSL_UNSAFE_FUZZER_MODE) && \
209 !defined(BORINGSSL_UNSAFE_DETERMINISTIC_MODE)
210#define BORINGSSL_UNSAFE_DETERMINISTIC_MODE
211#endif
Brian Smith061332f2016-01-17 09:30:42 -1000212
Adam Langley208e2392017-05-08 12:53:15 -0700213#if defined(__has_feature)
214#if __has_feature(address_sanitizer)
215#define OPENSSL_ASAN
216#endif
Adam Langleyf64a6ee2017-05-17 13:05:50 -0700217#if __has_feature(memory_sanitizer)
218#define OPENSSL_MSAN
219#endif
Adam Langley208e2392017-05-08 12:53:15 -0700220#endif
221
Vincent Batts60931e22017-09-20 11:51:54 -0400222// Have a generic fall-through for different versions of C/C++.
223#if defined(__cplusplus) && __cplusplus >= 201703L
224#define OPENSSL_FALLTHROUGH [[fallthrough]]
225#elif defined(__cplusplus) && __cplusplus >= 201103L && defined(__clang__)
226#define OPENSSL_FALLTHROUGH [[clang::fallthrough]]
227#elif defined(__cplusplus) && __cplusplus >= 201103L && __GNUC__ >= 7
228#define OPENSSL_FALLTHROUGH [[gnu::fallthrough]]
229#elif __GNUC__ >= 7 // gcc 7
230#define OPENSSL_FALLTHROUGH __attribute__ ((fallthrough))
231#else // C++11 on gcc 6, and all other cases
232#define OPENSSL_FALLTHROUGH
233#endif
234
David Benjamin4512b792017-08-18 19:21:50 -0400235// CRYPTO_THREADID is a dummy value.
David Benjaminf0df86a2015-04-20 11:32:12 -0400236typedef int CRYPTO_THREADID;
237
Adam Langley95c29f32014-06-20 12:00:00 -0700238typedef int ASN1_BOOLEAN;
239typedef int ASN1_NULL;
240typedef struct ASN1_ITEM_st ASN1_ITEM;
241typedef struct asn1_object_st ASN1_OBJECT;
242typedef struct asn1_pctx_st ASN1_PCTX;
243typedef struct asn1_string_st ASN1_BIT_STRING;
244typedef struct asn1_string_st ASN1_BMPSTRING;
245typedef struct asn1_string_st ASN1_ENUMERATED;
246typedef struct asn1_string_st ASN1_GENERALIZEDTIME;
247typedef struct asn1_string_st ASN1_GENERALSTRING;
248typedef struct asn1_string_st ASN1_IA5STRING;
249typedef struct asn1_string_st ASN1_INTEGER;
250typedef struct asn1_string_st ASN1_OCTET_STRING;
251typedef struct asn1_string_st ASN1_PRINTABLESTRING;
252typedef struct asn1_string_st ASN1_STRING;
253typedef struct asn1_string_st ASN1_T61STRING;
254typedef struct asn1_string_st ASN1_TIME;
255typedef struct asn1_string_st ASN1_UNIVERSALSTRING;
256typedef struct asn1_string_st ASN1_UTCTIME;
257typedef struct asn1_string_st ASN1_UTF8STRING;
258typedef struct asn1_string_st ASN1_VISIBLESTRING;
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700259typedef struct asn1_type_st ASN1_TYPE;
Adam Langley95c29f32014-06-20 12:00:00 -0700260typedef struct AUTHORITY_KEYID_st AUTHORITY_KEYID;
Matt Braithwaiteb9afd512016-07-19 12:41:35 -0700261typedef struct BASIC_CONSTRAINTS_st BASIC_CONSTRAINTS;
Adam Langley95c29f32014-06-20 12:00:00 -0700262typedef struct DIST_POINT_st DIST_POINT;
Matt Braithwaiteb9afd512016-07-19 12:41:35 -0700263typedef struct DSA_SIG_st DSA_SIG;
Adam Langley95c29f32014-06-20 12:00:00 -0700264typedef struct ISSUING_DIST_POINT_st ISSUING_DIST_POINT;
265typedef struct NAME_CONSTRAINTS_st NAME_CONSTRAINTS;
Matt Braithwaite16f774f2015-08-03 14:14:14 -0700266typedef struct Netscape_spkac_st NETSCAPE_SPKAC;
267typedef struct Netscape_spki_st NETSCAPE_SPKI;
Adam Langleyff452c12016-03-08 14:17:02 -0800268typedef struct RIPEMD160state_st RIPEMD160_CTX;
Adam Langley95c29f32014-06-20 12:00:00 -0700269typedef struct X509_POLICY_CACHE_st X509_POLICY_CACHE;
270typedef struct X509_POLICY_LEVEL_st X509_POLICY_LEVEL;
271typedef struct X509_POLICY_NODE_st X509_POLICY_NODE;
272typedef struct X509_POLICY_TREE_st X509_POLICY_TREE;
Matt Braithwaiteb9afd512016-07-19 12:41:35 -0700273typedef struct X509_VERIFY_PARAM_st X509_VERIFY_PARAM;
Adam Langley95c29f32014-06-20 12:00:00 -0700274typedef struct X509_algor_st X509_ALGOR;
Matt Braithwaite16f774f2015-08-03 14:14:14 -0700275typedef struct X509_crl_info_st X509_CRL_INFO;
Adam Langley95c29f32014-06-20 12:00:00 -0700276typedef struct X509_crl_st X509_CRL;
Matt Braithwaite16f774f2015-08-03 14:14:14 -0700277typedef struct X509_extension_st X509_EXTENSION;
278typedef struct X509_info_st X509_INFO;
279typedef struct X509_name_entry_st X509_NAME_ENTRY;
280typedef struct X509_name_st X509_NAME;
Adam Langley95c29f32014-06-20 12:00:00 -0700281typedef struct X509_pubkey_st X509_PUBKEY;
Matt Braithwaite16f774f2015-08-03 14:14:14 -0700282typedef struct X509_req_info_st X509_REQ_INFO;
283typedef struct X509_req_st X509_REQ;
284typedef struct X509_sig_st X509_SIG;
285typedef struct X509_val_st X509_VAL;
Adam Langley95c29f32014-06-20 12:00:00 -0700286typedef struct bignum_ctx BN_CTX;
287typedef struct bignum_st BIGNUM;
288typedef struct bio_method_st BIO_METHOD;
289typedef struct bio_st BIO;
290typedef struct bn_gencb_st BN_GENCB;
291typedef struct bn_mont_ctx_st BN_MONT_CTX;
292typedef struct buf_mem_st BUF_MEM;
293typedef struct cbb_st CBB;
294typedef struct cbs_st CBS;
Adam Langley0d107e12015-05-05 16:36:32 -0700295typedef struct cmac_ctx_st CMAC_CTX;
Adam Langley95c29f32014-06-20 12:00:00 -0700296typedef struct conf_st CONF;
Brian Smith054e6822015-03-27 21:12:01 -1000297typedef struct conf_value_st CONF_VALUE;
Adam Langley9ef99d52016-10-25 17:33:49 -0700298typedef struct crypto_buffer_pool_st CRYPTO_BUFFER_POOL;
299typedef struct crypto_buffer_st CRYPTO_BUFFER;
Adam Langley95c29f32014-06-20 12:00:00 -0700300typedef struct dh_st DH;
Adam Langley95c29f32014-06-20 12:00:00 -0700301typedef struct dsa_st DSA;
Matt Braithwaiteb9afd512016-07-19 12:41:35 -0700302typedef struct ec_group_st EC_GROUP;
Adam Langley95c29f32014-06-20 12:00:00 -0700303typedef struct ec_key_st EC_KEY;
Matt Braithwaiteb9afd512016-07-19 12:41:35 -0700304typedef struct ec_point_st EC_POINT;
Adam Langley95c29f32014-06-20 12:00:00 -0700305typedef struct ecdsa_method_st ECDSA_METHOD;
306typedef struct ecdsa_sig_st ECDSA_SIG;
307typedef struct engine_st ENGINE;
308typedef struct env_md_ctx_st EVP_MD_CTX;
309typedef struct env_md_st EVP_MD;
Adam Langleyfd772a52014-06-20 12:00:00 -0700310typedef struct evp_aead_st EVP_AEAD;
Adam Langley95c29f32014-06-20 12:00:00 -0700311typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX;
312typedef struct evp_cipher_st EVP_CIPHER;
David Benjamin97a33932015-09-19 15:17:34 -0400313typedef struct evp_encode_ctx_st EVP_ENCODE_CTX;
Adam Langley95c29f32014-06-20 12:00:00 -0700314typedef struct evp_pkey_asn1_method_st EVP_PKEY_ASN1_METHOD;
315typedef struct evp_pkey_ctx_st EVP_PKEY_CTX;
316typedef struct evp_pkey_method_st EVP_PKEY_METHOD;
317typedef struct evp_pkey_st EVP_PKEY;
318typedef struct hmac_ctx_st HMAC_CTX;
Adam Langleyc9eb7ea2014-08-22 11:06:14 -0700319typedef struct md4_state_st MD4_CTX;
Adam Langley95c29f32014-06-20 12:00:00 -0700320typedef struct md5_state_st MD5_CTX;
Adam Langley5127db32014-09-19 10:49:56 -0700321typedef struct pkcs12_st PKCS12;
Matt Braithwaite16f774f2015-08-03 14:14:14 -0700322typedef struct pkcs8_priv_key_info_st PKCS8_PRIV_KEY_INFO;
323typedef struct private_key_st X509_PKEY;
Adam Langley95c29f32014-06-20 12:00:00 -0700324typedef struct rand_meth_st RAND_METHOD;
Adam Langley3f92d212015-02-20 15:32:52 -0800325typedef struct rc4_key_st RC4_KEY;
Adam Langley95c29f32014-06-20 12:00:00 -0700326typedef struct rsa_meth_st RSA_METHOD;
327typedef struct rsa_st RSA;
328typedef struct sha256_state_st SHA256_CTX;
329typedef struct sha512_state_st SHA512_CTX;
330typedef struct sha_state_st SHA_CTX;
Arnar Birgissonf27459e2016-02-09 18:09:00 -0800331typedef struct spake2_ctx_st SPAKE2_CTX;
David Benjamincfd65b62015-09-14 01:54:44 -0400332typedef struct srtp_protection_profile_st SRTP_PROTECTION_PROFILE;
David Benjamin79c117a2015-09-13 13:53:19 -0400333typedef struct ssl_cipher_st SSL_CIPHER;
Adam Langley95c29f32014-06-20 12:00:00 -0700334typedef struct ssl_ctx_st SSL_CTX;
David Benjamine39ac8f2017-07-20 12:22:21 -0400335typedef struct ssl_method_st SSL_METHOD;
Adam Langleyd04ca952017-02-28 11:26:51 -0800336typedef struct ssl_private_key_method_st SSL_PRIVATE_KEY_METHOD;
David Benjamina6b8cdf2015-09-13 14:07:33 -0400337typedef struct ssl_session_st SSL_SESSION;
David Benjamine39ac8f2017-07-20 12:22:21 -0400338typedef struct ssl_st SSL;
Adam Langley4c341d02017-03-08 19:33:21 -0800339typedef struct ssl_ticket_aead_method_st SSL_TICKET_AEAD_METHOD;
Adam Langley95c29f32014-06-20 12:00:00 -0700340typedef struct st_ERR_FNS ERR_FNS;
341typedef struct v3_ext_ctx X509V3_CTX;
Matt Braithwaite16f774f2015-08-03 14:14:14 -0700342typedef struct x509_attributes_st X509_ATTRIBUTE;
343typedef struct x509_cert_aux_st X509_CERT_AUX;
Matt Braithwaite16f774f2015-08-03 14:14:14 -0700344typedef struct x509_cinf_st X509_CINF;
Adam Langley95c29f32014-06-20 12:00:00 -0700345typedef struct x509_crl_method_st X509_CRL_METHOD;
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700346typedef struct x509_lookup_st X509_LOOKUP;
Adam Langley95c29f32014-06-20 12:00:00 -0700347typedef struct x509_revoked_st X509_REVOKED;
348typedef struct x509_st X509;
349typedef struct x509_store_ctx_st X509_STORE_CTX;
350typedef struct x509_store_st X509_STORE;
Matt Braithwaite16f774f2015-08-03 14:14:14 -0700351typedef struct x509_trust_st X509_TRUST;
352
Adam Langley95c29f32014-06-20 12:00:00 -0700353typedef void *OPENSSL_BLOCK;
354
355
Adam Langleyb2cb0ec2014-09-02 14:28:49 -0700356#if defined(__cplusplus)
David Benjamin4512b792017-08-18 19:21:50 -0400357} // extern C
David Benjaminebb4a372017-07-20 12:50:11 -0400358#elif !defined(BORINGSSL_NO_CXX)
359#define BORINGSSL_NO_CXX
360#endif
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700361
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700362// MSVC doesn't set __cplusplus to 201103 to indicate C++11 support (see
363// https://connect.microsoft.com/VisualStudio/feedback/details/763051/a-value-of-predefined-macro-cplusplus-is-still-199711l)
364// so MSVC is just assumed to support C++11.
David Benjaminf0e935d2016-09-06 18:10:19 -0400365#if !defined(BORINGSSL_NO_CXX) && __cplusplus < 201103L && !defined(_MSC_VER)
366#define BORINGSSL_NO_CXX
367#endif
368
David Benjamin3e5619d2016-09-07 17:28:59 -0400369#if !defined(BORINGSSL_NO_CXX)
370extern "C++" {
371
372#include <memory>
373
374// STLPort, used by some Android consumers, not have std::unique_ptr.
375#if defined(_STLPORT_VERSION)
376#define BORINGSSL_NO_CXX
377#endif
378
379} // extern C++
380#endif // !BORINGSSL_NO_CXX
381
David Benjaminf0e935d2016-09-06 18:10:19 -0400382#if defined(BORINGSSL_NO_CXX)
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700383
384#define BORINGSSL_MAKE_DELETER(type, deleter)
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700385
386#else
387
David Benjaminf0e935d2016-09-06 18:10:19 -0400388extern "C++" {
389
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700390namespace bssl {
391
392namespace internal {
393
David Benjamincfc11c22017-07-18 22:45:18 -0400394// The Enable parameter is ignored and only exists so specializations can use
395// SFINAE.
396template <typename T, typename Enable = void>
David Benjamin47092032016-09-09 14:54:10 -0400397struct DeleterImpl {};
398
399template <typename T>
400struct Deleter {
401 void operator()(T *ptr) {
402 // Rather than specialize Deleter for each type, we specialize
403 // DeleterImpl. This allows bssl::UniquePtr<T> to be used while only
404 // including base.h as long as the destructor is not emitted. This matches
405 // std::unique_ptr's behavior on forward-declared types.
406 //
407 // DeleterImpl itself is specialized in the corresponding module's header
408 // and must be included to release an object. If not included, the compiler
409 // will error that DeleterImpl<T> does not have a method Free.
410 DeleterImpl<T>::Free(ptr);
411 }
412};
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700413
David Benjaminf0e935d2016-09-06 18:10:19 -0400414template <typename T, typename CleanupRet, void (*init)(T *),
415 CleanupRet (*cleanup)(T *)>
416class StackAllocated {
417 public:
418 StackAllocated() { init(&ctx_); }
419 ~StackAllocated() { cleanup(&ctx_); }
420
Matthew Braithwaite1b0bd282016-09-27 13:25:32 -0700421 StackAllocated(const StackAllocated<T, CleanupRet, init, cleanup> &) = delete;
422 T& operator=(const StackAllocated<T, CleanupRet, init, cleanup> &) = delete;
423
David Benjaminf0e935d2016-09-06 18:10:19 -0400424 T *get() { return &ctx_; }
425 const T *get() const { return &ctx_; }
426
David Benjamin4492a612017-08-02 17:16:31 -0400427 T *operator->() { return &ctx_; }
428 const T *operator->() const { return &ctx_; }
429
David Benjaminf0e935d2016-09-06 18:10:19 -0400430 void Reset() {
431 cleanup(&ctx_);
432 init(&ctx_);
433 }
434
435 private:
436 T ctx_;
437};
438
439} // namespace internal
440
David Benjamin47092032016-09-09 14:54:10 -0400441#define BORINGSSL_MAKE_DELETER(type, deleter) \
442 namespace internal { \
443 template <> \
444 struct DeleterImpl<type> { \
445 static void Free(type *ptr) { deleter(ptr); } \
446 }; \
David Benjaminf0e935d2016-09-06 18:10:19 -0400447 }
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700448
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700449// Holds ownership of heap-allocated BoringSSL structures. Sample usage:
David Benjamin8ee0d142017-05-02 09:54:05 -0400450// bssl::UniquePtr<RSA> rsa(RSA_new());
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700451// bssl::UniquePtr<BIO> bio(BIO_new(BIO_s_mem()));
452template <typename T>
453using UniquePtr = std::unique_ptr<T, internal::Deleter<T>>;
454
455} // namespace bssl
456
David Benjamin4512b792017-08-18 19:21:50 -0400457} // extern C++
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700458
David Benjaminf0e935d2016-09-06 18:10:19 -0400459#endif // !BORINGSSL_NO_CXX
460
David Benjamin4512b792017-08-18 19:21:50 -0400461#endif // OPENSSL_HEADER_BASE_H