summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/evp_local.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/evp/evp_local.h')
-rw-r--r--src/lib/libcrypto/evp/evp_local.h324
1 files changed, 324 insertions, 0 deletions
diff --git a/src/lib/libcrypto/evp/evp_local.h b/src/lib/libcrypto/evp/evp_local.h
new file mode 100644
index 0000000000..ba34a7949d
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_local.h
@@ -0,0 +1,324 @@
1/* $OpenBSD: evp_local.h,v 1.1 2022/11/26 16:08:52 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_EVP_LOCL_H
60#define HEADER_EVP_LOCL_H
61
62__BEGIN_HIDDEN_DECLS
63
64/*
65 * Don't free md_ctx->pctx in EVP_MD_CTX_cleanup(). Needed for ownership
66 * handling in EVP_MD_CTX_set_pkey_ctx().
67 */
68#define EVP_MD_CTX_FLAG_KEEP_PKEY_CTX 0x0400
69
70typedef int evp_sign_method(int type, const unsigned char *m,
71 unsigned int m_length, unsigned char *sigret, unsigned int *siglen,
72 void *key);
73typedef int evp_verify_method(int type, const unsigned char *m,
74 unsigned int m_length, const unsigned char *sigbuf, unsigned int siglen,
75 void *key);
76
77struct ecx_key_st {
78 int nid;
79 int key_len;
80 uint8_t *priv_key;
81 size_t priv_key_len;
82 uint8_t *pub_key;
83 size_t pub_key_len;
84};
85
86/* Type needs to be a bit field
87 * Sub-type needs to be for variations on the method, as in, can it do
88 * arbitrary encryption.... */
89struct evp_pkey_st {
90 int type;
91 int save_type;
92 int references;
93 const EVP_PKEY_ASN1_METHOD *ameth;
94 ENGINE *engine;
95 union {
96 void *ptr;
97#ifndef OPENSSL_NO_RSA
98 struct rsa_st *rsa; /* RSA */
99#endif
100#ifndef OPENSSL_NO_DSA
101 struct dsa_st *dsa; /* DSA */
102#endif
103#ifndef OPENSSL_NO_DH
104 struct dh_st *dh; /* DH */
105#endif
106#ifndef OPENSSL_NO_EC
107 struct ec_key_st *ec; /* ECC */
108 struct ecx_key_st *ecx; /* ECX */
109#endif
110#ifndef OPENSSL_NO_GOST
111 struct gost_key_st *gost; /* GOST */
112#endif
113 } pkey;
114 int save_parameters;
115 STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
116} /* EVP_PKEY */;
117
118struct env_md_st {
119 int type;
120 int pkey_type;
121 int md_size;
122 unsigned long flags;
123 int (*init)(EVP_MD_CTX *ctx);
124 int (*update)(EVP_MD_CTX *ctx, const void *data, size_t count);
125 int (*final)(EVP_MD_CTX *ctx, unsigned char *md);
126 int (*copy)(EVP_MD_CTX *to, const EVP_MD_CTX *from);
127 int (*cleanup)(EVP_MD_CTX *ctx);
128
129 int block_size;
130 int ctx_size; /* how big does the ctx->md_data need to be */
131 /* control function */
132 int (*md_ctrl)(EVP_MD_CTX *ctx, int cmd, int p1, void *p2);
133} /* EVP_MD */;
134
135struct env_md_ctx_st {
136 const EVP_MD *digest;
137 ENGINE *engine; /* functional reference if 'digest' is ENGINE-provided */
138 unsigned long flags;
139 void *md_data;
140 /* Public key context for sign/verify */
141 EVP_PKEY_CTX *pctx;
142 /* Update function: usually copied from EVP_MD */
143 int (*update)(EVP_MD_CTX *ctx, const void *data, size_t count);
144} /* EVP_MD_CTX */;
145
146struct evp_cipher_st {
147 int nid;
148 int block_size;
149 int key_len; /* Default value for variable length ciphers */
150 int iv_len;
151 unsigned long flags; /* Various flags */
152 int (*init)(EVP_CIPHER_CTX *ctx, const unsigned char *key,
153 const unsigned char *iv, int enc); /* init key */
154 int (*do_cipher)(EVP_CIPHER_CTX *ctx, unsigned char *out,
155 const unsigned char *in, size_t inl);/* encrypt/decrypt data */
156 void (*cleanup)(EVP_CIPHER_CTX *); /* cleanup ctx */
157 int ctx_size; /* how big ctx->cipher_data needs to be */
158 int (*set_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Populate a ASN1_TYPE with parameters */
159 int (*get_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Get parameters from a ASN1_TYPE */
160 int (*ctrl)(EVP_CIPHER_CTX *, int type, int arg, void *ptr); /* Miscellaneous operations */
161 void *app_data; /* Application data */
162} /* EVP_CIPHER */;
163
164struct evp_cipher_ctx_st {
165 const EVP_CIPHER *cipher;
166 ENGINE *engine; /* functional reference if 'cipher' is ENGINE-provided */
167 int encrypt; /* encrypt or decrypt */
168 int buf_len; /* number we have left */
169
170 unsigned char oiv[EVP_MAX_IV_LENGTH]; /* original iv */
171 unsigned char iv[EVP_MAX_IV_LENGTH]; /* working iv */
172 unsigned char buf[EVP_MAX_BLOCK_LENGTH];/* saved partial block */
173 int num; /* used by cfb/ofb/ctr mode */
174
175 void *app_data; /* application stuff */
176 int key_len; /* May change for variable length cipher */
177 unsigned long flags; /* Various flags */
178 void *cipher_data; /* per EVP data */
179 int final_used;
180 int block_mask;
181 unsigned char final[EVP_MAX_BLOCK_LENGTH];/* possible final block */
182} /* EVP_CIPHER_CTX */;
183
184struct evp_Encode_Ctx_st {
185
186 int num; /* number saved in a partial encode/decode */
187 int length; /* The length is either the output line length
188 * (in input bytes) or the shortest input line
189 * length that is ok. Once decoding begins,
190 * the length is adjusted up each time a longer
191 * line is decoded */
192 unsigned char enc_data[80]; /* data to encode */
193 int line_num; /* number read on current line */
194 int expect_nl;
195} /* EVP_ENCODE_CTX */;
196
197#define EVP_MAXCHUNK ((size_t)1<<(sizeof(long)*8-2))
198
199struct evp_pkey_ctx_st {
200 /* Method associated with this operation */
201 const EVP_PKEY_METHOD *pmeth;
202 /* Engine that implements this method or NULL if builtin */
203 ENGINE *engine;
204 /* Key: may be NULL */
205 EVP_PKEY *pkey;
206 /* Peer key for key agreement, may be NULL */
207 EVP_PKEY *peerkey;
208 /* Actual operation */
209 int operation;
210 /* Algorithm specific data */
211 void *data;
212 /* Application specific data */
213 void *app_data;
214 /* Keygen callback */
215 EVP_PKEY_gen_cb *pkey_gencb;
216 /* implementation specific keygen data */
217 int *keygen_info;
218 int keygen_info_count;
219} /* EVP_PKEY_CTX */;
220
221#define EVP_PKEY_FLAG_DYNAMIC 1
222
223struct evp_pkey_method_st {
224 int pkey_id;
225 int flags;
226
227 int (*init)(EVP_PKEY_CTX *ctx);
228 int (*copy)(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src);
229 void (*cleanup)(EVP_PKEY_CTX *ctx);
230
231 int (*paramgen_init)(EVP_PKEY_CTX *ctx);
232 int (*paramgen)(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey);
233
234 int (*keygen_init)(EVP_PKEY_CTX *ctx);
235 int (*keygen)(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey);
236
237 int (*sign_init)(EVP_PKEY_CTX *ctx);
238 int (*sign)(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
239 const unsigned char *tbs, size_t tbslen);
240
241 int (*verify_init)(EVP_PKEY_CTX *ctx);
242 int (*verify)(EVP_PKEY_CTX *ctx,
243 const unsigned char *sig, size_t siglen,
244 const unsigned char *tbs, size_t tbslen);
245
246 int (*verify_recover_init)(EVP_PKEY_CTX *ctx);
247 int (*verify_recover)(EVP_PKEY_CTX *ctx,
248 unsigned char *rout, size_t *routlen,
249 const unsigned char *sig, size_t siglen);
250
251 int (*signctx_init)(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx);
252 int (*signctx)(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
253 EVP_MD_CTX *mctx);
254
255 int (*verifyctx_init)(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx);
256 int (*verifyctx)(EVP_PKEY_CTX *ctx, const unsigned char *sig,
257 int siglen, EVP_MD_CTX *mctx);
258
259 int (*encrypt_init)(EVP_PKEY_CTX *ctx);
260 int (*encrypt)(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
261 const unsigned char *in, size_t inlen);
262
263 int (*decrypt_init)(EVP_PKEY_CTX *ctx);
264 int (*decrypt)(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
265 const unsigned char *in, size_t inlen);
266
267 int (*derive_init)(EVP_PKEY_CTX *ctx);
268 int (*derive)(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen);
269
270 int (*ctrl)(EVP_PKEY_CTX *ctx, int type, int p1, void *p2);
271 int (*ctrl_str)(EVP_PKEY_CTX *ctx, const char *type, const char *value);
272
273 int (*digestsign)(EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen,
274 const unsigned char *tbs, size_t tbslen);
275 int (*digestverify) (EVP_MD_CTX *ctx, const unsigned char *sig,
276 size_t siglen, const unsigned char *tbs, size_t tbslen);
277
278 int (*check)(EVP_PKEY *pkey);
279 int (*public_check)(EVP_PKEY *pkey);
280 int (*param_check)(EVP_PKEY *pkey);
281} /* EVP_PKEY_METHOD */;
282
283void evp_pkey_set_cb_translate(BN_GENCB *cb, EVP_PKEY_CTX *ctx);
284
285int PKCS5_v2_PBKDF2_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
286 ASN1_TYPE *param, const EVP_CIPHER *c, const EVP_MD *md, int en_de);
287
288/* EVP_AEAD represents a specific AEAD algorithm. */
289struct evp_aead_st {
290 unsigned char key_len;
291 unsigned char nonce_len;
292 unsigned char overhead;
293 unsigned char max_tag_len;
294
295 int (*init)(struct evp_aead_ctx_st*, const unsigned char *key,
296 size_t key_len, size_t tag_len);
297 void (*cleanup)(struct evp_aead_ctx_st*);
298
299 int (*seal)(const struct evp_aead_ctx_st *ctx, unsigned char *out,
300 size_t *out_len, size_t max_out_len, const unsigned char *nonce,
301 size_t nonce_len, const unsigned char *in, size_t in_len,
302 const unsigned char *ad, size_t ad_len);
303
304 int (*open)(const struct evp_aead_ctx_st *ctx, unsigned char *out,
305 size_t *out_len, size_t max_out_len, const unsigned char *nonce,
306 size_t nonce_len, const unsigned char *in, size_t in_len,
307 const unsigned char *ad, size_t ad_len);
308};
309
310/* An EVP_AEAD_CTX represents an AEAD algorithm configured with a specific key
311 * and message-independent IV. */
312struct evp_aead_ctx_st {
313 const EVP_AEAD *aead;
314 /* aead_state is an opaque pointer to the AEAD specific state. */
315 void *aead_state;
316};
317
318int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *str);
319int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *hex);
320int EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md_name);
321
322__END_HIDDEN_DECLS
323
324#endif /* !HEADER_EVP_LOCL_H */