1PROVIDER-CIPHER(7ossl) OpenSSL PROVIDER-CIPHER(7ossl)
2
3
4
6 provider-cipher - The cipher library <-> provider functions
7
9 #include <openssl/core_dispatch.h>
10 #include <openssl/core_names.h>
11
12 /*
13 * None of these are actual functions, but are displayed like this for
14 * the function signatures for functions that are offered as function
15 * pointers in OSSL_DISPATCH arrays.
16 */
17
18 /* Context management */
19 void *OSSL_FUNC_cipher_newctx(void *provctx);
20 void OSSL_FUNC_cipher_freectx(void *cctx);
21 void *OSSL_FUNC_cipher_dupctx(void *cctx);
22
23 /* Encryption/decryption */
24 int OSSL_FUNC_cipher_encrypt_init(void *cctx, const unsigned char *key,
25 size_t keylen, const unsigned char *iv,
26 size_t ivlen, const OSSL_PARAM params[]);
27 int OSSL_FUNC_cipher_decrypt_init(void *cctx, const unsigned char *key,
28 size_t keylen, const unsigned char *iv,
29 size_t ivlen, const OSSL_PARAM params[]);
30 int OSSL_FUNC_cipher_update(void *cctx, unsigned char *out, size_t *outl,
31 size_t outsize, const unsigned char *in, size_t inl);
32 int OSSL_FUNC_cipher_final(void *cctx, unsigned char *out, size_t *outl,
33 size_t outsize);
34 int OSSL_FUNC_cipher_cipher(void *cctx, unsigned char *out, size_t *outl,
35 size_t outsize, const unsigned char *in, size_t inl);
36
37 /* Cipher parameter descriptors */
38 const OSSL_PARAM *OSSL_FUNC_cipher_gettable_params(void *provctx);
39
40 /* Cipher operation parameter descriptors */
41 const OSSL_PARAM *OSSL_FUNC_cipher_gettable_ctx_params(void *cctx,
42 void *provctx);
43 const OSSL_PARAM *OSSL_FUNC_cipher_settable_ctx_params(void *cctx,
44 void *provctx);
45
46 /* Cipher parameters */
47 int OSSL_FUNC_cipher_get_params(OSSL_PARAM params[]);
48
49 /* Cipher operation parameters */
50 int OSSL_FUNC_cipher_get_ctx_params(void *cctx, OSSL_PARAM params[]);
51 int OSSL_FUNC_cipher_set_ctx_params(void *cctx, const OSSL_PARAM params[]);
52
54 This documentation is primarily aimed at provider authors. See
55 provider(7) for further information.
56
57 The CIPHER operation enables providers to implement cipher algorithms
58 and make them available to applications via the API functions
59 EVP_EncryptInit_ex(3), EVP_EncryptUpdate(3) and EVP_EncryptFinal(3) (as
60 well as the decrypt equivalents and other related functions).
61
62 All "functions" mentioned here are passed as function pointers between
63 libcrypto and the provider in OSSL_DISPATCH arrays via OSSL_ALGORITHM
64 arrays that are returned by the provider's provider_query_operation()
65 function (see "Provider Functions" in provider-base(7)).
66
67 All these "functions" have a corresponding function type definition
68 named OSSL_FUNC_{name}_fn, and a helper function to retrieve the
69 function pointer from an OSSL_DISPATCH element named OSSL_FUNC_{name}.
70 For example, the "function" OSSL_FUNC_cipher_newctx() has these:
71
72 typedef void *(OSSL_FUNC_cipher_newctx_fn)(void *provctx);
73 static ossl_inline OSSL_FUNC_cipher_newctx_fn
74 OSSL_FUNC_cipher_newctx(const OSSL_DISPATCH *opf);
75
76 OSSL_DISPATCH arrays are indexed by numbers that are provided as macros
77 in openssl-core_dispatch.h(7), as follows:
78
79 OSSL_FUNC_cipher_newctx OSSL_FUNC_CIPHER_NEWCTX
80 OSSL_FUNC_cipher_freectx OSSL_FUNC_CIPHER_FREECTX
81 OSSL_FUNC_cipher_dupctx OSSL_FUNC_CIPHER_DUPCTX
82
83 OSSL_FUNC_cipher_encrypt_init OSSL_FUNC_CIPHER_ENCRYPT_INIT
84 OSSL_FUNC_cipher_decrypt_init OSSL_FUNC_CIPHER_DECRYPT_INIT
85 OSSL_FUNC_cipher_update OSSL_FUNC_CIPHER_UPDATE
86 OSSL_FUNC_cipher_final OSSL_FUNC_CIPHER_FINAL
87 OSSL_FUNC_cipher_cipher OSSL_FUNC_CIPHER_CIPHER
88
89 OSSL_FUNC_cipher_get_params OSSL_FUNC_CIPHER_GET_PARAMS
90 OSSL_FUNC_cipher_get_ctx_params OSSL_FUNC_CIPHER_GET_CTX_PARAMS
91 OSSL_FUNC_cipher_set_ctx_params OSSL_FUNC_CIPHER_SET_CTX_PARAMS
92
93 OSSL_FUNC_cipher_gettable_params OSSL_FUNC_CIPHER_GETTABLE_PARAMS
94 OSSL_FUNC_cipher_gettable_ctx_params OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS
95 OSSL_FUNC_cipher_settable_ctx_params OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS
96
97 A cipher algorithm implementation may not implement all of these
98 functions. In order to be a consistent set of functions there must at
99 least be a complete set of "encrypt" functions, or a complete set of
100 "decrypt" functions, or a single "cipher" function. In all cases both
101 the OSSL_FUNC_cipher_newctx and OSSL_FUNC_cipher_freectx functions must
102 be present. All other functions are optional.
103
104 Context Management Functions
105 OSSL_FUNC_cipher_newctx() should create and return a pointer to a
106 provider side structure for holding context information during a cipher
107 operation. A pointer to this context will be passed back in a number
108 of the other cipher operation function calls. The parameter provctx is
109 the provider context generated during provider initialisation (see
110 provider(7)).
111
112 OSSL_FUNC_cipher_freectx() is passed a pointer to the provider side
113 cipher context in the cctx parameter. This function should free any
114 resources associated with that context.
115
116 OSSL_FUNC_cipher_dupctx() should duplicate the provider side cipher
117 context in the cctx parameter and return the duplicate copy.
118
119 Encryption/Decryption Functions
120 OSSL_FUNC_cipher_encrypt_init() initialises a cipher operation for
121 encryption given a newly created provider side cipher context in the
122 cctx parameter. The key to be used is given in key which is keylen
123 bytes long. The IV to be used is given in iv which is ivlen bytes
124 long. The params, if not NULL, should be set on the context in a
125 manner similar to using OSSL_FUNC_cipher_set_ctx_params().
126
127 OSSL_FUNC_cipher_decrypt_init() is the same as
128 OSSL_FUNC_cipher_encrypt_init() except that it initialises the context
129 for a decryption operation.
130
131 OSSL_FUNC_cipher_update() is called to supply data to be
132 encrypted/decrypted as part of a previously initialised cipher
133 operation. The cctx parameter contains a pointer to a previously
134 initialised provider side context. OSSL_FUNC_cipher_update() should
135 encrypt/decrypt inl bytes of data at the location pointed to by in.
136 The encrypted data should be stored in out and the amount of data
137 written to *outl which should not exceed outsize bytes.
138 OSSL_FUNC_cipher_update() may be called multiple times for a single
139 cipher operation. It is the responsibility of the cipher
140 implementation to handle input lengths that are not multiples of the
141 block length. In such cases a cipher implementation will typically
142 cache partial blocks of input data until a complete block is obtained.
143 out may be the same location as in but it should not partially overlap.
144 The same expectations apply to outsize as documented for
145 EVP_EncryptUpdate(3) and EVP_DecryptUpdate(3).
146
147 OSSL_FUNC_cipher_final() completes an encryption or decryption started
148 through previous OSSL_FUNC_cipher_encrypt_init() or
149 OSSL_FUNC_cipher_decrypt_init(), and OSSL_FUNC_cipher_update() calls.
150 The cctx parameter contains a pointer to the provider side context.
151 Any final encryption/decryption output should be written to out and the
152 amount of data written to *outl which should not exceed outsize bytes.
153 The same expectations apply to outsize as documented for
154 EVP_EncryptFinal(3) and EVP_DecryptFinal(3).
155
156 OSSL_FUNC_cipher_cipher() performs encryption/decryption using the
157 provider side cipher context in the cctx parameter that should have
158 been previously initialised via a call to
159 OSSL_FUNC_cipher_encrypt_init() or OSSL_FUNC_cipher_decrypt_init().
160 This should call the raw underlying cipher function without any
161 padding. This will be invoked in the provider as a result of the
162 application calling EVP_Cipher(3). The application is responsible for
163 ensuring that the input is a multiple of the block length. The data to
164 be encrypted/decrypted will be in in, and it will be inl bytes in
165 length. The output from the encryption/decryption should be stored in
166 out and the amount of data stored should be put in *outl which should
167 be no more than outsize bytes.
168
169 Cipher Parameters
170 See OSSL_PARAM(3) for further details on the parameters structure used
171 by these functions.
172
173 OSSL_FUNC_cipher_get_params() gets details of the algorithm
174 implementation and stores them in params.
175
176 OSSL_FUNC_cipher_set_ctx_params() sets cipher operation parameters for
177 the provider side cipher context cctx to params. Any parameter
178 settings are additional to any that were previously set. Passing NULL
179 for params should return true.
180
181 OSSL_FUNC_cipher_get_ctx_params() gets cipher operation details details
182 from the given provider side cipher context cctx and stores them in
183 params. Passing NULL for params should return true.
184
185 OSSL_FUNC_cipher_gettable_params(),
186 OSSL_FUNC_cipher_gettable_ctx_params(), and
187 OSSL_FUNC_cipher_settable_ctx_params() all return constant OSSL_PARAM
188 arrays as descriptors of the parameters that
189 OSSL_FUNC_cipher_get_params(), OSSL_FUNC_cipher_get_ctx_params(), and
190 OSSL_FUNC_cipher_set_ctx_params() can handle, respectively.
191 OSSL_FUNC_cipher_gettable_ctx_params() and
192 OSSL_FUNC_cipher_settable_ctx_params() will return the parameters
193 associated with the provider side context cctx in its current state if
194 it is not NULL. Otherwise, they return the parameters associated with
195 the provider side algorithm provctx.
196
197 Parameters currently recognised by built-in ciphers are listed in
198 "PARAMETERS" in EVP_EncryptInit(3). Not all parameters are relevant
199 to, or are understood by all ciphers.
200
202 OSSL_FUNC_cipher_newctx() and OSSL_FUNC_cipher_dupctx() should return
203 the newly created provider side cipher context, or NULL on failure.
204
205 OSSL_FUNC_cipher_encrypt_init(), OSSL_FUNC_cipher_decrypt_init(),
206 OSSL_FUNC_cipher_update(), OSSL_FUNC_cipher_final(),
207 OSSL_FUNC_cipher_cipher(), OSSL_FUNC_cipher_get_params(),
208 OSSL_FUNC_cipher_get_ctx_params() and OSSL_FUNC_cipher_set_ctx_params()
209 should return 1 for success or 0 on error.
210
211 OSSL_FUNC_cipher_gettable_params(),
212 OSSL_FUNC_cipher_gettable_ctx_params() and
213 OSSL_FUNC_cipher_settable_ctx_params() should return a constant
214 OSSL_PARAM array, or NULL if none is offered.
215
217 provider(7), OSSL_PROVIDER-FIPS(7), OSSL_PROVIDER-default(7),
218 OSSL_PROVIDER-legacy(7), EVP_CIPHER-AES(7), EVP_CIPHER-ARIA(7),
219 EVP_CIPHER-BLOWFISH(7), EVP_CIPHER-CAMELLIA(7), EVP_CIPHER-CAST(7),
220 EVP_CIPHER-CHACHA(7), EVP_CIPHER-DES(7), EVP_CIPHER-IDEA(7),
221 EVP_CIPHER-RC2(7), EVP_CIPHER-RC4(7), EVP_CIPHER-RC5(7),
222 EVP_CIPHER-SEED(7), EVP_CIPHER-SM4(7), life_cycle-cipher(7),
223 EVP_EncryptInit(3)
224
226 The provider CIPHER interface was introduced in OpenSSL 3.0.
227
229 Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
230
231 Licensed under the Apache License 2.0 (the "License"). You may not use
232 this file except in compliance with the License. You can obtain a copy
233 in the file LICENSE in the source distribution or at
234 <https://www.openssl.org/source/license.html>.
235
236
237
2383.0.5 2022-11-01 PROVIDER-CIPHER(7ossl)