Path: blob/main/crypto/openssl/providers/common/include/prov/provider_util.h
48534 views
/*1* Copyright 2019-2025 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#include <openssl/provider.h>10#include <openssl/types.h>1112typedef struct {13/*14* References to the underlying cipher implementation. |cipher| caches15* the cipher, always. |alloc_cipher| only holds a reference to an16* explicitly fetched cipher.17*/18const EVP_CIPHER *cipher; /* cipher */19EVP_CIPHER *alloc_cipher; /* fetched cipher */2021/* Conditions for legacy EVP_CIPHER uses */22ENGINE *engine; /* cipher engine */23} PROV_CIPHER;2425typedef struct {26/*27* References to the underlying digest implementation. |md| caches28* the digest, always. |alloc_md| only holds a reference to an explicitly29* fetched digest.30*/31const EVP_MD *md; /* digest */32EVP_MD *alloc_md; /* fetched digest */3334/* Conditions for legacy EVP_MD uses */35ENGINE *engine; /* digest engine */36} PROV_DIGEST;3738/* Cipher functions */39/*40* Load a cipher from the specified parameters with the specified context.41* The params "properties", "engine" and "cipher" are used to determine the42* implementation used. If a provider cannot be found, it falls back to trying43* non-provider based implementations.44*/45int ossl_prov_cipher_load_from_params(PROV_CIPHER *pc,46const OSSL_PARAM params[],47OSSL_LIB_CTX *ctx);4849/* Reset the PROV_CIPHER fields and free any allocated cipher reference */50void ossl_prov_cipher_reset(PROV_CIPHER *pc);5152/* Clone a PROV_CIPHER structure into a second */53int ossl_prov_cipher_copy(PROV_CIPHER *dst, const PROV_CIPHER *src);5455/* Query the cipher and associated engine (if any) */56const EVP_CIPHER *ossl_prov_cipher_cipher(const PROV_CIPHER *pc);57ENGINE *ossl_prov_cipher_engine(const PROV_CIPHER *pc);5859/* Digest functions */6061/*62* Fetch a digest from the specified libctx using the provided mdname and63* propquery. Store the result in the PROV_DIGEST and return the fetched md.64*/65const EVP_MD *ossl_prov_digest_fetch(PROV_DIGEST *pd, OSSL_LIB_CTX *libctx,66const char *mdname, const char *propquery);6768/*69* Load a digest from the specified parameters with the specified context.70* The params "properties", "engine" and "digest" are used to determine the71* implementation used. If a provider cannot be found, it falls back to trying72* non-provider based implementations.73*/74int ossl_prov_digest_load_from_params(PROV_DIGEST *pd,75const OSSL_PARAM params[],76OSSL_LIB_CTX *ctx);7778/* Reset the PROV_DIGEST fields and free any allocated digest reference */79void ossl_prov_digest_reset(PROV_DIGEST *pd);8081/* Clone a PROV_DIGEST structure into a second */82int ossl_prov_digest_copy(PROV_DIGEST *dst, const PROV_DIGEST *src);8384/* Query the digest and associated engine (if any) */85const EVP_MD *ossl_prov_digest_md(const PROV_DIGEST *pd);86ENGINE *ossl_prov_digest_engine(const PROV_DIGEST *pd);8788/* Set a specific md, resets current digests first */89void ossl_prov_digest_set_md(PROV_DIGEST *pd, EVP_MD *md);9091/*92* Set the various parameters on an EVP_MAC_CTX from the supplied arguments.93* If any of the supplied ciphername/mdname etc are NULL then the values94* from the supplied params (if non NULL) are used instead.95*/96int ossl_prov_set_macctx(EVP_MAC_CTX *macctx,97const OSSL_PARAM params[],98const char *ciphername,99const char *mdname,100const char *engine,101const char *properties,102const unsigned char *key,103size_t keylen);104105/* MAC functions */106/*107* Load an EVP_MAC_CTX* from the specified parameters with the specified108* library context.109* The params "mac" and "properties" are used to determine the implementation110* used, and the parameters "digest", "cipher", "engine" and "properties" are111* passed to the MAC via the created MAC context if they are given.112* If there is already a created MAC context, it will be replaced if the "mac"113* parameter is found, otherwise it will simply be used as is, and passed the114* parameters to pilfer as it sees fit.115*116* As an option, a MAC name may be explicitly given, and if it is, the "mac"117* parameter will be ignored.118* Similarly, as an option, a cipher name or a digest name may be explicitly119* given, and if any of them is, the "digest" and "cipher" parameters are120* ignored.121*/122int ossl_prov_macctx_load_from_params(EVP_MAC_CTX **macctx,123const OSSL_PARAM params[],124const char *macname,125const char *ciphername,126const char *mdname,127OSSL_LIB_CTX *ctx);128129typedef struct ag_capable_st {130OSSL_ALGORITHM alg;131int (*capable)(void);132} OSSL_ALGORITHM_CAPABLE;133134/*135* Dynamically select algorithms by calling a capable() method.136* If this method is NULL or the method returns 1 then the algorithm is added.137*/138void ossl_prov_cache_exported_algorithms(const OSSL_ALGORITHM_CAPABLE *in,139OSSL_ALGORITHM *out);140141/* Duplicate a lump of memory safely */142int ossl_prov_memdup(const void *src, size_t src_len,143unsigned char **dest, size_t *dest_len);144145146