diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/man/EVP_EncryptInit.3 | 533 |
1 files changed, 390 insertions, 143 deletions
diff --git a/src/lib/libcrypto/man/EVP_EncryptInit.3 b/src/lib/libcrypto/man/EVP_EncryptInit.3 index 3757bfc815..1a7fe40a66 100644 --- a/src/lib/libcrypto/man/EVP_EncryptInit.3 +++ b/src/lib/libcrypto/man/EVP_EncryptInit.3 | |||
| @@ -1,10 +1,61 @@ | |||
| 1 | .\" $OpenBSD: EVP_EncryptInit.3,v 1.3 2016/11/21 22:19:15 jmc Exp $ | 1 | .\" $OpenBSD: EVP_EncryptInit.3,v 1.4 2016/11/26 20:26:25 schwarze Exp $ |
| 2 | .\" OpenSSL 5211e094 Nov 11 14:39:11 2014 -0800 | ||
| 2 | .\" | 3 | .\" |
| 3 | .Dd $Mdocdate: November 21 2016 $ | 4 | .\" This file was written by Dr. Stephen Henson <steve@openssl.org>. |
| 5 | .\" Copyright (c) 2000-2002, 2005, 2012-2016 The OpenSSL Project. | ||
| 6 | .\" All rights reserved. | ||
| 7 | .\" | ||
| 8 | .\" Redistribution and use in source and binary forms, with or without | ||
| 9 | .\" modification, are permitted provided that the following conditions | ||
| 10 | .\" are met: | ||
| 11 | .\" | ||
| 12 | .\" 1. Redistributions of source code must retain the above copyright | ||
| 13 | .\" notice, this list of conditions and the following disclaimer. | ||
| 14 | .\" | ||
| 15 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | .\" notice, this list of conditions and the following disclaimer in | ||
| 17 | .\" the documentation and/or other materials provided with the | ||
| 18 | .\" distribution. | ||
| 19 | .\" | ||
| 20 | .\" 3. All advertising materials mentioning features or use of this | ||
| 21 | .\" software must display the following acknowledgment: | ||
| 22 | .\" "This product includes software developed by the OpenSSL Project | ||
| 23 | .\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 24 | .\" | ||
| 25 | .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | .\" endorse or promote products derived from this software without | ||
| 27 | .\" prior written permission. For written permission, please contact | ||
| 28 | .\" openssl-core@openssl.org. | ||
| 29 | .\" | ||
| 30 | .\" 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | .\" nor may "OpenSSL" appear in their names without prior written | ||
| 32 | .\" permission of the OpenSSL Project. | ||
| 33 | .\" | ||
| 34 | .\" 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | .\" acknowledgment: | ||
| 36 | .\" "This product includes software developed by the OpenSSL Project | ||
| 37 | .\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 38 | .\" | ||
| 39 | .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | .\" OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | .\" | ||
| 52 | .Dd $Mdocdate: November 26 2016 $ | ||
| 4 | .Dt EVP_ENCRYPTINIT 3 | 53 | .Dt EVP_ENCRYPTINIT 3 |
| 5 | .Os | 54 | .Os |
| 6 | .Sh NAME | 55 | .Sh NAME |
| 56 | .Nm EVP_CIPHER_CTX_new , | ||
| 7 | .Nm EVP_CIPHER_CTX_init , | 57 | .Nm EVP_CIPHER_CTX_init , |
| 58 | .Nm EVP_CIPHER_CTX_free , | ||
| 8 | .Nm EVP_EncryptInit_ex , | 59 | .Nm EVP_EncryptInit_ex , |
| 9 | .Nm EVP_EncryptUpdate , | 60 | .Nm EVP_EncryptUpdate , |
| 10 | .Nm EVP_EncryptFinal_ex , | 61 | .Nm EVP_EncryptFinal_ex , |
| @@ -66,7 +117,6 @@ | |||
| 66 | .Nm EVP_idea_ecb , | 117 | .Nm EVP_idea_ecb , |
| 67 | .Nm EVP_idea_cfb , | 118 | .Nm EVP_idea_cfb , |
| 68 | .Nm EVP_idea_ofb , | 119 | .Nm EVP_idea_ofb , |
| 69 | .Nm EVP_idea_cbc , | ||
| 70 | .Nm EVP_rc2_cbc , | 120 | .Nm EVP_rc2_cbc , |
| 71 | .Nm EVP_rc2_ecb , | 121 | .Nm EVP_rc2_ecb , |
| 72 | .Nm EVP_rc2_cfb , | 122 | .Nm EVP_rc2_cfb , |
| @@ -81,6 +131,18 @@ | |||
| 81 | .Nm EVP_cast5_ecb , | 131 | .Nm EVP_cast5_ecb , |
| 82 | .Nm EVP_cast5_cfb , | 132 | .Nm EVP_cast5_cfb , |
| 83 | .Nm EVP_cast5_ofb , | 133 | .Nm EVP_cast5_ofb , |
| 134 | .Nm EVP_aes_128_cbc , | ||
| 135 | .Nm EVP_aes_128_ecb , | ||
| 136 | .Nm EVP_aes_128_cfb , | ||
| 137 | .Nm EVP_aes_128_ofb , | ||
| 138 | .Nm EVP_aes_192_cbc , | ||
| 139 | .Nm EVP_aes_192_ecb , | ||
| 140 | .Nm EVP_aes_192_cfb , | ||
| 141 | .Nm EVP_aes_192_ofb , | ||
| 142 | .Nm EVP_aes_256_cbc , | ||
| 143 | .Nm EVP_aes_256_ecb , | ||
| 144 | .Nm EVP_aes_256_cfb , | ||
| 145 | .Nm EVP_aes_256_ofb , | ||
| 84 | .Nm EVP_aes_128_gcm , | 146 | .Nm EVP_aes_128_gcm , |
| 85 | .Nm EVP_aes_192_gcm , | 147 | .Nm EVP_aes_192_gcm , |
| 86 | .Nm EVP_aes_256_gcm , | 148 | .Nm EVP_aes_256_gcm , |
| @@ -90,14 +152,21 @@ | |||
| 90 | .Nm EVP_rc5_32_12_16_cbc , | 152 | .Nm EVP_rc5_32_12_16_cbc , |
| 91 | .Nm EVP_rc5_32_12_16_cfb , | 153 | .Nm EVP_rc5_32_12_16_cfb , |
| 92 | .Nm EVP_rc5_32_12_16_ecb , | 154 | .Nm EVP_rc5_32_12_16_ecb , |
| 93 | .Nm EVP_rc5_32_12_16_ofb | 155 | .Nm EVP_rc5_32_12_16_ofb , |
| 156 | .Nm EVP_chacha20 | ||
| 94 | .Nd EVP cipher routines | 157 | .Nd EVP cipher routines |
| 95 | .Sh SYNOPSIS | 158 | .Sh SYNOPSIS |
| 96 | .In openssl/evp.h | 159 | .In openssl/evp.h |
| 160 | .Ft EVP_CIPHER_CTX * | ||
| 161 | .Fn EVP_CIPHER_CTX_new void | ||
| 97 | .Ft void | 162 | .Ft void |
| 98 | .Fo EVP_CIPHER_CTX_init | 163 | .Fo EVP_CIPHER_CTX_init |
| 99 | .Fa "EVP_CIPHER_CTX *ctx" | 164 | .Fa "EVP_CIPHER_CTX *ctx" |
| 100 | .Fc | 165 | .Fc |
| 166 | .Ft void | ||
| 167 | .Fo EVP_CIPHER_CTX_free | ||
| 168 | .Fa "EVP_CIPHER_CTX *ctx" | ||
| 169 | .Fc | ||
| 101 | .Ft int | 170 | .Ft int |
| 102 | .Fo EVP_EncryptInit_ex | 171 | .Fo EVP_EncryptInit_ex |
| 103 | .Fa "EVP_CIPHER_CTX *ctx" | 172 | .Fa "EVP_CIPHER_CTX *ctx" |
| @@ -230,28 +299,83 @@ | |||
| 230 | .Fo EVP_get_cipherbyname | 299 | .Fo EVP_get_cipherbyname |
| 231 | .Fa "const char *name" | 300 | .Fa "const char *name" |
| 232 | .Fc | 301 | .Fc |
| 233 | .Fd #define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a)) | 302 | .Ft const EVP_CIPHER * |
| 234 | .Fd #define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a)) | 303 | .Fo EVP_get_cipherbynid |
| 235 | .Fd #define EVP_CIPHER_nid(e) ((e)->nid) | 304 | .Fa "int nid" |
| 236 | .Fd #define EVP_CIPHER_block_size(e) ((e)->block_size) | 305 | .Fc |
| 237 | .Fd #define EVP_CIPHER_key_length(e) ((e)->key_len) | 306 | .Ft const EVP_CIPHER * |
| 238 | .Fd #define EVP_CIPHER_iv_length(e) ((e)->iv_len) | 307 | .Fo EVP_get_cipherbyobj |
| 239 | .Fd #define EVP_CIPHER_flags(e) ((e)->flags) | 308 | .Fa "const ASN1_OBJECT *a" |
| 240 | .Fd #define EVP_CIPHER_mode(e) ((e)->flags) & EVP_CIPH_MODE) | 309 | .Fc |
| 310 | .Ft int | ||
| 311 | .Fo EVP_CIPHER_nid | ||
| 312 | .Fa "const EVP_CIPHER *e" | ||
| 313 | .Fc | ||
| 314 | .Ft int | ||
| 315 | .Fo EVP_CIPHER_block_size | ||
| 316 | .Fa "const EVP_CIPHER *e" | ||
| 317 | .Fc | ||
| 318 | .Ft int | ||
| 319 | .Fo EVP_CIPHER_key_length | ||
| 320 | .Fa "const EVP_CIPHER *e" | ||
| 321 | .Fc | ||
| 322 | .Ft int | ||
| 323 | .Fo EVP_CIPHER_iv_length | ||
| 324 | .Fa "const EVP_CIPHER *e" | ||
| 325 | .Fc | ||
| 326 | .Ft unsigned long | ||
| 327 | .Fo EVP_CIPHER_flags | ||
| 328 | .Fa "const EVP_CIPHER *e" | ||
| 329 | .Fc | ||
| 330 | .Ft unsigned long | ||
| 331 | .Fo EVP_CIPHER_mode | ||
| 332 | .Fa "const EVP_CIPHER *e" | ||
| 333 | .Fc | ||
| 241 | .Ft int | 334 | .Ft int |
| 242 | .Fo EVP_CIPHER_type | 335 | .Fo EVP_CIPHER_type |
| 243 | .Fa "const EVP_CIPHER *ctx" | 336 | .Fa "const EVP_CIPHER *ctx" |
| 244 | .Fc | 337 | .Fc |
| 245 | .Fd #define EVP_CIPHER_CTX_cipher(e) ((e)->cipher) | 338 | .Ft const EVP_CIPHER * |
| 246 | .Fd #define EVP_CIPHER_CTX_nid(e) ((e)->cipher->nid) | 339 | .Fo EVP_CIPHER_CTX_cipher |
| 247 | .Fd #define EVP_CIPHER_CTX_block_size(e) ((e)->cipher->block_size) | 340 | .Fa "const EVP_CIPHER_CTX *ctx" |
| 248 | .Fd #define EVP_CIPHER_CTX_key_length(e) ((e)->key_len) | 341 | .Fc |
| 249 | .Fd #define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len) | 342 | .Ft int |
| 250 | .Fd #define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) | 343 | .Fo EVP_CIPHER_CTX_nid |
| 251 | .Fd #define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d)) | 344 | .Fa "const EVP_CIPHER_CTX *ctx" |
| 252 | .Fd #define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c)) | 345 | .Fc |
| 253 | .Fd #define EVP_CIPHER_CTX_flags(e) ((e)->cipher->flags) | 346 | .Ft int |
| 254 | .Fd #define EVP_CIPHER_CTX_mode(e) ((e)->cipher->flags & EVP_CIPH_MODE) | 347 | .Fo EVP_CIPHER_CTX_block_size |
| 348 | .Fa "const EVP_CIPHER_CTX *ctx" | ||
| 349 | .Fc | ||
| 350 | .Ft int | ||
| 351 | .Fo EVP_CIPHER_CTX_key_length | ||
| 352 | .Fa "const EVP_CIPHER_CTX *ctx" | ||
| 353 | .Fc | ||
| 354 | .Ft int | ||
| 355 | .Fo EVP_CIPHER_CTX_iv_length | ||
| 356 | .Fa "const EVP_CIPHER_CTX *ctx" | ||
| 357 | .Fc | ||
| 358 | .Ft void * | ||
| 359 | .Fo EVP_CIPHER_CTX_get_app_data | ||
| 360 | .Fa "const EVP_CIPHER_CTX *ctx" | ||
| 361 | .Fc | ||
| 362 | .Ft void | ||
| 363 | .Fo EVP_CIPHER_CTX_set_app_data | ||
| 364 | .Fa "const EVP_CIPHER_CTX *ctx" | ||
| 365 | .Fa "void *data" | ||
| 366 | .Fc | ||
| 367 | .Ft int | ||
| 368 | .Fo EVP_CIPHER_CTX_type | ||
| 369 | .Fa "const EVP_CIPHER_CTX *ctx" | ||
| 370 | .Fc | ||
| 371 | .Ft unsigned long | ||
| 372 | .Fo EVP_CIPHER_CTX_flags | ||
| 373 | .Fa "const EVP_CIPHER_CTX *ctx" | ||
| 374 | .Fc | ||
| 375 | .Ft unsigned long | ||
| 376 | .Fo EVP_CIPHER_CTX_mode | ||
| 377 | .Fa "const EVP_CIPHER_CTX *ctx" | ||
| 378 | .Fc | ||
| 255 | .Ft int | 379 | .Ft int |
| 256 | .Fo EVP_CIPHER_param_to_asn1 | 380 | .Fo EVP_CIPHER_param_to_asn1 |
| 257 | .Fa "EVP_CIPHER_CTX *c" | 381 | .Fa "EVP_CIPHER_CTX *c" |
| @@ -266,10 +390,26 @@ | |||
| 266 | The EVP cipher routines are a high level interface to certain symmetric | 390 | The EVP cipher routines are a high level interface to certain symmetric |
| 267 | ciphers. | 391 | ciphers. |
| 268 | .Pp | 392 | .Pp |
| 393 | .Fn EVP_CIPHER_CTX_new | ||
| 394 | creates a cipher context. | ||
| 395 | .Pp | ||
| 269 | .Fn EVP_CIPHER_CTX_init | 396 | .Fn EVP_CIPHER_CTX_init |
| 270 | initializes the cipher context | 397 | initializes the cipher context |
| 271 | .Fa ctx . | 398 | .Fa ctx . |
| 272 | .Pp | 399 | .Pp |
| 400 | .Fn EVP_CIPHER_CTX_free | ||
| 401 | clears all information from a cipher context and frees up any | ||
| 402 | allocated memory associate with it, including | ||
| 403 | .Fa ctx | ||
| 404 | itself. | ||
| 405 | This function should be called after all operations using a cipher | ||
| 406 | are complete, so sensitive information does not remain in memory. | ||
| 407 | If | ||
| 408 | .Fa ctx | ||
| 409 | is a | ||
| 410 | .Dv NULL | ||
| 411 | pointer, no action occurs. | ||
| 412 | .Pp | ||
| 273 | .Fn EVP_EncryptInit_ex | 413 | .Fn EVP_EncryptInit_ex |
| 274 | sets up the cipher context | 414 | sets up the cipher context |
| 275 | .Fa ctx | 415 | .Fa ctx |
| @@ -317,7 +457,7 @@ of data. | |||
| 317 | The amount of data written depends on the block alignment of the | 457 | The amount of data written depends on the block alignment of the |
| 318 | encrypted data: as a result the amount of data written may be anything | 458 | encrypted data: as a result the amount of data written may be anything |
| 319 | from zero bytes to (inl + cipher_block_size - 1) so | 459 | from zero bytes to (inl + cipher_block_size - 1) so |
| 320 | .Fa outl | 460 | .Fa out |
| 321 | should contain sufficient room. | 461 | should contain sufficient room. |
| 322 | The actual number of bytes written is placed in | 462 | The actual number of bytes written is placed in |
| 323 | .Fa outl . | 463 | .Fa outl . |
| @@ -432,10 +572,16 @@ corresponding OBJECT IDENTIFIER. | |||
| 432 | .Pp | 572 | .Pp |
| 433 | .Fn EVP_CIPHER_CTX_set_padding | 573 | .Fn EVP_CIPHER_CTX_set_padding |
| 434 | enables or disables padding. | 574 | enables or disables padding. |
| 575 | This function should be called after the context is set up for | ||
| 576 | encryption or decryption with | ||
| 577 | .Fn EVP_EncryptInit_ex , | ||
| 578 | .Fn EVP_DecryptInit_ex , | ||
| 579 | or | ||
| 580 | EVP_CipherInit_ex . | ||
| 435 | By default encryption operations are padded using standard block padding | 581 | By default encryption operations are padded using standard block padding |
| 436 | and the padding is checked and removed when decrypting. | 582 | and the padding is checked and removed when decrypting. |
| 437 | If the | 583 | If the |
| 438 | .Sy padding | 584 | .Fa padding |
| 439 | parameter is zero, then no padding is performed, the total amount of data | 585 | parameter is zero, then no padding is performed, the total amount of data |
| 440 | encrypted or decrypted must then be a multiple of the block size or an | 586 | encrypted or decrypted must then be a multiple of the block size or an |
| 441 | error will occur. | 587 | error will occur. |
| @@ -483,7 +629,7 @@ or | |||
| 483 | .Vt EVP_CIPHER_CTX | 629 | .Vt EVP_CIPHER_CTX |
| 484 | structure. | 630 | structure. |
| 485 | The constant | 631 | The constant |
| 486 | .Dv EVP_MAX_IV_LENGTH | 632 | .Dv EVP_MAX_BLOCK_LENGTH |
| 487 | is also the maximum block length for all ciphers. | 633 | is also the maximum block length for all ciphers. |
| 488 | .Pp | 634 | .Pp |
| 489 | .Fn EVP_CIPHER_type | 635 | .Fn EVP_CIPHER_type |
| @@ -553,7 +699,62 @@ the RC2 effective key length is not supported). | |||
| 553 | allows various cipher specific parameters to be determined and set. | 699 | allows various cipher specific parameters to be determined and set. |
| 554 | Currently only the RC2 effective key length and the number of rounds of | 700 | Currently only the RC2 effective key length and the number of rounds of |
| 555 | RC5 can be set. | 701 | RC5 can be set. |
| 702 | .Pp | ||
| 703 | Where possible the EVP interface to symmetric ciphers should be | ||
| 704 | used in preference to the low level interfaces. | ||
| 705 | This is because the code then becomes transparent to the cipher used and | ||
| 706 | much more flexible. | ||
| 707 | .Pp | ||
| 708 | PKCS padding works by adding n padding bytes of value n to make the | ||
| 709 | total length of the encrypted data a multiple of the block size. | ||
| 710 | Padding is always added so if the data is already a multiple of the | ||
| 711 | block size n will equal the block size. | ||
| 712 | For example if the block size is 8 and 11 bytes are to be encrypted then | ||
| 713 | 5 padding bytes of value 5 will be added. | ||
| 714 | .Pp | ||
| 715 | When decrypting the final block is checked to see if it has the correct | ||
| 716 | form. | ||
| 717 | .Pp | ||
| 718 | Although the decryption operation can produce an error if padding is | ||
| 719 | enabled, it is not a strong test that the input data or key is correct. | ||
| 720 | A random block has better than 1 in 256 chance of being of the correct | ||
| 721 | format and problems with the input data earlier on will not produce a | ||
| 722 | final decrypt error. | ||
| 723 | .Pp | ||
| 724 | If padding is disabled then the decryption operation will always succeed | ||
| 725 | if the total amount of data decrypted is a multiple of the block size. | ||
| 726 | .Pp | ||
| 727 | The functions | ||
| 728 | .Fn EVP_EncryptInit , | ||
| 729 | .Fn EVP_EncryptFinal , | ||
| 730 | .Fn EVP_DecryptInit , | ||
| 731 | .Fn EVP_CipherInit , | ||
| 732 | and | ||
| 733 | .Fn EVP_CipherFinal | ||
| 734 | are obsolete but are retained for compatibility with existing code. | ||
| 735 | New code should use | ||
| 736 | .Fn EVP_EncryptInit_ex , | ||
| 737 | .Fn EVP_EncryptFinal_ex , | ||
| 738 | .Fn EVP_DecryptInit_ex , | ||
| 739 | .Fn EVP_DecryptFinal_ex , | ||
| 740 | .Fn EVP_CipherInit_ex , | ||
| 741 | and | ||
| 742 | .Fn EVP_CipherFinal_ex | ||
| 743 | because they can reuse an existing context without allocating and | ||
| 744 | freeing it up on each call. | ||
| 745 | .Pp | ||
| 746 | .Fn EVP_get_cipherbynid | ||
| 747 | and | ||
| 748 | .Fn EVP_get_cipherbyobj | ||
| 749 | are implemented as macros. | ||
| 556 | .Sh RETURN VALUES | 750 | .Sh RETURN VALUES |
| 751 | .Fn EVP_CIPHER_CTX_new | ||
| 752 | returns a pointer to a newly created | ||
| 753 | .Vt EVP_CIPHER_CTX | ||
| 754 | for success or | ||
| 755 | .Dv NULL | ||
| 756 | for failure. | ||
| 757 | .Pp | ||
| 557 | .Fn EVP_EncryptInit_ex , | 758 | .Fn EVP_EncryptInit_ex , |
| 558 | .Fn EVP_EncryptUpdate , | 759 | .Fn EVP_EncryptUpdate , |
| 559 | and | 760 | and |
| @@ -625,103 +826,61 @@ structure. | |||
| 625 | .Fn EVP_CIPHER_param_to_asn1 | 826 | .Fn EVP_CIPHER_param_to_asn1 |
| 626 | and | 827 | and |
| 627 | .Fn EVP_CIPHER_asn1_to_param | 828 | .Fn EVP_CIPHER_asn1_to_param |
| 628 | return 1 for success or 0 for failure. | 829 | return greater than zero for success and zero or a negative number |
| 629 | .Pp | 830 | for failure. |
| 630 | Where possible the EVP interface to symmetric ciphers should be | ||
| 631 | used in preference to the low level interfaces. | ||
| 632 | This is because the code then becomes transparent to the cipher used and | ||
| 633 | much more flexible. | ||
| 634 | .Pp | ||
| 635 | PKCS padding works by adding n padding bytes of value n to make the | ||
| 636 | total length of the encrypted data a multiple of the block size. | ||
| 637 | Padding is always added so if the data is already a multiple of the | ||
| 638 | block size n will equal the block size. | ||
| 639 | For example if the block size is 8 and 11 bytes are to be encrypted then | ||
| 640 | 5 padding bytes of value 5 will be added. | ||
| 641 | .Pp | ||
| 642 | When decrypting the final block is checked to see if it has the correct | ||
| 643 | form. | ||
| 644 | .Pp | ||
| 645 | Although the decryption operation can produce an error if padding is | ||
| 646 | enabled, it is not a strong test that the input data or key is correct. | ||
| 647 | A random block has better than 1 in 256 chance of being of the correct | ||
| 648 | format and problems with the input data earlier on will not produce a | ||
| 649 | final decrypt error. | ||
| 650 | .Pp | ||
| 651 | If padding is disabled then the decryption operation will always succeed | ||
| 652 | if the total amount of data decrypted is a multiple of the block size. | ||
| 653 | .Pp | ||
| 654 | The functions | ||
| 655 | .Fn EVP_EncryptInit , | ||
| 656 | .Fn EVP_EncryptFinal , | ||
| 657 | .Fn EVP_DecryptInit , | ||
| 658 | .Fn EVP_CipherInit , | ||
| 659 | and | ||
| 660 | .Fn EVP_CipherFinal | ||
| 661 | are obsolete but are retained for compatibility with existing code. | ||
| 662 | New code should use | ||
| 663 | .Fn EVP_EncryptInit_ex , | ||
| 664 | .Fn EVP_EncryptFinal_ex , | ||
| 665 | .Fn EVP_DecryptInit_ex , | ||
| 666 | .Fn EVP_DecryptFinal_ex , | ||
| 667 | .Fn EVP_CipherInit_ex , | ||
| 668 | and | ||
| 669 | .Fn EVP_CipherFinal_ex | ||
| 670 | because they can reuse an existing context without allocating and | ||
| 671 | freeing it up on each call. | ||
| 672 | .Sh CIPHER LISTING | 831 | .Sh CIPHER LISTING |
| 673 | All algorithms have a fixed key length unless otherwise stated. | 832 | All algorithms have a fixed key length unless otherwise stated. |
| 674 | .Bl -tag -width Ds | 833 | .Bl -tag -width Ds |
| 675 | .It Fn EVP_enc_null void | 834 | .It Fn EVP_enc_null |
| 676 | Null cipher: does nothing. | 835 | Null cipher: does nothing. |
| 677 | .It Xo | 836 | .It Xo |
| 678 | .Fn EVP_aes_128_cbc void , | 837 | .Fn EVP_aes_128_cbc , |
| 679 | .Fn EVP_aes_128_ecb void , | 838 | .Fn EVP_aes_128_ecb , |
| 680 | .Fn EVP_aes_128_cfb void , | 839 | .Fn EVP_aes_128_cfb , |
| 681 | .Fn EVP_aes_128_ofb void | 840 | .Fn EVP_aes_128_ofb |
| 682 | .Xc | 841 | .Xc |
| 683 | 128-bit AES in CBC, ECB, CFB and OFB modes respectively. | 842 | AES with a 128-bit key in CBC, ECB, CFB and OFB modes respectively. |
| 684 | .It Xo | 843 | .It Xo |
| 685 | .Fn EVP_aes_192_cbc void , | 844 | .Fn EVP_aes_192_cbc , |
| 686 | .Fn EVP_aes_192_ecb void , | 845 | .Fn EVP_aes_192_ecb , |
| 687 | .Fn EVP_aes_192_cfb void , | 846 | .Fn EVP_aes_192_cfb , |
| 688 | .Fn EVP_aes_192_ofb void | 847 | .Fn EVP_aes_192_ofb |
| 689 | .Xc | 848 | .Xc |
| 690 | 192-bit AES in CBC, ECB, CFB and OFB modes respectively. | 849 | AES with a 192-bit key in CBC, ECB, CFB and OFB modes respectively. |
| 691 | .It Xo | 850 | .It Xo |
| 692 | .Fn EVP_aes_256_cbc void , | 851 | .Fn EVP_aes_256_cbc , |
| 693 | .Fn EVP_aes_256_ecb void , | 852 | .Fn EVP_aes_256_ecb , |
| 694 | .Fn EVP_aes_256_cfb void , | 853 | .Fn EVP_aes_256_cfb , |
| 695 | .Fn EVP_aes_256_ofb void | 854 | .Fn EVP_aes_256_ofb |
| 696 | .Xc | 855 | .Xc |
| 697 | 256-bit AES in CBC, ECB, CFB and OFB modes respectively. | 856 | AES with a 256-bit key in CBC, ECB, CFB and OFB modes respectively. |
| 698 | .It Xo | 857 | .It Xo |
| 699 | .Fn EVP_des_cbc void , | 858 | .Fn EVP_des_cbc , |
| 700 | .Fn EVP_des_ecb void , | 859 | .Fn EVP_des_ecb , |
| 701 | .Fn EVP_des_cfb void , | 860 | .Fn EVP_des_cfb , |
| 702 | .Fn EVP_des_ofb void | 861 | .Fn EVP_des_ofb |
| 703 | .Xc | 862 | .Xc |
| 704 | DES in CBC, ECB, CFB and OFB modes respectively. | 863 | DES in CBC, ECB, CFB and OFB modes respectively. |
| 705 | .It Xo | 864 | .It Xo |
| 706 | .Fn EVP_des_ede_cbc void , | 865 | .Fn EVP_des_ede_cbc , |
| 707 | .Fn EVP_des_ede void , | 866 | .Fn EVP_des_ede , |
| 708 | .Fn EVP_des_ede_ofb void , | 867 | .Fn EVP_des_ede_ofb , |
| 709 | .Fn EVP_des_ede_cfb void | 868 | .Fn EVP_des_ede_cfb |
| 710 | .Xc | 869 | .Xc |
| 711 | Two key triple DES in CBC, ECB, CFB and OFB modes respectively. | 870 | Two key triple DES in CBC, ECB, CFB and OFB modes respectively. |
| 712 | .It Xo | 871 | .It Xo |
| 713 | .Fn EVP_des_ede3_cbc void , | 872 | .Fn EVP_des_ede3_cbc , |
| 714 | .Fn EVP_des_ede3 void , | 873 | .Fn EVP_des_ede3 , |
| 715 | .Fn EVP_des_ede3_ofb void , | 874 | .Fn EVP_des_ede3_ofb , |
| 716 | .Fn EVP_des_ede3_cfb void | 875 | .Fn EVP_des_ede3_cfb |
| 717 | .Xc | 876 | .Xc |
| 718 | Three key triple DES in CBC, ECB, CFB and OFB modes respectively. | 877 | Three key triple DES in CBC, ECB, CFB and OFB modes respectively. |
| 719 | .It Fn EVP_desx_cbc void | 878 | .It Fn EVP_desx_cbc |
| 720 | DESX algorithm in CBC mode. | 879 | DESX algorithm in CBC mode. |
| 721 | .It Fn EVP_rc4 void | 880 | .It Fn EVP_rc4 |
| 722 | RC4 stream cipher. | 881 | RC4 stream cipher. |
| 723 | This is a variable key length cipher with default key length 128 bits. | 882 | This is a variable key length cipher with default key length 128 bits. |
| 724 | .It Fn EVP_rc4_40 void | 883 | .It Fn EVP_rc4_40 |
| 725 | RC4 stream cipher with 40-bit key length. | 884 | RC4 stream cipher with 40-bit key length. |
| 726 | This is obsolete and new code should use | 885 | This is obsolete and new code should use |
| 727 | .Fn EVP_rc4 | 886 | .Fn EVP_rc4 |
| @@ -729,25 +888,25 @@ and the | |||
| 729 | .Fn EVP_CIPHER_CTX_set_key_length | 888 | .Fn EVP_CIPHER_CTX_set_key_length |
| 730 | function. | 889 | function. |
| 731 | .It Xo | 890 | .It Xo |
| 732 | .Fn EVP_idea_cbc void , | 891 | .Fn EVP_idea_cbc , |
| 733 | .Fn EVP_idea_ecb void , | 892 | .Fn EVP_idea_ecb , |
| 734 | .Fn EVP_idea_cfb void , | 893 | .Fn EVP_idea_cfb , |
| 735 | .Fn EVP_idea_ofb void | 894 | .Fn EVP_idea_ofb |
| 736 | .Xc | 895 | .Xc |
| 737 | IDEA encryption algorithm in CBC, ECB, CFB and OFB modes respectively. | 896 | IDEA encryption algorithm in CBC, ECB, CFB and OFB modes respectively. |
| 738 | .It Xo | 897 | .It Xo |
| 739 | .Fn EVP_rc2_cbc void , | 898 | .Fn EVP_rc2_cbc , |
| 740 | .Fn EVP_rc2_ecb void , | 899 | .Fn EVP_rc2_ecb , |
| 741 | .Fn EVP_rc2_cfb void , | 900 | .Fn EVP_rc2_cfb , |
| 742 | .Fn EVP_rc2_ofb void | 901 | .Fn EVP_rc2_ofb |
| 743 | .Xc | 902 | .Xc |
| 744 | RC2 encryption algorithm in CBC, ECB, CFB and OFB modes respectively. | 903 | RC2 encryption algorithm in CBC, ECB, CFB and OFB modes respectively. |
| 745 | This is a variable key length cipher with an additional parameter called | 904 | This is a variable key length cipher with an additional parameter called |
| 746 | "effective key bits" or "effective key length". | 905 | "effective key bits" or "effective key length". |
| 747 | By default both are set to 128 bits. | 906 | By default both are set to 128 bits. |
| 748 | .It Xo | 907 | .It Xo |
| 749 | .Fn EVP_rc2_40_cbc void , | 908 | .Fn EVP_rc2_40_cbc , |
| 750 | .Fn EVP_rc2_64_cbc void | 909 | .Fn EVP_rc2_64_cbc |
| 751 | .Xc | 910 | .Xc |
| 752 | RC2 algorithm in CBC mode with a default key length and effective key | 911 | RC2 algorithm in CBC mode with a default key length and effective key |
| 753 | length of 40 and 64 bits. | 912 | length of 40 and 64 bits. |
| @@ -758,58 +917,146 @@ and | |||
| 758 | .Fn EVP_CIPHER_CTX_ctrl | 917 | .Fn EVP_CIPHER_CTX_ctrl |
| 759 | to set the key length and effective key length. | 918 | to set the key length and effective key length. |
| 760 | .It Xo | 919 | .It Xo |
| 761 | .Fn EVP_bf_cbc void , | 920 | .Fn EVP_bf_cbc , |
| 762 | .Fn EVP_bf_ecb void , | 921 | .Fn EVP_bf_ecb , |
| 763 | .Fn EVP_bf_cfb void , | 922 | .Fn EVP_bf_cfb , |
| 764 | .Fn EVP_bf_ofb void | 923 | .Fn EVP_bf_ofb |
| 765 | .Xc | 924 | .Xc |
| 766 | Blowfish encryption algorithm in CBC, ECB, CFB and OFB modes | 925 | Blowfish encryption algorithm in CBC, ECB, CFB and OFB modes |
| 767 | respectively. | 926 | respectively. |
| 768 | This is a variable key length cipher. | 927 | This is a variable key length cipher. |
| 769 | .It Xo | 928 | .It Xo |
| 770 | .Fn EVP_cast5_cbc void , | 929 | .Fn EVP_cast5_cbc , |
| 771 | .Fn EVP_cast5_ecb void , | 930 | .Fn EVP_cast5_ecb , |
| 772 | .Fn EVP_cast5_cfb void , | 931 | .Fn EVP_cast5_cfb , |
| 773 | .Fn EVP_cast5_ofb void | 932 | .Fn EVP_cast5_ofb |
| 774 | .Xc | 933 | .Xc |
| 775 | CAST encryption algorithm in CBC, ECB, CFB and OFB modes respectively. | 934 | CAST encryption algorithm in CBC, ECB, CFB and OFB modes respectively. |
| 776 | This is a variable key length cipher. | 935 | This is a variable key length cipher. |
| 777 | .It Xo | 936 | .It Xo |
| 778 | .Fn EVP_rc5_32_12_16_cbc void , | 937 | .Fn EVP_rc5_32_12_16_cbc , |
| 779 | .Fn EVP_rc5_32_12_16_ecb void , | 938 | .Fn EVP_rc5_32_12_16_ecb , |
| 780 | .Fn EVP_rc5_32_12_16_cfb void , | 939 | .Fn EVP_rc5_32_12_16_cfb , |
| 781 | .Fn EVP_rc5_32_12_16_ofb void | 940 | .Fn EVP_rc5_32_12_16_ofb |
| 782 | .Xc | 941 | .Xc |
| 783 | RC5 encryption algorithm in CBC, ECB, CFB and OFB modes respectively. | 942 | RC5 encryption algorithm in CBC, ECB, CFB and OFB modes respectively. |
| 784 | This is a variable key length cipher with an additional "number of | 943 | This is a variable key length cipher with an additional "number of |
| 785 | rounds" parameter. | 944 | rounds" parameter. |
| 786 | By default the key length is set to 128 bits and 12 rounds. | 945 | By default the key length is set to 128 bits and 12 rounds. |
| 946 | .It Xo | ||
| 947 | .Fn EVP_aes_128_gcm , | ||
| 948 | .Fn EVP_aes_192_gcm , | ||
| 949 | .Fn EVP_aes_256_gcm | ||
| 950 | .Xc | ||
| 951 | AES Galois Counter Mode (GCM) for 128, 192 and 256 bit keys respectively. | ||
| 952 | These ciphers require additional control operations to function | ||
| 953 | correctly: see the GCM mode section below for details. | ||
| 954 | .It Xo | ||
| 955 | .Fn EVP_aes_128_ccm , | ||
| 956 | .Fn EVP_aes_192_ccm , | ||
| 957 | .Fn EVP_aes_256_ccm | ||
| 958 | .Xc | ||
| 959 | AES Counter with CBC-MAC Mode (CCM) for 128, 192 and 256 bit keys | ||
| 960 | respectively. | ||
| 961 | These ciphers require additional control operations to function | ||
| 962 | correctly: see CCM mode section below for details. | ||
| 963 | .It Fn EVP_chacha20 | ||
| 964 | The ChaCha20 stream cipher. | ||
| 965 | The key length is 256 bits, the IV is 96 bits long. | ||
| 787 | .El | 966 | .El |
| 788 | .Sh EXAMPLES | 967 | .Ss GCM mode |
| 789 | Get the number of rounds used in RC5: | 968 | For GCM mode ciphers, the behaviour of the EVP interface |
| 790 | .Bd -literal -offset indent | 969 | is subtly altered and several additional ctrl operations are |
| 791 | int nrounds; | 970 | supported. |
| 792 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GET_RC5_ROUNDS, 0, &nrounds); | ||
| 793 | .Ed | ||
| 794 | .Pp | 971 | .Pp |
| 795 | Get the RC2 effective key length: | 972 | To specify any additional authenticated data (AAD), a call to |
| 796 | .Bd -literal -offset indent | 973 | .Fn EVP_CipherUpdate , |
| 797 | int key_bits; | 974 | .Fn EVP_EncryptUpdate , |
| 798 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GET_RC2_KEY_BITS, 0, &key_bits); | 975 | or |
| 799 | .Ed | 976 | .Fn EVP_DecryptUpdate |
| 977 | should be made with the output parameter out set to | ||
| 978 | .Dv NULL . | ||
| 800 | .Pp | 979 | .Pp |
| 801 | Set the number of rounds used in RC5: | 980 | When decrypting, the return value of |
| 802 | .Bd -literal -offset indent | 981 | .Fn EVP_DecryptFinal |
| 803 | int nrounds; | 982 | or |
| 804 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_RC5_ROUNDS, nrounds, NULL); | 983 | .Fn EVP_CipherFinal |
| 805 | .Ed | 984 | indicates if the operation was successful. |
| 985 | If it does not indicate success, the authentication operation has | ||
| 986 | failed and any output data MUST NOT be used as it is corrupted. | ||
| 806 | .Pp | 987 | .Pp |
| 807 | Set the effective key length used in RC2: | 988 | The following ctrls are supported in GCM mode: |
| 808 | .Bd -literal -offset indent | 989 | .Bl -tag -width Ds |
| 809 | int key_bits; | 990 | .It Fn EVP_CIPHER_CTX_ctrl ctx EVP_CTRL_GCM_SET_IVLEN ivlen NULL |
| 810 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_RC2_KEY_BITS, key_bits, NULL); | 991 | Sets the IV length: this call can only be made before specifying an IV. |
| 811 | .Ed | 992 | If not called, a default IV length is used. |
| 993 | For GCM AES the default is 12, i.e. 96 bits. | ||
| 994 | .It Fn EVP_CIPHER_CTX_ctrl ctx EVP_CTRL_GCM_GET_TAG taglen tag | ||
| 995 | Writes | ||
| 996 | .Fa taglen | ||
| 997 | bytes of the tag value to the buffer indicated by | ||
| 998 | .Fa tag . | ||
| 999 | This call can only be made when encrypting data and after all data has | ||
| 1000 | been processed, e.g. after an | ||
| 1001 | .Fn EVP_EncryptFinal | ||
| 1002 | call. | ||
| 1003 | .It Fn EVP_CIPHER_CTX_ctrl ctx EVP_CTRL_GCM_SET_TAG taglen tag | ||
| 1004 | Sets the expected tag to | ||
| 1005 | .Fa taglen | ||
| 1006 | bytes from | ||
| 1007 | .Fa tag . | ||
| 1008 | This call is only legal when decrypting data and must be made before | ||
| 1009 | any data is processed, e.g. before any | ||
| 1010 | .Fa EVP_DecryptUpdate | ||
| 1011 | call. | ||
| 1012 | .El | ||
| 1013 | .Ss CCM mode | ||
| 1014 | The behaviour of CCM mode ciphers is similar to GCM mode, but with | ||
| 1015 | a few additional requirements and different ctrl values. | ||
| 812 | .Pp | 1016 | .Pp |
| 1017 | Like GCM mode any additional authenticated data (AAD) is passed | ||
| 1018 | by calling | ||
| 1019 | .Fn EVP_CipherUpdate , | ||
| 1020 | .Fn EVP_EncryptUpdate , | ||
| 1021 | or | ||
| 1022 | .Fn EVP_DecryptUpdate | ||
| 1023 | with the output parameter out set to | ||
| 1024 | .Dv NULL . | ||
| 1025 | Additionally, the total | ||
| 1026 | plaintext or ciphertext length MUST be passed to | ||
| 1027 | .Fn EVP_CipherUpdate , | ||
| 1028 | .Fn EVP_EncryptUpdate , | ||
| 1029 | or | ||
| 1030 | .Fn EVP_DecryptUpdate | ||
| 1031 | with the output and input | ||
| 1032 | parameters | ||
| 1033 | .Pq Fa in No and Fa out | ||
| 1034 | set to | ||
| 1035 | .Dv NULL | ||
| 1036 | and the length passed in the | ||
| 1037 | .Fa inl | ||
| 1038 | parameter. | ||
| 1039 | .Pp | ||
| 1040 | The following ctrls are supported in CCM mode: | ||
| 1041 | .Bl -tag -width Ds | ||
| 1042 | .It Fn EVP_CIPHER_CTX_ctrl ctx EVP_CTRL_CCM_SET_TAG taglen tag | ||
| 1043 | This call is made to set the expected CCM tag value when decrypting or | ||
| 1044 | the length of the tag (with the | ||
| 1045 | .Fa tag | ||
| 1046 | parameter set to | ||
| 1047 | .Dv NULL ) | ||
| 1048 | when encrypting. | ||
| 1049 | The tag length is often referred to as M. | ||
| 1050 | If not set, a default value is used (12 for AES). | ||
| 1051 | .It Fn EVP_CIPHER_CTX_ctrl ctx EVP_CTRL_CCM_SET_L ivlen NULL | ||
| 1052 | Sets the CCM L value. | ||
| 1053 | If not set, a default is used (8 for AES). | ||
| 1054 | .It Fn EVP_CIPHER_CTX_ctrl ctx EVP_CTRL_CCM_SET_IVLEN ivlen NULL | ||
| 1055 | Sets the CCM nonce (IV) length: this call can only be made before | ||
| 1056 | specifying an nonce value. | ||
| 1057 | The nonce length is given by 15 - L so it is 7 by default for AES. | ||
| 1058 | .El | ||
| 1059 | .Sh EXAMPLES | ||
| 813 | Encrypt a string using blowfish: | 1060 | Encrypt a string using blowfish: |
| 814 | .Bd -literal -offset 3n | 1061 | .Bd -literal -offset 3n |
| 815 | int | 1062 | int |
