diff options
author | schwarze <> | 2016-11-03 09:35:34 +0000 |
---|---|---|
committer | schwarze <> | 2016-11-03 09:35:34 +0000 |
commit | 4d607f17ea3eb38ed9f7703afd423f6055c686d4 (patch) | |
tree | 58d82d0d7f6aeee380eaadbcfaa231ecbe6b90a0 /src/lib/libcrypto/doc/EVP_EncryptInit.pod | |
parent | cf67afe5881727d740e9f6c772aa478123f7d698 (diff) | |
download | openbsd-4d607f17ea3eb38ed9f7703afd423f6055c686d4.tar.gz openbsd-4d607f17ea3eb38ed9f7703afd423f6055c686d4.tar.bz2 openbsd-4d607f17ea3eb38ed9f7703afd423f6055c686d4.zip |
convert EVP manuals from pod to mdoc
Diffstat (limited to 'src/lib/libcrypto/doc/EVP_EncryptInit.pod')
-rw-r--r-- | src/lib/libcrypto/doc/EVP_EncryptInit.pod | 548 |
1 files changed, 0 insertions, 548 deletions
diff --git a/src/lib/libcrypto/doc/EVP_EncryptInit.pod b/src/lib/libcrypto/doc/EVP_EncryptInit.pod deleted file mode 100644 index 7ae3fe31ea..0000000000 --- a/src/lib/libcrypto/doc/EVP_EncryptInit.pod +++ /dev/null | |||
@@ -1,548 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_CIPHER_CTX_init, EVP_EncryptInit_ex, EVP_EncryptUpdate, | ||
6 | EVP_EncryptFinal_ex, EVP_DecryptInit_ex, EVP_DecryptUpdate, | ||
7 | EVP_DecryptFinal_ex, EVP_CipherInit_ex, EVP_CipherUpdate, | ||
8 | EVP_CipherFinal_ex, EVP_CIPHER_CTX_set_key_length, | ||
9 | EVP_CIPHER_CTX_ctrl, EVP_CIPHER_CTX_cleanup, EVP_EncryptInit, | ||
10 | EVP_EncryptFinal, EVP_DecryptInit, EVP_DecryptFinal, | ||
11 | EVP_CipherInit, EVP_CipherFinal, EVP_get_cipherbyname, | ||
12 | EVP_get_cipherbynid, EVP_get_cipherbyobj, EVP_CIPHER_nid, | ||
13 | EVP_CIPHER_block_size, EVP_CIPHER_key_length, EVP_CIPHER_iv_length, | ||
14 | EVP_CIPHER_flags, EVP_CIPHER_mode, EVP_CIPHER_type, EVP_CIPHER_CTX_cipher, | ||
15 | EVP_CIPHER_CTX_nid, EVP_CIPHER_CTX_block_size, EVP_CIPHER_CTX_key_length, | ||
16 | EVP_CIPHER_CTX_iv_length, EVP_CIPHER_CTX_get_app_data, | ||
17 | EVP_CIPHER_CTX_set_app_data, EVP_CIPHER_CTX_type, EVP_CIPHER_CTX_flags, | ||
18 | EVP_CIPHER_CTX_mode, EVP_CIPHER_param_to_asn1, EVP_CIPHER_asn1_to_param, | ||
19 | EVP_CIPHER_CTX_set_padding, EVP_enc_null, EVP_des_cbc, EVP_des_ecb, | ||
20 | EVP_des_cfb, EVP_des_ofb, EVP_des_ede_cbc, EVP_des_ede, EVP_des_ede_ofb, | ||
21 | EVP_des_ede_cfb, EVP_des_ede3_cbc, EVP_des_ede3, EVP_des_ede3_ofb, | ||
22 | EVP_des_ede3_cfb, EVP_desx_cbc, EVP_rc4, EVP_rc4_40, EVP_idea_cbc, | ||
23 | EVP_idea_ecb, EVP_idea_cfb, EVP_idea_ofb, EVP_idea_cbc, EVP_rc2_cbc, | ||
24 | EVP_rc2_ecb, EVP_rc2_cfb, EVP_rc2_ofb, EVP_rc2_40_cbc, EVP_rc2_64_cbc, | ||
25 | EVP_bf_cbc, EVP_bf_ecb, EVP_bf_cfb, EVP_bf_ofb, EVP_cast5_cbc, | ||
26 | EVP_cast5_ecb, EVP_cast5_cfb, EVP_cast5_ofb, | ||
27 | EVP_aes_128_gcm, EVP_aes_192_gcm, EVP_aes_256_gcm, EVP_aes_128_ccm, | ||
28 | EVP_aes_192_ccm, EVP_aes_256_ccm, EVP_rc5_32_12_16_cbc, | ||
29 | EVP_rc5_32_12_16_cfb, EVP_rc5_32_12_16_ecb, EVP_rc5_32_12_16_ofb | ||
30 | - EVP cipher routines | ||
31 | |||
32 | =head1 SYNOPSIS | ||
33 | |||
34 | #include <openssl/evp.h> | ||
35 | |||
36 | void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a); | ||
37 | |||
38 | int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, | ||
39 | ENGINE *impl, unsigned char *key, unsigned char *iv); | ||
40 | int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
41 | int *outl, unsigned char *in, int inl); | ||
42 | int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
43 | int *outl); | ||
44 | |||
45 | int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, | ||
46 | ENGINE *impl, unsigned char *key, unsigned char *iv); | ||
47 | int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
48 | int *outl, unsigned char *in, int inl); | ||
49 | int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, | ||
50 | int *outl); | ||
51 | |||
52 | int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, | ||
53 | ENGINE *impl, unsigned char *key, unsigned char *iv, int enc); | ||
54 | int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
55 | int *outl, unsigned char *in, int inl); | ||
56 | int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, | ||
57 | int *outl); | ||
58 | |||
59 | int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, | ||
60 | unsigned char *key, unsigned char *iv); | ||
61 | int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
62 | int *outl); | ||
63 | |||
64 | int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, | ||
65 | unsigned char *key, unsigned char *iv); | ||
66 | int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, | ||
67 | int *outl); | ||
68 | |||
69 | int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, | ||
70 | unsigned char *key, unsigned char *iv, int enc); | ||
71 | int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, | ||
72 | int *outl); | ||
73 | |||
74 | int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *x, int padding); | ||
75 | int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen); | ||
76 | int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr); | ||
77 | int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a); | ||
78 | |||
79 | const EVP_CIPHER *EVP_get_cipherbyname(const char *name); | ||
80 | #define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a)) | ||
81 | #define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a)) | ||
82 | |||
83 | #define EVP_CIPHER_nid(e) ((e)->nid) | ||
84 | #define EVP_CIPHER_block_size(e) ((e)->block_size) | ||
85 | #define EVP_CIPHER_key_length(e) ((e)->key_len) | ||
86 | #define EVP_CIPHER_iv_length(e) ((e)->iv_len) | ||
87 | #define EVP_CIPHER_flags(e) ((e)->flags) | ||
88 | #define EVP_CIPHER_mode(e) ((e)->flags) & EVP_CIPH_MODE) | ||
89 | int EVP_CIPHER_type(const EVP_CIPHER *ctx); | ||
90 | |||
91 | #define EVP_CIPHER_CTX_cipher(e) ((e)->cipher) | ||
92 | #define EVP_CIPHER_CTX_nid(e) ((e)->cipher->nid) | ||
93 | #define EVP_CIPHER_CTX_block_size(e) ((e)->cipher->block_size) | ||
94 | #define EVP_CIPHER_CTX_key_length(e) ((e)->key_len) | ||
95 | #define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len) | ||
96 | #define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) | ||
97 | #define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d)) | ||
98 | #define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c)) | ||
99 | #define EVP_CIPHER_CTX_flags(e) ((e)->cipher->flags) | ||
100 | #define EVP_CIPHER_CTX_mode(e) ((e)->cipher->flags & EVP_CIPH_MODE) | ||
101 | |||
102 | int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type); | ||
103 | int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type); | ||
104 | |||
105 | =head1 DESCRIPTION | ||
106 | |||
107 | The EVP cipher routines are a high level interface to certain | ||
108 | symmetric ciphers. | ||
109 | |||
110 | EVP_CIPHER_CTX_init() initializes cipher context B<ctx>. | ||
111 | |||
112 | EVP_EncryptInit_ex() sets up cipher context B<ctx> for encryption | ||
113 | with cipher B<type> from ENGINE B<impl>. B<ctx> must be initialized | ||
114 | before calling this function. B<type> is normally supplied | ||
115 | by a function such as EVP_aes_256_cbc(). If B<impl> is NULL then the | ||
116 | default implementation is used. B<key> is the symmetric key to use | ||
117 | and B<iv> is the IV to use (if necessary), the actual number of bytes | ||
118 | used for the key and IV depends on the cipher. It is possible to set | ||
119 | all parameters to NULL except B<type> in an initial call and supply | ||
120 | the remaining parameters in subsequent calls, all of which have B<type> | ||
121 | set to NULL. This is done when the default cipher parameters are not | ||
122 | appropriate. | ||
123 | |||
124 | EVP_EncryptUpdate() encrypts B<inl> bytes from the buffer B<in> and | ||
125 | writes the encrypted version to B<out>. This function can be called | ||
126 | multiple times to encrypt successive blocks of data. The amount | ||
127 | of data written depends on the block alignment of the encrypted data: | ||
128 | as a result the amount of data written may be anything from zero bytes | ||
129 | to (inl + cipher_block_size - 1) so B<outl> should contain sufficient | ||
130 | room. The actual number of bytes written is placed in B<outl>. | ||
131 | |||
132 | If padding is enabled (the default) then EVP_EncryptFinal_ex() encrypts | ||
133 | the "final" data, that is any data that remains in a partial block. | ||
134 | It uses L<standard block padding|/NOTES> (aka PKCS padding). The encrypted | ||
135 | final data is written to B<out> which should have sufficient space for | ||
136 | one cipher block. The number of bytes written is placed in B<outl>. After | ||
137 | this function is called the encryption operation is finished and no further | ||
138 | calls to EVP_EncryptUpdate() should be made. | ||
139 | |||
140 | If padding is disabled then EVP_EncryptFinal_ex() will not encrypt any more | ||
141 | data and it will return an error if any data remains in a partial block: | ||
142 | that is if the total data length is not a multiple of the block size. | ||
143 | |||
144 | EVP_DecryptInit_ex(), EVP_DecryptUpdate() and EVP_DecryptFinal_ex() are the | ||
145 | corresponding decryption operations. EVP_DecryptFinal() will return an | ||
146 | error code if padding is enabled and the final block is not correctly | ||
147 | formatted. The parameters and restrictions are identical to the encryption | ||
148 | operations except that if padding is enabled the decrypted data buffer B<out> | ||
149 | passed to EVP_DecryptUpdate() should have sufficient room for | ||
150 | (B<inl> + cipher_block_size) bytes unless the cipher block size is 1 in | ||
151 | which case B<inl> bytes is sufficient. | ||
152 | |||
153 | EVP_CipherInit_ex(), EVP_CipherUpdate() and EVP_CipherFinal_ex() are | ||
154 | functions that can be used for decryption or encryption. The operation | ||
155 | performed depends on the value of the B<enc> parameter. It should be set | ||
156 | to 1 for encryption, 0 for decryption and -1 to leave the value unchanged | ||
157 | (the actual value of 'enc' being supplied in a previous call). | ||
158 | |||
159 | EVP_CIPHER_CTX_cleanup() clears all information from a cipher context | ||
160 | and free up any allocated memory associate with it. It should be called | ||
161 | after all operations using a cipher are complete so sensitive information | ||
162 | does not remain in memory. | ||
163 | |||
164 | EVP_EncryptInit(), EVP_DecryptInit() and EVP_CipherInit() behave in a | ||
165 | similar way to EVP_EncryptInit_ex(), EVP_DecryptInit_ex and | ||
166 | EVP_CipherInit_ex() except the B<ctx> parameter does not need to be | ||
167 | initialized and they always use the default cipher implementation. | ||
168 | |||
169 | EVP_EncryptFinal(), EVP_DecryptFinal() and EVP_CipherFinal() are | ||
170 | identical to EVP_EncryptFinal_ex(), EVP_DecryptFinal_ex() and | ||
171 | EVP_CipherFinal_ex(). In previous releases of OpenSSL they also used to clean | ||
172 | up the B<ctx>, but this is no longer done and EVP_CIPHER_CTX_clean() | ||
173 | must be called to free any context resources. | ||
174 | |||
175 | EVP_get_cipherbyname(), EVP_get_cipherbynid() and EVP_get_cipherbyobj() | ||
176 | return an EVP_CIPHER structure when passed a cipher name, a NID or an | ||
177 | ASN1_OBJECT structure. | ||
178 | |||
179 | EVP_CIPHER_nid() and EVP_CIPHER_CTX_nid() return the NID of a cipher when | ||
180 | passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX> structure. The actual NID | ||
181 | value is an internal value which may not have a corresponding OBJECT | ||
182 | IDENTIFIER. | ||
183 | |||
184 | EVP_CIPHER_CTX_set_padding() enables or disables padding. By default | ||
185 | encryption operations are padded using standard block padding and the | ||
186 | padding is checked and removed when decrypting. If the B<pad> parameter | ||
187 | is zero then no padding is performed, the total amount of data encrypted | ||
188 | or decrypted must then be a multiple of the block size or an error will | ||
189 | occur. | ||
190 | |||
191 | EVP_CIPHER_key_length() and EVP_CIPHER_CTX_key_length() return the key | ||
192 | length of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX> | ||
193 | structure. The constant B<EVP_MAX_KEY_LENGTH> is the maximum key length | ||
194 | for all ciphers. Note: although EVP_CIPHER_key_length() is fixed for a | ||
195 | given cipher, the value of EVP_CIPHER_CTX_key_length() may be different | ||
196 | for variable key length ciphers. | ||
197 | |||
198 | EVP_CIPHER_CTX_set_key_length() sets the key length of the cipher ctx. | ||
199 | If the cipher is a fixed length cipher then attempting to set the key | ||
200 | length to any value other than the fixed value is an error. | ||
201 | |||
202 | EVP_CIPHER_iv_length() and EVP_CIPHER_CTX_iv_length() return the IV | ||
203 | length of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX>. | ||
204 | It will return zero if the cipher does not use an IV. The constant | ||
205 | B<EVP_MAX_IV_LENGTH> is the maximum IV length for all ciphers. | ||
206 | |||
207 | EVP_CIPHER_block_size() and EVP_CIPHER_CTX_block_size() return the block | ||
208 | size of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX> | ||
209 | structure. The constant B<EVP_MAX_IV_LENGTH> is also the maximum block | ||
210 | length for all ciphers. | ||
211 | |||
212 | EVP_CIPHER_type() and EVP_CIPHER_CTX_type() return the type of the passed | ||
213 | cipher or context. This "type" is the actual NID of the cipher OBJECT | ||
214 | IDENTIFIER as such it ignores the cipher parameters and 40 bit RC2 and | ||
215 | 128 bit RC2 have the same NID. If the cipher does not have an object | ||
216 | identifier or does not have ASN1 support this function will return | ||
217 | B<NID_undef>. | ||
218 | |||
219 | EVP_CIPHER_CTX_cipher() returns the B<EVP_CIPHER> structure when passed | ||
220 | an B<EVP_CIPHER_CTX> structure. | ||
221 | |||
222 | EVP_CIPHER_mode() and EVP_CIPHER_CTX_mode() return the block cipher mode: | ||
223 | EVP_CIPH_ECB_MODE, EVP_CIPH_CBC_MODE, EVP_CIPH_CFB_MODE or | ||
224 | EVP_CIPH_OFB_MODE. If the cipher is a stream cipher then | ||
225 | EVP_CIPH_STREAM_CIPHER is returned. | ||
226 | |||
227 | EVP_CIPHER_param_to_asn1() sets the AlgorithmIdentifier "parameter" based | ||
228 | on the passed cipher. This will typically include any parameters and an | ||
229 | IV. The cipher IV (if any) must be set when this call is made. This call | ||
230 | should be made before the cipher is actually "used" (before any | ||
231 | EVP_EncryptUpdate(), EVP_DecryptUpdate() calls for example). This function | ||
232 | may fail if the cipher does not have any ASN1 support. | ||
233 | |||
234 | EVP_CIPHER_asn1_to_param() sets the cipher parameters based on an ASN1 | ||
235 | AlgorithmIdentifier "parameter". The precise effect depends on the cipher | ||
236 | In the case of RC2, for example, it will set the IV and effective key length. | ||
237 | This function should be called after the base cipher type is set but before | ||
238 | the key is set. For example EVP_CipherInit() will be called with the IV and | ||
239 | key set to NULL, EVP_CIPHER_asn1_to_param() will be called and finally | ||
240 | EVP_CipherInit() again with all parameters except the key set to NULL. It is | ||
241 | possible for this function to fail if the cipher does not have any ASN1 support | ||
242 | or the parameters cannot be set (for example the RC2 effective key length | ||
243 | is not supported. | ||
244 | |||
245 | EVP_CIPHER_CTX_ctrl() allows various cipher specific parameters to be determined | ||
246 | and set. Currently only the RC2 effective key length and the number of rounds of | ||
247 | RC5 can be set. | ||
248 | |||
249 | =head1 RETURN VALUES | ||
250 | |||
251 | EVP_EncryptInit_ex(), EVP_EncryptUpdate() and EVP_EncryptFinal_ex() | ||
252 | return 1 for success and 0 for failure. | ||
253 | |||
254 | EVP_DecryptInit_ex() and EVP_DecryptUpdate() return 1 for success and 0 for | ||
255 | failure. EVP_DecryptFinal_ex() returns 0 if the decrypt failed or 1 for | ||
256 | success. | ||
257 | |||
258 | EVP_CipherInit_ex() and EVP_CipherUpdate() return 1 for success and 0 for | ||
259 | failure. EVP_CipherFinal_ex() returns 0 for a decryption failure or 1 for | ||
260 | success. | ||
261 | |||
262 | EVP_CIPHER_CTX_cleanup() returns 1 for success and 0 for failure. | ||
263 | |||
264 | EVP_get_cipherbyname(), EVP_get_cipherbynid() and EVP_get_cipherbyobj() | ||
265 | return an B<EVP_CIPHER> structure or NULL on error. | ||
266 | |||
267 | EVP_CIPHER_nid() and EVP_CIPHER_CTX_nid() return a NID. | ||
268 | |||
269 | EVP_CIPHER_block_size() and EVP_CIPHER_CTX_block_size() return the block | ||
270 | size. | ||
271 | |||
272 | EVP_CIPHER_key_length() and EVP_CIPHER_CTX_key_length() return the key | ||
273 | length. | ||
274 | |||
275 | EVP_CIPHER_CTX_set_padding() always returns 1. | ||
276 | |||
277 | EVP_CIPHER_iv_length() and EVP_CIPHER_CTX_iv_length() return the IV | ||
278 | length or zero if the cipher does not use an IV. | ||
279 | |||
280 | EVP_CIPHER_type() and EVP_CIPHER_CTX_type() return the NID of the cipher's | ||
281 | OBJECT IDENTIFIER or NID_undef if it has no defined OBJECT IDENTIFIER. | ||
282 | |||
283 | EVP_CIPHER_CTX_cipher() returns an B<EVP_CIPHER> structure. | ||
284 | |||
285 | EVP_CIPHER_param_to_asn1() and EVP_CIPHER_asn1_to_param() return 1 for | ||
286 | success or zero for failure. | ||
287 | |||
288 | =head1 CIPHER LISTING | ||
289 | |||
290 | All algorithms have a fixed key length unless otherwise stated. | ||
291 | |||
292 | =over 4 | ||
293 | |||
294 | =item EVP_enc_null(void) | ||
295 | |||
296 | Null cipher: does nothing. | ||
297 | |||
298 | =item EVP_aes_128_cbc(void), EVP_aes_128_ecb(void), EVP_aes_128_cfb(void), EVP_aes_128_ofb(void) | ||
299 | |||
300 | 128-bit AES in CBC, ECB, CFB and OFB modes respectively. | ||
301 | |||
302 | =item EVP_aes_192_cbc(void), EVP_aes_192_ecb(void), EVP_aes_192_cfb(void), EVP_aes_192_ofb(void) | ||
303 | |||
304 | 192-bit AES in CBC, ECB, CFB and OFB modes respectively. | ||
305 | |||
306 | =item EVP_aes_256_cbc(void), EVP_aes_256_ecb(void), EVP_aes_256_cfb(void), EVP_aes_256_ofb(void) | ||
307 | |||
308 | 256-bit AES in CBC, ECB, CFB and OFB modes respectively. | ||
309 | |||
310 | =item EVP_des_cbc(void), EVP_des_ecb(void), EVP_des_cfb(void), EVP_des_ofb(void) | ||
311 | |||
312 | DES in CBC, ECB, CFB and OFB modes respectively. | ||
313 | |||
314 | =item EVP_des_ede_cbc(void), EVP_des_ede(), EVP_des_ede_ofb(void), | ||
315 | EVP_des_ede_cfb(void) | ||
316 | |||
317 | Two key triple DES in CBC, ECB, CFB and OFB modes respectively. | ||
318 | |||
319 | =item EVP_des_ede3_cbc(void), EVP_des_ede3(), EVP_des_ede3_ofb(void), | ||
320 | EVP_des_ede3_cfb(void) | ||
321 | |||
322 | Three key triple DES in CBC, ECB, CFB and OFB modes respectively. | ||
323 | |||
324 | =item EVP_desx_cbc(void) | ||
325 | |||
326 | DESX algorithm in CBC mode. | ||
327 | |||
328 | =item EVP_rc4(void) | ||
329 | |||
330 | RC4 stream cipher. This is a variable key length cipher with default key length | ||
331 | 128 bits. | ||
332 | |||
333 | =item EVP_rc4_40(void) | ||
334 | |||
335 | RC4 stream cipher with 40 bit key length. This is obsolete and new code should | ||
336 | use EVP_rc4() and the EVP_CIPHER_CTX_set_key_length() function. | ||
337 | |||
338 | =item EVP_idea_cbc() EVP_idea_ecb(void), EVP_idea_cfb(void), | ||
339 | EVP_idea_ofb(void), EVP_idea_cbc(void) | ||
340 | |||
341 | IDEA encryption algorithm in CBC, ECB, CFB and OFB modes respectively. | ||
342 | |||
343 | =item EVP_rc2_cbc(void), EVP_rc2_ecb(void), EVP_rc2_cfb(void), EVP_rc2_ofb(void) | ||
344 | |||
345 | RC2 encryption algorithm in CBC, ECB, CFB and OFB modes respectively. This is a | ||
346 | variable key length cipher with an additional parameter called "effective key | ||
347 | bits" or "effective key length". By default both are set to 128 bits. | ||
348 | |||
349 | =item EVP_rc2_40_cbc(void), EVP_rc2_64_cbc(void) | ||
350 | |||
351 | RC2 algorithm in CBC mode with a default key length and effective key length of | ||
352 | 40 and 64 bits. These are obsolete and new code should use EVP_rc2_cbc(), | ||
353 | EVP_CIPHER_CTX_set_key_length() and EVP_CIPHER_CTX_ctrl() to set the key length | ||
354 | and effective key length. | ||
355 | |||
356 | =item EVP_bf_cbc(void), EVP_bf_ecb(void), EVP_bf_cfb(void), EVP_bf_ofb(void); | ||
357 | |||
358 | Blowfish encryption algorithm in CBC, ECB, CFB and OFB modes respectively. This | ||
359 | is a variable key length cipher. | ||
360 | |||
361 | =item EVP_cast5_cbc(void), EVP_cast5_ecb(void), EVP_cast5_cfb(void), | ||
362 | EVP_cast5_ofb(void) | ||
363 | |||
364 | CAST encryption algorithm in CBC, ECB, CFB and OFB modes respectively. This is | ||
365 | a variable key length cipher. | ||
366 | |||
367 | =item EVP_rc5_32_12_16_cbc(void), EVP_rc5_32_12_16_ecb(void), | ||
368 | EVP_rc5_32_12_16_cfb(void), EVP_rc5_32_12_16_ofb(void) | ||
369 | |||
370 | RC5 encryption algorithm in CBC, ECB, CFB and OFB modes respectively. This is a | ||
371 | variable key length cipher with an additional "number of rounds" parameter. By | ||
372 | default the key length is set to 128 bits and 12 rounds. | ||
373 | |||
374 | =back | ||
375 | |||
376 | =head1 NOTES | ||
377 | |||
378 | Where possible the B<EVP> interface to symmetric ciphers should be used in | ||
379 | preference to the low level interfaces. This is because the code then becomes | ||
380 | transparent to the cipher used and much more flexible. | ||
381 | |||
382 | PKCS padding works by adding B<n> padding bytes of value B<n> to make the total | ||
383 | length of the encrypted data a multiple of the block size. Padding is always | ||
384 | added so if the data is already a multiple of the block size B<n> will equal | ||
385 | the block size. For example if the block size is 8 and 11 bytes are to be | ||
386 | encrypted then 5 padding bytes of value 5 will be added. | ||
387 | |||
388 | When decrypting the final block is checked to see if it has the correct form. | ||
389 | |||
390 | Although the decryption operation can produce an error if padding is enabled, | ||
391 | it is not a strong test that the input data or key is correct. A random block | ||
392 | has better than 1 in 256 chance of being of the correct format and problems with | ||
393 | the input data earlier on will not produce a final decrypt error. | ||
394 | |||
395 | If padding is disabled then the decryption operation will always succeed if | ||
396 | the total amount of data decrypted is a multiple of the block size. | ||
397 | |||
398 | The functions EVP_EncryptInit(), EVP_EncryptFinal(), EVP_DecryptInit(), | ||
399 | EVP_CipherInit() and EVP_CipherFinal() are obsolete but are retained for | ||
400 | compatibility with existing code. New code should use EVP_EncryptInit_ex(), | ||
401 | EVP_EncryptFinal_ex(), EVP_DecryptInit_ex(), EVP_DecryptFinal_ex(), | ||
402 | EVP_CipherInit_ex() and EVP_CipherFinal_ex() because they can reuse an | ||
403 | existing context without allocating and freeing it up on each call. | ||
404 | |||
405 | =head1 BUGS | ||
406 | |||
407 | For RC5 the number of rounds can currently only be set to 8, 12 or 16. This is | ||
408 | a limitation of the current RC5 code rather than the EVP interface. | ||
409 | |||
410 | EVP_MAX_KEY_LENGTH and EVP_MAX_IV_LENGTH only refer to the internal ciphers with | ||
411 | default key lengths. If custom ciphers exceed these values the results are | ||
412 | unpredictable. This is because it has become standard practice to define a | ||
413 | generic key as a fixed unsigned char array containing EVP_MAX_KEY_LENGTH bytes. | ||
414 | |||
415 | The ASN1 code is incomplete (and sometimes inaccurate) it has only been tested | ||
416 | for certain common S/MIME ciphers (RC2, DES, triple DES) in CBC mode. | ||
417 | |||
418 | =head1 EXAMPLES | ||
419 | |||
420 | Get the number of rounds used in RC5: | ||
421 | |||
422 | int nrounds; | ||
423 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GET_RC5_ROUNDS, 0, &nrounds); | ||
424 | |||
425 | Get the RC2 effective key length: | ||
426 | |||
427 | int key_bits; | ||
428 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GET_RC2_KEY_BITS, 0, &key_bits); | ||
429 | |||
430 | Set the number of rounds used in RC5: | ||
431 | |||
432 | int nrounds; | ||
433 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_RC5_ROUNDS, nrounds, NULL); | ||
434 | |||
435 | Set the effective key length used in RC2: | ||
436 | |||
437 | int key_bits; | ||
438 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_RC2_KEY_BITS, key_bits, NULL); | ||
439 | |||
440 | Encrypt a string using blowfish: | ||
441 | |||
442 | int | ||
443 | do_crypt(char *outfile) | ||
444 | { | ||
445 | unsigned char outbuf[1024]; | ||
446 | int outlen, tmplen; | ||
447 | /* | ||
448 | * Bogus key and IV: we'd normally set these from | ||
449 | * another source. | ||
450 | */ | ||
451 | unsigned char key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; | ||
452 | unsigned char iv[] = {1,2,3,4,5,6,7,8}; | ||
453 | const char intext[] = "Some Crypto Text"; | ||
454 | EVP_CIPHER_CTX ctx; | ||
455 | FILE *out; | ||
456 | EVP_CIPHER_CTX_init(&ctx); | ||
457 | EVP_EncryptInit_ex(&ctx, EVP_bf_cbc(), NULL, key, iv); | ||
458 | |||
459 | if (!EVP_EncryptUpdate(&ctx, outbuf, &outlen, intext, | ||
460 | strlen(intext))) { | ||
461 | /* Error */ | ||
462 | return 0; | ||
463 | } | ||
464 | /* | ||
465 | * Buffer passed to EVP_EncryptFinal() must be after data just | ||
466 | * encrypted to avoid overwriting it. | ||
467 | */ | ||
468 | if (!EVP_EncryptFinal_ex(&ctx, outbuf + outlen, &tmplen)) { | ||
469 | /* Error */ | ||
470 | return 0; | ||
471 | } | ||
472 | outlen += tmplen; | ||
473 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
474 | /* | ||
475 | * Need binary mode for fopen because encrypted data is | ||
476 | * binary data. Also cannot use strlen() on it because | ||
477 | * it won't be NUL terminated and may contain embedded | ||
478 | * NULs. | ||
479 | */ | ||
480 | out = fopen(outfile, "wb"); | ||
481 | fwrite(outbuf, 1, outlen, out); | ||
482 | fclose(out); | ||
483 | return 1; | ||
484 | } | ||
485 | |||
486 | The ciphertext from the above example can be decrypted using the B<openssl> | ||
487 | utility with the command line: | ||
488 | |||
489 | S<openssl bf -in cipher.bin -K 000102030405060708090A0B0C0D0E0F -iv 0102030405060708 -d> | ||
490 | |||
491 | General encryption, decryption function example using FILE I/O and RC2 with an | ||
492 | 80 bit key: | ||
493 | |||
494 | int | ||
495 | do_crypt(FILE *in, FILE *out, int do_encrypt) | ||
496 | { | ||
497 | /* Allow enough space in output buffer for additional block */ | ||
498 | inbuf[1024], outbuf[1024 + EVP_MAX_BLOCK_LENGTH]; | ||
499 | int inlen, outlen; | ||
500 | /* | ||
501 | * Bogus key and IV: we'd normally set these from | ||
502 | * another source. | ||
503 | */ | ||
504 | unsigned char key[] = "0123456789"; | ||
505 | unsigned char iv[] = "12345678"; | ||
506 | |||
507 | /* Don't set key or IV because we will modify the parameters */ | ||
508 | EVP_CIPHER_CTX_init(&ctx); | ||
509 | EVP_CipherInit_ex(&ctx, EVP_rc2(), NULL, NULL, NULL, do_encrypt); | ||
510 | EVP_CIPHER_CTX_set_key_length(&ctx, 10); | ||
511 | /* We finished modifying parameters so now we can set key and IV */ | ||
512 | EVP_CipherInit_ex(&ctx, NULL, NULL, key, iv, do_encrypt); | ||
513 | |||
514 | for(;;) { | ||
515 | inlen = fread(inbuf, 1, 1024, in); | ||
516 | if (inlen <= 0) | ||
517 | break; | ||
518 | if (!EVP_CipherUpdate(&ctx, outbuf, &outlen, inbuf, | ||
519 | inlen)) { | ||
520 | /* Error */ | ||
521 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
522 | return 0; | ||
523 | } | ||
524 | fwrite(outbuf, 1, outlen, out); | ||
525 | } | ||
526 | if (!EVP_CipherFinal_ex(&ctx, outbuf, &outlen)) { | ||
527 | /* Error */ | ||
528 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
529 | return 0; | ||
530 | } | ||
531 | fwrite(outbuf, 1, outlen, out); | ||
532 | |||
533 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
534 | return 1; | ||
535 | } | ||
536 | |||
537 | =head1 SEE ALSO | ||
538 | |||
539 | L<evp(3)|evp(3)> | ||
540 | |||
541 | =head1 HISTORY | ||
542 | |||
543 | EVP_CIPHER_CTX_init(), EVP_EncryptInit_ex(), EVP_EncryptFinal_ex(), | ||
544 | EVP_DecryptInit_ex(), EVP_DecryptFinal_ex(), EVP_CipherInit_ex(), | ||
545 | EVP_CipherFinal_ex() and EVP_CIPHER_CTX_set_padding() appeared in | ||
546 | OpenSSL 0.9.7. | ||
547 | |||
548 | =cut | ||