webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
base.h
Go to the documentation of this file.
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
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 
56 
57 /* This file should be the first included by all BoringSSL headers. */
58 
59 #include <stddef.h>
60 #include <stdint.h>
61 #include <sys/types.h>
62 
63 #if defined(__MINGW32__)
64 /* stdio.h is needed on MinGW for __MINGW_PRINTF_FORMAT. */
65 #include <stdio.h>
66 #endif
67 
68 #include <openssl/opensslconf.h>
69 
70 #if defined(BORINGSSL_PREFIX)
71 #include <boringssl_prefix_symbols.h>
72 #endif
73 
74 #if defined(__cplusplus)
75 extern "C" {
76 #endif
77 
78 
79 #if defined(__x86_64) || defined(_M_AMD64) || defined(_M_X64)
80 #define OPENSSL_64_BIT
81 #define OPENSSL_X86_64
82 #elif defined(__x86) || defined(__i386) || defined(__i386__) || defined(_M_IX86)
83 #define OPENSSL_32_BIT
84 #define OPENSSL_X86
85 #elif defined(__aarch64__)
86 #define OPENSSL_64_BIT
87 #define OPENSSL_AARCH64
88 #elif defined(__arm) || defined(__arm__) || defined(_M_ARM)
89 #define OPENSSL_32_BIT
90 #define OPENSSL_ARM
91 #elif (defined(__PPC64__) || defined(__powerpc64__)) && defined(_LITTLE_ENDIAN)
92 #define OPENSSL_64_BIT
93 #define OPENSSL_PPC64LE
94 #elif defined(__mips__) && !defined(__LP64__)
95 #define OPENSSL_32_BIT
96 #define OPENSSL_MIPS
97 #elif defined(__mips__) && defined(__LP64__)
98 #define OPENSSL_64_BIT
99 #define OPENSSL_MIPS64
100 #elif defined(__pnacl__)
101 #define OPENSSL_32_BIT
102 #define OPENSSL_PNACL
103 #elif defined(__myriad2__)
104 #define OPENSSL_32_BIT
105 #else
106 #error "Unknown target CPU"
107 #endif
108 
109 #if defined(__APPLE__)
110 #define OPENSSL_APPLE
111 #endif
112 
113 #if defined(_WIN32)
114 #define OPENSSL_WINDOWS
115 #endif
116 
117 #if defined(TRUSTY)
118 #define OPENSSL_TRUSTY
119 #define OPENSSL_NO_THREADS
120 #endif
121 
122 #define OPENSSL_IS_BORINGSSL
123 #define BORINGSSL_201512
124 #define BORINGSSL_201603
125 #define OPENSSL_VERSION_NUMBER 0x100020af
126 #define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER
127 
128 /* BORINGSSL_API_VERSION is a positive integer that increments as BoringSSL
129  * changes over time. The value itself is not meaningful. It will be incremented
130  * whenever is convenient to coordinate an API change with consumers. This will
131  * not denote any special point in development.
132  *
133  * A consumer may use this symbol in the preprocessor to temporarily build
134  * against multiple revisions of BoringSSL at the same time. It is not
135  * recommended to do so for longer than is necessary. */
136 #define BORINGSSL_API_VERSION 2
137 
138 #if defined(BORINGSSL_SHARED_LIBRARY)
139 
140 #if defined(OPENSSL_WINDOWS)
141 
142 #if defined(BORINGSSL_IMPLEMENTATION)
143 #define OPENSSL_EXPORT __declspec(dllexport)
144 #else
145 #define OPENSSL_EXPORT __declspec(dllimport)
146 #endif
147 
148 #else /* defined(OPENSSL_WINDOWS) */
149 
150 #if defined(BORINGSSL_IMPLEMENTATION)
151 #define OPENSSL_EXPORT __attribute__((visibility("default")))
152 #else
153 #define OPENSSL_EXPORT
154 #endif
155 
156 #endif /* defined(OPENSSL_WINDOWS) */
157 
158 #else /* defined(BORINGSSL_SHARED_LIBRARY) */
159 
160 #define OPENSSL_EXPORT
161 
162 #endif /* defined(BORINGSSL_SHARED_LIBRARY) */
163 
164 
165 #if defined(__GNUC__)
166 /* MinGW has two different printf implementations. Ensure the format macro
167  * matches the selected implementation. See
168  * https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/. */
169 #if defined(__MINGW_PRINTF_FORMAT)
170 #define OPENSSL_PRINTF_FORMAT_FUNC(string_index, first_to_check) \
171  __attribute__( \
172  (__format__(__MINGW_PRINTF_FORMAT, string_index, first_to_check)))
173 #else
174 #define OPENSSL_PRINTF_FORMAT_FUNC(string_index, first_to_check) \
175  __attribute__((__format__(__printf__, string_index, first_to_check)))
176 #endif
177 #else
178 #define OPENSSL_PRINTF_FORMAT_FUNC(string_index, first_to_check)
179 #endif
180 
181 /* OPENSSL_MSVC_PRAGMA emits a pragma on MSVC and nothing on other compilers. */
182 #if defined(_MSC_VER)
183 #define OPENSSL_MSVC_PRAGMA(arg) __pragma(arg)
184 #else
185 #define OPENSSL_MSVC_PRAGMA(arg)
186 #endif
187 
188 
189 /* CRYPTO_THREADID is a dummy value. */
190 typedef int CRYPTO_THREADID;
191 
192 typedef int ASN1_BOOLEAN;
193 typedef int ASN1_NULL;
194 typedef struct ASN1_ITEM_st ASN1_ITEM;
196 typedef struct asn1_pctx_st ASN1_PCTX;
208 typedef struct asn1_string_st ASN1_TIME;
213 typedef struct asn1_type_st ASN1_TYPE;
214 
217 typedef struct DIST_POINT_st DIST_POINT;
218 typedef struct DSA_SIG_st DSA_SIG;
224 typedef struct PBE2PARAM_st PBE2PARAM;
225 typedef struct PBEPARAM_st PBEPARAM;
233 typedef struct X509_algor_st X509_ALGOR;
235 typedef struct X509_crl_st X509_CRL;
237 typedef struct X509_info_st X509_INFO;
239 typedef struct X509_name_st X509_NAME;
243 typedef struct X509_req_st X509_REQ;
244 typedef struct X509_sig_st X509_SIG;
245 typedef struct X509_val_st X509_VAL;
246 typedef struct bignum_ctx BN_CTX;
247 typedef struct bignum_st BIGNUM;
248 typedef struct bio_method_st BIO_METHOD;
249 typedef struct bio_st BIO;
250 typedef struct bn_gencb_st BN_GENCB;
252 typedef struct buf_mem_st BUF_MEM;
253 typedef struct cbb_st CBB;
254 typedef struct cbs_st CBS;
255 typedef struct cmac_ctx_st CMAC_CTX;
256 typedef struct conf_st CONF;
257 typedef struct conf_value_st CONF_VALUE;
258 typedef struct dh_st DH;
259 typedef struct dsa_st DSA;
260 typedef struct ec_group_st EC_GROUP;
261 typedef struct ec_key_st EC_KEY;
262 typedef struct ec_point_st EC_POINT;
264 typedef struct ecdsa_sig_st ECDSA_SIG;
265 typedef struct engine_st ENGINE;
266 typedef struct env_md_ctx_st EVP_MD_CTX;
267 typedef struct env_md_st EVP_MD;
268 typedef struct evp_aead_st EVP_AEAD;
270 typedef struct evp_cipher_st EVP_CIPHER;
275 typedef struct evp_pkey_st EVP_PKEY;
276 typedef struct hmac_ctx_st HMAC_CTX;
277 typedef struct md4_state_st MD4_CTX;
278 typedef struct md5_state_st MD5_CTX;
280 typedef struct pkcs12_st PKCS12;
282 typedef struct private_key_st X509_PKEY;
283 typedef struct rand_meth_st RAND_METHOD;
284 typedef struct rc4_key_st RC4_KEY;
285 typedef struct rsa_meth_st RSA_METHOD;
286 typedef struct rsa_st RSA;
289 typedef struct sha_state_st SHA_CTX;
290 typedef struct spake2_ctx_st SPAKE2_CTX;
292 typedef struct ssl_cipher_st SSL_CIPHER;
293 typedef struct ssl_ctx_st SSL_CTX;
295 typedef struct ssl_method_st SSL_METHOD;
297 typedef struct ssl_st SSL;
298 typedef struct st_ERR_FNS ERR_FNS;
299 typedef struct v3_ext_ctx X509V3_CTX;
303 typedef struct x509_cinf_st X509_CINF;
307 typedef struct x509_st X509;
309 typedef struct x509_store_st X509_STORE;
310 typedef struct x509_trust_st X509_TRUST;
311 
312 typedef void *OPENSSL_BLOCK;
313 
314 
315 #if defined(__cplusplus)
316 } /* extern C */
317 
318 // MSVC doesn't set __cplusplus to 201103 to indicate C++11 support (see
319 // https://connect.microsoft.com/VisualStudio/feedback/details/763051/a-value-of-predefined-macro-cplusplus-is-still-199711l)
320 // so MSVC is just assumed to support C++11.
321 #if !defined(BORINGSSL_NO_CXX) && __cplusplus < 201103L && !defined(_MSC_VER)
322 #define BORINGSSL_NO_CXX
323 #endif
324 
325 #if !defined(BORINGSSL_NO_CXX)
326 extern "C++" {
327 
328 #include <memory>
329 
330 // STLPort, used by some Android consumers, not have std::unique_ptr.
331 #if defined(_STLPORT_VERSION)
332 #define BORINGSSL_NO_CXX
333 #endif
334 
335 } // extern C++
336 #endif // !BORINGSSL_NO_CXX
337 
338 #if defined(BORINGSSL_NO_CXX)
339 
340 #define BORINGSSL_MAKE_DELETER(type, deleter)
341 #define BORINGSSL_MAKE_STACK_DELETER(type, deleter)
342 
343 #else
344 
345 extern "C++" {
346 
347 #include <memory>
348 
349 namespace bssl {
350 
351 namespace internal {
352 
353 template <typename T>
354 struct DeleterImpl {};
355 
356 template <typename T>
357 struct Deleter {
358  void operator()(T *ptr) {
359  // Rather than specialize Deleter for each type, we specialize
360  // DeleterImpl. This allows bssl::UniquePtr<T> to be used while only
361  // including base.h as long as the destructor is not emitted. This matches
362  // std::unique_ptr's behavior on forward-declared types.
363  //
364  // DeleterImpl itself is specialized in the corresponding module's header
365  // and must be included to release an object. If not included, the compiler
366  // will error that DeleterImpl<T> does not have a method Free.
367  DeleterImpl<T>::Free(ptr);
368  }
369 };
370 
371 template <typename T, typename CleanupRet, void (*init)(T *),
372  CleanupRet (*cleanup)(T *)>
373 class StackAllocated {
374  public:
375  StackAllocated() { init(&ctx_); }
376  ~StackAllocated() { cleanup(&ctx_); }
377 
378  StackAllocated(const StackAllocated<T, CleanupRet, init, cleanup> &) = delete;
379  T& operator=(const StackAllocated<T, CleanupRet, init, cleanup> &) = delete;
380 
381  T *get() { return &ctx_; }
382  const T *get() const { return &ctx_; }
383 
384  void Reset() {
385  cleanup(&ctx_);
386  init(&ctx_);
387  }
388 
389  private:
390  T ctx_;
391 };
392 
393 } // namespace internal
394 
395 #define BORINGSSL_MAKE_DELETER(type, deleter) \
396  namespace internal { \
397  template <> \
398  struct DeleterImpl<type> { \
399  static void Free(type *ptr) { deleter(ptr); } \
400  }; \
401  }
402 
403 // This makes a unique_ptr to STACK_OF(type) that owns all elements on the
404 // stack, i.e. it uses sk_pop_free() to clean up.
405 #define BORINGSSL_MAKE_STACK_DELETER(type, deleter) \
406  namespace internal { \
407  template <> \
408  struct DeleterImpl<STACK_OF(type)> { \
409  static void Free(STACK_OF(type) *ptr) { \
410  sk_##type##_pop_free(ptr, deleter); \
411  } \
412  }; \
413  }
414 
415 // Holds ownership of heap-allocated BoringSSL structures. Sample usage:
416 // bssl::UniquePtr<BIO> rsa(RSA_new());
417 // bssl::UniquePtr<BIO> bio(BIO_new(BIO_s_mem()));
418 template <typename T>
419 using UniquePtr = std::unique_ptr<T, internal::Deleter<T>>;
420 
421 } // namespace bssl
422 
423 } /* extern C++ */
424 
425 #endif // !BORINGSSL_NO_CXX
426 
427 #endif
428 
429 #endif /* OPENSSL_HEADER_BASE_H */
Definition: dsa.h:146
struct st_ERR_FNS ERR_FNS
Definition: base.h:298
int CRYPTO_THREADID
Definition: base.h:190
void Reset()
Definition: metrics_default.cc:285
Definition: x509.h:518
Definition: x509.h:390
Definition: x509v3.h:245
Definition: x509.h:533
Definition: x509.h:443
Definition: dh.h:249
Definition: x509.h:116
void * OPENSSL_BLOCK
Definition: base.h:312
Definition: x509.h:463
Definition: ssl.h:3776
Definition: md5.h:95
Definition: ssl.h:3644
Definition: engine.c:27
Definition: asn1.h:517
Definition: x509.h:129
Definition: x509v3.h:149
Definition: pkcs8.c:1052
Definition: internal.h:67
Definition: x509v3.h:353
Definition: x509.h:203
Definition: cipher.h:448
Definition: asn1t.h:514
Definition: dsa.h:390
Definition: rsa.h:598
Definition: x509.h:135
Definition: x509.h:122
Definition: bn.h:902
Definition: ripemd.h:71
Definition: bn.h:893
Definition: x509.h:417
Definition: rc4.h:70
Definition: internal.h:196
Definition: x509_vfy.h:163
Definition: internal.h:181
Definition: MD5.h:34
Definition: x509.h:488
Definition: pcy_int.h:115
Definition: sha.h:101
Definition: x509v3.h:126
Definition: ssl.h:2546
Definition: spake25519.c:273
Definition: internal.h:69
Definition: rand.h:102
Definition: internal.h:34
Definition: internal.h:232
void
Definition: AVFoundationCFSoftLinking.h:81
Definition: internal.h:74
Definition: asn1.h:199
Definition: x509v3.h:257
Definition: evp.h:730
Definition: conf.h:88
Definition: bytestring.h:286
TestSubObjConstructor T
Definition: TestTypedefs.idl:84
int ASN1_NULL
Definition: base.h:193
Definition: x509_vfy.h:215
Definition: x509v3.h:327
Definition: cmac.c:59
int ASN1_BOOLEAN
Definition: base.h:192
Definition: x509.h:282
Definition: x509.h:105
Definition: bytestring.h:37
Definition: x509.h:511
Definition: bio.h:810
Definition: buf.h:71
Definition: base64.h:166
struct asn1_pctx_st ASN1_PCTX
Definition: base.h:196
Definition: x509_vfy.h:181
Definition: internal.h:1207
Definition: x509.h:147
Definition: sha.h:178
Definition: x509.h:211
Definition: asn1.h:228
Definition: internal.h:138
Definition: document.h:393
Definition: digest.h:245
void init()
Definition: HTMLNames.cpp:1637
Definition: hmac.h:148
Definition: x509.h:178
Definition: conf.h:82
Definition: x509.h:193
Definition: bn.h:655
Definition: ec_key.h:233
Definition: x509.h:241
Definition: internal.h:510
Definition: internal.h:114
Definition: bytestring_test.cc:31
Definition: pcy_int.h:149
Definition: ssl.h:4031
Definition: md4.h:94
Definition: pcy_int.h:140
Definition: bio.h:796
Definition: sha.h:245
Definition: ctx.c:111
Definition: ssl.h:3620
Definition: x509.h:405
Definition: pcy_int.h:163
Definition: x509.h:232
Definition: x509.h:496
Definition: x509_vfy.h:228
Definition: x509.h:482
Definition: x_crl.c:79
Definition: ecdsa.h:98
Definition: x509.h:165
Definition: x509.h:271
Definition: cipher.h:501
Definition: asn1.h:480
#define T(a)
Definition: row_common.cc:1964
Definition: rsa.h:527
Definition: x509.h:523