Document the new EVP_CIPHER and EVP_CIPHER_CTX functionality
[openssl.git] / doc / crypto / EVP_CIPHER_meth_new.pod
1 =pod
2
3 =head1 NAME
4
5 EVP_CIPHER_meth_new, EVP_CIPHER_meth_dup, EVP_CIPHER_meth_free,
6 EVP_CIPHER_meth_set_iv_length, EVP_CIPHER_meth_set_flags,
7 EVP_CIPHER_meth_set_impl_ctx_size, EVP_CIPHER_meth_set_init,
8 EVP_CIPHER_meth_set_do_cipher, EVP_CIPHER_meth_set_cleanup,
9 EVP_CIPHER_meth_set_set_asn1_params, EVP_CIPHER_meth_set_get_asn1_params,
10 EVP_CIPHER_meth_set_ctrl, EVP_CIPHER_meth_get_init,
11 EVP_CIPHER_meth_get_do_cipher, EVP_CIPHER_meth_get_cleanup,
12 EVP_CIPHER_meth_get_set_asn1_params, EVP_CIPHER_meth_get_get_asn1_params,
13 EVP_CIPHER_meth_get_ctrl  - Routines to build up EVP_CIPHER methods
14
15 =head1 SYNOPSIS
16
17  #include <openssl/evp.h>
18
19  EVP_CIPHER *EVP_CIPHER_meth_new(int cipher_type, int block_size, int key_len);
20  EVP_CIPHER *EVP_CIPHER_meth_dup(const EVP_CIPHER *cipher);
21  void EVP_CIPHER_meth_free(EVP_CIPHER *cipher);
22  
23  int EVP_CIPHER_meth_set_iv_length(EVP_CIPHER *cipher, int iv_len);
24  int EVP_CIPHER_meth_set_flags(EVP_CIPHER *cipher, unsigned long flags);
25  int EVP_CIPHER_meth_set_impl_ctx_size(EVP_CIPHER *cipher, int ctx_size);
26  int EVP_CIPHER_meth_set_init(EVP_CIPHER *cipher,
27                               int (*init) (EVP_CIPHER_CTX *ctx,
28                                            const unsigned char *key,
29                                            const unsigned char *iv,
30                                            int enc));
31  int EVP_CIPHER_meth_set_do_cipher(EVP_CIPHER *cipher,
32                                    int (*do_cipher) (EVP_CIPHER_CTX *ctx,
33                                                      unsigned char *out,
34                                                      const unsigned char *in,
35                                                      size_t inl));
36  int EVP_CIPHER_meth_set_cleanup(EVP_CIPHER *cipher,
37                                  int (*cleanup) (EVP_CIPHER_CTX *));
38  int EVP_CIPHER_meth_set_set_asn1_params(EVP_CIPHER *cipher,
39                                          int (*set_asn1_parameters) (EVP_CIPHER_CTX *,
40                                                                      ASN1_TYPE *));
41  int EVP_CIPHER_meth_set_get_asn1_params(EVP_CIPHER *cipher,
42                                          int (*get_asn1_parameters) (EVP_CIPHER_CTX *,
43                                                                      ASN1_TYPE *));
44  int EVP_CIPHER_meth_set_ctrl(EVP_CIPHER *cipher,
45                               int (*ctrl) (EVP_CIPHER_CTX *, int type,
46                                            int arg, void *ptr));
47  
48  int (*EVP_CIPHER_meth_get_init(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx,
49                                                            const unsigned char *key,
50                                                            const unsigned char *iv,
51                                                            int enc);
52  int (*EVP_CIPHER_meth_get_do_cipher(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx,
53                                                                 unsigned char *out,
54                                                                 const unsigned char *in,
55                                                                 size_t inl);
56  int (*EVP_CIPHER_meth_get_cleanup(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *);
57  int (*EVP_CIPHER_meth_get_set_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
58                                                                       ASN1_TYPE *);
59  int (*EVP_CIPHER_meth_get_get_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
60                                                                 ASN1_TYPE *);
61  int (*EVP_CIPHER_meth_get_ctrl(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
62                                                            int type, int arg,
63                                                            void *ptr);
64
65 =head1 DESCRIPTION
66
67 The B<EVP_CIPHER> type is a structure for symmetric cipher method
68 implementation.
69
70 EVP_CIPHER_meth_new() creates a new B<EVP_CIPHER> structure.
71
72 EVP_CIPHER_meth_dup() creates a copy of B<cipher>.
73
74 EVP_CIPHER_meth_free() destroys a B<EVP_CIPHER> structure.
75
76 EVP_CIPHER_meth_iv_length() sets the length of the IV.
77 This is only needed when the implemented cipher mode requires it.
78
79 EVP_CIPHER_meth_set_flags() sets the flags to describe optional
80 behaviours in the particular B<cipher>.
81 With the exception of cipher modes, of which only one may be present,
82 several flags can be or'd together.
83 The available flags are:
84
85 =over 4
86
87 =over 4
88
89 =item The cipher modes:
90
91 =over 4
92
93 =item EVP_CIPH_STREAM_CIPHER
94
95 =item EVP_CIPH_ECB_MODE
96
97 =item EVP_CIPH_CBC_MODE
98
99 =item EVP_CIPH_CFB_MODE
100
101 =item EVP_CIPH_OFB_MODE
102
103 =item EVP_CIPH_CTR_MODE
104
105 =item EVP_CIPH_GCM_MODE
106
107 =item EVP_CIPH_CCM_MODE
108
109 =item EVP_CIPH_XTS_MODE
110
111 =item EVP_CIPH_WRAP_MODE
112
113 =item EVP_CIPH_OCB_MODE
114
115 =back
116
117 =item EVP_CIPH_VARIABLE_LENGTH
118
119 This cipher is of variable length.
120
121 =item EVP_CIPH_CUSTOM_IV
122
123 Storing and initialising the IV is left entirely to the
124 implementation.
125
126 =item EVP_CIPH_ALWAYS_CALL_INIT
127
128 Set this if the implementation's init() function should be called even
129 if B<key> is B<NULL>.
130
131 =item EVP_CIPH_CTRL_INIT
132
133 Set this to have the implementation's ctrl() function called with
134 command code B<EVP_CTRL_INIT> early in its setup.
135
136 =item EVP_CIPH_CUSTOM_KEY_LENGTH
137
138 Checking and setting the key length after creating the B<EVP_CIPHER>
139 is left to the implementation.
140 Whenever someone uses EVP_CIPHER_CTX_set_key_length() on a
141 B<EVP_CIPHER> with this flag set, the implementation's ctrl() function
142 will be called with the control code B<EVP_CTRL_SET_KEY_LENGTH> and
143 the key length in B<arg>.
144
145 =item EVP_CIPH_NO_PADDING
146
147 Don't use standard block padding.
148
149 =item EVP_CIPH_RAND_KEY
150
151 Making a key with random content is left to the implementation.
152 This is done by calling the implementation's ctrl() function with the
153 control code B<EVP_CTRL_RAND_KEY> and the pointer to the key memory
154 storage in B<ptr>.
155
156 =item EVP_CIPH_CUSTOM_COPY
157
158 Set this to have the implementation's ctrl() function called with
159 command code B<EVP_CTRL_COPY> at the end of EVP_CIPHER_CTX_copy().
160 The intended use is for further things to deal with after the
161 implementation specific data block has been copied.
162 The destination B<EVP_CIPHER_CTX> is passed to the control with the
163 B<ptr> parameter.
164 The implementation specific data block is reached with
165 EVP_CIPHER_CTX_cipher_data().
166
167 =item EVP_CIPH_FLAG_DEFAULT_ASN1
168
169 Use the default EVP routines to pass IV to and from ASN.1.
170
171 =item EVP_CIPH_FLAG_LENGTH_BITS
172
173 Signals that the length of the input buffer for encryption /
174 decryption is to be understood as the number of bits bits instead of
175 bytes for this implementation.
176 This is only useful for CFB1 ciphers.
177
178 =begin comment
179 The FIPS flags seem to be unused, so I'm hiding them until I get an
180 explanation or they get removed.  /RL
181
182 =item EVP_CIPH_FLAG_FIPS
183
184 =item EVP_CIPH_FLAG_NON_FIPS_ALLOW
185
186 =end comment
187
188 =item EVP_CIPH_FLAG_CUSTOM_CIPHER
189
190 This indicates that the implementation takes care of everything,
191 including padding, buffering and finalization.
192 The EVP routines will simply give them control and do nothing more.
193
194 =item EVP_CIPH_FLAG_AEAD_CIPHER
195
196 This indicates that this is a AEAD cipher implementation.
197
198 =item EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
199
200 =begin comment
201
202 I could use some help explaining this one!
203
204 =end comment
205
206 =back
207
208 =back
209
210 EVP_CIPHER_meth_set_init() sets the cipher init function for
211 B<cipher>.
212 The cipher init function is called by EVP_CipherInit(),
213 EVP_CipherInit_ex(), EVP_EncryptInit(), EVP_EncryptInit_ex(),
214 EVP_DecryptInit(), EVP_DecryptInit_ex().
215
216 EVP_CIPHER_meth_set_do_cipher() sets the cipher function for
217 B<cipher>.
218 The cipher function is called by EVP_CipherUpdate(),
219 EVP_EncryptUpdate(), EVP_DecryptUpdate(), EVP_CipherFinal(),
220 EVP_EncryptFinal(), EVP_EncryptFinal_ex(), EVP_DecryptFinal() and
221 EVP_DecryptFinal_ex().
222
223 EVP_CIPHER_meth_set_cleanup() sets the function for B<cipher> to do
224 extra cleanup before the method's privata data structure is cleaned
225 out and freed.
226 Note that the cleanup function is passed a B<EVP_CIPHER_CTX *>, the
227 private data structure is then available with
228 EVP_CIPHER_CTX_cipher_data().
229 This cleanup function is called by EVP_CIPHER_CTX_reset() and
230 EVP_CIPHER_CTX_free().
231
232 EVP_CIPHER_meth_set_ctrl() sets the control function for B<cipher>.
233
234
235 EVP_CIPHER_meth_get_input_blocksize(), EVP_CIPHER_meth_get_result_size(),
236 EVP_CIPHER_meth_get_app_datasize(), EVP_CIPHER_meth_get_flags(),
237 EVP_CIPHER_meth_get_init(), EVP_CIPHER_meth_get_update(),
238 EVP_CIPHER_meth_get_final(), EVP_CIPHER_meth_get_copy(),
239 EVP_CIPHER_meth_get_cleanup() and EVP_CIPHER_meth_get_ctrl() are all used
240 to retrieve the method data given with the EVP_CIPHER_meth_set_*()
241 functions above.
242
243 =head1 SEE ALSO
244
245 L<EVP_EncryptInit>
246
247 =head1 HISTORY
248
249 The B<EVP_CIPHER> structure was openly available in OpenSSL before version
250 1.1.
251 The functions described here were added in OpenSSL version 1.1.
252
253 =cut