/src/openssl/include/openssl/crypto.h
Line | Count | Source |
1 | | /* |
2 | | * WARNING: do not edit! |
3 | | * Generated by Makefile from include/openssl/crypto.h.in |
4 | | * |
5 | | * Copyright 1995-2026 The OpenSSL Project Authors. All Rights Reserved. |
6 | | * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved |
7 | | * |
8 | | * Licensed under the Apache License 2.0 (the "License"). You may not use |
9 | | * this file except in compliance with the License. You can obtain a copy |
10 | | * in the file LICENSE in the source distribution or at |
11 | | * https://www.openssl.org/source/license.html |
12 | | */ |
13 | | |
14 | | /* clang-format off */ |
15 | | |
16 | | /* clang-format on */ |
17 | | |
18 | | #ifndef OPENSSL_CRYPTO_H |
19 | | #define OPENSSL_CRYPTO_H |
20 | | #pragma once |
21 | | |
22 | | #include <openssl/macros.h> |
23 | | #ifndef OPENSSL_NO_DEPRECATED_3_0 |
24 | | #define HEADER_CRYPTO_H |
25 | | #endif |
26 | | |
27 | | #include <stdlib.h> |
28 | | #include <time.h> |
29 | | |
30 | | #include <openssl/e_os2.h> |
31 | | |
32 | | #ifndef OPENSSL_NO_STDIO |
33 | | #include <stdio.h> |
34 | | #endif |
35 | | |
36 | | #include <openssl/safestack.h> |
37 | | #include <openssl/opensslv.h> |
38 | | #include <openssl/types.h> |
39 | | #include <openssl/opensslconf.h> |
40 | | #include <openssl/cryptoerr.h> |
41 | | #include <openssl/core.h> |
42 | | |
43 | | #ifdef CHARSET_EBCDIC |
44 | | #include <openssl/ebcdic.h> |
45 | | #endif |
46 | | |
47 | | /* |
48 | | * Resolve problems on some operating systems with symbol names that clash |
49 | | * one way or another |
50 | | */ |
51 | | #include <openssl/symhacks.h> |
52 | | |
53 | | #ifndef OPENSSL_NO_DEPRECATED_1_1_0 |
54 | | #include <openssl/opensslv.h> |
55 | | #endif |
56 | | |
57 | | #ifdef __cplusplus |
58 | | extern "C" { |
59 | | #endif |
60 | | |
61 | | #ifndef OPENSSL_NO_DEPRECATED_1_1_0 |
62 | | #define SSLeay OpenSSL_version_num |
63 | | #define SSLeay_version OpenSSL_version |
64 | | #define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER |
65 | | #define SSLEAY_VERSION OPENSSL_VERSION |
66 | | #define SSLEAY_CFLAGS OPENSSL_CFLAGS |
67 | | #define SSLEAY_BUILT_ON OPENSSL_BUILT_ON |
68 | | #define SSLEAY_PLATFORM OPENSSL_PLATFORM |
69 | | #define SSLEAY_DIR OPENSSL_DIR |
70 | | |
71 | | /* |
72 | | * Old type for allocating dynamic locks. No longer used. Use the new thread |
73 | | * API instead. |
74 | | */ |
75 | | typedef struct { |
76 | | int dummy; |
77 | | } CRYPTO_dynlock; |
78 | | |
79 | | #endif /* OPENSSL_NO_DEPRECATED_1_1_0 */ |
80 | | |
81 | | typedef void CRYPTO_RWLOCK; |
82 | | |
83 | | CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void); |
84 | | __owur int CRYPTO_THREAD_read_lock(CRYPTO_RWLOCK *lock); |
85 | | __owur int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock); |
86 | | int CRYPTO_THREAD_unlock(CRYPTO_RWLOCK *lock); |
87 | | void CRYPTO_THREAD_lock_free(CRYPTO_RWLOCK *lock); |
88 | | |
89 | | int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock); |
90 | | int CRYPTO_atomic_add64(uint64_t *val, uint64_t op, uint64_t *ret, |
91 | | CRYPTO_RWLOCK *lock); |
92 | | int CRYPTO_atomic_and(uint64_t *val, uint64_t op, uint64_t *ret, |
93 | | CRYPTO_RWLOCK *lock); |
94 | | int CRYPTO_atomic_or(uint64_t *val, uint64_t op, uint64_t *ret, |
95 | | CRYPTO_RWLOCK *lock); |
96 | | int CRYPTO_atomic_load(uint64_t *val, uint64_t *ret, CRYPTO_RWLOCK *lock); |
97 | | int CRYPTO_atomic_load_int(int *val, int *ret, CRYPTO_RWLOCK *lock); |
98 | | int CRYPTO_atomic_store(uint64_t *dst, uint64_t val, CRYPTO_RWLOCK *lock); |
99 | | int CRYPTO_atomic_store_int(int *dst, int val, CRYPTO_RWLOCK *lock); |
100 | | int CRYPTO_atomic_load_ptr(void **ptr, void **ret, CRYPTO_RWLOCK *lock); |
101 | | int CRYPTO_atomic_store_ptr(void **dst, void **val, CRYPTO_RWLOCK *lock); |
102 | | int CRYPTO_atomic_cmp_exch_ptr(void **ptr, void **expect, void *desire, CRYPTO_RWLOCK *lock, |
103 | | int *lock_failed); |
104 | | |
105 | | /* No longer needed, so this is a no-op */ |
106 | | #define OPENSSL_malloc_init() \ |
107 | | while (0) \ |
108 | | continue |
109 | | |
110 | | #define OPENSSL_malloc(num) \ |
111 | 2.82k | CRYPTO_malloc(num, OPENSSL_FILE, OPENSSL_LINE) |
112 | | #define OPENSSL_zalloc(num) \ |
113 | 18.7k | CRYPTO_zalloc(num, OPENSSL_FILE, OPENSSL_LINE) |
114 | | #define OPENSSL_malloc_array(num, size) \ |
115 | 0 | CRYPTO_malloc_array(num, size, OPENSSL_FILE, OPENSSL_LINE) |
116 | | #define OPENSSL_calloc(num, size) \ |
117 | 829 | CRYPTO_calloc(num, size, OPENSSL_FILE, OPENSSL_LINE) |
118 | | #define OPENSSL_aligned_alloc(num, alignment, freeptr) \ |
119 | 0 | CRYPTO_aligned_alloc(num, alignment, freeptr, \ |
120 | 0 | OPENSSL_FILE, OPENSSL_LINE) |
121 | | #define OPENSSL_aligned_alloc_array(num, size, alignment, freeptr) \ |
122 | 3 | CRYPTO_aligned_alloc_array(num, size, alignment, freeptr, \ |
123 | 3 | OPENSSL_FILE, OPENSSL_LINE) |
124 | | #define OPENSSL_realloc(addr, num) \ |
125 | 1.33k | CRYPTO_realloc(addr, num, OPENSSL_FILE, OPENSSL_LINE) |
126 | | #define OPENSSL_clear_realloc(addr, old_num, num) \ |
127 | 0 | CRYPTO_clear_realloc(addr, old_num, num, OPENSSL_FILE, OPENSSL_LINE) |
128 | | #define OPENSSL_realloc_array(addr, num, size) \ |
129 | 24 | CRYPTO_realloc_array(addr, num, size, OPENSSL_FILE, OPENSSL_LINE) |
130 | | #define OPENSSL_clear_realloc_array(addr, old_num, num, size) \ |
131 | | CRYPTO_clear_realloc_array(addr, old_num, num, size, \ |
132 | | OPENSSL_FILE, OPENSSL_LINE) |
133 | | #define OPENSSL_clear_free(addr, num) \ |
134 | 8.70k | CRYPTO_clear_free(addr, num, OPENSSL_FILE, OPENSSL_LINE) |
135 | | #define OPENSSL_free(addr) \ |
136 | 13.5k | CRYPTO_free(addr, OPENSSL_FILE, OPENSSL_LINE) |
137 | | #define OPENSSL_memdup(str, s) \ |
138 | 0 | CRYPTO_memdup((str), s, OPENSSL_FILE, OPENSSL_LINE) |
139 | | #define OPENSSL_strdup(str) \ |
140 | 341 | CRYPTO_strdup(str, OPENSSL_FILE, OPENSSL_LINE) |
141 | | #define OPENSSL_strndup(str, n) \ |
142 | 34 | CRYPTO_strndup(str, n, OPENSSL_FILE, OPENSSL_LINE) |
143 | | #define OPENSSL_secure_malloc(num) \ |
144 | 0 | CRYPTO_secure_malloc(num, OPENSSL_FILE, OPENSSL_LINE) |
145 | | #define OPENSSL_secure_zalloc(num) \ |
146 | 0 | CRYPTO_secure_zalloc(num, OPENSSL_FILE, OPENSSL_LINE) |
147 | | #define OPENSSL_secure_malloc_array(num, size) \ |
148 | 0 | CRYPTO_secure_malloc_array(num, size, OPENSSL_FILE, OPENSSL_LINE) |
149 | | #define OPENSSL_secure_calloc(num, size) \ |
150 | 0 | CRYPTO_secure_calloc(num, size, OPENSSL_FILE, OPENSSL_LINE) |
151 | | #define OPENSSL_secure_free(addr) \ |
152 | 0 | CRYPTO_secure_free(addr, OPENSSL_FILE, OPENSSL_LINE) |
153 | | #define OPENSSL_secure_clear_free(addr, num) \ |
154 | 0 | CRYPTO_secure_clear_free(addr, num, OPENSSL_FILE, OPENSSL_LINE) |
155 | | #define OPENSSL_secure_actual_size(ptr) \ |
156 | | CRYPTO_secure_actual_size(ptr) |
157 | | |
158 | | size_t OPENSSL_strlcpy(char *dst, const char *src, size_t siz); |
159 | | size_t OPENSSL_strlcat(char *dst, const char *src, size_t siz); |
160 | | size_t OPENSSL_strnlen(const char *str, size_t maxlen); |
161 | | int OPENSSL_strtoul(const char *str, char **endptr, int base, unsigned long *num); |
162 | | int OPENSSL_buf2hexstr_ex(char *str, size_t str_n, size_t *strlength, |
163 | | const unsigned char *buf, size_t buflen, |
164 | | const char sep); |
165 | | char *OPENSSL_buf2hexstr(const unsigned char *buf, long buflen); |
166 | | int OPENSSL_hexstr2buf_ex(unsigned char *buf, size_t buf_n, size_t *buflen, |
167 | | const char *str, const char sep); |
168 | | unsigned char *OPENSSL_hexstr2buf(const char *str, long *buflen); |
169 | | int OPENSSL_hexchar2int(unsigned char c); |
170 | | int OPENSSL_strcasecmp(const char *s1, const char *s2); |
171 | | int OPENSSL_strncasecmp(const char *s1, const char *s2, size_t n); |
172 | | |
173 | | #define OPENSSL_MALLOC_MAX_NELEMS(type) (((1U << (sizeof(int) * 8 - 1)) - 1) / sizeof(type)) |
174 | | |
175 | | /* |
176 | | * These functions return the values of OPENSSL_VERSION_MAJOR, |
177 | | * OPENSSL_VERSION_MINOR, OPENSSL_VERSION_PATCH, OPENSSL_VERSION_PRE_RELEASE |
178 | | * and OPENSSL_VERSION_BUILD_METADATA, respectively. |
179 | | */ |
180 | | unsigned int OPENSSL_version_major(void); |
181 | | unsigned int OPENSSL_version_minor(void); |
182 | | unsigned int OPENSSL_version_patch(void); |
183 | | const char *OPENSSL_version_pre_release(void); |
184 | | const char *OPENSSL_version_build_metadata(void); |
185 | | |
186 | | unsigned long OpenSSL_version_num(void); |
187 | | const char *OpenSSL_version(int type); |
188 | 1 | #define OPENSSL_VERSION 0 |
189 | 0 | #define OPENSSL_CFLAGS 1 |
190 | 0 | #define OPENSSL_BUILT_ON 2 |
191 | 0 | #define OPENSSL_PLATFORM 3 |
192 | 0 | #define OPENSSL_DIR 4 |
193 | 0 | #define OPENSSL_ENGINES_DIR 5 |
194 | 0 | #define OPENSSL_VERSION_STRING 6 |
195 | 0 | #define OPENSSL_FULL_VERSION_STRING 7 |
196 | 0 | #define OPENSSL_MODULES_DIR 8 |
197 | 0 | #define OPENSSL_CPU_INFO 9 |
198 | 0 | #define OPENSSL_WINCTX 10 |
199 | | |
200 | | const char *OPENSSL_info(int type); |
201 | | /* |
202 | | * The series starts at 1001 to avoid confusion with the OpenSSL_version |
203 | | * types. |
204 | | */ |
205 | 0 | #define OPENSSL_INFO_CONFIG_DIR 1001 |
206 | 0 | #define OPENSSL_INFO_ENGINES_DIR 1002 |
207 | 0 | #define OPENSSL_INFO_MODULES_DIR 1003 |
208 | 0 | #define OPENSSL_INFO_DSO_EXTENSION 1004 |
209 | 0 | #define OPENSSL_INFO_DIR_FILENAME_SEPARATOR 1005 |
210 | 0 | #define OPENSSL_INFO_LIST_SEPARATOR 1006 |
211 | 0 | #define OPENSSL_INFO_SEED_SOURCE 1007 |
212 | 0 | #define OPENSSL_INFO_CPU_SETTINGS 1008 |
213 | 0 | #define OPENSSL_INFO_WINDOWS_CONTEXT 1009 |
214 | | |
215 | | int OPENSSL_issetugid(void); |
216 | | |
217 | | struct crypto_ex_data_st { |
218 | | OSSL_LIB_CTX *ctx; |
219 | | STACK_OF(void) *sk; |
220 | | }; |
221 | | |
222 | | /* clang-format off */ |
223 | | SKM_DEFINE_STACK_OF_INTERNAL(void, void, void) |
224 | 0 | #define sk_void_num(sk) OPENSSL_sk_num(ossl_check_const_void_sk_type(sk)) |
225 | 0 | #define sk_void_value(sk, idx) ((void *)OPENSSL_sk_value(ossl_check_const_void_sk_type(sk), (idx))) |
226 | | #define sk_void_new(cmp) \ |
227 | | ((STACK_OF(void) *)OPENSSL_sk_set_thunks( \ |
228 | | OPENSSL_sk_set_copy_thunks( \ |
229 | | OPENSSL_sk_set_cmp_thunks( \ |
230 | | OPENSSL_sk_new(ossl_check_void_compfunc_type(cmp)), \ |
231 | | sk_void_cmpfunc_thunk), \ |
232 | | sk_void_copyfunc_thunk), \ |
233 | | sk_void_freefunc_thunk)) |
234 | | #define sk_void_new_null() \ |
235 | 0 | ((STACK_OF(void) *)OPENSSL_sk_set_thunks( \ |
236 | 0 | OPENSSL_sk_set_copy_thunks( \ |
237 | 0 | OPENSSL_sk_set_cmp_thunks( \ |
238 | 0 | OPENSSL_sk_new_null(), \ |
239 | 0 | sk_void_cmpfunc_thunk), \ |
240 | 0 | sk_void_copyfunc_thunk), \ |
241 | 0 | sk_void_freefunc_thunk)) |
242 | | #define sk_void_new_reserve(cmp, n) \ |
243 | | ((STACK_OF(void) *)OPENSSL_sk_set_thunks( \ |
244 | | OPENSSL_sk_set_copy_thunks( \ |
245 | | OPENSSL_sk_set_cmp_thunks( \ |
246 | | OPENSSL_sk_new_reserve(ossl_check_void_compfunc_type(cmp), (n)), \ |
247 | | sk_void_cmpfunc_thunk), \ |
248 | | sk_void_copyfunc_thunk), \ |
249 | | sk_void_freefunc_thunk)) |
250 | | #define sk_void_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_void_sk_type(sk), (n)) |
251 | 0 | #define sk_void_free(sk) OPENSSL_sk_free(ossl_check_void_sk_type(sk)) |
252 | | #define sk_void_zero(sk) OPENSSL_sk_zero(ossl_check_void_sk_type(sk)) |
253 | | #define sk_void_delete(sk, i) ((void *)OPENSSL_sk_delete(ossl_check_void_sk_type(sk), (i))) |
254 | | #define sk_void_delete_ptr(sk, ptr) ((void *)OPENSSL_sk_delete_ptr(ossl_check_void_sk_type(sk), ossl_check_void_type(ptr))) |
255 | 0 | #define sk_void_push(sk, ptr) OPENSSL_sk_push(ossl_check_void_sk_type(sk), ossl_check_void_type(ptr)) |
256 | | #define sk_void_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_void_sk_type(sk), ossl_check_void_type(ptr)) |
257 | 0 | #define sk_void_pop(sk) ((void *)OPENSSL_sk_pop(ossl_check_void_sk_type(sk))) |
258 | | #define sk_void_shift(sk) ((void *)OPENSSL_sk_shift(ossl_check_void_sk_type(sk))) |
259 | | #define sk_void_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_void_sk_type(sk), ossl_check_void_freefunc_type(freefunc)) |
260 | | #define sk_void_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_void_sk_type(sk), ossl_check_void_type(ptr), (idx)) |
261 | 0 | #define sk_void_set(sk, idx, ptr) ((void *)OPENSSL_sk_set(ossl_check_void_sk_type(sk), (idx), ossl_check_void_type(ptr))) |
262 | | #define sk_void_find(sk, ptr) OPENSSL_sk_find(ossl_check_void_sk_type(sk), ossl_check_void_type(ptr)) |
263 | | #define sk_void_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_void_sk_type(sk), ossl_check_void_type(ptr)) |
264 | | #define sk_void_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_void_sk_type(sk), ossl_check_void_type(ptr), pnum) |
265 | | #define sk_void_sort(sk) OPENSSL_sk_sort(ossl_check_void_sk_type(sk)) |
266 | | #define sk_void_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_void_sk_type(sk)) |
267 | | #define sk_void_dup(sk) \ |
268 | | ((STACK_OF(void) *)OPENSSL_sk_set_thunks( \ |
269 | | OPENSSL_sk_set_copy_thunks( \ |
270 | | OPENSSL_sk_set_cmp_thunks( \ |
271 | | OPENSSL_sk_dup(ossl_check_const_void_sk_type(sk)), \ |
272 | | sk_void_cmpfunc_thunk), \ |
273 | | sk_void_copyfunc_thunk), \ |
274 | | sk_void_freefunc_thunk)) |
275 | | #define sk_void_deep_copy(sk, copyfunc, freefunc) \ |
276 | | ((STACK_OF(void) *)OPENSSL_sk_set_thunks( \ |
277 | | OPENSSL_sk_set_copy_thunks( \ |
278 | | OPENSSL_sk_set_cmp_thunks( \ |
279 | | OPENSSL_sk_deep_copy( \ |
280 | | ossl_check_const_void_sk_type(sk), \ |
281 | | ossl_check_void_copyfunc_type(copyfunc), \ |
282 | | ossl_check_void_freefunc_type(freefunc)), \ |
283 | | sk_void_cmpfunc_thunk), \ |
284 | | sk_void_copyfunc_thunk), \ |
285 | | sk_void_freefunc_thunk)) |
286 | | #define sk_void_set_cmp_func(sk, cmp) ((sk_void_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_void_sk_type(sk), ossl_check_void_compfunc_type(cmp))) |
287 | | |
288 | | /* clang-format on */ |
289 | | |
290 | | /* |
291 | | * Per class, we have a STACK of function pointers. |
292 | | */ |
293 | | #define CRYPTO_EX_INDEX_SSL 0 |
294 | | #define CRYPTO_EX_INDEX_SSL_CTX 1 |
295 | | #define CRYPTO_EX_INDEX_SSL_SESSION 2 |
296 | 0 | #define CRYPTO_EX_INDEX_X509 3 |
297 | 0 | #define CRYPTO_EX_INDEX_X509_STORE 4 |
298 | 0 | #define CRYPTO_EX_INDEX_X509_STORE_CTX 5 |
299 | 0 | #define CRYPTO_EX_INDEX_DH 6 |
300 | 0 | #define CRYPTO_EX_INDEX_DSA 7 |
301 | 0 | #define CRYPTO_EX_INDEX_EC_KEY 8 |
302 | 0 | #define CRYPTO_EX_INDEX_RSA 9 |
303 | | #define CRYPTO_EX_INDEX_ENGINE 10 |
304 | 0 | #define CRYPTO_EX_INDEX_UI 11 |
305 | 0 | #define CRYPTO_EX_INDEX_BIO 12 |
306 | | #define CRYPTO_EX_INDEX_APP 13 |
307 | 0 | #define CRYPTO_EX_INDEX_UI_METHOD 14 |
308 | | #define CRYPTO_EX_INDEX_RAND_DRBG 15 |
309 | | #define CRYPTO_EX_INDEX_DRBG CRYPTO_EX_INDEX_RAND_DRBG |
310 | | #define CRYPTO_EX_INDEX_OSSL_LIB_CTX 16 |
311 | 0 | #define CRYPTO_EX_INDEX_EVP_PKEY 17 |
312 | 0 | #define CRYPTO_EX_INDEX__COUNT 18 |
313 | | |
314 | | typedef void CRYPTO_EX_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad, |
315 | | int idx, long argl, void *argp); |
316 | | typedef void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad, |
317 | | int idx, long argl, void *argp); |
318 | | typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from, |
319 | | void **from_d, int idx, long argl, void *argp); |
320 | | __owur int CRYPTO_get_ex_new_index(int class_index, long argl, void *argp, |
321 | | CRYPTO_EX_new *new_func, |
322 | | CRYPTO_EX_dup *dup_func, |
323 | | CRYPTO_EX_free *free_func); |
324 | | /* No longer use an index. */ |
325 | | int CRYPTO_free_ex_index(int class_index, int idx); |
326 | | |
327 | | /* |
328 | | * Initialise/duplicate/free CRYPTO_EX_DATA variables corresponding to a |
329 | | * given class (invokes whatever per-class callbacks are applicable) |
330 | | */ |
331 | | int CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad); |
332 | | int CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA *to, |
333 | | const CRYPTO_EX_DATA *from); |
334 | | |
335 | | void CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad); |
336 | | |
337 | | /* Allocate a single item in the CRYPTO_EX_DATA variable */ |
338 | | int CRYPTO_alloc_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad, |
339 | | int idx); |
340 | | |
341 | | /* |
342 | | * Get/set data in a CRYPTO_EX_DATA variable corresponding to a particular |
343 | | * index (relative to the class type involved) |
344 | | */ |
345 | | int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val); |
346 | | void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx); |
347 | | |
348 | | #ifndef OPENSSL_NO_DEPRECATED_1_1_0 |
349 | | /* |
350 | | * This function cleans up all "ex_data" state. It mustn't be called under |
351 | | * potential race-conditions. |
352 | | */ |
353 | | #define CRYPTO_cleanup_all_ex_data() \ |
354 | | while (0) \ |
355 | | continue |
356 | | |
357 | | /* |
358 | | * The old locking functions have been removed completely without compatibility |
359 | | * macros. This is because the old functions either could not properly report |
360 | | * errors, or the returned error values were not clearly documented. |
361 | | * Replacing the locking functions with no-ops would cause race condition |
362 | | * issues in the affected applications. It is far better for them to fail at |
363 | | * compile time. |
364 | | * On the other hand, the locking callbacks are no longer used. Consequently, |
365 | | * the callback management functions can be safely replaced with no-op macros. |
366 | | */ |
367 | | #define CRYPTO_num_locks() (1) |
368 | | #define CRYPTO_set_locking_callback(func) |
369 | | #define CRYPTO_get_locking_callback() (NULL) |
370 | | #define CRYPTO_set_add_lock_callback(func) |
371 | | #define CRYPTO_get_add_lock_callback() (NULL) |
372 | | |
373 | | /* |
374 | | * These defines where used in combination with the old locking callbacks, |
375 | | * they are not called anymore, but old code that's not called might still |
376 | | * use them. |
377 | | */ |
378 | | #define CRYPTO_LOCK 1 |
379 | | #define CRYPTO_UNLOCK 2 |
380 | | #define CRYPTO_READ 4 |
381 | | #define CRYPTO_WRITE 8 |
382 | | |
383 | | /* This structure is no longer used */ |
384 | | typedef struct crypto_threadid_st { |
385 | | int dummy; |
386 | | } CRYPTO_THREADID; |
387 | | /* Only use CRYPTO_THREADID_set_[numeric|pointer]() within callbacks */ |
388 | | #define CRYPTO_THREADID_set_numeric(id, val) |
389 | | #define CRYPTO_THREADID_set_pointer(id, ptr) |
390 | | #define CRYPTO_THREADID_set_callback(threadid_func) (0) |
391 | | #define CRYPTO_THREADID_get_callback() (NULL) |
392 | | #define CRYPTO_THREADID_current(id) |
393 | | #define CRYPTO_THREADID_cmp(a, b) (-1) |
394 | | #define CRYPTO_THREADID_cpy(dest, src) |
395 | | #define CRYPTO_THREADID_hash(id) (0UL) |
396 | | |
397 | | #ifndef OPENSSL_NO_DEPRECATED_1_0_0 |
398 | | #define CRYPTO_set_id_callback(func) |
399 | | #define CRYPTO_get_id_callback() (NULL) |
400 | | #define CRYPTO_thread_id() (0UL) |
401 | | #endif /* OPENSSL_NO_DEPRECATED_1_0_0 */ |
402 | | |
403 | | #define CRYPTO_set_dynlock_create_callback(dyn_create_function) |
404 | | #define CRYPTO_set_dynlock_lock_callback(dyn_lock_function) |
405 | | #define CRYPTO_set_dynlock_destroy_callback(dyn_destroy_function) |
406 | | #define CRYPTO_get_dynlock_create_callback() (NULL) |
407 | | #define CRYPTO_get_dynlock_lock_callback() (NULL) |
408 | | #define CRYPTO_get_dynlock_destroy_callback() (NULL) |
409 | | #endif /* OPENSSL_NO_DEPRECATED_1_1_0 */ |
410 | | |
411 | | typedef void *(*CRYPTO_malloc_fn)(size_t num, const char *file, int line); |
412 | | typedef void *(*CRYPTO_realloc_fn)(void *addr, size_t num, const char *file, |
413 | | int line); |
414 | | typedef void (*CRYPTO_free_fn)(void *addr, const char *file, int line); |
415 | | int CRYPTO_set_mem_functions(CRYPTO_malloc_fn malloc_fn, |
416 | | CRYPTO_realloc_fn realloc_fn, |
417 | | CRYPTO_free_fn free_fn); |
418 | | void CRYPTO_get_mem_functions(CRYPTO_malloc_fn *malloc_fn, |
419 | | CRYPTO_realloc_fn *realloc_fn, |
420 | | CRYPTO_free_fn *free_fn); |
421 | | |
422 | | OSSL_CRYPTO_ALLOC void *CRYPTO_malloc(size_t num, const char *file, int line); |
423 | | OSSL_CRYPTO_ALLOC void *CRYPTO_zalloc(size_t num, const char *file, int line); |
424 | | OSSL_CRYPTO_ALLOC void *CRYPTO_malloc_array(size_t num, size_t size, |
425 | | const char *file, int line); |
426 | | OSSL_CRYPTO_ALLOC void *CRYPTO_calloc(size_t num, size_t size, |
427 | | const char *file, int line); |
428 | | OSSL_CRYPTO_ALLOC void *CRYPTO_aligned_alloc(size_t num, size_t align, |
429 | | void **freeptr, const char *file, |
430 | | int line); |
431 | | OSSL_CRYPTO_ALLOC void *CRYPTO_aligned_alloc_array(size_t num, size_t size, |
432 | | size_t align, void **freeptr, |
433 | | const char *file, int line); |
434 | | void *CRYPTO_memdup(const void *str, size_t siz, const char *file, int line); |
435 | | char *CRYPTO_strdup(const char *str, const char *file, int line); |
436 | | char *CRYPTO_strndup(const char *str, size_t s, const char *file, int line); |
437 | | void CRYPTO_free(void *ptr, const char *file, int line); |
438 | | void CRYPTO_clear_free(void *ptr, size_t num, const char *file, int line); |
439 | | void *CRYPTO_realloc(void *addr, size_t num, const char *file, int line); |
440 | | void *CRYPTO_clear_realloc(void *addr, size_t old_num, size_t num, |
441 | | const char *file, int line); |
442 | | void *CRYPTO_realloc_array(void *addr, size_t num, size_t size, |
443 | | const char *file, int line); |
444 | | void *CRYPTO_clear_realloc_array(void *addr, size_t old_num, size_t num, |
445 | | size_t size, const char *file, int line); |
446 | | |
447 | | int CRYPTO_secure_malloc_init(size_t sz, size_t minsize); |
448 | | int CRYPTO_secure_malloc_done(void); |
449 | | OSSL_CRYPTO_ALLOC void *CRYPTO_secure_malloc(size_t num, const char *file, int line); |
450 | | OSSL_CRYPTO_ALLOC void *CRYPTO_secure_zalloc(size_t num, const char *file, int line); |
451 | | OSSL_CRYPTO_ALLOC void *CRYPTO_secure_malloc_array(size_t num, size_t size, |
452 | | const char *file, int line); |
453 | | OSSL_CRYPTO_ALLOC void *CRYPTO_secure_calloc(size_t num, size_t size, |
454 | | const char *file, int line); |
455 | | void CRYPTO_secure_free(void *ptr, const char *file, int line); |
456 | | void CRYPTO_secure_clear_free(void *ptr, size_t num, |
457 | | const char *file, int line); |
458 | | int CRYPTO_secure_allocated(const void *ptr); |
459 | | int CRYPTO_secure_malloc_initialized(void); |
460 | | size_t CRYPTO_secure_actual_size(void *ptr); |
461 | | size_t CRYPTO_secure_used(void); |
462 | | |
463 | | void OPENSSL_cleanse(void *ptr, size_t len); |
464 | | |
465 | | #ifndef OPENSSL_NO_CRYPTO_MDEBUG |
466 | | /* |
467 | | * The following can be used to detect memory leaks in the library. If |
468 | | * used, it turns on malloc checking |
469 | | */ |
470 | | #define CRYPTO_MEM_CHECK_OFF 0x0 /* Control only */ |
471 | | #define CRYPTO_MEM_CHECK_ON 0x1 /* Control and mode bit */ |
472 | | #define CRYPTO_MEM_CHECK_ENABLE 0x2 /* Control and mode bit */ |
473 | | #define CRYPTO_MEM_CHECK_DISABLE 0x3 /* Control only */ |
474 | | |
475 | | /* max allowed length for value of OPENSSL_MALLOC_FAILURES env var. */ |
476 | | #define CRYPTO_MEM_CHECK_MAX_FS 256 |
477 | | |
478 | | void CRYPTO_get_alloc_counts(int *mcount, int *rcount, int *fcount); |
479 | | #ifndef OPENSSL_NO_DEPRECATED_3_0 |
480 | | #define OPENSSL_mem_debug_push(info) \ |
481 | | CRYPTO_mem_debug_push(info, OPENSSL_FILE, OPENSSL_LINE) |
482 | | #define OPENSSL_mem_debug_pop() \ |
483 | | CRYPTO_mem_debug_pop() |
484 | | #endif |
485 | | #ifndef OPENSSL_NO_DEPRECATED_3_0 |
486 | | OSSL_DEPRECATEDIN_3_0 int CRYPTO_set_mem_debug(int flag); |
487 | | OSSL_DEPRECATEDIN_3_0 int CRYPTO_mem_ctrl(int mode); |
488 | | OSSL_DEPRECATEDIN_3_0 int CRYPTO_mem_debug_push(const char *info, |
489 | | const char *file, int line); |
490 | | OSSL_DEPRECATEDIN_3_0 int CRYPTO_mem_debug_pop(void); |
491 | | OSSL_DEPRECATEDIN_3_0 void CRYPTO_mem_debug_malloc(void *addr, size_t num, |
492 | | int flag, |
493 | | const char *file, int line); |
494 | | OSSL_DEPRECATEDIN_3_0 void CRYPTO_mem_debug_realloc(void *addr1, void *addr2, |
495 | | size_t num, int flag, |
496 | | const char *file, int line); |
497 | | OSSL_DEPRECATEDIN_3_0 void CRYPTO_mem_debug_free(void *addr, int flag, |
498 | | const char *file, int line); |
499 | | OSSL_DEPRECATEDIN_3_0 |
500 | | int CRYPTO_mem_leaks_cb(int (*cb)(const char *str, size_t len, void *u), |
501 | | void *u); |
502 | | #endif |
503 | | #ifndef OPENSSL_NO_STDIO |
504 | | #ifndef OPENSSL_NO_DEPRECATED_3_0 |
505 | | OSSL_DEPRECATEDIN_3_0 int CRYPTO_mem_leaks_fp(FILE *); |
506 | | #endif |
507 | | #endif |
508 | | #ifndef OPENSSL_NO_DEPRECATED_3_0 |
509 | | OSSL_DEPRECATEDIN_3_0 int CRYPTO_mem_leaks(BIO *bio); |
510 | | #endif |
511 | | #endif /* OPENSSL_NO_CRYPTO_MDEBUG */ |
512 | | |
513 | | /* die if we have to */ |
514 | | ossl_noreturn void OPENSSL_die(const char *assertion, const char *file, int line); |
515 | | #ifndef OPENSSL_NO_DEPRECATED_1_1_0 |
516 | | #define OpenSSLDie(f, l, a) OPENSSL_die((a), (f), (l)) |
517 | | #endif |
518 | | #define OPENSSL_assert(e) \ |
519 | 4 | (void)((e) ? 0 : (OPENSSL_die("assertion failed: " #e, OPENSSL_FILE, OPENSSL_LINE), 1)) |
520 | | |
521 | | int OPENSSL_isservice(void); |
522 | | |
523 | | void OPENSSL_init(void); |
524 | | #ifdef OPENSSL_SYS_UNIX |
525 | | #ifndef OPENSSL_NO_DEPRECATED_3_0 |
526 | | OSSL_DEPRECATEDIN_3_0 void OPENSSL_fork_prepare(void); |
527 | | OSSL_DEPRECATEDIN_3_0 void OPENSSL_fork_parent(void); |
528 | | OSSL_DEPRECATEDIN_3_0 void OPENSSL_fork_child(void); |
529 | | #endif |
530 | | #endif |
531 | | |
532 | | struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result); |
533 | | int OPENSSL_gmtime_adj(struct tm *tm, int offset_day, long offset_sec); |
534 | | int OPENSSL_gmtime_diff(int *pday, int *psec, |
535 | | const struct tm *from, const struct tm *to); |
536 | | |
537 | | /* |
538 | | * CRYPTO_memcmp returns zero iff the |len| bytes at |a| and |b| are equal. |
539 | | * It takes an amount of time dependent on |len|, but independent of the |
540 | | * contents of |a| and |b|. Unlike memcmp, it cannot be used to put elements |
541 | | * into a defined order as the return value when a != b is undefined, other |
542 | | * than to be non-zero. |
543 | | */ |
544 | | int CRYPTO_memcmp(const void *in_a, const void *in_b, size_t len); |
545 | | |
546 | | /* Standard initialisation options */ |
547 | 2 | #define OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS 0x00000001L |
548 | 3 | #define OPENSSL_INIT_LOAD_CRYPTO_STRINGS 0x00000002L |
549 | 3 | #define OPENSSL_INIT_ADD_ALL_CIPHERS 0x00000004L |
550 | 3 | #define OPENSSL_INIT_ADD_ALL_DIGESTS 0x00000008L |
551 | 2 | #define OPENSSL_INIT_NO_ADD_ALL_CIPHERS 0x00000010L |
552 | 2 | #define OPENSSL_INIT_NO_ADD_ALL_DIGESTS 0x00000020L |
553 | 2 | #define OPENSSL_INIT_LOAD_CONFIG 0x00000040L |
554 | 2 | #define OPENSSL_INIT_NO_LOAD_CONFIG 0x00000080L |
555 | 2 | #define OPENSSL_INIT_ASYNC 0x00000100L |
556 | | /* FREE: 0x00010000L */ |
557 | 2 | #define OPENSSL_INIT_ATFORK 0x00020000L |
558 | | /* OPENSSL_INIT_BASE_ONLY 0x00040000L */ |
559 | | #define OPENSSL_INIT_NO_ATEXIT 0x00080000L |
560 | | /* OPENSSL_INIT flag range 0x03f00000 reserved for OPENSSL_init_ssl() */ |
561 | | /* FREE: 0x04000000L */ |
562 | | /* FREE: 0x08000000L */ |
563 | | /* FREE: 0x10000000L */ |
564 | | /* FREE: 0x20000000L */ |
565 | | /* FREE: 0x40000000L */ |
566 | | /* FREE: 0x80000000L */ |
567 | | /* Max OPENSSL_INIT flag value is 0x80000000 */ |
568 | | |
569 | | /* ENGINEs are no longer available */ |
570 | | #define OPENSSL_INIT_ENGINE_ALL_BUILTIN 0 |
571 | | |
572 | | #ifdef OPENSSL_ENGINE_STUBS |
573 | | #define OPENSSL_INIT_ENGINE_RDRAND 0 |
574 | | #define OPENSSL_INIT_ENGINE_DYNAMIC 0 |
575 | | #define OPENSSL_INIT_ENGINE_OPENSSL 0 |
576 | | #define OPENSSL_INIT_ENGINE_CRYPTODEV 0 |
577 | | #define OPENSSL_INIT_ENGINE_CAPI 0 |
578 | | #define OPENSSL_INIT_ENGINE_PADLOCK 0 |
579 | | #define OPENSSL_INIT_ENGINE_AFALG 0 |
580 | | #endif |
581 | | |
582 | | /* Library initialisation functions */ |
583 | | void OPENSSL_cleanup(void); |
584 | | int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings); |
585 | | void OPENSSL_thread_stop(void); |
586 | | void OPENSSL_thread_stop_ex(OSSL_LIB_CTX *ctx); |
587 | | |
588 | | /* Low-level control of initialization */ |
589 | | OPENSSL_INIT_SETTINGS *OPENSSL_INIT_new(void); |
590 | | #ifndef OPENSSL_NO_STDIO |
591 | | int OPENSSL_INIT_set_config_filename(OPENSSL_INIT_SETTINGS *settings, |
592 | | const char *config_filename); |
593 | | void OPENSSL_INIT_set_config_file_flags(OPENSSL_INIT_SETTINGS *settings, |
594 | | unsigned long flags); |
595 | | int OPENSSL_INIT_set_config_appname(OPENSSL_INIT_SETTINGS *settings, |
596 | | const char *config_appname); |
597 | | #endif |
598 | | void OPENSSL_INIT_free(OPENSSL_INIT_SETTINGS *settings); |
599 | | |
600 | | #if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG) |
601 | | #if defined(_WIN32) |
602 | | #if defined(BASETYPES) || defined(_WINDEF_H) |
603 | | /* application has to include <windows.h> in order to use this */ |
604 | | typedef DWORD CRYPTO_THREAD_LOCAL; |
605 | | typedef DWORD CRYPTO_THREAD_ID; |
606 | | |
607 | | typedef LONG CRYPTO_ONCE; |
608 | | #define CRYPTO_ONCE_STATIC_INIT 0 |
609 | | #endif |
610 | | #else |
611 | | #if defined(__TANDEM) && defined(_SPT_MODEL_) |
612 | | #define SPT_THREAD_SIGNAL 1 |
613 | | #define SPT_THREAD_AWARE 1 |
614 | | #include <spthread.h> |
615 | | #else |
616 | | #include <pthread.h> |
617 | | #endif |
618 | | typedef pthread_once_t CRYPTO_ONCE; |
619 | | typedef pthread_key_t CRYPTO_THREAD_LOCAL; |
620 | | typedef pthread_t CRYPTO_THREAD_ID; |
621 | | |
622 | | #define CRYPTO_ONCE_STATIC_INIT PTHREAD_ONCE_INIT |
623 | | #endif |
624 | | #endif |
625 | | |
626 | | #if !defined(CRYPTO_ONCE_STATIC_INIT) |
627 | | typedef unsigned int CRYPTO_ONCE; |
628 | | typedef unsigned int CRYPTO_THREAD_LOCAL; |
629 | | typedef unsigned int CRYPTO_THREAD_ID; |
630 | | #define CRYPTO_ONCE_STATIC_INIT 0 |
631 | | #endif |
632 | | |
633 | | int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void)); |
634 | | |
635 | | int CRYPTO_THREAD_init_local(CRYPTO_THREAD_LOCAL *key, void (*cleanup)(void *)); |
636 | | void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key); |
637 | | int CRYPTO_THREAD_set_local(CRYPTO_THREAD_LOCAL *key, void *val); |
638 | | int CRYPTO_THREAD_cleanup_local(CRYPTO_THREAD_LOCAL *key); |
639 | | |
640 | | CRYPTO_THREAD_ID CRYPTO_THREAD_get_current_id(void); |
641 | | int CRYPTO_THREAD_compare_id(CRYPTO_THREAD_ID a, CRYPTO_THREAD_ID b); |
642 | | |
643 | | OSSL_LIB_CTX *OSSL_LIB_CTX_new(void); |
644 | | OSSL_LIB_CTX *OSSL_LIB_CTX_new_from_dispatch(const OSSL_CORE_HANDLE *handle, |
645 | | const OSSL_DISPATCH *in); |
646 | | OSSL_LIB_CTX *OSSL_LIB_CTX_new_child(const OSSL_CORE_HANDLE *handle, |
647 | | const OSSL_DISPATCH *in); |
648 | | int OSSL_LIB_CTX_load_config(OSSL_LIB_CTX *ctx, const char *config_file); |
649 | | void OSSL_LIB_CTX_free(OSSL_LIB_CTX *); |
650 | | OSSL_LIB_CTX *OSSL_LIB_CTX_get0_global_default(void); |
651 | | OSSL_LIB_CTX *OSSL_LIB_CTX_set0_default(OSSL_LIB_CTX *libctx); |
652 | | int OSSL_LIB_CTX_get_conf_diagnostics(OSSL_LIB_CTX *ctx); |
653 | | void OSSL_LIB_CTX_set_conf_diagnostics(OSSL_LIB_CTX *ctx, int value); |
654 | | |
655 | | void OSSL_sleep(uint64_t millis); |
656 | | |
657 | | void *OSSL_LIB_CTX_get_data(OSSL_LIB_CTX *ctx, int index); |
658 | | |
659 | | #ifdef __cplusplus |
660 | | } |
661 | | #endif |
662 | | #endif |