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