Path: blob/main/crypto/openssl/include/internal/cryptlib.h
34879 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) || \36defined(__x86_64) || defined(__x86_64__) || \37defined(_M_AMD64) || defined(_M_X64)38# define OPENSSL_IA32CAP_P_MAX_INDEXES 1039extern unsigned int OPENSSL_ia32cap_P[];40#endif4142void OPENSSL_showfatal(const char *fmta, ...);43int ossl_do_ex_data_init(OSSL_LIB_CTX *ctx);44void ossl_crypto_cleanup_all_ex_data_int(OSSL_LIB_CTX *ctx);45int openssl_init_fork_handlers(void);46int openssl_get_fork_id(void);4748char *ossl_safe_getenv(const char *name);4950extern CRYPTO_RWLOCK *memdbg_lock;51int openssl_strerror_r(int errnum, char *buf, size_t buflen);52# if !defined(OPENSSL_NO_STDIO)53FILE *openssl_fopen(const char *filename, const char *mode);54# else55void *openssl_fopen(const char *filename, const char *mode);56# endif5758uint32_t OPENSSL_rdtsc(void);59size_t OPENSSL_instrument_bus(unsigned int *, size_t);60size_t OPENSSL_instrument_bus2(unsigned int *, size_t, size_t);6162/* ex_data structures */6364/*65* Each structure type (sometimes called a class), that supports66* exdata has a stack of callbacks for each instance.67*/68struct ex_callback_st {69long argl; /* Arbitrary long */70void *argp; /* Arbitrary void * */71int priority; /* Priority ordering for freeing */72CRYPTO_EX_new *new_func;73CRYPTO_EX_free *free_func;74CRYPTO_EX_dup *dup_func;75};7677/*78* The state for each class. This could just be a typedef, but79* a structure allows future changes.80*/81typedef struct ex_callbacks_st {82STACK_OF(EX_CALLBACK) *meth;83} EX_CALLBACKS;8485typedef struct ossl_ex_data_global_st {86CRYPTO_RWLOCK *ex_data_lock;87EX_CALLBACKS ex_data[CRYPTO_EX_INDEX__COUNT];88} OSSL_EX_DATA_GLOBAL;8990/* OSSL_LIB_CTX */9192# define OSSL_LIB_CTX_PROVIDER_STORE_RUN_ONCE_INDEX 093# define OSSL_LIB_CTX_DEFAULT_METHOD_STORE_RUN_ONCE_INDEX 194# define OSSL_LIB_CTX_METHOD_STORE_RUN_ONCE_INDEX 295# define OSSL_LIB_CTX_MAX_RUN_ONCE 39697# define OSSL_LIB_CTX_EVP_METHOD_STORE_INDEX 098# define OSSL_LIB_CTX_PROVIDER_STORE_INDEX 199# define OSSL_LIB_CTX_PROPERTY_DEFN_INDEX 2100# define OSSL_LIB_CTX_PROPERTY_STRING_INDEX 3101# define OSSL_LIB_CTX_NAMEMAP_INDEX 4102# define OSSL_LIB_CTX_DRBG_INDEX 5103# define OSSL_LIB_CTX_DRBG_NONCE_INDEX 6104/* slot 7 unused, was CRNG test data and can be reused */105# ifdef FIPS_MODULE106# define OSSL_LIB_CTX_THREAD_EVENT_HANDLER_INDEX 8107# endif108# define OSSL_LIB_CTX_FIPS_PROV_INDEX 9109# define OSSL_LIB_CTX_ENCODER_STORE_INDEX 10110# define OSSL_LIB_CTX_DECODER_STORE_INDEX 11111# define OSSL_LIB_CTX_SELF_TEST_CB_INDEX 12112# define OSSL_LIB_CTX_BIO_PROV_INDEX 13113# define OSSL_LIB_CTX_GLOBAL_PROPERTIES 14114# define OSSL_LIB_CTX_STORE_LOADER_STORE_INDEX 15115# define OSSL_LIB_CTX_PROVIDER_CONF_INDEX 16116# define OSSL_LIB_CTX_BIO_CORE_INDEX 17117# define OSSL_LIB_CTX_CHILD_PROVIDER_INDEX 18118# define OSSL_LIB_CTX_THREAD_INDEX 19119# define OSSL_LIB_CTX_DECODER_CACHE_INDEX 20120# define OSSL_LIB_CTX_COMP_METHODS 21121# define OSSL_LIB_CTX_INDICATOR_CB_INDEX 22122# define OSSL_LIB_CTX_MAX_INDEXES 22123124OSSL_LIB_CTX *ossl_lib_ctx_get_concrete(OSSL_LIB_CTX *ctx);125int ossl_lib_ctx_is_default(OSSL_LIB_CTX *ctx);126int ossl_lib_ctx_is_global_default(OSSL_LIB_CTX *ctx);127128/* Functions to retrieve pointers to data by index */129void *ossl_lib_ctx_get_data(OSSL_LIB_CTX *, int /* index */);130131void ossl_lib_ctx_default_deinit(void);132OSSL_EX_DATA_GLOBAL *ossl_lib_ctx_get_ex_data_global(OSSL_LIB_CTX *ctx);133134const char *ossl_lib_ctx_get_descriptor(OSSL_LIB_CTX *libctx);135CRYPTO_THREAD_LOCAL *ossl_lib_ctx_get_rcukey(OSSL_LIB_CTX *libctx);136137OSSL_LIB_CTX *ossl_crypto_ex_data_get_ossl_lib_ctx(const CRYPTO_EX_DATA *ad);138int ossl_crypto_new_ex_data_ex(OSSL_LIB_CTX *ctx, int class_index, void *obj,139CRYPTO_EX_DATA *ad);140int ossl_crypto_get_ex_new_index_ex(OSSL_LIB_CTX *ctx, int class_index,141long argl, void *argp,142CRYPTO_EX_new *new_func,143CRYPTO_EX_dup *dup_func,144CRYPTO_EX_free *free_func,145int priority);146int ossl_crypto_free_ex_index_ex(OSSL_LIB_CTX *ctx, int class_index, int idx);147148/* Function for simple binary search */149150/* Flags */151# define OSSL_BSEARCH_VALUE_ON_NOMATCH 0x01152# define OSSL_BSEARCH_FIRST_VALUE_ON_MATCH 0x02153154const void *ossl_bsearch(const void *key, const void *base, int num,155int size, int (*cmp) (const void *, const void *),156int flags);157158char *ossl_sk_ASN1_UTF8STRING2text(STACK_OF(ASN1_UTF8STRING) *text,159const char *sep, size_t max_len);160char *ossl_ipaddr_to_asc(unsigned char *p, int len);161162char *ossl_buf2hexstr_sep(const unsigned char *buf, long buflen, char sep);163unsigned char *ossl_hexstr2buf_sep(const char *str, long *buflen,164const char sep);165166/**167* Writes |n| value in hex format into |buf|,168* and returns the number of bytes written169*/170size_t ossl_to_hex(char *buf, uint8_t n);171172STACK_OF(SSL_COMP) *ossl_load_builtin_compressions(void);173void ossl_free_compression_methods_int(STACK_OF(SSL_COMP) *methods);174175#endif176177178