| 1 |
// Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
#ifndef OPENSSL_HEADER_BASE_H |
| 5 |
#define OPENSSL_HEADER_BASE_H |
| 6 |
|
| 7 |
|
| 8 |
/** |
| 9 |
* @file |
| 10 |
* @brief This file should be the first included by all AWS-LC headers. |
| 11 |
*/ |
| 12 |
|
| 13 |
#include <stddef.h> |
| 14 |
#include <stdint.h> |
| 15 |
#include <stdlib.h> |
| 16 |
#include <sys/types.h> |
| 17 |
|
| 18 |
#if defined(__MINGW32__) |
| 19 |
// stdio.h is needed on MinGW for __MINGW_PRINTF_FORMAT. |
| 20 |
#include <stdio.h> |
| 21 |
#endif |
| 22 |
|
| 23 |
#if defined(__APPLE__) |
| 24 |
#include <TargetConditionals.h> |
| 25 |
#endif |
| 26 |
|
| 27 |
// Include an AWS-LC-only header so consumers including this header without |
| 28 |
// setting up include paths do not accidentally pick up the system |
| 29 |
// opensslconf.h. |
| 30 |
#include <openssl/is_awslc.h> |
| 31 |
#include <openssl/opensslconf.h> |
| 32 |
#include <openssl/target.h> // IWYU pragma: export |
| 33 |
|
| 34 |
#include <openssl/boringssl_prefix_symbols.h> |
| 35 |
|
| 36 |
#if defined(__cplusplus) |
| 37 |
extern "C" { |
| 38 |
#endif |
| 39 |
|
| 40 |
#if defined(BORINGSSL_FIPS) |
| 41 |
#define AWSLC_FIPS |
| 42 |
#endif |
| 43 |
|
| 44 |
#define AWSLC_VERSION_NAME "AWS-LC" |
| 45 |
#define OPENSSL_IS_AWSLC |
| 46 |
// |OPENSSL_VERSION_NUMBER| should match the version number in opensslv.h. |
| 47 |
#define OPENSSL_VERSION_NUMBER @OPENSSL_VERSION_NUMBER@ |
| 48 |
#define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER |
| 49 |
|
| 50 |
// BORINGSSL_API_VERSION is replaced with AWSLC_API_VERSION to avoid users interpreting AWSLC as BoringSSL. |
| 51 |
// Below are BoringSSL's comments on BORINGSSL_API_VERSION. |
| 52 |
// BORINGSSL_API_VERSION is a positive integer that increments as BoringSSL |
| 53 |
// changes over time. The value itself is not meaningful. It will be incremented |
| 54 |
// whenever is convenient to coordinate an API change with consumers. This will |
| 55 |
// not denote any special point in development. |
| 56 |
// |
| 57 |
// A consumer may use this symbol in the preprocessor to temporarily build |
| 58 |
// against multiple revisions of BoringSSL at the same time. It is not |
| 59 |
// recommended to do so for longer than is necessary. |
| 60 |
#define AWSLC_API_VERSION 35 |
| 61 |
|
| 62 |
// This string tracks the most current production release version on Github |
| 63 |
// https://github.com/aws/aws-lc/releases. |
| 64 |
// When bumping the encoded version number, also update the test fixture: |
| 65 |
// ServiceIndicatorTest.AWSLCVersionString |
| 66 |
// Note: there are two versions of this test. Only one test is compiled |
| 67 |
// depending on FIPS mode. |
| 68 |
#define AWSLC_VERSION_NUMBER_STRING "@SOFTWARE_VERSION@" |
| 69 |
|
| 70 |
#if defined(BORINGSSL_SHARED_LIBRARY) |
| 71 |
|
| 72 |
#if defined(OPENSSL_WINDOWS) |
| 73 |
|
| 74 |
#if defined(BORINGSSL_IMPLEMENTATION) |
| 75 |
#define OPENSSL_EXPORT __declspec(dllexport) |
| 76 |
#else |
| 77 |
#define OPENSSL_EXPORT __declspec(dllimport) |
| 78 |
#endif |
| 79 |
|
| 80 |
#else // defined(OPENSSL_WINDOWS) |
| 81 |
|
| 82 |
#if defined(BORINGSSL_IMPLEMENTATION) |
| 83 |
#define OPENSSL_EXPORT __attribute__((visibility("default"))) |
| 84 |
#else |
| 85 |
#define OPENSSL_EXPORT |
| 86 |
#endif |
| 87 |
|
| 88 |
#endif // defined(OPENSSL_WINDOWS) |
| 89 |
|
| 90 |
#else // defined(BORINGSSL_SHARED_LIBRARY) |
| 91 |
|
| 92 |
#if defined(OPENSSL_WINDOWS) |
| 93 |
#define OPENSSL_EXPORT |
| 94 |
#else |
| 95 |
#define OPENSSL_EXPORT __attribute__((visibility("default"))) |
| 96 |
#endif |
| 97 |
|
| 98 |
#endif // defined(BORINGSSL_SHARED_LIBRARY) |
| 99 |
|
| 100 |
#if !defined(OPENSSL_WARN_UNUSED_RESULT) |
| 101 |
// This should only affect internal usage of functions |
| 102 |
#if defined(BORINGSSL_IMPLEMENTATION) || defined(AWS_LC_TEST_ENV) |
| 103 |
#if defined(__GNUC__) || defined(__clang__) |
| 104 |
# define OPENSSL_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result)) |
| 105 |
#elif defined(_MSC_VER) |
| 106 |
# define OPENSSL_WARN_UNUSED_RESULT _Check_return_ |
| 107 |
#else |
| 108 |
# define OPENSSL_WARN_UNUSED_RESULT |
| 109 |
#endif |
| 110 |
#else |
| 111 |
// The macro is ignored by consumers |
| 112 |
# define OPENSSL_WARN_UNUSED_RESULT |
| 113 |
#endif |
| 114 |
#endif |
| 115 |
|
| 116 |
#if defined(_MSC_VER) |
| 117 |
|
| 118 |
// OPENSSL_DEPRECATED is used to mark a function as deprecated. Use |
| 119 |
// of any functions so marked in caller code will produce a warning. |
| 120 |
// OPENSSL_BEGIN_ALLOW_DEPRECATED and OPENSSL_END_ALLOW_DEPRECATED |
| 121 |
// can be used to suppress the warning in regions of caller code. |
| 122 |
#define OPENSSL_DEPRECATED __declspec(deprecated) |
| 123 |
#define OPENSSL_BEGIN_ALLOW_DEPRECATED \ |
| 124 |
__pragma(warning(push)) __pragma(warning(disable : 4996)) |
| 125 |
#define OPENSSL_END_ALLOW_DEPRECATED __pragma(warning(pop)) |
| 126 |
|
| 127 |
#elif (defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC_MINOR__ >= 6))) || defined(__clang__) |
| 128 |
// `_Pragma("GCC diagnostic push")` was added in GCC 4.6 |
| 129 |
// http://gcc.gnu.org/gcc-4.6/changes.html |
| 130 |
#define OPENSSL_DEPRECATED __attribute__((__deprecated__)) |
| 131 |
#define OPENSSL_BEGIN_ALLOW_DEPRECATED \ |
| 132 |
_Pragma("GCC diagnostic push") \ |
| 133 |
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") |
| 134 |
#define OPENSSL_END_ALLOW_DEPRECATED _Pragma("GCC diagnostic pop") |
| 135 |
|
| 136 |
#else |
| 137 |
|
| 138 |
#define OPENSSL_DEPRECATED |
| 139 |
#define OPENSSL_BEGIN_ALLOW_DEPRECATED |
| 140 |
#define OPENSSL_END_ALLOW_DEPRECATED |
| 141 |
|
| 142 |
#endif |
| 143 |
|
| 144 |
|
| 145 |
#if defined(__GNUC__) || defined(__clang__) |
| 146 |
// MinGW has two different printf implementations. Ensure the format macro |
| 147 |
// matches the selected implementation. See |
| 148 |
// https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/. |
| 149 |
#if defined(__MINGW_PRINTF_FORMAT) |
| 150 |
#define OPENSSL_PRINTF_FORMAT_FUNC(string_index, first_to_check) \ |
| 151 |
__attribute__( \ |
| 152 |
(__format__(__MINGW_PRINTF_FORMAT, string_index, first_to_check))) |
| 153 |
#else |
| 154 |
#define OPENSSL_PRINTF_FORMAT_FUNC(string_index, first_to_check) \ |
| 155 |
__attribute__((__format__(__printf__, string_index, first_to_check))) |
| 156 |
#endif |
| 157 |
#else |
| 158 |
#define OPENSSL_PRINTF_FORMAT_FUNC(string_index, first_to_check) |
| 159 |
#endif |
| 160 |
|
| 161 |
// OPENSSL_CLANG_PRAGMA emits a pragma on clang and nothing on other compilers. |
| 162 |
#if defined(__clang__) |
| 163 |
#define OPENSSL_CLANG_PRAGMA(arg) _Pragma(arg) |
| 164 |
#else |
| 165 |
#define OPENSSL_CLANG_PRAGMA(arg) |
| 166 |
#endif |
| 167 |
|
| 168 |
// OPENSSL_MSVC_PRAGMA emits a pragma on MSVC and nothing on other compilers. |
| 169 |
#if defined(_MSC_VER) |
| 170 |
#define OPENSSL_MSVC_PRAGMA(arg) __pragma(arg) |
| 171 |
#else |
| 172 |
#define OPENSSL_MSVC_PRAGMA(arg) |
| 173 |
#endif |
| 174 |
|
| 175 |
#if defined(__GNUC__) || defined(__clang__) |
| 176 |
#define OPENSSL_UNUSED __attribute__((unused)) |
| 177 |
#else |
| 178 |
#define OPENSSL_UNUSED |
| 179 |
#endif |
| 180 |
|
| 181 |
// C99-compatible static assertion using bit-field width trick. |
| 182 |
// A negative bit-field width causes a compile-time error. |
| 183 |
// |
| 184 |
// Previously we defined |OPENSSL_STATIC_ASSERT| to use one of two keywords: |
| 185 |
// |Static_assert| or |static_assert|. The latter was used if we were compiling |
| 186 |
// a C++ translation unit or on Windows (excluding when using a Clang compiler). |
| 187 |
// The former was used in other cases. However, these two keywords are not |
| 188 |
// defined before C11. So, we can't rely on these when we want to be C99 |
| 189 |
// compliant. If we at some point decide that we want to only be compliant with |
| 190 |
// C11 (and up), we can reintroduce these keywords. Instead, use a method that |
| 191 |
// is guaranteed to be C99 compliant and still give us an equivalent static |
| 192 |
// assert mechanism. |
| 193 |
// |
| 194 |
// The solution below defines a struct type containing a bit field. |
| 195 |
// The name of that type is |static_assertion_msg|. |msg| is a concatenation of |
| 196 |
// a user-chosen error (which should be chosen with respect to actual assertion) |
| 197 |
// and the line the assertion is defined. This should ensure name uniqueness. |
| 198 |
// The width of the bit field is set to 1 or -1, depending on the evaluation of |
| 199 |
// the boolean expression |cond|. If the condition is false, the width requested |
| 200 |
// is -1, which is illegal and would cause the compiler to throw an error. |
| 201 |
// |
| 202 |
// An example of an error thrown during compilation: |
| 203 |
// ``` |
| 204 |
// error: negative width in bit-field |
| 205 |
// 'static_assertion_at_line_913_error_is_AEAD_state_is_too_small' |
| 206 |
// ``` |
| 207 |
#define AWSLC_CONCAT(left, right) left##right |
| 208 |
#define AWSLC_STATIC_ASSERT_DEFINE(cond, msg) typedef struct { \ |
| 209 |
unsigned int AWSLC_CONCAT(static_assertion_, msg) : (cond) ? 1 : -1; \ |
| 210 |
} AWSLC_CONCAT(static_assertion_, msg) OPENSSL_UNUSED; |
| 211 |
#define AWSLC_STATIC_ASSERT_ADD_LINE0(cond, suffix) AWSLC_STATIC_ASSERT_DEFINE(cond, AWSLC_CONCAT(at_line_, suffix)) |
| 212 |
#define AWSLC_STATIC_ASSERT_ADD_LINE1(cond, line, suffix) AWSLC_STATIC_ASSERT_ADD_LINE0(cond, AWSLC_CONCAT(line, suffix)) |
| 213 |
#define AWSLC_STATIC_ASSERT_ADD_LINE2(cond, suffix) AWSLC_STATIC_ASSERT_ADD_LINE1(cond, __LINE__, suffix) |
| 214 |
#define AWSLC_STATIC_ASSERT_ADD_ERROR(cond, suffix) AWSLC_STATIC_ASSERT_ADD_LINE2(cond, AWSLC_CONCAT(_error_is_, suffix)) |
| 215 |
#define OPENSSL_STATIC_ASSERT(cond, error) AWSLC_STATIC_ASSERT_ADD_ERROR(cond, error) |
| 216 |
|
| 217 |
// Sanity check of "target.h": OPENSSL_64_BIT/OPENSSL_32_BIT must match actual pointer size |
| 218 |
#if defined(OPENSSL_64_BIT) |
| 219 |
OPENSSL_STATIC_ASSERT(sizeof(void *) == 8, pointer_size_must_be_8_bytes_for_64_bit) |
| 220 |
#elif defined(OPENSSL_32_BIT) |
| 221 |
OPENSSL_STATIC_ASSERT(sizeof(void *) == 4, pointer_size_must_be_4_bytes_for_32_bit) |
| 222 |
#endif |
| 223 |
|
| 224 |
// Sanity checks of "target.h": OPENSSL_BIG_ENDIAN should be consistent with other endianness indicators. |
| 225 |
// If architecture-specific big-endian macros are defined, OPENSSL_BIG_ENDIAN should be too. |
| 226 |
#if (defined(__ARMEB__) || defined(__AARCH64EB__) || defined(__MIPSEB__) || \ |
| 227 |
defined(__BIG_ENDIAN__) || (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \ |
| 228 |
__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) && !defined(OPENSSL_BIG_ENDIAN) |
| 229 |
#error "Big-endian architecture detected but OPENSSL_BIG_ENDIAN is not defined" |
| 230 |
#endif |
| 231 |
// If architecture-specific little-endian macros are defined, OPENSSL_BIG_ENDIAN should not be. |
| 232 |
#if (defined(__ARMEL__) || defined(__AARCH64EL__) || defined(__MIPSEL__) || \ |
| 233 |
defined(__LITTLE_ENDIAN__) || (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \ |
| 234 |
__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) && defined(OPENSSL_BIG_ENDIAN) |
| 235 |
#error "Little-endian architecture detected but OPENSSL_BIG_ENDIAN is defined" |
| 236 |
#endif |
| 237 |
|
| 238 |
// C and C++ handle inline functions differently. In C++, an inline function is |
| 239 |
// defined in just the header file, potentially emitted in multiple compilation |
| 240 |
// units (in cases the compiler did not inline), but each copy must be identical |
| 241 |
// to satsify ODR. In C, a non-static inline must be manually emitted in exactly |
| 242 |
// one compilation unit with a separate extern inline declaration. |
| 243 |
// |
| 244 |
// In both languages, exported inline functions referencing file-local symbols |
| 245 |
// are problematic. C forbids this altogether (though GCC and Clang seem not to |
| 246 |
// enforce it). It works in C++, but ODR requires the definitions be identical, |
| 247 |
// including all names in the definitions resolving to the "same entity". In |
| 248 |
// practice, this is unlikely to be a problem, but an inline function that |
| 249 |
// returns a pointer to a file-local symbol |
| 250 |
// could compile oddly. |
| 251 |
// |
| 252 |
// Historically, we used static inline in headers. However, to satisfy ODR, use |
| 253 |
// plain inline in C++, to allow inline consumer functions to call our header |
| 254 |
// functions. Plain inline would also work better with C99 inline, but that is |
| 255 |
// not used much in practice, extern inline is tedious, and there are conflicts |
| 256 |
// with the old gnu89 model: |
| 257 |
// https://stackoverflow.com/questions/216510/extern-inline |
| 258 |
#if defined(__cplusplus) |
| 259 |
#define OPENSSL_INLINE inline |
| 260 |
#else |
| 261 |
// Add OPENSSL_UNUSED so that, should an inline function be emitted via macro |
| 262 |
// (e.g. a |STACK_OF(T)| implementation) in a source file without tripping |
| 263 |
// clang's -Wunused-function. |
| 264 |
#define OPENSSL_INLINE static inline OPENSSL_UNUSED |
| 265 |
#endif |
| 266 |
|
| 267 |
#if defined(OPENSSL_WINDOWS) |
| 268 |
#define OPENSSL_NOINLINE __declspec(noinline) |
| 269 |
#else |
| 270 |
#define OPENSSL_NOINLINE __attribute__((noinline)) |
| 271 |
#endif |
| 272 |
|
| 273 |
// ossl_ssize_t is a signed type which is large enough to fit the size of any |
| 274 |
// valid memory allocation. We prefer using |size_t|, but sometimes we need a |
| 275 |
// signed type for OpenSSL API compatibility. This type can be used in such |
| 276 |
// cases to avoid overflow. |
| 277 |
// |
| 278 |
// Not all |size_t| values fit in |ossl_ssize_t|, but all |size_t| values that |
| 279 |
// are sizes of or indices into C objects, can be converted without overflow. |
| 280 |
typedef ptrdiff_t ossl_ssize_t; |
| 281 |
|
| 282 |
// CBS_ASN1_TAG is the type used by |CBS| and |CBB| for ASN.1 tags. See that |
| 283 |
// header for details. This type is defined in base.h as a forward declaration. |
| 284 |
typedef uint32_t CBS_ASN1_TAG; |
| 285 |
|
| 286 |
// CRYPTO_THREADID is a dummy value. |
| 287 |
typedef int CRYPTO_THREADID; |
| 288 |
|
| 289 |
// An |ASN1_NULL| is an opaque type. asn1.h represents the ASN.1 NULL value as |
| 290 |
// an opaque, non-NULL |ASN1_NULL*| pointer. |
| 291 |
typedef struct asn1_null_st ASN1_NULL; |
| 292 |
|
| 293 |
typedef int ASN1_BOOLEAN; |
| 294 |
typedef struct ASN1_ITEM_st ASN1_ITEM; |
| 295 |
typedef struct asn1_object_st ASN1_OBJECT; |
| 296 |
typedef struct asn1_pctx_st ASN1_PCTX; |
| 297 |
typedef struct asn1_string_st ASN1_BIT_STRING; |
| 298 |
typedef struct asn1_string_st ASN1_BMPSTRING; |
| 299 |
typedef struct asn1_string_st ASN1_ENUMERATED; |
| 300 |
typedef struct asn1_string_st ASN1_GENERALIZEDTIME; |
| 301 |
typedef struct asn1_string_st ASN1_GENERALSTRING; |
| 302 |
typedef struct asn1_string_st ASN1_IA5STRING; |
| 303 |
typedef struct asn1_string_st ASN1_INTEGER; |
| 304 |
typedef struct asn1_string_st ASN1_OCTET_STRING; |
| 305 |
typedef struct asn1_string_st ASN1_PRINTABLESTRING; |
| 306 |
typedef struct asn1_string_st ASN1_STRING; |
| 307 |
typedef struct asn1_string_st ASN1_T61STRING; |
| 308 |
typedef struct asn1_string_st ASN1_TIME; |
| 309 |
typedef struct asn1_string_st ASN1_UNIVERSALSTRING; |
| 310 |
typedef struct asn1_string_st ASN1_UTCTIME; |
| 311 |
typedef struct asn1_string_st ASN1_UTF8STRING; |
| 312 |
typedef struct asn1_string_st ASN1_VISIBLESTRING; |
| 313 |
typedef struct asn1_type_st ASN1_TYPE; |
| 314 |
typedef struct AUTHORITY_KEYID_st AUTHORITY_KEYID; |
| 315 |
typedef struct BASIC_CONSTRAINTS_st BASIC_CONSTRAINTS; |
| 316 |
typedef struct DIST_POINT_st DIST_POINT; |
| 317 |
typedef struct DSA_SIG_st DSA_SIG; |
| 318 |
typedef struct GENERAL_NAME_st GENERAL_NAME; |
| 319 |
typedef struct ISSUING_DIST_POINT_st ISSUING_DIST_POINT; |
| 320 |
typedef struct NAME_CONSTRAINTS_st NAME_CONSTRAINTS; |
| 321 |
typedef struct Netscape_spkac_st NETSCAPE_SPKAC; |
| 322 |
typedef struct Netscape_spki_st NETSCAPE_SPKI; |
| 323 |
typedef struct RIPEMD160state_st RIPEMD160_CTX; |
| 324 |
typedef struct X509_VERIFY_PARAM_st X509_VERIFY_PARAM; |
| 325 |
typedef struct X509_algor_st X509_ALGOR; |
| 326 |
typedef struct X509_crl_st X509_CRL; |
| 327 |
typedef struct X509_extension_st X509_EXTENSION; |
| 328 |
typedef struct X509_info_st X509_INFO; |
| 329 |
typedef struct X509_name_entry_st X509_NAME_ENTRY; |
| 330 |
typedef struct X509_name_st X509_NAME; |
| 331 |
typedef struct X509_pubkey_st X509_PUBKEY; |
| 332 |
typedef struct X509_req_st X509_REQ; |
| 333 |
typedef struct x509_sig_info_st X509_SIG_INFO; |
| 334 |
typedef struct X509_sig_st X509_SIG; |
| 335 |
typedef struct bignum_ctx BN_CTX; |
| 336 |
typedef struct bignum_st BIGNUM; |
| 337 |
typedef struct bio_method_st BIO_METHOD; |
| 338 |
typedef struct bio_st BIO; |
| 339 |
typedef struct blake2b_state_st BLAKE2B_CTX; |
| 340 |
typedef struct bn_gencb_st BN_GENCB; |
| 341 |
typedef struct bn_mont_ctx_st BN_MONT_CTX; |
| 342 |
typedef struct buf_mem_st BUF_MEM; |
| 343 |
typedef struct cast_key_st CAST_KEY; |
| 344 |
typedef struct cbb_st CBB; |
| 345 |
typedef struct cbs_st CBS; |
| 346 |
typedef struct cmac_ctx_st CMAC_CTX; |
| 347 |
typedef struct conf_st CONF; |
| 348 |
typedef struct conf_value_st CONF_VALUE; |
| 349 |
typedef struct crypto_buffer_pool_st CRYPTO_BUFFER_POOL; |
| 350 |
typedef struct crypto_buffer_st CRYPTO_BUFFER; |
| 351 |
typedef struct ctr_drbg_state_st CTR_DRBG_STATE; |
| 352 |
typedef struct dh_st DH; |
| 353 |
typedef struct dsa_st DSA; |
| 354 |
typedef struct ec_group_st EC_GROUP; |
| 355 |
typedef struct ec_key_st EC_KEY; |
| 356 |
typedef struct ec_point_st EC_POINT; |
| 357 |
typedef struct ec_key_method_st EC_KEY_METHOD; |
| 358 |
typedef struct ecdsa_sig_st ECDSA_SIG; |
| 359 |
typedef struct engine_st ENGINE; |
| 360 |
typedef struct env_md_ctx_st EVP_MD_CTX; |
| 361 |
typedef struct env_md_st EVP_MD; |
| 362 |
typedef struct evp_aead_st EVP_AEAD; |
| 363 |
typedef struct evp_aead_ctx_st EVP_AEAD_CTX; |
| 364 |
typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX; |
| 365 |
typedef struct evp_cipher_st EVP_CIPHER; |
| 366 |
|
| 367 |
/** |
| 368 |
* @typedef EVP_ENCODE_CTX |
| 369 |
* @copydoc evp_encode_ctx_st |
| 370 |
* @see evp_encode_ctx_st |
| 371 |
*/ |
| 372 |
typedef struct evp_encode_ctx_st EVP_ENCODE_CTX; |
| 373 |
typedef struct evp_hpke_aead_st EVP_HPKE_AEAD; |
| 374 |
typedef struct evp_hpke_ctx_st EVP_HPKE_CTX; |
| 375 |
typedef struct evp_hpke_kdf_st EVP_HPKE_KDF; |
| 376 |
typedef struct evp_hpke_kem_st EVP_HPKE_KEM; |
| 377 |
typedef struct evp_hpke_key_st EVP_HPKE_KEY; |
| 378 |
typedef struct evp_kem_st EVP_KEM; |
| 379 |
typedef struct kem_key_st KEM_KEY; |
| 380 |
typedef struct evp_pkey_ctx_st EVP_PKEY_CTX; |
| 381 |
typedef struct evp_pkey_asn1_method_st EVP_PKEY_ASN1_METHOD; |
| 382 |
typedef struct evp_pkey_st EVP_PKEY; |
| 383 |
typedef struct evp_pkey_ctx_signature_context_params_st EVP_PKEY_CTX_SIGNATURE_CONTEXT_PARAMS; |
| 384 |
typedef struct hmac_ctx_st HMAC_CTX; |
| 385 |
typedef struct md4_state_st MD4_CTX; |
| 386 |
typedef struct md5_state_st MD5_CTX; |
| 387 |
typedef struct pqdsa_key_st PQDSA_KEY; |
| 388 |
typedef struct ocsp_req_ctx_st OCSP_REQ_CTX; |
| 389 |
typedef struct ossl_init_settings_st OPENSSL_INIT_SETTINGS; |
| 390 |
typedef struct pkcs7_digest_st PKCS7_DIGEST; |
| 391 |
typedef struct pkcs7_enc_content_st PKCS7_ENC_CONTENT; |
| 392 |
typedef struct pkcs7_encrypt_st PKCS7_ENCRYPT; |
| 393 |
typedef struct pkcs7_envelope_st PKCS7_ENVELOPE; |
| 394 |
typedef struct pkcs7_issuer_and_serial_st PKCS7_ISSUER_AND_SERIAL; |
| 395 |
typedef struct pkcs7_recip_info_st PKCS7_RECIP_INFO; |
| 396 |
typedef struct pkcs7_sign_envelope_st PKCS7_SIGN_ENVELOPE; |
| 397 |
typedef struct pkcs7_signed_st PKCS7_SIGNED; |
| 398 |
typedef struct pkcs7_signer_info_st PKCS7_SIGNER_INFO; |
| 399 |
typedef struct pkcs7_st PKCS7; |
| 400 |
typedef struct pkcs12_st PKCS12; |
| 401 |
typedef struct pkcs8_priv_key_info_st PKCS8_PRIV_KEY_INFO; |
| 402 |
typedef struct private_key_st X509_PKEY; |
| 403 |
typedef struct rand_meth_st RAND_METHOD; |
| 404 |
typedef struct rc4_key_st RC4_KEY; |
| 405 |
typedef struct rsa_meth_st RSA_METHOD; |
| 406 |
typedef struct rsassa_pss_params_st RSASSA_PSS_PARAMS; |
| 407 |
typedef struct rsa_pss_params_st RSA_PSS_PARAMS; |
| 408 |
typedef struct rsa_st RSA; |
| 409 |
typedef struct sha256_state_st SHA256_CTX; |
| 410 |
typedef struct sha512_state_st SHA512_CTX; |
| 411 |
typedef struct sha_state_st SHA_CTX; |
| 412 |
typedef struct spake2_ctx_st SPAKE2_CTX; |
| 413 |
typedef struct srtp_protection_profile_st SRTP_PROTECTION_PROFILE; |
| 414 |
typedef struct ssl_cipher_st SSL_CIPHER; |
| 415 |
typedef struct ssl_ctx_st SSL_CTX; |
| 416 |
typedef struct ssl_early_callback_ctx SSL_CLIENT_HELLO; |
| 417 |
typedef struct ssl_ech_keys_st SSL_ECH_KEYS; |
| 418 |
typedef struct ssl_method_st SSL_METHOD; |
| 419 |
typedef struct ssl_private_key_method_st SSL_PRIVATE_KEY_METHOD; |
| 420 |
typedef struct ssl_quic_method_st SSL_QUIC_METHOD; |
| 421 |
typedef struct ssl_session_st SSL_SESSION; |
| 422 |
typedef struct ssl_st SSL; |
| 423 |
typedef struct ssl_ticket_aead_method_st SSL_TICKET_AEAD_METHOD; |
| 424 |
typedef struct st_ERR_FNS ERR_FNS; |
| 425 |
typedef struct trust_token_st TRUST_TOKEN; |
| 426 |
typedef struct trust_token_client_st TRUST_TOKEN_CLIENT; |
| 427 |
typedef struct trust_token_issuer_st TRUST_TOKEN_ISSUER; |
| 428 |
typedef struct trust_token_method_st TRUST_TOKEN_METHOD; |
| 429 |
typedef struct v3_ext_ctx X509V3_CTX; |
| 430 |
typedef struct v3_ext_method X509V3_EXT_METHOD; |
| 431 |
typedef struct x509_attributes_st X509_ATTRIBUTE; |
| 432 |
typedef struct x509_lookup_st X509_LOOKUP; |
| 433 |
typedef struct x509_lookup_method_st X509_LOOKUP_METHOD; |
| 434 |
typedef struct x509_object_st X509_OBJECT; |
| 435 |
typedef struct x509_revoked_st X509_REVOKED; |
| 436 |
typedef struct x509_st X509; |
| 437 |
typedef struct x509_store_ctx_st X509_STORE_CTX; |
| 438 |
typedef struct x509_store_st X509_STORE; |
| 439 |
typedef struct x509_trust_st X509_TRUST; |
| 440 |
|
| 441 |
typedef void *OPENSSL_BLOCK; |
| 442 |
|
| 443 |
// BSSL_CHECK aborts if |condition| is not true. |
| 444 |
#define BSSL_CHECK(condition) \ |
| 445 |
do { \ |
| 446 |
if (!(condition)) { \ |
| 447 |
abort(); \ |
| 448 |
} \ |
| 449 |
} while (0); |
| 450 |
|
| 451 |
#if defined(__cplusplus) |
| 452 |
} // extern C |
| 453 |
#elif !defined(BORINGSSL_NO_CXX) |
| 454 |
#define BORINGSSL_NO_CXX |
| 455 |
#endif |
| 456 |
|
| 457 |
#if defined(BORINGSSL_PREFIX) |
| 458 |
#define BSSL_NAMESPACE_BEGIN \ |
| 459 |
namespace bssl { \ |
| 460 |
inline namespace BORINGSSL_PREFIX { |
| 461 |
#define BSSL_NAMESPACE_END \ |
| 462 |
} \ |
| 463 |
} |
| 464 |
#else |
| 465 |
#define BSSL_NAMESPACE_BEGIN namespace bssl { |
| 466 |
#define BSSL_NAMESPACE_END } |
| 467 |
#endif |
| 468 |
|
| 469 |
// MSVC doesn't set __cplusplus to 201103 to indicate C++11 support (see |
| 470 |
// https://connect.microsoft.com/VisualStudio/feedback/details/763051/a-value-of-predefined-macro-cplusplus-is-still-199711l) |
| 471 |
// so MSVC is just assumed to support C++11. |
| 472 |
#if !defined(BORINGSSL_NO_CXX) && __cplusplus < 201103L && !defined(_MSC_VER) |
| 473 |
#define BORINGSSL_NO_CXX |
| 474 |
#endif |
| 475 |
|
| 476 |
#if !defined(BORINGSSL_NO_CXX) |
| 477 |
|
| 478 |
extern "C++" { |
| 479 |
|
| 480 |
#include <memory> |
| 481 |
|
| 482 |
// STLPort, used by some Android consumers, not have std::unique_ptr. |
| 483 |
#if defined(_STLPORT_VERSION) |
| 484 |
#define BORINGSSL_NO_CXX |
| 485 |
#endif |
| 486 |
|
| 487 |
} // extern C++ |
| 488 |
#endif // !BORINGSSL_NO_CXX |
| 489 |
|
| 490 |
#if defined(BORINGSSL_NO_CXX) |
| 491 |
|
| 492 |
#define BORINGSSL_MAKE_DELETER(type, deleter) |
| 493 |
#define BORINGSSL_MAKE_UP_REF(type, up_ref_func) |
| 494 |
|
| 495 |
#else |
| 496 |
|
| 497 |
extern "C++" { |
| 498 |
|
| 499 |
BSSL_NAMESPACE_BEGIN |
| 500 |
|
| 501 |
namespace internal { |
| 502 |
|
| 503 |
// The Enable parameter is ignored and only exists so specializations can use |
| 504 |
// SFINAE. |
| 505 |
template <typename T, typename Enable = void> |
| 506 |
struct DeleterImpl {}; |
| 507 |
|
| 508 |
struct Deleter { |
| 509 |
template <typename T> |
| 510 |
void operator()(T *ptr) { |
| 511 |
// Rather than specialize Deleter for each type, we specialize |
| 512 |
// DeleterImpl. This allows bssl::UniquePtr<T> to be used while only |
| 513 |
// including base.h as long as the destructor is not emitted. This matches |
| 514 |
// std::unique_ptr's behavior on forward-declared types. |
| 515 |
// |
| 516 |
// DeleterImpl itself is specialized in the corresponding module's header |
| 517 |
// and must be included to release an object. If not included, the compiler |
| 518 |
// will error that DeleterImpl<T> does not have a method Free. |
| 519 |
DeleterImpl<T>::Free(ptr); |
| 520 |
} |
| 521 |
}; |
| 522 |
|
| 523 |
template <typename T, typename CleanupRet, void (*init)(T *), |
| 524 |
CleanupRet (*cleanup)(T *)> |
| 525 |
class StackAllocated { |
| 526 |
public: |
| 527 |
StackAllocated() { init(&ctx_); } |
| 528 |
~StackAllocated() { cleanup(&ctx_); } |
| 529 |
|
| 530 |
StackAllocated(const StackAllocated &) = delete; |
| 531 |
StackAllocated& operator=(const StackAllocated &) = delete; |
| 532 |
|
| 533 |
T *get() { return &ctx_; } |
| 534 |
const T *get() const { return &ctx_; } |
| 535 |
|
| 536 |
T *operator->() { return &ctx_; } |
| 537 |
const T *operator->() const { return &ctx_; } |
| 538 |
|
| 539 |
void Reset() { |
| 540 |
cleanup(&ctx_); |
| 541 |
init(&ctx_); |
| 542 |
} |
| 543 |
|
| 544 |
private: |
| 545 |
T ctx_; |
| 546 |
}; |
| 547 |
|
| 548 |
template <typename T, typename CleanupRet, void (*init)(T *), |
| 549 |
CleanupRet (*cleanup)(T *), void (*move)(T *, T *)> |
| 550 |
class StackAllocatedMovable { |
| 551 |
public: |
| 552 |
StackAllocatedMovable() { init(&ctx_); } |
| 553 |
~StackAllocatedMovable() { cleanup(&ctx_); } |
| 554 |
|
| 555 |
StackAllocatedMovable(StackAllocatedMovable &&other) { |
| 556 |
init(&ctx_); |
| 557 |
move(&ctx_, &other.ctx_); |
| 558 |
} |
| 559 |
StackAllocatedMovable &operator=(StackAllocatedMovable &&other) { |
| 560 |
move(&ctx_, &other.ctx_); |
| 561 |
return *this; |
| 562 |
} |
| 563 |
|
| 564 |
T *get() { return &ctx_; } |
| 565 |
const T *get() const { return &ctx_; } |
| 566 |
|
| 567 |
T *operator->() { return &ctx_; } |
| 568 |
const T *operator->() const { return &ctx_; } |
| 569 |
|
| 570 |
void Reset() { |
| 571 |
cleanup(&ctx_); |
| 572 |
init(&ctx_); |
| 573 |
} |
| 574 |
|
| 575 |
private: |
| 576 |
T ctx_; |
| 577 |
}; |
| 578 |
|
| 579 |
} // namespace internal |
| 580 |
|
| 581 |
#define BORINGSSL_MAKE_DELETER(type, deleter) \ |
| 582 |
namespace internal { \ |
| 583 |
template <> \ |
| 584 |
struct DeleterImpl<type> { \ |
| 585 |
static void Free(type *ptr) { deleter(ptr); } \ |
| 586 |
}; \ |
| 587 |
} |
| 588 |
|
| 589 |
// Holds ownership of heap-allocated BoringSSL structures. Sample usage: |
| 590 |
// bssl::UniquePtr<RSA> rsa(RSA_new()); |
| 591 |
// bssl::UniquePtr<BIO> bio(BIO_new(BIO_s_mem())); |
| 592 |
template <typename T> |
| 593 |
using UniquePtr = std::unique_ptr<T, internal::Deleter>; |
| 594 |
|
| 595 |
#define BORINGSSL_MAKE_UP_REF(type, up_ref_func) \ |
| 596 |
inline UniquePtr<type> UpRef(type *v) { \ |
| 597 |
if (v != nullptr) { \ |
| 598 |
up_ref_func(v); \ |
| 599 |
} \ |
| 600 |
return UniquePtr<type>(v); \ |
| 601 |
} \ |
| 602 |
\ |
| 603 |
inline UniquePtr<type> UpRef(const UniquePtr<type> &ptr) { \ |
| 604 |
return UpRef(ptr.get()); \ |
| 605 |
} |
| 606 |
|
| 607 |
BSSL_NAMESPACE_END |
| 608 |
|
| 609 |
} // extern C++ |
| 610 |
|
| 611 |
#endif // !BORINGSSL_NO_CXX |
| 612 |
|
| 613 |
#endif // OPENSSL_HEADER_BASE_H |