]>
Commit | Line | Data |
---|---|---|
aa6bb135 | 1 | /* |
39147079 | 2 | * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. |
d02b48c6 | 3 | * |
48f4ad77 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
aa6bb135 RS |
5 | * this file except in compliance with the License. You can obtain a copy |
6 | * in the file LICENSE in the source distribution or at | |
7 | * https://www.openssl.org/source/license.html | |
d02b48c6 RE |
8 | */ |
9 | ||
ae4186b0 DMSP |
10 | #ifndef OSSL_INTERNAL_CRYPTLIB_H |
11 | # define OSSL_INTERNAL_CRYPTLIB_H | |
d02b48c6 | 12 | |
0f113f3e MC |
13 | # include <stdlib.h> |
14 | # include <string.h> | |
d02b48c6 | 15 | |
0f113f3e | 16 | # ifdef OPENSSL_USE_APPLINK |
b1132792 | 17 | # define BIO_FLAGS_UPLINK_INTERNAL 0x8000 |
0f113f3e | 18 | # include "ms/uplink.h" |
b1132792 BE |
19 | # else |
20 | # define BIO_FLAGS_UPLINK_INTERNAL 0 | |
0f113f3e | 21 | # endif |
ea1b02db | 22 | |
0f113f3e MC |
23 | # include <openssl/crypto.h> |
24 | # include <openssl/buffer.h> | |
25 | # include <openssl/bio.h> | |
26 | # include <openssl/err.h> | |
677963e5 | 27 | # include "internal/nelem.h" |
d02b48c6 | 28 | |
67dc995e MC |
29 | #ifdef NDEBUG |
30 | # define ossl_assert(x) ((x) != 0) | |
31 | #else | |
32 | __owur static ossl_inline int ossl_assert_int(int expr, const char *exprstr, | |
33 | const char *file, int line) | |
34 | { | |
35 | if (!expr) | |
36 | OPENSSL_die(exprstr, file, line); | |
37 | ||
38 | return expr; | |
39 | } | |
40 | ||
41 | # define ossl_assert(x) ossl_assert_int((x) != 0, "Assertion failed: "#x, \ | |
42 | __FILE__, __LINE__) | |
43 | ||
44 | #endif | |
45 | ||
39147079 P |
46 | /* |
47 | * Use this inside a union with the field that needs to be aligned to a | |
48 | * reasonable boundary for the platform. The most pessimistic alignment | |
49 | * of the listed types will be used by the compiler. | |
50 | */ | |
51 | # define OSSL_UNION_ALIGN \ | |
52 | double align; \ | |
53 | ossl_uintmax_t align_int; \ | |
54 | void *align_ptr | |
55 | ||
4a1f3f27 | 56 | typedef struct ex_callback_st EX_CALLBACK; |
4a1f3f27 DSH |
57 | DEFINE_STACK_OF(EX_CALLBACK) |
58 | ||
e6b5c341 | 59 | typedef struct mem_st MEM; |
89d6aa10 | 60 | DEFINE_LHASH_OF(MEM); |
4a1f3f27 | 61 | |
198c42f5 P |
62 | # define OPENSSL_CONF "openssl.cnf" |
63 | ||
0f113f3e MC |
64 | # ifndef OPENSSL_SYS_VMS |
65 | # define X509_CERT_AREA OPENSSLDIR | |
66 | # define X509_CERT_DIR OPENSSLDIR "/certs" | |
67 | # define X509_CERT_FILE OPENSSLDIR "/cert.pem" | |
68 | # define X509_PRIVATE_DIR OPENSSLDIR "/private" | |
98d8ddd2 | 69 | # define CTLOG_FILE OPENSSLDIR "/ct_log_list.cnf" |
0f113f3e | 70 | # else |
d17d3293 | 71 | # define X509_CERT_AREA "OSSL$DATAROOT:[000000]" |
a90f8d76 RL |
72 | # define X509_CERT_DIR "OSSL$DATAROOT:[CERTS]" |
73 | # define X509_CERT_FILE "OSSL$DATAROOT:[000000]cert.pem" | |
74 | # define X509_PRIVATE_DIR "OSSL$DATAROOT:[PRIVATE]" | |
75 | # define CTLOG_FILE "OSSL$DATAROOT:[000000]ct_log_list.cnf" | |
0f113f3e | 76 | # endif |
d02b48c6 | 77 | |
0f113f3e MC |
78 | # define X509_CERT_DIR_EVP "SSL_CERT_DIR" |
79 | # define X509_CERT_FILE_EVP "SSL_CERT_FILE" | |
8c6afbc5 | 80 | # define CTLOG_FILE_EVP "CTLOG_FILE" |
d02b48c6 | 81 | |
54a656ef | 82 | /* size of string representations */ |
0f113f3e MC |
83 | # define DECIMAL_SIZE(type) ((sizeof(type)*8+2)/3+1) |
84 | # define HEX_SIZE(type) (sizeof(type)*2) | |
54a656ef | 85 | |
2b247cf8 | 86 | void OPENSSL_cpuid_setup(void); |
24fd8541 BE |
87 | #if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \ |
88 | defined(__x86_64) || defined(__x86_64__) || \ | |
89 | defined(_M_AMD64) || defined(_M_X64) | |
e303f55f | 90 | extern unsigned int OPENSSL_ia32cap_P[]; |
24fd8541 | 91 | #endif |
0f113f3e | 92 | void OPENSSL_showfatal(const char *fmta, ...); |
1aedc35f MC |
93 | int do_ex_data_init(OPENSSL_CTX *ctx); |
94 | void crypto_cleanup_all_ex_data_int(OPENSSL_CTX *ctx); | |
2915fe19 | 95 | int openssl_init_fork_handlers(void); |
84952925 | 96 | int openssl_get_fork_id(void); |
2b247cf8 | 97 | |
5c39a55d P |
98 | char *ossl_safe_getenv(const char *name); |
99 | ||
0e598a3d | 100 | extern CRYPTO_RWLOCK *memdbg_lock; |
7d37818d | 101 | int openssl_strerror_r(int errnum, char *buf, size_t buflen); |
09487816 AP |
102 | # if !defined(OPENSSL_NO_STDIO) |
103 | FILE *openssl_fopen(const char *filename, const char *mode); | |
104 | # else | |
105 | void *openssl_fopen(const char *filename, const char *mode); | |
106 | # endif | |
7d37818d | 107 | |
360fc9f4 | 108 | uint32_t OPENSSL_rdtsc(void); |
c8f37048 BE |
109 | size_t OPENSSL_instrument_bus(unsigned int *, size_t); |
110 | size_t OPENSSL_instrument_bus2(unsigned int *, size_t, size_t); | |
d807db26 | 111 | |
1aedc35f MC |
112 | /* ex_data structures */ |
113 | ||
114 | /* | |
115 | * Each structure type (sometimes called a class), that supports | |
116 | * exdata has a stack of callbacks for each instance. | |
117 | */ | |
118 | struct ex_callback_st { | |
119 | long argl; /* Arbitrary long */ | |
120 | void *argp; /* Arbitrary void * */ | |
121 | CRYPTO_EX_new *new_func; | |
122 | CRYPTO_EX_free *free_func; | |
123 | CRYPTO_EX_dup *dup_func; | |
124 | }; | |
125 | ||
126 | /* | |
127 | * The state for each class. This could just be a typedef, but | |
128 | * a structure allows future changes. | |
129 | */ | |
130 | typedef struct ex_callbacks_st { | |
131 | STACK_OF(EX_CALLBACK) *meth; | |
132 | } EX_CALLBACKS; | |
133 | ||
134 | typedef struct ossl_ex_data_global_st { | |
135 | CRYPTO_RWLOCK *ex_data_lock; | |
136 | EX_CALLBACKS ex_data[CRYPTO_EX_INDEX__COUNT]; | |
137 | } OSSL_EX_DATA_GLOBAL; | |
138 | ||
139 | ||
140 | /* OPENSSL_CTX */ | |
141 | ||
142 | # define OPENSSL_CTX_PROVIDER_STORE_RUN_ONCE_INDEX 0 | |
143 | # define OPENSSL_CTX_DEFAULT_METHOD_STORE_RUN_ONCE_INDEX 1 | |
144 | # define OPENSSL_CTX_METHOD_STORE_RUN_ONCE_INDEX 2 | |
145 | # define OPENSSL_CTX_MAX_RUN_ONCE 3 | |
146 | ||
181ea366 | 147 | # define OPENSSL_CTX_EVP_METHOD_STORE_INDEX 0 |
1aedc35f MC |
148 | # define OPENSSL_CTX_PROVIDER_STORE_INDEX 1 |
149 | # define OPENSSL_CTX_PROPERTY_DEFN_INDEX 2 | |
150 | # define OPENSSL_CTX_PROPERTY_STRING_INDEX 3 | |
f2182a4e | 151 | # define OPENSSL_CTX_NAMEMAP_INDEX 4 |
da0d114c | 152 | # define OPENSSL_CTX_DRBG_INDEX 5 |
a2f27fd7 MC |
153 | # define OPENSSL_CTX_DRBG_NONCE_INDEX 6 |
154 | # define OPENSSL_CTX_RAND_CRNGT_INDEX 7 | |
e41faf57 | 155 | # define OPENSSL_CTX_THREAD_EVENT_HANDLER_INDEX 8 |
da747958 | 156 | # define OPENSSL_CTX_FIPS_PROV_INDEX 9 |
0d003c52 | 157 | # define OPENSSL_CTX_SERIALIZER_STORE_INDEX 10 |
36fc5fc6 SL |
158 | # define OPENSSL_CTX_SELF_TEST_CB_INDEX 11 |
159 | # define OPENSSL_CTX_MAX_INDEXES 12 | |
b8fe36fe | 160 | |
d64b6299 | 161 | typedef struct openssl_ctx_method { |
1aedc35f | 162 | void *(*new_func)(OPENSSL_CTX *ctx); |
d64b6299 RL |
163 | void (*free_func)(void *); |
164 | } OPENSSL_CTX_METHOD; | |
1aedc35f | 165 | |
d4c051ce MC |
166 | OPENSSL_CTX *openssl_ctx_get_concrete(OPENSSL_CTX *ctx); |
167 | ||
d64b6299 | 168 | /* Functions to retrieve pointers to data by index */ |
1aedc35f MC |
169 | void *openssl_ctx_get_data(OPENSSL_CTX *, int /* index */, |
170 | const OPENSSL_CTX_METHOD * ctx); | |
d64b6299 | 171 | |
1aedc35f MC |
172 | void openssl_ctx_default_deinit(void); |
173 | OSSL_EX_DATA_GLOBAL *openssl_ctx_get_ex_data_global(OPENSSL_CTX *ctx); | |
174 | typedef int (openssl_ctx_run_once_fn)(OPENSSL_CTX *ctx); | |
175 | typedef void (openssl_ctx_onfree_fn)(OPENSSL_CTX *ctx); | |
b8fe36fe MC |
176 | |
177 | int openssl_ctx_run_once(OPENSSL_CTX *ctx, unsigned int idx, | |
178 | openssl_ctx_run_once_fn run_once_fn); | |
179 | int openssl_ctx_onfree(OPENSSL_CTX *ctx, openssl_ctx_onfree_fn onfreefn); | |
1aedc35f MC |
180 | |
181 | OPENSSL_CTX *crypto_ex_data_get_openssl_ctx(const CRYPTO_EX_DATA *ad); | |
182 | int crypto_new_ex_data_ex(OPENSSL_CTX *ctx, int class_index, void *obj, | |
183 | CRYPTO_EX_DATA *ad); | |
184 | int crypto_get_ex_new_index_ex(OPENSSL_CTX *ctx, int class_index, | |
185 | long argl, void *argp, | |
186 | CRYPTO_EX_new *new_func, | |
187 | CRYPTO_EX_dup *dup_func, | |
188 | CRYPTO_EX_free *free_func); | |
189 | int crypto_free_ex_index_ex(OPENSSL_CTX *ctx, int class_index, int idx); | |
5c3f1e34 RL |
190 | |
191 | /* Function for simple binary search */ | |
192 | ||
193 | /* Flags */ | |
194 | # define OSSL_BSEARCH_VALUE_ON_NOMATCH 0x01 | |
195 | # define OSSL_BSEARCH_FIRST_VALUE_ON_MATCH 0x02 | |
196 | ||
197 | const void *ossl_bsearch(const void *key, const void *base, int num, | |
198 | int size, int (*cmp) (const void *, const void *), | |
199 | int flags); | |
200 | ||
d02b48c6 | 201 | #endif |