Update copyright year
[openssl.git] / providers / common / include / prov / provider_util.h
1 /*
2  * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
3  *
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
8  */
9
10 #include <openssl/provider.h>
11 #include <openssl/engine.h>
12
13 typedef struct {
14     /*
15      * References to the underlying cipher implementation.  |cipher| caches
16      * the cipher, always.  |alloc_cipher| only holds a reference to an
17      * explicitly fetched cipher.
18      */
19     const EVP_CIPHER *cipher;   /* cipher */
20     EVP_CIPHER *alloc_cipher;   /* fetched cipher */
21
22     /* Conditions for legacy EVP_CIPHER uses */
23     ENGINE *engine;             /* cipher engine */
24 } PROV_CIPHER;
25
26 typedef struct {
27     /*
28      * References to the underlying digest implementation.  |md| caches
29      * the digest, always.  |alloc_md| only holds a reference to an explicitly
30      * fetched digest.
31      */
32     const EVP_MD *md;           /* digest */
33     EVP_MD *alloc_md;           /* fetched digest */
34
35     /* Conditions for legacy EVP_MD uses */
36     ENGINE *engine;             /* digest engine */
37 } PROV_DIGEST;
38
39 /* Cipher functions */
40 /*
41  * Load a cipher from the specified parameters with the specified context.
42  * The params "properties", "engine" and "cipher" are used to determine the
43  * implementation used.  If a provider cannot be found, it falls back to trying
44  * non-provider based implementations.
45  */
46 int ossl_prov_cipher_load_from_params(PROV_CIPHER *pc,
47                                       const OSSL_PARAM params[],
48                                       OPENSSL_CTX *ctx);
49
50 /* Reset the PROV_CIPHER fields and free any allocated cipher reference */
51 void ossl_prov_cipher_reset(PROV_CIPHER *pc);
52
53 /* Clone a PROV_CIPHER structure into a second */
54 int ossl_prov_cipher_copy(PROV_CIPHER *dst, const PROV_CIPHER *src);
55
56 /* Query the cipher and associated engine (if any) */
57 const EVP_CIPHER *ossl_prov_cipher_cipher(const PROV_CIPHER *pc);
58 ENGINE *ossl_prov_cipher_engine(const PROV_CIPHER *pc);
59
60 /* Digest functions */
61 /*
62  * Load a digest from the specified parameters with the specified context.
63  * The params "properties", "engine" and "digest" are used to determine the
64  * implementation used.  If a provider cannot be found, it falls back to trying
65  * non-provider based implementations.
66  */
67 int ossl_prov_digest_load_from_params(PROV_DIGEST *pd,
68                                       const OSSL_PARAM params[],
69                                       OPENSSL_CTX *ctx);
70
71 /* Reset the PROV_DIGEST fields and free any allocated digest reference */
72 void ossl_prov_digest_reset(PROV_DIGEST *pd);
73
74 /* Clone a PROV_DIGEST structure into a second */
75 int ossl_prov_digest_copy(PROV_DIGEST *dst, const PROV_DIGEST *src);
76
77 /* Query the digest and associated engine (if any) */
78 const EVP_MD *ossl_prov_digest_md(const PROV_DIGEST *pd);
79 ENGINE *ossl_prov_digest_engine(const PROV_DIGEST *pd);
80
81 /* MAC functions */
82 /*
83  * Load an EVP_MAC_CTX* from the specified parameters with the specified
84  * library context.
85  * The params "mac" and "properties" are used to determine the implementation
86  * used, and the parameters "digest", "cipher", "engine" and "properties" are
87  * passed to the MAC via the created MAC context if they are given.
88  * If there is already a created MAC context, it will be replaced if the "mac"
89  * parameter is found, otherwise it will simply be used as is, and passed the
90  * parameters to pilfer as it sees fit.
91  *
92  * As an option, a MAC name may be explicitly given, and if it is, the "mac"
93  * parameter will be ignored.
94  * Similarly, as an option, a cipher name or a digest name may be explicitly
95  * given, and if any of them is, the "digest" and "cipher" parameters are
96  * ignored.
97  */
98 int ossl_prov_macctx_load_from_params(EVP_MAC_CTX **macctx,
99                                       const OSSL_PARAM params[],
100                                       const char *macname,
101                                       const char *ciphername,
102                                       const char *mdname,
103                                       OPENSSL_CTX *ctx);
104
105 typedef struct ag_capable_st {
106     OSSL_ALGORITHM alg;
107     int (*capable)(void);
108 } OSSL_ALGORITHM_CAPABLE;
109
110 /*
111  * Dynamically select algorithms by calling a capable() method.
112  * If this method is NULL or the method returns 1 then the algorithm is added.
113  */
114 void ossl_prov_cache_exported_algorithms(const OSSL_ALGORITHM_CAPABLE *in,
115                                          OSSL_ALGORITHM *out);