1PROVIDER-CIPHER(7ossl)              OpenSSL             PROVIDER-CIPHER(7ossl)
2
3
4

NAME

6       provider-cipher - The cipher library <-> provider functions
7

SYNOPSIS

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

DESCRIPTION

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(3) arrays via
64       OSSL_ALGORITHM(3) arrays that are returned by the provider's
65       provider_query_operation() function (see "Provider Functions" in
66       provider-base(7)).
67
68       All these "functions" have a corresponding function type definition
69       named OSSL_FUNC_{name}_fn, and a helper function to retrieve the
70       function pointer from an OSSL_DISPATCH(3) element named
71       OSSL_FUNC_{name}.  For example, the "function"
72       OSSL_FUNC_cipher_newctx() has these:
73
74        typedef void *(OSSL_FUNC_cipher_newctx_fn)(void *provctx);
75        static ossl_inline OSSL_FUNC_cipher_newctx_fn
76            OSSL_FUNC_cipher_newctx(const OSSL_DISPATCH *opf);
77
78       OSSL_DISPATCH(3) arrays are indexed by numbers that are provided as
79       macros in openssl-core_dispatch.h(7), as follows:
80
81        OSSL_FUNC_cipher_newctx               OSSL_FUNC_CIPHER_NEWCTX
82        OSSL_FUNC_cipher_freectx              OSSL_FUNC_CIPHER_FREECTX
83        OSSL_FUNC_cipher_dupctx               OSSL_FUNC_CIPHER_DUPCTX
84
85        OSSL_FUNC_cipher_encrypt_init         OSSL_FUNC_CIPHER_ENCRYPT_INIT
86        OSSL_FUNC_cipher_decrypt_init         OSSL_FUNC_CIPHER_DECRYPT_INIT
87        OSSL_FUNC_cipher_update               OSSL_FUNC_CIPHER_UPDATE
88        OSSL_FUNC_cipher_final                OSSL_FUNC_CIPHER_FINAL
89        OSSL_FUNC_cipher_cipher               OSSL_FUNC_CIPHER_CIPHER
90
91        OSSL_FUNC_cipher_get_params           OSSL_FUNC_CIPHER_GET_PARAMS
92        OSSL_FUNC_cipher_get_ctx_params       OSSL_FUNC_CIPHER_GET_CTX_PARAMS
93        OSSL_FUNC_cipher_set_ctx_params       OSSL_FUNC_CIPHER_SET_CTX_PARAMS
94
95        OSSL_FUNC_cipher_gettable_params      OSSL_FUNC_CIPHER_GETTABLE_PARAMS
96        OSSL_FUNC_cipher_gettable_ctx_params  OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS
97        OSSL_FUNC_cipher_settable_ctx_params  OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS
98
99       A cipher algorithm implementation may not implement all of these
100       functions.  In order to be a consistent set of functions there must at
101       least be a complete set of "encrypt" functions, or a complete set of
102       "decrypt" functions, or a single "cipher" function.  In all cases both
103       the OSSL_FUNC_cipher_newctx and OSSL_FUNC_cipher_freectx functions must
104       be present.  All other functions are optional.
105
106   Context Management Functions
107       OSSL_FUNC_cipher_newctx() should create and return a pointer to a
108       provider side structure for holding context information during a cipher
109       operation.  A pointer to this context will be passed back in a number
110       of the other cipher operation function calls.  The parameter provctx is
111       the provider context generated during provider initialisation (see
112       provider(7)).
113
114       OSSL_FUNC_cipher_freectx() is passed a pointer to the provider side
115       cipher context in the cctx parameter.  This function should free any
116       resources associated with that context.
117
118       OSSL_FUNC_cipher_dupctx() should duplicate the provider side cipher
119       context in the cctx parameter and return the duplicate copy.
120
121   Encryption/Decryption Functions
122       OSSL_FUNC_cipher_encrypt_init() initialises a cipher operation for
123       encryption given a newly created provider side cipher context in the
124       cctx parameter.  The key to be used is given in key which is keylen
125       bytes long.  The IV to be used is given in iv which is ivlen bytes
126       long.  The params, if not NULL, should be set on the context in a
127       manner similar to using OSSL_FUNC_cipher_set_ctx_params().
128
129       OSSL_FUNC_cipher_decrypt_init() is the same as
130       OSSL_FUNC_cipher_encrypt_init() except that it initialises the context
131       for a decryption operation.
132
133       OSSL_FUNC_cipher_update() is called to supply data to be
134       encrypted/decrypted as part of a previously initialised cipher
135       operation.  The cctx parameter contains a pointer to a previously
136       initialised provider side context.  OSSL_FUNC_cipher_update() should
137       encrypt/decrypt inl bytes of data at the location pointed to by in.
138       The encrypted data should be stored in out and the amount of data
139       written to *outl which should not exceed outsize bytes.
140       OSSL_FUNC_cipher_update() may be called multiple times for a single
141       cipher operation.  It is the responsibility of the cipher
142       implementation to handle input lengths that are not multiples of the
143       block length.  In such cases a cipher implementation will typically
144       cache partial blocks of input data until a complete block is obtained.
145       out may be the same location as in but it should not partially overlap.
146       The same expectations apply to outsize as documented for
147       EVP_EncryptUpdate(3) and EVP_DecryptUpdate(3).
148
149       OSSL_FUNC_cipher_final() completes an encryption or decryption started
150       through previous OSSL_FUNC_cipher_encrypt_init() or
151       OSSL_FUNC_cipher_decrypt_init(), and OSSL_FUNC_cipher_update() calls.
152       The cctx parameter contains a pointer to the provider side context.
153       Any final encryption/decryption output should be written to out and the
154       amount of data written to *outl which should not exceed outsize bytes.
155       The same expectations apply to outsize as documented for
156       EVP_EncryptFinal(3) and EVP_DecryptFinal(3).
157
158       OSSL_FUNC_cipher_cipher() performs encryption/decryption using the
159       provider side cipher context in the cctx parameter that should have
160       been previously initialised via a call to
161       OSSL_FUNC_cipher_encrypt_init() or OSSL_FUNC_cipher_decrypt_init().
162       This should call the raw underlying cipher function without any
163       padding.  This will be invoked in the provider as a result of the
164       application calling EVP_Cipher(3).  The application is responsible for
165       ensuring that the input is a multiple of the block length.  The data to
166       be encrypted/decrypted will be in in, and it will be inl bytes in
167       length.  The output from the encryption/decryption should be stored in
168       out and the amount of data stored should be put in *outl which should
169       be no more than outsize bytes.
170
171   Cipher Parameters
172       See OSSL_PARAM(3) for further details on the parameters structure used
173       by these functions.
174
175       OSSL_FUNC_cipher_get_params() gets details of the algorithm
176       implementation and stores them in params.
177
178       OSSL_FUNC_cipher_set_ctx_params() sets cipher operation parameters for
179       the provider side cipher context cctx to params.  Any parameter
180       settings are additional to any that were previously set.  Passing NULL
181       for params should return true.
182
183       OSSL_FUNC_cipher_get_ctx_params() gets cipher operation details details
184       from the given provider side cipher context cctx and stores them in
185       params.  Passing NULL for params should return true.
186
187       OSSL_FUNC_cipher_gettable_params(),
188       OSSL_FUNC_cipher_gettable_ctx_params(), and
189       OSSL_FUNC_cipher_settable_ctx_params() all return constant
190       OSSL_PARAM(3) arrays as descriptors of the parameters that
191       OSSL_FUNC_cipher_get_params(), OSSL_FUNC_cipher_get_ctx_params(), and
192       OSSL_FUNC_cipher_set_ctx_params() can handle, respectively.
193       OSSL_FUNC_cipher_gettable_ctx_params() and
194       OSSL_FUNC_cipher_settable_ctx_params() will return the parameters
195       associated with the provider side context cctx in its current state if
196       it is not NULL.  Otherwise, they return the parameters associated with
197       the provider side algorithm provctx.
198
199       Parameters currently recognised by built-in ciphers are listed in
200       "PARAMETERS" in EVP_EncryptInit(3).  Not all parameters are relevant
201       to, or are understood by all ciphers.
202

