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