2 * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
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
10 #ifndef HEADER_CRYPTLIB_H
11 # define HEADER_CRYPTLIB_H
16 # ifdef OPENSSL_USE_APPLINK
17 # undef BIO_FLAGS_UPLINK
18 # define BIO_FLAGS_UPLINK 0x8000
19 # include "ms/uplink.h"
22 # include <openssl/crypto.h>
23 # include <openssl/buffer.h>
24 # include <openssl/bio.h>
25 # include <openssl/err.h>
26 # include "internal/nelem.h"
29 # define ossl_assert(x) ((x) != 0)
31 __owur
static ossl_inline
int ossl_assert_int(int expr
, const char *exprstr
,
32 const char *file
, int line
)
35 OPENSSL_die(exprstr
, file
, line
);
40 # define ossl_assert(x) ossl_assert_int((x) != 0, "Assertion failed: "#x, \
46 * Use this inside a union with the field that needs to be aligned to a
47 * reasonable boundary for the platform. The most pessimistic alignment
48 * of the listed types will be used by the compiler.
50 # define OSSL_UNION_ALIGN \
52 ossl_uintmax_t align_int; \
55 typedef struct ex_callback_st EX_CALLBACK
;
57 DEFINE_STACK_OF(EX_CALLBACK
)
59 typedef struct app_mem_info_st APP_INFO
;
61 typedef struct mem_st MEM
;
64 # define OPENSSL_CONF "openssl.cnf"
66 # ifndef OPENSSL_SYS_VMS
67 # define X509_CERT_AREA OPENSSLDIR
68 # define X509_CERT_DIR OPENSSLDIR "/certs"
69 # define X509_CERT_FILE OPENSSLDIR "/cert.pem"
70 # define X509_PRIVATE_DIR OPENSSLDIR "/private"
71 # define CTLOG_FILE OPENSSLDIR "/ct_log_list.cnf"
73 # define X509_CERT_AREA "OSSL$DATAROOT:[000000]"
74 # define X509_CERT_DIR "OSSL$DATAROOT:[CERTS]"
75 # define X509_CERT_FILE "OSSL$DATAROOT:[000000]cert.pem"
76 # define X509_PRIVATE_DIR "OSSL$DATAROOT:[PRIVATE]"
77 # define CTLOG_FILE "OSSL$DATAROOT:[000000]ct_log_list.cnf"
80 # define X509_CERT_DIR_EVP "SSL_CERT_DIR"
81 # define X509_CERT_FILE_EVP "SSL_CERT_FILE"
82 # define CTLOG_FILE_EVP "CTLOG_FILE"
84 /* size of string representations */
85 # define DECIMAL_SIZE(type) ((sizeof(type)*8+2)/3+1)
86 # define HEX_SIZE(type) (sizeof(type)*2)
88 void OPENSSL_cpuid_setup(void);
89 extern unsigned int OPENSSL_ia32cap_P
[];
90 void OPENSSL_showfatal(const char *fmta
, ...);
91 int do_ex_data_init(OPENSSL_CTX
*ctx
);
92 void crypto_cleanup_all_ex_data_int(OPENSSL_CTX
*ctx
);
93 int openssl_init_fork_handlers(void);
95 char *ossl_safe_getenv(const char *name
);
97 extern CRYPTO_RWLOCK
*memdbg_lock
;
98 int openssl_strerror_r(int errnum
, char *buf
, size_t buflen
);
99 # if !defined(OPENSSL_NO_STDIO)
100 FILE *openssl_fopen(const char *filename
, const char *mode
);
102 void *openssl_fopen(const char *filename
, const char *mode
);
105 uint32_t OPENSSL_rdtsc(void);
106 size_t OPENSSL_instrument_bus(unsigned int *, size_t);
107 size_t OPENSSL_instrument_bus2(unsigned int *, size_t, size_t);
109 /* ex_data structures */
112 * Each structure type (sometimes called a class), that supports
113 * exdata has a stack of callbacks for each instance.
115 struct ex_callback_st
{
116 long argl
; /* Arbitrary long */
117 void *argp
; /* Arbitrary void * */
118 CRYPTO_EX_new
*new_func
;
119 CRYPTO_EX_free
*free_func
;
120 CRYPTO_EX_dup
*dup_func
;
124 * The state for each class. This could just be a typedef, but
125 * a structure allows future changes.
127 typedef struct ex_callbacks_st
{
128 STACK_OF(EX_CALLBACK
) *meth
;
131 typedef struct ossl_ex_data_global_st
{
132 CRYPTO_RWLOCK
*ex_data_lock
;
133 EX_CALLBACKS ex_data
[CRYPTO_EX_INDEX__COUNT
];
134 } OSSL_EX_DATA_GLOBAL
;
139 # define OPENSSL_CTX_PROVIDER_STORE_RUN_ONCE_INDEX 0
140 # define OPENSSL_CTX_DEFAULT_METHOD_STORE_RUN_ONCE_INDEX 1
141 # define OPENSSL_CTX_METHOD_STORE_RUN_ONCE_INDEX 2
142 # define OPENSSL_CTX_MAX_RUN_ONCE 3
144 # define OPENSSL_CTX_DEFAULT_METHOD_STORE_INDEX 0
145 # define OPENSSL_CTX_PROVIDER_STORE_INDEX 1
146 # define OPENSSL_CTX_PROPERTY_DEFN_INDEX 2
147 # define OPENSSL_CTX_PROPERTY_STRING_INDEX 3
148 # define OPENSSL_CTX_NAMEMAP_INDEX 4
149 # define OPENSSL_CTX_DRBG_INDEX 5
150 # define OPENSSL_CTX_MAX_INDEXES 6
152 typedef struct openssl_ctx_method
{
153 void *(*new_func
)(OPENSSL_CTX
*ctx
);
154 void (*free_func
)(void *);
155 } OPENSSL_CTX_METHOD
;
157 /* Functions to retrieve pointers to data by index */
158 void *openssl_ctx_get_data(OPENSSL_CTX
*, int /* index */,
159 const OPENSSL_CTX_METHOD
* ctx
);
161 void openssl_ctx_default_deinit(void);
162 OSSL_EX_DATA_GLOBAL
*openssl_ctx_get_ex_data_global(OPENSSL_CTX
*ctx
);
163 typedef int (openssl_ctx_run_once_fn
)(OPENSSL_CTX
*ctx
);
164 typedef void (openssl_ctx_onfree_fn
)(OPENSSL_CTX
*ctx
);
166 int openssl_ctx_run_once(OPENSSL_CTX
*ctx
, unsigned int idx
,
167 openssl_ctx_run_once_fn run_once_fn
);
168 int openssl_ctx_onfree(OPENSSL_CTX
*ctx
, openssl_ctx_onfree_fn onfreefn
);
170 OPENSSL_CTX
*crypto_ex_data_get_openssl_ctx(const CRYPTO_EX_DATA
*ad
);
171 int crypto_new_ex_data_ex(OPENSSL_CTX
*ctx
, int class_index
, void *obj
,
173 int crypto_get_ex_new_index_ex(OPENSSL_CTX
*ctx
, int class_index
,
174 long argl
, void *argp
,
175 CRYPTO_EX_new
*new_func
,
176 CRYPTO_EX_dup
*dup_func
,
177 CRYPTO_EX_free
*free_func
);
178 int crypto_free_ex_index_ex(OPENSSL_CTX
*ctx
, int class_index
, int idx
);
180 /* Function for simple binary search */
183 # define OSSL_BSEARCH_VALUE_ON_NOMATCH 0x01
184 # define OSSL_BSEARCH_FIRST_VALUE_ON_MATCH 0x02
186 const void *ossl_bsearch(const void *key
, const void *base
, int num
,
187 int size
, int (*cmp
) (const void *, const void *),