RETURN VALUES

204       OSSL_FUNC_cipher_newctx() and OSSL_FUNC_cipher_dupctx() should return
205       the newly created provider side cipher context, or NULL on failure.
206
207       OSSL_FUNC_cipher_encrypt_init(), OSSL_FUNC_cipher_decrypt_init(),
208       OSSL_FUNC_cipher_update(), OSSL_FUNC_cipher_final(),
209       OSSL_FUNC_cipher_cipher(), OSSL_FUNC_cipher_get_params(),
210       OSSL_FUNC_cipher_get_ctx_params() and OSSL_FUNC_cipher_set_ctx_params()
211       should return 1 for success or 0 on error.
212
213       OSSL_FUNC_cipher_gettable_params(),
214       OSSL_FUNC_cipher_gettable_ctx_params() and
215       OSSL_FUNC_cipher_settable_ctx_params() should return a constant
216       OSSL_PARAM(3) array, or NULL if none is offered.
217

SEE ALSO

219       provider(7), OSSL_PROVIDER-FIPS(7), OSSL_PROVIDER-default(7),
220       OSSL_PROVIDER-legacy(7), EVP_CIPHER-AES(7), EVP_CIPHER-ARIA(7),
221       EVP_CIPHER-BLOWFISH(7), EVP_CIPHER-CAMELLIA(7), EVP_CIPHER-CAST(7),
222       EVP_CIPHER-CHACHA(7), EVP_CIPHER-DES(7), EVP_CIPHER-IDEA(7),
223       EVP_CIPHER-RC2(7), EVP_CIPHER-RC4(7), EVP_CIPHER-RC5(7),
224       EVP_CIPHER-SEED(7), EVP_CIPHER-SM4(7), EVP_CIPHER-NULL(7),
225       life_cycle-cipher(7), EVP_EncryptInit(3)
226

HISTORY

228       The provider CIPHER interface was introduced in OpenSSL 3.0.
229
231       Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.
232
233       Licensed under the Apache License 2.0 (the "License").  You may not use
234       this file except in compliance with the License.  You can obtain a copy
235       in the file LICENSE in the source distribution or at
236       <https://www.openssl.org/source/license.html>.
237
238
239
2403.0.9                             2023-07-27            PROVIDER-CIPHER(7ossl)
Impressum