2 * Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
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
10 /* EVP_MD_CTX related stuff */
12 #include <openssl/core_numbers.h>
14 struct evp_md_ctx_st {
15 const EVP_MD *reqdigest; /* The original requested digest */
17 ENGINE *engine; /* functional reference if 'digest' is
21 /* Public key context for sign/verify */
23 /* Update function: usually copied from EVP_MD */
24 int (*update) (EVP_MD_CTX *ctx, const void *data, size_t count);
28 EVP_MD *fetched_digest;
31 struct evp_cipher_ctx_st {
32 const EVP_CIPHER *cipher;
33 ENGINE *engine; /* functional reference if 'cipher' is
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 */
48 unsigned char final[EVP_MAX_BLOCK_LENGTH]; /* possible final block */
52 EVP_CIPHER *fetched_cipher;
53 } /* EVP_CIPHER_CTX */ ;
55 struct evp_mac_ctx_st {
56 const EVP_MAC *meth; /* Method structure */
57 void *data; /* Individual method data */
60 struct evp_kdf_ctx_st {
61 const EVP_KDF *meth; /* Method structure */
62 EVP_KDF_IMPL *impl; /* Algorithm-specific data */
65 struct evp_keymgmt_st {
66 int id; /* libcrypto internal */
70 CRYPTO_REF_COUNT refcnt;
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;
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;
91 struct evp_keyexch_st {
94 CRYPTO_REF_COUNT refcnt;
99 OSSL_OP_keyexch_newctx_fn *newctx;
100 OSSL_OP_keyexch_init_fn *init;
101 OSSL_OP_keyexch_set_peer_fn *set_peer;
102 OSSL_OP_keyexch_derive_fn *derive;
103 OSSL_OP_keyexch_freectx_fn *freectx;
104 OSSL_OP_keyexch_dupctx_fn *dupctx;
105 OSSL_OP_keyexch_set_params_fn *set_params;
108 int PKCS5_v2_PBKDF2_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass,
109 int passlen, ASN1_TYPE *param,
110 const EVP_CIPHER *c, const EVP_MD *md,
113 struct evp_Encode_Ctx_st {
114 /* number saved in a partial encode/decode */
117 * The length is either the output line length (in input bytes) or the
118 * shortest input line length that is ok. Once decoding begins, the
119 * length is adjusted up each time a longer line is decoded
123 unsigned char enc_data[80];
124 /* number read on current line */
129 typedef struct evp_pbe_st EVP_PBE_CTL;
130 DEFINE_STACK_OF(EVP_PBE_CTL)
132 int is_partially_overlapping(const void *ptr1, const void *ptr2, int len);
134 #include <openssl/ossl_typ.h>
135 #include <openssl/core.h>
137 void *evp_generic_fetch(OPENSSL_CTX *ctx, int operation_id,
138 const char *algorithm, const char *properties,
139 void *(*new_method)(const char *name,
140 const OSSL_DISPATCH *fns,
141 OSSL_PROVIDER *prov),
142 int (*up_ref_method)(void *),
143 void (*free_method)(void *));
144 void evp_generic_do_all(OPENSSL_CTX *libctx, int operation_id,
145 void (*user_fn)(void *method, void *arg),
147 void *(*new_method)(const char *name,
148 const OSSL_DISPATCH *fns,
149 OSSL_PROVIDER *prov),
150 void (*free_method)(void *));
152 /* Helper functions to avoid duplicating code */
155 * These methods implement different ways to pass a params array to the
156 * provider. They will return one of these values:
158 * -2 if the method doesn't come from a provider
159 * (evp_do_param will return this to the called)
160 * -1 if the provider doesn't offer the desired function
161 * (evp_do_param will raise an error and return 0)
162 * or the return value from the desired function
163 * (evp_do_param will return it to the caller)
165 int evp_do_ciph_getparams(const EVP_CIPHER *ciph, OSSL_PARAM params[]);
166 int evp_do_ciph_ctx_getparams(const EVP_CIPHER *ciph, void *provctx,
167 OSSL_PARAM params[]);
168 int evp_do_ciph_ctx_setparams(const EVP_CIPHER *ciph, void *provctx,
169 OSSL_PARAM params[]);
171 OSSL_PARAM *evp_pkey_to_param(EVP_PKEY *pkey, size_t *sz);
173 #define M_check_autoarg(ctx, arg, arglen, err) \
174 if (ctx->pmeth->flags & EVP_PKEY_FLAG_AUTOARGLEN) { \
175 size_t pksize = (size_t)EVP_PKEY_size(ctx->pkey); \
178 EVPerr(err, EVP_R_INVALID_KEY); /*ckerr_ignore*/ \
185 if (*arglen < pksize) { \
186 EVPerr(err, EVP_R_BUFFER_TOO_SMALL); /*ckerr_ignore*/ \