]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/evp/evp_locl.h
Refactor ossl_method_construct() in terms of ossl_algorithm_do_all()
[thirdparty/openssl.git] / crypto / evp / evp_locl.h
CommitLineData
0f113f3e 1/*
c13d2ab4 2 * Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
5da2f69f 3 *
4a8b0c55 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
aa6bb135
RS
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
5da2f69f
DSH
8 */
9
7638370c
RL
10/* EVP_MD_CTX related stuff */
11
ff64702b
MC
12#include <openssl/core_numbers.h>
13
7638370c 14struct evp_md_ctx_st {
b7c913c8 15 const EVP_MD *reqdigest; /* The original requested digest */
7638370c
RL
16 const EVP_MD *digest;
17 ENGINE *engine; /* functional reference if 'digest' is
18 * ENGINE-provided */
19 unsigned long flags;
20 void *md_data;
21 /* Public key context for sign/verify */
22 EVP_PKEY_CTX *pctx;
23 /* Update function: usually copied from EVP_MD */
24 int (*update) (EVP_MD_CTX *ctx, const void *data, size_t count);
8c8cf0d9
MC
25
26 /* Provider ctx */
27 void *provctx;
28 EVP_MD *fetched_digest;
7638370c
RL
29} /* EVP_MD_CTX */ ;
30
8baf9968
RL
31struct evp_cipher_ctx_st {
32 const EVP_CIPHER *cipher;
33 ENGINE *engine; /* functional reference if 'cipher' is
34 * ENGINE-provided */
35 int encrypt; /* encrypt or decrypt */
36 int buf_len; /* number we have left */
37 unsigned char oiv[EVP_MAX_IV_LENGTH]; /* original iv */
38 unsigned char iv[EVP_MAX_IV_LENGTH]; /* working iv */
39 unsigned char buf[EVP_MAX_BLOCK_LENGTH]; /* saved partial block */
40 int num; /* used by cfb/ofb/ctr mode */
41 /* FIXME: Should this even exist? It appears unused */
42 void *app_data; /* application stuff */
43 int key_len; /* May change for variable length cipher */
44 unsigned long flags; /* Various flags */
45 void *cipher_data; /* per EVP data */
46 int final_used;
47 int block_mask;
48 unsigned char final[EVP_MAX_BLOCK_LENGTH]; /* possible final block */
df05f2ce
MC
49
50 /* Provider ctx */
51 void *provctx;
52 EVP_CIPHER *fetched_cipher;
8baf9968
RL
53} /* EVP_CIPHER_CTX */ ;
54
567db2c1
RL
55struct evp_mac_ctx_st {
56 const EVP_MAC *meth; /* Method structure */
57 void *data; /* Individual method data */
58} /* EVP_MAC_CTX */;
59
5a285add 60struct evp_kdf_ctx_st {
d2ba8123 61 const EVP_KDF *meth; /* Method structure */
5a285add
DM
62 EVP_KDF_IMPL *impl; /* Algorithm-specific data */
63} /* EVP_KDF_CTX */ ;
64
a94a3e0d
RL
65struct evp_keymgmt_st {
66 int id; /* libcrypto internal */
67
6b9e3724 68 char *name;
a94a3e0d
RL
69 OSSL_PROVIDER *prov;
70 CRYPTO_REF_COUNT refcnt;
71 CRYPTO_RWLOCK *lock;
72
73 /* Domain parameter routines */
74 OSSL_OP_keymgmt_importdomparams_fn *importdomparams;
75 OSSL_OP_keymgmt_gendomparams_fn *gendomparams;
76 OSSL_OP_keymgmt_freedomparams_fn *freedomparams;
77 OSSL_OP_keymgmt_exportdomparams_fn *exportdomparams;
78 OSSL_OP_keymgmt_importdomparam_types_fn *importdomparam_types;
79 OSSL_OP_keymgmt_exportdomparam_types_fn *exportdomparam_types;
80
81 /* Key routines */
82 OSSL_OP_keymgmt_importkey_fn *importkey;
83 OSSL_OP_keymgmt_genkey_fn *genkey;
84 OSSL_OP_keymgmt_loadkey_fn *loadkey;
85 OSSL_OP_keymgmt_freekey_fn *freekey;
86 OSSL_OP_keymgmt_exportkey_fn *exportkey;
87 OSSL_OP_keymgmt_importkey_types_fn *importkey_types;
88 OSSL_OP_keymgmt_exportkey_types_fn *exportkey_types;
89} /* EVP_KEYMGMT */ ;
90
ff64702b 91struct evp_keyexch_st {
6b9e3724 92 char *name;
ff64702b
MC
93 OSSL_PROVIDER *prov;
94 CRYPTO_REF_COUNT refcnt;
95 CRYPTO_RWLOCK *lock;
96
97 OSSL_OP_keyexch_newctx_fn *newctx;
98 OSSL_OP_keyexch_init_fn *init;
99 OSSL_OP_keyexch_set_peer_fn *set_peer;
100 OSSL_OP_keyexch_derive_fn *derive;
101 OSSL_OP_keyexch_freectx_fn *freectx;
102 OSSL_OP_keyexch_dupctx_fn *dupctx;
35aca9ec 103 OSSL_OP_keyexch_set_params_fn *set_params;
ff64702b
MC
104} /* EVP_KEYEXCH */;
105
0f113f3e
MC
106int PKCS5_v2_PBKDF2_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass,
107 int passlen, ASN1_TYPE *param,
108 const EVP_CIPHER *c, const EVP_MD *md,
109 int en_de);
a0be4fd1
RL
110
111struct evp_Encode_Ctx_st {
112 /* number saved in a partial encode/decode */
113 int num;
114 /*
115 * The length is either the output line length (in input bytes) or the
116 * shortest input line length that is ok. Once decoding begins, the
117 * length is adjusted up each time a longer line is decoded
118 */
119 int length;
120 /* data to encode */
121 unsigned char enc_data[80];
122 /* number read on current line */
123 int line_num;
c0804614 124 unsigned int flags;
a0be4fd1 125};
4a1f3f27
DSH
126
127typedef struct evp_pbe_st EVP_PBE_CTL;
128DEFINE_STACK_OF(EVP_PBE_CTL)
7141ba31
MC
129
130int is_partially_overlapping(const void *ptr1, const void *ptr2, int len);
c13d2ab4
RL
131
132#include <openssl/ossl_typ.h>
133#include <openssl/core.h>
134
135void *evp_generic_fetch(OPENSSL_CTX *ctx, int operation_id,
136 const char *algorithm, const char *properties,
6b9e3724
RL
137 void *(*new_method)(const char *name,
138 const OSSL_DISPATCH *fns,
c13d2ab4 139 OSSL_PROVIDER *prov),
7c95390e 140 int (*up_ref_method)(void *),
0211740f 141 void (*free_method)(void *));
13273237
RL
142
143/* Helper functions to avoid duplicating code */
144
145/*
459b15d4 146 * These methods implement different ways to pass a params array to the
13273237
RL
147 * provider. They will return one of these values:
148 *
149 * -2 if the method doesn't come from a provider
150 * (evp_do_param will return this to the called)
151 * -1 if the provider doesn't offer the desired function
152 * (evp_do_param will raise an error and return 0)
153 * or the return value from the desired function
154 * (evp_do_param will return it to the caller)
155 */
459b15d4
SL
156int evp_do_ciph_getparams(const EVP_CIPHER *ciph, OSSL_PARAM params[]);
157int evp_do_ciph_ctx_getparams(const EVP_CIPHER *ciph, void *provctx,
13273237 158 OSSL_PARAM params[]);
459b15d4 159int evp_do_ciph_ctx_setparams(const EVP_CIPHER *ciph, void *provctx,
13273237 160 OSSL_PARAM params[]);
ff64702b
MC
161
162OSSL_PARAM *evp_pkey_to_param(EVP_PKEY *pkey, size_t *sz);
163
164#define M_check_autoarg(ctx, arg, arglen, err) \
165 if (ctx->pmeth->flags & EVP_PKEY_FLAG_AUTOARGLEN) { \
166 size_t pksize = (size_t)EVP_PKEY_size(ctx->pkey); \
167 \
168 if (pksize == 0) { \
169 EVPerr(err, EVP_R_INVALID_KEY); /*ckerr_ignore*/ \
170 return 0; \
171 } \
172 if (arg == NULL) { \
173 *arglen = pksize; \
174 return 1; \
175 } \
176 if (*arglen < pksize) { \
177 EVPerr(err, EVP_R_BUFFER_TOO_SMALL); /*ckerr_ignore*/ \
178 return 0; \
179 } \
180 }