Path: blob/main/crypto/openssl/include/internal/cryptlib.h
102625 views
/*1* Copyright 1995-2024 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the Apache License 2.0 (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/89#ifndef OSSL_INTERNAL_CRYPTLIB_H10#define OSSL_INTERNAL_CRYPTLIB_H11#pragma once1213#ifdef OPENSSL_USE_APPLINK14#define BIO_FLAGS_UPLINK_INTERNAL 0x800015#include "ms/uplink.h"16#else17#define BIO_FLAGS_UPLINK_INTERNAL 018#endif1920#include "internal/common.h"2122#include <openssl/crypto.h>23#include <openssl/buffer.h>24#include <openssl/bio.h>25#include <openssl/asn1.h>26#include <openssl/err.h>2728typedef struct ex_callback_st EX_CALLBACK;29DEFINE_STACK_OF(EX_CALLBACK)3031typedef struct mem_st MEM;32DEFINE_LHASH_OF_EX(MEM);3334void OPENSSL_cpuid_setup(void);35#if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64)36#define OPENSSL_IA32CAP_P_MAX_INDEXES 1037extern unsigned int OPENSSL_ia32cap_P[];38#endif3940void OPENSSL_showfatal(const char *fmta, ...);41int ossl_do_ex_data_init(OSSL_LIB_CTX *ctx);42void ossl_crypto_cleanup_all_ex_data_int(OSSL_LIB_CTX *ctx);43int openssl_init_fork_handlers(void);44int openssl_get_fork_id(void);4546char *ossl_safe_getenv(const char *name);4748extern CRYPTO_RWLOCK *memdbg_lock;49int openssl_strerror_r(int errnum, char *buf, size_t buflen);50#if !defined(OPENSSL_NO_STDIO)51FILE *openssl_fopen(const char *filename, const char *mode);52#else53void *openssl_fopen(const char *filename, const char *mode);54#endif5556uint32_t OPENSSL_rdtsc(void);57size_t OPENSSL_instrument_bus(unsigned int *, size_t);58size_t OPENSSL_instrument_bus2(unsigned int *, size_t, size_t);5960/* ex_data structures */6162/*63* Each structure type (sometimes called a class), that supports64* exdata has a stack of callbacks for each instance.65*/66struct ex_callback_st {67long argl; /* Arbitrary long */68void *argp; /* Arbitrary void * */69int priority; /* Priority ordering for freeing */70CRYPTO_EX_new *new_func;71CRYPTO_EX_free *free_func;72CRYPTO_EX_dup *dup_func;73};7475/*76* The state for each class. This could just be a typedef, but77* a structure allows future changes.78*/79typedef struct ex_callbacks_st {80STACK_OF(EX_CALLBACK) *meth;81} EX_CALLBACKS;8283typedef struct ossl_ex_data_global_st {84CRYPTO_RWLOCK *ex_data_lock;85EX_CALLBACKS ex_data[CRYPTO_EX_INDEX__COUNT];86} OSSL_EX_DATA_GLOBAL;8788/* OSSL_LIB_CTX */8990#define OSSL_LIB_CTX_PROVIDER_STORE_RUN_ONCE_INDEX 091#define OSSL_LIB_CTX_DEFAULT_METHOD_STORE_RUN_ONCE_INDEX 192#define OSSL_LIB_CTX_METHOD_STORE_RUN_ONCE_INDEX 293#define OSSL_LIB_CTX_MAX_RUN_ONCE 39495#define OSSL_LIB_CTX_EVP_METHOD_STORE_INDEX 096#define OSSL_LIB_CTX_PROVIDER_STORE_INDEX 197#define OSSL_LIB_CTX_PROPERTY_DEFN_INDEX 298#define OSSL_LIB_CTX_PROPERTY_STRING_INDEX 399#define OSSL_LIB_CTX_NAMEMAP_INDEX 4100#define OSSL_LIB_CTX_DRBG_INDEX 5101#define OSSL_LIB_CTX_DRBG_NONCE_INDEX 6102/* slot 7 unused, was CRNG test data and can be reused */103#ifdef FIPS_MODULE104#define OSSL_LIB_CTX_THREAD_EVENT_HANDLER_INDEX 8105#endif106#define OSSL_LIB_CTX_FIPS_PROV_INDEX 9107#define OSSL_LIB_CTX_ENCODER_STORE_INDEX 10108#define OSSL_LIB_CTX_DECODER_STORE_INDEX 11109#define OSSL_LIB_CTX_SELF_TEST_CB_INDEX 12110#define OSSL_LIB_CTX_BIO_PROV_INDEX 13111#define OSSL_LIB_CTX_GLOBAL_PROPERTIES 14112#define OSSL_LIB_CTX_STORE_LOADER_STORE_INDEX 15113#define OSSL_LIB_CTX_PROVIDER_CONF_INDEX 16114#define OSSL_LIB_CTX_BIO_CORE_INDEX 17115#define OSSL_LIB_CTX_CHILD_PROVIDER_INDEX 18116#define OSSL_LIB_CTX_THREAD_INDEX 19117#define OSSL_LIB_CTX_DECODER_CACHE_INDEX 20118#define OSSL_LIB_CTX_COMP_METHODS 21119#define OSSL_LIB_CTX_INDICATOR_CB_INDEX 22120#define OSSL_LIB_CTX_MAX_INDEXES 22121122OSSL_LIB_CTX *ossl_lib_ctx_get_concrete(OSSL_LIB_CTX *ctx);123int ossl_lib_ctx_is_default(OSSL_LIB_CTX *ctx);124int ossl_lib_ctx_is_global_default(OSSL_LIB_CTX *ctx);125126/* Functions to retrieve pointers to data by index */127void *ossl_lib_ctx_get_data(OSSL_LIB_CTX *, int /* index */);128129void ossl_lib_ctx_default_deinit(void);130OSSL_EX_DATA_GLOBAL *ossl_lib_ctx_get_ex_data_global(OSSL_LIB_CTX *ctx);131132const char *ossl_lib_ctx_get_descriptor(OSSL_LIB_CTX *libctx);133CRYPTO_THREAD_LOCAL *ossl_lib_ctx_get_rcukey(OSSL_LIB_CTX *libctx);134135OSSL_LIB_CTX *ossl_crypto_ex_data_get_ossl_lib_ctx(const CRYPTO_EX_DATA *ad);136int ossl_crypto_new_ex_data_ex(OSSL_LIB_CTX *ctx, int class_index, void *obj,137CRYPTO_EX_DATA *ad);138int ossl_crypto_get_ex_new_index_ex(OSSL_LIB_CTX *ctx, int class_index,139long argl, void *argp,140CRYPTO_EX_new *new_func,141CRYPTO_EX_dup *dup_func,142CRYPTO_EX_free *free_func,143int priority);144int ossl_crypto_free_ex_index_ex(OSSL_LIB_CTX *ctx, int class_index, int idx);145146/* Function for simple binary search */147148/* Flags */149#define OSSL_BSEARCH_VALUE_ON_NOMATCH 0x01150#define OSSL_BSEARCH_FIRST_VALUE_ON_MATCH 0x02151152const void *ossl_bsearch(const void *key, const void *base, int num,153int size, int (*cmp)(const void *, const void *),154int flags);155156char *ossl_sk_ASN1_UTF8STRING2text(STACK_OF(ASN1_UTF8STRING) *text,157const char *sep, size_t max_len);158char *ossl_ipaddr_to_asc(unsigned char *p, int len);159160char *ossl_buf2hexstr_sep(const unsigned char *buf, long buflen, char sep);161unsigned char *ossl_hexstr2buf_sep(const char *str, long *buflen,162const char sep);163164/**165* Writes |n| value in hex format into |buf|,166* and returns the number of bytes written167*/168size_t ossl_to_hex(char *buf, uint8_t n);169170STACK_OF(SSL_COMP) *ossl_load_builtin_compressions(void);171void ossl_free_compression_methods_int(STACK_OF(SSL_COMP) *methods);172173#endif174175176