1.\" $OpenBSD: crypto.3,v 1.30 2024/12/07 19:22:15 schwarze Exp $ 2.\" OpenSSL a9c85cea Nov 11 09:33:55 2016 +0100 3.\" 4.\" This file is a derived work. 5.\" The changes are covered by the following Copyright and license: 6.\" 7.\" Copyright (c) 2021 Ingo Schwarze <schwarze@openbsd.org> 8.\" 9.\" Permission to use, copy, modify, and distribute this software for any 10.\" purpose with or without fee is hereby granted, provided that the above 11.\" copyright notice and this permission notice appear in all copies. 12.\" 13.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 14.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 15.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 16.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 17.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 18.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 19.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20.\" 21.\" The original file was written by Ulf Moeller <ulf@openssl.org> and 22.\" Dr. Stephen Henson <steve@openssl.org>. 23.\" Copyright (c) 2000, 2002 The OpenSSL Project. All rights reserved. 24.\" 25.\" Redistribution and use in source and binary forms, with or without 26.\" modification, are permitted provided that the following conditions 27.\" are met: 28.\" 29.\" 1. Redistributions of source code must retain the above copyright 30.\" notice, this list of conditions and the following disclaimer. 31.\" 32.\" 2. Redistributions in binary form must reproduce the above copyright 33.\" notice, this list of conditions and the following disclaimer in 34.\" the documentation and/or other materials provided with the 35.\" distribution. 36.\" 37.\" 3. All advertising materials mentioning features or use of this 38.\" software must display the following acknowledgment: 39.\" "This product includes software developed by the OpenSSL Project 40.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 41.\" 42.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 43.\" endorse or promote products derived from this software without 44.\" prior written permission. For written permission, please contact 45.\" openssl-core@openssl.org. 46.\" 47.\" 5. Products derived from this software may not be called "OpenSSL" 48.\" nor may "OpenSSL" appear in their names without prior written 49.\" permission of the OpenSSL Project. 50.\" 51.\" 6. Redistributions of any form whatsoever must retain the following 52.\" acknowledgment: 53.\" "This product includes software developed by the OpenSSL Project 54.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 55.\" 56.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 57.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 58.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 59.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 60.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 61.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 62.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 63.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 65.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 66.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 67.\" OF THE POSSIBILITY OF SUCH DAMAGE. 68.\" 69.Dd $Mdocdate: December 7 2024 $ 70.Dt CRYPTO 3 71.Os 72.Sh NAME 73.Nm crypto 74.Nd OpenSSL cryptographic library 75.Sh DESCRIPTION 76The OpenSSL crypto library implements a wide range of cryptographic 77algorithms used in various Internet standards. 78The services provided by this library are used by the OpenSSL 79implementations of TLS and S/MIME, and they have also been used to 80implement SSH, OpenPGP, and other cryptographic standards. 81.Pp 82.Sy Symmetric ciphers 83including AES, Blowfish, CAST, ChaCha20, IDEA, DES, RC2, and RC4 84are provided by the generic interface 85.Xr EVP_EncryptInit 3 . 86Low-level stand-alone interfaces include 87.Xr AES_encrypt 3 , 88.Xr BF_set_key 3 , 89.Xr ChaCha 3 , 90.Xr DES_set_key 3 , 91.Xr RC2_encrypt 3 , 92and 93.Xr RC4 3 . 94.Pp 95.Sy Public key cryptography and key agreement 96are provided by 97.Xr DH_new 3 , 98.Xr ECDH_compute_key 3 , 99.Xr X25519 3 , 100.Xr DSA_new 3 , 101.Xr ECDSA_SIG_new 3 , 102.Xr RSA_new 3 , 103and 104.Xr EVP_PKEY_new 3 . 105.Pp 106.Sy Certificates 107are handled by 108.Xr X509_new 3 109and 110.Xr X509v3_add_ext 3 . 111.Pp 112.Sy Authentication codes and hash functions 113offered include 114.Xr EVP_DigestInit 3 , 115.Xr CMAC_Init 3 , 116.Xr HMAC 3 , 117.Xr MD4 3 , 118.Xr MD5 3 , 119.Xr RIPEMD160 3 , 120.Xr SHA1 3 , 121and 122.Xr SHA256 3 . 123.Pp 124.Sy Input, output, and data encoding 125facilities include 126.Xr ASN1_TYPE_get 3 , 127.Xr BIO_new 3 , 128.Xr CMS_ContentInfo_new 3 , 129.Xr evp 3 , 130.Xr EVP_EncodeInit 3 , 131.Xr PEM_read 3 , 132.Xr PKCS7_encrypt 3 , 133.Xr PKCS7_sign 3 , 134.Xr PKCS12_create 3 , 135and 136.Xr SMIME_write_PKCS7 3 . 137.Pp 138.Sy Auxiliary features include: 139.Bl -dash -compact 140.It 141configuration file handling: see 142.Xr OPENSSL_config 3 143.It 144error reporting: see 145.Xr ERR 3 146.It 147.Xr OCSP_REQUEST_new 3 148.It 149.Xr UI_new 3 150.El 151.Pp 152.Sy Internal utilities 153include 154.Xr BIO_f_buffer 3 , 155.Xr BN_new 3 , 156.Xr EC_GROUP_new 3 , 157.Xr lh_new 3 , 158and 159.Xr STACK_OF 3 . 160.Sh NAMING CONVENTIONS 161Elements used in the names of API functions include the following: 162.Bl -tag -width Ds 163.It add0 164See 165.Dq set0 166below. 167.It add1 168See 169.Dq set1 170below. 171.It BIO 172basic input and/or output abstraction: 173The function manipulates objects of the idiosyncratic OpenSSL 174.Vt BIO 175object type. 176See 177.Xr BIO_new 3 . 178.It bio 179The function uses a 180.Vt BIO 181object for input or output. 182In many cases, simpler variants of the function are available 183that operate directly on 184.In stdio.h 185.Vt FILE 186objects or directly in RAM, usually using byte arrays. 187.It BIO_f_ 188filter BIO: 189The function returns a pointer to a static built-in object that, 190when passed to 191.Xr BIO_new 3 , 192results in the creation of a BIO object that can write data to 193and/or read data from another 194.Vt BIO 195object. 196.It BIO_s_ 197source and/or sink BIO: 198The function returns a pointer to a static built-in object that, 199when passed to 200.Xr BIO_new 3 , 201results in the creation of a BIO object 202that can write data to an external destination 203and/or read data from an external source, 204for example a file descriptor or object, a memory buffer, or the network. 205.It BN 206big number: 207The function operates on 208.Vt BIGNUM 209objects representing integer numbers of variable, almost unlimited size. 210See 211.Xr BN_new 3 . 212.It cb 213callback: 214The function takes or returns a function pointer 215that is called by API functions from inside the library. 216The function pointed to may be defined by the application program. 217In some cases, API functions with 218.Dq cb 219in their name may return function pointers to internal functions 220defined inside the library that are not API functions. 221The element 222.Dq cb 223is also used in the names of some function pointer datatypes 224declared with 225.Sy typedef . 226In a small number of cases, the all caps form 227.Dq CB 228is used with the same meaning. 229.It CTX 230context: 231The function operates on a wrapper object around another object. 232The purposes and properties of such 233.Dq CTX 234wrapper objects vary wildly depending on the objects in question. 235A few function names use the lower case form 236.Dq ctx 237in the same sense. 238.It d2i 239DER to internal: 240The function decodes input conforming to ASN.1 basic encoding rules (BER) 241and either stores the result in an existing object 242or in a newly allocated object. 243The latter is usually preferable because 244creating a new object is more robust and less error prone. 245In spite of the name, the input usually does not need to conform to ASN.1 246distinguished encoding rules (DER), which are more restrictive than BER. 247.It EVP 248digital EnVeloPe library: 249See 250.Xr evp 3 . 251.It ex 252This name element is used for two completely unrelated purposes. 253.Pp 254extended version: 255The function is similar to an older function without the 256.Dq ex 257in its name, but takes one or more additional arguments 258in order to make it more versatile. 259In several cases, the older version is now deprecated. 260.Pp 261extra data: 262Some object types support storing additional, application-specific data 263inside objects in addition to the data the object is designed to hold. 264The function sets, retrieves, or prepares for using such extra data. 265Related function names usually contain 266.Dq ex_data 267or 268.Dq ex_new_index . 269See 270.Xr CRYPTO_set_ex_data 3 . 271.It fp 272file pointer: 273The function takes a 274.Vt FILE * 275argument. 276Usually, the function is a variant of another function taking a 277.Vt BIO * 278argument instead. 279.It i2d 280internal to DER: 281The function encodes an object passed as an argument 282according to ASN.1 distinguished encoding rules (DER). 283There are a few rare exceptions of functions that have 284.Dq i2d 285in their name but produce output anyway 286that only conforms to ASN.1 basic encoding rules (BER) and not to DER. 287.It get0 288The function returns an internal pointer 289owned by the object passed as an argument. 290The returned pointer must not be freed by the calling code. 291It will be freed automatically 292when the object owning the pointer will be freed. 293.It get1 294The function returns a copy of a sub-object 295of an object passed as an argument. 296The caller is responsible for freeing the returned object 297when it is no longer needed. 298.Pp 299If the object type is reference counted, usually the reference count 300is incremented instead of copying the object. 301Consequently, modifying the returned object may still impact all 302objects containing references to it. 303The caller is responsible for freeing the returned object 304when it is no longer needed; for reference-counted objects still 305referenced elsewhere, this will merely decrement the reference count. 306.It get 307Functions containing 308.Dq get 309in their name without a following digit may behave in 310.Dq get0 311or, more rarely, in 312.Dq get1 313style. 314To find out which is the case, refer to the individual manual pages. 315.It lh 316linear hash: 317The function manipulates a dynamic hash table. 318See 319.Xr lh_new 3 . 320.It md 321message digest. 322Some function names use the all caps form 323.Dq MD 324in the same sense. 325.It meth 326The function manipulates an object holding a function table. 327Usually, such function tables allow the application program 328to implement additional cryptographic or I/O algorithms 329and to use them with the same high-level API functions as the 330algorithms provided by the library itself, or to replace the 331implementations of algorithms provided by the library with 332custom implementations provided by the application program. 333Some API functions use the name elements 334.Dq method 335or 336.Dq METHOD 337in the same sense. 338See also the 339.Dq cb 340entry in the present list. 341.It nid 342numerical identifier: 343A non-standard, LibreSSL-specific 344.Vt int 345number associated with an ASN.1 object identifier. 346In several cases, the all caps form 347.Dq NID 348is used in the same sense. 349See 350.Xr OBJ_nid2obj 3 . 351.It obj 352This name element and its all caps form 353.Dq OBJ 354usually refer to ASN.1 object identifiers represented by the 355.Vt ASN1_OBJECT 356data type. 357See 358.Xr ASN1_OBJECT_new 3 . 359.It PKEY 360In most cases, this name element and its lower case form 361.Dq pkey 362mean 363.Dq private key , 364but for both forms, there are some cases where they mean 365.Dq public key 366instead. 367.It set0 368The function transfers ownership of a pointer passed as an argument 369to an object passed as another argument, 370by storing the pointer inside the object. 371The transferred pointer must not be freed by the calling code. 372It will be freed automatically 373when the object now owning the pointer will be freed. 374.It set1 375The function copies the content of one object passed as an argument 376into another object also passed as an argument. 377When the calling code no longer needs the copied object, 378it can free that object. 379.Pp 380In some cases, if the object to be copied is reference counted, 381the function does not actually copy the object but merely increments 382its reference count and stores the pointer to it in the other object. 383When the calling code no longer needs its original pointer to 384the now inner object, it can free the original pointer, thus 385decrementing the reference count of the inner object 386and transferring ownership of the inner object to the outer object. 387The inner object will then be freed automatically 388when the outer object is freed later on. 389.It set 390Functions containing 391.Dq set 392in their name without a following digit may behave in 393.Dq set0 394or, more rarely, in 395.Dq set1 396style. 397To find out which is the case, refer to the individual manual pages. 398.It sk 399stack: 400The function manipulates a variable-sized array of pointers 401in the idiosyncratic style described in 402.Xr OPENSSL_sk_new 3 . 403.It TS 404X.509 time-stamp protocol: 405See 406.Xr TS_REQ_new 3 . 407.It up_ref 408The function increments the reference count of the argument by one. 409Only a minority of object types support reference counting. 410For those that do, if the reference count is greater than one, 411the corresponding 412.Dq free 413function reverses the effect of one call to the 414.Dq up_ref 415function rather than freeing the object. 416.El 417.Sh SEE ALSO 418.Xr openssl 1 , 419.Xr ssl 3 420