1.\" $OpenBSD: ERR.3,v 1.11 2023/07/26 20:15:51 tb Exp $ 2.\" OpenSSL 186bb907 Apr 13 11:05:13 2015 -0700 3.\" 4.\" This file was written by Ulf Moeller <ulf@openssl.org> and 5.\" Dr. Stephen Henson <steve@openssl.org>. 6.\" Copyright (c) 2000, 2015 The OpenSSL Project. 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: July 26 2023 $ 53.Dt ERR 3 54.Os 55.Sh NAME 56.Nm ERR 57.Nd OpenSSL error codes 58.Sh SYNOPSIS 59.In openssl/err.h 60.Sh DESCRIPTION 61When a call to the OpenSSL library fails, this is usually signaled by 62the return value, and an error code is stored in an error queue 63associated with the current thread. 64The 65.Nm 66library provides functions to obtain these error codes and textual error 67messages. 68The 69.Xr ERR_get_error 3 70manpage describes how to access error codes. 71.Pp 72Error codes contain information about where the error occurred, and what 73went wrong. 74.Xr ERR_GET_LIB 3 75describes how to extract this information. 76A method to obtain human-readable error messages is described in 77.Xr ERR_error_string 3 . 78.Pp 79.Xr ERR_clear_error 3 80can be used to clear the error queue. 81.Pp 82Note that 83.Xr ERR_remove_state 3 84should be used to avoid memory leaks when threads are terminated. 85.Sh ADDING NEW ERROR CODES TO OPENSSL 86See 87.Xr ERR_put_error 3 88if you want to record error codes in the OpenSSL error system from 89within your application. 90.Pp 91The remainder of this section is of interest only if you want to add new 92error codes to OpenSSL or add error codes from external libraries. 93.Pp 94When you are using new function or reason codes, run 95.Sy make errors . 96The necessary 97.Sy #define Ns s 98will then automatically be added to the sub-library's header file. 99.Ss Adding new libraries 100When adding a new sub-library to OpenSSL, assign it a library number 101.Dv ERR_LIB_XXX , 102define a macro 103.Fn XXXerr 104(both in 105.In openssl/err.h ) , 106add its name to 107.Va ERR_str_libraries[] 108(in 109.Pa /usr/src/lib/libcrypto/err/err.c ) , 110and add 111.Fn ERR_load_XXX_strings 112to the 113.Fn ERR_load_crypto_strings 114function (in 115.Sy /usr/src/lib/libcrypto/err/err_all.c ) . 116Finally, add 117.Pa xxx_err.c 118to the 119.Pa Makefile . 120.Sh USING ERROR CODES IN EXTERNAL LIBRARIES 121It is also possible to use OpenSSL's error code scheme in external 122libraries. 123.Sh INTERNALS 124The error queues are stored in a hash table with one 125.Vt ERR_STATE 126entry for each PID. 127.Fn ERR_get_state 128returns the current thread's 129.Vt ERR_STATE . 130An 131.Vt ERR_STATE 132can hold up to 133.Dv ERR_NUM_ERRORS 134error codes. 135When more error codes are added, the old ones are overwritten, on the 136assumption that the most recent errors are most important. 137.Pp 138Error strings are also stored in a hash table. 139.Sh SEE ALSO 140.Xr crypto 3 , 141.Xr ERR_asprintf_error_data 3 , 142.Xr ERR_clear_error 3 , 143.Xr ERR_error_string 3 , 144.Xr ERR_get_error 3 , 145.Xr ERR_GET_LIB 3 , 146.Xr ERR_load_crypto_strings 3 , 147.Xr ERR_load_strings 3 , 148.Xr ERR_print_errors 3 , 149.Xr ERR_put_error 3 , 150.Xr ERR_remove_state 3 , 151.Xr ERR_set_mark 3 , 152.Xr SSL_get_error 3 153